|
@@ -38,6 +38,35 @@ vaddr_t firstfree; /* first free virtual address; set by start.S */
|
|
|
static paddr_t firstpaddr; /* address of first free physical page */
|
|
|
static paddr_t lastpaddr; /* one past end of last free physical page */
|
|
|
|
|
|
+// vm stuffs
|
|
|
+extern struct coremap map;
|
|
|
+
|
|
|
+static void vmem_bootstrap(void)
|
|
|
+{
|
|
|
+ paddr_t min;
|
|
|
+ paddr_t max;
|
|
|
+ // size of ram available
|
|
|
+ ram_getsize(&min, &max);
|
|
|
+ // # of frames if we start here
|
|
|
+ map.framecount = (max - min) / PAGE_SIZE;
|
|
|
+ // start of the coremap array
|
|
|
+ map.num = (int *) PADDR_TO_KVADDR(min);
|
|
|
+ // min should start at a page start address (roundup), and be after the space for the array
|
|
|
+ min += ROUNDUP(map.framecount * sizeof(int), PAGE_SIZE);
|
|
|
+ // framecount needs to reflect the frames we took for the array of frames
|
|
|
+ map.framecount = (max - min) / PAGE_SIZE;
|
|
|
+ // set the start of actual virtual memory
|
|
|
+ map.start = min;
|
|
|
+ // set next frame to the start
|
|
|
+ map.next = 0;
|
|
|
+
|
|
|
+ // set all frames to empty
|
|
|
+ for (int i = 0; i < map.framecount; ++i)
|
|
|
+ {
|
|
|
+ map.num[i] = -1;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/*
|
|
|
* Called very early in system boot to figure out how much physical
|
|
|
* RAM is available.
|
|
@@ -54,7 +83,7 @@ ram_bootstrap(void)
|
|
|
* This is the same as the last physical address, as long as
|
|
|
* we have less than 508 megabytes of memory. If we had more,
|
|
|
* various annoying properties of the MIPS architecture would
|
|
|
- * force the RAM to be discontiguous. This is not a case we
|
|
|
+ * force the RAM to be discontiguous. This is not a case we
|
|
|
* are going to worry about.
|
|
|
*/
|
|
|
if (ramsize > 508*1024*1024) {
|
|
@@ -63,14 +92,17 @@ ram_bootstrap(void)
|
|
|
|
|
|
lastpaddr = ramsize;
|
|
|
|
|
|
- /*
|
|
|
+ /*
|
|
|
* Get first free virtual address from where start.S saved it.
|
|
|
* Convert to physical address.
|
|
|
*/
|
|
|
firstpaddr = firstfree - MIPS_KSEG0;
|
|
|
|
|
|
- kprintf("%uk physical memory available\n",
|
|
|
+ kprintf("%uk physical memory available\n",
|
|
|
(lastpaddr-firstpaddr)/1024);
|
|
|
+
|
|
|
+ // initialize VM
|
|
|
+ vmem_bootstrap();
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -88,7 +120,7 @@ ram_bootstrap(void)
|
|
|
* it's not a legal *allocatable* physical address, because it's the
|
|
|
* page with the exception handlers on it.
|
|
|
*
|
|
|
- * This function should not be called once the VM system is initialized,
|
|
|
+ * This function should not be called once the VM system is initialized,
|
|
|
* so it is not synchronized.
|
|
|
*/
|
|
|
paddr_t
|
|
@@ -114,7 +146,7 @@ ram_stealmem(unsigned long npages)
|
|
|
* initializes in order to find out what memory it has available to
|
|
|
* manage.
|
|
|
*
|
|
|
- * This function should not be called once the VM system is initialized,
|
|
|
+ * This function should not be called once the VM system is initialized,
|
|
|
* so it is not synchronized.
|
|
|
*/
|
|
|
void
|