Skip to contentSkip to conversation

a.out kernel loader

PATCH In review Bean 5 participants 26 messages Jan 27, 2008 – Feb 1, 2008

lore
Share & tools
lore

Bean

author
#0 lore raw

PATCH 1/1 a.out kernel loader

Hi,

This patch add support for a.out kernel, which includes the 4th loader of BSD system. For example, to start FreeBSD:

set root=(hd0,0,a)
aout /boot/loader

* conf/i386-pc.rmk (pkglib_MODULES): Add aout.mod and _aout.mod. (aout_mod_SOURCES): New variable.
(aout_mod_CFLAGS): Likewise.
(aout_mod_LDFLAGS): Likewise.
(_aout_mod_SOURCES): New variable. (_aout_mod_CFLAGS): Likewise.
(_aout_mod_LDFLAGS): Likewise.

* loader/i386/pc/aout.c: New file.

* loader/i386/pc/aout_normal.c: New file.

conf/i386-pc.rmk +12 -2
index 52dc06b..2d30a81 100644
@@ -150,8 +150,8 @@ grub_mkrescue_SOURCES = util/i386/pc/grub-mkrescue.in
 
 # Modules.
 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 \
+	_multiboot.mod chain.mod multiboot.mod _aout.mod aout.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
 
@@ -180,6 +180,16 @@ linux_mod_SOURCES = loader/i386/pc/linux_normal.c
 linux_mod_CFLAGS = $(COMMON_CFLAGS)
 linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For _aout.mod.
+_aout_mod_SOURCES = loader/i386/pc/aout.c
+_aout_mod_CFLAGS = $(COMMON_CFLAGS)
+_aout_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For aout.mod.
+aout_mod_SOURCES = loader/i386/pc/aout_normal.c
+aout_mod_CFLAGS = $(COMMON_CFLAGS)
+aout_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 # For normal.mod.
 normal_mod_DEPENDENCIES = grub_script.tab.c grub_script.tab.h
 normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c	\
loader/i386/pc/aout.c new file +54 -0

54 lines not on this page · raw message

(((mid)&0x03ff)<<16) | \
+ (((mag)&0xffff)) ) )
+
+#define N_ALIGN(ex,x) \
+ (N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC || \
+ N_GETMAGIC_NET(ex) == ZMAGIC || N_GETMAGIC_NET(ex) == QMAGIC ? \
+ ((x) + __LDPGSZ - 1) & ~(unsigned long)(__LDPGSZ - 1) : (x))
+
+/* Valid magic number check. */
+#define N_BADMAG(ex) \
+ (N_GETMAGIC(ex) != OMAGIC && N_GETMAGIC(ex) != NMAGIC && \
+ N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC && \
+ N_GETMAGIC_NET(ex) != OMAGIC && N_GETMAGIC_NET(ex) != NMAGIC && \
+ N_GETMAGIC_NET(ex) != ZMAGIC && N_GETMAGIC_NET(ex) != QMAGIC)
+
+/* Address of the bottom of the text segment. */ +#define N_TXTADDR(ex) \
+ ((N_GETMAGIC(ex) == OMAGIC || N_GETMAGIC(ex) == NMAGIC || \
+ N_GETMAGIC(ex) == ZMAGIC) ? 0 : __LDPGSZ)
+
+/* Address of the bottom of the data segment. */ +#define N_DATADDR(ex) \
+ N_ALIGN(ex, N_TXTADDR(ex) + (ex).a_text)
+
+/* Text segment offset. */
+#define N_TXTOFF(ex) \
+ (N_GETMAGIC(ex) == ZMAGIC ? __LDPGSZ : (N_GETMAGIC(ex) == QMAGIC || \
+ N_GETMAGIC_NET(ex) == ZMAGIC) ? 0 : sizeof(struct aout_header))
+
+/* Data segment offset. */
+#define N_DATOFF(ex) \
+ N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text)
+
+/* Relocation table offset. */
+#define N_RELOFF(ex) \
+ N_ALIGN(ex, N_DATOFF(ex) + (ex).a_data)
+
+/* Symbol table offset. */
+#define N_SYMOFF(ex) \
+ (N_RELOFF(ex) + (ex).a_trsize + (ex).a_drsize)
+
+/* String table offset. */
+#define N_STROFF(ex) (N_SYMOFF(ex) + (ex).a_syms)
+
+/*
+ * Header prepended to each a.out file.
+ * only manipulate the a_midmag field via the
+ * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros in a.out.h
+ */
+
+struct aout_header
+{

+  grub_uint32_t a_midmag;	/* htonl(flags<<26 | mid<<16 | magic) */
+  grub_uint32_t a_text;		/* text segment size */
+  grub_uint32_t a_data;		/* initialized data size */
+  grub_uint32_t a_bss;		/* uninitialized data size */
+  grub_uint32_t a_syms;		/* symbol table size */
+  grub_uint32_t a_entry;	/* entry point */
+  grub_uint32_t a_trsize;	/* text relocation size */
+  grub_uint32_t a_drsize;	/* data relocation size */
+};
+
+/* a_magic */
+#define	OMAGIC          0x107	/* 0407 old impure format */
+#define	NMAGIC          0x108	/* 0410 read-only text */
+#define	ZMAGIC          0x10b	/* 0413 demand load format */
+#define QMAGIC          0xcc	/* 0314 "compact" demand load format */

+
+/* a_mid */
+#define MID_ZERO 0 /* unknown - implementation dependent */
+#define MID_SUN010 1 /* sun 68010/68020 binary */
+#define MID_SUN020 2 /* sun 68020-only binary */
+#define MID_I386 134 /* i386 BSD binary */
+#define MID_SPARC 138 /* sparc */
+#define MID_HP200 200 /* hp200 (68010) BSD binary */
+#define MID_HP300 300 /* hp300 (68020+68881) BSD binary */
+#define MID_HPUX 0x20C /* hp200/300 HP-UX binary */
+#define MID_HPUX800 0x20B /* hp800 HP-UX binary */
+
+/*
+ * a_flags
+ */
+#define EX_PIC 0x10 /* contains position independant code */
+#define EX_DYNAMIC 0x20 /* contains run-time link-edit info */
+#define EX_DPMASK 0x30 /* mask for the above */
+
+static grub_addr_t entry;
+
+static grub_err_t
+grub_aout_boot (void)
+{
+ grub_multiboot_real_boot (entry, 0);
+
+ /* Not reached. */
+ return GRUB_ERR_NONE;
+}
+
+static grub_err_t
+grub_aout_unload (void)
+{
+ grub_dl_unref (my_mod);
+ return GRUB_ERR_NONE;
+}
+
+void
+grub_rescue_cmd_aout (int argc, char *argv[])
+{

+  grub_file_t file = 0;
+  struct aout_header ah;
+  grub_addr_t cur_addr;
+  int align_4k;

+
+ grub_dl_ref (my_mod);
+
+ if (argc == 0)
+ {
+ grub_error (GRUB_ERR_BAD_ARGUMENT, "no kernel specified");
+ goto fail;
+ }
+
+ file = grub_file_open (argv[0]);
+ if (!file)
+ goto fail;
+
+ if ((grub_size_t) grub_file_size (file) > grub_os_area_size)
+ {
+ grub_error (GRUB_ERR_OUT_OF_RANGE, "too big kernel (0x%x > 0x%x)",
+ (grub_size_t) grub_file_size (file), grub_os_area_size);
+ goto fail;
+ }
+
+ if (grub_file_read (file, (char *) &ah, sizeof (ah)) != sizeof (ah))
+ {
+ grub_error (GRUB_ERR_READ_ERROR, "cannot read the a.out header");
+ goto fail;
+ }
+
+ if (N_BADMAG (ah))
+ {
+ grub_error (GRUB_ERR_BAD_OS, "invalid magic number");
+ goto fail;
+ }
+
+ entry = ah.a_entry & 0xFFFFFF;
+
+ if (*((char *) &ah) == 0xb && (*((char *) &ah + 1) == 1))
+ {
+ cur_addr = entry;
+ align_4k = 0;
+ }
+ else
+ {
+ cur_addr = entry & 0xF00000;
+ align_4k = 1;
+ }
+
+ grub_file_seek (file, N_TXTOFF (ah));
+
+ if (grub_errno)
+ goto fail;
+
+ if (cur_addr < 0x100000)
+ {
+ grub_error (GRUB_ERR_BAD_OS, "load address below 1M");
+ goto fail;
+ }
+
+ if (grub_file_read (file, (char *) cur_addr, ah.a_text) != (int) ah.a_text)
+ {
+ grub_error (GRUB_ERR_READ_ERROR, "read text fails");
+ goto fail;
+ }
+
+ cur_addr += ah.a_text;
+
+ if (align_4k)
+ cur_addr = (cur_addr + 0xFFF) & 0xFFFFF000;
+
+ if (grub_file_read (file, (char *) cur_addr, ah.a_data) != (int) ah.a_data)
+ {
+ grub_error (GRUB_ERR_READ_ERROR, "read data fails");
+ goto fail;
+ }
+
+ cur_addr += ah.a_data;
+
+ if (align_4k)
+ cur_addr = (cur_addr + 0xFFF) & 0xFFFFF000;
+
+ if (ah.a_bss)
+ grub_memset ((char *) cur_addr, 0, ah.a_bss);
+
+ if (grub_errno == GRUB_ERR_NONE)
+ grub_loader_set (grub_aout_boot, grub_aout_unload, 1);
+
+fail:
+
+ if (file)
+ grub_file_close (file);
+
+ if (grub_errno != GRUB_ERR_NONE)
+ grub_dl_unref (my_mod);
+}
+
+GRUB_MOD_INIT (aout)
+{
+ grub_rescue_register_command ("aout", grub_rescue_cmd_aout, "load a.out");
+ my_mod = mod;
+}
+
+GRUB_MOD_FINI (aout)
+{
+ grub_rescue_unregister_command ("aout");
+}

loader/i386/pc/aout_normal.c new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
Bean
#1 lore raw
Quoted 4 lines · Bean

Hi,

This patch add support for a.out kernel, which includes the 4th loader of BSD system. For example, to start FreeBSD:

Cool!

How FreeBSD-specific is this? Will the same module apply to other a.out binaries ? (I ask since you gave it a generic name)

Quoted 1 line

+++ b/loader/i386/pc/aout.c

How i386-specific is it? Can it possibly work for non-i386 objects in the future?

Review

Quoted 10 lines
(quoted diff) +10 -0
+/* a_mid */
+#define	MID_ZERO	0	/* unknown - implementation dependent */
+#define	MID_SUN010	1	/* sun 68010/68020 binary */
+#define	MID_SUN020	2	/* sun 68020-only binary */
+#define MID_I386	134	/* i386 BSD binary */
+#define MID_SPARC	138	/* sparc */
+#define	MID_HP200	200	/* hp200 (68010) BSD binary */
+#define	MID_HP300	300	/* hp300 (68020+68881) BSD binary */
+#define	MID_HPUX	0x20C	/* hp200/300 HP-UX binary */
+#define	MID_HPUX800     0x20B	/* hp800 HP-UX binary */

These aren't used through the code. Did you copy them from a standard header or so?

loader/i386/pc/aout_normal.c

Quoted 4 lines
loader/i386/pc/aout_normal.c new file +4 -0
+static grub_err_t
+grub_aout_boot (void)
+{
+  grub_multiboot_real_boot (entry, 0);

Ugh :-)

Is there really anything desired from grub_multiboot_real_boot? (other than grub_dl_unload_all and grub_stop_floppy)

I wonder if it makes sense to split grub_dl_unload_all/grub_stop_floppy out of grub_multiboot_real_boot to make a generic "real_boot" function that lives in kernel and is used by grub_multiboot_real_boot and directly by modules like this one.

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 /.)
author
#2 lore raw
Quoted 10 lines · Robert Millan
Quoted 4 lines · Bean

Hi,

This patch add support for a.out kernel, which includes the 4th loader of BSD system. For example, to start FreeBSD:

Cool!

How FreeBSD-specific is this? Will the same module apply to other a.out binaries ? (I ask since you gave it a generic name)

it's an old format of the unix system:

http://en.wikipedia.org/wiki/A.out

Signature · 1 line
Bean
#3 lore raw
Quoted 7 lines · Bean
Quoted 6 lines · Robert Millan
Quoted 4 lines · Bean

Hi,

This patch add support for a.out kernel, which includes the 4th loader of BSD system. For example, to start FreeBSD:

Quoted 8 lines
Quoted 4 lines

Cool!

How FreeBSD-specific is this? Will the same module apply to other a.out binaries ? (I ask since you gave it a generic name)

it's an old format of the unix system:

http://en.wikipedia.org/wiki/A.out

I know.. I was referring to your loader.

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 /.)
author
#4 lore raw
Quoted 11 lines · Robert Millan
Quoted 9 lines · Bean
Quoted 8 lines · Robert Millan
Quoted 4 lines · Bean

Hi,

This patch add support for a.out kernel, which includes the 4th loader of BSD system. For example, to start FreeBSD:

Cool!

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

How FreeBSD-specific is this? Will the same module apply to other a.out binaries ? (I ask since you gave it a generic name)

it's an old format of the unix system:

http://en.wikipedia.org/wiki/A.out

I know.. I was referring to your loader.

it should be generic, but i only test it using the loader from freebsd.

Signature · 1 line
Bean
#5 lore raw
Quoted 11 lines · Bean
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines

How FreeBSD-specific is this? Will the same module apply to other a.out binaries ? (I ask since you gave it a generic name)

it's an old format of the unix system:

http://en.wikipedia.org/wiki/A.out

I know.. I was referring to your loader.

it should be generic, but i only test it using the loader from freebsd.

In that case, I'd suggest putting it directly in loader/ (without i386/pc/).

Moving files on CVS is a PITA :-/

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 /.)
author
#6 lore raw
Quoted 9 lines · Robert Millan
Quoted 8 lines · Bean
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

How FreeBSD-specific is this? Will the same module apply to other a.out binaries ? (I ask since you gave it a generic name)

it's an old format of the unix system:

http://en.wikipedia.org/wiki/A.out

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

I know.. I was referring to your loader.

it should be generic, but i only test it using the loader from freebsd.

In that case, I'd suggest putting it directly in loader/ (without i386/pc/).

Moving files on CVS is a PITA :-/

ok, here is the new patch.
* conf/i386-pc.rmk (pkglib_MODULES): Add aout.mod and _aout.mod. (aout_mod_SOURCES): New variable.
(aout_mod_CFLAGS): Likewise.
(aout_mod_LDFLAGS): Likewise.
(_aout_mod_SOURCES): New variable. (_aout_mod_CFLAGS): Likewise.
(_aout_mod_LDFLAGS): Likewise.

* loader/aout.c: New file.

* loader/aout_normal.c: New file.

* loader/i386/pc/aout.c: New file.

* include/grub/aout_loader.h: New file.

conf/i386-pc.rmk +12 -2
index ff02332..36af7de 100644
@@ -151,8 +151,8 @@ grub_mkrescue_SOURCES = util/i386/pc/grub-mkrescue.in
 
 # Modules.
 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 \
+	_multiboot.mod chain.mod multiboot.mod _aout.mod aout.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
 
@@ -221,6 +221,16 @@ multiboot_mod_SOURCES = loader/multiboot_loader_normal.c
 multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
 multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For _aout.mod.
+_aout_mod_SOURCES = loader/aout.c loader/i386/pc/aout.c
+_aout_mod_CFLAGS = $(COMMON_CFLAGS)
+_aout_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For aout.mod.
+aout_mod_SOURCES = loader/aout_normal.c
+aout_mod_CFLAGS = $(COMMON_CFLAGS)
+aout_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 # For vbe.mod.
 vbe_mod_SOURCES = video/i386/pc/vbe.c video/i386/pc/vbeblit.c \
 		  video/i386/pc/vbefill.c video/i386/pc/vbeutil.c
include/grub/aout_loader.h new file +45 -0

45 lines not on this page · raw message

(((mid)&0x03ff)<<16) | \
+ (((mag)&0xffff)) ) )
+
+#define N_ALIGN(ex,x) \
+ (N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC || \
+ N_GETMAGIC_NET(ex) == ZMAGIC || N_GETMAGIC_NET(ex) == QMAGIC ? \
+ ((x) + __LDPGSZ - 1) & ~(unsigned long)(__LDPGSZ - 1) : (x))
+
+/* Valid magic number check. */
+#define N_BADMAG(ex) \
+ (N_GETMAGIC(ex) != OMAGIC && N_GETMAGIC(ex) != NMAGIC && \
+ N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC && \
+ N_GETMAGIC_NET(ex) != OMAGIC && N_GETMAGIC_NET(ex) != NMAGIC && \
+ N_GETMAGIC_NET(ex) != ZMAGIC && N_GETMAGIC_NET(ex) != QMAGIC)
+
+/* Address of the bottom of the text segment. */ +#define N_TXTADDR(ex) \
+ ((N_GETMAGIC(ex) == OMAGIC || N_GETMAGIC(ex) == NMAGIC || \
+ N_GETMAGIC(ex) == ZMAGIC) ? 0 : __LDPGSZ)
+
+/* Address of the bottom of the data segment. */ +#define N_DATADDR(ex) \
+ N_ALIGN(ex, N_TXTADDR(ex) + (ex).a_text)
+
+/* Text segment offset. */
+#define N_TXTOFF(ex) \
+ (N_GETMAGIC(ex) == ZMAGIC ? __LDPGSZ : (N_GETMAGIC(ex) == QMAGIC || \
+ N_GETMAGIC_NET(ex) == ZMAGIC) ? 0 : sizeof(struct aout_header))
+
+/* Data segment offset. */
+#define N_DATOFF(ex) \
+ N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text)
+
+/* Relocation table offset. */
+#define N_RELOFF(ex) \
+ N_ALIGN(ex, N_DATOFF(ex) + (ex).a_data)
+
+/* Symbol table offset. */
+#define N_SYMOFF(ex) \
+ (N_RELOFF(ex) + (ex).a_trsize + (ex).a_drsize)
+
+/* String table offset. */
+#define N_STROFF(ex) (N_SYMOFF(ex) + (ex).a_syms)
+
+/*
+ * Header prepended to each a.out file.
+ * only manipulate the a_midmag field via the
+ * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros in a.out.h
+ */
+
+struct aout_header
+{

+  grub_uint32_t a_midmag;	/* htonl(flags<<26 | mid<<16 | magic) */
+  grub_uint32_t a_text;		/* text segment size */
+  grub_uint32_t a_data;		/* initialized data size */
+  grub_uint32_t a_bss;		/* uninitialized data size */
+  grub_uint32_t a_syms;		/* symbol table size */
+  grub_uint32_t a_entry;	/* entry point */
+  grub_uint32_t a_trsize;	/* text relocation size */
+  grub_uint32_t a_drsize;	/* data relocation size */
+};
+
+/* a_magic */
+#define	OMAGIC          0x107	/* 0407 old impure format */
+#define	NMAGIC          0x108	/* 0410 read-only text */
+#define	ZMAGIC          0x10b	/* 0413 demand load format */
+#define QMAGIC          0xcc	/* 0314 "compact" demand load format */

+
+/* a_mid */
+#define MID_ZERO 0 /* unknown - implementation dependent */
+#define MID_SUN010 1 /* sun 68010/68020 binary */
+#define MID_SUN020 2 /* sun 68020-only binary */
+#define MID_I386 134 /* i386 BSD binary */
+#define MID_SPARC 138 /* sparc */
+#define MID_HP200 200 /* hp200 (68010) BSD binary */
+#define MID_HP300 300 /* hp300 (68020+68881) BSD binary */
+#define MID_HPUX 0x20C /* hp200/300 HP-UX binary */
+#define MID_HPUX800 0x20B /* hp800 HP-UX binary */
+
+/*
+ * a_flags
+ */
+#define EX_PIC 0x10 /* contains position independant code */
+#define EX_DYNAMIC 0x20 /* contains run-time link-edit info */
+#define EX_DPMASK 0x30 /* mask for the above */
+
+void grub_aout_arch_boot (grub_addr_t entry); +void grub_rescue_cmd_aout (int argc, char *argv[]); +
+#endif /* ! GRUB_AOUT_LOADER_HEADER */

loader/aout.c new file +149 -0

149 lines not on this page · raw message

loader/aout_normal.c new file +45 -0

45 lines not on this page · raw message

loader/i386/pc/aout.c new file +28 -0
new file mode 100755
index 0000000..179d70f
@@ -0,0 +1,28 @@
+/* aout.c - boot an aout OS image. */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2008  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/loader.h>
+#include <grub/machine/loader.h>
+#include <grub/aout_loader.h>
+
+void
+grub_aout_arch_boot (grub_addr_t entry)
+{
+  grub_multiboot2_real_boot (entry, 0);
+}
Signature · 1 line
Bean
#7 lore raw
Quoted 12 lines · Bean
Quoted 11 lines · Robert Millan
Quoted 10 lines · Bean
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines

How FreeBSD-specific is this? Will the same module apply to other a.out binaries ? (I ask since you gave it a generic name)

it's an old format of the unix system:

http://en.wikipedia.org/wiki/A.out

I know.. I was referring to your loader.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

it should be generic, but i only test it using the loader from freebsd.

In that case, I'd suggest putting it directly in loader/ (without i386/pc/).

Moving files on CVS is a PITA :-/

ok, here is the new patch...

Good news and bad news. With this patch and your most recent ufs patch I can aout /boot/loader or multiboot /netbsd from a UFS partition, that is the good news.

The bad news is that when I type 'boot', /boot/loader prints out its one line of text to identify itself and then hangs forever.

When I type 'boot' after loading the netbsd kernel with multiboot, the machine reboots instantly instead of starting the OS.

Any ideas?

author
#8 lore raw
Quoted 26 lines · walt
Quoted 12 lines · Bean
Quoted 11 lines · Robert Millan
Quoted 10 lines · Bean
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines

How FreeBSD-specific is this? Will the same module apply to other a.out binaries ? (I ask since you gave it a generic name)

it's an old format of the unix system:

http://en.wikipedia.org/wiki/A.out

I know.. I was referring to your loader.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

it should be generic, but i only test it using the loader from freebsd.

In that case, I'd suggest putting it directly in loader/ (without i386/pc/).

Moving files on CVS is a PITA :-/

ok, here is the new patch...

Good news and bad news. With this patch and your most recent ufs patch I can aout /boot/loader or multiboot /netbsd from a UFS partition, that is the good news.

Quoted 7 lines

The bad news is that when I type 'boot', /boot/loader prints out its one line of text to identify itself and then hangs forever.

When I type 'boot' after loading the netbsd kernel with multiboot, the machine reboots instantly instead of starting the OS.

Any ideas?

is grub legacy ok ?

Signature · 1 line
Bean
#9 lore raw
Quoted 1 line · Bean

On Jan 28, 2008 10:37 PM, walt<[email protected]> wrote:

...

Quoted 7 lines
Quoted 7 lines

Good news and bad news. With this patch and your most recent ufs patch I can aout /boot/loader or multiboot /netbsd from a UFS partition, that is the good news.

The bad news is that when I type 'boot', /boot/loader prints out its one line of text to identify itself and then hangs forever.

Quoted 6 lines
Quoted 4 lines

When I type 'boot' after loading the netbsd kernel with multiboot, the machine reboots instantly instead of starting the OS.

Any ideas?

is grub legacy ok ?

I'm not sure what information you are asking for. Nothing has changed at my end concerning legacy. It still works, but why should it not?

author
#10 lore raw
Quoted 13 lines · walt
Quoted 1 line · Bean

On Jan 28, 2008 10:37 PM, walt<[email protected]> wrote:

...

Quoted 10 lines
Quoted 10 lines

Good news and bad news. With this patch and your most recent ufs patch I can aout /boot/loader or multiboot /netbsd from a UFS partition, that is the good news.

The bad news is that when I type 'boot', /boot/loader prints out its one line of text to identify itself and then hangs forever.

When I type 'boot' after loading the netbsd kernel with multiboot, the machine reboots instantly instead of starting the OS.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Any ideas?

is grub legacy ok ?

I'm not sure what information you are asking for. Nothing has changed at my end concerning legacy. It still works, but why should it not?

this is strange, it's working for me. perhaps you can try to load netnsd kernel from the ufs image you sent.

loopback loop (hd0,0)/ufs
multiboot (loop)/netbsd
boot

ufs is better placed in non ufs partition.

If this works, then it means there is still bug in the ufs driver.

Signature · 1 line
Bean
#11 lore raw
Quoted 24 lines · Bean
Quoted 13 lines · walt
Quoted 1 line · Bean

On Jan 28, 2008 10:37 PM, walt<[email protected]> wrote:

...

Quoted 10 lines
Quoted 10 lines

Good news and bad news. With this patch and your most recent ufs patch I can aout /boot/loader or multiboot /netbsd from a UFS partition, that is the good news.

The bad news is that when I type 'boot', /boot/loader prints out its one line of text to identify itself and then hangs forever.

When I type 'boot' after loading the netbsd kernel with multiboot, the machine reboots instantly instead of starting the OS.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Any ideas?

is grub legacy ok ?

I'm not sure what information you are asking for. Nothing has changed at my end concerning legacy. It still works, but why should it not?

this is strange, it's working for me. perhaps you can try to load netnsd kernel from the ufs image you sent.

Quoted 7 lines

loopback loop (hd0,0)/ufs
multiboot (loop)/netbsd
boot

ufs is better placed in non ufs partition.

If this works, then it means there is still bug in the ufs driver.

Sorry, I gave you incomplete information. I can use 'multiboot' to load the netbsd from any kind of fs, but it makes no difference: 'boot' then causes the machine to reboot instantly. The same applies to aout: I can aout load from any fs, but then 'boot' make the machine hang. The type of fs makes no difference.

I can still 'chainload +1' or 'linux' successfully.

All of the above applies to the latest grub2 from cvs with your most recent ufs and aout patches applied.

author
#12 lore raw
Quoted 10 lines · walt

Sorry, I gave you incomplete information. I can use 'multiboot' to load the netbsd from any kind of fs, but it makes no difference: 'boot' then causes the machine to reboot instantly. The same applies to aout: I can aout load from any fs, but then 'boot' make the machine hang. The type of fs makes no difference.

I can still 'chainload +1' or 'linux' successfully.

All of the above applies to the latest grub2 from cvs with your most recent ufs and aout patches applied.

in this case, the ufs driver should be ok.

btw, do you remember to apply the multiboot patch ? you can also make a qemu image for me to test.

Signature · 1 line
Bean
#13 lore raw
Quoted 9 lines · Bean
Quoted 8 lines · walt

Sorry, I gave you incomplete information. I can use 'multiboot' to load the netbsd from any kind of fs, but it makes no difference: 'boot' then causes the machine to reboot instantly. The same applies to aout: I can aout load from any fs, but then 'boot' make the machine hang. The type of fs makes no difference.

I can still 'chainload +1' or 'linux' successfully.

Quoted 7 lines
Quoted 2 lines

All of the above applies to the latest grub2 from cvs with your most recent ufs and aout patches applied.

in this case, the ufs driver should be ok.

btw, do you remember to apply the multiboot patch ? you can also make a qemu image for me to test.

Aha! I forgot the multiboot patch :o( Now I can multiboot netbsd from any filesystem and it 'just works'. Most excellent, thank you!

Sadly, 'aout /boot/loader' still hangs when I type 'boot'. The loader is obviously probing the floppy drive because I can hear it seeking just like it does when the machine reboots. This is not what happens when /boot/loader is working normally -- it should immediately load the kernel from the hard disk with no additional hardware probing.

Let me know if I can give you any more info.

author
#14 lore raw
Quoted 22 lines · walt
Quoted 9 lines · Bean
Quoted 8 lines · walt

Sorry, I gave you incomplete information. I can use 'multiboot' to load the netbsd from any kind of fs, but it makes no difference: 'boot' then causes the machine to reboot instantly. The same applies to aout: I can aout load from any fs, but then 'boot' make the machine hang. The type of fs makes no difference.

I can still 'chainload +1' or 'linux' successfully.

Quoted 7 lines
Quoted 2 lines

All of the above applies to the latest grub2 from cvs with your most recent ufs and aout patches applied.

in this case, the ufs driver should be ok.

btw, do you remember to apply the multiboot patch ? you can also make a qemu image for me to test.

Aha! I forgot the multiboot patch :o( Now I can multiboot netbsd from any filesystem and it 'just works'. Most excellent, thank you!

Quoted 7 lines

Sadly, 'aout /boot/loader' still hangs when I type 'boot'. The loader is obviously probing the floppy drive because I can hear it seeking just like it does when the machine reboots. This is not what happens when /boot/loader is working normally -- it should immediately load the kernel from the hard disk with no additional hardware probing.

Let me know if I can give you any more info.

i see, perhaps i need to set %dl properly before jumping to the code.

Signature · 1 line
Bean
#15 lore raw
In reply to walt
Quoted 6 lines · walt

When I type 'boot' after loading the netbsd kernel with multiboot, the machine reboots instantly instead of starting the OS.

Any ideas?

I've encountered this in qemu where it tells you you are executing code outside ram/rom at the kernel virtual entry address of 0xc0100000. The NetBSD/i386 kernel needs to be loaded/entered at physical address 0x00100000, it's, however, linked to run at 0xc0100000.

This is trivial to fix, but the trivial fix may not be the right fix.

Now if only I was having more luck when grub2 was loaded from coreboot. But that's another thread maybe.

Jonathan Kollasch

author
#16 lore raw
Quoted 13 lines · On Jan 29, 2008 3:11 PM, <[email protected]> wrote:
Quoted 6 lines · walt

When I type 'boot' after loading the netbsd kernel with multiboot, the machine reboots instantly instead of starting the OS.

Any ideas?

I've encountered this in qemu where it tells you you are executing code outside ram/rom at the kernel virtual entry address of 0xc0100000. The NetBSD/i386 kernel needs to be loaded/entered at physical address 0x00100000, it's, however, linked to run at 0xc0100000.

Quoted 4 lines

This is trivial to fix, but the trivial fix may not be the right fix.

Now if only I was having more luck when grub2 was loaded from coreboot. But that's another thread maybe.

my previous multiboot patch fix this problem.

Signature · 1 line
Bean
#17 lore raw
Quoted 14 lines · Bean
Quoted 13 lines · On Jan 29, 2008 3:11 PM, <[email protected]> wrote:
Quoted 6 lines · walt

When I type 'boot' after loading the netbsd kernel with multiboot, the machine reboots instantly instead of starting the OS.

Any ideas?

I've encountered this in qemu where it tells you you are executing code outside ram/rom at the kernel virtual entry address of 0xc0100000. The NetBSD/i386 kernel needs to be loaded/entered at physical address 0x00100000, it's, however, linked to run at 0xc0100000.

Quoted 6 lines
Quoted 4 lines

This is trivial to fix, but the trivial fix may not be the right fix.

Now if only I was having more luck when grub2 was loaded from coreboot. But that's another thread maybe.

my previous multiboot patch fix this problem.

Did that make it into the repository yet?

author
#18 lore raw
Quoted 16 lines · On Jan 30, 2008 2:11 AM, <[email protected]> wrote:
Quoted 14 lines · Bean
Quoted 13 lines · On Jan 29, 2008 3:11 PM, <[email protected]> wrote:
Quoted 6 lines · walt

When I type 'boot' after loading the netbsd kernel with multiboot, the machine reboots instantly instead of starting the OS.

Any ideas?

I've encountered this in qemu where it tells you you are executing code outside ram/rom at the kernel virtual entry address of 0xc0100000. The NetBSD/i386 kernel needs to be loaded/entered at physical address 0x00100000, it's, however, linked to run at 0xc0100000.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

This is trivial to fix, but the trivial fix may not be the right fix.

Now if only I was having more luck when grub2 was loaded from coreboot. But that's another thread maybe.

my previous multiboot patch fix this problem.

Did that make it into the repository yet?

no, you need to find it among the replies.

Signature · 1 line
Bean
#19 lore raw
In reply to [email protected]
Quoted 3 lines · On Tue, Jan 29, 2008 at 01:11:57AM -0600, [email protected] wrote:

Now if only I was having more luck when grub2 was loaded from coreboot. But that's another thread maybe.

Could you bring this up? (please change Subject if you do)

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 /.)
#20 lore raw
In reply to Bean
Quoted 12 lines · Bean
Quoted 11 lines · Robert Millan
Quoted 10 lines · Bean
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines

How FreeBSD-specific is this? Will the same module apply to other a.out binaries ? (I ask since you gave it a generic name)

it's an old format of the unix system:

http://en.wikipedia.org/wiki/A.out

I know.. I was referring to your loader.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

it should be generic, but i only test it using the loader from freebsd.

In that case, I'd suggest putting it directly in loader/ (without i386/pc/).

Moving files on CVS is a PITA :-/

ok, here is the new patch.

It would be nice if a.out support could be shared so it can be used for multiboot as well.

Quoted 101 lines

* conf/i386-pc.rmk (pkglib_MODULES): Add aout.mod and _aout.mod. (aout_mod_SOURCES): New variable.
(aout_mod_CFLAGS): Likewise.
(aout_mod_LDFLAGS): Likewise.
(_aout_mod_SOURCES): New variable. (_aout_mod_CFLAGS): Likewise.
(_aout_mod_LDFLAGS): Likewise.

* loader/aout.c: New file.

* loader/aout_normal.c: New file.

* loader/i386/pc/aout.c: New file.

* include/grub/aout_loader.h: New file.

conf/i386-pc.rmk +12 -2
index ff02332..36af7de 100644
@@ -151,8 +151,8 @@ grub_mkrescue_SOURCES = util/i386/pc/grub-mkrescue.in
 
 # Modules.
 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 \
+	_multiboot.mod chain.mod multiboot.mod _aout.mod aout.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
 
@@ -221,6 +221,16 @@ multiboot_mod_SOURCES = loader/multiboot_loader_normal.c
 multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
 multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For _aout.mod.
+_aout_mod_SOURCES = loader/aout.c loader/i386/pc/aout.c
+_aout_mod_CFLAGS = $(COMMON_CFLAGS)
+_aout_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For aout.mod.
+aout_mod_SOURCES = loader/aout_normal.c
+aout_mod_CFLAGS = $(COMMON_CFLAGS)
+aout_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 # For vbe.mod.
 vbe_mod_SOURCES = video/i386/pc/vbe.c video/i386/pc/vbeblit.c \
 		  video/i386/pc/vbefill.c video/i386/pc/vbeutil.c
include/grub/aout_loader.h new file +45 -0
new file mode 100755
index 0000000..64311eb
@@ -0,0 +1,134 @@
+/* aout_loader.h - a.out loader header file. */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2008  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef GRUB_AOUT_LOADER_HEADER
+#define GRUB_AOUT_LOADER_HEADER 1
+
+#define __LDPGSZ 0x1000
+
+#define N_GETMAGIC(ex) \
+	( (ex).a_midmag & 0xffff )
+#define N_GETMID(ex) \
+	( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETMID_NET(ex) : \
+	((ex).a_midmag >> 16) & 0x03ff )
+#define N_GETFLAG(ex) \
+	( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETFLAG_NET(ex) : \
+	((ex).a_midmag >> 26) & 0x3f )
+#define N_SETMAGIC(ex,mag,mid,flag) \
+	( (ex).a_midmag = (((flag) & 0x3f) <<26) | (((mid) & 0x03ff) << 16) | \
+	((mag) & 0xffff) )
+
+#define N_GETMAGIC_NET(ex) \
+	(grub_be_to_cpu32((ex).a_midmag) & 0xffff)
+#define N_GETMID_NET(ex) \
+	((grub_be_to_cpu32((ex).a_midmag) >> 16) & 0x03ff)
+#define N_GETFLAG_NET(ex) \
+	((grub_be_to_cpu32((ex).a_midmag) >> 26) & 0x3f)
+#define N_SETMAGIC_NET(ex,mag,mid,flag) \
+	( (ex).a_midmag = grub_cpu_to_be32( (((flag)&0x3f)<<26) |

(((mid)&0x03ff)<<16) | \

include/grub/aout_loader.h

Quoted 8 lines
include/grub/aout_loader.h new file +8 -0
+	(((mag)&0xffff)) ) )
+
+#define N_ALIGN(ex,x) \
+	(N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC || \
+	 N_GETMAGIC_NET(ex) == ZMAGIC || N_GETMAGIC_NET(ex) == QMAGIC ? \
+	 ((x) + __LDPGSZ - 1) & ~(unsigned long)(__LDPGSZ - 1) : (x))
+
+/* Valid magic number check. */

Please use two spaces after a `.'. I know this sounds minor, but I'd like to keep a consistent coding style. Same for the other comments.

Quoted 30 lines
include/grub/aout_loader.h new file +30 -0
+#define	N_BADMAG(ex) \
+	(N_GETMAGIC(ex) != OMAGIC && N_GETMAGIC(ex) != NMAGIC && \
+	 N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC && \
+	 N_GETMAGIC_NET(ex) != OMAGIC && N_GETMAGIC_NET(ex) != NMAGIC && \
+	 N_GETMAGIC_NET(ex) != ZMAGIC && N_GETMAGIC_NET(ex) != QMAGIC)
+
+/* Address of the bottom of the text segment. */
+#define N_TXTADDR(ex) \
+	((N_GETMAGIC(ex) == OMAGIC || N_GETMAGIC(ex) == NMAGIC || \
+	N_GETMAGIC(ex) == ZMAGIC) ? 0 : __LDPGSZ)
+
+/* Address of the bottom of the data segment. */
+#define N_DATADDR(ex) \
+	N_ALIGN(ex, N_TXTADDR(ex) + (ex).a_text)
+
+/* Text segment offset. */
+#define	N_TXTOFF(ex) \
+	(N_GETMAGIC(ex) == ZMAGIC ? __LDPGSZ : (N_GETMAGIC(ex) == QMAGIC || \
+	N_GETMAGIC_NET(ex) == ZMAGIC) ? 0 : sizeof(struct aout_header))
+
+/* Data segment offset. */
+#define	N_DATOFF(ex) \
+	N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text)
+
+/* Relocation table offset. */
+#define N_RELOFF(ex) \
+	N_ALIGN(ex, N_DATOFF(ex) + (ex).a_data)
+
+/* Symbol table offset. */
+#define N_SYMOFF(ex) \

include/grub/aout_loader.h

Quoted 10 lines
include/grub/aout_loader.h new file +10 -0
+	(N_RELOFF(ex) + (ex).a_trsize + (ex).a_drsize)
+
+/* String table offset. */
+#define	N_STROFF(ex)	(N_SYMOFF(ex) + (ex).a_syms)
+
+/*
+ * Header prepended to each a.out file.
+ * only manipulate the a_midmag field via the
+ * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros in a.out.h
+ */

Please do not use comments like this with a asterix on each line.

include/grub/aout_loader.h

Quoted 11 lines
include/grub/aout_loader.h new file +11 -0
+struct aout_header
+{
+  grub_uint32_t a_midmag;	/* htonl(flags<<26 | mid<<16 | magic) */
+  grub_uint32_t a_text;		/* text segment size */
+  grub_uint32_t a_data;		/* initialized data size */
+  grub_uint32_t a_bss;		/* uninitialized data size */
+  grub_uint32_t a_syms;		/* symbol table size */
+  grub_uint32_t a_entry;	/* entry point */
+  grub_uint32_t a_trsize;	/* text relocation size */
+  grub_uint32_t a_drsize;	/* data relocation size */
+};

Please fix these comments. Same for those below.

Quoted 6 lines
include/grub/aout_loader.h new file +6 -0
+/* a_magic */
+#define	OMAGIC          0x107	/* 0407 old impure format */
+#define	NMAGIC          0x108	/* 0410 read-only text */
+#define	ZMAGIC          0x10b	/* 0413 demand load format */
+#define QMAGIC          0xcc	/* 0314 "compact" demand load format */
+

include/grub/aout_loader.h

Quoted 10 lines
include/grub/aout_loader.h new file +10 -0
+/* a_mid */
+#define	MID_ZERO	0	/* unknown - implementation dependent */
+#define	MID_SUN010	1	/* sun 68010/68020 binary */
+#define	MID_SUN020	2	/* sun 68020-only binary */
+#define MID_I386	134	/* i386 BSD binary */
+#define MID_SPARC	138	/* sparc */
+#define	MID_HP200	200	/* hp200 (68010) BSD binary */
+#define	MID_HP300	300	/* hp300 (68020+68881) BSD binary */
+#define	MID_HPUX	0x20C	/* hp200/300 HP-UX binary */
+#define	MID_HPUX800     0x20B	/* hp800 HP-UX binary */

Like Robert asked, did you type this yourself?

Quoted 261 lines
include/grub/aout_loader.h new file +11 -0
+/*
+ * a_flags
+ */
+#define EX_PIC		0x10	/* contains position independant code */
+#define EX_DYNAMIC	0x20	/* contains run-time link-edit info */
+#define EX_DPMASK	0x30	/* mask for the above */
+
+void grub_aout_arch_boot (grub_addr_t entry);
+void grub_rescue_cmd_aout (int argc, char *argv[]);
+
+#endif /* ! GRUB_AOUT_LOADER_HEADER */
loader/aout.c new file +149 -0
new file mode 100644
index 0000000..584f93a
@@ -0,0 +1,149 @@
+/* aout.c - boot a.out loader (*BSD)  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2008  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/loader.h>
+#include <grub/file.h>
+#include <grub/err.h>
+#include <grub/rescue.h>
+#include <grub/dl.h>
+#include <grub/aout_loader.h>
+
+static grub_dl_t my_mod;
+
+static grub_addr_t entry;
+
+static grub_err_t
+grub_aout_boot (void)
+{
+  grub_aout_arch_boot (entry);
+
+  /* Not reached.  */
+  return GRUB_ERR_NONE;
+}
+
+static grub_err_t
+grub_aout_unload (void)
+{
+  grub_dl_unref (my_mod);
+  return GRUB_ERR_NONE;
+}
+
+void
+grub_rescue_cmd_aout (int argc, char *argv[])
+{
+  grub_file_t file = 0;
+  struct aout_header ah;
+  grub_addr_t cur_addr;
+  int align_4k;
+
+  grub_dl_ref (my_mod);
+
+  if (argc == 0)
+    {
+      grub_error (GRUB_ERR_BAD_ARGUMENT, "no kernel specified");
+      goto fail;
+    }
+
+  file = grub_file_open (argv[0]);
+  if (!file)
+    goto fail;
+
+  if (grub_file_read (file, (char *) &ah, sizeof (ah)) != sizeof (ah))
+    {
+      grub_error (GRUB_ERR_READ_ERROR, "cannot read the a.out header");
+      goto fail;
+    }
+
+  if (N_BADMAG (ah))
+    {
+      grub_error (GRUB_ERR_BAD_OS, "invalid magic number");
+      goto fail;
+    }
+
+  entry = ah.a_entry & 0xFFFFFF;
+
+  if (*((char *) &ah) == 0xb && (*((char *) &ah + 1) == 1))
+    {
+      cur_addr = entry;
+      align_4k = 0;
+    }
+  else
+    {
+      cur_addr = entry & 0xF00000;
+      align_4k = 1;
+    }
+
+  grub_file_seek (file, N_TXTOFF (ah));
+
+  if (grub_errno)
+    goto fail;
+
+  if (cur_addr < 0x100000)
+    {
+      grub_error (GRUB_ERR_BAD_OS, "load address below 1M");
+      goto fail;
+    }
+
+  if (grub_file_read (file, (char *) cur_addr, ah.a_text) != (int) ah.a_text)
+    {
+      grub_error (GRUB_ERR_READ_ERROR, "read text fails");
+      goto fail;
+    }
+
+  cur_addr += ah.a_text;
+
+  if (align_4k)
+    cur_addr = (cur_addr + 0xFFF) & 0xFFFFF000;
+
+  if (grub_file_read (file, (char *) cur_addr, ah.a_data) != (int) ah.a_data)
+    {
+      grub_error (GRUB_ERR_READ_ERROR, "read data fails");
+      goto fail;
+    }
+
+  cur_addr += ah.a_data;
+
+  if (align_4k)
+    cur_addr = (cur_addr + 0xFFF) & 0xFFFFF000;
+
+  if (ah.a_bss)
+    grub_memset ((char *) cur_addr, 0, ah.a_bss);
+
+  if (grub_errno == GRUB_ERR_NONE)
+    grub_loader_set (grub_aout_boot, grub_aout_unload, 1);
+
+fail:
+
+  if (file)
+    grub_file_close (file);
+
+  if (grub_errno != GRUB_ERR_NONE)
+    grub_dl_unref (my_mod);
+}
+
+GRUB_MOD_INIT (aout)
+{
+  grub_rescue_register_command ("aout", grub_rescue_cmd_aout, "load a.out");
+  my_mod = mod;
+}
+
+GRUB_MOD_FINI (aout)
+{
+  grub_rescue_unregister_command ("aout");
+}
loader/aout_normal.c new file +45 -0
new file mode 100644
index 0000000..6dc0b3e
@@ -0,0 +1,45 @@
+/* aout_normal.c - boot a.out loader (*BSD)  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2008  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/loader.h>
+#include <grub/err.h>
+#include <grub/normal.h>
+#include <grub/dl.h>
+#include <grub/aout_loader.h>
+
+static grub_err_t
+grub_normal_aout_command (struct grub_arg_list *state
+			  __attribute__ ((unused)), int argc, char **args)
+{
+  grub_rescue_cmd_aout (argc, args);
+  return grub_errno;
+}
+
+GRUB_MOD_INIT (aout_normal)
+{
+  (void) mod;			/* To stop warning.  */
+  grub_register_command ("aout", grub_normal_aout_command,
+			 GRUB_COMMAND_FLAG_BOTH,
+			 "aout FILE [ARGS...]", "Load an a.out kernel.", 0);
+}
+
+GRUB_MOD_FINI (aout_normal)
+{
+  grub_unregister_command ("aout");
+}
loader/i386/pc/aout.c new file +28 -0
new file mode 100755
index 0000000..179d70f
@@ -0,0 +1,28 @@
+/* aout.c - boot an aout OS image. */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2008  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/loader.h>
+#include <grub/machine/loader.h>
+#include <grub/aout_loader.h>
+
+void
+grub_aout_arch_boot (grub_addr_t entry)
+{
+  grub_multiboot2_real_boot (entry, 0);
+}
Signature · 8 lines
-- 
Bean


_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
author
#21 lore raw
Quoted 16 lines · Marco Gerards
Quoted 14 lines · Bean
Quoted 13 lines · Robert Millan
Quoted 11 lines · Bean
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines

How FreeBSD-specific is this? Will the same module apply to other a.out binaries ? (I ask since you gave it a generic name)

it's an old format of the unix system:

http://en.wikipedia.org/wiki/A.out

I know.. I was referring to your loader.

it should be generic, but i only test it using the loader from freebsd.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

In that case, I'd suggest putting it directly in loader/ (without i386/pc/).

Moving files on CVS is a PITA :-/

ok, here is the new patch.

It would be nice if a.out support could be shared so it can be used for multiboot as well.

you mean adding it to the multiboot module ?

Quoted 4 lines
Quoted 4 lines
(quoted diff) +4 -0
+/* a_mid */
+#define      MID_ZERO        0       /* unknown - implementation dependent */
+#define      MID_SUN010      1       /* sun 68010/68020 binary */
+#define      MID_SUN020      2       /* sun 68020-only binary */
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+#define MID_I386     134     /* i386 BSD binary */
+#define MID_SPARC    138     /* sparc */
+#define      MID_HP200       200     /* hp200 (68010) BSD binary */
+#define      MID_HP300       300     /* hp300 (68020+68881) BSD binary */
+#define      MID_HPUX        0x20C   /* hp200/300 HP-UX binary */
+#define      MID_HPUX800     0x20B   /* hp800 HP-UX binary */

Like Robert asked, did you type this yourself?

the header is copied from grub legacy image_aout.h, maybe i can format it properly.

Signature · 1 line
Bean
#22 lore raw
Quoted 19 lines · Bean
Quoted 18 lines · Marco Gerards
Quoted 16 lines · Bean
Quoted 15 lines · Robert Millan
Quoted 11 lines · Bean
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines

How FreeBSD-specific is this? Will the same module apply to other a.out binaries ? (I ask since you gave it a generic name)

it's an old format of the unix system:

http://en.wikipedia.org/wiki/A.out

I know.. I was referring to your loader.

it should be generic, but i only test it using the loader from freebsd.

In that case, I'd suggest putting it directly in loader/ (without i386/pc/).

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Moving files on CVS is a PITA :-/

ok, here is the new patch.

It would be nice if a.out support could be shared so it can be used for multiboot as well.

you mean adding it to the multiboot module ?

The multiboot standard supports a.out. It would be nice if it was also capable of a.out. So this code can somehow be shared, like ELF support is shared now.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4 -0
+/* a_mid */
+#define      MID_ZERO        0       /* unknown - implementation dependent */
+#define      MID_SUN010      1       /* sun 68010/68020 binary */
+#define      MID_SUN020      2       /* sun 68020-only binary */
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+#define MID_I386     134     /* i386 BSD binary */
+#define MID_SPARC    138     /* sparc */
+#define      MID_HP200       200     /* hp200 (68010) BSD binary */
+#define      MID_HP300       300     /* hp300 (68020+68881) BSD binary */
+#define      MID_HPUX        0x20C   /* hp200/300 HP-UX binary */
+#define      MID_HPUX800     0x20B   /* hp800 HP-UX binary */

Like Robert asked, did you type this yourself?

Quoted 2 lines

the header is copied from grub legacy image_aout.h, maybe i can format it properly.

Please do not blindly assume the copyright assignments for GRUB Legacy are ok... Perhaps they are not, I can't check...

--
Marco

author
#23 lore raw
Quoted 25 lines · Marco Gerards
Quoted 23 lines · Bean
Quoted 22 lines · Marco Gerards
Quoted 19 lines · Bean
Quoted 9 lines · Robert Millan
Quoted 8 lines · Bean
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

How FreeBSD-specific is this? Will the same module apply to other a.out binaries ? (I ask since you gave it a generic name)

it's an old format of the unix system:

http://en.wikipedia.org/wiki/A.out

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

I know.. I was referring to your loader.

it should be generic, but i only test it using the loader from freebsd.

In that case, I'd suggest putting it directly in loader/ (without i386/pc/).

Moving files on CVS is a PITA :-/

ok, here is the new patch.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

It would be nice if a.out support could be shared so it can be used for multiboot as well.

you mean adding it to the multiboot module ?

The multiboot standard supports a.out. It would be nice if it was also capable of a.out. So this code can somehow be shared, like ELF support is shared now.

but it doesn't have the multiboot header, or the header is not necessary in multiboot 2 ?

btw, where can i find spec on multiboot 2 ?

Signature · 1 line
Bean
#24 lore raw
Quoted 7 lines · Bean
Quoted 4 lines

The multiboot standard supports a.out. It would be nice if it was also capable of a.out. So this code can somehow be shared, like ELF support is shared now.

but it doesn't have the multiboot header, or the header is not necessary in multiboot 2 ?

It has a header, but that is the part that cannot be shared, of course. I think what Marco means is to split generic a.out stuff like we do for ELF (we have ELF in kernel because it's used by the module loader, but for a.out maybe it's better to use a separate module?).

For example we could have:

- aout.mod: provides generic a.out routines.
- freebsd-loader.mod: freebsd-specific part (relies on aout routines).
- multiboot.mod: may be improved to rely on aout.mod when necessary.

Quoted 1 line

btw, where can i find spec on multiboot 2 ?

See http://grub.enbug.org/MultibootDraft

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 /.)
#25 lore raw
Quoted 14 lines · Robert Millan
Quoted 7 lines · Bean
Quoted 4 lines

The multiboot standard supports a.out. It would be nice if it was also capable of a.out. So this code can somehow be shared, like ELF support is shared now.

but it doesn't have the multiboot header, or the header is not necessary in multiboot 2 ?

It has a header, but that is the part that cannot be shared, of course. I think what Marco means is to split generic a.out stuff like we do for ELF (we have ELF in kernel because it's used by the module loader, but for a.out maybe it's better to use a separate module?).

Quoted 5 lines

For example we could have:

- aout.mod: provides generic a.out routines.
- freebsd-loader.mod: freebsd-specific part (relies on aout routines).
- multiboot.mod: may be improved to rely on aout.mod when necessary.

Right! I need a rml extension for gnus that transforms my brainwaves into an email ;-)

--
Marco