-
-
Save okuoku/23c2fbd2400d21949fbb5e80c686149d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Starting... | |
BIOS len = 53730 | |
Kernel len = 8549052 | |
Configure... | |
Run... | |
Leave... | |
[ 0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80400000 | |
[ 0.000000] Linux version 5.4.61 (oku@ubuntults) (gcc version 9.3.0 (Buildroot 2020.08-269-g4823661825-dirty)) #1 SMP Sun Sep 6 21:26:45 JST 2020 | |
[ 0.000000] initrd not found or empty - disabling initrd | |
[ 0.000000] Zone ranges: | |
[ 0.000000] Normal [mem 0x0000000080400000-0x000000008fffffff] | |
[ 0.000000] Movable zone start for each node | |
[ 0.000000] Early memory node ranges | |
[ 0.000000] node 0: [mem 0x0000000080400000-0x000000008fffffff] | |
[ 0.000000] Initmem setup node 0 [mem 0x0000000080400000-0x000000008fffffff] | |
[ 0.000000] elf_hwcap is 0x112d | |
[ 0.000000] percpu: Embedded 13 pages/cpu s21452 r8192 d23604 u53248 | |
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 63882 | |
[ 0.000000] Kernel command line: console=hvc0 root=/dev/root ro | |
[ 0.000000] Dentry cache hash table entries: 32768 (order: 5, 131072 bytes, linear) | |
[ 0.000000] Inode-cache hash table entries: 16384 (order: 4, 65536 bytes, linear) | |
[ 0.000000] Sorting __ex_table... | |
[ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off | |
[ 0.000000] Memory: 246920K/258048K available (5942K kernel code, 264K rwdata, 1689K rodata, 192K init, 249K bss, 11128K reserved, 0K cma-reserved) | |
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1 | |
[ 0.000000] rcu: Hierarchical RCU implementation. | |
[ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1. | |
[ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies. | |
[ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1 | |
[ 0.000000] NR_IRQS: 0, nr_irqs: 0, preallocated irqs: 0 | |
[ 0.000000] plic: mapped 31 interrupts with 1 handlers for 2 contexts. | |
[ 0.000000] riscv_timer_init_dt: Registering clocksource cpuid [0] hartid [0] | |
[ 0.000000] clocksource: riscv_clocksource: mask: 0xffffffffffffffff max_cycles: 0x24e6a1710, max_idle_ns: 440795202120 ns | |
[ 0.000023] sched_clock: 64 bits at 10MHz, resolution 100ns, wraps every 4398046511100ns | |
[ 0.000376] Console: colour dummy device 80x25 | |
[ 0.003184] printk: console [hvc0] enabled | |
[ 0.003300] Calibrating delay loop (skipped), value calculated using timer frequency.. 20.00 BogoMIPS (lpj=40000) | |
[ 0.003483] pid_max: default: 32768 minimum: 301 | |
[ 0.003937] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear) | |
[ 0.004080] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear) | |
[ 0.007696] rcu: Hierarchical SRCU implementation. | |
[ 0.008417] smp: Bringing up secondary CPUs ... | |
[ 0.008507] smp: Brought up 1 node, 1 CPU | |
[ 0.009183] devtmpfs: initialized | |
[ 0.011049] random: get_random_u32 called from bucket_table_alloc.isra.0+0x4c/0x14c with crng_init=0 | |
[ 0.011840] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns | |
[ 0.012142] futex hash table entries: 256 (order: 2, 16384 bytes, linear) | |
[ 0.012905] NET: Registered protocol family 16 | |
[ 0.051170] vgaarb: loaded | |
[ 0.052100] SCSI subsystem initialized | |
[ 0.053041] usbcore: registered new interface driver usbfs | |
[ 0.053266] usbcore: registered new interface driver hub | |
[ 0.053461] usbcore: registered new device driver usb | |
[ 0.055764] clocksource: Switched to clocksource riscv_clocksource | |
[ 0.072871] NET: Registered protocol family 2 | |
[ 0.074664] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 6144 bytes, linear) | |
[ 0.074869] TCP established hash table entries: 2048 (order: 1, 8192 bytes, linear) | |
[ 0.075128] TCP bind hash table entries: 2048 (order: 2, 16384 bytes, linear) | |
[ 0.075394] TCP: Hash tables configured (established 2048 bind 2048) | |
[ 0.075643] UDP hash table entries: 256 (order: 1, 8192 bytes, linear) | |
[ 0.075814] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes, linear) | |
[ 0.076241] NET: Registered protocol family 1 | |
[ 0.077334] RPC: Registered named UNIX socket transport module. | |
[ 0.077438] RPC: Registered udp transport module. | |
[ 0.077525] RPC: Registered tcp transport module. | |
[ 0.077614] RPC: Registered tcp NFSv4.1 backchannel transport module. | |
[ 0.077728] PCI: CLS 0 bytes, default 64 | |
[ 0.079453] workingset: timestamp_bits=30 max_order=16 bucket_order=0 | |
[ 0.107776] NFS: Registering the id_resolver key type | |
[ 0.107892] Key type id_resolver registered | |
[ 0.107972] Key type id_legacy registered | |
[ 0.108071] nfs4filelayout_init: NFSv4 File Layout Driver Registering... | |
[ 0.108479] 9p: Installing v9fs 9p2000 file system support | |
[ 0.109473] NET: Registered protocol family 38 | |
[ 0.109620] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 253) | |
[ 0.109744] io scheduler mq-deadline registered | |
[ 0.109829] io scheduler kyber registered | |
[ 0.211750] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled | |
[ 0.214973] [drm] radeon kernel modesetting enabled. | |
[ 0.228233] loop: module loaded | |
[ 0.229404] libphy: Fixed MDIO Bus: probed | |
[ 0.231130] e1000e: Intel(R) PRO/1000 Network Driver - 3.2.6-k | |
[ 0.231232] e1000e: Copyright(c) 1999 - 2015 Intel Corporation. | |
[ 0.231576] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver | |
[ 0.231688] ehci-pci: EHCI PCI platform driver | |
[ 0.231874] ehci-platform: EHCI generic platform driver | |
[ 0.232073] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver | |
[ 0.232180] ohci-pci: OHCI PCI platform driver | |
[ 0.232356] ohci-platform: OHCI generic platform driver | |
[ 0.233183] usbcore: registered new interface driver uas | |
[ 0.233410] usbcore: registered new interface driver usb-storage | |
[ 0.233831] mousedev: PS/2 mouse device common for all mice | |
[ 0.234573] usbcore: registered new interface driver usbhid | |
[ 0.234669] usbhid: USB HID core driver | |
[ 0.237389] NET: Registered protocol family 10 | |
[ 0.239112] Segment Routing with IPv6 | |
[ 0.239384] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver | |
[ 0.241102] NET: Registered protocol family 17 | |
[ 0.241780] 9pnet: Installing 9P2000 support | |
[ 0.241966] Key type dns_resolver registered | |
[ 0.244013] VFS: Cannot open root device "root" or unknown-block(0,0): error -6 | |
[ 0.244135] Please append a correct "root=" boot option; here are the available partitions: | |
[ 0.244286] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) | |
[ 0.244434] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.4.61 #1 | |
[ 0.244534] Call Trace: | |
[ 0.244608] [<c00324be>] walk_stackframe+0x0/0xa6 | |
[ 0.244713] [<c0032620>] show_stack+0x28/0x32 | |
[ 0.244811] [<c05e4372>] dump_stack+0x6a/0x86 | |
[ 0.244906] [<c00370f8>] panic+0xdc/0x23e | |
[ 0.244998] [<c0000efc>] mount_block_root+0x17e/0x210 | |
[ 0.245103] [<c000107a>] mount_root+0xec/0x102 | |
[ 0.245201] [<c0001196>] prepare_namespace+0x106/0x14e | |
[ 0.245308] [<c0000ba0>] kernel_init_freeable+0x18a/0x1a6 | |
[ 0.245417] [<c05f8924>] kernel_init+0x12/0xf0 | |
[ 0.245517] [<c00313f8>] ret_from_exception+0x0/0xc | |
[ 0.245622] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) ]--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Makefile.in b/Makefile.in | |
index aeabdc2..f6b8c2f 100644 | |
--- a/Makefile.in | |
+++ b/Makefile.in | |
@@ -61,7 +61,7 @@ else | |
march := -march=@WITH_ARCH@ | |
endif | |
is_32bit := $(findstring 32,$(march)) | |
-mabi := -mabi=$(if $(is_32bit),ilp32,lp64) | |
+mabi := -mabi=$(if $(is_32bit),ilp32d,lp64d) | |
# Installation directories | |
diff --git a/bbl/bbl.lds b/bbl/bbl.lds | |
index 26f5816..615c3dc 100644 | |
--- a/bbl/bbl.lds | |
+++ b/bbl/bbl.lds | |
@@ -43,15 +43,10 @@ SECTIONS | |
_etext = .; | |
/*--------------------------------------------------------------------*/ | |
- /* HTIF, isolated onto separate page */ | |
+ /* HTIF I/Os */ | |
/*--------------------------------------------------------------------*/ | |
- . = ALIGN(0x1000); | |
- .htif : | |
- { | |
- PROVIDE( __htif_base = .); | |
- *(.htif) | |
- } | |
- . = ALIGN(0x1000); | |
+ tohost = 0x40008000; | |
+ fromhost = 0x40008008; | |
/*--------------------------------------------------------------------*/ | |
/* Initialized data segment */ | |
diff --git a/machine/fdt.c b/machine/fdt.c | |
index e8a504f..260fae8 100644 | |
--- a/machine/fdt.c | |
+++ b/machine/fdt.c | |
@@ -646,8 +646,12 @@ static bool hart_filter_mask(const struct hart_filter *filter) | |
{ | |
if (filter->mmu_type == NULL) return true; | |
if (strcmp(filter->status, "okay")) return true; | |
+#if __riscv_xlen == 32 | |
+ if (!strcmp(filter->mmu_type, "riscv,sv32")) return false; | |
+#else | |
if (!strcmp(filter->mmu_type, "riscv,sv39")) return false; | |
if (!strcmp(filter->mmu_type, "riscv,sv48")) return false; | |
+#endif | |
printm("hart_filter_mask saw unknown hart type: status=\"%s\", mmu_type=\"%s\"\n", | |
filter->status, filter->mmu_type); | |
return true; | |
diff --git a/machine/htif.c b/machine/htif.c | |
index aae8c56..360cbb4 100644 | |
--- a/machine/htif.c | |
+++ b/machine/htif.c | |
@@ -7,19 +7,12 @@ | |
#include "syscall.h" | |
#include <string.h> | |
-extern uint64_t __htif_base; | |
-volatile uint64_t tohost __attribute__((section(".htif"))); | |
-volatile uint64_t fromhost __attribute__((section(".htif"))); | |
+volatile extern uint64_t tohost; | |
+volatile extern uint64_t fromhost; | |
volatile int htif_console_buf; | |
static spinlock_t htif_lock = SPINLOCK_INIT; | |
uintptr_t htif; | |
-#define TOHOST(base_int) (uint64_t *)(base_int + TOHOST_OFFSET) | |
-#define FROMHOST(base_int) (uint64_t *)(base_int + FROMHOST_OFFSET) | |
- | |
-#define TOHOST_OFFSET ((uintptr_t)tohost - (uintptr_t)__htif_base) | |
-#define FROMHOST_OFFSET ((uintptr_t)fromhost - (uintptr_t)__htif_base) | |
- | |
static void __check_fromhost() | |
{ | |
uint64_t fh = fromhost; | |
@@ -91,7 +84,7 @@ void htif_syscall(uintptr_t arg) | |
void htif_console_putchar(uint8_t ch) | |
{ | |
-#if __riscv_xlen == 32 | |
+#if __riscv_xlen == 32 && 0 | |
// HTIF devices are not supported on RV32, so proxy a write system call | |
volatile uint64_t magic_mem[8]; | |
magic_mem[0] = SYS_write; | |
diff --git a/machine/htif.h b/machine/htif.h | |
index a4e5e8e..e06440a 100644 | |
--- a/machine/htif.h | |
+++ b/machine/htif.h | |
@@ -5,14 +5,9 @@ | |
#include <stdint.h> | |
-#if __riscv_xlen == 64 | |
# define TOHOST_CMD(dev, cmd, payload) \ | |
(((uint64_t)(dev) << 56) | ((uint64_t)(cmd) << 48) | (uint64_t)(payload)) | |
-#else | |
-# define TOHOST_CMD(dev, cmd, payload) ({ \ | |
- if ((dev) || (cmd)) __builtin_trap(); \ | |
- (payload); }) | |
-#endif | |
+ | |
#define FROMHOST_DEV(fromhost_value) ((uint64_t)(fromhost_value) >> 56) | |
#define FROMHOST_CMD(fromhost_value) ((uint64_t)(fromhost_value) << 8 >> 56) | |
#define FROMHOST_DATA(fromhost_value) ((uint64_t)(fromhost_value) << 16 >> 16) | |
diff --git a/machine/mentry.S b/machine/mentry.S | |
index 99e1b72..1aae2c1 100644 | |
--- a/machine/mentry.S | |
+++ b/machine/mentry.S | |
@@ -220,6 +220,46 @@ __trap_from_machine_mode: | |
jal trap_from_machine_mode | |
j restore_regs | |
+#define HTIF_TOHOST 0x40008000 | |
+ | |
+putstring: | |
+ li a2, HTIF_TOHOST | |
+ li a3, (1 << 24) | (1 << 16) | |
+1: | |
+ lbu a1, (a0) | |
+ beqz a1, 2f | |
+/* Note: we use 32 bit accesses to work in all base isa modes */ | |
+ sw a1, 0(a2) | |
+ sw a3, 4(a2) | |
+/* wait until the char is handled */ | |
+3: | |
+ lw a1, 0(a2) | |
+ lw a4, 4(a2) | |
+ or a1, a1, a4 | |
+ bnez a1, 3b | |
+ addi a0, a0, 1 | |
+ j 1b | |
+2: | |
+ ret | |
+fatal_error: | |
+ jal putstring | |
+ # exit the emulator if possible | |
+ li a2, HTIF_TOHOST | |
+ li a1, 1 | |
+ sw a1, 0(a2) | |
+ sw zero, 4(a2) | |
+1: | |
+ wfi | |
+ j 1b | |
+ | |
+rv32_expected_str: | |
+ .asciz "Must run this program on a 32 bit RISCV CPU - aborting\n" | |
+rv64_expected_str: | |
+ .asciz "Must run this program on a 64 bit RISCV CPU - aborting\n" | |
+rv128_detected_str: | |
+ .asciz "128 bit RISCV CPU detected: setting XLEN to 64 bits\n" | |
+ .align 4 | |
+ | |
do_reset: | |
li x1, 0 | |
li x2, 0 | |
@@ -255,6 +295,41 @@ do_reset: | |
li x31, 0 | |
csrw mscratch, x0 | |
+ # check MXL value and abort if it is not what we expect | |
+ mv s0, a0 | |
+ mv s1, a1 | |
+ csrr a0, misa | |
+ bgez a0, misa_rv32 | |
+#if __riscv_xlen == 32 | |
+ la a0, rv32_expected_str | |
+ j fatal_error | |
+#else | |
+ slli a0, a0, 1 | |
+ bgez a0, misa_ok | |
+ # we are on a 128 bit CPU: we force MXL to 64 bit as a test | |
+ la a0, rv128_detected_str | |
+ jal putstring | |
+ li a0, 1 | |
+ li a1, 126 | |
+ # cannot use slli because no 128 bit support in gas | |
+ sll a0, a0, a1 | |
+ csrc misa, a0 | |
+ # also set MSTATUS.SXL and MSTATUS.UXL to 64 bits | |
+ li a0, (3 << 32) | (3 << 34) | |
+ csrs mstatus, a0 | |
+ li a0, (1 << 32) | (1 << 34) | |
+ csrc mstatus, a0 | |
+ j misa_ok | |
+#endif | |
+misa_rv32: | |
+#if __riscv_xlen == 64 | |
+ la a0, rv64_expected_str | |
+ j fatal_error | |
+#endif | |
+misa_ok: | |
+ mv a0, s0 | |
+ mv a1, s1 | |
+ | |
# write mtvec and make sure it sticks | |
la t0, trap_vector | |
csrw mtvec, t0 | |
diff --git a/machine/minit.c b/machine/minit.c | |
index 953e1ba..fb6efbe 100644 | |
--- a/machine/minit.c | |
+++ b/machine/minit.c | |
@@ -156,7 +156,7 @@ void init_first_hart(uintptr_t hartid, uintptr_t dtb) | |
query_uart(dtb); | |
query_uart16550(dtb); | |
query_htif(dtb); | |
- printm("bbl loader\r\n"); | |
+ // printm("bbl loader\r\n"); | |
hart_init(); | |
hls_init(0); // this might get called again from parse_config_string | |
diff --git a/machine/mtrap.c b/machine/mtrap.c | |
index e48d3d5..fd78793 100644 | |
--- a/machine/mtrap.c | |
+++ b/machine/mtrap.c | |
@@ -35,8 +35,13 @@ static uintptr_t mcall_console_putchar(uint8_t ch) | |
void putstring(const char* s) | |
{ | |
- while (*s) | |
- mcall_console_putchar(*s++); | |
+ int c; | |
+ while (*s) { | |
+ c = *s++; | |
+ if (c == '\n') | |
+ mcall_console_putchar('\r'); | |
+ mcall_console_putchar(c); | |
+ } | |
} | |
void vprintm(const char* s, va_list vl) | |
diff --git a/pk/pk.lds b/pk/pk.lds | |
index 52a7239..8fb2e68 100644 | |
--- a/pk/pk.lds | |
+++ b/pk/pk.lds | |
@@ -43,15 +43,10 @@ SECTIONS | |
_etext = .; | |
/*--------------------------------------------------------------------*/ | |
- /* HTIF, isolated onto separate page */ | |
+ /* HTIF I/Os */ | |
/*--------------------------------------------------------------------*/ | |
- . = ALIGN(0x1000); | |
- .htif : | |
- { | |
- PROVIDE( __htif_base = . ); | |
- *(.htif) | |
- } | |
- . = ALIGN(0x1000); | |
+ tohost = 0x40008000; | |
+ fromhost = 0x40008008; | |
/*--------------------------------------------------------------------*/ | |
/* Initialized data segment */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment