From 257062b1500733a1e27e59df2166edb8cc8bf9a9 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 30 Jan 2008 13:33:04 +0100 Subject: [PATCH] --- yaml --- r: 80251 b: refs/heads/master c: acd644bb4abb4d9f0ba6b9ec2b356263971ef9d0 h: refs/heads/master i: 80249: 5c337c260580d77c9443f42a29f839694876d77c 80247: 518336cf155df30c86719a03299a79a1e0ae9ffd v: v3 --- [refs] | 2 +- trunk/arch/x86/boot/main.c | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/[refs] b/[refs] index 0e20a41c2efd..548730be2d68 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 1a8514e04e3f0249a75f66225e99cdf48d305be7 +refs/heads/master: acd644bb4abb4d9f0ba6b9ec2b356263971ef9d0 diff --git a/trunk/arch/x86/boot/main.c b/trunk/arch/x86/boot/main.c index 22ca62ba40c8..7828da5cfd07 100644 --- a/trunk/arch/x86/boot/main.c +++ b/trunk/arch/x86/boot/main.c @@ -100,20 +100,32 @@ static void set_bios_mode(void) #endif } -void main(void) +static void init_heap(void) { - /* First, copy the boot header into the "zeropage" */ - copy_boot_params(); + char *stack_end; - /* End of heap check */ if (boot_params.hdr.loadflags & CAN_USE_HEAP) { - heap_end = (char *)(boot_params.hdr.heap_end_ptr - +0x200-STACK_SIZE); + asm("leal %P1(%%esp),%0" + : "=r" (stack_end) : "i" (-STACK_SIZE)); + + heap_end = (char *) + ((size_t)boot_params.hdr.heap_end_ptr + 0x200); + if (heap_end > stack_end) + heap_end = stack_end; } else { /* Boot protocol 2.00 only, no heap available */ puts("WARNING: Ancient bootloader, some functionality " "may be limited!\n"); } +} + +void main(void) +{ + /* First, copy the boot header into the "zeropage" */ + copy_boot_params(); + + /* End of heap check */ + init_heap(); /* Make sure we have all the proper CPU support */ if (validate_cpu()) {