Browse Source

riscv: reconciliations and bug fixes

amd64/core.json now includes virtio, since that's portable
but not usable with riscv yet. mmutlbflush, as designed,
can't take a parameter on pretty much everything. We can
change it back if it ever makes sense, but its use in port/
had an amd64 dependency wired in. Elf64 has to be more relaxed
about alignment in ELF program headers, due to gcc issues.
syscallfmt needs to be more careful about not throwing an
error when a system call has invalid arguments.

Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Ronald G. Minnich 7 years ago
parent
commit
e40f3d70cd

+ 3 - 2
sys/src/9/amd64/core.json

@@ -111,6 +111,7 @@
 			"../port/devether.c",
 			"../port/devmouse.c",
 			"../port/devpci.c",
+			"../port/devvcon.c",
 			"devpmc.c",
 			"ether.c",
 			"fpu.c",
@@ -133,8 +134,8 @@
 			"systab.c",
 			"tcore.c",
 			"trap.c",
-			"../port/usbehci.c"
-
+			"../port/usbehci.c",
+			"../port/virtio_lib.c"
 		]
 	}
 }

+ 1 - 1
sys/src/9/amd64/fns.h

@@ -106,7 +106,7 @@ void	mapraminit(uint64_t, uint64_t);
 void	mapupainit(uint64_t, uint32_t);
 void	meminit(void);
 void	mfence(void);
-void	mmuflushtlb(uint64_t);
+void	mmuflushtlb(void);
 void	mmuinit(void);
 uintptr_t	mmukmap(uintptr_t, uintptr_t, usize);
 int	mmukmapsync(uint64_t);

+ 1 - 1
sys/src/9/amd64/mmu.c

@@ -29,7 +29,7 @@
 #define PPN(x)		((x)&~(PGSZ-1))
 
 void
-mmuflushtlb(uint64_t u)
+mmuflushtlb(void)
 {
 
 	machp()->tlbpurge++;

+ 6 - 2
sys/src/9/port/elf64.c

@@ -269,6 +269,7 @@ static struct {
 	{"amd64", EM_X86_64},
 	{"aarch64", EM_AARCH64},
 	{"power64", EM_PPC64},
+	{"riscv", EM_RISCV},
 };
 
 static int
@@ -418,9 +419,12 @@ elf64ldseg(Chan *c, uintptr_t *entryp, Ldseg **rp, char *mach, uint32_t minpgsz)
 						error(Ebadexec);
 					}
 
+					/* this is so ridiculous. We can align the section, but we can't tell
+					 * gnu ld how to set the value of the alignment. What a pile of crap.
+					 * Just ignore it for now. */
 					if(align < minpgsz){
-						print("elf64ldseg: align 0x%x < minpgsz 0x%x\n", align, minpgsz);
-						error(Ebadexec);
+						print("elf64ldseg: WARNING ONLY: align 0x%x < minpgsz 0x%x\n", align, minpgsz);
+						//error(Ebadexec);
 					}
 
 					if(offset & (align-1) != vaddr & (align-1)){

+ 0 - 2
sys/src/9/port/port.json

@@ -40,7 +40,6 @@
 			"../port/devtab.c",
 			"../port/devtrace.c",
 			"../port/devuart.c",
-			"../port/devvcon.c",
 			"../port/devwd.c",
 			"../port/devws.c",
 			"../port/edf.c",
@@ -78,7 +77,6 @@
 			"../port/syszio.c",
 			"../port/taslock.c",
 			"../port/tod.c",
-			"../port/virtio_lib.c",
 			"../port/watermarks.c"
 		]
 	}

+ 1 - 1
sys/src/9/port/portdat.h

@@ -910,7 +910,7 @@ struct Proc
 
 	/* NIX */
 	Mach	*ac;
-	Page	*acpml4;
+	Page	*acPageTableRoot;
 	int	prepagemem;
 	Nixpctl *nixpctl;	/* NIX queue based system calls */
 

+ 2 - 2
sys/src/9/port/proc.c

@@ -228,7 +228,7 @@ sched(void)
 		stackok();
 
 		procsave(up);
-		mmuflushtlb(machp()->MMU.pml4->pa);
+		mmuflushtlb();
 		if(setlabel(&up->sched)){
 			procrestore(up);
 			spllo();
@@ -964,7 +964,7 @@ sleep(Rendez *r, int (*f)(void*), void *arg)
 		machp()->cs++;
 
 		procsave(up);
-		mmuflushtlb(machp()->MMU.pml4->pa);
+		mmuflushtlb();
 		if(setlabel(&up->sched)) {
 			/*
 			 *  here when the process is awakened

+ 6 - 0
sys/src/9/port/syscallfmt.c

@@ -28,6 +28,10 @@ fmtrwdata(Fmt* f, char* a, int n, char* suffix)
 		fmtprint(f, "0x0%s", suffix);
 		return;
 	}
+	if(!okaddr((uintptr_t)a, n, 0)){
+		fmtprint(f, "(BAD %p)%s", a, suffix);
+		return;
+	}
 	a = validaddr(a, n, 0);
 	t = smalloc(n+1);
 	for(i = 0; i < n; i++){
@@ -145,6 +149,8 @@ syscallfmt(uint8_t what, int syscallno, Ar0 *ar0, uint64_t start, uint64_t stop,
 		argv = va_arg(list, char**);
 		evenaddr(PTR2UINT(argv));
 		for(;;){
+			if (! okaddr((uintptr_t)argv, sizeof(char**), 0))
+				break;
 			a = *(char**)validaddr(argv, sizeof(char**), 0);
 			if(a == nil)
 				break;