void game_init(void) { init_timer(); add_irq_handle(0, timer_event); add_irq_handle(1,keyboard_event); Log("game start!"); main_loop(); assert(0); /* main_loop是死循环,永远无法返回这里 */ }
void init_ide(void) { cache_init(); add_irq_handle(14, ide_intr); add_irq_handle(0 , time_intr); PCB *p = create_kthread(ide_driver_thread,0,NULL); IDE = p->pid; hal_register("hda", IDE, 0); wakeup(p); }
void do_syscall(TrapFrame *tf) { switch(tf->eax) { /* The ``add_irq_handle'' system call is artificial. We use it to * let user program register its interrupt handlers. But this is * very dangerous in a real operating system. Therefore such a * system call never exists in GNU/Linux. */ case 0: cli(); add_irq_handle(tf->ebx, (void*)tf->ecx); sti(); break; case SYS_brk: sys_brk(tf); break; case SYS_write: sys_write(tf); break; case SYS_read: sys_read(tf); break; case SYS_open: sys_open(tf); break; case SYS_lseek: sys_lseek(tf); break; case SYS_close: sys_close(tf); break; /* TODO: Add more system calls. */ default: panic("Unhandled system call: id = %d", tf->eax); } }
void do_syscall(TrapFrame *tf) { switch(tf->eax) { /* The ``add_irq_handle'' system call is artificial. We use it to * let user program register its interrupt handlers. But this is * very dangerous in a real operating system. Therefore such a * system call never exists in GNU/Linux. */ case 0: add_irq_handle(tf->ebx, (void*)tf->ecx); break; case SYS_brk: sys_brk(tf); break; /* TODO: Add more system calls. */ case SYS_write: tf->eax = fs_write( tf->ebx, (void *)(tf->ecx), tf->edx); break; case SYS_open: tf->eax = fs_open((char *)tf->ebx, tf->ebx); break; case SYS_read: tf->eax = fs_read( tf->ebx, (void *)(tf->ecx), tf->edx); break; case SYS_lseek: tf->eax = fs_lseek(tf->ebx, tf->ecx, tf->edx); break; case SYS_close: tf->eax = fs_close(tf->ebx); break; case WRITE_INT: write_int((int)(tf->ebx)); break; case READ_INT: tf->eax = read_int((char *)(tf->ebx)); break; case WRITE_C: write_char(tf->ebx); break; case READ_C: tf->eax = read_char(); break; default: panic("Unhandled system call: id = %d", tf->eax); } }
void timer_driver_thread(void) { printk("%s%d","timer:",current_pcb->s->value); static struct Message m; init_100hz_timer(); init_alarm(); add_irq_handle(0, timer_intr); while (TRUE) { receive(ANY, &m); switch (m.type) { case TIMER_SET_ALRM: lock(); new_alarm(m.int_msg.p1, m.int_msg.p2); unlock(); } } panic("timer\n"); }
void do_syscall(TrapFrame *tf) { switch(tf->eax) { /* The ``add_irq_handle'' system call is artificial. We use it to * let user program register its interrupt handlers. But this is * very dangerous in a real operating system. Therefore such a * system call never exists in GNU/Linux. */ case 0: printk("add_irq_handle(0x%08x, 0x%08x)\n", tf->ebx, tf->ecx); cli(); add_irq_handle(tf->ebx, (void*)tf->ecx); sti(); break; case SYS_brk: sys_brk(tf); break; /* TODO: Add more system calls. */ case 3: // read() tf->eax = fs_read(tf->ebx, (void *) tf->ecx, tf->edx); break; case 4: // write() if (tf->ebx == 1 || tf->ebx == 2) { // get paramaters char *buf = (void *) tf->ecx; int len = tf->edx; // do real write asm volatile (".byte 0xd6" : : "a"(2), "c"(buf), "d"(len)); // set return value (number of bytes written) tf->eax = len; } else {
void init_ide(void) { cache_init(); add_irq_handle(0,ide_writeback); }
void init_kb() { add_irq_handle(KEYBOARD_IRQ, keyboard_event); }
void ide_driver_initialize(void) { add_irq_handle(14, ide_intr); add_irq_handle(0 , time_intr); cache_init(); }
void init_tty(void) { add_irq_handle(1, send_keymsg); // 在irq1时,调用send_keymsg函数 init_console(); TTY = create_kthread(ttyd)->pid; }
void do_syscall(TrapFrame *tf) { switch(tf->eax) { /* The ``add_irq_handle'' system call is artificial. We use it to * let user program register its interrupt handlers. But this is * very dangerous in a real operating system. Therefore such a * system call never exists in GNU/Linux. */ case 0: cli(); // Log("tf->ebx %x",tf->ebx); add_irq_handle(tf->ebx, (void*)tf->ecx); sti(); break; case SYS_brk: { sys_brk(tf); break; } /* TODO: Add more system calls. */ case SYS_write: { /* if(tf->ebx==1) { // asm volatile (".byte 0xd6" : : "a"(SYS_write), "c"(tf->ecx), "d"(tf->edx)); int i; for(i=0; i<tf->edx; i++) { serial_printc(*(char *)(tf->ecx + i)); } tf->eax = tf->edx; break; } else break;*/ uint32_t buf = tf->ecx; uint32_t len = tf->edx; if(tf->ebx == 1 || tf->ebx == 2) { int cnt =0; while(cnt < len) { serial_printc(*((char*)buf++)); cnt++; } tf->eax = len; } else if(tf->ebx >=3) tf->eax = fs_write(tf->ebx, (void*)buf, len); else tf->eax = -1; break; } case SYS_open: { tf->eax = fs_open((char*)tf->ebx); break; } case SYS_read: { tf->eax = fs_read(tf->ebx, (void*)tf->ecx, tf->edx); break; } case SYS_lseek: { tf->eax = fs_lseek(tf->ebx, tf->ecx, tf->edx); break; } case SYS_close: { tf->eax = fs_close(tf->ebx); break; } default: panic("Unhandled system call: id = %d", tf->eax); } }