2 Copyright (c) 2003-2006 Hewlett-Packard Development Company, L.P.
3 Permission is hereby granted, free of charge, to any person
4 obtaining a copy of this software and associated documentation
5 files (the "Software"), to deal in the Software without
6 restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the
9 Software is furnished to do so, subject to the following
12 The above copyright notice and this permission notice shall be
13 included in all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 OTHER DEALINGS IN THE SOFTWARE.
30 #include "uwx_scoreboard.h"
32 #include "uwx_trace.h"
35 static struct uwx_env uwx_env;
36 #define free(p) /* nullified */
37 #define malloc(sz) ((sz == sizeof(uwx_env)) ? &uwx_env : NULL)
40 alloc_cb uwx_allocate_cb = 0;
41 free_cb uwx_free_cb = 0;
43 int uwx_register_alloc_cb(alloc_cb alloc, free_cb free)
45 uwx_allocate_cb = alloc;
50 int uwx_init_history(struct uwx_env *env)
57 for (i = 0; i < NSPECIALREG; i++)
58 env->history.special[i] = UWX_DISP_REG(i);;
59 for (i = 0; i < NPRESERVEDGR; i++)
60 env->history.gr[i] = UWX_DISP_REG(UWX_REG_GR(4+i));
61 for (i = 0; i < NPRESERVEDBR; i++)
62 env->history.br[i] = UWX_DISP_REG(UWX_REG_BR(1+i));
63 for (i = 0; i < 4; i++)
64 env->history.fr[i] = UWX_DISP_REG(UWX_REG_FR(2+i));
65 for ( ; i < NPRESERVEDFR; i++)
66 env->history.fr[i] = UWX_DISP_REG(UWX_REG_FR(12+i));
71 int uwx_init_env(struct uwx_env *env, size_t total_size)
74 struct uwx_str_pool *str_pool;
75 struct uwx_scoreboard *scoreboards;
77 str_pool = (struct uwx_str_pool *)(env + 1);
78 scoreboards = (struct uwx_scoreboard *)(str_pool + 1);
80 if (sizeof(struct uwx_env) + sizeof(struct uwx_str_pool) > total_size)
82 total_size -= sizeof(struct uwx_env) + sizeof(struct uwx_str_pool);
84 env->context.valid_regs = 0;
85 env->context.valid_frs = 0;
86 for (i = 0; i < NSPECIALREG; i++)
87 env->context.special[i] = 0;
88 for (i = 0; i < NPRESERVEDGR; i++)
89 env->context.gr[i] = 0;
90 for (i = 0; i < NPRESERVEDBR; i++)
91 env->context.br[i] = 0;
92 for (i = 0; i < NPRESERVEDFR; i++) {
93 env->context.fr[i].part0 = 0;
94 env->context.fr[i].part1 = 0;
98 env->function_offset = 0;
99 env->ptr_size = DWORDSZ;
104 (void)uwx_init_history(env);
105 if (uwx_allocate_cb != NULL)
106 env->allocate_cb = uwx_allocate_cb;
108 env->allocate_cb = NULL;
109 if (uwx_free_cb != NULL)
110 env->free_cb = uwx_free_cb;
113 env->free_scoreboards = 0;
114 env->used_scoreboards = 0;
115 env->labeled_scoreboards = 0;
116 (void)uwx_init_str_pool(env, str_pool);
117 env->module_name = 0;
118 env->function_name = 0;
124 env->abi_context = 0;
125 env->nsbreg = NSBREG;
126 env->nscoreboards = 0;
130 for (i = 0; total_size >= sizeof(struct uwx_scoreboard); i++) {
131 (void) uwx_prealloc_scoreboard(env, &scoreboards[i]);
132 total_size -= sizeof(struct uwx_scoreboard);
137 int uwx_set_nofr(struct uwx_env *env)
140 return UWX_ERR_NOENV;
142 env->nsbreg = NSBREG_NOFR;
146 struct uwx_env *uwx_init()
151 total_size = sizeof(struct uwx_env) +
152 sizeof(struct uwx_str_pool) +
153 NSCOREBOARDS * sizeof(struct uwx_scoreboard);
155 if (uwx_allocate_cb == 0)
156 env = (struct uwx_env *) malloc(total_size);
158 env = (struct uwx_env *) (*uwx_allocate_cb)(total_size);
160 uwx_init_env(env, total_size);
166 int uwx_set_remote(struct uwx_env *env, int is_big_endian_target)
168 int is_big_endian_host;
172 return UWX_ERR_NOENV;
176 is_big_endian_host = 1;
177 p = (char *)&is_big_endian_host;
179 if (is_big_endian_target == is_big_endian_host)
187 int uwx_register_callbacks(
191 lookupip_cb lookupip)
194 return UWX_ERR_NOENV;
196 env->copyin = copyin;
197 env->lookupip = lookupip;
201 int uwx_get_abi_context_code(struct uwx_env *env)
204 return UWX_ERR_NOENV;
205 return env->abi_context;
208 int uwx_free(struct uwx_env *env)
211 uwx_free_scoreboards(env);
212 uwx_free_str_pool(env);
214 if (env->free_cb == 0)
217 (*env->free_cb)((void *)env);