Adds a shared RW page to every address space
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 4 Jun 2009 21:33:31 +0000 (14:33 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Fri, 5 Jun 2009 23:43:41 +0000 (16:43 -0700)
include/arch/smp.h
include/ros/memlayout.h
kern/src/env.c

index cf48822..9ebcd4b 100644 (file)
@@ -31,6 +31,7 @@ typedef struct per_cpu_info {
        // will want it padded out to an even cacheline
 } per_cpu_info_t;
 extern per_cpu_info_t per_cpu_info[MAX_NUM_CPUS];
+extern volatile uint8_t num_cpus;
 
 /* SMP bootup functions */
 void smp_boot(void);
index 3aa65cb..d3d7c98 100644 (file)
@@ -41,6 +41,8 @@
  *                     +------------------------------+ 0xbec01000      PTSIZE
  *                     |     Per-Process R/O Info     | R-/R-  PGSIZE     |
  * UTOP, UINFO  ---->  +------------------------------+ 0xbec00000      --+
+ *                     |      Global Shared Page      | RW/RW  PGSIZE     |
+ *      UGDATA  ---->  +------------------------------+ 0xbebff000        | 
  *                     |  Unmapped (future expansion) | --/--             |
  *                     +------------------------------+ 0xbe801000      PTSIZE
  *                     |     Per-Process R/W Data     | RW/RW  PGSIZE     |
 // Top of user-accessible VM
 #define UTOP           UINFO
 
+// Read-write, global page.  Shared by all processes.  Can't be trusted.
+#define UGDATA         (UTOP - PGSIZE)
+
 // Read-write, per-process shared data structures
 #define UDATA          (UTOP - PTSIZE)
 #define UDATA_PAGES 1
index 4ebe904..0d2730a 100644 (file)
@@ -182,6 +182,22 @@ env_setup_vm(env_t *e)
                page_free(pgdata);
                return r;
        }
+
+       /* Shared page for all processes.  Can't be trusted, but still very useful
+        * at this stage for us.  Consider removing when we have real processes.
+        * (TODO).  Note the page is alloced only the first time through
+        */
+       static page_t* shared_page = 0;
+       if (!shared_page)
+               page_alloc(&shared_page);
+       // Up it, so it never goes away.  One per user, plus one from page_alloc
+       // This is necessary, since it's in the per-process range of memory that
+       // gets freed during page_free.
+       shared_page->pp_ref++;
+
+       // Inserted into every process's address space at UGDATA
+       page_insert(e->env_pgdir, shared_page, (void*)UGDATA, PTE_U | PTE_W);
+
        return 0;
 }