/** * Initializes the container data for the root process (the one with index 0). * The root process is the one that gets spawned first by the kernel. */ void container_init(unsigned int mbi_addr) { unsigned int real_quota; // TODO: define your local variables here. int max_nps; int i; pmem_init(mbi_addr); real_quota = 0; max_nps = get_nps(); /** * TODO: compute the available quota and store it into the variable real_quota. * It should be the number of the unallocated pages with the normal permission * in the physical memory allocation table. */ for (i = 0; i < max_nps; i++) { if (at_is_norm(i) == 1 && at_is_allocated(i) == 0) { real_quota += 1; } } KERN_DEBUG("\nreal quota: %d\n\n", real_quota); CONTAINER[0].quota = real_quota; CONTAINER[0].usage = 0; CONTAINER[0].parent = 0; CONTAINER[0].nchildren = 0; CONTAINER[0].used = 1; }
/** * Initializes the container data for the root process (the one with index 0). * The root process is the one that gets spawned first by the kernel. */ void container_init(unsigned int mbi_addr) { unsigned int real_quota; unsigned int nps, i, norm, used; pmem_init(mbi_addr); real_quota = 0; /** * compute the available quota and store it into the variable real_quota. * It should be the number of the unallocated pages with the normal permission * in the physical memory allocation table. */ nps = get_nps(); i = 1; while (i < nps) { norm = at_is_norm(i); used = at_is_allocated(i); if (norm == 1 && used == 0) real_quota++; i++; } KERN_DEBUG("\nreal quota: %d\n\n", real_quota); CONTAINER[0].quota = real_quota; CONTAINER[0].usage = 0; CONTAINER[0].parent = 0; CONTAINER[0].nchildren = 0; CONTAINER[0].used = 1; }
/* **++ ** FUNCTIONAL DESCRIPTION: ** ** i8042_wait_input ** ** This function waits until input is available to be read from ** the 8042 output buffer. ** ** FORMAL PARAMETERS: ** ** iot I/O tag for the mapped register space ** ioh I/O handle for the mapped register space ** type Type of input to wait for (auxiliary, keyboard or any). ** ** IMPLICIT INPUTS: ** ** none. ** ** IMPLICIT OUTPUTS: ** ** none. ** ** FUNCTION VALUE: ** ** 0 - Timed out waiting for input ** 1 - Input available to be read **-- */ int i8042_wait_input(bus_space_tag_t iot, bus_space_handle_t ioh, u_char type) { register u_int count; register u_char status; int retValue = 0; for (count = I8042_WAIT_THRESHOLD; count; count--) { /* Check if there is a character to be read */ status = bus_space_read_1(iot, ioh, KBSTATPO); if (((status & type) == type) || ((type == I8042_ANY_DATA) && (status & KBS_DIB))) { retValue = 1; break; } I8042_DELAY; } KERN_DEBUG(i8042debug, KERN_DEBUG_INFO, ("i8042_wait_input: returning : %s\n\tlast status : 0x%x\n", retValue ? "Found Data" : "Exceeded Wait Threshold", status)); return (retValue); } /* End i8042_wait_input */
void kern_init (uintptr_t mbi_addr) { thread_init(mbi_addr); KERN_DEBUG("Kernel initialized.\n"); kern_main (); }
int mon_start_user (int argc, char **argv, struct Trapframe *tf) { unsigned int idle_pid; idle_pid = proc_create (_binary___obj_user_idle_idle_start, 10000); KERN_DEBUG("process idle %d is created.\n", idle_pid); KERN_INFO("Start user-space ... \n"); tqueue_remove (NUM_IDS, idle_pid); tcb_set_state (idle_pid, TSTATE_RUN); set_curid (idle_pid); kctx_switch (0, idle_pid); KERN_PANIC("mon_startuser() should never reach here.\n"); }
static void kern_main (void) { KERN_DEBUG("In kernel main.\n\n"); #ifdef TEST dprintf("Testing the PKCtxNew layer...\n"); if(test_PKCtxNew() == 0) dprintf("All tests passed.\n"); else dprintf("Test failed.\n"); dprintf("\n"); dprintf("Testing the PTCBInit layer...\n"); if(test_PTCBInit() == 0) dprintf("All tests passed.\n"); else dprintf("Test failed.\n"); dprintf("\n"); dprintf("Testing the PTQueueInit layer...\n"); if(test_PTQueueInit() == 0) dprintf("All tests passed.\n"); else dprintf("Test failed.\n"); dprintf("\n"); dprintf("Testing the PThread layer...\n"); if(test_PThread() == 0) dprintf("All tests passed.\n"); else dprintf("Test failed.\n"); dprintf("\n"); dprintf("\nTest complete. Please Use Ctrl-a x to exit qemu."); #else monitor(NULL); #endif }
static void trap_dump(tf_t *tf) { if (tf == NULL) return; uintptr_t base = (uintptr_t) tf; KERN_DEBUG("trapframe at %x\n", base); KERN_DEBUG("\t%08x:\tedi: \t\t%08x\n", &tf->regs.edi, tf->regs.edi); KERN_DEBUG("\t%08x:\tesi: \t\t%08x\n", &tf->regs.esi, tf->regs.esi); KERN_DEBUG("\t%08x:\tebp: \t\t%08x\n", &tf->regs.ebp, tf->regs.ebp); KERN_DEBUG("\t%08x:\tesp: \t\t%08x\n", &tf->regs.oesp, tf->regs.oesp); KERN_DEBUG("\t%08x:\tebx: \t\t%08x\n", &tf->regs.ebx, tf->regs.ebx); KERN_DEBUG("\t%08x:\tedx: \t\t%08x\n", &tf->regs.edx, tf->regs.edx); KERN_DEBUG("\t%08x:\tecx: \t\t%08x\n", &tf->regs.ecx, tf->regs.ecx); KERN_DEBUG("\t%08x:\teax: \t\t%08x\n", &tf->regs.eax, tf->regs.eax); KERN_DEBUG("\t%08x:\tes: \t\t%08x\n", &tf->es, tf->es); KERN_DEBUG("\t%08x:\tds: \t\t%08x\n", &tf->ds, tf->ds); KERN_DEBUG("\t%08x:\ttrapno:\t\t%08x\n", &tf->trapno, tf->trapno); KERN_DEBUG("\t%08x:\terr: \t\t%08x\n", &tf->err, tf->err); KERN_DEBUG("\t%08x:\teip: \t\t%08x\n", &tf->eip, tf->eip); KERN_DEBUG("\t%08x:\tcs: \t\t%08x\n", &tf->cs, tf->cs); KERN_DEBUG("\t%08x:\teflags:\t\t%08x\n", &tf->eflags, tf->eflags); KERN_DEBUG("\t%08x:\tesp: \t\t%08x\n", &tf->esp, tf->esp); KERN_DEBUG("\t%08x:\tss: \t\t%08x\n", &tf->ss, tf->ss); }
/* **++ ** FUNCTIONAL DESCRIPTION: ** ** i8042_cmd ** ** This function sends a command to the 8042 device or the auxiliary ** device hanging off it. The command is retried a ** number of times if a resend response is received. ** ** FORMAL PARAMETERS: ** ** iot I/O tag for the mapped register space ** ioh I/O handle for the mapped register space ** auxCmd An indication of what type of command this is. ** checkResponse A switch indicating whether to read a result after ** executing the command and compare ot with ** "responseExpected". ** responseExpected Only valid if "checkResponse" is non-zero. This ** is compared with the data value read after the ** command has been executed. ** value Command to send to the device selected by "auxCmd". ** ** IMPLICIT INPUTS: ** ** none. ** ** IMPLICIT OUTPUTS: ** ** none. ** ** FUNCTION VALUE: ** ** 0 - Failed to send command or receive acknowledgement for it ** 1 - Command sent and responded to successfully. **-- */ int i8042_cmd(bus_space_tag_t iot, bus_space_handle_t ioh, u_char auxCmd, u_char checkResponse, u_char responseExpected, u_char value) { u_int retries; register u_char c = 0; int status; /* Assume failure */ status = 0; for (retries = I8042_RETRIES; i8042_wait_output(iot,ioh) && retries; retries--) { if (auxCmd == I8042_AUX_CMD) { /* Setup to write command to auxiliary device */ bus_space_write_1(iot, ioh, KBCMDPO, KBC_AUXWRITE); /* Write actual command to selected device */ if (i8042_wait_output(iot,ioh)) { bus_space_write_1(iot, ioh, KBOUTPO, value); } else { KERN_DEBUG(i8042debug, KERN_DEBUG_WARNING, ("i8042_cmd: failed aux device request of 0x%x\n", value)); break; } } else if (auxCmd == I8042_CMD) { /* Write command to keyboard controller requested. */ bus_space_write_1(iot, ioh, KBCMDPO, value); } else if (auxCmd == I8042_KBD_CMD) { /* Write a command to actual keyboard H/W device. */ bus_space_write_1(iot, ioh, KBOUTPO, value); } else if (auxCmd == I8042_WRITE_CCB) { /* Write 8042 Controller Command Byte requested */ bus_space_write_1(iot, ioh, KBCMDPO, K_LDCMDBYTE); /* Write actual command to selected device */ if (i8042_wait_output(iot,ioh)) { bus_space_write_1(iot, ioh, KBOUTPO, value); } else { KERN_DEBUG(i8042debug, KERN_DEBUG_WARNING, ("i8042_cmd: failed contoller command byte " "write request of 0x%x\n", value)); break; } } else { KERN_DEBUG(i8042debug, KERN_DEBUG_WARNING, ("i8042_cmd: invalid device identifier of 0x%x\n", auxCmd)); break; } /* Does anyone need to check the result of this command ? */ if (checkResponse == I8042_CHECK_RESPONSE) { /* get response from device and check if ** successful. */ if (i8042_wait_input(iot,ioh,I8042_ANY_DATA)) { c = bus_space_read_1(iot, ioh, KBDATAPO); if (c == responseExpected) { /* Successfull command so we're outa here */ status = 1; break; } else if (c == KBR_RESEND) { /* Hmm response was try again so lets. */ KERN_DEBUG(i8042debug, KERN_DEBUG_WARNING, ("i8042_cmd: resend of 0x%x\n", value)); } else { /* response was nothing we expected so we're ** outa here. */ KERN_DEBUG(i8042debug, KERN_DEBUG_WARNING, ("i8042_cmd: unexpected response 0x%x\n", c)); break; } } /* End If able to get response from device */ else { /* Timmed out waiting for a response .... maybe we ** weren't meant to get one ?? */ KERN_DEBUG(i8042debug, KERN_DEBUG_WARNING, ("i8042_cmd: no response to command 0x%x\n", value)); break; } } /* End if need to check for response */ else { /* Not requested to check for response and we did send the ** command so I guess we were successful :-) */ status = 1; break; } } /* End loop for several retries if needed a response */ /* Diagnostic output on command value, result and status returned */ KERN_DEBUG(i8042debug, KERN_DEBUG_INFO, ("i8042_cmd: %s Device : Command 0x%x: %s:\n\t " "Check Value 0x%x: " "Response Value 0x%x: Status being returned 0x%x\n", (auxCmd == I8042_AUX_CMD) ? "Auxiliary" : "Keyboard", value, (checkResponse == I8042_CHECK_RESPONSE) ? "Checking response" : "NOT checking response", responseExpected, c, status)); return (status); } /* End i8042_cmd */