static void init_exec(void) { /* * Install ram based file system. */ exec_init(&bin_exec); }
int make1( TARGET *t ) { memset( (char *)counts, 0, sizeof( *counts ) ); #ifdef OPT_SERIAL_OUTPUT_EXT exec_init(); #endif /* Recursively make the target and its dependents */ make1a( t, (TARGET *)0 ); /* Wait for any outstanding commands to finish running. */ while( execwait() ) ; #ifdef OPT_SERIAL_OUTPUT_EXT exec_done(); #endif /* Talk about it */ if( DEBUG_MAKE && counts->failed ) printf( "*** failed updating %d target(s)...\n", counts->failed ); if( DEBUG_MAKE && counts->skipped ) printf( "*** skipped %d target(s)...\n", counts->skipped ); if( DEBUG_MAKE && counts->made ) printf( "*** updated %d target(s)...\n", counts->made ); return counts->total != counts->made; }
static void init_exec() { /* * Install ram based file system. */ exec_init(&elf_exec); }
int main(int argc, char* argv[]) { struct t_exec exec; struct item *item; struct t_var *var; if (argc > 1) { debug_level = atoi(argv[1]); } else { debug_level = 1; } printf("debug_level: %d\n", debug_level); do { if (exec_init(&exec, stdin) < 0) { fprintf(stderr, "Failed to exec\n"); break; } core_apply(&exec); exec.parser.max_output = 100; exec_addfunc2(&exec, "funcA", &myfunc); if (exec_statements(&exec) < 0) { fprintf(stderr, "exec_statements() failed\n"); break; } /* * Print all the vars */ item = exec.vars.first; if (item) { printf("Vars:\n"); while (item) { var = (struct t_var *) item->value; printf(" %s=%s\n", var->name, value_to_s(var->value)); item = item->next; } } } while (0); exec_close(&exec); printf("Done.\n"); return 0; }
bool elfexec_init(void *elf, size_t file_size, struct elfexec *holder, uint8_t priority, seL4_CPtr io_ep) { if (io_ep == seL4_CapNull || elf == NULL || holder == NULL) { ERRX_RAISE_GENERIC(GERR_NULL_VALUE); return false; } holder->page_directory = object_alloc(seL4_IA32_PageDirectoryObject); if (holder->page_directory == NULL) { ERRX_TRACEPOINT; return false; } holder->cspace = object_alloc(seL4_CapTableObject); if (holder->cspace == NULL) { object_free_token(holder->page_directory); ERRX_TRACEPOINT; return false; } holder->priv_cookie = 0; holder->pd = elfloader_load(elf, file_size, object_cap(holder->page_directory)); if (holder->pd == NULL) { elfexec_destroy(holder); ERRX_TRACEPOINT; return false; } seL4_IA32_Page ipc_page = elfloader_get_page(holder->pd, (void *) IPC_ADDRESS, ELF_MEM_READABLE | ELF_MEM_WRITABLE, true); if (ipc_page == seL4_CapNull) { elfexec_destroy(holder); ERRX_TRACEPOINT; return false; } if (!cspace_configure(holder, ipc_page, io_ep)) { elfexec_destroy(holder); ERRX_TRACEPOINT; return false; } // other capability parameters such as page directory are pulled from the cspace holder->priv_cookie = exec_init(object_cap(holder->cspace), IPC_ADDRESS, priority, holder->pd->entry_position); if (!holder->priv_cookie) { elfexec_destroy(holder); ERRX_TRACEPOINT; return false; } return true; }
int main(int argc, char **argv, char **envp) { char * const console_dev = "/dev/console"; char * const null_dev = "/dev/null"; char * const ttyAS0_dev = "/dev/ttyAS0"; char * const vfd_dev = "/dev/vfd"; if (getpid()==1) { int fh; mode_t old = umask(0000); if (access(console_dev,F_OK)) { mknod(console_dev,S_IFCHR|0600,makedev(5,1)); fh = open(console_dev,O_RDWR); if (fh){ /* descriptor 0 is already open?!? */ close(fh); } else { /* create stdout/stderr for init */ (void)dup(0); /* 1 */ (void)dup(0); /* 2 */ } } if (access(null_dev,F_OK)) mknod(null_dev,S_IFCHR|0666,makedev(1,3)); if (access(ttyAS0_dev,F_OK)) mknod(ttyAS0_dev,S_IFCHR|0660,makedev(204,40)); if (access(vfd_dev,F_OK)) mknod(vfd_dev,S_IFCHR|0660,makedev(147,0)); umask(old); /* finally become the real init */ exec_init(argv, envp); } else { fprintf (stderr, "This program is supposed to be run by the kernel.\n"); } return 0; }
LIST * builtin_shell( PARSE *parse, LOL *args, int *jmp ) { LIST *l = lol_get( args, 0 ); LIST *shell = var_get( "JAMSHELL" ); /* shell is per-target */ LIST *output = L0; exec_init(); for( ; l; l = list_next( l ) ) { execcmd( l->string, shell_done, &output, shell, 1 ); execwait(); } exec_done(); return output; }
int main(int argc, char* argv[]) { struct t_exec exec; do { if (exec_init(&exec, stdin) < 0) { fprintf(stderr, "Failed to exec\n"); break; } core_apply(&exec); exec.parser.max_output = 100; if (exec_statements(&exec) < 0) { break; } } while (0); exec_close(&exec); return 0; }
/* * This routine does all of the common setup for invoking init; global * and non-global zones employ this routine for the functionality which is * in common. * * This program (init, presumably) must be a 32-bit process. */ int start_init_common() { proc_t *p = curproc; ASSERT_STACK_ALIGNED(); p->p_zone->zone_proc_initpid = p->p_pid; p->p_cstime = p->p_stime = p->p_cutime = p->p_utime = 0; p->p_usrstack = (caddr_t)USRSTACK32; p->p_model = DATAMODEL_ILP32; p->p_stkprot = PROT_ZFOD & ~PROT_EXEC; p->p_datprot = PROT_ZFOD & ~PROT_EXEC; p->p_stk_ctl = INT32_MAX; p->p_as = as_alloc(); p->p_as->a_proc = p; p->p_as->a_userlimit = (caddr_t)USERLIMIT32; (void) hat_setup(p->p_as->a_hat, HAT_INIT); init_core(); init_mstate(curthread, LMS_SYSTEM); return (exec_init(p->p_zone->zone_initname, p->p_zone->zone_bootargs)); }
int main(void) { uint16_t major, minor, build; int i, res, count; // main init of hardware plus a version-dependent number for the parameters that will // force a format of parameter between version numbers. pixyInit(SRAM3_LOC, &LR0[0], sizeof(LR0)); cc_init(g_chirpUsb); ser_init(); exec_init(g_chirpUsb); // load programs exec_addProg(&g_progBlobs); ptLoadParams(); exec_addProg(&g_progPt); #if 0 chaseLoadParams(); exec_addProg(&g_progChase); #endif exec_addProg(&g_progVideo, true); // this code formats if the version has changed for (i=0, count=0; i<25; i++) { res = prm_get("fwver", &major, &minor, &build, END); if (res>=0 && major==FW_MAJOR_VER && minor==FW_MINOR_VER && build==FW_BUILD_VER) count++; } if (count==0) prm_format(); // check version prm_add("fwver", PRM_FLAG_INTERNAL, "", UINT16(FW_MAJOR_VER), UINT16(FW_MINOR_VER), UINT16(FW_BUILD_VER), END); ser_setInterface(SER_INTERFACE_UART); rcs_setLimits(1, -250, 250); // extends servo range to maximum//0x__BBRRGG //28 == full back, 12 == full angle down, 22 == parallel uint8_t WBV_sub = 0x16; uint32_t WBV = WBV_sub | WBV_sub << 8 | WBV_sub << 16; cam_setWBV(WBV); // sets the white balance manually cam_setAEC(0); // turns off auto exposure correction cam_setBrightness(35); // sets the brightness while(1) { //edgeDetect_highres_run(); edgeDetect_run(); // run the main edgeDetect function //exec_loop(); // Debug through pixymon } #if 0 #define DELAY 1000000 rcs_setFreq(100); rcs_setLimits(0, -200, 200); rcs_setLimits(1, -200, 200); while(1) { rcs_setPos(0, 0); delayus(DELAY); rcs_setPos(0, 500); delayus(DELAY); rcs_setPos(0, 1000); delayus(DELAY); rcs_setPos(1, 0); delayus(DELAY); rcs_setPos(1, 500); delayus(DELAY); rcs_setPos(1, 1000); delayus(DELAY); } #endif #if 0 while(1) { g_chirpUsb->service(); handleButton(); } #endif }
int main(void) { uint16_t major, minor, build; char *type; int i, res, count, count2; volatile uint32_t d; // insert a small delay so power supply can stabilize for (d=0; d<2500000; d++); #ifdef KEIL pixyInit(SRAM3_LOC, &LR0[0], sizeof(LR0)); #else pixyInit(); #endif #if 0 i = 0; char *foo; while(1) { foo = new (std::nothrow) char[128]; if (foo==NULL) { _DBG("full\n"); break; } else { _DBH32((int)foo); _DBG(" "); _DBH32(i); _DBG("\n"); } i++; } while(1); #endif // main init of hardware plus a version-dependent number for the parameters that will // force a format of parameter between version numbers. #ifndef LEGO rcs_init(); #endif cc_init(g_chirpUsb); ser_init(); exec_init(g_chirpUsb); #if 0 exec_addProg(&g_progBlobs); ptLoadParams(); exec_addProg(&g_progPt); exec_addProg(&g_progVideo, true); #if 0 cam_setMode(CAM_MODE1); while(1) periodic(); #endif #endif #if 1 // load programs exec_addProg(&g_progBlobs); #ifndef LEGO // need to call this to get the pan/tilt parameters to display. // We can make some properties modal, meaning they are only diaplayed when the program is running. // We might want to do this here, but this is good for now. ptLoadParams(); exec_addProg(&g_progPt); #endif #if 0 chaseLoadParams(); exec_addProg(&g_progChase); #endif exec_addProg(&g_progVideo, true); #if 1 // this code formats if the version has changed for (i=0, count=0, count2=0; i<25; i++) { res = prm_get("fwver", &major, &minor, &build, END); if (res>=0 && major==FW_MAJOR_VER && minor==FW_MINOR_VER && build==FW_BUILD_VER) count++; res = prm_get("fwtype", &type, END); if (res>=0 && strcmp(type, FW_TYPE)==0) count2++; } if (count==0 || count2==0) prm_format(); #endif // check version prm_add("fwver", PRM_FLAG_INTERNAL, "", UINT16(FW_MAJOR_VER), UINT16(FW_MINOR_VER), UINT16(FW_BUILD_VER), END); prm_add("fwtype", PRM_FLAG_INTERNAL, "", STRING(FW_TYPE), END); exec_loop(); #endif #if 0 #define DELAY 1000000 rcs_setFreq(100); rcs_setLimits(0, -200, 200); rcs_setLimits(1, -200, 200); while(1) { rcs_setPos(0, 0); delayus(DELAY); rcs_setPos(0, 500); delayus(DELAY); rcs_setPos(0, 1000); delayus(DELAY); rcs_setPos(1, 0); delayus(DELAY); rcs_setPos(1, 500); delayus(DELAY); rcs_setPos(1, 1000); delayus(DELAY); } #endif #if 0 while(1) { g_chirpUsb->service(); handleButton(); } #endif }
int main() { dispatch_msg *msg; timing_init(); //Initiate the process grid pgrid_init(); while(1) { //Receive the dispatch message from the master-process dispatch_reset(); dispatch_recv(&msg); //Handle the message switch(msg->type) { case BH_CLUSTER_DISPATCH_INIT: { char *name = msg->payload; check_error(exec_init(name),__FILE__,__LINE__); break; } case BH_CLUSTER_DISPATCH_SHUTDOWN: { check_error(exec_shutdown(),__FILE__,__LINE__); return 0; } case BH_CLUSTER_DISPATCH_EXTMETHOD: { bh_opcode opcode = *((bh_opcode *)msg->payload); char *name = msg->payload+sizeof(bh_opcode); check_error(exec_extmethod(name, opcode),__FILE__,__LINE__); break; } case BH_CLUSTER_DISPATCH_EXEC: { //Get the size of the the serialized BhIR bh_intp bhir_size = *((bh_intp*) msg->payload); //Deserialize the BhIR bh_ir bhir = bh_ir(((char*)msg->payload)+sizeof(bh_intp), bhir_size); //The number of new arrays bh_intp *noa = (bh_intp *)(((char*)msg->payload)+sizeof(bh_intp)+bhir_size); //The list of new arrays dispatch_array *darys = (dispatch_array*)(noa+1); //number of new arrays //Insert the new array into the array store and the array maps std::stack<bh_base*> base_darys; for(bh_intp i=0; i < *noa; ++i) { bh_base *ary = dispatch_new_slave_array(&darys[i].ary, darys[i].id); base_darys.push(ary); } //Receive the dispatched array-data from the master-process dispatch_array_data(base_darys); //Update all instruction to reference local arrays for(uint64_t i=0; i < bhir.instr_list.size(); ++i) { bh_instruction *inst = &bhir.instr_list[i]; int nop = bh_noperands(inst->opcode); bh_view *ops = bh_inst_operands(inst); //Convert all instructon operands for(bh_intp j=0; j<nop; ++j) { if(bh_is_constant(&ops[j])) continue; bh_base *base = bh_base_array(&ops[j]); assert(dispatch_slave_exist((bh_intp)base)); bh_base_array(&ops[j]) = dispatch_master2slave((bh_intp)base); } } check_error(exec_execute(&bhir),__FILE__,__LINE__); break; } default: fprintf(stderr, "[VEM-CLUSTER] Slave (rank %d) " "received unknown message type\n", pgrid_myrank); MPI_Abort(MPI_COMM_WORLD,BH_ERROR); } } timing_finalize(); return BH_SUCCESS; }
/* * Main routine for exec service. */ int main(int argc, char *argv[]) { const struct msg_map *map; struct msg *msg; object_t obj; int error; sys_log("Starting exec server\n"); /* Boost thread priority. */ thread_setpri(thread_self(), PRI_EXEC); /* * Set capability for us */ bind_cap("/boot/exec", task_self()); /* * Setup exception handler. */ exception_setup(exception_handler); /* * Initialize exec loaders. */ exec_init(); /* * Create an object to expose our service. */ error = object_create("!exec", &obj); if (error) sys_panic("fail to create object"); msg = malloc(MAX_EXECMSG); ASSERT(msg); /* * Message loop */ for (;;) { /* * Wait for an incoming request. */ error = msg_receive(obj, msg, MAX_EXECMSG); if (error) continue; error = EINVAL; map = &execmsg_map[0]; while (map->code != 0) { if (map->code == msg->hdr.code) { error = (*map->func)(msg); break; } map++; } #ifdef DEBUG_EXEC if (error) DPRINTF(("exec: msg error=%d code=%x\n", error, msg->hdr.code)); #endif /* * Reply to the client. * * Note: If EXEC_EXECVE request is handled successfully, * the receiver task has been terminated here. But, we * have to call msg_reply() even in such case to reset * our IPC state. */ msg->hdr.status = error; error = msg_reply(obj, msg, MAX_EXECMSG); } }
/** The main entry point of GridLAB-D @returns Exit codes XC_SUCCESS, etc. (see gridlabd.h) **/ int main(int argc, /**< the number entries on command-line argument list \p argv */ char *argv[]) /**< a list of pointers to the command-line arguments */ { char *pd1, *pd2; int i, pos=0; char *browser = getenv("GLBROWSER"); /* set the default timezone */ timestamp_set_tz(NULL); exec_clock(); /* initialize the wall clock */ realtime_starttime(); /* mark start */ /* set the process info */ global_process_id = getpid(); /* specify the default browser */ if ( browser!= NULL ) strncpy(global_browser,browser,sizeof(global_browser)-1); #if defined WIN32 && _DEBUG atexit(pause_at_exit); #endif #ifdef WIN32 kill_starthandler(); atexit(kill_stophandler); #endif /* capture the execdir */ strcpy(global_execname,argv[0]); strcpy(global_execdir,argv[0]); pd1 = strrchr(global_execdir,'/'); pd2 = strrchr(global_execdir,'\\'); if (pd1>pd2) *pd1='\0'; else if (pd2>pd1) *pd2='\0'; /* determine current working directory */ getcwd(global_workdir,1024); /* capture the command line */ for (i=0; i<argc; i++) { if (pos < (int)(sizeof(global_command_line)-strlen(argv[i]))) pos += sprintf(global_command_line+pos,"%s%s",pos>0?" ":"",argv[i]); } /* main initialization */ if (!output_init(argc,argv) || !exec_init()) exit(XC_INIERR); /* set thread count equal to processor count if not passed on command-line */ if (global_threadcount == 0) global_threadcount = processor_count(); output_verbose("detected %d processor(s)", processor_count()); output_verbose("using %d helper thread(s)", global_threadcount); /* process command line arguments */ if (cmdarg_load(argc,argv)==FAILED) { output_fatal("shutdown after command line rejected"); /* TROUBLESHOOT The command line is not valid and the system did not complete its startup procedure. Correct the problem with the command line and try again. */ exit(XC_ARGERR); } /* stitch clock */ global_clock = global_starttime; /* initialize scheduler */ sched_init(0); /* recheck threadcount in case user set it 0 */ if (global_threadcount == 0) { global_threadcount = processor_count(); output_verbose("using %d helper thread(s)", global_threadcount); } /* see if newer version is available */ if ( global_check_version ) check_version(1); /* setup the random number generator */ random_init(); /* pidfile */ if (strcmp(global_pidfile,"")!=0) { FILE *fp = fopen(global_pidfile,"w"); if (fp==NULL) { output_fatal("unable to create pidfile '%s'", global_pidfile); /* TROUBLESHOOT The system must allow creation of the process id file at the location indicated in the message. Create and/or modify access rights to the path for that file and try again. */ exit(XC_PRCERR); } #ifdef WIN32 #define getpid _getpid #endif fprintf(fp,"%d\n",getpid()); output_verbose("process id %d written to %s", getpid(), global_pidfile); fclose(fp); atexit(delete_pidfile); } /* do legal stuff */ #ifdef LEGAL_NOTICE if (strcmp(global_pidfile,"")==0 && legal_notice()==FAILED) exit(XC_USRERR); #endif /* start the processing environment */ output_verbose("load time: %d sec", realtime_runtime()); output_verbose("starting up %s environment", global_environment); if (environment_start(argc,argv)==FAILED) { output_fatal("environment startup failed: %s", strerror(errno)); /* TROUBLESHOOT The requested environment could not be started. This usually follows a more specific message regarding the startup problem. Follow the recommendation for the indicated problem. */ if ( exec_getexitcode()==XC_SUCCESS ) exec_setexitcode(XC_ENVERR); } /* save the model */ if (strcmp(global_savefile,"")!=0) { if (saveall(global_savefile)==FAILED) output_error("save to '%s' failed", global_savefile); } /* do module dumps */ if (global_dumpall!=FALSE) { output_verbose("dumping module data"); module_dumpall(); } /* KML output */ if (strcmp(global_kmlfile,"")!=0) kml_dump(global_kmlfile); /* terminate */ module_termall(); /* wrap up */ output_verbose("shutdown complete"); /* profile results */ if (global_profiler) { class_profiles(); module_profiles(); } #ifdef DUMP_SCHEDULES /* dump a copy of the schedules for reference */ schedule_dumpall("schedules.txt"); #endif /* restore locale */ locale_pop(); /* if pause enabled */ #ifndef WIN32 if (global_pauseatexit) { output_verbose("pausing at exit"); while (true) { sleep(5); } } #endif /* compute elapsed runtime */ output_verbose("elapsed runtime %d seconds", realtime_runtime()); output_verbose("exit code %d", exec_getexitcode()); exit(exec_getexitcode()); }
int make( LIST * targets, int anyhow ) { COUNTS counts[ 1 ]; int status = 0; /* 1 if anything fails */ #ifdef OPT_HEADER_CACHE_EXT hcache_init(); #endif memset( (char *)counts, 0, sizeof( *counts ) ); /* Make sure that the tables are set up correctly. */ exec_init(); /* First bind all targets with LOCATE_TARGET setting. This is needed to * correctly handle dependencies to generated headers. */ bind_explicitly_located_targets(); { LISTITER iter, end; PROFILE_ENTER( MAKE_MAKE0 ); for ( iter = list_begin( targets ), end = list_end( targets ); iter != end; iter = list_next( iter ) ) { TARGET * t = bindtarget( list_item( iter ) ); if ( t->fate == T_FATE_INIT ) make0( t, 0, 0, counts, anyhow, 0 ); } PROFILE_EXIT( MAKE_MAKE0 ); } #ifdef OPT_GRAPH_DEBUG_EXT if ( DEBUG_GRAPH ) { LISTITER iter, end; for ( iter = list_begin( targets ), end = list_end( targets ); iter != end; iter = list_next( iter ) ) dependGraphOutput( bindtarget( list_item( iter ) ), 0 ); } #endif if ( DEBUG_MAKE ) { if ( counts->targets ) out_printf( "...found %d target%s...\n", counts->targets, counts->targets > 1 ? "s" : "" ); if ( counts->temp ) out_printf( "...using %d temp target%s...\n", counts->temp, counts->temp > 1 ? "s" : "" ); if ( counts->updating ) out_printf( "...updating %d target%s...\n", counts->updating, counts->updating > 1 ? "s" : "" ); if ( counts->cantfind ) out_printf( "...can't find %d target%s...\n", counts->cantfind, counts->cantfind > 1 ? "s" : "" ); if ( counts->cantmake ) out_printf( "...can't make %d target%s...\n", counts->cantmake, counts->cantmake > 1 ? "s" : "" ); } status = counts->cantfind || counts->cantmake; { PROFILE_ENTER( MAKE_MAKE1 ); status |= make1( targets ); PROFILE_EXIT( MAKE_MAKE1 ); } return status; }
int main (void) { exec_init(); exec_run(); return 0; }
int main(void) { //CTIMER_DECLARE(); #if 0 uint32_t memory = SRAM1_LOC; uint32_t lut = SRAM1_LOC; //while(1); memset((void *)QQ_LOC, 0x01, 0x3000); g_qqueue->writeIndex = 0; g_qqueue->produced = 0; g_qqueue->consumed = 0; while(1) getRLSFrame(&memory, &lut); #endif #if 0 int i = 0x12345678; foo(&i); printf("%d\n", i); while(1); #endif #if 0 int i; uint32_t lut = SRAM1_LOC; uint32_t memory = SRAM1_LOC+0x1000; uint8_t *plut = (uint8_t *)lut; for (i=0; i<0x4000; i++) plut[i] = i%5==0 ? 1 : 0; while(1) getRLSFrame(&memory, &lut); #endif #if 1 _DBG("M0 start\n"); chirpOpen(); exec_init(); frame_init(); rls_init(); #if 0 while(1) { if (g_foo) loop0(); } #endif #if 0 vsync(); #endif #if 0 //while(g_loop); uint8_t type = CAM_GRAB_M1R2; uint32_t memory = SRAM1_LOC; uint16_t offset = 0; uint16_t width = 320; uint16_t height = 200; while(1) { getFrame(&type, &memory, &offset, &offset, &width, &height); i++; if (i%50==0) { _DBD32(i), _CR(); } } #endif //printf("M0 ready\n"); exec_loop(); #endif #if 0 while(1) { CTIMER_START(); syncM1((uint32_t *)&LPC_GPIO_PORT->PIN[1], 0x2000); CTIMER_STOP(); printf("%d\n", CTIMER_GET()); } #endif #if 0 { uint32_t i; uint8_t *lut = (uint8_t *)SRAM1_LOC + 0x10000; uint32_t memory = SRAM1_LOC; uint32_t size = SRAM1_SIZE/2; for (i=0; i<0x10000; i++) lut[i] = 0; lut[0xb400] = 0; lut[0xb401] = 1; lut[0xb402] = 1; lut[0xb403] = 1; lut[0xb404] = 0; lut[0xb405] = 1; lut[0xb406] = 1; lut[0xb407] = 0; lut[0xb408] = 0; lut[0xb409] = 0; while(1) getRLSFrame(&memory, &size); //, (uint32_t *)&lut); } #endif return 0; }
int main(void) { //CTIMER_DECLARE(); #if 0 uint32_t memory = SRAM1_LOC; uint32_t lut = SRAM1_LOC; //while(1); memset((void *)QQ_LOC, 0x01, 0x3000); g_qqueue->writeIndex = 0; g_qqueue->produced = 0; g_qqueue->consumed = 0; while(1) getRLSFrame(&memory, &lut); #endif #if 0 int i = 0x12345678; foo(&i); printf("%d\n", i); while(1); #endif #if 0 int i; uint32_t lut = SRAM1_LOC; uint32_t memory = SRAM1_LOC+0x1000; uint8_t *plut = (uint8_t *)lut; for (i=0; i<0x4000; i++) plut[i] = i%5==0 ? 1 : 0; while(1) getRLSFrame(&memory, &lut); #endif #if 1 printf("M0 start\n"); chirpOpen(); exec_init(); frame_init(); rls_init(); //printf("M0 ready\n"); exec_loop(); #endif #if 0 while(1) { CTIMER_START(); syncM1((uint32_t *)&LPC_GPIO_PORT->PIN[1], 0x2000); CTIMER_STOP(); printf("%d\n", CTIMER_GET()); } #endif #if 0 { uint32_t i; uint8_t *lut = (uint8_t *)SRAM1_LOC + 0x10000; uint32_t memory = SRAM1_LOC; uint32_t size = SRAM1_SIZE/2; for (i=0; i<0x10000; i++) lut[i] = 0; lut[0xb400] = 0; lut[0xb401] = 1; lut[0xb402] = 1; lut[0xb403] = 1; lut[0xb404] = 0; lut[0xb405] = 1; lut[0xb406] = 1; lut[0xb407] = 0; lut[0xb408] = 0; lut[0xb409] = 0; while(1) getRLSFrame(&memory, &size); //, (uint32_t *)&lut); } #endif }
TMODENTRY TUINT tek_init_exec(struct TTask *task, struct TModule *mod, TUINT16 version, TTAGITEM *tags) { TEXECBASE *exec = (TEXECBASE *) mod; if (exec == TNULL) { if (version == 0xffff) return sizeof(TAPTR) * EXEC_NUMVECTORS; /* negative size */ if (version <= EXEC_VERSION) return sizeof(TEXECBASE); /* positive size */ return 0; } if (exec_init(exec, tags)) { exec->texb_Module.tmd_Handle.thn_Hook.thk_Entry = exec_dispatch; exec->texb_Module.tmd_Version = EXEC_VERSION; exec->texb_Module.tmd_Revision = EXEC_REVISION; exec->texb_Module.tmd_Flags = TMODF_VECTORTABLE; TInitVectors(&exec->texb_Module, exec_vectors, EXEC_NUMVECTORS); /* overwrite CopyMem and FillMem with HAL functions, for getting rid of one callframe: */ ((TMFPTR *) exec)[-14] = ((TMFPTR *) exec->texb_HALBase)[-13]; ((TMFPTR *) exec)[-15] = ((TMFPTR *) exec->texb_HALBase)[-14]; #if defined(ENABLE_EXEC_IFACE) /* initialize interface: */ exec->texb_Module.tmd_Flags |= TMODF_QUERYIFACE; TInitInterface(&exec->texb_Exec1IFace.IFace, (struct TModule *) exec, "exec", 1); exec->texb_Exec1IFace.GetHALBase = ((TAPTR *) exec)[-11]; exec->texb_Exec1IFace.OpenModule = ((TAPTR *) exec)[-12]; exec->texb_Exec1IFace.CloseModule = ((TAPTR *) exec)[-13]; exec->texb_Exec1IFace.CopyMem = ((TAPTR *) exec)[-14]; exec->texb_Exec1IFace.FillMem = ((TAPTR *) exec)[-15]; exec->texb_Exec1IFace.CreateMemManager = ((TAPTR *) exec)[-16]; exec->texb_Exec1IFace.Alloc = ((TAPTR *) exec)[-17]; exec->texb_Exec1IFace.Alloc0 = ((TAPTR *) exec)[-18]; exec->texb_Exec1IFace.QueryInterface = ((TAPTR *) exec)[-19]; exec->texb_Exec1IFace.Free = ((TAPTR *) exec)[-20]; exec->texb_Exec1IFace.Realloc = ((TAPTR *) exec)[-21]; exec->texb_Exec1IFace.GetMemManager = ((TAPTR *) exec)[-22]; exec->texb_Exec1IFace.GetSize = ((TAPTR *) exec)[-23]; exec->texb_Exec1IFace.CreateLock = ((TAPTR *) exec)[-24]; exec->texb_Exec1IFace.Lock = ((TAPTR *) exec)[-25]; exec->texb_Exec1IFace.Unlock = ((TAPTR *) exec)[-26]; exec->texb_Exec1IFace.AllocSignal = ((TAPTR *) exec)[-27]; exec->texb_Exec1IFace.FreeSignal = ((TAPTR *) exec)[-28]; exec->texb_Exec1IFace.Signal = ((TAPTR *) exec)[-29]; exec->texb_Exec1IFace.SetSignal = ((TAPTR *) exec)[-30]; exec->texb_Exec1IFace.Wait = ((TAPTR *) exec)[-31]; exec->texb_Exec1IFace.StrEqual = ((TAPTR *) exec)[-32]; exec->texb_Exec1IFace.CreatePort = ((TAPTR *) exec)[-33]; exec->texb_Exec1IFace.PutMsg = ((TAPTR *) exec)[-34]; exec->texb_Exec1IFace.GetMsg = ((TAPTR *) exec)[-35]; exec->texb_Exec1IFace.AckMsg = ((TAPTR *) exec)[-36]; exec->texb_Exec1IFace.ReplyMsg = ((TAPTR *) exec)[-37]; exec->texb_Exec1IFace.DropMsg = ((TAPTR *) exec)[-38]; exec->texb_Exec1IFace.SendMsg = ((TAPTR *) exec)[-39]; exec->texb_Exec1IFace.WaitPort = ((TAPTR *) exec)[-40]; exec->texb_Exec1IFace.GetPortSignal = ((TAPTR *) exec)[-41]; exec->texb_Exec1IFace.GetUserPort = ((TAPTR *) exec)[-42]; exec->texb_Exec1IFace.GetSyncPort = ((TAPTR *) exec)[-43]; exec->texb_Exec1IFace.CreateTask = ((TAPTR *) exec)[-44]; exec->texb_Exec1IFace.FindTask = ((TAPTR *) exec)[-45]; exec->texb_Exec1IFace.GetTaskData = ((TAPTR *) exec)[-46]; exec->texb_Exec1IFace.SetTaskData = ((TAPTR *) exec)[-47]; exec->texb_Exec1IFace.GetTaskMemManager = ((TAPTR *) exec)[-48]; exec->texb_Exec1IFace.AllocMsg = ((TAPTR *) exec)[-49]; exec->texb_Exec1IFace.AllocMsg0 = ((TAPTR *) exec)[-50]; exec->texb_Exec1IFace.LockAtom = ((TAPTR *) exec)[-51]; exec->texb_Exec1IFace.UnlockAtom = ((TAPTR *) exec)[-52]; exec->texb_Exec1IFace.GetAtomData = ((TAPTR *) exec)[-53]; exec->texb_Exec1IFace.SetAtomData = ((TAPTR *) exec)[-54]; exec->texb_Exec1IFace.CreatePool = ((TAPTR *) exec)[-55]; exec->texb_Exec1IFace.AllocPool = ((TAPTR *) exec)[-56]; exec->texb_Exec1IFace.FreePool = ((TAPTR *) exec)[-57]; exec->texb_Exec1IFace.ReallocPool = ((TAPTR *) exec)[-58]; exec->texb_Exec1IFace.PutIO = ((TAPTR *) exec)[-59]; exec->texb_Exec1IFace.WaitIO = ((TAPTR *) exec)[-60]; exec->texb_Exec1IFace.DoIO = ((TAPTR *) exec)[-61]; exec->texb_Exec1IFace.CheckIO = ((TAPTR *) exec)[-62]; exec->texb_Exec1IFace.AbortIO = ((TAPTR *) exec)[-63]; exec->texb_Exec1IFace.AddModules = ((TAPTR *) exec)[-69]; exec->texb_Exec1IFace.RemModules = ((TAPTR *) exec)[-70]; exec->texb_Exec1IFace.AllocTimeRequest = ((TAPTR *) exec)[-71]; exec->texb_Exec1IFace.FreeTimeRequest = ((TAPTR *) exec)[-72]; exec->texb_Exec1IFace.GetSystemTime = ((TAPTR *) exec)[-73]; exec->texb_Exec1IFace.GetUniversalDate = ((TAPTR *) exec)[-74]; exec->texb_Exec1IFace.GetLocalDate = ((TAPTR *) exec)[-75]; exec->texb_Exec1IFace.WaitTime = ((TAPTR *) exec)[-76]; exec->texb_Exec1IFace.WaitDate = ((TAPTR *) exec)[-77]; #endif return TTRUE; } return 0; }
int main (int argc, char* argv[]) { MPI_Init(&argc, &argv); const int nMPI = 2; int rank, size; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); if (size > nMPI) { std::cout << "This test is only executable with at most 2 processes. Exiting." << std::endl; MPI_Finalize(); return 0; } std::cout << "MPI Rank " << rank << ": loading mesh..." << std::endl; ExampleMeshMPI* mesh = example_mpi_mesh(RECT, rank); std::cout << "MPI Rank " << rank << ": loaded!" << std::endl; /* * Sample program structure: * - loop over cells (PL0): * incr indirectly vertices (+=1) * - loop over vertices (PL1): * pow to 2 * - loop over cells (PL2): * incr indirectly vertices (+=1) * - loop over vertices (PL3): * pow to 2 */ // sets set_t* vertices = set("vertices", mesh->vertices, mesh->vertices_halo, 0); set_t* cells = set("cells", mesh->cells, mesh->cells_halo, 0); // maps map_t* c2vMap = map("c2v", cells, vertices, mesh->c2v, mesh->c2vSize); // descriptors desc_list pl0Desc ({desc(c2vMap, INC)}); desc_list pl1Desc ({desc(DIRECT, READ), desc(DIRECT, WRITE)}); desc_list pl2Desc ({desc(c2vMap, INC)}); desc_list pl3Desc ({desc(DIRECT, READ), desc(DIRECT, WRITE)}); // inspector const int tileSize = 3; inspector_t* insp = insp_init(tileSize, ONLY_MPI); insp_add_parloop (insp, "pl0", cells, &pl0Desc); insp_add_parloop (insp, "pl1", vertices, &pl1Desc); insp_add_parloop (insp, "pl2", cells, &pl2Desc); insp_add_parloop (insp, "pl3", vertices, &pl3Desc); const int seed = 0; insp_run (insp, seed); for (int i = 0; i < nMPI; i++) { if (i == rank) { insp_print (insp, HIGH); generate_vtk (insp, HIGH, vertices, mesh->coords, DIM2, rank); } MPI_Barrier(MPI_COMM_WORLD); } // executor executor_t* exec = exec_init (insp); // free memory insp_free (insp); exec_free (exec); delete mesh; MPI_Finalize(); return 0; }
int main(void) { // pixyInit(SRAM3_LOC, &LR0[0], sizeof(LR0)); #if 0 pixyInit(); cc_init(g_chirpUsb); ser_init(); exec_init(g_chirpUsb); #endif #if 1 /* test loop */ pixyInit(); exec_init(g_chirpUsb); #if 0 int i = 0; cam_setMode(1); while(1) { //uint8_t reg = cam_getRegister(0x0a); g_chirpUsb->service(); cprintf("hello world %d\n", i++); } #endif #if 0 while(1) { uint8_t *frame = (uint8_t *)SRAM1_LOC; int res; res = cam_getFrame(frame, SRAM1_SIZE, CAM_GRAB_M1R2, 0, 0, CAM_RES2_WIDTH, CAM_RES2_HEIGHT); i++; if (i%50==0) { lpc_printf("%d\n", i); } } #endif #endif #if 1 exec_addProg(&g_progBlobs); ptLoadParams(); exec_addProg(&g_progPt); exec_addProg(&g_progVideo, true); exec_loop(); #endif #if 0 //prm_format(); ColorModel model, *model2; uint32_t len; model.m_hue[0].m_slope = 1.0; model.m_hue[0].m_yi = 2.0; model.m_hue[1].m_slope = 3.0; model.m_hue[1].m_yi = 4.0; model.m_sat[0].m_slope = 5.0; model.m_sat[0].m_yi = 6.0; model.m_sat[1].m_slope = 7.0; model.m_sat[1].m_yi = 8.0; prm_add("signature1", "Color signature 1", INTS8(sizeof(ColorModel), &model), END); prm_set("signature1", INTS8(sizeof(ColorModel), &model), END); model.m_hue[0].m_slope = 9.0; model.m_hue[0].m_yi = 10.0; model.m_hue[1].m_slope = 11.0; model.m_hue[1].m_yi = 12.0; model.m_sat[0].m_slope = 13.0; model.m_sat[0].m_yi = 14.0; model.m_sat[1].m_slope = 15.0; model.m_sat[1].m_yi = 16.0; prm_add("signature2", "Color signature 2", INTS8(sizeof(ColorModel), &model), END); prm_set("signature2", INTS8(sizeof(ColorModel), &model), END); prm_get("signature1", &len, &model2, END); model.m_hue[0].m_slope = 17.0; model.m_hue[0].m_yi = 18.0; model.m_hue[1].m_slope = 19.0; model.m_hue[1].m_yi = 20.0; model.m_sat[0].m_slope = 21.0; model.m_sat[0].m_yi = 22.0; model.m_sat[1].m_slope = 23.0; model.m_sat[1].m_yi = 24.0; prm_get("signature1", &len, &model2, END); prm_set("signature1", INTS8(sizeof(ColorModel), &model), END); prm_get("signature1", &len, &model2, END); prm_get("signature2", &len, &model2, END); #endif #if 0 #define DELAY 1000000 rcs_setFreq(100); rcs_setLimits(0, -200, 200); rcs_setLimits(1, -200, 200); while(1) { rcs_setPos(0, 0); delayus(DELAY); rcs_setPos(0, 500); delayus(DELAY); rcs_setPos(0, 1000); delayus(DELAY); rcs_setPos(1, 0); delayus(DELAY); rcs_setPos(1, 500); delayus(DELAY); rcs_setPos(1, 1000); delayus(DELAY); } #endif #if 0 while(1) { g_chirpUsb->service(); handleButton(); } #endif }
/* * Called by proc_exit() when a zone's init exits, presumably because * it failed. As long as the given zone is still in the "running" * state, we will re-exec() init, but first we need to reset things * which are usually inherited across exec() but will break init's * assumption that it is being exec()'d from a virgin process. Most * importantly this includes closing all file descriptors (exec only * closes those marked close-on-exec) and resetting signals (exec only * resets handled signals, and we need to clear any signals which * killed init). Anything else that exec(2) says would be inherited, * but would affect the execution of init, needs to be reset. */ static int restart_init(int what, int why) { kthread_t *t = curthread; klwp_t *lwp = ttolwp(t); proc_t *p = ttoproc(t); user_t *up = PTOU(p); vnode_t *oldcd, *oldrd; int i, err; char reason_buf[64]; /* * Let zone admin (and global zone admin if this is for a non-global * zone) know that init has failed and will be restarted. */ zcmn_err(p->p_zone->zone_id, CE_WARN, "init(1M) %s: restarting automatically", exit_reason(reason_buf, sizeof (reason_buf), what, why)); if (!INGLOBALZONE(p)) { cmn_err(CE_WARN, "init(1M) for zone %s (pid %d) %s: " "restarting automatically", p->p_zone->zone_name, p->p_pid, reason_buf); } /* * Remove any fpollinfo_t's for this (last) thread from our file * descriptors so closeall() can ASSERT() that they're all gone. * Then close all open file descriptors in the process. */ pollcleanup(); closeall(P_FINFO(p)); /* * Grab p_lock and begin clearing miscellaneous global process * state that needs to be reset before we exec the new init(1M). */ mutex_enter(&p->p_lock); prbarrier(p); p->p_flag &= ~(SKILLED | SEXTKILLED | SEXITING | SDOCORE); up->u_cmask = CMASK; sigemptyset(&t->t_hold); sigemptyset(&t->t_sig); sigemptyset(&t->t_extsig); sigemptyset(&p->p_sig); sigemptyset(&p->p_extsig); sigdelq(p, t, 0); sigdelq(p, NULL, 0); if (p->p_killsqp) { siginfofree(p->p_killsqp); p->p_killsqp = NULL; } /* * Reset any signals that are ignored back to the default disposition. * Other u_signal members will be cleared when exec calls sigdefault(). */ for (i = 1; i < NSIG; i++) { if (up->u_signal[i - 1] == SIG_IGN) { up->u_signal[i - 1] = SIG_DFL; sigemptyset(&up->u_sigmask[i - 1]); } } /* * Clear the current signal, any signal info associated with it, and * any signal information from contracts and/or contract templates. */ lwp->lwp_cursig = 0; lwp->lwp_extsig = 0; if (lwp->lwp_curinfo != NULL) { siginfofree(lwp->lwp_curinfo); lwp->lwp_curinfo = NULL; } lwp_ctmpl_clear(lwp); /* * Reset both the process root directory and the current working * directory to the root of the zone just as we do during boot. */ VN_HOLD(p->p_zone->zone_rootvp); oldrd = up->u_rdir; up->u_rdir = p->p_zone->zone_rootvp; VN_HOLD(p->p_zone->zone_rootvp); oldcd = up->u_cdir; up->u_cdir = p->p_zone->zone_rootvp; if (up->u_cwd != NULL) { refstr_rele(up->u_cwd); up->u_cwd = NULL; } mutex_exit(&p->p_lock); if (oldrd != NULL) VN_RELE(oldrd); if (oldcd != NULL) VN_RELE(oldcd); /* Free the controlling tty. (freectty() always assumes curproc.) */ ASSERT(p == curproc); (void) freectty(B_TRUE); /* * Now exec() the new init(1M) on top of the current process. If we * succeed, the caller will treat this like a successful system call. * If we fail, we issue messages and the caller will proceed with exit. */ err = exec_init(p->p_zone->zone_initname, NULL); if (err == 0) return (0); zcmn_err(p->p_zone->zone_id, CE_WARN, "failed to restart init(1M) (err=%d): system reboot required", err); if (!INGLOBALZONE(p)) { cmn_err(CE_WARN, "failed to restart init(1M) for zone %s " "(pid %d, err=%d): zoneadm(1M) boot required", p->p_zone->zone_name, p->p_pid, err); } return (-1); }
/** The main entry point of GridLAB-D Exit codes - \b 0 run completed ok - \b 1 command-line processor stopped - \b 2 environment startup failed - \b 3 test procedure failed - \b 4 user rejects conditions of use - \b 5 simulation stopped before completing - \b 6 initialization failed **/ int main(int argc, /**< the number entries on command-line argument list \p argv */ char *argv[]) /**< a list of pointers to the command-line arguments */ { int rv = 0; time_t t_load = time(NULL); global_process_id = getpid(); #if defined WIN32 && _DEBUG atexit(pause_at_exit); #endif /* main initialization */ if (!output_init(argc,argv) || !exec_init()) exit(6); /* process command line arguments */ if (cmdarg_load(argc,argv)==FAILED) { output_fatal("shutdown after command line rejected"); /* TROUBLESHOOT The command line is not valid and the system did not complete its startup procedure. Correct the problem with the command line and try again. */ exit(1); } /* setup the random number generator */ random_init(); /* pidfile */ if (strcmp(global_pidfile,"")!=0) { FILE *fp = fopen(global_pidfile,"w"); if (fp==NULL) { output_fatal("unable to create pidfile '%s'", global_pidfile); /* TROUBLESHOOT The system must allow creation of the process id file at the location indicated in the message. Create and/or modify access rights to the path for that file and try again. */ exit(1); } #ifdef WIN32 #define getpid _getpid #endif fprintf(fp,"%d\n",getpid()); output_verbose("process id %d written to %s", getpid(), global_pidfile); fclose(fp); atexit(delete_pidfile); } /* do legal stuff */ #ifdef LEGAL_NOTICE if (strcmp(global_pidfile,"")==0 && legal_notice()==FAILED) exit(4); #endif /* set up the test */ if (global_test_mode) { #ifndef _NO_CPPUNIT output_message("Entering test mode"); if (test_start(argc,argv)==FAILED) { output_fatal("shutdown after startup test failed"); /* TROUBLESHOOT A self-test procedure failed and the system stopped. Check the output of the test stream and correct the indicated problem. If the test stream is not redirected so as to save the output, try using the <b>--redirect</b> command line option. */ exit(3); } exit(0); /* There is no environment to speak of, so exit. */ #else output_message("Unit Tests not enabled. Recompile with _NO_CPPUNIT unset"); #endif } /* start the processing environment */ output_verbose("load time: %d sec", time(NULL) - t_load); output_verbose("starting up %s environment", global_environment); if (environment_start(argc,argv)==FAILED) { output_fatal("environment startup failed: %s", strerror(errno)); /* TROUBLESHOOT The requested environment could not be started. This usually follows a more specific message regarding the startup problem. Follow the recommendation for the indicated problem. */ rv = 2; } /* post process the test */ if (global_test_mode) { #ifndef _NO_CPPUNIT output_message("Exiting test mode"); if (test_end(argc,argv)==FAILED) { output_error("shutdown after end test failed"); exit(3); } #endif } /* save the model */ if (strcmp(global_savefile,"")!=0) { if (saveall(global_savefile)==FAILED) output_error("save to '%s' failed", global_savefile); } /* do module dumps */ if (global_dumpall!=FALSE) { output_verbose("dumping module data"); module_dumpall(); } /* KML output */ if (strcmp(global_kmlfile,"")!=0) kml_dump(global_kmlfile); /* wrap up */ output_verbose("shutdown complete"); /* profile results */ if (global_profiler) class_profiles(); /* restore locale */ locale_pop(); /* compute elapsed runtime */ output_verbose("elapsed runtime %d seconds", realtime_runtime()); exit(rv); }
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { static first = 1; char key[MAXNAME]; int i; if (first==1) { first = 0; /* prevent Matlab from clearing GridLAB */ mexLock(); /* register Matlab output routines */ output_set_stdout(mexPrintf); output_set_stderr(cmex_printerr); /* display legal stuff */ legal_license(); /* initialize GridLAB */ exec_init(); } /* check number of input arguments */ if (nrhs<1) { output_error("Use gl('help') for a list of commands."); return; } /* check type of first argument */ if (!mxIsChar(prhs[0])) { output_error("token must be a string"); return; } /* read first argument */ if (mxGetString(prhs[0],key,sizeof(key))!=0) output_warning("GridLAB key string too long"); /* scan command map to find call function */ for (i=0; i<sizeof(cmdMap)/sizeof(cmdMap[0]); i++) { if (strcmp(key,cmdMap[i].name)==0) { if (cmdMap[i].call == NULL) /* help request */ { int j; if (nrhs==1) { output_raw("Available top-level commands\n"); for (j=0; j<sizeof(cmdMap)/sizeof(cmdMap[0]); j++) output_raw("\t%s\t%s\n", cmdMap[j].name, cmdMap[j].brief); output_raw("Use gl('help',command) for details\n"); return; } else if (mxIsChar(prhs[1])) { char cmd[MAXNAME]; if (mxGetString(prhs[1],cmd,sizeof(cmd))!=0) output_warning("command string too long to read fully"); for (j=0; j<sizeof(cmdMap)/sizeof(cmdMap[0]); j++) { if (strcmp(cmd,cmdMap[j].name)==0) { output_raw("Help for command '%s'\n\n%s\n", cmd, cmdMap[j].detail ? cmdMap[j].detail : "\tNo details available\n"); return; } } output_error("Command '%s' does not exist", cmd); return; } else { output_error("command must be a string"); return; } } else { (cmdMap[i].call)(nlhs,plhs,nrhs-1,prhs+1); return; } } } /* function not found */ { int nret = nlhs; output_error("unrecognized GridLAB operation--gl('help') for list"); while (nret-->0) plhs[nret] = mxCreateDoubleMatrix(0,0,mxREAL); } return; }