From b225b42f056026a30f00519f86e67f628eccb831 Mon Sep 17 00:00:00 2001 From: okuji Date: Wed, 22 May 2002 17:08:37 +0000 Subject: [PATCH] 2002-05-23 Yoshinori K. Okuji Define the behavior of the boot loader when the load end address and the bss end address are zero in the Multiboot Specification, and add the support into GRUB. I've modified a patch from Yuri Zaporogets . * stage2/boot.c (load_image): In the case of Multiboot a.out kludge, set the load end address to the load address plus the size of the OS image file, if it is zero. Similarly, set the bss end address to the load end address, if it is zero. * util/mbchk.c (check_multiboot): Don't check if the load address is greater than or equal to the load end address, if the load end address is zero. Don't check if the load end address is greater than the bss end address, if the bss end address is zero. And, don't check if the load end address is less than or equal to the entry address, if the load end address is zero. * docs/multiboot.texi (The address fields of Multiboot header): Added descriptions about the behavior of the boot loader when LOAD_END_ADDR is zero and BSS_END_ADDR is zero. --- ChangeLog | 23 +++++++++++++++++++++++ NEWS | 5 +++++ docs/multiboot.texi | 5 ++++- stage2/boot.c | 10 ++++++++++ util/mbchk.c | 10 ++++++---- 5 files changed, 48 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index b85012acb..3c42ba9b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2002-05-23 Yoshinori K. Okuji + + Define the behavior of the boot loader when the load end address + and the bss end address are zero in the Multiboot Specification, + and add the support into GRUB. I've modified a patch from Yuri + Zaporogets . + + * stage2/boot.c (load_image): In the case of Multiboot a.out + kludge, set the load end address to the load address plus the + size of the OS image file, if it is zero. Similarly, set the bss + end address to the load end address, if it is zero. + + * util/mbchk.c (check_multiboot): Don't check if the load + address is greater than or equal to the load end address, if the + load end address is zero. Don't check if the load end address is + greater than the bss end address, if the bss end address is + zero. And, don't check if the load end address is less than or + equal to the entry address, if the load end address is zero. + + * docs/multiboot.texi (The address fields of Multiboot header): + Added descriptions about the behavior of the boot loader when + LOAD_END_ADDR is zero and BSS_END_ADDR is zero. + 2002-05-22 Yoshinori K. Okuji * stage2/builtins.c (boot_func): If DEBUG is true, print diff --git a/NEWS b/NEWS index 44824e00c..275217ccb 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,10 @@ NEWS - list of user-visible changes between releases of GRUB +New in 0.93: +* Define the behavior of the boot loader when the load end address is + zero and the bss end address is zero in the Multiboot Specification. + Also, add the support into GRUB. + New in 0.92 - 2002-04-30: * The command "displaymem" uses only hex digits for consistency. * The netboot code goes back to the progress bars instead of dots, for diff --git a/docs/multiboot.texi b/docs/multiboot.texi index 97bbbd5fc..15ac005af 100644 --- a/docs/multiboot.texi +++ b/docs/multiboot.texi @@ -467,12 +467,15 @@ Contains the physical address of the end of the data segment. (load_end_addr - load_addr) specifies how much data to load. This implies that the text and data segments must be consecutive in the OS image; this is true for existing a.out executable formats. +If this field is zero, the boot loader assumes that the text and data +segments occupy the whole OS image file. @item bss_end_addr Contains the physical address of the end of the bss segment. The boot loader initializes this area to zero, and reserves the memory it occupies to avoid placing boot modules and other data relevant to the -operating system in that area. +operating system in that area. If this field is zero, the boot loader +assumes that no bss segment is present. @item entry_addr The physical address to which the boot loader should jump in order to diff --git a/stage2/boot.c b/stage2/boot.c index 466ce71bf..065bb2473 100644 --- a/stage2/boot.c +++ b/stage2/boot.c @@ -141,8 +141,18 @@ load_image (char *kernel, char *arg, kernel_t suggested_type, cur_addr = pu.mb->load_addr; /* first offset into file */ grub_seek (i - (pu.mb->header_addr - cur_addr)); + + /* If the load end address is zero, load the whole contents. */ + if (! pu.mb->load_end_addr) + pu.mb->load_end_addr = cur_addr + filemax; + text_len = pu.mb->load_end_addr - cur_addr; data_len = 0; + + /* If the bss end address is zero, assume that there is no bss area. */ + if (! pu.mb->bss_end_addr) + pu.mb->bss_end_addr = pu.mb->load_end_addr; + bss_len = pu.mb->bss_end_addr - pu.mb->load_end_addr; if (pu.mb->header_addr < pu.mb->load_addr diff --git a/util/mbchk.c b/util/mbchk.c index ee738e59c..d10e422c6 100644 --- a/util/mbchk.c +++ b/util/mbchk.c @@ -1,6 +1,6 @@ /* mbchk - a simple checker for the format of a Multiboot kernel */ /* - * Copyright (C) 1999, 2001 Free Software Foundation, Inc. + * Copyright (C) 1999,2001,2002 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -126,7 +126,7 @@ check_multiboot (const char *filename, FILE *fp) return 0; } - if (mbh->load_addr >= mbh->load_end_addr) + if (mbh->load_end_addr && mbh->load_addr >= mbh->load_end_addr) { fprintf (stderr, "%s: load_addr is not less than load_end_addr" @@ -135,7 +135,7 @@ check_multiboot (const char *filename, FILE *fp) return 0; } - if (mbh->load_end_addr > mbh->bss_end_addr) + if (mbh->bss_end_addr && mbh->load_end_addr > mbh->bss_end_addr) { fprintf (stderr, "%s: load_end_addr is greater than bss_end_addr" @@ -153,7 +153,9 @@ check_multiboot (const char *filename, FILE *fp) return 0; } - if (mbh->load_end_addr <= mbh->entry_addr) + /* FIXME: It is better to check if the entry address is within the + file, especially when the load end address is zero. */ + if (mbh->load_end_addr && mbh->load_end_addr <= mbh->entry_addr) { fprintf (stderr, "%s: load_end_addr is not less than entry_addr"