X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fthreads%2Finit.c;h=01eec1120c923804083b747367b4e1a621ea5e19;hb=19becec31c5704572a3575336c57364d72fd572b;hp=60d6c46c4a98c3a5a7992f69e8422bf28f96cbd9;hpb=fde3b8ee3eaf48b1a6bb14568aedc207e62accab;p=pintos-anon diff --git a/src/threads/init.c b/src/threads/init.c index 60d6c46..01eec11 100644 --- a/src/threads/init.c +++ b/src/threads/init.c @@ -11,6 +11,7 @@ #include "devices/kbd.h" #include "devices/input.h" #include "devices/serial.h" +#include "devices/shutdown.h" #include "devices/timer.h" #include "devices/vga.h" #include "devices/rtc.h" @@ -53,6 +54,9 @@ bool power_off_when_done; /* -r: Reboot after kernel tasks complete? */ static bool reboot_when_done; +/* -ul: Maximum number of pages to put into palloc's user pool. */ +static size_t user_page_limit = SIZE_MAX; + static void ram_init (void); static void paging_init (void); @@ -61,9 +65,6 @@ static char **parse_options (char **argv); static void run_actions (char **argv); static void usage (void); -static void print_stats (void); - - int main (void) NO_RETURN; /* Pintos main program. */ @@ -88,7 +89,7 @@ main (void) printf ("Pintos booting with %'zu kB RAM...\n", ram_pages * PGSIZE / 1024); /* Initialize memory system. */ - palloc_init (); + palloc_init (user_page_limit); malloc_init (); paging_init (); @@ -126,10 +127,10 @@ main (void) /* Finish up. */ if (reboot_when_done) - reboot (); + shutdown_reboot (); if (power_off_when_done) - power_off (); + shutdown_power_off (); thread_exit (); } @@ -373,80 +374,5 @@ usage (void) " -ul=COUNT Limit user memory to COUNT pages.\n" #endif ); - power_off (); -} - -/* Keyboard control register port. */ -#define CONTROL_REG 0x64 - -/* Reboots the machine via the keyboard controller. */ -void -reboot (void) -{ - int i; - - printf ("Rebooting...\n"); - - /* See [kbd] for details on how to program the keyboard - * controller. */ - for (i = 0; i < 100; i++) - { - int j; - - /* Poll keyboard controller's status byte until - * 'input buffer empty' is reported. */ - for (j = 0; j < 0x10000; j++) - { - if ((inb (CONTROL_REG) & 0x02) == 0) - break; - timer_udelay (2); - } - - timer_udelay (50); - - /* Pulse bit 0 of the output port P2 of the keyboard controller. - * This will reset the CPU. */ - outb (CONTROL_REG, 0xfe); - timer_udelay (50); - } -} - -/* Powers down the machine we're running on, - as long as we're running on Bochs or QEMU. */ -void -power_off (void) -{ - const char s[] = "Shutdown"; - const char *p; - -#ifdef FILESYS - filesys_done (); -#endif - - print_stats (); - - printf ("Powering off...\n"); - serial_flush (); - - for (p = s; *p != '\0'; p++) - outb (0x8900, *p); - asm volatile ("cli; hlt" : : : "memory"); - printf ("still running...\n"); - for (;;); -} - -/* Print statistics about Pintos execution. */ -static void -print_stats (void) -{ - timer_print_stats (); - thread_print_stats (); -#ifdef FILESYS - disk_print_stats (); -#endif - console_print_stats (); - kbd_print_stats (); -#ifdef USERPROG - exception_print_stats (); -#endif + shutdown_power_off (); }