From 7f8bd359548ce61cad5011e44075d21e83d56314 Mon Sep 17 00:00:00 2001 From: Jacob Moody Date: Wed, 27 Mar 2024 15:54:10 +0000 Subject: [PATCH] 9l: add -H6 for elf targeting kexec --- sys/src/cmd/9l/asm.c | 66 +++++++++++++++++++++++++++++--------------- sys/src/cmd/9l/obj.c | 13 +++++++-- 2 files changed, 54 insertions(+), 25 deletions(-) diff --git a/sys/src/cmd/9l/asm.c b/sys/src/cmd/9l/asm.c index 85b38527d..2234bc925 100644 --- a/sys/src/cmd/9l/asm.c +++ b/sys/src/cmd/9l/asm.c @@ -93,6 +93,7 @@ asmb(void) case 1: case 2: case 5: + case 6: seek(cout, HEADR+textsize, 0); break; case 3: @@ -125,6 +126,7 @@ asmb(void) case 1: case 2: case 5: + case 6: seek(cout, HEADR+textsize+datsize, 0); break; case 3: @@ -194,6 +196,7 @@ asmb(void) case 3: break; case 5: + case 6: strnput("\177ELF", 4); /* e_ident */ CPUT(2); /* class = 64 bit */ CPUT(2); /* data = MSB */ @@ -210,32 +213,49 @@ asmb(void) lput((0x40L<<16)|0x38L); /* Ehdr & Phdr sizes*/ lput((3L<<16)|0x40L); /* # Phdrs & Shdr size */ lput((3L<<16)|2L); /* # Shdrs & shdr string size */ - } - else{ - llput(0L); - lput(0L); /* flags = PPC */ + } else { + llput(0L); /* offset to first shdr */ + lput(0L); /* flags = PPC */ lput((0x40L<<16)|0x38L); /* Ehdr & Phdr sizes*/ - lput((3L<<16)|0L); /* # Phdrs & Shdr size */ - lput((3L<<16)|0L); /* # Shdrs & shdr string size */ + if(HEADTYPE == 5) + lput((3L<<16)|0L); /* # Phdrs & Shdr size */ + else + lput((2L<<16)|0L); /* # Phdrs & Shdr size */ + lput((0L<<16)|0L); /* # Shdrs & shdr string size */ } - lput(1L); /* text - type = PT_LOAD */ - lput(0x05L); /* protections = RX */ - llput(HEADR); /* file offset */ - llput(INITTEXT); /* vaddr */ - llput(INITTEXT); /* paddr */ - llput(textsize); /* file size */ - llput(textsize); /* memory size */ - llput(0x10000L); /* alignment */ - - lput(1L); /* data - type = PT_LOAD */ - lput(0x07L); /* protections = RWX */ - llput(HEADR+textsize); /* file offset */ - llput(INITDAT); /* vaddr */ - llput(INITDAT); /* paddr */ - llput(datsize); /* file size */ - llput(datsize); /* memory size */ - llput(0x10000L); /* alignment */ + if(HEADTYPE == 5){ + lput(1L); /* text - type = PT_LOAD */ + lput(0x05L); /* protections = RX */ + llput(HEADR); /* file offset */ + llput(INITTEXT); /* vaddr */ + llput(INITTEXT); /* paddr */ + llput(textsize); /* file size */ + llput(textsize); /* memory size */ + llput(0x10000L); /* alignment */ + + lput(1L); /* data - type = PT_LOAD */ + lput(0x07L); /* protections = RWX */ + llput(HEADR+textsize); /* file offset */ + llput(INITDAT); /* vaddr */ + llput(INITDAT); /* paddr */ + llput(datsize); /* file size */ + llput(datsize); /* memory size */ + llput(0x10000L); /* alignment */ + } else { + lput(1L); /* text + data - type = PT_LOAD */ + lput(0x07L); /* protections = RWX */ + llput(HEADR); /* file offset */ + /* + * linux kexec shits the bed with high physical segments. + * These are not actually used, so we just grumble and comply. + * / + llput(INITTEXT&0xFFFFFFFF); /* vaddr */ + llput(INITTEXT&0xFFFFFFFF); /* paddr */ + llput(textsize+datsize); /* file size */ + llput(textsize+datsize); /* memory size */ + llput(0x100000L); /* alignment */ + } lput(0L); /* data - type = PT_NULL */ lput(0x04L); /* protections = R */ diff --git a/sys/src/cmd/9l/obj.c b/sys/src/cmd/9l/obj.c index 77a25da43..73e9981b8 100644 --- a/sys/src/cmd/9l/obj.c +++ b/sys/src/cmd/9l/obj.c @@ -168,9 +168,18 @@ main(int argc, char *argv[]) if(INITTEXT == -1) INITTEXT = 0x00400000L+HEADR; if(INITDAT == -1) - INITDAT = 0x10000000; + INITDAT = 0; if(INITRND == -1) - INITRND = 0; + INITRND = 0x10000; + break; + case 6: /* bootable elf executable */ + HEADR = rnd(0x40L+3*0x38L, 16); + if(INITTEXT == -1) + INITTEXT = 0x00400000L+HEADR; + if(INITDAT == -1) + INITDAT = 0; + if(INITRND == -1) + INITRND = 0x100000; break; } if(INITDAT != 0 && INITRND != 0)