shithub: riscv

Download patch

ref: ceba67bc0648dec08ff495b6c2608a46462b64ab
parent: 29ce934c91dec63f3ab7d3826297874c8cc6aac0
author: Jacob Moody <moody@posixcafe.org>
date: Sun Oct 1 17:08:38 EDT 2023

9l: fix ELF generation

--- a/sys/src/cmd/9l/asm.c
+++ b/sys/src/cmd/9l/asm.c
@@ -195,56 +195,56 @@
 		break;
 	case 5:
 		strnput("\177ELF", 4);		/* e_ident */
-		CPUT(1);			/* class = 32 bit */
+		CPUT(2);			/* class = 64 bit */
 		CPUT(2);			/* data = MSB */
 		CPUT(1);			/* version = CURRENT */
 		strnput("", 9);
-		lput((2L<<16)|20L);		/* type = EXEC; machine = PowerPC */
+		lput((2L<<16)|21L);		/* type = EXEC; machine = PowerPC64 */
 		lput(1L);			/* version = CURRENT */
-		lput(PADDR(entryvalue()));	/* entry vaddr */
-		lput(52L);			/* offset to first phdr */
+		llput(entryvalue());	/* entry vaddr */
+		llput(0x40L);			/* offset to first phdr */
 
 		if(debug['S']){
-			lput(HEADR+textsize+datsize+symsize);	/* offset to first shdr */
+			llput(HEADR+textsize+datsize+symsize);	/* offset to first shdr */
 			lput(0L);		/* flags = PPC */
-			lput((52L<<16)|32L);	/* Ehdr & Phdr sizes*/
-			lput((3L<<16)|40L);	/* # Phdrs & Shdr size */
+			lput((0x40L<<16)|0x38L);	/* Ehdr & Phdr sizes*/
+			lput((3L<<16)|0x40L);	/* # Phdrs & Shdr size */
 			lput((3L<<16)|2L);	/* # Shdrs & shdr string size */
 		}
 		else{
-			lput(0L);
+			llput(0L);
 			lput(0L);		/* flags = PPC */
-			lput((52L<<16)|32L);	/* Ehdr & Phdr sizes*/
+			lput((0x40L<<16)|0x38L);	/* Ehdr & Phdr sizes*/
 			lput((3L<<16)|0L);	/* # Phdrs & Shdr size */
 			lput((3L<<16)|0L);	/* # Shdrs & shdr string size */
 		}
 
 		lput(1L);			/* text - type = PT_LOAD */
-		lput(HEADR);			/* file offset */
-		lput(PADDR(INITTEXT));	/* vaddr */
-		lput(INITTEXT);			/* paddr */
-		lput(textsize);			/* file size */
-		lput(textsize);			/* memory size */
 		lput(0x05L);			/* protections = RX */
-		lput(0x10000L);			/* alignment */
+		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(HEADR+textsize);		/* file offset */
-		lput(PADDR(INITDAT));		/* vaddr */
-		lput(INITDAT);			/* paddr */
-		lput(datsize);			/* file size */
-		lput(datsize);			/* memory size */
 		lput(0x07L);			/* protections = RWX */
-		lput(0x10000L);			/* alignment */
+		llput(HEADR+textsize);		/* file offset */
+		llput(INITDAT);		/* vaddr */
+		llput(INITDAT);			/* paddr */
+		llput(datsize);			/* file size */
+		llput(datsize);			/* memory size */
+		llput(0x10000L);			/* alignment */
 
 		lput(0L);			/* data - type = PT_NULL */
-		lput(HEADR+textsize+datsize);	/* file offset */
-		lput(0L);
-		lput(0L);
-		lput(symsize);			/* symbol table size */
-		lput(lcsize);			/* line number size */
 		lput(0x04L);			/* protections = R */
-		lput(0x04L);			/* alignment code?? */
+		llput(HEADR+textsize+datsize);	/* file offset */
+		llput(0L);
+		llput(0L);
+		llput(symsize);			/* symbol table size */
+		llput(lcsize);			/* line number size */
+		llput(0x04L);			/* alignment code?? */
 		cflush();
 
 		if(!debug['S'])
@@ -253,37 +253,37 @@
 		seek(cout, HEADR+textsize+datsize+symsize, 0);
 		lput(1);			/* Section name (string tbl index) */
 		lput(1);			/* Section type */
-		lput(2|4);			/* Section flags */
-		lput(PADDR(INITTEXT));	/* Section virtual addr at execution */
-		lput(HEADR);			/* Section file offset */
-		lput(textsize);			/* Section size in bytes */
+		llput(2|4);			/* Section flags */
+		llput(INITTEXT);	/* Section virtual addr at execution */
+		llput(HEADR);			/* Section file offset */
+		llput(textsize);			/* Section size in bytes */
 		lput(0);			/* Link to another section */
 		lput(0);			/* Additional section information */
-		lput(0x10000L);			/* Section alignment */
-		lput(0);			/* Entry size if section holds table */
+		llput(0x10000L);			/* Section alignment */
+		llput(0);			/* Entry size if section holds table */
 
 		lput(7);			/* Section name (string tbl index) */
 		lput(1);			/* Section type */
-		lput(2|1);			/* Section flags */
-		lput(PADDR(INITDAT));		/* Section virtual addr at execution */
-		lput(HEADR+textsize);		/* Section file offset */
-		lput(datsize);			/* Section size in bytes */
+		llput(2|1);			/* Section flags */
+		llput(INITDAT);		/* Section virtual addr at execution */
+		llput(HEADR+textsize);		/* Section file offset */
+		llput(datsize);			/* Section size in bytes */
 		lput(0);			/* Link to another section */
 		lput(0);			/* Additional section information */
-		lput(0x10000L);			/* Section alignment */
-		lput(0);			/* Entry size if section holds table */
+		llput(0x10000L);			/* Section alignment */
+		llput(0);			/* Entry size if section holds table */
 
 		/* string section header */
 		lput(12);			/* Section name (string tbl index) */
 		lput(3);			/* Section type */
-		lput(1 << 5);			/* Section flags */
-		lput(0);			/* Section virtual addr at execution */
-		lput(HEADR+textsize+datsize+symsize+3*40);	/* Section file offset */
-		lput(14);			/* Section size in bytes */
+		llput(1 << 5);			/* Section flags */
+		llput(0);			/* Section virtual addr at execution */
+		llput(HEADR+textsize+datsize+symsize+3*40);	/* Section file offset */
+		llput(14);			/* Section size in bytes */
 		lput(0);			/* Link to another section */
 		lput(0);			/* Additional section information */
-		lput(1);			/* Section alignment */
-		lput(0);			/* Entry size if section holds table */
+		llput(1);			/* Section alignment */
+		llput(0);			/* Entry size if section holds table */
 
 		/* string table */
 		cput(0);
--- a/sys/src/cmd/9l/obj.c
+++ b/sys/src/cmd/9l/obj.c
@@ -164,7 +164,7 @@
 			INITRND = 0;
 		break;
 	case 5:	/* elf executable */
-		HEADR = rnd(52L+3*32L, 16);
+		HEADR = rnd(0x40L+3*0x38L, 16);
 		if(INITTEXT == -1)
 			INITTEXT = 0x00400000L+HEADR;
 		if(INITDAT == -1)