int register_output_module(char *path) { void *dl, *dlsym_addr; int (*mod_init)(void); if (nr_outputs == MAXOUTS) return -1; dl = dlopen(path, RTLD_NOW|RTLD_LOCAL); if (!dl) return -1; dlsym_addr = dlsym(dl, "netconsd_output_handler"); if (!dlsym_addr) goto err_close; mod_init = dlsym(dl, "netconsd_output_init"); if (mod_init && mod_init()) goto err_close; output_dlhandles[nr_outputs] = dl; outputs[nr_outputs] = dlsym_addr; nr_outputs++; return 0; err_close: dlclose(dl); return -1; }
/*---------------------------------------------------------------------------*/ void bsp_post_init (void) { volatile u32 *vec_loc ; /* The irq vector (loc 0x8018) and the fiq vector (0x801c) got */ /* wiped out by the function cpu_int_init(). Therefore, replace */ /* them. These values originally came from the linker when file */ /* boot.s was compiled. For some other reason, these values has */ /* to be written to 0x18 and 0x1c instead of 0x8018 and 0x801c. */ vec_loc = (volatile u32 *) 0x18 ; *vec_loc = 0xe59ff018 ; vec_loc = (volatile u32 *) 0x1c ; *vec_loc = 0xe59ff018 ; /* Initialize the devices */ if (dev_init() != GOOD) printf ("ERR: dev_init() failed !!!\n") ; /* Initialize the modules */ mod_init () ; /* Module Links */ os_link (&stdio_link, &uart_link, &uart_link) ; } /* End of function bsp_post_init () */
/*************************************************************************** ************************ ENTRYPOINT AND MAIN LOOP ************************* **************************************************************************/ int main(void) { // Init MCU init_application(); #ifdef CONFIG_TEST // Branch to welcome screen test_mode(); #else /* clear whole scren */ display_clear(0, 0); #endif /* Init modules */ mod_init(); /* main loop */ while (1) { /* Go to LPM3, wait for interrupts */ _BIS_SR(LPM3_bits + GIE); __no_operation(); /* service watchdog on wakeup */ #ifdef USE_WATCHDOG // Service watchdog (reset counter) WDTCTL = (WDTCTL & 0xff) | WDTPW | WDTCNTCL; #endif /* check if any driver has events pending */ check_events(); /* check for button presses, drive the menu */ check_buttons(); } }
/*---------------------------------------------------------------------------*/ void bsp_post_init (void) { /***********************/ /* Initialize all Apps */ /***********************/ if (B8000_init () != GOOD) printf ("ERR: B8000_init() Failed !!!\n") ; /* Initialize the configured modules */ mod_init() ; /**************************/ /* Initialize all Devices */ /**************************/ dev_init() ; /* Link all the Stackable Applications. This can happen only */ /* after the Applications and the Devices are initialized. */ #if 1 /* To interact via the serial port, change this to a 0 */ os_link (&stdio_link, &kbd_link, &b8000_link) ; #else os_link (&stdio_link, &ns16550_link, &ns16550_link) ; #endif /* Put User Application Entry Function here */ /* Enable the PIC so interrupts can get to the processor */ enablePcInts () ; return ; } /* End of function bsp_post_init () */
PyMODINIT_FUNC MODINIT3(void) { PyObject *m; m = PyModule_Create(&modInfo); if (!m) return NULL; return mod_init(m); }
PyMODINIT_FUNC MODINIT2(void) { PyObject *m; m = Py_InitModule(SPONGE_MODULE, NULL); if (m == NULL) return; PyModule_AddStringConstant(m, "__doc__", mod_doc); mod_init(m); }
static int module_add(irc_connection *con, config_group *group, const char *module_file) { init_module_func mod_generic_init; module_message_handler mod_msg_handler; module_init mod_init; module_close mod_close; if (module_by_name(con, Module_name(module_file), NULL)) return -9; void* module_libfile = dlopen(module_file, RTLD_NOW | RTLD_LOCAL); if (!module_libfile) { Printerr("dlopen: %s\n", dlerror()); return -1; } module_message_handler module_msg_handler = dlsym(module_libfile, "module_message_handler"); if (!module_msg_handler) return -2; LINK_FUNC(mod_generic_init, "init_module_generic", -3); mod_generic_init(irc_send_raw_msg, config_get_value, group); LINK_FUNC(mod_init, "module_init", -4); LINK_FUNC(mod_msg_handler, "module_message_handler", -5); LINK_FUNC(mod_close, "module_close", -6); if (mod_init(con)) return -7; module_listitem *p = malloc(sizeof(module_listitem)); if (!p) return -8; /* Ok, everything seems to be fine. So we can finally populate the * module structure's pointers and add it to the list of * loaded modules! */ p->name = Module_name(module_file); p->next = NULL; p->libhandle = module_libfile; p->init = mod_init; p->handle_msg = module_msg_handler; p->close = mod_close; module_listitem *l = con->modules; if (l) { while (l->next) l = l->next; l->next = p; } else con->modules = p; con->module_count++; return 0; }
int main(int ac, char** av) { file_context_t fc = FILE_STATIC_INITIALIZER; pcm_buf_t* pcm_buf = NULL; mod_context_t mc; if (file_open(&fc, ac > 1 ? av[1] : "../data/alban.mod") == -1) { printf("failed opening file\n"); goto on_error; } if (mod_init(&mc, file_get_data(&fc), file_get_size(&fc)) == -1) { printf("failed mod_init\n"); goto on_error; } pcm_alloc_buf(&pcm_buf, 48000); { FILE *f=fopen("output.raw","wb"); unsigned int i; for (i = 0; i < 100; ++i) { mod_fetch(&mc, pcm_get_buf_data(pcm_buf), pcm_get_buf_count(pcm_buf)); #if 0 write(1, pcm_get_buf_data(pcm_buf), pcm_get_buf_size(pcm_buf)); #else fwrite(pcm_get_buf_data(pcm_buf),1,pcm_get_buf_size(pcm_buf),f); #endif } fclose(f); } on_error: if (pcm_buf != NULL) pcm_free_buf(pcm_buf); file_close(&fc); return 0; }
void music_start() { int size; int r; cffat_init(); cffat_load("3.MOD", modfile, sizeof(modfile), &size); cffat_done(); r = mod_init(&mod_context, modfile, size); mod_fetch(&mod_context, sndbuf1, NSAMPLES); mod_fetch(&mod_context, sndbuf2, NSAMPLES); mod_fetch(&mod_context, sndbuf3, NSAMPLES); snd_play_refill(sndbuf1); snd_play_refill(sndbuf2); snd_play_refill(sndbuf3); snd_play_start(callback, NSAMPLES, NULL); }
int kern_init(void) { extern char edata[], end[]; memset(edata, 0, end - edata); cons_init(); // init the console const char *message = "(THU.CST) os is loading ..."; kprintf("%s\n\n", message); print_kerninfo(); /* Only to initialize lcpu_count. */ mp_init(); debug_init(); // init debug registers pmm_init(); // init physical memory management pmm_init_ap(); pic_init(); // init interrupt controller idt_init(); // init interrupt descriptor table vmm_init(); // init virtual memory management sched_init(); // init scheduler proc_init(); // init process table sync_init(); // init sync struct ide_init(); // init ide devices #ifdef UCONFIG_SWAP swap_init(); // init swap #endif fs_init(); // init fs clock_init(); // init clock interrupt mod_init(); intr_enable(); // enable irq interrupt /* do nothing */ cpu_idle(); // run idle process }
// Call up each module in the map and execute its initializer. void init_modules( ) { map < string, void *>::iterator mod; const char *error; while( mod != module.end( ) ) { typedef void INIT( ); INIT *mod_init; mod_init = ( INIT * ) dlsym( mod->second, "module_init" ); if( ( error = dlerror( ) ) ) { log_printf( "Module entry failure: %s", error ); continue; } // If this works, it should have fired off something. mod_init( ); } }
int main(){ DDRB |= 1<<PB4; // ------------------ Modem Send Test ----------------------- mod_init(); char c; softuart_init(); softuart_rx(); DDRB |= 1<<PB1; while(1){ /* if (softuart_kbhit()){ */ /* c = softuart_getchar(); */ /* PORTB ^= 1<<PB4; */ /* modem_put(c); */ /* } */ _delay_ms(100); PORTB ^= 1<<PB1; /* modem_put(0b11110000); */ /* modem_put(0b11110000); */ /* modem_put(0b11110000); */ /* modem_put(0b11110000); */ } // ------------------ Modem Receive and UART Send Test ----------------------- /* demod_init(); */ /* softuart_init(); */ /* softuart_tx(); */ /* char c; */ /* while(1){ */ /* if (modem_available()){ */ /* PORTB ^= 1<<PB4; */ /* c = modem_get(); */ /* softuart_putchar(c); */ /* } */ /* } */ }
/* * Do any per-module initialization that is separate to each * configured instance of the module. e.g. set up connections * to external databases, read configuration files, set up * dictionary entries, etc. * * If configuration information is given in the config section * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. * */ static int mod_instantiate(UNUSED CONF_SECTION *conf, void *instance) { rlm_python_t *inst = instance; if (mod_init(inst) != 0) { return -1; } #define A(x) if (mod_load_function(&inst->x) < 0) goto failed A(instantiate); A(authenticate); A(authorize); A(preacct); A(accounting); A(checksimul); A(pre_proxy); A(post_proxy); A(post_auth); #ifdef WITH_COA A(recv_coa); A(send_coa); #endif A(detach); #undef A /* * Call the instantiate function. No request. Use the * return value. */ return do_python(inst, NULL, inst->instantiate.function, "instantiate", false); failed: Pyx_BLOCK_THREADS mod_error(); Pyx_UNBLOCK_THREADS mod_instance_clear(inst); return -1; }
/** * @brief Initializes all the subsystems. */ static void init (void) { /* Disable some subsystems. */ PRR = _BV(PRTWI) | /* Disable the TWI. */ _BV(PRTIM2) | /* Disable the Timer 2. */ _BV(PRTIM0) | /* Disable the Timer 0. */ _BV(PRUSART1) | /* Disable the USART 1. */ _BV(PRTIM1) | /* Disable the Timer 1. */ _BV(PRSPI) | /* Disable the SPI. */ _BV(PRUSART0) | /* Disable the USART 0. */ _BV(PRADC); /* Disable ADC. */ /* Initialize the LED. */ LED0_INIT(); /* * Initialize subsystems. */ mod_init(); /* Modules. */ adc_init(); /* ADC. */ pwm_init(); /* PWM IO. */ comm_init(); /* Communication with UART0. */ event_init(); /* Events. */ /* * Optional subsystems. */ timer_init(); /* Timer infrastructure on TIMER0. */ /*servo_init();*/ /* Servo motors on TIMER1. */ /* Set sleep mode. */ set_sleep_mode( SLEEP_MODE_IDLE ); /* Enable interrupts. */ sei(); }
int main(int argc, char *argv[]) { opt_t opt; int retval = 0; const char *m; /* * Initialize. */ err_init(xbasename(argv[0])); /* init err package */ /* * If running setuid, fork a child to handle * all privileged operations and drop privs in this process. */ privsep_init(); /* * Seed options with default values: */ opt_default(&opt, argv[0]); /* * Override defaults with environment */ opt_env(&opt); /* * Process any options that need to be handled early: */ opt_args_early(&opt, argc, argv); /* * Load static or dynamic pdsh modules */ mod_init(); /* * Allow module directory to be overridden, but not when * running as root or setuid. (This is mainly for testing...) */ if (!(m = getenv ("PDSH_MODULE_DIR")) || getuid() == 0 || getuid() != geteuid()) m = pdsh_module_dir; if (mod_load_modules(m, &opt) < 0) errx("%p: Couldn't load any pdsh modules\n"); /* * Handle options. */ opt_args(&opt, argc, argv); /* override with command line */ if (opt_verify(&opt)) { /* verify options, print errors */ /* * Do the work. */ if (opt.info_only) /* display info only */ opt_list(&opt); else if (pdsh_personality() == PCP && opt.pcp_server) retval = (_pcp_remote_server (&opt) < 0); else if (pdsh_personality() == PCP && opt.pcp_client) retval = (_pcp_remote_client (&opt) < 0); else if (pdsh_personality() == PCP || opt.cmd != NULL) retval = dsh(&opt); /* single dsh/pcp command */ else /* prompt loop */ _interactive_dsh(&opt); } else { retval = 1; } mod_exit(); /* * Clean up. */ privsep_fini(); opt_free(&opt); /* free heap storage in opt struct */ err_cleanup(); return retval; }
int main(int argc, char **argv) { char config_file[PATH_MAX+1]; /* Parse command line arguments. */ { int ch, dflag = 0; opterr = 0; while((ch = getopt(argc, argv, "dvc:")) != -1) { switch(ch) { case 'd': dflag = 1; break; case 'v': if(++vlevel > 3) vlevel = 3; break; case 'c': strncpy(config_file, optarg, PATH_MAX); break; case '?': default: usage(argv[0]); exit(1); break; } } if(dflag == 1) daemonize(); } /* Determine what configuration file to use. */ if(strlen(config_file) > 0) { if(access(config_file, F_OK|R_OK) != 0) { switch(errno) { case ENOENT: if(vlevel > 0) fprintf(stderr, "[INFO] Can't find configuration file (%s).\n", config_file); break; case EACCES: if(vlevel > 0) fprintf(stderr, "[INFO] Can't access the file (%s).\n", config_file); break; } exit(1); } } else { char *homedir = getenv("HOME"); snprintf(config_file, PATH_MAX, "%s/%s", homedir, CONFIG_FILENAME); if(access(config_file, F_OK|R_OK) != 0) { switch(errno) { case ENOENT: if(vlevel > 0) fprintf(stderr, "[INFO] Can't find configuration file (%s).\n", config_file); break; case EACCES: if(vlevel > 0) fprintf(stderr, "[INFO] Can't access the file (%s).\n", config_file); break; } if(vlevel > 0) fprintf(stderr, "[INFO] Attempting to use default configuration in %s.\n", CONFIG_DEFAULT_PATH); if(access(CONFIG_DEFAULT_PATH, F_OK|R_OK) != 0) { fprintf(stderr, "No configuration file was found.\n"); exit(1); } strncpy(config_file, CONFIG_DEFAULT_PATH, PATH_MAX); } } /* Initialize our module system just before we read our configs. */ mod_init(); /* Get bot configurations and place in bots. */ bots = calloc(1, sizeof(*bots)); if(bots == NULL) return -1; read_config(config_file); #ifdef OPENSSL_ENABLED /* If compiled with OpenSSL support, setup thread locking callbacks and locks. */ ssl_init(); #endif /* OPENSSL_ENABLED */ /* Initialize our regular expressions. */ regex_init(); /* XXX Remove this for release. */ //mod_load("libmod_urltools.dylib"); /* Create all nessesary threads. */ { struct bot_in *next_bot = bots->b_first; /* Make our threads detachable. */ pthread_attr_init(&thread_attr); pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); /* Set some thread specific stuffs. */ pthread_key_create(&m_sock_fds, NULL); pthread_key_create(&bot, NULL); pthread_key_create(&irc_s, NULL); /* Launch a new thread per bot. */ for(; next_bot != NULL; next_bot = next_bot->next) bot_spawn(next_bot); } /* Exit the current thread and allow the others to continue. */ pthread_exit(NULL); return(0); }
int kern_init(uint64_t mbmagic, uint64_t mbmem) { extern char edata[], end[]; memset(edata, 0, end - edata); /* percpu variable for CPU0 is preallocated */ percpu_offsets[0] = __percpu_start; cons_init(); // init the console const char *message = "(THU.CST) os is loading ..."; kprintf("%s\n\n", message); if(mbmagic == MULTIBOOT_BOOTLOADER_MAGIC){ kprintf("Multiboot dectected: param %p\n", (void*)mbmem); mbmem2e820((Mbdata*)VADDR_DIRECT(mbmem)); parse_initrd((Mbdata*)VADDR_DIRECT(mbmem)); } print_kerninfo(); /* get_cpu_var not available before tls_init() */ hz_init(); gdt_init(per_cpu_ptr(cpus, 0)); tls_init(per_cpu_ptr(cpus, 0)); acpitables_init(); lapic_init(); numa_init(); pmm_init_numa(); // init physical memory management, numa awared /* map the lapic */ lapic_init_late(); //init the acpi stuff idt_init(); // init interrupt descriptor table pic_init(); // init interrupt controller // acpi_conf_init(); percpu_init(); cpus_init(); #ifdef UCONFIG_ENABLE_IPI ipi_init(); #endif refcache_init(); vmm_init(); // init virtual memory management sched_init(); // init scheduler proc_init(); // init process table sync_init(); // init sync struct /* ext int */ ioapic_init(); acpi_init(); ide_init(); // init ide devices #ifdef UCONFIG_SWAP swap_init(); // init swap #endif fs_init(); // init fs clock_init(); // init clock interrupt mod_init(); trap_init(); //XXX put here? bootaps(); intr_enable(); // enable irq interrupt #ifdef UCONFIG_HAVE_LINUX_DDE36_BASE dde_kit_init(); #endif /* do nothing */ cpu_idle(); // run idle process }