usb.patch, with conflicts and some warnings fixed
[pintos-anon] / src / threads / init.c
index cebec2c817f5954b9accf9558dbd36822c1fb8f4..dbb41da71c93e9dfb22623b8e569ada51d7ce28a 100644 (file)
 #include "devices/input.h"
 #include "devices/serial.h"
 #include "devices/shutdown.h"
+#include "devices/pci.h"
 #include "devices/timer.h"
 #include "devices/vga.h"
 #include "devices/rtc.h"
+#include "devices/usb.h"
 #include "threads/interrupt.h"
 #include "threads/io.h"
 #include "threads/loader.h"
@@ -40,6 +42,7 @@
 
 /* Page directory with kernel mappings only. */
 uint32_t *init_page_dir;
+bool init_page_dir_initialized;
 
 #ifdef FILESYS
 /* -f: Format the file system? */
@@ -59,6 +62,7 @@ static size_t user_page_limit = SIZE_MAX;
 
 static void bss_init (void);
 static void paging_init (void);
+static void pci_zone_init (void);
 
 static char **read_command_line (void);
 static char **parse_options (char **argv);
@@ -109,6 +113,7 @@ main (void)
   intr_init ();
   timer_init ();
   kbd_init ();
+  pci_init ();
   input_init ();
 #ifdef USERPROG
   exception_init ();
@@ -119,9 +124,11 @@ main (void)
   thread_start ();
   serial_init_queue ();
   timer_calibrate ();
+  usb_init ();
 
 #ifdef FILESYS
   /* Initialize file system. */
+  usb_storage_init ();
   ide_init ();
   locate_block_devices ();
   filesys_init (format_filesys);
@@ -174,18 +181,39 @@ paging_init (void)
       if (pd[pde_idx] == 0)
         {
           pt = palloc_get_page (PAL_ASSERT | PAL_ZERO);
-          pd[pde_idx] = pde_create (pt);
+          pd[pde_idx] = pde_create_kernel (pt);
         }
 
       pt[pte_idx] = pte_create_kernel (vaddr, !in_kernel_text);
     }
 
+  pci_zone_init ();
+
   /* Store the physical address of the page directory into CR3
      aka PDBR (page directory base register).  This activates our
      new page tables immediately.  See [IA32-v2a] "MOV--Move
      to/from Control Registers" and [IA32-v3a] 3.7.5 "Base Address
      of the Page Directory". */
   asm volatile ("movl %0, %%cr3" : : "r" (vtop (init_page_dir)));
+
+  init_page_dir_initialized = true;
+}
+
+/* initialize PCI zone at PCI_ADDR_ZONE_BEGIN - PCI_ADDR_ZONE_END*/
+static void
+pci_zone_init (void)
+{
+  int i;
+  for (i = 0; i < PCI_ADDR_ZONE_PDES; i++)
+    {
+      size_t pde_idx = pd_no ((void *) PCI_ADDR_ZONE_BEGIN) + i;
+      uint32_t pde;
+      void *pt;
+
+      pt = palloc_get_page (PAL_ASSERT | PAL_ZERO);
+      pde = pde_create_kernel (pt);
+      init_page_dir[pde_idx] = pde;
+    }
 }
 
 /* Breaks the kernel command line into words and returns them as