static int __init kforth_init(void) { mutex_init(&kforth_mutex); in_buf=kmalloc(CHUNK_SIZE,GFP_KERNEL); out_buf=kmalloc(CHUNK_SIZE,GFP_KERNEL); if(in_buf==NULL) return -ENOMEM; if(out_buf==NULL) return -ENOMEM; fc=forth_init(); majorNumber = register_chrdev(0, DEVICE_NAME, &fops); if (majorNumber<0){ printk(KERN_ALERT "Kforth failed to register a major number\n"); return majorNumber; } // Register the device class fClass = class_create(THIS_MODULE, CLASS_NAME); if (IS_ERR(fClass)){ // Check for error and clean up if there is unregister_chrdev(majorNumber, DEVICE_NAME); printk(KERN_ALERT "Failed to register device class\n"); return PTR_ERR(fClass); // Correct way to return an error on a pointer } // Register the device driver fDevice = device_create(fClass, NULL, MKDEV(majorNumber, 0), NULL, DEVICE_NAME); if (IS_ERR(fDevice)){ // Clean up if there is an error class_destroy(fClass); // Repeated code but the alternative is goto statements unregister_chrdev(majorNumber, DEVICE_NAME); printk(KERN_ALERT "Failed to create the device\n"); return PTR_ERR(fDevice); } return 0; }
static forth_t *forth_initial_enviroment(forth_t **o, forth_cell_t size, FILE *input, FILE *output, enum forth_debug_level verbose, int argc, char **argv) { errno = 0; assert(input && output && argv); if(*o) goto finished; #ifdef USE_BUILT_IN_CORE (void)size; *o = forth_load_core_memory((char*)forth_core_data, forth_core_size); forth_set_file_input(*o, input); forth_set_file_input(*o, output); #else *o = forth_init(size, input, output, NULL); #endif if(!(*o)) { fatal("forth initialization failed, %s", forth_strerror()); exit(EXIT_FAILURE); } finished: forth_set_debug_level(*o, verbose); forth_set_args(*o, argc, argv); return *o; }
int openbios(void) { #ifdef CONFIG_DEBUG_CONSOLE #ifdef CONFIG_DEBUG_CONSOLE_SERIAL uart_init(CONFIG_SERIAL_PORT, CONFIG_SERIAL_SPEED); #endif /* Clear the screen. */ cls(); #endif collect_sys_info(&sys_info); dict = (unsigned char *)sys_info.dict_start; dicthead = (cell)sys_info.dict_end; last = sys_info.dict_last; dictlimit = sys_info.dict_limit; forth_init(); relocate(&sys_info); #ifdef CONFIG_DEBUG_CONSOLE_VGA video_init(); #endif #ifdef CONFIG_DEBUG_BOOT printk("forth started.\n"); printk("initializing memory..."); #endif init_memory(); #ifdef CONFIG_DEBUG_BOOT printk("done\n"); #endif PUSH_xt( bind_noname_func(arch_init) ); fword("PREPOST-initializer"); PC = (ucell)findword("initialize-of"); if (!PC) { printk("panic: no dictionary entry point.\n"); return -1; } #ifdef CONFIG_DEBUG_DICTIONARY printk("done (%d bytes).\n", dicthead); printk("Jumping to dictionary...\n"); #endif enterforth((xt_t)PC); return 0; }