From 1dfd43ac27873441d3c7abe6867acfcf2aa52cce Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Wed, 31 Aug 2011 22:01:59 +0000 Subject: [PATCH] boot e820 memory detection fixes --- boot/boot.h | 17 ----------------- boot/boot/Makefile | 2 +- boot/boot/boot.c | 18 ++++++++++++------ boot/boot/boothead.s | 37 ++++++++++++++++-------------------- boot/boot/bootimage.c | 1 + boot/boot/emem.h | 26 +++++++++++++++++++++++++ boot/minix.ack16.mk | 3 ++- common/include/minix/const.h | 2 +- servers/vm/vm.h | 2 +- 9 files changed, 60 insertions(+), 48 deletions(-) create mode 100644 boot/boot/emem.h diff --git a/boot/boot.h b/boot/boot.h index 50160ba25..27deb16a2 100644 --- a/boot/boot.h +++ b/boot/boot.h @@ -62,23 +62,6 @@ EXTERN u16_t cddevice; /* Drive that is CD if known. */ #define CDNAME "cd" /* Name of the CD device. */ -typedef struct { /* One chunk of free memory. */ - u32_t base; /* Start byte. */ - u32_t size; /* Number of bytes. */ -} memory; - -typedef struct { /* One chunk of free memory. */ - u32_t base_lo; /* Start byte. */ - u32_t base_hi; - u32_t size_lo; /* Number of bytes. */ - u32_t size_hi; /* Number of bytes. */ - u32_t type; - u32_t acpi_attrs; -} e820_memory; - -EXTERN memory mem[3]; /* List of available memory. */ -EXTERN e820_memory emem[16]; /* List of available memory. */ -EXTERN int mem_entries; EXTERN int mon_return; /* Monitor stays in memory? */ EXTERN int cdbooted; /* Did we boot from CD? (Set by boothead.s.) */ diff --git a/boot/boot/Makefile b/boot/boot/Makefile index 8a4c53770..39292b566 100644 --- a/boot/boot/Makefile +++ b/boot/boot/Makefile @@ -2,9 +2,9 @@ .include # XXX: Can only be built with ACK currently +MINIXID= -sep .include "${.CURDIR}/../minix.ack16.mk" AFLAGS+= -Was-ncc -#LDFLAGS+= -stack 12kb STRIPFLAG= -s LIBDIR?= /usr/lib/i86 diff --git a/boot/boot/boot.c b/boot/boot/boot.c index 4cf600dfe..79d82f4a6 100644 --- a/boot/boot/boot.c +++ b/boot/boot/boot.c @@ -41,6 +41,7 @@ char version[]= "2.20"; #undef EXTERN #define EXTERN /* Empty */ #include "boot.h" +#include "emem.h" #define arraysize(a) (sizeof(a) / sizeof((a)[0])) #define arraylimit(a) ((a) + arraysize(a)) @@ -548,14 +549,19 @@ static void initialize(void) u32_t dma64k; #endif - if (mem_entries) { + if (emem_entries) { int i, j; j = 0; - for(i = 0; i < mem_entries ; i++) { - if (j < 3 && emem[i].type == 1 && !emem[i].base_hi) { - mem[j].base = emem[i].base_lo; - mem[j].size = emem[i].size_lo; - j++; + for(i = 0; i < emem_entries ; i++) { + if (emem[i].type == 1 && + !emem[i].base_hi && !emem[i].size_hi) { + if(j < MEM_ENTRIES) { + mem[j].base = emem[i].base_lo; + mem[j].size = emem[i].size_lo; + j++; + } else { + printf("WARNING: boot skipping memory\n"); + } } } } diff --git a/boot/boot/boothead.s b/boot/boot/boothead.s index 01e203067..c2e0e6f01 100644 --- a/boot/boot/boothead.s +++ b/boot/boot/boothead.s @@ -1,3 +1,4 @@ +# ! Boothead.s - BIOS support for boot.c Author: Kees J. Bot ! ! @@ -32,12 +33,15 @@ SS_SELECTOR = 5*8 ! Monitor stack CS_SELECTOR = 6*8 ! Kernel code MCS_SELECTOR= 7*8 ! Monitor code + E820_MAGIC= 0x534D4150 ESC = 0x1B ! Escape character MB_BOOT_MAGIC = 0x2BADB002 ! Multiboot BootLoader Magic MULTIBOOT_STRUCT_ADDR = 0x9500 ! Multiboot Struct's Location +#include "emem.h" + ! Imported variables and functions: .extern _caddr, _daddr, _runsize, _edata, _end ! Runtime environment .extern _device ! BIOS device number @@ -45,7 +49,7 @@ .extern _k_flags ! Special kernel flags .extern _mem ! Free memory list .extern _emem ! Free memory list for E820 -.extern _mem_entries ! Free memory E820 list entries +.extern _emem_entries ! Free memory E820 list entries .extern _cdbooted ! Whether we booted from CD .extern _cddevice ! Whether we booted from CD .extern _do_multiboot ! Whether we are multibooting @@ -157,17 +161,17 @@ sepID: xor bx, bx ! zero EBX xor bp, bp !zero bp .data1 o32 - mov dx, e820_magic + mov dx, #E820_MAGIC .data1 o32 - mov cx, const_24 ! request 24 bytes + mov cx, #EMEM_SIZE ! request 24 bytes .data1 o32 - mov ax, const_0xe820 + mov ax, #0xE820 int 0x15 jc e820_failed .data1 o32 - mov dx, e820_magic + mov dx, #E820_MAGIC .data1 o32 cmp dx, ax jne e820_failed @@ -179,30 +183,30 @@ sepID: e820_next: .data1 o32 - mov ax, const_0xe820 + mov ax, #0xE820 mov 20(di), #1 ! force a valid ACPI 3.X entry .data1 o32 - mov cx, const_24 ! request 24 bytes + mov cx, #EMEM_SIZE ! request 24 bytes int 0x15 jc e820_done .data1 o32 - mov dx, e820_magic + mov dx, #E820_MAGIC e820_gotit: jcxz e820_skip - cmp bp, #16 - je e820_done ! we have only space for 16 entries + cmp bp, #EMEM_ENTRIES + je e820_done ! we have EMEM_ENTRIES storage inc bp - add di, #24 + add di, #EMEM_SIZE ! increase di for next entry e820_skip: .data1 o32 test bx, bx jne e820_next e820_done: - mov _mem_entries, bp + mov _emem_entries, bp jmp memory_detected e820_failed: @@ -251,7 +255,6 @@ no_ext: memory_detected: - ! Time to switch to a higher level language (not much higher) call _boot @@ -1620,14 +1623,6 @@ p_mcs_desc: .data2 0xFFFF, UNSET .data1 UNSET, 0x9A, 0x00, 0x00 -e820_magic: -! .data1 0x53, 0x4D, 0x41, 0x50 - .data1 0x50, 0x41, 0x4D, 0x53 -const_24: - .data1 0x18, 0x0, 0x0, 0x0 -const_0xe820: - .data2 0xe820 - .bss .comm old_vid_mode, 2 ! Video mode at startup diff --git a/boot/boot/bootimage.c b/boot/boot/bootimage.c index 3047ffda9..92d823594 100644 --- a/boot/boot/bootimage.c +++ b/boot/boot/bootimage.c @@ -26,6 +26,7 @@ #include #include "rawfs.h" #include "image.h" +#include "emem.h" #include "boot.h" #include diff --git a/boot/boot/emem.h b/boot/boot/emem.h new file mode 100644 index 000000000..3f863b6e9 --- /dev/null +++ b/boot/boot/emem.h @@ -0,0 +1,26 @@ + +#define EMEM_ENTRIES 16 +#define EMEM_SIZE 24 /* size in bytes of e820_memory struct */ +#define MEM_ENTRIES 3 + +#ifndef __ASSEMBLY__ + +typedef struct { /* One chunk of free memory. */ + u32_t base; /* Start byte. */ + u32_t size; /* Number of bytes. */ +} memory; + +EXTERN memory mem[MEM_ENTRIES]; /* List of available memory. */ + +typedef struct { /* One chunk of free memory. */ + u32_t base_lo; /* Start byte. */ + u32_t base_hi; + u32_t size_lo; /* Number of bytes. */ + u32_t size_hi; /* Number of bytes. */ + u32_t type; + u32_t acpi_attrs; +} e820_memory; + +EXTERN e820_memory emem[EMEM_ENTRIES]; /* List of available memory. */ +EXTERN int emem_entries; +#endif diff --git a/boot/minix.ack16.mk b/boot/minix.ack16.mk index f069894a5..04576027f 100644 --- a/boot/minix.ack16.mk +++ b/boot/minix.ack16.mk @@ -8,4 +8,5 @@ COMPILER_TYPE=ack OBJECT_FMT=a.out CPPFLAGS+= -mi86 AFLAGS+= -mi86 -LDFLAGS+= -mi86 -.o -com # no crtso, common I+D +LDFLAGS+= -mi86 -.o $(MINIXID) # no crtso +MINIXID?= -com # common I+D default diff --git a/common/include/minix/const.h b/common/include/minix/const.h index 892483172..24eb4fa28 100644 --- a/common/include/minix/const.h +++ b/common/include/minix/const.h @@ -103,7 +103,7 @@ * namely low mem below 1M, 1M-16M, and mem after 16M. More chunks are needed * for DOS MINIX. */ -#define NR_MEMS 8 +#define NR_MEMS 16 /* Click to byte conversions (and vice versa). */ diff --git a/servers/vm/vm.h b/servers/vm/vm.h index 85d218142..ce4ab1616 100644 --- a/servers/vm/vm.h +++ b/servers/vm/vm.h @@ -20,7 +20,7 @@ /* VM behaviour */ #define MEMPROTECT 0 /* Slab objects not mapped. Access with USE() */ -#define JUNKFREE 0 /* Fill freed pages with junk */ +#define JUNKFREE 1 /* Fill freed pages with junk */ #define NONCONTIGUOUS 0 /* Make phys pages max. noncontiguous */ /* How noisy are we supposed to be? */ -- 2.44.0