// Step the program through a single operation. void cmd_step(char **_){ if (sigsetjmp(jump,1) == 0){ if (proc_tick()){ puts("Read `term`, exited succesfully"); } } }
int core_run(void) { int s_server = 0, s_listener = 0; bool running = true; struct pollfd fds[MAX_SOCKETS]; store_init(); net_init(); state_init(); if((s_server = srv_init()) < 0) return EXIT_FAILURE; if(srv_connect() == -1){ ERR("srv_connect() failed. Exiting..."); return EXIT_FAILURE; } if((s_listener = clt_init()) == -1){ ERR("clt_init() failed. Exiting..."); return EXIT_FAILURE; } memset(fds, 0 , sizeof(fds)); net_poll_add(s_server, POLLIN); net_poll_add_listener(s_listener, POLLIN); while(running){ net_poll(POLLTIMEOUT); proc_tick(); for(int i = 0; i < net_nfds(); i++){ while(net_socket_avail(i)){ char msg[513] = ""; net_socket_msg(i, msg, sizeof msg); proc_proc(i, msg); } } while(proc_wqueue_length()){ wqueue_entry_t ent = proc_wqueue_head(); net_socket_write(ENT_GET(ent, target), ENT_GET(ent, data), ENT_GET(ent, datasz)); proc_wqueue_next(); } } return EXIT_SUCCESS; }
void trap(struct trapframe *tf) { uint cr2; //print_trapframe(tf); procdump(); //chy for debug if (cp!=NULL) dbmsg("trap frame from %x %x, cp name %s\n",tf->eip, tf->trapno,cp->name); if(tf->trapno == T_SYSCALL){ if(cp->killed) exit(); cp->tf = tf; syscall(); if(cp->killed) exit(); return; } switch(tf->trapno){ cprintf("interrupt %x, trap frame : %x\n",tf->trapno, (uint)tf); case IRQ_OFFSET + IRQ_TIMER: // if(cpu() == 0){ acquire(&tickslock); ticks++; wakeup(&ticks); release(&tickslock); // } lapic_eoi(); break; case IRQ_OFFSET + IRQ_IDE: ide_intr(); lapic_eoi(); break; case IRQ_OFFSET + IRQ_KBD: kbd_intr(); lapic_eoi(); break; case IRQ_OFFSET + IRQ_SPURIOUS: cprintf("cpu%d: spurious interrupt at %x:%x\n", cpu(), tf->cs, tf->eip); lapic_eoi(); break; case T_PGFLT: cprintf("page fault!\n"); //cprintf("current process uses %d pages.\n", cp->sz/PAGE); cr2=rcr2(); if(handle_pgfault(cr2)<0){ cprintf("cannot handle page fault! Virtual addr: %x, eip: %x\n", cr2, tf->eip); }else{ cprintf("page fault handled successfully! Virtual addr: %x, eip: %x\n", cr2, tf->eip); } //cprintf("current process uses %d pages.\n", cp->sz/PAGE); break; default: if(cp == 0 || (tf->cs&3) == 0){ // In kernel, it must be our mistake. cprintf("unexpected trap %d from cpu %d eip %x esp %x cr2 %x, pid %d %s \n", tf->trapno, cpu(), tf->eip, tf->esp, rcr2(),cp->pid, cp->name); panic("trap"); } // In user space, assume process misbehaved. cprintf("pid %d %s: trap %d err %d on cpu %d eip %x cr2 %x -- kill proc\n", cp->pid, cp->name, tf->trapno, tf->err, cpu(), tf->eip, rcr2()); cp->killed = 1; } // Force process exit if it has been killed and is in user space. // (If it is still executing in the kernel, let it keep running // until it gets to the regular system call return.) if(cp && cp->killed && (tf->cs&3) == DPL_USER) exit(); // Force process to give up CPU on clock tick. // If interrupts were on while locks held, would need to check nlock. if(cp && cp->state == RUNNING && tf->trapno == IRQ_OFFSET+IRQ_TIMER){ #ifdef LOAD_BALANCE_ON if(cp == idleproc[cpu()]){ struct rq* rq = theCpu.rq; rq->sched_class->load_balance(rq); } #endif proc_tick(theCpu.rq, cp); } }