Browse Source

riscv: get all the libs and cmd to build

We have to stop building snoopy and the aeexec tool by
default for now (you can still build them for amd64 by hand).

But with this change you can build at top level and everything
builds as expected. For instance, building riscv for me is this:

ARCH=riscv CC=~/projects/riscv/riscv-tools/bin/riscv64-unknown-elf-gcc\
	LD=~/projects/riscv/riscv-tools/bin/riscv64-unknown-elf-ld build

and it builds. The kernel no longer links but that's taken care of by sweat equity.

Harvey is once again multi-architecture, at least for libraries and userland.

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

+ 4 - 0
.gitignore

@@ -11,6 +11,10 @@ amd64/9*
 amd64/bin
 amd64/init
 amd64/lib
+riscv/9*
+riscv/bin
+riscv/init
+riscv/lib
 
 acme/bin/amd64
 

+ 1 - 1
build.json

@@ -13,7 +13,7 @@
 			"/sys/src/cmd",
 			"/sys/src/games/games.json",
 			"/acme/build.json",
-			"/sys/src/9/amd64",
+			"/sys/src/9/$ARCH",
 			"/sys/src/regress",
 			"/sys/src/regress/fs"
 		]

+ 0 - 1
sys/src/9/amd64/build.json

@@ -83,7 +83,6 @@
 				]
 			},
 			"Ramfiles": {
-				"aexec": "/$ARCH/bin/acpi/aeexec",
 				"bind": "/$ARCH/bin/bind",
 				"boot": "/sys/src/9/boot/bootcpu.elf.out",
 				"cat": "/$ARCH/bin/cat",

+ 151 - 0
sys/src/9/port/riscvport.json

@@ -0,0 +1,151 @@
+{
+	"port": {
+		"#SourceFiles": [
+			"../port/devcec.c"
+		],
+		"Cflags": [
+			"-fasm"
+		],
+		"Pre": [
+			"mksys -o ../port/error.h '-mode=error.h' $HARVEY/sys/src/sysconf.json"
+		],
+		"#SourceFiles": [
+			"../port/alarm.c",
+			"../port/allocb.c",
+			"../port/cache.c",
+			"../port/chan.c",
+			"../port/cpu_buffer.c",
+			"../port/dev.c",
+			"../port/devcap.c",
+			"../port/devcons.c",
+			"../port/devcoreboot.c",
+			"../port/devdup.c",
+			"../port/devenv.c",
+			"../port/devfdmux.c",
+			"../port/devkprof.c",
+			"../port/devkbin.c",
+			"../port/devmnt.c",
+			"../port/devmntn.c",
+			"../port/devpipe.c",
+			"../port/devproc.c",
+			"../port/devramfs.c",
+			"../port/devregress.c",
+			"../port/devroot.c",
+			"../port/devsd.c",
+			"../port/devsegment.c",
+			"../port/devsrv.c",
+			"../port/devssl.c",
+			"../port/devtls.c",
+			"../port/devtab.c",
+			"../port/devtrace.c",
+			"../port/devuart.c",
+			"../port/devwd.c",
+			"../port/devws.c",
+			"../port/edf.c",
+			"../port/elf64.c",
+			"../port/ethermii.c",
+			"../port/fault.c",
+			"../port/fortuna.c",
+			"../port/getput.c",
+			"../port/hexdump.c",
+			"../port/image.c",
+			"../port/kdebug.c",
+		        "../port/ipchecksum.c",
+			"../port/mul64fract.c",
+			"../port/netif.c",
+			"../port/page.c",
+			"../port/pager.c",
+			"../port/parse.c",
+			"../port/pgrp.c",
+			"../port/portclock.c",
+			"../port/print.c",
+			"../port/proc.c",
+			"../port/ps.c",
+			"../port/qio.c",
+			"../port/qlock.c",
+			"../port/random.c",
+			"../port/rebootcmd.c",
+			"../port/rmap.c",
+			"../port/sdscsi.c",
+			"../port/segment.c",
+			"../port/sysauth.c",
+			"../port/syscallfmt.c",
+			"../port/sysfile.c",
+			"../port/sysproc.c",
+			"../port/sysseg.c",
+			"../port/syszio.c",
+			"../port/taslock.c",
+			"../port/tod.c",
+			"../port/virtio_lib.c",
+			"../port/watermarks.c"
+		],
+		"SourceFiles": [
+			"../port/alarm.c",
+			"../port/allocb.c",
+			"../port/cache.c",
+			"../port/chan.c",
+			"../port/cpu_buffer.c",
+			"../port/dev.c",
+			"../port/devcap.c",
+			"../port/devcons.c",
+			"../port/devcoreboot.c",
+			"../port/devdup.c",
+			"../port/devenv.c",
+			"../port/devfdmux.c",
+			"../port/devkprof.c",
+			"../port/devkbin.c",
+			"../port/devmnt.c",
+			"../port/devmntn.c",
+			"../port/devpipe.c",
+			"../port/devproc.c",
+			"../port/devramfs.c",
+			"../port/devregress.c",
+			"../port/devroot.c",
+			"../port/devsd.c",
+			"../port/devsegment.c",
+			"../port/devsrv.c",
+			"../port/devssl.c",
+			"../port/devtls.c",
+			"../port/devtab.c",
+			"../port/devtrace.c",
+			"../port/devuart.c",
+			"../port/devwd.c",
+			"../port/devws.c",
+			"../port/edf.c",
+			"../port/elf64.c",
+			"../port/ethermii.c",
+			"../port/fault.c",
+			"../port/fortuna.c",
+			"../port/getput.c",
+			"../port/hexdump.c",
+			"../port/image.c",
+			"../port/kdebug.c",
+		        "../port/ipchecksum.c",
+			"../port/mul64fract.c",
+			"../port/netif.c",
+			"../port/page.c",
+			"../port/pager.c",
+			"../port/parse.c",
+			"../port/pgrp.c",
+			"../port/portclock.c",
+			"../port/print.c",
+			"../port/proc.c",
+			"../port/ps.c",
+			"../port/qio.c",
+			"../port/qlock.c",
+			"../port/random.c",
+			"../port/rebootcmd.c",
+			"../port/rmap.c",
+			"../port/sdscsi.c",
+			"../port/segment.c",
+			"../port/sysauth.c",
+			"../port/syscallfmt.c",
+			"../port/sysfile.c",
+			"../port/sysproc.c",
+			"../port/sysseg.c",
+			"../port/taslock.c",
+			"../port/tod.c",
+			"../port/watermarks.c"
+		]
+	}
+}

+ 12 - 0
sys/src/9/riscv/asm.S

@@ -0,0 +1,12 @@
+# startmach starts a function after setting up the mach
+# pointer. The function is in a0, the mach pointer in a1.
+.globl startmach
+startmach: 
+	csrw	sscratch, a1
+	mv	ra,a0
+	ret
+
+.globl machp
+machp:
+	csrr	a0,sscratch
+	ret

+ 3 - 2
sys/src/9/riscv/build.json

@@ -4,9 +4,10 @@
 			"CONF=riscvcpu"
 		],
 		"Include": [
-			"core.json"
+			"core.json",
+			"../port/riscvport.json"
 		],
-		"IncludeSomeday": [
+		"IncludeSomedayWhenRISCVgetsvirtio": [
 			"../ip/ip.json",
 			"../port/port.json"
 		],

+ 2 - 1
sys/src/9/riscv/core.json

@@ -17,7 +17,8 @@
 			"-Wno-unknown-pragmas",
 			"-Werror",
 			"-I", "/sys/src/9/riscv",
-			"-I", "/sys/src/9/port"
+			"-I", "/sys/src/9/port",
+			"-I", "/sys/src/libc/9syscall"
 		],
 	    "Libs": [
 			"/$ARCH/lib/klibc.a"

+ 21 - 3
sys/src/9/riscv/main.c

@@ -16,6 +16,8 @@
 #include "init.h"
 #include "io.h"
 
+extern void (*consuartputs)(char*, int);
+
 void testPrint(uint8_t c);
 
 void msg(char *s)
@@ -29,6 +31,12 @@ void die(char *s)
 	while (1);
 }
 
+static void puts(char * s, int n)
+{
+	while (n--)
+		testPrint(*s++);
+}
+
 static int x = 0x123456;
 
 /* mach struct for hart 0. */
@@ -68,9 +76,19 @@ void bsp(void)
 	active.exiting = 0;
 	active.nbooting = 0;
 
-	msg("call asminit\n");
-	/* TODO: can the asm code be made portable? A lot of it looks like it can. */
-	//asminit();
+	/*
+	 * Need something for initial delays
+	 * until a timebase is worked out.
+	 */
+	mach->cpuhz = 2000000000ll;
+	mach->cpumhz = 2000;
+	sys->cyclefreq = mach->cpuhz;
+
+	// this is in 386, so ... not yet. i8250console("0");
+	// probably pull in the one from coreboot for riscv.
+
+	consuartputs = puts;
+
 	die("Completed hart for bsp OK!\n");
 }
 

+ 27 - 0
sys/src/9/riscv/uart.c

@@ -0,0 +1,27 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2014 Google Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <u.h>
+
+uintptr_t uart_platform_base(int idx)
+{
+	return (uintptr_t) 0x40001000;
+}
+
+void testPrint(uint8_t c)
+{
+	uint8_t *cp = (void *)uart_platform_base(0);
+	*cp = c;
+}

+ 1 - 1
sys/src/cmd/acpica/build.json

@@ -1,6 +1,6 @@
 {
 	"acpica": {
-		"Projects": [
+		"NoProjectsSinceCanNotBuildOnRISCVYet": [
 			"acpiexec/"
 		]
 	}

+ 133 - 0
sys/src/cmd/gdbserver/regsriscv.c

@@ -0,0 +1,133 @@
+/*
+ * Kernel Debug Core
+ *
+ * Maintainer: Jason Wessel <jason.wessel@windriver.com>
+ *
+ * Copyright (C) 2000-2001 VERITAS Software Corporation.
+ * Copyright (C) 2002-2004 Timesys Corporation
+ * Copyright (C) 2003-2004 Amit S. Kale <amitkale@linsyssoft.com>
+ * Copyright (C) 2004 Pavel Machek <pavel@ucw.cz>
+ * Copyright (C) 2004-2006 Tom Rini <trini@kernel.crashing.org>
+ * Copyright (C) 2004-2006 LinSysSoft Technologies Pvt. Ltd.
+ * Copyright (C) 2005-2009 Wind River Systems, Inc.
+ * Copyright (C) 2007 MontaVista Software, Inc.
+ * Copyright (C) 2008 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
+ *
+ * Contributors at various stages not listed above:
+ *  Jason Wessel ( jason.wessel@windriver.com )
+ *  George Anzinger <george@mvista.com>
+ *  Anurekh Saxena (anurekh.saxena@timesys.com)
+ *  Lake Stevens Instrument Division (Glenn Engel)
+ *  Jim Kingdon, Cygnus Support.
+ *
+ * Original KGDB stub: David Grothe <dave@gcom.com>,
+ * Tigran Aivazian <tigran@sco.com>
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ */
+
+#include <u.h>
+#include <libc.h>
+#include <ureg.h>
+#include <ctype.h>
+
+#include "debug_core.h"
+#include "gdb.h"
+
+/* all because gdb has stupid register layouts. Too bad. */
+
+static char *
+gdb_hex_reg_helper(uintptr_t *gdb_regs, int regnum, char *out)
+{
+	int offset = 0;
+
+	if (regnum <= GDB_PC)
+		return mem2hex((void *)&gdb_regs[offset], out, sizeof(uintptr_t));
+	if (regnum == GDB_PS)
+		return mem2hex((void *)&gdb_regs[offset], out, sizeof(uint32_t));
+	memset(out, 0, sizeof(uint32_t));
+	return nil;
+}
+
+/* Handle the 'p' individual regster get */
+void
+gdb_cmd_reg_get(struct state *ks)
+{
+	unsigned long regnum;
+	char *ptr = (char *)&remcom_in_buffer[1];
+
+	hex2long(&ptr, &regnum);
+	syslog(0, "gdbserver", "Get reg %p: ", regnum);
+	if (regnum >= DBG_MAX_REG_NUM) {
+		syslog(0, "gdbserver", "fails\n");
+		error_packet(remcom_out_buffer, Einval);
+		return;
+	}
+	syslog(0, "gdbserver", "returns :%s:\n", ptr);
+	gdb_hex_reg_helper(ks->gdbregs, regnum, (char *)ptr);
+}
+
+/* Handle the 'P' individual regster set */
+void
+gdb_cmd_reg_set(struct state *ks)
+{
+	fprint(2, "%s: NOET YET\n", __func__);
+#if 0 // not yet.
+	unsigned long regnum;
+	char *ptr = &remcom_in_buffer[1];
+	int i = 0;
+
+	hex2long(&ptr, &regnum);
+	if (*ptr++ != '=' ||
+		!dbg_get_reg(regnum, gdb_regs, ks->linux_regs)) {
+		error_packet(remcom_out_buffer, -EINVAL);
+		return;
+	}
+	memset(gdb_regs, 0, sizeof(gdb_regs));
+	while (i < sizeof(gdb_regs) * 2)
+		if (hex_to_bin(ptr[i]) >= 0)
+			i++;
+		else
+			break;
+	i = i / 2;
+	hex2mem(ptr, (char *)gdb_regs, i);
+	dbg_set_reg(regnum, gdb_regs, ks->linux_regs);
+#endif
+	strcpy((char *)remcom_out_buffer, "OK");
+}
+
+void arch_set_pc(uintptr_t *regs, unsigned long pc)
+{
+	// not yet.
+}
+
+char *
+gpr(struct state *ks, int pid)
+{
+	if (ks->gdbregs == nil)
+		ks->gdbregs = malloc(NUMREGBYTES);
+
+	if (pid <= 0) {
+		syslog(0, "gdbserver", "%s: FUCK. pid <= 0", __func__);
+		pid = 1;
+	}
+	char *cp = ks->gdbregs;
+	char *regname = smprint("/proc/%d/gdbregs", pid);
+	int fd = open(regname, 0);
+	if (fd < 0) {
+		syslog(0, "gdbserver", "open(%s, 0): %r\n", regname);
+		return errstring(Enoent);
+	}
+
+	if (pread(fd, cp, NUMREGBYTES, 0) < NUMREGBYTES){
+		close(fd);
+		return errstring(Eio);
+	}
+	close(fd);
+
+	return nil;
+
+}
+

+ 16 - 0
sys/src/cmd/gdbserver/riscv.S

@@ -0,0 +1,16 @@
+
+/*
+ * This file is part of the UCB release of Plan 9. It is subject to the license
+ * terms in the LICENSE file found in the top-level directory of this
+ * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
+ * part of the UCB release of Plan 9, including this file, may be copied,
+ * modified, propagated, or distributed except according to the terms contained
+ * in the LICENSE file.
+ */
+
+.text
+.global breakpoint
+breakpoint:
+	.long 0xdeadbeef
+.global ebreakpoint
+ebreakpoint:

+ 4 - 2
sys/src/cmd/ip/ip.json

@@ -4,14 +4,16 @@
 			"/sys/src/cmd/cmd.json"
 		],
 		"Install": "/$ARCH/bin/ip",
+		"NoProjects": [
+			"snoopy/build.json"
+		],
 		"Projects": [
 			"ftpd.json",
 			"dhcpd/dhcpd.json",
 			"dhcpd/dhcpleases.json",
 			"ftpfs/ftpfs.json",
 			"httpd/httpd.json",
-			"ipconfig/ipconfig.json",
-			"snoopy/build.json"
+			"ipconfig/ipconfig.json"
 		],
 		"SourceFilesCmd": [
 			"ping.c",

+ 0 - 1
sys/src/libacpi/acfileio.c

@@ -118,7 +118,6 @@
 #include "acapps.h"
 #include "actables.h"
 #include "acutils.h"
-#include <errno.h>
 
 #define _COMPONENT          ACPI_UTILITIES
         ACPI_MODULE_NAME    ("acfileio")

+ 1 - 0
sys/src/libacpi/acpica/acpiflags.json

@@ -19,6 +19,7 @@
 			"-Wno-unused-variable",
 			"-Wall", 
 			"-nostdlib",
+			"-nostdinc",
 		        "-fno-builtin",
 			"-include", "u.h",
 			"-include", "libc.h",

+ 0 - 1
sys/src/libacpi/olsneracpi.c

@@ -24,7 +24,6 @@ THE SOFTWARE.
 #include "acapps.h"
 #include "actables.h"
 #include "acutils.h"
-#include <errno.h>
 #define DBGFLG 0
 #define _COMPONENT          ACPI_UTILITIES
 ACPI_MODULE_NAME    ("harvey")

+ 2 - 2
sys/src/libmach/6.c

@@ -10,10 +10,10 @@
 /*
  * amd64 definition
  */
-#include <u.h>
+#include <amd64/include/u.h>
 #include <libc.h>
 #include <bio.h>
-#include <ureg.h>
+#include <amd64/include/ureg.h>
 #include <mach.h>
 
 #define	REGOFF(x)	offsetof(struct Ureg, x)