// ************************************************************************************************* // @fn main // @brief Main routine // @param none // @return none // ************************************************************************************************* int main(void) { #ifdef EMU emu_init(); #endif // Init MCU init_application(); // Assign initial value to global variables init_global_variables(); #ifdef CONFIG_TEST // Branch to welcome screen test_mode(); #else display_all_off(); #endif // Main control loop: wait in low power mode until some event needs to be processed while(1) { // When idle go to LPM3 idle_loop(); // Process wake-up events if (button.all_flags || sys.all_flags) wakeup_event(); // Process actions requested by logic modules if (request.all_flags) process_requests(); // Before going to LPM3, update display if (display.all_flags) display_update(); } }
void game_frame() { if (emu_started) { emu_frame(); } else { menu_frame(); if (menu_done) emu_init(menu_choice); } }
int Winapi ec_init(void) { char * initfile = (char *) 0; char filename_buf[MAX_PATH_LEN]; pword goal,module; int res; /*---------------------------------------------------------------- * Make the connection to the shared heap, if any. * Because of mmap problems on some machines this should * happen AFTER initializing the message passing system. *----------------------------------------------------------------*/ mem_init(ec_options.init_flags); /* depends on -c and -m options */ /* * Init the global (shared) eclipse structures, dictionary, code... * Maybe load a saved state. * Note that we don't have an engine yet! */ eclipse_global_init(ec_options.init_flags); /*---------------------------------------------------------------- * Setup the Prolog engine *----------------------------------------------------------------*/ /* * Initialize the Prolog engine */ emu_init(ec_options.init_flags, 0); initfile = strcat(strcpy(filename_buf, ec_eclipse_home), "/lib/kernel.eco"); if (ec_access(initfile, R_OK) < 0) { initfile = strcat(strcpy(filename_buf, ec_eclipse_home), "/lib/kernel.pl"); if (ec_access(initfile, R_OK) < 0) { ec_panic("Aborting: Can't find boot file! Please check either\na) your program's setting for eclipsedir in ec_set_option(), or\nb) your setting for ECLIPSEDIR environment variable.\n","ec_init()"); } } res = eclipse_boot(initfile); if (res != PSUCCEED) return res; goal = ec_term(ec_did("main",1), ec_long(ec_options.init_flags & INIT_SHARED ? 0 : 1)); module.val.did = ec_.d.kernel_sepia; module.tag.kernel = ModuleTag(ec_.d.kernel_sepia); if (main_emulc_noexit(goal.val, goal.tag, module.val, module.tag) != PYIELD) return PFAIL; return PSUCCEED; }
int main() { #ifdef EMULATION emu_init(); #endif irq_setmask(0); irq_enable(1); uart_async_init(); banner(); brd_init(); cpustats_init(); time_init(); mem_init(); vga_init(); snd_init(); pfpu_init(); tmu_init(); renderer_init(); apipe_init(); rpipe_init(); slowout_init(); hdlcd_init(); ui_init(); shell_init(); while(1) { if(readchar_nonblock()) shell_input(readchar()); apipe_service(); rpipe_service(); #ifdef EMULATION emu_service(); #endif } return 0; }
int main(int argc, char *argv[]) { void *lowest_segments[2] = { NULL, NULL }; Elf32_Ehdr hdr; Elf32_Phdr *phdr; FILE *fi; maps_range maps[16]; int map_cnt; int i, ret, envc, sfp; long *stack_frame; struct stat st; char buf[64]; long lret; if (argc < 2) { fprintf(stderr, "usage: %s <program> [args]\n", argv[0]); return 1; } g_argv = argv; lret = g_personality(-1); if (g_syscall_error(lret) != -1) { lret |= 0x0240000; // ADDR_COMPAT_LAYOUT | ADDR_NO_RANDOMIZE g_personality(lret); } fi = fopen("/proc/self/maps", "r"); CHECK_NE(fi, NULL, "fopen maps"); for (i = 0; i < ARRAY_SIZE(maps); i++) { ret = fscanf(fi, "%lx-%lx %*s %*s %*s %*s %*s\n", &maps[i].start, &maps[i].end); if (ret <= 0) break; CHECK_EQ(ret, 2, "maps parse error"); } fclose(fi); map_cnt = i; CHECK_NE(map_cnt, 0, "no maps"); CHECK_NE(map_cnt, ARRAY_SIZE(maps), "too many maps"); fi = fopen(argv[1], "rb"); if (fi == NULL) FAIL_PERROR("fopen"); if (fread(&hdr, 1, sizeof(hdr), fi) != sizeof(hdr)) FAIL_PERROR("too small or"); if (memcmp(hdr.e_ident, ELFMAG "\x01\x01", SELFMAG + 2) != 0) { fprintf(stderr, "not 32bit LE ELF?\n"); return 1; } HDR_CHECK_EQ(e_type, ET_EXEC, "not executable"); HDR_CHECK_EQ(e_machine, EM_ARM, "not ARM"); HDR_CHECK_EQ(e_phentsize, sizeof(Elf32_Phdr), "bad PH entry size"); HDR_CHECK_NE(e_phnum, 0, "no PH entries"); phdr = malloc(hdr.e_phnum * hdr.e_phentsize); CHECK_NE(phdr, NULL, "OOM"); if (fread(phdr, hdr.e_phentsize, hdr.e_phnum, fi) != hdr.e_phnum) FAIL_PERROR("too small or"); for (i = 0; i < hdr.e_phnum; i++) { Elf32_Addr end_addr = phdr[i].p_vaddr + phdr[i].p_memsz; Elf32_Addr align; void *ptr, *map_ptr; if (phdr[i].p_type == PT_NOTE) continue; if (phdr[i].p_type != PT_LOAD) { fprintf(stderr, "skipping section %d\n", phdr[i].p_type); continue; } ret = is_range_used(maps, map_cnt, phdr[i].p_vaddr, end_addr); if (ret) { fprintf(stderr, "segment %d (%08x-%08x) hits %08lx-%08lx in maps\n", i, phdr[i].p_vaddr, end_addr, maps[ret - 1].start, maps[ret - 1].end); return 1; } log("load %d %08x-%08x from %08x\n", phdr[i].p_type, phdr[i].p_vaddr, end_addr, phdr[i].p_offset); align = phdr[i].p_vaddr & 0xfff; map_ptr = (void *)(phdr[i].p_vaddr - align); ptr = mmap(map_ptr, phdr[i].p_memsz + align, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_FIXED|MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); if (ptr == MAP_FAILED || ptr != map_ptr) FAIL_PERROR("mmap"); if (phdr[i].p_filesz > 0) { if (fseek(fi, phdr[i].p_offset, SEEK_SET) != 0) FAIL_PERROR("fseek"); if (fread((char *)ptr + align, 1, phdr[i].p_filesz, fi) != phdr[i].p_filesz) FAIL_PERROR("too small or"); if (phdr[i].p_flags & PF_X) do_patches((char *)ptr + align, phdr[i].p_filesz); } if (lowest_segments[0] == NULL || map_ptr < lowest_segments[0]) lowest_segments[0] = map_ptr; } // build self bin path snprintf(buf, sizeof(buf), "/proc/self/fd/%d", fileno(fi)); if (lstat(buf, &st) != 0) FAIL_PERROR("lstat bin_path"); bin_path = malloc(st.st_size + 1); CHECK_NE(bin_path, NULL, "bin_path"); ret = readlink(buf, bin_path, st.st_size); if (ret < 0) FAIL_PERROR("readlink"); bin_path[ret] = 0; fclose(fi); emu_init(lowest_segments, 0); // generate stack frame: argc, argv[], NULL, env[], NULL for (envc = 0; environ[envc] != NULL; envc++) ; stack_frame = calloc(argc + envc + 3, sizeof(stack_frame[0])); if (stack_frame == NULL) { fprintf(stderr, "stack_frame OOM\n"); return 1; } // update the environment setenv("_", bin_path, 1); sfp = 0; stack_frame[sfp++] = argc - 1; for (i = 1; i < argc; i++) stack_frame[sfp++] = (long)argv[i]; stack_frame[sfp++] = 0; for (i = 0; i < envc; i++) stack_frame[sfp++] = (long)environ[i]; stack_frame[sfp++] = 0; log("entering %08x, %d stack entries\n", hdr.e_entry, sfp); do_entry(hdr.e_entry, stack_frame, sfp, NULL); fprintf(stderr, "do_entry failed!\n"); return 1; }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { int ret; char *p,*p2,*cmdline; memset(configfilename,0,1024); MyRegisterClass(hInstance); if(InitInstance(hInstance,nCmdShow) == 0) { return(FALSE); } log_sethook(console_loghook); //make the exe path variable GetModuleFileName(hInstance,exepath,1024); if((p = strrchr(exepath,PATH_SEPERATOR)) != 0) { *p = 0; } if(emu_init() != 0) return(FALSE); ShowWindow(hWnd,nCmdShow); UpdateWindow(hWnd); p = cmdline = mem_strdup(lpCmdLine); if(*p == '\"') { p++; if((p2 = strchr(p,'\"')) != 0) *p2 = 0; } if(strcmp(p,"") != 0) { char *filename; //it is a relative path, make full path name if(p[1] != ':') { char *cwd = system_getcwd(); int len = strlen(p) + strlen(cwd) + 2; filename = (char*)mem_alloc(len); sprintf(filename,"%s\\%s",cwd,p); } //already full path name else { filename = mem_strdup(p); } log_printf("trying lpcmdline as filename (%s)...\n",filename); loadrom(filename); mem_free(filename); } mem_free(cmdline); ret = (emu_mainloop() == 0) ? TRUE : FALSE; emu_kill(); return(emu_exit(ret)); }
int main(int argc, char **argv) { char bootfile_buf[MAX_PATH_LEN]; char * initfile = (char *) 0; char * eclipsedir = (char *) 0; int c, new_argc; pword goal, module; int err; int init_flags = INIT_SHARED|INIT_PRIVATE|INIT_ENGINE|INIT_PROCESS; unsigned startup_delay = 0; int vm_options = 0; char * session, * nsrv_hostname; unsigned nsrv_port_number; #ifdef PROFILE moncontrol(0); /* disable profiling by default */ #endif /* * collect information from the command line * remove some internally used arguments from the command line */ for (c = new_argc = 1; c < argc; ) { if (argv[c][0] == '-' && argv[c][2] == 0) /* single char opt */ { switch (argv[c][1]) { case 'a': /* -a <worker> <session> <nsrv_hostname> <nsrv_port_no> */ if (++c + 4 > argc) usage(argv[c-1]); ec_options.parallel_worker = atoi(argv[c++]); session = argv[c++]; nsrv_hostname = argv[c++]; nsrv_port_number = atoi(argv[c++]); break; case 'c': /* -c <shared_map_file> */ if (++c + 1 > argc) usage(argv[c-1]); ec_options.mapfile = argv[c++]; ec_options.allocation = ALLOC_FIXED; init_flags &= ~INIT_SHARED; break; case 'm': /* -m <shared_map_file> */ if (++c + 1 > argc) usage(argv[c-1]); ec_options.mapfile = argv[c++]; ec_options.allocation = ALLOC_FIXED; break; case 'b': /* -b <bootfile> */ argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-1]); argv[new_argc++] = argv[c++]; /* shift */ break; case 'e': /* -e <goal> */ argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-1]); argv[new_argc++] = argv[c++]; /* shift */ break; case 'g': /* -g <size> */ argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-1]); argv[new_argc++] = argv[c]; /* shift */ ec_options.globalsize = sizearg(argv[c++]); if (ec_options.globalsize < MIN_GLOBAL) { ec_bad_exit("ECLiPSe: Global stack size out of range."); } break; case 'd': /* -d <n> */ /* delay worker startup by <n> seconds */ if (++c + 1 > argc) usage(argv[c-1]); startup_delay = atoi(argv[c++]); if (startup_delay == 0) ec_options.io_option = OWN_IO; /* every worker has its own i/o */ else sleep(startup_delay); break; case 'D': /* -D <eclipsedir> */ if (++c + 1 > argc) usage(argv[c-1]); eclipsedir = argv[c++]; break; case 'l': /* -l <size> */ argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-1]); argv[new_argc++] = argv[c]; /* shift */ ec_options.localsize = sizearg(argv[c++]); if (ec_options.localsize < MIN_LOCAL) { ec_bad_exit("ECLiPSe: local stack size out of range."); } break; case 'h': /* -h <size> */ argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-1]); argv[new_argc++] = argv[c]; /* shift */ ec_options.privatesize = sizearg(argv[c++]); if (ec_options.privatesize < MIN_PRIVATE) { ec_bad_exit("ECLiPSe: Private heap size out of range."); } break; case 's': /* -s <size> */ argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-1]); argv[new_argc++] = argv[c]; /* shift */ ec_options.sharedsize = sizearg(argv[c++]); if (ec_options.sharedsize < MIN_SHARED) { ec_bad_exit("ECLiPSe: Shared heap size out of range."); } break; case 'o': /* enable oracles */ c += 1; vm_options = ORACLES_ENABLED; break; case 'p': argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-2]); argv[new_argc++] = argv[c]; /* shift */ ec_options.option_p = atoi(argv[c++]); break; case '-': /* -- give the rest to Prolog */ for (; c < argc;) argv[new_argc++] = argv[c++]; break; default: /* unknown: error */ usage(argv[c]); break; } } else if (!strcmp(argv[c], "-debug_level")) { if (++c + 1 > argc) usage(argv[c-1]); ec_options.debug_level = atoi(argv[c++]); } else if (!strcmp(argv[c], "-layout")) { int lflags = 0; char *from = 0; char *to = 0; long increment = 0L; if (++c + 1 <= argc) lflags = (int) strtol(argv[c++], (char **) 0, 16); if (c + 1 <= argc) increment = strtol(argv[c++], (char **) 0, 16); if (c + 1 <= argc) from = (char *) strtol(argv[c++], (char **) 0, 16); if (c + 1 <= argc) to = (char *) strtol(argv[c++], (char **) 0, 16); if (ec_options.allocation == ALLOC_FIXED) mem_layout(); #ifdef HAVE_MMAP ec_layout(lflags, from, to, increment); #else ec_bad_exit("ECLiPSe: The -layout scan is not supported without\nmemory mapping."); #endif } else if (!strcmp(argv[c], "-norl")) { argv[new_argc++] = argv[c++]; /* shift */ ec_options.rl = 0; } else /* raise error unless preceeded by a -- option */ { usage(argv[c]); } } /*---------------------------------------------------------------- * Initialize private heap as early as possible * (must be before setup_mps()) *----------------------------------------------------------------*/ malloc_init(); irq_lock_init(delayed_break); /*---------------------------------------------------------------- * Init message passing system *----------------------------------------------------------------*/ if (ec_options.parallel_worker) { setup_mps(ec_options.parallel_worker, session, nsrv_hostname, nsrv_port_number, init_flags & INIT_SHARED); } /*---------------------------------------------------------------- * Make the connection to the shared heap, if any. * Because of mmap problems on some machines this should * happen AFTER initializing the message passing system. *----------------------------------------------------------------*/ mem_init(init_flags); /* depends on -c and -m options */ /*---------------------------------------------------------------- * Init parallel scheduler etc. *----------------------------------------------------------------*/ if (ec_options.parallel_worker) { parallel_init(init_flags); } /*---------------------------------------------------------------- * Init the low-level I/O stuff, ie the part which should * really not be done by eclipse itself... *----------------------------------------------------------------*/ /* char_io_init(); does not yet exist */ /*---------------------------------------------------------------- * Entry point after longjmp(reset) *----------------------------------------------------------------*/ switch (setjmp(reset)) { case 0: /* raw boot or -r from above */ break; case 3: /* restore program state */ case 2: init_flags = REINIT_SHARED|INIT_ENGINE|INIT_PRIVATE; break; case 4: /* restore execution state */ init_flags = REINIT_SHARED|INIT_PRIVATE; break; case 1: /* reset after fatal error */ default: if (!(GlobalFlags & HEAP_READY) || ec_options.parallel_worker) { (void) ec_cleanup(); exit(-1); } init_flags = INIT_ENGINE; switch (memory_corrupted++) { case 0: break; case 1: /* try to print a message */ memory_corrupted = 2; ec_bad_exit("ECLiPSe: Fatal error, memory corrupted."); /* fall to */ case 2: /* we couldn't even print the message */ exit(-1); } break; } /* * set up our own panic function which longjumps back to reset * To access command line through global variabes */ ec_options.user_panic = main_panic; ec_options.Argc = new_argc; ec_options.Argv = argv; ec_options.eclipse_home = (char *) 0; ec_options.init_flags = init_flags; if (eclipsedir) ec_options.eclipse_home = eclipsedir; /* * Init the global (shared) eclipse structures, dictionary, code... * Maybe load a saved state. * Note that we don't have an engine yet! */ eclipse_global_init(init_flags); /*---------------------------------------------------------------- * Setup the Prolog engine *----------------------------------------------------------------*/ /* * If we have a PROG_AND_DATA saved state (execution state saved) * we are finished and enter the emulator. */ if (!(init_flags & INIT_ENGINE)) { err = restart_emulc(); (void) ec_cleanup(); exit(err); } /* * Initialize the Prolog engine */ emu_init(init_flags, vm_options); /* * If we are not running an already booted eclipse, * compile $ECLIPSEDIR/lib/kernel.eco */ if (init_flags & INIT_SHARED) { char msg[1024]; initfile = strcat(strcpy(bootfile_buf, ec_eclipse_home), "/lib/kernel.eco"); if (ec_access(initfile, R_OK) < 0) { sprintf(msg, "ECLiPSe: Can't find boot file %s!\nPlease check the setting of your ECLIPSEDIR environment variable\nor use the -D <dir> command line option.", initfile); ec_bad_exit(msg); } err = eclipse_boot(initfile); if (err != PSUCCEED) { (void) ec_cleanup(); exit(err); } } if (init_flags & (INIT_SHARED|REINIT_SHARED)) GlobalFlags |= HEAP_READY; /* for the other workers */ goal = ec_term(ec_did("main",1), ec_long(init_flags & INIT_SHARED ? 0 : 1)); module.val.did = d_.kernel_sepia; module.tag.kernel = ModuleTag(d_.kernel_sepia); if (ec_options.parallel_worker <= 1) /* only or first worker */ { err = main_emulc_noexit(goal.val, goal.tag, module.val, module.tag); if (err == PYIELD) { memory_corrupted = 0; /* assume it's ok */ ec_post_goal(ec_term(ec_did(":",2), ec_atom(ec_did("sepia_kernel",0)), ec_atom(ec_did("standalone_toplevel",0)))); do { err = ec_resume(); } while (err == PYIELD); } } else { err = slave_emulc(); } ec_cleanup(); exit(err); /*NOTREACHED*/ }
int main(void) { emu_init(); emu_step(); return 0; }
int main(int argc, char *argv[]) { g_argv = argv; plat_early_init(); in_init(); //in_probe(); plat_target_init(); plat_init(); emu_prep_defconfig(); // depends on input emu_read_config(NULL, 0); emu_init(); menu_init(); engineState = PGS_Menu; if (argc > 1) parse_cmd_line(argc, argv); if (engineState == PGS_ReloadRom) { if (emu_reload_rom(rom_fname_reload)) { engineState = PGS_Running; if (load_state_slot >= 0) { state_slot = load_state_slot; emu_save_load_game(1, 0); } } } for (;;) { switch (engineState) { case PGS_Menu: menu_loop(); break; case PGS_TrayMenu: menu_loop_tray(); break; case PGS_ReloadRom: if (emu_reload_rom(rom_fname_reload)) engineState = PGS_Running; else { printf("PGS_ReloadRom == 0\n"); engineState = PGS_Menu; } break; case PGS_RestartRun: engineState = PGS_Running; /* vvv fallthrough */ case PGS_Running: emu_loop(); break; case PGS_Quit: goto endloop; default: printf("engine got into unknown state (%i), exitting\n", engineState); goto endloop; } } endloop: emu_finish(); plat_finish(); plat_target_finish(); return 0; }