|
|
| 1 |
#include <linux/init.h> // initcall_t |
1 |
#include <linux/init.h> // initcall_t |
| 2 |
#include <linux/kernel.h> // SYSTEM_BOOTING |
2 |
#include <linux/kernel.h> // SYSTEM_BOOTING |
| 3 |
#include <linux/sched.h> // struct task_struct |
3 |
#include <linux/sched.h> // struct task_struct |
|
|
4 |
#include <stdio.h> |
| 4 |
#include "sim-init.h" |
5 |
#include "sim-init.h" |
| 5 |
#include "sim.h" |
6 |
#include "sim.h" |
| 6 |
|
7 |
|
|
|
| 113 |
|
114 |
|
| 114 |
static struct SimKernel *g_kernel; |
115 |
static struct SimKernel *g_kernel; |
| 115 |
|
116 |
|
|
|
117 |
|
| 118 |
static int num_handler = 0; |
| 119 |
void *atexit_list[1024]; |
| 120 |
|
| 116 |
void sim_init (struct SimExported *exported, const struct SimImported *imported, struct SimKernel *kernel) |
121 |
void sim_init (struct SimExported *exported, const struct SimImported *imported, struct SimKernel *kernel) |
| 117 |
{ |
122 |
{ |
| 118 |
// make sure we can call the callbacks |
123 |
// make sure we can call the callbacks |
|
|
| 172 |
|
177 |
|
| 173 |
// finally, put the system in RUNNING state. |
178 |
// finally, put the system in RUNNING state. |
| 174 |
system_state = SYSTEM_RUNNING; |
179 |
system_state = SYSTEM_RUNNING; |
|
|
180 |
|
| 181 |
/* XXX handle atexit registration for gcov */ |
| 182 |
int i; |
| 183 |
for (i = 0; i < 1024; i++) |
| 184 |
{ |
| 185 |
if (atexit_list [i]) |
| 186 |
g_imported.atexit (g_kernel, (void (*)(void))atexit_list[i]); |
| 187 |
} |
| 188 |
|
| 175 |
} |
189 |
} |
| 176 |
|
190 |
|
| 177 |
|
191 |
|
|
|
| 195 |
{ |
209 |
{ |
| 196 |
return g_imported.memset (g_kernel, dst, value, size); |
210 |
return g_imported.memset (g_kernel, dst, value, size); |
| 197 |
} |
211 |
} |
|
|
212 |
int atexit (void (*function)(void)) |
| 213 |
{ |
| 214 |
if (g_imported.atexit == 0) |
| 215 |
{ |
| 216 |
atexit_list[num_handler++] = function; |
| 217 |
return 0; |
| 218 |
} |
| 219 |
else |
| 220 |
{ |
| 221 |
return g_imported.atexit (g_kernel, function); |
| 222 |
} |
| 223 |
} |
| 224 |
int access (const char *pathname, int mode) |
| 225 |
{ |
| 226 |
return g_imported.access (g_kernel, pathname, mode); |
| 227 |
} |
| 228 |
char *getenv (const char *name) |
| 229 |
{ |
| 230 |
return g_imported.getenv (g_kernel, name); |
| 231 |
} |
| 232 |
pid_t getpid(void) |
| 233 |
{ |
| 234 |
return (pid_t)0; |
| 235 |
} |
| 236 |
int mkdir(const char *pathname, mode_t mode) |
| 237 |
{ |
| 238 |
return g_imported.mkdir (g_kernel, pathname, mode); |
| 239 |
} |
| 240 |
int open(const char *pathname, int flags) |
| 241 |
{ |
| 242 |
return g_imported.open (g_kernel, pathname, flags); |
| 243 |
} |
| 244 |
int fcntl(int fd, int cmd, ... /* arg */ ) |
| 245 |
{ |
| 246 |
return 0; |
| 247 |
} |
| 248 |
int __fxstat (int ver, int fd, void *buf) |
| 249 |
{ |
| 250 |
return g_imported.__fxstat (g_kernel, ver, fd, buf); |
| 251 |
} |
| 252 |
int fseek(FILE *stream, long offset, int whence) |
| 253 |
{ |
| 254 |
return g_imported.fseek (g_kernel, stream, offset, whence); |
| 255 |
} |
| 256 |
long ftell(FILE *stream) |
| 257 |
{ |
| 258 |
return g_imported.ftell (g_kernel, stream); |
| 259 |
} |
| 260 |
void setbuf(FILE *stream, char *buf) |
| 261 |
{ |
| 262 |
return g_imported.setbuf (g_kernel, stream, buf); |
| 263 |
} |
| 264 |
FILE *fdopen(int fd, const char *mode) |
| 265 |
{ |
| 266 |
return g_imported.fdopen (g_kernel, fd, mode); |
| 267 |
} |
| 268 |
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) |
| 269 |
{ |
| 270 |
return g_imported.fread (g_kernel, ptr, size, nmemb, stream); |
| 271 |
} |
| 272 |
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) |
| 273 |
{ |
| 274 |
return g_imported.fwrite (g_kernel, ptr, size, nmemb, stream); |
| 275 |
} |
| 276 |
int fclose(FILE *fp) |
| 277 |
{ |
| 278 |
return g_imported.fclose (g_kernel, fp); |
| 279 |
} |
| 198 |
unsigned long sim_random (void) |
280 |
unsigned long sim_random (void) |
| 199 |
{ |
281 |
{ |
| 200 |
return g_imported.random (g_kernel); |
282 |
return g_imported.random (g_kernel); |
|
|
| 230 |
struct SimTask *sim_task_start (void (*callback) (void *), void *context) |
312 |
struct SimTask *sim_task_start (void (*callback) (void *), void *context) |
| 231 |
{ |
313 |
{ |
| 232 |
struct SimTaskTrampolineContext *ctx = sim_malloc (sizeof (struct SimTaskTrampolineContext)); |
314 |
struct SimTaskTrampolineContext *ctx = sim_malloc (sizeof (struct SimTaskTrampolineContext)); |
|
|
315 |
if (!ctx) |
| 316 |
{ |
| 317 |
return NULL; |
| 318 |
} |
| 233 |
ctx->callback = callback; |
319 |
ctx->callback = callback; |
| 234 |
ctx->context = context; |
320 |
ctx->context = context; |
| 235 |
return g_imported.task_start (g_kernel, &sim_task_start_trampoline, ctx); |
321 |
return g_imported.task_start (g_kernel, &sim_task_start_trampoline, ctx); |