shithub: riscv

Download patch

ref: 7f8bd359548ce61cad5011e44075d21e83d56314
parent: 5fe33fb80804cadc3c934337fde81af5b7d44243
author: Jacob Moody <moody@posixcafe.org>
date: Wed Mar 27 11:54:10 EDT 2024

9l: add -H6 for elf targeting kexec

--- a/sys/src/cmd/9l/asm.c
+++ b/sys/src/cmd/9l/asm.c
@@ -93,6 +93,7 @@
 	case 1:
 	case 2:
 	case 5:
+	case 6:
 		seek(cout, HEADR+textsize, 0);
 		break;
 	case 3:
@@ -125,6 +126,7 @@
 		case 1:
 		case 2:
 		case 5:
+		case 6:
 			seek(cout, HEADR+textsize+datsize, 0);
 			break;
 		case 3:
@@ -194,6 +196,7 @@
 	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 @@
 			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 */
--- a/sys/src/cmd/9l/obj.c
+++ b/sys/src/cmd/9l/obj.c
@@ -168,9 +168,18 @@
 		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)