int setkb_main(int argc, char **argv) { driver_t *ps2 = getDriver(PS2_DRIVER); if ( argc > 2 ) { cprintk(LIGHTRED, BLACK, "Cantidad de argumentos incorrecta\n"); return 1; } if ( argc == 1 ) { const char * kname; const char ** knames; (ps2->ioctl_driver)(PS2_GETLAYOUT,1,&kname); (ps2->ioctl_driver)(PS2_LAYOUTS,1,&knames); printk("Teclado actual: %s\n", kname); printk( "Disponibles:\n"); const char **p = knames; while ( *p ) printk("\t%s\n", *p++); return 0; } bool valid=false; (ps2->ioctl_driver)(PS2_SETLAYOUT,2,argv[1],&valid); if ( valid ) { printk("Teclado actual: %s\n", argv[1]); return 0; } cprintk(LIGHTRED, BLACK, "Teclado %s desconocido\n", argv[1]); return 2; }
int ts_main(int argc, char *argv[]) { unsigned i, ntasks, n, skip; TaskInfo_t *ti, *info; bool enabled[NVCONS]; bool check_cons = false; // por defecto habilitar todas las consolas bool cursor; (getDriver(CONS_DRIVER)->ioctl_driver)(CONS_CURSOR,2,false,&cursor); memset(enabled, 0, sizeof enabled); for ( i = 1 ; i < argc ; i++ ) // habilitar las consolas especificadas { unsigned cons = atoi(argv[i]); if ( cons < NVCONS ) enabled[cons] = check_cons = true; } (getDriver(CONS_DRIVER)->ioctl_driver)(CONS_CLEAR,0); cprintk(WHITE, BLUE, "%s", title); (getDriver(CONS_DRIVER)->ioctl_driver)(CONS_GOTOXY,2,0,24); cprintk(WHITE, BLUE, "%s", foot); skip = 0; do { info = GetTasks(&ntasks); for ( n = 0, i = 1, ti = info ; i < 24 && ntasks-- ; ti++ ) { if ( (check_cons && !enabled[ti->consnum]) || n++ < skip ) continue; (getDriver(CONS_DRIVER)->ioctl_driver)(CONS_GOTOXY,2,0,i++); char namebuf[20]; sprintf(namebuf, ti->protected ? "[%.16s]" : "%.18s", name(ti->task)); cprintk(WHITE, BLACK, "%8x %-18s %u %10u %-9s %-18.18s", ti->task, namebuf, ti->consnum, ti->priority, statename(ti->state), name(ti->waiting)); if ( ti->is_timeout ) cprintk(WHITE, BLACK, " %10u", ti->timeout); else (getDriver(CONS_DRIVER)->ioctl_driver)(CONS_CLREOL,0); } while ( i < 24 ) { (getDriver(CONS_DRIVER)->ioctl_driver)(CONS_GOTOXY,2,0,i++); (getDriver(CONS_DRIVER)->ioctl_driver)(CONS_CLREOL,0); } Free(info); } while ( getuser(&skip) ); (getDriver(CONS_DRIVER)->ioctl_driver)(CONS_CLEAR,0); (getDriver(CONS_DRIVER)->ioctl_driver)(CONS_CURSOR,2,cursor,NULL); return 0; }
int ts_main(int argc, char *argv[]) { unsigned i, ntasks, n, skip; TaskInfo_t *ti, *info; bool enabled[NVCONS]; bool check_cons = false; // por defecto habilitar todas las consolas bool cursor = mt_cons_cursor(false); memset(enabled, 0, sizeof enabled); for ( i = 1 ; i < argc ; i++ ) // habilitar las consolas especificadas { unsigned cons = atoi(argv[i]); if ( cons < NVCONS ) enabled[cons] = check_cons = true; } mt_cons_clear(); cprintk(WHITE, BLUE, "%s", title); // permite escribir con letra y fondo particular mt_cons_gotoxy(0, 24); // me ubica en un lugar en pantalla (X e Y) para deespues escribir. cprintk(WHITE, BLUE, "%s", foot); skip = 0; do { info = GetTasks(&ntasks); for ( n = 0, i = 1, ti = info ; i < 24 && ntasks-- ; ti++ ) { if ( (check_cons && !enabled[ti->consnum]) || n++ < skip ) continue; mt_cons_gotoxy(0, i++); char namebuf[20]; sprintf(namebuf, ti->protected ? "[%.16s]" : "%.18s", name(ti->task)); cprintk(WHITE, BLACK, "%8x %-18s %u %10u %-9s %-18.18s", ti->task, namebuf, ti->consnum, ti->priority, statename(ti->state), name(ti->waiting)); if ( ti->is_timeout ) cprintk(WHITE, BLACK, " %10u", ti->timeout); else mt_cons_clreol(); } while ( i < 24 ) { mt_cons_gotoxy(0, i++); mt_cons_clreol(); } Free(info); } while ( getuser(&skip) ); mt_cons_clear(); mt_cons_cursor(cursor); return 0; }
static void mputch(int x, int y, int c, unsigned fg, unsigned bg) { Atomic(); mt_cons_gotoxy(x, y); cprintk(fg, bg, "%c", c); Unatomic(); }
static int sys_test(uint32_t args[]) { int errno = (int)args[0]; cprintk(rc_black, rc_light_brown, "\n\tsys_test run here!\n"); return errno; }
static void show_test_cons(int color){ driver_t *cons = getDriver(CONS_DRIVER); cons->ioctl_driver(CONS_CLEAR,0); cprintk(MAGENTA, BLACK,"\n ** TEST CONSOLA **\n\n\n"); cprintk(YELLOW, BLACK, "Presione q para salir\n\n"); cprintk(LIGHTMAGENTA, BLACK,"\n \ ** Seleccione un color **\n\ \n\n"); printk(" 1.Turquesa\n\ 2.Violeta\n\ 3.Amarillo\n\ 4.Azul\n\ 5.Rojo\n\n"); cons->ioctl_driver(CONS_GOTOXY,2,20,20); cprintk(color, BLACK, "ESTO ES UN TEST DE CONSOLA"); }
// vfs 初始化 void vfs_init(void) { cprintk(rc_black, rc_light_brown, "Init Virtual File System ...\n\n"); struct vfsmount *mount; mount = kmalloc(sizeof(struct vfsmount)); assert(mount != NULL, "vfs_init alloc vfsmount failed!"); // 初始化VFS目录树 init_mount_tree(mount); current->files.vfsmount = mount; }
static void ide_tester(){ unsigned i; driver_t *cons = getDriver(CONS_DRIVER); cprintk(YELLOW, BLACK, "Presione q para salir\n\n"); for ( i = IDE_PRI_MASTER ; i <= IDE_SEC_SLAVE ; i++ ) test_ide(i); while(getch() !='q'); cons->ioctl_driver(CONS_CLEAR,0); }
int interface_tester_main(int argc, char *argv[]) { driver_t *cons = getDriver(CONS_DRIVER); cons->ioctl_driver(CONS_CLEAR,0); int option; while((option = showMenu())!=EXIT){ switch(option){ case IDE: cons->ioctl_driver(CONS_CLEAR,0); cprintk(MAGENTA, BLACK,"\n ** TEST DISCO RIGIDO **\n\n\n"); ide_tester(); break; case CONS: cons->ioctl_driver(CONS_CLEAR,0); cprintk(MAGENTA, BLACK,"\n ** TEST CONSOLA **\n\n\n"); cons_tester(); break; default: cons->ioctl_driver(CONS_CLEAR,0); cprintk(RED, BLACK,"Opcion incorrecta.\n\n"); break; } } cons->ioctl_driver(CONS_CLEAR,0); return 0; }
void kernel_init() { init_gdt(); init_idt(); init_debug(); init_mm(); init_vmm(); init_heap(); init_sched(); console_clear(); cprintk(rc_light_brown, "Welcome to SuperSong's OS, version: %s\n\n", "v0.1"); init_timer(200); cprintk(rc_light_cyan, "kernel in memory start: 0x%x\n", __kernel_mem_start); cprintk(rc_light_cyan, "kernel in memory end: 0x%x\n", __kernel_mem_end); cprintk(rc_light_cyan, "kernel in memory_used: %d KBs\n", (__kernel_mem_end - __kernel_mem_start + 1023) / 1024); show_memory_map(); cprintk(rc_red, "\nThe count of physical memory pages is: %d\n\n", phy_page_count); kthread_create(thread, NULL); enable_intr(); while (1) { cprintk(rc_red, "Thraed1\n"); } while (1) { __asm__ volatile ("hlt"); } }
// 屏幕显示初始化 void console_init(void) { console_clear(); cprintk(rc_black, rc_green, "Hello, Hurlex II kernel!\n\n"); }
int thread(void *arg) { while (1) { cprintk(rc_green, "Thread2\n"); } }
int shell_main(int argc, char **argv) { execpars ex; char line[BUFSIZE]; struct cmdentry *cp; unsigned fg, bg; TaskInfo_t info; char *hist[NHIST]; int pos, hfirst, hcur, hlast; bool wait, found; for ( hcur = 0 ; hcur < NHIST ; hcur++ ) hist[hcur] = Malloc(BUFSIZE); hfirst = hcur = hlast = -1; mt_cons_getattr(&fg, &bg); GetInfo(CurrentTask(), &info); while ( true ) { // Leer línea de comando eventualmente usando la historia mt_cons_setattr(LIGHTGRAY, BLACK); mt_cons_cursor(true); cprintk(LIGHTCYAN, BLACK, "\rMT%u> ", info.consnum); mt_cons_clreom(); hcur = -1; *line = 0; do { switch ( pos = getline(line, sizeof line) ) { case FIRST: if ( (hcur = hfirst) != -1) strcpy(line, hist[hcur]); break; case LAST: if ( (hcur = hlast) != -1 ) strcpy(line, hist[hcur]); break; case BACK: if ( hcur == -1 ) hcur = hlast; else if ( hcur != hfirst ) hcur = prev(hcur); if ( hcur != -1 ) strcpy(line, hist[hcur]); break; case FWD: if ( hcur != -1 ) { if ( hcur == hlast ) { hcur = -1; *line = 0; } else { hcur = next(hcur); strcpy(line, hist[hcur]); } } break; } } while ( pos < 0 ); // Sacar espacios al final y detectar comando en background wait = true; while ( --pos >= 0 ) { char c = line[pos]; switch ( c ) { case ' ': case '\t': case '\r': case '\n': line[pos] = 0; continue; } if ( c == '&' ) wait = false; break; } // Separar en argumentos strcpy(ex.buf, line); if ( !wait ) ex.buf[pos] = 0; // quitamos el & final antes de separar ex.nargs = separate(ex.buf, ex.args, NARGS); if ( !ex.nargs ) continue; ex.args[ex.nargs] = NULL; // Guardar línea en la historia si es distinta de la última if ( hlast == -1 ) { hlast = hfirst = 0; strcpy(hist[hlast], line); } else if ( strcmp(hist[hlast], line) != 0 ) { hlast = next(hlast); if ( hfirst == hlast ) hfirst = next(hlast); strcpy(hist[hlast], line); } /* Comandos internos */ if ( strcmp(ex.args[0], "help") == 0 ) { printk("Comandos internos:\n"); printk("\thelp\n"); printk("\texit [status]\n"); printk("\treboot\n"); printk("Aplicaciones:\n");\ for ( cp = cmdtab ; cp->name ; cp++ ) printk("\t%s %s\n", cp->name, cp->params); continue; } if ( strcmp(ex.args[0], "exit") == 0 ) { mt_cons_setattr(fg, bg); for ( hcur = 0 ; hcur < NHIST ; hcur++ ) Free(hist[hcur]); return ex.nargs > 1 ? atoi(ex.args[1]) : 0; } if ( strcmp(ex.args[0], "reboot") == 0 ) { *(short *) 0x472 = 0x1234; while ( true ) outb(0x64, 0xFE); } /* Aplicaciones */ found = false; for ( cp = cmdtab ; cp->name ; cp++ ) if ( strcmp(ex.args[0], cp->name) == 0 ) { found = true; ex.func = cp->func; if ( wait ) // correr app y esperarla { int status; Task_t *t = CreateTask(attached_app, MAIN_STKSIZE, &ex, ex.args[0], DEFAULT_PRIO); Attach(t); Ready(t); while ( !Join(t, &status) ) ; if ( status != 0 ) { cprintk(LIGHTRED, BLACK, "\rStatus: %d\n", status); mt_cons_clreol(); } } else // correr app en background { Task_t *t = CreateTask(detached_app, MAIN_STKSIZE, &ex, ex.args[0], DEFAULT_PRIO); cprintk(LIGHTGREEN, BLACK, "\rTask: %x\n", t); mt_cons_clreol(); Ready(t); Send(t, NULL, 0); // esperar que copie los parámetros } break; } if ( !found ) cprintk(LIGHTRED, BLACK, "Comando %s desconocido\n", ex.args[0]); } }
int shell_main(int argc, char **argv) { char buf[BUFSIZE]; char *args[NARGS+1]; unsigned nargs; struct cmdentry *cp; unsigned fg, bg; mt_cons_getattr(&fg, &bg); while ( true ) { mt_cons_setattr(LIGHTGRAY, BLACK); cprintk(LIGHTCYAN, BLACK, PROMPT); /* leer linea de comando, fraccionarla en tokens y armar argv */ mt_getline(buf, sizeof buf); nargs = separate(buf, args, NARGS); if ( !nargs ) continue; args[nargs] = NULL; /* comandos internos */ if ( strcmp(args[0], "help") == 0 ) { printk("Comandos internos:\n"); printk("\thelp\n"); printk("\texit\n"); printk("\treboot\n"); printk("Aplicaciones:\n");\ for ( cp = cmdtab ; cp->name ; cp++ ) printk("\t%s\n", cp->name); continue; } if ( strcmp(args[0], "exit") == 0 ) { mt_cons_setattr(fg, bg); return nargs > 1 ? atoi(args[1]) : 0; } if ( strcmp(args[0], "reboot") == 0 ) { *(short *) 0x472 = 0x1234; while ( true ) outb(0x64, 0xFE); } /* aplicaciones */ bool found = false; for ( cp = cmdtab ; cp->name ; cp++ ) if ( strcmp(args[0], cp->name) == 0 ) { found = true; int n = cp->func(nargs, args); if ( n != 0 ) cprintk(LIGHTRED, BLACK, "Status: %d\n", n); break; } if ( !found ) cprintk(LIGHTRED, BLACK, "Comando %s desconocido\n", args[0]); } }