memdisk: New parameter (int15maxres) for specifying maximum RAM
authorGene Cumm <gene.cumm@gmail.com>
Sat, 5 Feb 2011 21:56:21 +0000 (16:56 -0500)
committerGene Cumm <gene.cumm@gmail.com>
Sat, 5 Feb 2011 21:56:21 +0000 (16:56 -0500)
Add a new parameter, int15maxres, for specifying (in decimal bytes) the
maximum amount of free RAM that different calls will return.  The RAM is
tagged in INT15h AXe820h as reserved in order to satisfy this.

memdisk/setup.c

index 4315189..bf3d5d6 100644 (file)
@@ -705,6 +705,39 @@ static int stack_needed(void)
   return v;
 }
 
+/*
+ * Specify max RAM by reservation
+ * Adds a reservation to data in INT15h to prevent access to the top of RAM
+ * if there's any above the point specified.
+ */
+void int15maxres(uint32_t restop)
+{
+    uint32_t ramtop;
+
+    if (high_mem) {
+       ramtop = high_mem + (1<<24);
+    } else if (low_mem) {
+       ramtop = low_mem + (1<<20);
+    } else {
+       ramtop = 0;
+    }
+
+    /* printf("  TOP RAM-%08x  RES-%08x", ramtop, restop); */
+    if (restop < ramtop) {
+       /* printf("  (A)"); */
+       insertrange(restop, (ramtop - restop), 3);
+       parse_mem();
+    }
+    if (high_mem) {
+       ramtop = high_mem + (1<<24);
+    } else if (low_mem) {
+       ramtop = low_mem + (1<<20);
+    } else {
+       ramtop = 0;
+    }
+    /* printf("    NOW RAM-%08x\n", ramtop); */
+}
+
 struct real_mode_args rm_args;
 
 /*
@@ -737,6 +770,7 @@ void setup(const struct real_mode_args *rm_args_ptr)
     int no_bpt;                        /* No valid BPT presented */
     uint32_t boot_seg = 0;     /* Meaning 0000:7C00 */
     uint32_t boot_len = 512;   /* One sector */
+    const char *p;
 
     /* We need to copy the rm_args into their proper place */
     memcpy(&rm_args, rm_args_ptr, sizeof rm_args);
@@ -942,6 +976,10 @@ void setup(const struct real_mode_args *rm_args_ptr)
        pptr->cd_pkt.geom3 = (uint8_t)(pptr->heads);
     }
 
+    if ((p = getcmditem("int15maxres")) != CMD_NOTFOUND) {
+       int15maxres(atou(p));
+    }
+
     /* The size is given by hptr->total_size plus the size of the E820
        map -- 12 bytes per range; we may need as many as 2 additional
        ranges (each insertrange() can worst-case turn 1 area into 3)