/* * This overrides the _exit() function in libc. * If the serial console (or remote GDB) is being used, it waits * until all the data has cleared out of the FIFOs; if the VGA * display is being used (normal console), then it waits for a keypress. * When it is done, it calls pc_reset() to reboot the computer. */ static void our_exit(int rc) { extern oskit_addr_t return_address; #if 0 printf("_exit(%d) called; %s...\r\n", rc, return_address ? "returning to netboot" : "rebooting"); #endif if (enable_gdb) { /* Detach from the remote GDB. */ gdb_serial_exit(rc); #ifdef HAVE_DEBUG_REGS /* Turn off the debug registers. */ set_dr7(get_dr7() & ~(DR7_G0 | DR7_G1 | DR7_G2 | DR7_G3)); #endif } /* flush and wait for `_exit called` message */ oskit_stream_release(console); if (!serial_console) { /* This is so that the user has a chance to SEE the output */ //~ printf("Press a key to reboot"); //~ printf("hit dat shit yo."); //~ getchar(); } if (return_address) { /* * The cleanup needs to be done here instead of in the * returned-to code because the return address may not * be accessible with our current paging and segment * state. * The order is important here: paging must be disabled * after we reload the gdt. */ cli(); clts(); phys_mem_va = 0; linear_base_va = 0; base_gdt_init(); /* Reload all since we changed linear_base_va. */ base_cpu_load(); paging_disable(); ((void (*)(void))return_address)(); } else pc_reset(); }
/* * This function is called at exit time if we're being debugged remotely; * it notifies the remoted debugger that we're exiting. * Unfortunately we can't pass back the true return code * because C's standard atexit mechanism doesn't provide it. */ static void gdb_atexit(void) { if (enable_gdb) gdb_serial_exit(0); }