a.out support for multiboot and freebsd
PATCH 1/1 a.out support for multiboot and freebsd
Hi,
This patch add a.out support for multiboot. It also support the boot2 loader (a.out format) of freebsd:
set root=(hd0,0,a)aout_freebsd /boot/loader
boot
2008-02-10 Bean <[email protected]>
* conf/i386-pc.rmk (pkglib_MODULES): Add aout.mod _aout_freebsd.mod and aout_freebsd.mod.
(aout_mod_SOURCES): New variable.
(aout_mod_CFLAGS): Likewise.
(aout_mod_LDFLAGS): Likewise.
(_aout_freebsd_mod_SOURCES): New variable. (_aout_freebsd_mod_CFLAGS): Likewise. (_aout_freebsd_mod_LDFLAGS): Likewise. (aout_freebsd_mod_SOURCES): New variable. (aout_freebsd_mod_CFLAGS): Likewise. (aout_freebsd_mod_LDFLAGS): Likewise.
* include/grub/aout.h: New file.
* include/grub/i386/loader.h (grub_freebsd_real_boot): New function. (grub_rescue_cmd_aout_freebsd): Likewise.
* kern/i386/loader.S (grub_freebsd_real_boot): New function.
* loader/aout.c: New file.
* loader/i386/pc/aout_freebsd.c: New file.
* loader/i386/pc/aout_freebsd_normal.c: New file.
* loader/i386/pc/multiboot.c (grub_multiboot): Handle a.out format.
conf/i386-pc.rmk +0 -0
@@ -146,7 +146,8 @@ pkglib_MODULES = biosdisk.mod _chain.mod
_linux.mod linux.mod normal.mod \
_multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod \
vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \
videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \
- ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod
+ ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \
+ aout.mod _aout_freebsd.mod aout_freebsd.mod
# For biosdisk.mod.
biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
@@ -298,4 +299,19 @@ lspci_mod_SOURCES = commands/lspci.c
lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS)
+# For aout.mod
+aout_mod_SOURCES = loader/aout.c
+aout_mod_CFLAGS = $(COMMON_CFLAGS)
+aout_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For _aout_freebsd.mod
+_aout_freebsd_mod_SOURCES = loader/i386/pc/aout_freebsd.c +_aout_freebsd_mod_CFLAGS = $(COMMON_CFLAGS) +_aout_freebsd_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For aout_freebsd.mod
+aout_freebsd_mod_SOURCES = loader/i386/pc/aout_freebsd_normal.c +aout_freebsd_mod_CFLAGS = $(COMMON_CFLAGS) +aout_freebsd_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
include $(srcdir)/conf/common.mk
include/grub/aout.h new file +91 -0
91 lines not on this page · raw message
include/grub/i386/loader.h +0 -0
@@ -39,10 +39,16 @@ void EXPORT_FUNC(grub_multiboot_real_boot)
(grub_addr_t entry,
void EXPORT_FUNC(grub_multiboot2_real_boot) (grub_addr_t entry,
struct grub_multiboot_info *mbi)
__attribute__ ((noreturn));
+void EXPORT_FUNC(grub_freebsd_real_boot) (grub_addr_t entry,
+ grub_uint32_t bootdrv,
+ void *bootinfo)
+ __attribute__ ((noreturn));
+
/* It is necessary to export these functions, because normal mode commands
reuse rescue mode commands. */
void grub_rescue_cmd_linux (int argc, char *argv[]);
void grub_rescue_cmd_initrd (int argc, char *argv[]);
+void grub_rescue_cmd_aout_freebsd (int argc, char *argv[]);
#endif /* ! GRUB_LOADER_CPU_HEADER */
kern/i386/loader.S +21 -0
@@ -162,3 +162,24 @@ FUNCTION(grub_multiboot2_real_boot) movl $MULTIBOOT2_BOOTLOADER_MAGIC,%eax popl %ecx jmp *%ecx + + +#define FREEBSD_RB_BOOTINFO 0x80000000 + +FUNCTION(grub_freebsd_real_boot) + pushl %ecx + xorl %ecx, %ecx + pushl %ecx + pushl %ecx + pushl %ecx + pushl %edx + pushl $FREEBSD_RB_BOOTINFO + pushl %eax + + call EXT_C(grub_dl_unload_all) + call EXT_C(grub_stop_floppy) + + cli + + popl %ecx + call *%ecx
loader/aout.c new file +61 -0
61 lines not on this page · raw message
loader/i386/pc/aout_freebsd.c new file +195 -0
195 lines not on this page · raw message
(quoted diff) +0 -0
b/loader/i386/pc/aout_freebsd_normal.c
new file mode 100755
index 0000000..d9e2b81
loader/i386/pc/aout_freebsd_normal.c new file +47 -0
47 lines not on this page · raw message
loader/i386/pc/multiboot.c +13 -1
@@ -36,6 +36,7 @@#include <grub/machine/init.h> #include <grub/machine/memory.h> #include <grub/elf.h> +#include <grub/aout.h> #include <grub/file.h> #include <grub/err.h> #include <grub/rescue.h>
@@ -315,7 +316,18 @@ grub_multiboot (int argc, char *argv[]) goto fail; } -if (grub_multiboot_load_elf (file, buffer) !=GRUB_ERR_NONE ) +if (header->flags &MULTIBOOT_AOUT_KLUDGE ) + { +if ((grub_aout_load (file, (char *) header - buffer, header->load_addr, + ((header->load_end_addr ==0 ) ?0 : + header->load_end_addr - header->load_addr), + header->bss_end_addr)) + !=GRUB_ERR_NONE ) + goto fail; + + entry = header->entry_addr; + } +else if (grub_multiboot_load_elf (file, buffer) !=GRUB_ERR_NONE ) goto fail; mbi =grub_malloc (sizeof (struct grub_multiboot_info ));
Signature · 1 line
Bean
Quoted 10 lines · Bean
Hi,
This patch add a.out support for multiboot. It also support the boot2 loader (a.out format) of freebsd:
set root=(hd0,0,a)
aout_freebsd/boot/loader
boot2008-02-10 Bean<[email protected]> ...
Hi Bean, and thanks for the patch. Unfortunately, the patch is malformed in at least two places and also has whitespace corruption. I did my best to edit the patch by hand until it seemed to apply okay, but I don't trust my results.
I have this same patch corruption problem with many of your posts. Can you change the way you attach patches somehow? Maybe change email client? Anyone else have a suggestion?
Bean, can you download your own patch from the mailing list and see if it will apply to your own code?
Thanks!
Quoted 17 lines · walt
Quoted 10 lines · Bean
Hi,
This patch add a.out support for multiboot. It also support the boot2 loader (a.out format) of freebsd:
set root=(hd0,0,a)
aout_freebsd/boot/loader
boot2008-02-10 Bean<[email protected]> ...
Hi Bean, and thanks for the patch. Unfortunately, the patch is malformed in at least two places and also has whitespace corruption. I did my best to edit the patch by hand until it seemed to apply okay, but I don't trust my results.
Quoted 6 lines
I have this same patch corruption problem with many of your posts. Can you change the way you attach patches somehow? Maybe change email client? Anyone else have a suggestion?
Bean, can you download your own patch from the mailing list and see if it will apply to your own code?
i'm using the web interface to send patch, maybe it cause some problem. here is the
raw diff file, it should be fine.
Signature · 1 line
Bean
conf/i386-pc.rmk +17 -1
@@ -146,7 +146,8 @@ pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \ _multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \ - ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod + ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \ + aout.mod _aout_freebsd.mod aout_freebsd.mod # For biosdisk.mod. biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
@@ -298,4 +299,19 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For aout.mod +aout_mod_SOURCES = loader/aout.c +aout_mod_CFLAGS = $(COMMON_CFLAGS) +aout_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For _aout_freebsd.mod +_aout_freebsd_mod_SOURCES = loader/i386/pc/aout_freebsd.c +_aout_freebsd_mod_CFLAGS = $(COMMON_CFLAGS) +_aout_freebsd_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For aout_freebsd.mod +aout_freebsd_mod_SOURCES = loader/i386/pc/aout_freebsd_normal.c +aout_freebsd_mod_CFLAGS = $(COMMON_CFLAGS) +aout_freebsd_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
include/grub/aout.h new file +91 -0
91 lines not on this page · raw message
include/grub/i386/loader.h +6 -0
@@ -39,10 +39,16 @@ void EXPORT_FUNC(grub_multiboot_real_boot) (grub_addr_t entry,void EXPORT_FUNC (grub_multiboot2_real_boot ) (grub_addr_t entry,struct grub_multiboot_info *mbi) __attribute__ ((noreturn)); +void EXPORT_FUNC (grub_freebsd_real_boot ) (grub_addr_t entry, +grub_uint32_t bootdrv, +void *bootinfo) + __attribute__ ((noreturn)); +/* It is necessary to export these functions, because normal mode commands reuse rescue mode commands. */ void grub_rescue_cmd_linux (int argc,char *argv[]);void grub_rescue_cmd_initrd (int argc,char *argv[]); +void grub_rescue_cmd_aout_freebsd (int argc,char *argv[]);#endif /* ! GRUB_LOADER_CPU_HEADER */
kern/i386/loader.S +21 -0
@@ -162,3 +162,24 @@ FUNCTION(grub_multiboot2_real_boot) movl $MULTIBOOT2_BOOTLOADER_MAGIC,%eax popl %ecx jmp *%ecx + + +#define FREEBSD_RB_BOOTINFO 0x80000000 + +FUNCTION(grub_freebsd_real_boot) + pushl %ecx + xorl %ecx, %ecx + pushl %ecx + pushl %ecx + pushl %ecx + pushl %edx + pushl $FREEBSD_RB_BOOTINFO + pushl %eax + + call EXT_C(grub_dl_unload_all) + call EXT_C(grub_stop_floppy) + + cli + + popl %ecx + call *%ecx
loader/aout.c new file +61 -0
61 lines not on this page · raw message
loader/i386/pc/aout_freebsd.c new file +195 -0
195 lines not on this page · raw message
loader/i386/pc/aout_freebsd_normal.c new file +47 -0
47 lines not on this page · raw message
loader/i386/pc/multiboot.c +13 -1
@@ -36,6 +36,7 @@#include <grub/machine/init.h> #include <grub/machine/memory.h> #include <grub/elf.h> +#include <grub/aout.h> #include <grub/file.h> #include <grub/err.h> #include <grub/rescue.h>
@@ -315,7 +316,18 @@ grub_multiboot (int argc, char *argv[]) goto fail; } -if (grub_multiboot_load_elf (file, buffer) !=GRUB_ERR_NONE ) +if (header->flags &MULTIBOOT_AOUT_KLUDGE ) + { +if ((grub_aout_load (file, (char *) header - buffer, header->load_addr, + ((header->load_end_addr ==0 ) ?0 : + header->load_end_addr - header->load_addr), + header->bss_end_addr)) + !=GRUB_ERR_NONE ) + goto fail; + + entry = header->entry_addr; + } +else if (grub_multiboot_load_elf (file, buffer) !=GRUB_ERR_NONE ) goto fail; mbi =grub_malloc (sizeof (struct grub_multiboot_info ));
Quoted 21 lines · Bean
Quoted 20 lines · walt
Quoted 10 lines · Bean
Hi,
This patch add a.out support for multiboot. It also support the boot2 loader (a.out format) of freebsd:
set root=(hd0,0,a)
aout_freebsd/boot/loader
boot2008-02-10 Bean<[email protected]> ...
Hi Bean, and thanks for the patch. Unfortunately, the patch is malformed in at least two places and also has whitespace corruption. I did my best to edit the patch by hand until it seemed to apply okay, but I don't trust my results.
I have this same patch corruption problem with many of your posts. Can you change the way you attach patches somehow? Maybe change email client? Anyone else have a suggestion?
Quoted 6 lines
Quoted 2 lines
Bean, can you download your own patch from the mailing list and see if it will apply to your own code?
i'm using the web interface to send patch, maybe it cause some problem. here is the
raw diff file, it should be fine.
Hi,
I looked differences of your patch attachments as compared with others that seems to be working nicely. When you copy'n'paste they will get broken.
Here is example from my message (mail client was Thunderbird):
Content-Type: text/plain;
name="unknown_glyph.diff"
Content-Disposition: inline;
filename="unknown_glyph.diff"
Content-Transfer-Encoding: Base64
And here is example from your email:
Content-Type: application/octet-stream; name=a3.diff
Content-Transfer-Encoding: base64
X-Attachment-Id: f_fch5ujm00
Content-Disposition: attachment; filename=a3.diff
With a quick check, gmail indeed does send them as binary as default when using Opera. Then I configured Opera to understand diff files (eg. that they are "text/plain"), after that gmail sent patches nicely. Perhaps you could add new MIME type to your web browser to handle "diff" file extesions as "text/plain"?
Thanks,
Vesa Jääskeläinen
Quoted 51 lines · Vesa Jääskeläinen
Quoted 21 lines · Bean
Quoted 20 lines · walt
Quoted 10 lines · Bean
Hi,
This patch add a.out support for multiboot. It also support the boot2 loader (a.out format) of freebsd:
set root=(hd0,0,a)
aout_freebsd/boot/loader
boot2008-02-10 Bean<[email protected]> ...
Hi Bean, and thanks for the patch. Unfortunately, the patch is malformed in at least two places and also has whitespace corruption. I did my best to edit the patch by hand until it seemed to apply okay, but I don't trust my results.
I have this same patch corruption problem with many of your posts. Can you change the way you attach patches somehow? Maybe change email client? Anyone else have a suggestion?
Quoted 6 lines
Quoted 2 lines
Bean, can you download your own patch from the mailing list and see if it will apply to your own code?
i'm using the web interface to send patch, maybe it cause some problem. here is the
raw diff file, it should be fine.Hi,
I looked differences of your patch attachments as compared with others that seems to be working nicely. When you copy'n'paste they will get broken.
Here is example from my message (mail client was Thunderbird):
Content-Type: text/plain;
name="unknown_glyph.diff"
Content-Disposition: inline;
filename="unknown_glyph.diff"
Content-Transfer-Encoding: Base64And here is example from your email:
Content-Type: application/octet-stream; name=a3.diff
Content-Transfer-Encoding: base64
X-Attachment-Id:f_fch5ujm00
Content-Disposition: attachment; filename=a3.diff
Quoted 5 lines
With a quick check, gmail indeed does send them as binary as default when using Opera. Then I configured Opera to understand diff files (eg. that they are "text/plain"), after that gmail sent patches nicely. Perhaps you could add new MIME type to your web browser to handle "diff" file extesions as "text/plain"?
I'm using firefox, is there a way to add MIME types ? or maybe i can rename the patch files as *.txt.
Signature · 1 line
Bean
Quoted 7 lines · Bean
Quoted 6 lines · walt
Quoted 5 lines · Bean
Hi,
This patch add a.out support for multiboot. It also support the boot2 loader (a.out format) of freebsd:
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
set root=(hd0,0,a)
aout_freebsd/boot/loader
boot...
i'm using the web interface to send patch, maybe it cause some problem. here is the raw diff file, it should be fine.
Yes, the patch is perfect this time, thanks. I'm still seeing two (small?) problems with aout /boot/loader.
The FreeBSD loader has a variable 'currdev' that is not being set correctly. 'currdev' must point to the partition containing /boot/kernel, otherwise loader will say "can't load 'kernel'". If I use the loader interactive shell to set currdev to the correct partition then it will boot the kernel correctly.
Well, almost correctly :o) The second problem is that once the kernel starts running, the console never shows the normal dmesg messages. I thought the kernel had died or rebooted until I saw the normal login prompt finally appear. Is this maybe some setting for the console that I can change in grub2 before starting loader?
Thanks for all your time and help with this!
Hi,
The following patch support freebsd a.out and elf, now you can load the kernel directly.
1. Boot through loader:
set root=(hd0,0,a)
freebsd /boot/loader
It should be able to deduce the root device from the root variable.
2. Booting directly:
freebsd (hd0,0,a)/boot/kernel/kernelfreebsd_loadenv (hd0,0,a)/boot/devices.hints
set FreeBSD.vfs.root.mountfrom=ufs:ad0s1a
environment variable for FreeBSD has the FreeBSD. prefix, the prefix is removed before jumping to kernel code.
Please note that you need to set root device explicitly using vfs.root.mountfrom.
Signature · 1 line
Bean
conf/i386-pc.rmk +17 -1
@@ -146,7 +146,8 @@ pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \ _multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \ - ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod + ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \ + aout.mod _freebsd.mod freebsd.mod # For biosdisk.mod. biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
@@ -298,4 +299,19 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For aout.mod +aout_mod_SOURCES = loader/aout.c +aout_mod_CFLAGS = $(COMMON_CFLAGS) +aout_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For _freebsd.mod +_freebsd_mod_SOURCES = loader/i386/pc/freebsd.c +_freebsd_mod_CFLAGS = $(COMMON_CFLAGS) +_freebsd_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For freebsd.mod +freebsd_mod_SOURCES = loader/i386/pc/freebsd_normal.c +freebsd_mod_CFLAGS = $(COMMON_CFLAGS) +freebsd_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
include/grub/aout.h new file +91 -0
91 lines not on this page · raw message
include/grub/i386/loader.h +7 -0
@@ -39,10 +39,17 @@ void EXPORT_FUNC(grub_multiboot_real_boot) (grub_addr_t entry,void EXPORT_FUNC (grub_multiboot2_real_boot ) (grub_addr_t entry,struct grub_multiboot_info *mbi) __attribute__ ((noreturn)); +void EXPORT_FUNC (grub_freebsd_real_boot ) (grub_addr_t entry, +grub_uint32_t bootdrv, +void *bootinfo) + __attribute__ ((noreturn)); +/* It is necessary to export these functions, because normal mode commands reuse rescue mode commands. */ void grub_rescue_cmd_linux (int argc,char *argv[]);void grub_rescue_cmd_initrd (int argc,char *argv[]); +void grub_rescue_cmd_freebsd (int argc,char *argv[]); +void grub_rescue_cmd_freebsd_loadenv (int argc,char *argv[]);#endif /* ! GRUB_LOADER_CPU_HEADER */
kern/elf.c +2 -2
@@ -228,9 +228,9 @@ grub_elf32_load (grub_elf_t _elf, grub_elf32_load_hook_t _load_hook,if (phdr->p_type !=PT_LOAD )return 0 ; - load_addr = phdr->p_paddr;if (load_hook &&load_hook (phdr, &load_addr))return 1 ; + load_addr = phdr->p_paddr;if (load_addr < load_base) load_base = load_addr;
@@ -407,9 +407,9 @@ grub_elf64_load (grub_elf_t _elf, grub_elf64_load_hook_t _load_hook,if (phdr->p_type !=PT_LOAD )return 0 ; - load_addr = phdr->p_paddr;if (load_hook &&load_hook (phdr, &load_addr))return 1 ; + load_addr = phdr->p_paddr;if (load_addr < load_base) load_base = load_addr;
kern/i386/loader.S +21 -0
@@ -162,3 +162,24 @@ FUNCTION(grub_multiboot2_real_boot) movl $MULTIBOOT2_BOOTLOADER_MAGIC,%eax popl %ecx jmp *%ecx + + +#define FREEBSD_RB_BOOTINFO 0x80000000 + +FUNCTION(grub_freebsd_real_boot) + pushl %ecx + xorl %ecx, %ecx + pushl %ecx + pushl %ecx + pushl %ecx + pushl %edx + pushl $FREEBSD_RB_BOOTINFO + pushl %eax + + call EXT_C(grub_dl_unload_all) + call EXT_C(grub_stop_floppy) + + cli + + popl %ecx + call *%ecx
loader/aout.c new file +61 -0
61 lines not on this page · raw message
loader/i386/pc/freebsd.c new file +361 -0
361 lines not on this page · raw message
loader/i386/pc/freebsd_normal.c new file +60 -0
60 lines not on this page · raw message
loader/i386/pc/multiboot.c +13 -1
@@ -36,6 +36,7 @@#include <grub/machine/init.h> #include <grub/machine/memory.h> #include <grub/elf.h> +#include <grub/aout.h> #include <grub/file.h> #include <grub/err.h> #include <grub/rescue.h>
@@ -315,7 +316,18 @@ grub_multiboot (int argc, char *argv[]) goto fail; } -if (grub_multiboot_load_elf (file, buffer) !=GRUB_ERR_NONE ) +if (header->flags &MULTIBOOT_AOUT_KLUDGE ) + { +if ((grub_aout_load (file, (char *) header - buffer, header->load_addr, + ((header->load_end_addr ==0 ) ?0 : + header->load_end_addr - header->load_addr), + header->bss_end_addr)) + !=GRUB_ERR_NONE ) + goto fail; + + entry = header->entry_addr; + } +else if (grub_multiboot_load_elf (file, buffer) !=GRUB_ERR_NONE ) goto fail; mbi =grub_malloc (sizeof (struct grub_multiboot_info ));
Quoted 11 lines · Bean
Hi,
The following patch support freebsd a.out and elf, now you can load the kernel directly.
1. Boot through loader:
set root=(hd0,0,a)
freebsd/boot/loaderIt should be able to deduce the root device from the root variable.
I still see currdev=disk0s1c but that should be s1a, not s1c.
Quoted 3 lines
2. Booting directly:
freebsd (hd0,0,a)/boot/kernel/kernel
At this point I see 'broken magic at 0x6b30'. I'm running FreeBSD CURRENT, not stable. Could that be the problem?
Quoted 6 lines · walt
Quoted 5 lines · Bean
Hi,
The following patch support freebsd a.out and elf, now you can load the kernel directly.
Quoted 8 lines
Quoted 6 lines
1. Boot through loader:
set root=(hd0,0,a)
freebsd/boot/loaderIt should be able to deduce the root device from the root variable.
I still see currdev=disk0s1c but that should be s1a, not s1c.
i found a small bug in the root device calculation, the new patch below should be ok.
Quoted 6 lines
Quoted 3 lines
2. Booting directly:
freebsd (hd0,0,a)/boot/kernel/kernelAt this point I see 'broken magic at
0x6b30'. I'm running FreeBSD CURRENT, not stable. Could that be the problem?
I'm testing FreeBSD 6.3, the 7 series haven't been tried yet. Perhaps you can upload the kernel file somewhere for me to check.
The patch also contain incomplete support for openbsd kernel, it's not working yet, you can just ignore it.
Signature · 1 line
Bean
conf/i386-pc.rmk +17 -1
@@ -146,7 +146,8 @@ pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \ _multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \ - ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod + ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \ + aout.mod _freebsd.mod freebsd.mod # For biosdisk.mod. biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
@@ -298,4 +299,19 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For aout.mod +aout_mod_SOURCES = loader/aout.c +aout_mod_CFLAGS = $(COMMON_CFLAGS) +aout_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For _freebsd.mod +_freebsd_mod_SOURCES = loader/i386/pc/freebsd.c +_freebsd_mod_CFLAGS = $(COMMON_CFLAGS) +_freebsd_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For freebsd.mod +freebsd_mod_SOURCES = loader/i386/pc/freebsd_normal.c +freebsd_mod_CFLAGS = $(COMMON_CFLAGS) +freebsd_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
include/grub/aout.h new file +91 -0
91 lines not on this page · raw message
include/grub/i386/bsd.h new file +131 -0
131 lines not on this page · raw message
include/grub/i386/loader.h +6 -0
@@ -39,10 +39,16 @@ void EXPORT_FUNC(grub_multiboot_real_boot) (grub_addr_t entry,void EXPORT_FUNC (grub_multiboot2_real_boot ) (grub_addr_t entry,struct grub_multiboot_info *mbi) __attribute__ ((noreturn)); +void EXPORT_FUNC (grub_unix_real_boot ) (grub_addr_t entry, ...) + __attribute__ ((cdecl,noreturn)); +/* It is necessary to export these functions, because normal mode commands reuse rescue mode commands. */ void grub_rescue_cmd_linux (int argc,char *argv[]);void grub_rescue_cmd_initrd (int argc,char *argv[]); +void grub_rescue_cmd_freebsd (int argc,char *argv[]); +void grub_rescue_cmd_freebsd_loadenv (int argc,char *argv[]); +void grub_rescue_cmd_openbsd (int argc,char *argv[]);#endif /* ! GRUB_LOADER_CPU_HEADER */
kern/elf.c +2 -2
@@ -228,9 +228,9 @@ grub_elf32_load (grub_elf_t _elf, grub_elf32_load_hook_t _load_hook,if (phdr->p_type !=PT_LOAD )return 0 ; - load_addr = phdr->p_paddr;if (load_hook &&load_hook (phdr, &load_addr))return 1 ; + load_addr = phdr->p_paddr;if (load_addr < load_base) load_base = load_addr;
@@ -407,9 +407,9 @@ grub_elf64_load (grub_elf_t _elf, grub_elf64_load_hook_t _load_hook,if (phdr->p_type !=PT_LOAD )return 0 ; - load_addr = phdr->p_paddr;if (load_hook &&load_hook (phdr, &load_addr))return 1 ; + load_addr = phdr->p_paddr;if (load_addr < load_base) load_base = load_addr;
kern/i386/loader.S +11 -0
@@ -162,3 +162,14 @@ FUNCTION(grub_multiboot2_real_boot) movl $MULTIBOOT2_BOOTLOADER_MAGIC,%eax popl %ecx jmp *%ecx + + +FUNCTION(grub_unix_real_boot) + call EXT_C(grub_dl_unload_all) + call EXT_C(grub_stop_floppy) + + cli + + popl %eax + popl %eax + call *%eax
loader/aout.c new file +61 -0
61 lines not on this page · raw message
loader/i386/pc/freebsd.c new file +430 -0
430 lines not on this page · raw message
loader/i386/pc/freebsd_normal.c new file +74 -0
74 lines not on this page · raw message
loader/i386/pc/multiboot.c +17 -1
@@ -36,6 +36,7 @@#include <grub/machine/init.h> #include <grub/machine/memory.h> #include <grub/elf.h> +#include <grub/aout.h> #include <grub/file.h> #include <grub/err.h> #include <grub/rescue.h>
@@ -315,7 +316,22 @@ grub_multiboot (int argc, char *argv[]) goto fail; } -if (grub_multiboot_load_elf (file, buffer) !=GRUB_ERR_NONE ) +if (header->flags &MULTIBOOT_AOUT_KLUDGE ) + { +int ofs; + + ofs = (char *) header - buffer - + (header->header_addr - header->load_addr); +if ((grub_aout_load (file, ofs, header->load_addr, + ((header->load_end_addr ==0 ) ?0 : + header->load_end_addr - header->load_addr), + header->bss_end_addr)) + !=GRUB_ERR_NONE ) + goto fail; + + entry = header->entry_addr; + } +else if (grub_multiboot_load_elf (file, buffer) !=GRUB_ERR_NONE ) goto fail; mbi =grub_malloc (sizeof (struct grub_multiboot_info ));
Hi,
Change in this patch:
1. support OpenBSD kernel:
set root=(hd0,3,a)
openbsd /bsd
The modules name is changed to bsd.mod.
2. Support setting kernel flags
one character represent one flag, for FreeBSD, it's "DhaCcdgmnpqrsv", for OpenBSD, it's "abcsd".
for example, to enable ask for root device name, single user mode and verbose output in FreeBSD:
set root=(hd0,2,a)
freebsd /boot/loader asv
Signature · 1 line
Bean
Quoted 13 lines · Bean
Hi,
Change in this patch:
1. support OpenBSD kernel:
set root=(hd0,3,a)
openbsd /bsdThe modules name is changed to bsd.mod.
2. Support setting kernel flags
Quoted 8 lines
one character represent one flag, for FreeBSD, it's "DhaCcdgmnpqrsv", for OpenBSD, it's "abcsd".
for example, to enable ask for root device name, single user mode and verbose output in FreeBSD:
set root=(hd0,2,a)
freebsd/boot/loaderasv
sorry, forget the patch.
Signature · 1 line
Bean
conf/i386-pc.rmk +17 -1
@@ -146,7 +146,8 @@ pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \ _multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \ - ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod + ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \ + aout.mod _bsd.mod bsd.mod # For biosdisk.mod. biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
@@ -298,4 +299,19 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For aout.mod +aout_mod_SOURCES = loader/aout.c +aout_mod_CFLAGS = $(COMMON_CFLAGS) +aout_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For _freebsd.mod +_bsd_mod_SOURCES = loader/i386/pc/bsd.c +_bsd_mod_CFLAGS = $(COMMON_CFLAGS) +_bsd_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For freebsd.mod +bsd_mod_SOURCES = loader/i386/pc/bsd_normal.c +bsd_mod_CFLAGS = $(COMMON_CFLAGS) +bsd_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
include/grub/aout.h new file +91 -0
91 lines not on this page · raw message
include/grub/i386/bsd.h new file +137 -0
137 lines not on this page · raw message
include/grub/i386/loader.h +3 -0
@@ -39,6 +39,9 @@ void EXPORT_FUNC(grub_multiboot_real_boot) (grub_addr_t entry,void EXPORT_FUNC (grub_multiboot2_real_boot ) (grub_addr_t entry,struct grub_multiboot_info *mbi) __attribute__ ((noreturn)); +void EXPORT_FUNC (grub_unix_real_boot ) (grub_addr_t entry, ...) + __attribute__ ((cdecl,noreturn)); +/* It is necessary to export these functions, because normal mode commands reuse rescue mode commands. */
include/grub/i386/pc/init.h +1 -1
@@ -40,7 +40,7 @@ struct grub_machine_mmap_entry/* Get a memory map entry. Return next continuation value. Zero means the end. */ -grub_uint32_t grub_get_mmap_entry (struct grub_machine_mmap_entry *entry, +grub_uint32_t EXPORT_FUNC (grub_get_mmap_entry ) (struct grub_machine_mmap_entry *entry,grub_uint32_t cont);/* Turn on/off Gate A20. */
kern/elf.c +2 -2
@@ -228,9 +228,9 @@ grub_elf32_load (grub_elf_t _elf, grub_elf32_load_hook_t _load_hook,if (phdr->p_type !=PT_LOAD )return 0 ; - load_addr = phdr->p_paddr;if (load_hook &&load_hook (phdr, &load_addr))return 1 ; + load_addr = phdr->p_paddr;if (load_addr < load_base) load_base = load_addr;
@@ -407,9 +407,9 @@ grub_elf64_load (grub_elf_t _elf, grub_elf64_load_hook_t _load_hook,if (phdr->p_type !=PT_LOAD )return 0 ; - load_addr = phdr->p_paddr;if (load_hook &&load_hook (phdr, &load_addr))return 1 ; + load_addr = phdr->p_paddr;if (load_addr < load_base) load_base = load_addr;
kern/i386/loader.S +11 -0
@@ -162,3 +162,14 @@ FUNCTION(grub_multiboot2_real_boot) movl $MULTIBOOT2_BOOTLOADER_MAGIC,%eax popl %ecx jmp *%ecx + + +FUNCTION(grub_unix_real_boot) + call EXT_C(grub_dl_unload_all) + call EXT_C(grub_stop_floppy) + + cli + + popl %eax + popl %eax + call *%eax
loader/aout.c new file +61 -0
61 lines not on this page · raw message
loader/i386/pc/bsd.c new file +481 -0
481 lines not on this page · raw message
loader/i386/pc/bsd_normal.c new file +71 -0
71 lines not on this page · raw message
loader/i386/pc/multiboot.c +17 -1
@@ -36,6 +36,7 @@#include <grub/machine/init.h> #include <grub/machine/memory.h> #include <grub/elf.h> +#include <grub/aout.h> #include <grub/file.h> #include <grub/err.h> #include <grub/rescue.h>
@@ -315,7 +316,22 @@ grub_multiboot (int argc, char *argv[]) goto fail; } -if (grub_multiboot_load_elf (file, buffer) !=GRUB_ERR_NONE ) +if (header->flags &MULTIBOOT_AOUT_KLUDGE ) + { +int ofs; + + ofs = (char *) header - buffer - + (header->header_addr - header->load_addr); +if ((grub_aout_load (file, ofs, header->load_addr, + ((header->load_end_addr ==0 ) ?0 : + header->load_end_addr - header->load_addr), + header->bss_end_addr)) + !=GRUB_ERR_NONE ) + goto fail; + + entry = header->entry_addr; + } +else if (grub_multiboot_load_elf (file, buffer) !=GRUB_ERR_NONE ) goto fail; mbi =grub_malloc (sizeof (struct grub_multiboot_info ));
conf/i386-pc.rmk lspci_mod_SOURCES = commands/lspci.c · line 308
Quoted 2 lines · Bean
conf/i386-pc.rmk +2
-0+# For _freebsd.mod +_bsd_mod_SOURCES = loader/i386/pc/bsd.c
You forgot to rename the commend ;-)
conf/i386-pc.rmk lspci_mod_SOURCES = commands/lspci.c · line 315
Quoted 7 lines
conf/i386-pc.rmk +7
-0+_bsd_mod_CFLAGS = $(COMMON_CFLAGS) +_bsd_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For freebsd.mod +bsd_mod_SOURCES = loader/i386/pc/bsd_normal.c +bsd_mod_CFLAGS = $(COMMON_CFLAGS) +bsd_mod_LDFLAGS = $(COMMON_LDFLAGS)
How much pc-dependant are those? Can we hope they will work in e.g. i386-coreboot in the future, when *BSD kernels remove their BIOS dependency?
Quoted 12 lines
include/grub/i386/bsd.h new file +12
-0+#define FREEBSD_RB_ASKNAME 0x1/* ask for file name to reboot from */ +#define FREEBSD_RB_SINGLE 0x2/* reboot to single user only */ +#define FREEBSD_RB_NOSYNC 0x4/* dont sync before reboot */ +#define FREEBSD_RB_HALT 0x8/* don't reboot, just halt */ +#define FREEBSD_RB_INITNAME 0x10/* name given for /etc/init (unused) */ +#define FREEBSD_RB_DFLTROOT 0x20/* use compiled-in rootdev */ +#define FREEBSD_RB_KDB 0x40/* give control to kernel debugger */ +#define FREEBSD_RB_RDONLY 0x80/* mount root fs read-only */ +#define FREEBSD_RB_DUMP 0x100/* dump kernel memory before reboot */ +#define FREEBSD_RB_MINIROOT 0x200/* mini-root present in memory at boot time */ +#define FREEBSD_RB_CONFIG 0x400/* invoke user configuration routing */ +#define FREEBSD_RB_VERBOSE 0x800/* print all potentially useful info */
include/grub/i386/bsd.h line 49
Quoted 10 lines
include/grub/i386/bsd.h new file +10
-0+#define FREEBSD_RB_SERIAL 0x1000/* user serial port as console */ +#define FREEBSD_RB_CDROM 0x2000/* use cdrom as root */ +#define FREEBSD_RB_GDB 0x8000/* use GDB remote debugger instead of DDB */ +#define FREEBSD_RB_MUTE 0x10000/* Come up with the console muted */ +#define FREEBSD_RB_PAUSE 0x100000 +#define FREEBSD_RB_QUIET 0x200000 +#define FREEBSD_RB_NOINTR 0x10000000 +#define FREENSD_RB_MULTIPLE 0x20000000/* Use multiple consoles */ +#define FREEBSD_RB_DUAL FREENSD_RB_MULTIPLE +#define FREEBSD_RB_BOOTINFO 0x80000000/* have `struct bootinfo *' arg */
Usually we have "(1 << 0)", "(1 << 1)", etc for bitmask lists.
kern/i386/loader.S FUNCTION(grub_multiboot2_real_boot) · line 175
Quoted 9 lines
kern/i386/loader.S +9
-0+FUNCTION(grub_unix_real_boot) + call EXT_C(grub_dl_unload_all) + call EXT_C(grub_stop_floppy) + + cli + + popl %eax + popl %eax + call *%eax
Why a call? Do we need the return address in the stack here? A comment would be nice in that case.
loader/i386/pc/bsd.c line 36
Quoted 2 lines
loader/i386/pc/bsd.c new file +2
-0+#define ALIGN_DWORD (a) ((a + 3) & (~3)) +#define ALIGN_PAGE (a) ((a + 4095) & (~4095))
We already have ALIGN_UP:
./include/grub/misc.h:#define ALIGN_UP(addr, align) ((long)((char *)addr + align - 1) & ~(align - 1))
it'd be better to reuse that, I think.
loader/i386/pc/bsd.c line 50
Quoted 7 lines
loader/i386/pc/bsd.c new file +7
-0+static const grub_uint32_t freebsd_flags[] = { +FREEBSD_RB_DUAL ,FREEBSD_RB_SERIAL ,FREEBSD_RB_ASKNAME , +FREEBSD_RB_CDROM ,FREEBSD_RB_CONFIG ,FREEBSD_RB_KDB , +FREEBSD_RB_GDB ,FREEBSD_RB_MUTE ,FREEBSD_RB_NOINTR , +FREEBSD_RB_PAUSE ,FREEBSD_RB_QUIET ,FREEBSD_RB_DFLTROOT , +FREEBSD_RB_SINGLE ,FREEBSD_RB_VERBOSE +};
We usually put a newline after the '='.
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call… if you are unable to speak? (as seen on /.)
Quoted 5 lines · Robert Millan
conf/i386-pc.rmk lspci_mod_SOURCES = commands/lspci.c · line 308
Quoted 2 lines · Bean
conf/i386-pc.rmk +2
-0+# For _freebsd.mod +_bsd_mod_SOURCES = loader/i386/pc/bsd.cYou forgot to rename the commend ;-)
oh, yes.
Quoted 12 lines
conf/i386-pc.rmk lspci_mod_SOURCES = commands/lspci.c · line 315
Quoted 8 lines
conf/i386-pc.rmk +7
-0+_bsd_mod_CFLAGS = $(COMMON_CFLAGS) +_bsd_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For freebsd.mod +bsd_mod_SOURCES = loader/i386/pc/bsd_normal.c +bsd_mod_CFLAGS = $(COMMON_CFLAGS) +bsd_mod_LDFLAGS = $(COMMON_LDFLAGS)How much pc-dependant are those? Can we hope they will work in e.g. i386-coreboot in the future, when *BSD kernels remove their BIOS dependency?
freebsd doesn't need bios at all, openbsd need the memory map, but i guess it's easy to construct one without using int 15.
Quoted 17 lines
Quoted 17 lines
include/grub/i386/bsd.h new file +16
-0+#define FREEBSD_RB_ASKNAME 0x1/* ask for file name to reboot from */ +#define FREEBSD_RB_SINGLE 0x2/* reboot to single user only */ +#define FREEBSD_RB_NOSYNC 0x4/* dont sync before reboot */ +#define FREEBSD_RB_HALT 0x8/* don't reboot, just halt */ +#define FREEBSD_RB_INITNAME 0x10/* name given for /etc/init (unused) */ +#define FREEBSD_RB_DFLTROOT 0x20/* use compiled-in rootdev */ +#define FREEBSD_RB_KDB 0x40/* give control to kernel debugger */ +#define FREEBSD_RB_RDONLY 0x80/* mount root fs read-only */ +#define FREEBSD_RB_DUMP 0x100/* dump kernel memory before reboot */ +#define FREEBSD_RB_MINIROOT 0x200/* mini-root present in memory at boot time */ +#define FREEBSD_RB_CONFIG 0x400/* invoke user configuration routing */ +#define FREEBSD_RB_VERBOSE 0x800/* print all potentially useful info */ +#define FREEBSD_RB_SERIAL 0x1000/* user serial port as console */ +#define FREEBSD_RB_CDROM 0x2000/* use cdrom as root */ +#define FREEBSD_RB_GDB 0x8000/* use GDB remote debugger instead of DDB */ +#define FREEBSD_RB_MUTE 0x10000/* Come up with the console muted */
Quoted 8 lines
include/grub/i386/bsd.h line 49
Quoted 6 lines
include/grub/i386/bsd.h new file +6
-0+#define FREEBSD_RB_PAUSE 0x100000 +#define FREEBSD_RB_QUIET 0x200000 +#define FREEBSD_RB_NOINTR 0x10000000 +#define FREENSD_RB_MULTIPLE 0x20000000/* Use multiple consoles */ +#define FREEBSD_RB_DUAL FREENSD_RB_MULTIPLE +#define FREEBSD_RB_BOOTINFO 0x80000000/* have `struct bootinfo *' arg */ Usually we have "(1 << 0)", "(1 << 1)", etc for bitmask lists.
ok.
Quoted 13 lines
kern/i386/loader.S FUNCTION(grub_multiboot2_real_boot) · line 175
Quoted 10 lines
kern/i386/loader.S +9
-0+FUNCTION(grub_unix_real_boot) + call EXT_C(grub_dl_unload_all) + call EXT_C(grub_stop_floppy) + + cli + + popl %eax + popl %eax + call *%eaxWhy a call? Do we need the return address in the stack here? A comment would be nice in that case.
bsds using stack to pass parameter, it's like this:
void __cdecl (*func)(parm1, parm2,...);
the first pop remove the return address, the second gets the address of func, and then call it. the function never returns, using call just make sure the first parameter is at esp + 4.
Quoted 10 lines
loader/i386/pc/bsd.c line 36
Quoted 3 lines
loader/i386/pc/bsd.c new file +2
-0+#define ALIGN_DWORD (a) ((a + 3) & (~3)) +#define ALIGN_PAGE (a) ((a + 4095) & (~4095))We already have
ALIGN_UP:./include/grub/misc.h:#define
ALIGN_UP(addr, align)((long)((char *)addr + align - 1) & ~(align - 1))it'd be better to reuse that, I think.
Quoted 9 lines
loader/i386/pc/bsd.c line 50
Quoted 7 lines
loader/i386/pc/bsd.c new file +7
-0+static const grub_uint32_t freebsd_flags[] = { +FREEBSD_RB_DUAL ,FREEBSD_RB_SERIAL ,FREEBSD_RB_ASKNAME , +FREEBSD_RB_CDROM ,FREEBSD_RB_CONFIG ,FREEBSD_RB_KDB , +FREEBSD_RB_GDB ,FREEBSD_RB_MUTE ,FREEBSD_RB_NOINTR , +FREEBSD_RB_PAUSE ,FREEBSD_RB_QUIET ,FREEBSD_RB_DFLTROOT , +FREEBSD_RB_SINGLE ,FREEBSD_RB_VERBOSE +};We usually put a newline after the '='.
ok.
Signature · 1 line
Bean
Quoted 12 lines · Bean
Quoted 11 lines
conf/i386-pc.rmk lspci_mod_SOURCES = commands/lspci.c · line 315
Quoted 7 lines
conf/i386-pc.rmk +7
-0+_bsd_mod_CFLAGS = $(COMMON_CFLAGS) +_bsd_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For freebsd.mod +bsd_mod_SOURCES = loader/i386/pc/bsd_normal.c +bsd_mod_CFLAGS = $(COMMON_CFLAGS) +bsd_mod_LDFLAGS = $(COMMON_LDFLAGS)How much pc-dependant are those? Can we hope they will work in e.g. i386-coreboot in the future, when *BSD kernels remove their BIOS dependency?
Quoted 2 lines
freebsd doesn't need bios at all, openbsd need the memory map, but i guess it's easy to construct one without using int 15.
In that case, loader/i386/ would be better than loader/i386/pc. Moving files in CVS is painful ;-)
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
kern/i386/loader.S +4
-0+FUNCTION(grub_unix_real_boot) + call EXT_C(grub_dl_unload_all) + call EXT_C(grub_stop_floppy) +Quoted 8 lines
kern/i386/loader.S FUNCTION(grub_multiboot2_real_boot) · line 175
Quoted 5 lines
kern/i386/loader.S +5
-0+ cli + + popl %eax + popl %eax + call *%eaxWhy a call? Do we need the return address in the stack here? A comment would be nice in that case.
Quoted 7 lines
bsds using stack to pass parameter, it's like this:
void
__cdecl(*func)(parm1, parm2,...);the first pop remove the return address, the second gets the address of func, and then call it. the function never returns, using call just make sure the first parameter is at esp + 4.
Ok. How about adding a comment to make this clear? Maybe something like:
/* Use cdecl calling convention for *BSD kernels. */ FUNCTION(grub_unix_real_boot)
.... /* Discard `grub_unix_real_boot' return address. */ popl %eax /* Fetch `entry' address ... */ popl %eax /* ... and put our return address in its place (the kernel will ignore it, but it expects %esp to point to it. */ call *%eax
does this look good?
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call… if you are unable to speak? (as seen on /.)
Quoted 14 lines · Bean
Quoted 13 lines · Bean
Hi,
Change in this patch:
1. support OpenBSD kernel:
set root=(hd0,3,a)
openbsd /bsdThe modules name is changed to bsd.mod.
2. Support setting kernel flags
Quoted 8 lines
Quoted 8 lines
one character represent one flag, for FreeBSD, it's "DhaCcdgmnpqrsv", for OpenBSD, it's "abcsd".
for example, to enable ask for root device name, single user mode and verbose output in FreeBSD:
set root=(hd0,2,a)
freebsd/boot/loaderasv
Any BSD kernel I try to load, including /boot/loader, gives me a 'free magic broken' error. Same with 'multiboot netbsd'.
A separate problem is that 'ls' will list the root directory of my OpenBSD partition, but not any of the subdirectories like usr, etc, home.... It just says 'out of disk' when I try.
Quoted 7 lines · walt
Any BSD kernel I try to load, including
/boot/loader, gives me a 'free magic broken' error. Same with 'multiboot netbsd'.A separate problem is that 'ls' will list the root directory of my OpenBSD partition, but not any of the subdirectories like usr, etc, home.... It just says 'out of disk' when I try.
This seems like a fs problem, are you using the same system as before ?
perhaps you can copy the kernel to a fat partition and see if it can be loaded.
Signature · 1 line
Bean
Quoted 3 lines · walt
Any BSD kernel I try to load, including
/boot/loader, gives me a 'free magic broken' error. Same with 'multiboot netbsd'.
Sounds like an error I've seen before. What is the exact error you see, and when?
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call… if you are unable to speak? (as seen on /.)
Hi,
The new version adds NetBSD support and data file loading in FreeBSD. You can't load kernel modules, because they have relocation and symbol issue which is too much to handle, however, you can load data files like splashimage or memdisk. Examples:
1. Load freebsd loader
set root=(hd0,1,a)
freebsd /boot/loader
boot
2. Load freebsd kernel directly
set root=(hd0,1,a)
freebsd /boot/kernel/kernelfreebsd_loadenv /boot/device.hints freebsd_module /boot/splash.bmp type=splash_image_data set FreeBSD.vfs.root.mountfrom=ufs:ad0s1a boot
Note that in order to show the splashimage, you need to add splash_bmp module to the kernel.
3. Load OpenBSD kernel
set root=(hd0,2,a)
openbsd /bsd
4. Load NetBSD kernel
set root=(hd0,3,a)
netbsd /netbsd
2008-02-12 Bean <[email protected]>
* conf/i386-pc.rmk (pkglib_MODULES): Add aout.mod _bsd.mod and bsd.mod. (aout_mod_SOURCES): New variable.
(aout_mod_CFLAGS): Likewise.
(aout_mod_LDFLAGS): Likewise.
(_bsd_mod_SOURCES): New variable.
(_bsd_mod_CFLAGS): Likewise.
(_bsd_mod_LDFLAGS): Likewise.
(bsd_mod_SOURCES): New variable.
(bsd_mod_CFLAGS): Likewise.
(bsd_mod_LDFLAGS): Likewise.
* include/grub/aout.h: New file.
* include/grub/i386/loader.h (grub_unix_real_boot): New function.
* include/grub/i386/bsd.h: New file.
* include/grub/i386/pc/init.h (grub_get_mmap_entry): Use EXPORT_FUNC to make it public.
* kern/elf.c (grub_elf32_load): Get the physical address after the hook function is called, so that it's possible to change it inside the hook. (grub_elf64_load): Likewise.
* kern/i386/loader.S (grub_unix_real_boot): New function.
* loader/aout.c: New file.
* loader/i386/bsd.c: New file.
* loader/i386/bsd_normal.c: New file.
* loader/i386/pc/multiboot.c (grub_multiboot): Handle a.out format.
Signature · 1 line
Bean
conf/i386-pc.rmk +17 -1
@@ -146,7 +146,8 @@ pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \ _multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \ - ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod + ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \ + aout.mod _bsd.mod bsd.mod # For biosdisk.mod. biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
@@ -298,4 +299,19 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For aout.mod +aout_mod_SOURCES = loader/aout.c +aout_mod_CFLAGS = $(COMMON_CFLAGS) +aout_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For _bsd.mod +_bsd_mod_SOURCES = loader/i386/bsd.c +_bsd_mod_CFLAGS = $(COMMON_CFLAGS) +_bsd_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For bsd.mod +bsd_mod_SOURCES = loader/i386/bsd_normal.c +bsd_mod_CFLAGS = $(COMMON_CFLAGS) +bsd_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
include/grub/aout.h new file +91 -0
91 lines not on this page · raw message
include/grub/i386/bsd.h new file +232 -0
232 lines not on this page · raw message
include/grub/i386/loader.h +3 -0
@@ -39,6 +39,9 @@ void EXPORT_FUNC(grub_multiboot_real_boot) (grub_addr_t entry,void EXPORT_FUNC (grub_multiboot2_real_boot ) (grub_addr_t entry,struct grub_multiboot_info *mbi) __attribute__ ((noreturn)); +void EXPORT_FUNC (grub_unix_real_boot ) (grub_addr_t entry, ...) + __attribute__ ((cdecl,noreturn)); +/* It is necessary to export these functions, because normal mode commands reuse rescue mode commands. */
include/grub/i386/pc/init.h +1 -1
@@ -40,7 +40,7 @@ struct grub_machine_mmap_entry/* Get a memory map entry. Return next continuation value. Zero means the end. */ -grub_uint32_t grub_get_mmap_entry (struct grub_machine_mmap_entry *entry, +grub_uint32_t EXPORT_FUNC (grub_get_mmap_entry ) (struct grub_machine_mmap_entry *entry,grub_uint32_t cont);/* Turn on/off Gate A20. */
kern/elf.c +2 -2
@@ -228,9 +228,9 @@ grub_elf32_load (grub_elf_t _elf, grub_elf32_load_hook_t _load_hook,if (phdr->p_type !=PT_LOAD )return 0 ; - load_addr = phdr->p_paddr;if (load_hook &&load_hook (phdr, &load_addr))return 1 ; + load_addr = phdr->p_paddr;if (load_addr < load_base) load_base = load_addr;
@@ -407,9 +407,9 @@ grub_elf64_load (grub_elf_t _elf, grub_elf64_load_hook_t _load_hook,if (phdr->p_type !=PT_LOAD )return 0 ; - load_addr = phdr->p_paddr;if (load_hook &&load_hook (phdr, &load_addr))return 1 ; + load_addr = phdr->p_paddr;if (load_addr < load_base) load_base = load_addr;
kern/i386/loader.S +22 -0
@@ -162,3 +162,25 @@ FUNCTION(grub_multiboot2_real_boot) movl $MULTIBOOT2_BOOTLOADER_MAGIC,%eax popl %ecx jmp *%ecx + +/* + * Use cdecl calling convention for *BSD kernels. + */ + +FUNCTION(grub_unix_real_boot) + + call EXT_C(grub_dl_unload_all) + call EXT_C(grub_stop_floppy) + + /* Interrupts should be disabled. */ + cli + + /* Discard `grub_unix_real_boot' return address. */ + popl %eax + + /* Fetch `entry' address ... */ + popl %eax + + /* ... and put our return address in its place (the kernel will ignore + it, but it expects %esp to point to it. */ + call *%eax
loader/aout.c new file +61 -0
61 lines not on this page · raw message
loader/i386/bsd.c new file +772 -0
772 lines not on this page · raw message
loader/i386/bsd_normal.c new file +101 -0
101 lines not on this page · raw message
loader/i386/pc/multiboot.c +17 -1
@@ -36,6 +36,7 @@#include <grub/machine/init.h> #include <grub/machine/memory.h> #include <grub/elf.h> +#include <grub/aout.h> #include <grub/file.h> #include <grub/err.h> #include <grub/rescue.h>
@@ -315,7 +316,22 @@ grub_multiboot (int argc, char *argv[]) goto fail; } -if (grub_multiboot_load_elf (file, buffer) !=GRUB_ERR_NONE ) +if (header->flags &MULTIBOOT_AOUT_KLUDGE ) + { +int ofs; + + ofs = (char *) header - buffer - + (header->header_addr - header->load_addr); +if ((grub_aout_load (file, ofs, header->load_addr, + ((header->load_end_addr ==0 ) ?0 : + header->load_end_addr - header->load_addr), + header->bss_end_addr)) + !=GRUB_ERR_NONE ) + goto fail; + + entry = header->entry_addr; + } +else if (grub_multiboot_load_elf (file, buffer) !=GRUB_ERR_NONE ) goto fail; mbi =grub_malloc (sizeof (struct grub_multiboot_info ));
kern/i386/loader.S FUNCTION(grub_multiboot2_real_boot) · line 186
Quoted 3 lines · Bean
kern/i386/loader.S +3
-0+ /* ... and put our return address in its place (the kernel will ignore + it, but it expects %esp to point to it. */ + call *%eax
Unmatched parenthesis here (sorry I guess that's my fault ;-)).
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call… if you are unable to speak? (as seen on /.)
Quoted 6 lines · Robert Millan
Review
Quoted 3 lines · Bean
(quoted diff) +3
-0+ /* ... and put our return address in its place (the kernel will ignore + it, but it expects %esp to point to it. */ + call *%eaxUnmatched parenthesis here (sorry I guess that's my fault ;-)).
Ok. I also fix the alloc magic broken problem, it's caused by grub_elf_file, which will close the file when the elf magic is not found. However, the upper level still use that file, that cause the memory problem.
The patch should be applied after the previous bsd.diff.
Signature · 1 line
Bean
kern/elf.c +6 -7
@@ -85,9 +85,8 @@ grub_elf_file (grub_file_t file)return elf; fail: -grub_error_push (); -grub_elf_close (elf); -grub_error_pop (); +grub_free (elf->phdrs); +grub_free (elf);return 0 ; }
@@ -177,8 +176,8 @@ grub_elf32_size (grub_elf_t elf)/* Run through the program headers to calculate the total memory size we * should claim. */ - autoint calcsize (grub_elf_t _elf,Elf32_Phdr *phdr,void *_arg); - int calcsize (grub_elf_t UNUSED _elf, Elf32_Phdr *phdr, void UNUSED *_arg) + auto int NESTED_FUNC_ATTR calcsize (grub_elf_t _elf, Elf32_Phdr *phdr, void *_arg); + int NESTED_FUNC_ATTR calcsize (grub_elf_t UNUSED _elf, Elf32_Phdr *phdr, void UNUSED *_arg) {/* Only consider loadable segments. */ if (phdr->p_type !=PT_LOAD )
@@ -355,8 +354,8 @@ grub_elf64_size (grub_elf_t elf)/* Run through the program headers to calculate the total memory size we * should claim. */ - autoint calcsize (grub_elf_t _elf,Elf64_Phdr *phdr,void *_arg); - int calcsize (grub_elf_t UNUSED _elf, Elf64_Phdr *phdr, void UNUSED *_arg) + auto int NESTED_FUNC_ATTR calcsize (grub_elf_t _elf, Elf64_Phdr *phdr, void *_arg); + int NESTED_FUNC_ATTR calcsize (grub_elf_t UNUSED _elf, Elf64_Phdr *phdr, void UNUSED *_arg) {/* Only consider loadable segments. */ if (phdr->p_type !=PT_LOAD )
kern/i386/loader.S +4 -2
@@ -181,6 +181,8 @@ FUNCTION(grub_unix_real_boot) /* Fetch `entry' address ... */ popl %eax - /* ... and put our return address in its place (the kernel will ignore - it, but it expects %esp to point to it. */ + /* + * ... and put our return address in its place. The kernel will + * ignore it, but it expects %esp to point to it. + */ call *%eax
loader/i386/bsd.c +31 -32
123 lines not on this page · raw message
loader/multiboot2.c +1 -0
@@ -371,6 +371,7 @@ grub_multiboot2 (int argc, char *argv[]) }else { + grub_errno =0 ;grub_dprintf ("loader" ,"Loading non-ELF multiboot 2 file.\n" );if (header)
Quoted 6 lines · Bean
Quoted 5 lines · Robert Millan
Quoted 3 lines · Bean
(quoted diff) +3
-0+ /* ... and put our return address in its place (the kernel will ignore + it, but it expects %esp to point to it. */ + call *%eax
Quoted 8 lines
Quoted 1 line
Unmatched parenthesis here (sorry I guess that's my fault ;-)).
Ok. I also fix the alloc magic broken problem, it's caused by
grub_elf_file, which will close the file when the elf magic is not found. However, the upper level still use that file, that cause the memory problem.The patch should be applied after the previous bsd.diff.
You forgot the ChangeLog entry..
loader/multiboot2.c grub_multiboot2 (int argc, char *argv[]) · line 377
Quoted 10 lines
loader/multiboot2.c +1
-0@@ -371,6 +371,7 @@ grub_multiboot2 (int argc, char *argv[]) }else { + grub_errno =0 ;grub_dprintf ("loader" ,"Loading non-ELF multiboot 2 file.\n" );if (header)
Why this?
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call… if you are unable to speak? (as seen on /.)
Quoted 28 lines · Robert Millan
Quoted 6 lines · Bean
Quoted 5 lines · Robert Millan
Quoted 3 lines · Bean
(quoted diff) +3
-0+ /* ... and put our return address in its place (the kernel will ignore + it, but it expects %esp to point to it. */ + call *%eaxQuoted 8 lines
Quoted 1 line
Unmatched parenthesis here (sorry I guess that's my fault ;-)).
Ok. I also fix the alloc magic broken problem, it's caused by
grub_elf_file, which will close the file when the elf magic is not found. However, the upper level still use that file, that cause the memory problem.The patch should be applied after the previous bsd.diff.
You forgot the ChangeLog entry..
Quoted 9 lines
loader/multiboot2.c +1
-0@@ -371,6 +371,7 @@ grub_multiboot2 (int argc, char *argv[]) }else { + grub_errno =0 ;grub_dprintf ("loader" ,"Loading non-ELF multiboot 2 file.\n" );
Quoted 3 lines
loader/multiboot2.c grub_multiboot2 (int argc, char *argv[]) · line 377
Quoted 1 line
loader/multiboot2.c +0
-0if (header)Why this?
After grub_elf_file have failed, the grub_errno would be set, we need to reset it in order to test for another case.
Signature · 1 line
Bean
Quoted 6 lines · Bean
Ok. I also fix the alloc magic broken problem, it's caused by
grub_elf_file, which will close the file when the elf magic is not found. However, the upper level still use that file, that cause the memory problem.The patch should be applied after the previous bsd.diff...
I'm very confused by the results :o/ I'm now running today's cvs plus bsd.diff plus bsd_2.diff. Some things work and some don't.
I can boot openbsd perfectly -- but only if I load the 'bsd' kernel from a different filesystem e.g. FAT32. I can't read any files from the FFS/UFS on my openbsd partition -- I get 'outside of partition'.
I can multiboot netbsd perfectly -- but not from the netbsd partition. If I 'multiboot /netbsd' from the netbsd partition I get 'broken magic'. However, I can 'netbsd /netbsd' perfectly from the netbsd partition. (See why I'm confused?)
When I 'freebsd /boot/loader' or 'freebsd /boot/kernel/kernel' from the FreeBSD partition I get 'broken magic'. If I 'freebsd /kernel' from a FAT32 partition the kernel seems to load okay but then when I 'boot' nothing prints to the console and the OS never starts. If I 'freebsd /loader' from a FAT fs then the loader runs correctly but of course I need to set 'currdev' by hand.
I'm wondering if you have commited all of your UFS/FFS patches to cvs. Seems like I'm seeing some old UFS problems that you fixed once already(?).
Quoted 28 lines · walt
Quoted 6 lines · Bean
Ok. I also fix the alloc magic broken problem, it's caused by
grub_elf_file, which will close the file when the elf magic is not found. However, the upper level still use that file, that cause the memory problem.The patch should be applied after the previous bsd.diff...
I'm very confused by the results :o/ I'm now running today's cvs plus bsd.diff plus bsd_2.diff. Some things work and some don't.
I can boot openbsd perfectly -- but only if I load the 'bsd' kernel from a different filesystem e.g. FAT32. I can't read any files from the FFS/UFS on my openbsd partition -- I get 'outside of partition'.
I can multiboot netbsd perfectly -- but not from the netbsd partition. If I 'multiboot /netbsd' from the netbsd partition I get 'broken magic'. However, I can 'netbsd /netbsd' perfectly from the netbsd partition. (See why I'm confused?)
When I 'freebsd
/boot/loader' or 'freebsd/boot/kernel/kernel' from the FreeBSD partition I get 'broken magic'. If I 'freebsd /kernel' from a FAT32 partition the kernel seems to load okay but then when I 'boot' nothing prints to the console and the OS never starts. If I 'freebsd /loader' from a FAT fs then the loader runs correctly but of course I need to set 'currdev' by hand.
Quoted 3 lines
I'm wondering if you have commited all of your UFS/FFS patches to cvs. Seems like I'm seeing some old UFS problems that you fixed once already(?).
Is it possible that your build is not clean ? you can try to run make distclean and then configure and make, see if there is any difference.
i'm also putting my compiled version at:
http://grub4dos.sourceforge.net/grub2/g2ldr
you can load it as linux kernel, please see if it helps.
Signature · 1 line
Bean
Quoted 9 lines · Bean
Quoted 4 lines · walt
...
I'm wondering if you have commited all of your UFS/FFS patches to cvs. Seems like I'm seeing some old UFS problems that you fixed once already(?).Is it possible that your build is not clean ? you can try to run make distclean and then configure and make, see if there is any difference.
Yes, I do that every time. I'm betting that your source tree is not the same as mine -- i.e. you have some patches I don't have. Could you perhaps put up a tarball of your working source tree so I can compare it to mine?
Quoted 3 lines
i'm also putting my compiled version at:
Yes, this works perfectly except that I still can't read my openbsd filesystem correctly. I can list / but none of the subdirectories, and I can't even read a small text file from /. (I guess that also means I can't properly read the directories in /). Everything I try gives me 'out of partition' or similar.
Progress! :o)
Quoted 7 lines · walt
Yes, this works perfectly except that I still can't read my openbsd filesystem correctly. I can list / but none of the subdirectories, and I can't even read a small text file from /. (I guess that also means I can't properly read the directories in /). Everything I try gives me 'out of partition' or similar.
Progress! :o)
In that case, it should be a fs problem, what's the disk layout, how big is your ufs partition ? It could be handy if you can make a small image that produce similar results.
Signature · 1 line
Bean
Quoted 7 lines · Bean
Quoted 6 lines · walt
Yes, this works perfectly except that I still can't read my openbsd filesystem correctly. I can list / but none of the subdirectories, and I can't even read a small text file from /. (I guess that also means I can't properly read the directories in /). Everything I try gives me 'out of partition' or similar.
Quoted 5 lines
Quoted 1 line
Progress! :o)
In that case, it should be a fs problem, what's the disk layout, how big is your ufs partition ? It could be handy if you can make a small image that produce similar results.
I made a small openbsd image to send you, but it works perfectly with your g2ldr so there's no point in sending it :o) I think that problem is not worth your time or mine.
I still have the bigger problem that my grub2 doesn't work like your g2ldr. My version still halts with 'broken magic' or reboots instantly when I type 'boot'. These are bugs that I was seeing several weeks ago and you already fixed them once, but now they are back again.
I still think that a patch or two never got committed to cvs, but I don't know which one(s). Could you try applying your bsd.diff and bsd_2.diff to current cvs sources and see if it works for you?
Here is what I do:
Apply the two patches to a clean cvs tree.
./autogen.sh [because you patched an rmk file]
mkdir build
cd build
../configure && make
rm ata.mod
./grub-mkimage -d . -o grub2 *.mod
Then I use grub legacy to boot grub2 as the 'kernel'.
Do you see any problems with the above? Does it work properly for you?
Thanks, Bean!
Quoted 30 lines · walt
Quoted 7 lines · Bean
Quoted 6 lines · walt
Yes, this works perfectly except that I still can't read my openbsd filesystem correctly. I can list / but none of the subdirectories, and I can't even read a small text file from /. (I guess that also means I can't properly read the directories in /). Everything I try gives me 'out of partition' or similar.
Quoted 5 lines
Quoted 1 line
Progress! :o)
In that case, it should be a fs problem, what's the disk layout, how big is your ufs partition ? It could be handy if you can make a small image that produce similar results.
I made a small openbsd image to send you, but it works perfectly with your g2ldr so there's no point in sending it :o) I think that problem is not worth your time or mine.
I still have the bigger problem that my grub2 doesn't work like your g2ldr. My version still halts with 'broken magic' or reboots instantly when I type 'boot'. These are bugs that I was seeing several weeks ago and you already fixed them once, but now they are back again.
I still think that a patch or two never got committed to cvs, but I don't know which one(s). Could you try applying your bsd.diff and bsd_2.diff to current cvs sources and see if it works for you?
Here is what I do:
Quoted 7 lines
Apply the two patches to a clean cvs tree.
./autogen.sh [because you patched an rmk file]
mkdir build
cd build
../configure && make
rm ata.mod
./grub-mkimage -d . -o grub2 *.mod
Don't include all the modules in the kernel, you only need those necessary to access the boot partition, for example, i use the following command to create core.img:
./grub-mkimage -d . -o core.img biosdisk iso9660 pc fat ntfs ext2 ufs bsd boot ls multiboot
To create g2ldr, add the lnxboot.img header:
cat lnxboot.img core.img > g2ldr
This contain enough modules to do the test, no need to load extra module from disk.
Also, please use linux to build grub2, *bsd may compile ok, but don't know if the result is correct.
Signature · 1 line
Bean
Quoted 3 lines · walt
I made a small openbsd image to send you, but it works perfectly with your g2ldr so there's no point in sending it :o) I think that problem is not worth your time or mine.
BTW, how big is your ufs partition ? I have tested FreeBSD 6.3, NetBSD 4.0 and OpenBSD 4.2 in a 1G virtual disk, they all seems ok, perhaps if the disk is larger, the problem would occur.
Signature · 1 line
Bean
Quoted 8 lines · Bean
Quoted 3 lines · walt
I made a small openbsd image to send you, but it works perfectly with your g2ldr so there's no point in sending it :o) I think that problem is not worth your time or mine.
BTW, how big is your ufs partition ? I have tested FreeBSD 6.3, NetBSD 4.0 and OpenBSD 4.2 in a 1G virtual disk, they all seems ok, perhaps if the disk is larger, the problem would occur.
Your instructions to load only the needed modules works great, thanks.
My openbsd partition is 7GB, but some other ufs partitions are bigger than that. I suspect that I have some disklabel conflict on that disk. I have netbsd, openbsd, freebsd all installed on the same disk, each with its own disklabel. I don't know why it would cause that problem in particular, though.
I'd like to know exactly how you create your virtual disks for testing. I've been creating appropriate-size partitions on a USB stick and then copying whatever files I need onto it. Then I use dd to make an img file to run in qemu. It's a very slow process and I'd like to do it better. Any hints?
Thanks.
Quoted 19 lines · walt
Quoted 8 lines · Bean
Quoted 3 lines · walt
I made a small openbsd image to send you, but it works perfectly with your g2ldr so there's no point in sending it :o) I think that problem is not worth your time or mine.
BTW, how big is your ufs partition ? I have tested FreeBSD 6.3, NetBSD 4.0 and OpenBSD 4.2 in a 1G virtual disk, they all seems ok, perhaps if the disk is larger, the problem would occur.
Your instructions to load only the needed modules works great, thanks.
My openbsd partition is 7GB, but some other ufs partitions are bigger than that. I suspect that I have some disklabel conflict on that disk. I have netbsd, openbsd, freebsd all installed on the same disk, each with its own disklabel. I don't know why it would cause that problem in particular, though.
Quoted 5 lines
I'd like to know exactly how you create your virtual disks for testing. I've been creating appropriate-size partitions on a USB stick and then copying whatever files I need onto it. Then I use dd to make an img file to run in qemu. It's a very slow process and I'd like to do it better. Any hints?
I'm creating a blank disk using qemu-img, then install using the iso file.
Signature · 1 line
Bean
Quoted 5 lines · walt
I'd like to know exactly how you create your virtual disks for testing. I've been creating appropriate-size partitions on a USB stick and then copying whatever files I need onto it. Then I use dd to make an img file to run in qemu. It's a very slow process and I'd like to do it better. Any hints?
i think the problem may be caused by dd. bsd disk label record the start sector on disk, if you just copy the partition, the disk label would be wrong, therefore cause the 'out of partition' problem, which generally means reading beyond the end of disk. I recommend install inside qemu to create consistent disk structure.
Anyway, i think the bsd module should be fine, here is the whole patch, if nobody objects, i would like to commit it soon.
2008-02-16 Bean <[email protected]>
* conf/i386-pc.rmk (pkglib_MODULES): Add aout.mod _bsd.mod and bsd.mod. (aout_mod_SOURCES): New variable.
(aout_mod_CFLAGS): Likewise.
(aout_mod_LDFLAGS): Likewise.
(_bsd_mod_SOURCES): New variable.
(_bsd_mod_CFLAGS): Likewise.
(_bsd_mod_LDFLAGS): Likewise.
(bsd_mod_SOURCES): New variable.
(bsd_mod_CFLAGS): Likewise.
(bsd_mod_LDFLAGS): Likewise.
* include/grub/aout.h: New file.
* include/grub/i386/loader.h (grub_unix_real_boot): New function.
* include/grub/i386/bsd.h: New file.
* include/grub/i386/pc/init.h (grub_get_mmap_entry): Use EXPORT_FUNC to make it public.
* kern/elf.c (grub_elf32_load): Get the physical address after the hook function is called, so that it's possible to change it inside the hook. (grub_elf64_load): Likewise.
(grub_elf_file): Don't close the file if elf header is not found. (grub_elf_close): Close the file if grub_elf_file fails (The new grub_elf_file won't close it).
(grub_elf32_size): Use NESTED_FUNC_ATTR for nested function calcsize. (grub_elf64_size): Likewise.
* kern/i386/loader.S (grub_unix_real_boot): New function.
* loader/aout.c: New file.
* loader/i386/bsd.c: New file.
* loader/i386/bsd_normal.c: New file.
* loader/i386/pc/multiboot.c (grub_multiboot): Handle a.out format.
* loader/multiboot2.c (grub_multiboot2): Reset grub_errno so that it can test othe formats.
Signature · 1 line
Bean
conf/i386-pc.rmk +17 -1
@@ -152,7 +152,8 @@ pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \ _multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \ - ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod + ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \ + aout.mod _bsd.mod bsd.mod # For biosdisk.mod. biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
@@ -304,4 +305,19 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For aout.mod +aout_mod_SOURCES = loader/aout.c +aout_mod_CFLAGS = $(COMMON_CFLAGS) +aout_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For _bsd.mod +_bsd_mod_SOURCES = loader/i386/bsd.c +_bsd_mod_CFLAGS = $(COMMON_CFLAGS) +_bsd_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For bsd.mod +bsd_mod_SOURCES = loader/i386/bsd_normal.c +bsd_mod_CFLAGS = $(COMMON_CFLAGS) +bsd_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
include/grub/aout.h new file +91 -0
91 lines not on this page · raw message
include/grub/i386/bsd.h new file +232 -0
232 lines not on this page · raw message
include/grub/i386/loader.h +3 -0
@@ -39,6 +39,9 @@ void EXPORT_FUNC(grub_multiboot_real_boot) (grub_addr_t entry,void EXPORT_FUNC (grub_multiboot2_real_boot ) (grub_addr_t entry,struct grub_multiboot_info *mbi) __attribute__ ((noreturn)); +void EXPORT_FUNC (grub_unix_real_boot ) (grub_addr_t entry, ...) + __attribute__ ((cdecl,noreturn)); +/* It is necessary to export these functions, because normal mode commands reuse rescue mode commands. */
include/grub/i386/pc/init.h +1 -1
@@ -40,7 +40,7 @@ struct grub_machine_mmap_entry/* Get a memory map entry. Return next continuation value. Zero means the end. */ -grub_uint32_t grub_get_mmap_entry (struct grub_machine_mmap_entry *entry, +grub_uint32_t EXPORT_FUNC (grub_get_mmap_entry ) (struct grub_machine_mmap_entry *entry,grub_uint32_t cont);/* Turn on/off Gate A20. */
kern/elf.c +14 -10
@@ -85,9 +85,8 @@ grub_elf_file (grub_file_t file)return elf; fail: -grub_error_push (); -grub_elf_close (elf); -grub_error_pop (); +grub_free (elf->phdrs); +grub_free (elf);return 0 ; }
@@ -95,12 +94,17 @@ grub_elf_t grub_elf_open (const char *name) {grub_file_t file; +grub_elf_t elf; file =grub_gzfile_open (name,1 );if (! file)return 0 ; -return grub_elf_file (file); + elf =grub_elf_file (file); +if (! elf) +grub_file_close (file); + +return elf; }
@@ -177,8 +181,8 @@ grub_elf32_size (grub_elf_t elf)/* Run through the program headers to calculate the total memory size we * should claim. */ - autoint calcsize (grub_elf_t _elf,Elf32_Phdr *phdr,void *_arg); - int calcsize (grub_elf_t UNUSED _elf, Elf32_Phdr *phdr, void UNUSED *_arg) + auto int NESTED_FUNC_ATTR calcsize (grub_elf_t _elf, Elf32_Phdr *phdr, void *_arg); + int NESTED_FUNC_ATTR calcsize (grub_elf_t UNUSED _elf, Elf32_Phdr *phdr, void UNUSED *_arg) {/* Only consider loadable segments. */ if (phdr->p_type !=PT_LOAD )
@@ -228,9 +232,9 @@ grub_elf32_load (grub_elf_t _elf, grub_elf32_load_hook_t _load_hook,if (phdr->p_type !=PT_LOAD )return 0 ; - load_addr = phdr->p_paddr;if (load_hook &&load_hook (phdr, &load_addr))return 1 ; + load_addr = phdr->p_paddr;if (load_addr < load_base) load_base = load_addr;
@@ -355,8 +359,8 @@ grub_elf64_size (grub_elf_t elf)/* Run through the program headers to calculate the total memory size we * should claim. */ - autoint calcsize (grub_elf_t _elf,Elf64_Phdr *phdr,void *_arg); - int calcsize (grub_elf_t UNUSED _elf, Elf64_Phdr *phdr, void UNUSED *_arg) + auto int NESTED_FUNC_ATTR calcsize (grub_elf_t _elf, Elf64_Phdr *phdr, void *_arg); + int NESTED_FUNC_ATTR calcsize (grub_elf_t UNUSED _elf, Elf64_Phdr *phdr, void UNUSED *_arg) {/* Only consider loadable segments. */ if (phdr->p_type !=PT_LOAD )
@@ -407,9 +411,9 @@ grub_elf64_load (grub_elf_t _elf, grub_elf64_load_hook_t _load_hook,if (phdr->p_type !=PT_LOAD )return 0 ; - load_addr = phdr->p_paddr;if (load_hook &&load_hook (phdr, &load_addr))return 1 ; + load_addr = phdr->p_paddr;if (load_addr < load_base) load_base = load_addr;
kern/i386/loader.S +24 -0
@@ -162,3 +162,27 @@ FUNCTION(grub_multiboot2_real_boot) movl $MULTIBOOT2_BOOTLOADER_MAGIC,%eax popl %ecx jmp *%ecx + +/* + * Use cdecl calling convention for *BSD kernels. + */ + +FUNCTION(grub_unix_real_boot) + + call EXT_C(grub_dl_unload_all) + call EXT_C(grub_stop_floppy) + + /* Interrupts should be disabled. */ + cli + + /* Discard `grub_unix_real_boot' return address. */ + popl %eax + + /* Fetch `entry' address ... */ + popl %eax + + /* + * ... and put our return address in its place. The kernel will + * ignore it, but it expects %esp to point to it. + */ + call *%eax
loader/aout.c new file +61 -0
61 lines not on this page · raw message
loader/i386/bsd.c new file +771 -0
771 lines not on this page · raw message
loader/i386/bsd_normal.c new file +101 -0
101 lines not on this page · raw message
loader/i386/pc/multiboot.c +17 -1
@@ -36,6 +36,7 @@#include <grub/machine/init.h> #include <grub/machine/memory.h> #include <grub/elf.h> +#include <grub/aout.h> #include <grub/file.h> #include <grub/err.h> #include <grub/rescue.h>
@@ -315,7 +316,22 @@ grub_multiboot (int argc, char *argv[]) goto fail; } -if (grub_multiboot_load_elf (file, buffer) !=GRUB_ERR_NONE ) +if (header->flags &MULTIBOOT_AOUT_KLUDGE ) + { +int ofs; + + ofs = (char *) header - buffer - + (header->header_addr - header->load_addr); +if ((grub_aout_load (file, ofs, header->load_addr, + ((header->load_end_addr ==0 ) ?0 : + header->load_end_addr - header->load_addr), + header->bss_end_addr)) + !=GRUB_ERR_NONE ) + goto fail; + + entry = header->entry_addr; + } +else if (grub_multiboot_load_elf (file, buffer) !=GRUB_ERR_NONE ) goto fail; mbi =grub_malloc (sizeof (struct grub_multiboot_info ));
loader/multiboot2.c +1 -0
@@ -371,6 +371,7 @@ grub_multiboot2 (int argc, char *argv[]) }else { + grub_errno =0 ;grub_dprintf ("loader" ,"Loading non-ELF multiboot 2 file.\n" );if (header)
Quoted 3 lines · Bean
...
Anyway, i think the bsd module should be fine, here is the whole patch, if nobody objects, i would like to commit it soon...
I vote yes, thanks. I can boot freebsd directly, openbsd directly, netbsd directly or using multiboot. The only problem is that 'aout' doesn't appear as one of the commands I can choose, so I couldn't try it. When I used grub-mkimage I included aout.mod -- should that be needed in addition to bsd.mod?
Great work, Bean, thanks.
Quoted 6 lines · walt
Quoted 3 lines · Bean
...
Anyway, i think the bsd module should be fine, here is the whole patch, if nobody objects, i would like to commit it soon...
Quoted 7 lines
I vote yes, thanks. I can boot freebsd directly, openbsd directly, netbsd directly or using multiboot. The only problem is that 'aout' doesn't appear as one of the commands I can choose, so I couldn't try it. When I used grub-mkimage I included aout.mod -- should that be needed in addition to bsd.mod?
Great work, Bean, thanks.
aout is shared code for a.out support, bsd module use it to load the a.out format kernel (/boot/loader in freebsd). you don't need to specify it directly, grub-mkimage can figure out bsd depend on aout and load it automatically.
Signature · 1 line
Bean
Quoted 13 lines · Bean
Quoted 12 lines · walt
Quoted 3 lines · Bean
...
Anyway, i think the bsd module should be fine, here is the whole patch, if nobody objects, i would like to commit it soon...I vote yes, thanks. I can boot freebsd directly, openbsd directly, netbsd directly or using multiboot. The only problem is that 'aout' doesn't appear as one of the commands I can choose, so I couldn't try it. When I used grub-mkimage I included aout.mod -- should that be needed in addition to bsd.mod?
Quoted 6 lines
Quoted 1 line
Great work, Bean, thanks.
aout is shared code for a.out support, bsd module use it to load the a.out format kernel (
/boot/loaderin freebsd). you don't need to specify it directly, grub-mkimage can figure out bsd depend on aout and load it automatically.
Committed.
Signature · 1 line
Bean
Quoted 8 lines · Bean
Quoted 3 lines · walt
I made a small openbsd image to send you, but it works perfectly with your g2ldr so there's no point in sending it :o) I think that problem is not worth your time or mine.
BTW, how big is your ufs partition ? I have tested FreeBSD 6.3, NetBSD 4.0 and OpenBSD 4.2 in a 1G virtual disk, they all seems ok, perhaps if the disk is larger, the problem would occur.
Hah! I think I found the problem. I just noticed that gparted calls my openbsd/ufs partition an *ext2* filesystem! I seem to recall similar messages from other fs utility programs about the magic number being for ext2 even though it's really ufs. This is probably a leftover magic number from an earlier linux or such.
I haven't found any way to change just the magic number instead of deleting the partition and starting over. Do you know of an easy way to do it? I could use a hex disc editor but I don't know where the magic number is, exactly.
Thanks!
Quoted 15 lines · walt
Quoted 7 lines · Bean
Quoted 3 lines · walt
I made a small openbsd image to send you, but it works perfectly with your g2ldr so there's no point in sending it :o) I think that problem is not worth your time or mine.
BTW, how big is your ufs partition ? I have tested FreeBSD 6.3, NetBSD 4.0 and OpenBSD 4.2 in a 1G virtual disk, they all seems ok, perhaps if the disk is larger, the problem would occur.
Hah! I think I found the problem. I just noticed that gparted calls my openbsd/ufs partition an *ext2* filesystem! I seem to recall similar messages from other fs utility programs about the magic number being for ext2 even though it's really ufs. This is probably a leftover magic number from an earlier linux or such.
Quoted 4 lines
I haven't found any way to change just the magic number instead of deleting the partition and starting over. Do you know of an easy way to do it? I could use a hex disc editor but I don't know where the magic number is, exactly.
Never mind, I found the magic number and changed it. Now I don't see any complaints about ext2 or a bad magic number, but grub2 still can't read any directory but / on my openbsd partition. I'll go back to saying that this particular problem isn't worth more of your time or mine. (But I do learn a lot by chasing these bugs even if I can't fix them :o)