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