NextSTEP's bootloader for Sparc32 expects that the 32 bytes a.out header is copied just before the start address.
Signed-off-by: Olivier Danet odanet@caramail.com =================================================================== --- libopenbios/aout_load.c (révision 1257) +++ libopenbios/aout_load.c (copie de travail) @@ -139,6 +139,8 @@ goto out; } } + seek_io(fd, offset); + read_io(fd, (char *)(start-0x20), 0x20);
debug("Loaded %lu bytes\n", size); debug("entry point is %#lx\n", start); ===================================================================
On 01/02/14 20:54, Olivier Danet wrote:
NextSTEP's bootloader for Sparc32 expects that the 32 bytes a.out header is copied just before the start address.
Signed-off-by: Olivier Danet odanet@caramail.com
--- libopenbios/aout_load.c (révision 1257) +++ libopenbios/aout_load.c (copie de travail) @@ -139,6 +139,8 @@ goto out; } }
- seek_io(fd, offset);
- read_io(fd, (char *)(start-0x20), 0x20);
debug("Loaded %lu bytes\n", size); debug("entry point is %#lx\n", start); ===================================================================
Hmmmm I'm not sure that anything below load-base is supposed to be mapped. Is it possible to load the header at start, and then simply add N_TXTOFF(ehdr) to the read_io() destination offsets? Or are the addresses in the a.out binary absolute?
ATB,
Mark.
On 05/02/2014 00:40, Mark Cave-Ayland wrote:
On 01/02/14 20:54, Olivier Danet wrote:
NextSTEP's bootloader for Sparc32 expects that the 32 bytes a.out header is copied just before the start address.
Signed-off-by: Olivier Danet odanet@caramail.com
--- libopenbios/aout_load.c (révision 1257) +++ libopenbios/aout_load.c (copie de travail) @@ -139,6 +139,8 @@ goto out; } }
- seek_io(fd, offset);
- read_io(fd, (char *)(start-0x20), 0x20);
debug("Loaded %lu bytes\n", size); debug("entry point is %#lx\n", start); ===================================================================
Hmmmm I'm not sure that anything below load-base is supposed to be mapped. Is it possible to load the header at start, and then simply add N_TXTOFF(ehdr) to the read_io() destination offsets? Or are the addresses in the a.out binary absolute?
ATB,
Mark.
Here is the beginning of the NextSTEP bootloader :
Dump of assembler code from 0x4000 to 0x4100: => 0x00004000: tst %o0 0x00004004: be 0x404c 0x00004008: nop 0x0000400c: mov %o0, %g7 0x00004010: sethi %hi(0x4000), %o1 0x00004014: mov %o1, %o1 ! 0x4000 0x00004018: sub %o1, 0x1c, %o2 0x0000401c: ld [ %o2 ], %o2 <<<<<<< HERE : $O2=*(0x4000-0x1C) 0x00004020: add %o2, %o1, %o2 0x00004024: sethi %hi(0x5800), %g1 0x00004028: st %g7, [ %g1 + 0x110 ] ! 0x5910 0x0000402c: ld [ %o0 + 4 ], %o4 0x00004030: mov %o1, %l0 0x00004034: add %o1, 0x20, %l1 0x00004038: call 0x4088 0x0000403c: sub %o2, %o1, %l2 0x00004040: tst %o4 0x00004044: be 0x404c 0x00004048: nop 0x0000404c: save %o1, -96, %sp 0x00004050: call 0x432c
Addresses are absolute. This code is directly copied from the ISO's sector 1
It accesses the a.out header very early (which helped _a lot_ to find the bug) to get the a_text field, which is the lenght of the TEXT segment. Sun's OpenBOOT copies the whole header at 0x3FE0, not the .a_text only.
Are there SunOS version using a.out ?
Of course, we could add #ifdef CONFIG_SPARC32 fences.
Regards
On 05/02/14 22:51, Olivier Danet wrote:
Here is the beginning of the NextSTEP bootloader :
Dump of assembler code from 0x4000 to 0x4100: => 0x00004000: tst %o0 0x00004004: be 0x404c 0x00004008: nop 0x0000400c: mov %o0, %g7 0x00004010: sethi %hi(0x4000), %o1 0x00004014: mov %o1, %o1 ! 0x4000 0x00004018: sub %o1, 0x1c, %o2 0x0000401c: ld [ %o2 ], %o2 <<<<<<< HERE : $O2=*(0x4000-0x1C) 0x00004020: add %o2, %o1, %o2 0x00004024: sethi %hi(0x5800), %g1 0x00004028: st %g7, [ %g1 + 0x110 ] ! 0x5910 0x0000402c: ld [ %o0 + 4 ], %o4 0x00004030: mov %o1, %l0 0x00004034: add %o1, 0x20, %l1 0x00004038: call 0x4088 0x0000403c: sub %o2, %o1, %l2 0x00004040: tst %o4 0x00004044: be 0x404c 0x00004048: nop 0x0000404c: save %o1, -96, %sp 0x00004050: call 0x432c
Addresses are absolute. This code is directly copied from the ISO's sector 1
It accesses the a.out header very early (which helped _a lot_ to find the bug) to get the a_text field, which is the lenght of the TEXT segment. Sun's OpenBOOT copies the whole header at 0x3FE0, not the .a_text only.
Are there SunOS version using a.out ?
Of course, we could add #ifdef CONFIG_SPARC32 fences.
Hi Olivier,
Thanks for this. Checking the source here I see that only SPARC32 and SPARC64 define CONFIG_LOADER_AOUT, so it's a fairly limited audience.
I wonder if we need to control whether things are non-compliant or not through the CONFIG_QEMU switch?
Regardless, for this case I think just add a #define at the top of the file that controls whether or not to load the header beneath load-base. As a minor nit, would it be possible to rework the patch so that it optionally loads the header first before the payload? At the moment, it loads the payload and then seeks back to read in the header which seems slightly counter-intuitive.
ATB,
Mark.
On 07/02/2014 19:24, Mark Cave-Ayland wrote:
On 05/02/14 22:51, Olivier Danet wrote:
Here is the beginning of the NextSTEP bootloader :
Dump of assembler code from 0x4000 to 0x4100: => 0x00004000: tst %o0 0x00004004: be 0x404c 0x00004008: nop 0x0000400c: mov %o0, %g7 0x00004010: sethi %hi(0x4000), %o1 0x00004014: mov %o1, %o1 ! 0x4000 0x00004018: sub %o1, 0x1c, %o2 0x0000401c: ld [ %o2 ], %o2 <<<<<<< HERE : $O2=*(0x4000-0x1C) 0x00004020: add %o2, %o1, %o2 0x00004024: sethi %hi(0x5800), %g1 0x00004028: st %g7, [ %g1 + 0x110 ] ! 0x5910 0x0000402c: ld [ %o0 + 4 ], %o4 0x00004030: mov %o1, %l0 0x00004034: add %o1, 0x20, %l1 0x00004038: call 0x4088 0x0000403c: sub %o2, %o1, %l2 0x00004040: tst %o4 0x00004044: be 0x404c 0x00004048: nop 0x0000404c: save %o1, -96, %sp 0x00004050: call 0x432c
Addresses are absolute. This code is directly copied from the ISO's sector 1
It accesses the a.out header very early (which helped _a lot_ to find the bug) to get the a_text field, which is the lenght of the TEXT segment. Sun's OpenBOOT copies the whole header at 0x3FE0, not the .a_text only.
Are there SunOS version using a.out ?
Of course, we could add #ifdef CONFIG_SPARC32 fences.
Hi Olivier,
Thanks for this. Checking the source here I see that only SPARC32 and SPARC64 define CONFIG_LOADER_AOUT, so it's a fairly limited audience.
I wonder if we need to control whether things are non-compliant or not through the CONFIG_QEMU switch?
Regardless, for this case I think just add a #define at the top of the file that controls whether or not to load the header beneath load-base. As a minor nit, would it be possible to rework the patch so that it optionally loads the header first before the payload? At the moment, it loads the payload and then seeks back to read in the header which seems slightly counter-intuitive.
ATB,
Mark.
Right, there is no need to seek backwards to pick the a.out header on disk, as it is already loaded in memory.
Simpler :
Index: libopenbios/aout_load.c =================================================================== --- libopenbios/aout_load.c (révision 1257) +++ libopenbios/aout_load.c (copie de travail) @@ -9,6 +9,9 @@ #ifdef CONFIG_SPARC64 #define CONFIG_SPARC64_PAGE_SIZE_8KB #endif +#ifdef CONFIG_SPARC32 +#define AOUT_HEADER_COPY +#endif
#include "libopenbios/sys_info.h" #include "libopenbios/bindings.h" @@ -140,6 +143,10 @@ } }
+#ifdef AOUT_HEADER_COPY + // Copy the a.out header just before the start + memcpy((char *)(start-0x20), &ehdr, 0x20); +#endif debug("Loaded %lu bytes\n", size); debug("entry point is %#lx\n", start);
===================================================================
Olivier
On 09/02/14 21:56, Olivier Danet wrote:
Right, there is no need to seek backwards to pick the a.out header on disk, as it is already loaded in memory.
Simpler :
Index: libopenbios/aout_load.c
--- libopenbios/aout_load.c (révision 1257) +++ libopenbios/aout_load.c (copie de travail) @@ -9,6 +9,9 @@ #ifdef CONFIG_SPARC64 #define CONFIG_SPARC64_PAGE_SIZE_8KB #endif +#ifdef CONFIG_SPARC32 +#define AOUT_HEADER_COPY +#endif
#include "libopenbios/sys_info.h" #include "libopenbios/bindings.h" @@ -140,6 +143,10 @@ } }
+#ifdef AOUT_HEADER_COPY
- // Copy the a.out header just before the start
- memcpy((char *)(start-0x20), &ehdr, 0x20);
+#endif debug("Loaded %lu bytes\n", size); debug("entry point is %#lx\n", start);
===================================================================
Yes, this looks better to me. If you don't mind, I'll tweak the comment/commit message and apply it over the next few days.
ATB,
Mark.