Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
f80b7fe
Print to UART OK yay!
lupyuen Jun 29, 2023
5de250a
Print to UART OK yay!
lupyuen Jun 29, 2023
b873dc0
Adding Linux Header
lupyuen Jun 29, 2023
7ff868f
Adding Linux Header
lupyuen Jun 29, 2023
94348e7
Adding Linux Header
lupyuen Jun 29, 2023
0c59496
Adding Linux Header
lupyuen Jun 29, 2023
a0787e7
Adding Linux Header
lupyuen Jun 30, 2023
b4744c9
Added Linux Header
lupyuen Jun 30, 2023
b75df20
Start at 0x44000000
lupyuen Jun 30, 2023
9e92bbc
Moved Start Address to 0x40200000. NuttX boots with `123` yay!
lupyuen Jul 1, 2023
5c59366
Moved Start Address to 0x40200000. NuttX boots with `123` yay!
lupyuen Jul 1, 2023
ed09c34
Sync MZ with Linux
lupyuen Jul 1, 2023
ecee2d9
Change Machine Registers to Supervisor Registers
lupyuen Jul 4, 2023
06f8bc9
Fix Hart ID
lupyuen Jul 4, 2023
43de842
Clean up
lupyuen Jul 4, 2023
55967a3
Add log
lupyuen Jul 4, 2023
8fdd020
Hangs at qemu_rv_start
lupyuen Jul 4, 2023
e99a241
Hangs at qemu_rv_start
lupyuen Jul 4, 2023
dc59c26
Hangs at qemu_rv_start
lupyuen Jul 4, 2023
005f0ea
Revert to earlier `sed`
lupyuen Jul 4, 2023
2b8ef3d
Hang in up_putc
lupyuen Jul 4, 2023
093a531
Hang in riscv_earlyserialinit
lupyuen Jul 4, 2023
ef9618a
Hang in nx_start
lupyuen Jul 4, 2023
b82ffaf
Hangs in enter_critical_section
lupyuen Jul 4, 2023
e057296
Hangs in enter_critical_section
lupyuen Jul 4, 2023
541b22d
Hangs in THRE
lupyuen Jul 4, 2023
13e6af4
Change RAM Address
lupyuen Jul 4, 2023
4dcd007
Enable Critical Section with rv-virt:knsh64. Garbled output
lupyuen Jul 4, 2023
4f5d964
Skip init m-mode. Hang in riscv_earlyserialinit
lupyuen Jul 4, 2023
6285e1c
Disable riscv_earlyserialinit. Critical section OK with rv-virt:knsh64
lupyuen Jul 4, 2023
62764c1
Fix knsh64 PBASE and VBASE
lupyuen Jul 5, 2023
751f24d
Don't load the Interrupt Vector Table, use OpenSBI for crash logging
lupyuen Jul 5, 2023
87b91e6
u16550_setup OK
lupyuen Jul 5, 2023
a34d036
Disable riscv_earlyserialinit
lupyuen Jul 5, 2023
5f5df15
Use NuttX trap vector. Something garbled is printed
lupyuen Jul 13, 2023
04e3bfb
Comment out UART Setup. 123067DFAGHBCIcl
lupyuen Jul 13, 2023
4fd337e
Restore riscv_earlyserialinit. 123067DFAGaclbH
lupyuen Jul 13, 2023
a678f68
Restore UART wait. 123067DF
lupyuen Jul 13, 2023
236a2b0
Check UART Base. 123067DF
lupyuen Jul 13, 2023
5e3b755
Clear BSS. 123067DF
lupyuen Jul 13, 2023
71ce60f
Fixing u16550_putc. 123067DFm
lupyuen Jul 14, 2023
6cd805f
Fixing u16550_putc. 123067DFmoooooooo
lupyuen Jul 14, 2023
55bfcde
Debug UART Addr. 123067DFm155Eoo
lupyuen Jul 14, 2023
606d7a7
CONFIG_16550_REGINCR=4 yay! 123067DFm45DTpAqGaclbHm45DTpBqm45DTpCqI
lupyuen Jul 14, 2023
ef83404
CONFIG_16550_REGINCR=4 yay! 123067DFm45DTpAqGaclbHm45DTpBqm45DTpCqI
lupyuen Jul 14, 2023
12eb3d8
Clean up. 123067DFAGaclbHBCI
lupyuen Jul 14, 2023
3551b48
Use OpenSBI for crash logging. 123067DFAGaclbHBCI
lupyuen Jul 14, 2023
7cf7097
Enable Scheduler Debug. nx_start_application: Starting init task: /sy…
lupyuen Jul 15, 2023
2891894
Switch to NuttX Trap Vector. nx_start_application: Starting init task…
lupyuen Jul 15, 2023
cad0e95
exec_spawn never returns
lupyuen Jul 15, 2023
dbe1048
exec_spawn never returns
lupyuen Jul 15, 2023
2f52bba
Enable Binary Loader Logging. elf_init: filename: /system/bin/init lo…
lupyuen Jul 15, 2023
b79c90e
Restore UART
lupyuen Jul 15, 2023
854045e
Restore UART. Tested OK
lupyuen Jul 15, 2023
2261b80
Restore qemu_rv_start. elf_init: filename: /system/bin/init loadinfo:…
lupyuen Jul 15, 2023
dd721d0
Restore qemu_rv_start. up_dump_register: EPC: 0000000040200434
lupyuen Jul 15, 2023
6ed2880
Debug host_call. host_call: host_call: nbr=0x1, parm=0x40406778, size=24
lupyuen Jul 15, 2023
c994f46
Disable Semihosting
lupyuen Jul 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions arch/risc-v/src/common/riscv_hostfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <string.h>
#include <syscall.h>
#include <unistd.h>
#include <debug.h>////
#include <assert.h>////

/****************************************************************************
* Pre-processor Definitions
Expand All @@ -52,6 +54,9 @@

static long host_call(unsigned int nbr, void *parm, size_t size)
{
_info("nbr=0x%x, parm=%p, size=%ld\n", nbr, parm, size);////
DEBUGPANIC();//// Semihosting not supported

#ifdef CONFIG_RISCV_SEMIHOSTING_HOSTFS_CACHE_COHERENCE
up_clean_dcache(parm, parm + size);
#endif
Expand Down
86 changes: 82 additions & 4 deletions arch/risc-v/src/qemu-rv/qemu_rv_head.S
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,78 @@
.global __start

__start:
/* Begin Test */

/* DO NOT MODIFY. Image Header expected by Linux bootloaders.
*
* This `li` instruction has no meaningful effect except that
* its opcode forms the magic "MZ" signature of a PE/COFF file
* that is required for UEFI applications.
*
* Some bootloaders check the magic "MZ" to see if the image is a valid
* Linux image. But modifying the bootLoader is unnecessary unless we
* need to do a customized secure boot. So we just put "MZ" in the
* header to make the bootloader happy.
*/

c.li s4, -13 /* Magic Signature "MZ" (2 bytes) */
j real_start /* Jump to Kernel Start (2 bytes) */
.long 0 /* Executable Code padded to 8 bytes */
.quad 0x200000 /* Image load offset from start of RAM */
/* TODO: _e_initstack - __start */
.quad 171644 /* Effective size of kernel image, little-endian */
.quad 0x0 /* Kernel flags, little-endian */
.long 0x2 /* Version of this header */
.long 0 /* Reserved */
.quad 0 /* Reserved */
.ascii "RISCV\x00\x00\x00" /* Magic number, "RISCV" (8 bytes) */
.ascii "RSC\x05" /* Magic number 2, "RSC\x05" (4 bytes) */
.long 0 /* Reserved for PE COFF offset */

real_start:

/* Load UART Base Address to Register t0 */
li t0, 0x10000000

/* Load `1` to Register t1 */
li t1, 0x31
/* Store byte from Register t1 to UART Base Address, Offset 0 */
sb t1, 0(t0)

/* Load `2` to Register t1 */
li t1, 0x32
/* Store byte from Register t1 to UART Base Address, Offset 0 */
sb t1, 0(t0)

/* Load `3` to Register t1 */
li t1, 0x33
/* Store byte from Register t1 to UART Base Address, Offset 0 */
sb t1, 0(t0)

/* End Test */

/* Load mhartid (cpuid) */
/* Previously: csrr a0, mhartid */

/* We assume that OpenSBI has passed Hart ID (value 1) in Register a0. */
/* But NuttX expects Hart ID to start at 0, so we subtract 1. */
addi a0, a0, -1

csrr a0, mhartid
/* Print the Hart ID */
addi t1, a0, 0x30
/* Store byte from Register t1 to UART Base Address, Offset 0 */
sb t1, 0(t0)

/* Set stack pointer to the idle thread stack */

bnez a0, 1f
la sp, QEMU_RV_IDLESTACK_TOP
j 2f
1:
/* Print `4` */
li t0, 0x10000000
li t1, 0x34
sb t1, 0(t0)

/* Load the number of CPUs that the kernel supports */

Expand All @@ -63,10 +124,16 @@ __start:
/* If a0 (mhartid) >= t1 (the number of CPUs), stop here */

blt a0, t1, 3f
csrw mie, zero
csrw sie, zero
/* Previously: csrw mie, zero */
wfi

3:
/* Print `5` */
li t0, 0x10000000
li t1, 0x35
sb t1, 0(t0)

/* To get g_cpu_basestack[mhartid], must get g_cpu_basestack first */

la t0, g_cpu_basestack
Expand Down Expand Up @@ -95,13 +162,24 @@ __start:
add sp, sp, t0

2:
/* Print `6` */
li t0, 0x10000000
li t1, 0x36
sb t1, 0(t0)

/* Disable all interrupts (i.e. timer, external) in mie */

csrw mie, zero
csrw sie, zero
/* Previously: csrw mie, zero */

la t0, __trap_vec
csrw mtvec, t0
csrw stvec, t0
/* Previously: csrw mtvec, t0 */

/* Print `7` */
li t0, 0x10000000
li t1, 0x37
sb t1, 0(t0)

/* Jump to qemu_rv_start */

Expand Down
44 changes: 29 additions & 15 deletions arch/risc-v/src/qemu-rv/qemu_rv_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void qemu_rv_start(int mhartid)
{
/* Configure FPU */

*(volatile uint8_t *)0x10000000 = 'D';////
riscv_fpuconfig();

if (mhartid > 0)
Expand All @@ -112,15 +113,19 @@ void qemu_rv_start(int mhartid)
}

#ifndef CONFIG_BUILD_KERNEL
*(volatile uint8_t *)0x10000000 = 'E';////
qemu_rv_clear_bss();
#endif

*(volatile uint8_t *)0x10000000 = 'F';////
showprogress('A');

#ifdef USE_EARLYSERIALINIT
*(volatile uint8_t *)0x10000000 = 'G';////
riscv_earlyserialinit();
#endif

*(volatile uint8_t *)0x10000000 = 'H';////
showprogress('B');

/* Do board initialization */
Expand All @@ -135,14 +140,17 @@ void qemu_rv_start(int mhartid)

/* Call nx_start() */

*(volatile uint8_t *)0x10000000 = 'I';////
nx_start();

cpux:

#ifdef CONFIG_SMP
*(volatile uint8_t *)0x10000000 = 'J';////
riscv_cpu_boot(mhartid);
#endif

*(volatile uint8_t *)0x10000000 = 'K';////
while (true)
{
asm("WFI");
Expand All @@ -157,6 +165,8 @@ void qemu_rv_start(int mhartid)

void qemu_rv_start(int mhartid)
{
DEBUGASSERT(mhartid == 0); ////

/* NOTE: still in M-mode */

if (0 == mhartid)
Expand All @@ -171,51 +181,55 @@ void qemu_rv_start(int mhartid)
/* Disable MMU and enable PMP */

WRITE_CSR(satp, 0x0);
WRITE_CSR(pmpaddr0, 0x3fffffffffffffull);
WRITE_CSR(pmpcfg0, 0xf);
////WRITE_CSR(pmpaddr0, 0x3fffffffffffffull);
////WRITE_CSR(pmpcfg0, 0xf);

/* Set exception and interrupt delegation for S-mode */

WRITE_CSR(medeleg, 0xffff);
WRITE_CSR(mideleg, 0xffff);
////WRITE_CSR(medeleg, 0xffff);
////WRITE_CSR(mideleg, 0xffff);

/* Allow to write satp from S-mode */

CLEAR_CSR(mstatus, MSTATUS_TVM);
////CLEAR_CSR(mstatus, MSTATUS_TVM);

/* Set mstatus to S-mode and enable SUM */

CLEAR_CSR(mstatus, ~MSTATUS_MPP_MASK);
SET_CSR(mstatus, MSTATUS_MPPS | SSTATUS_SUM);
////CLEAR_CSR(mstatus, ~MSTATUS_MPP_MASK);
////SET_CSR(mstatus, MSTATUS_MPPS | SSTATUS_SUM);

/* Set the trap vector for S-mode */

WRITE_CSR(stvec, (uintptr_t)__trap_vec);

/* Set the trap vector for M-mode */

WRITE_CSR(mtvec, (uintptr_t)__trap_vec_m);
////WRITE_CSR(mtvec, (uintptr_t)__trap_vec_m);

if (0 == mhartid)
{
/* Only the primary CPU needs to initialize mtimer
* before entering to S-mode
*/

up_mtimer_initialize();
//// TODO
////up_mtimer_initialize();
}

/* Set mepc to the entry */

WRITE_CSR(mepc, (uintptr_t)qemu_rv_start_s);
////WRITE_CSR(mepc, (uintptr_t)qemu_rv_start_s);

/* Set a0 to mhartid explicitly and enter to S-mode */

asm volatile (
"mv a0, %0 \n"
"mret \n"
:: "r" (mhartid)
);
////asm volatile (
//// "mv a0, %0 \n"
//// "mret \n"
//// :: "r" (mhartid)
////);

//// Jump to S-Mode Init ourselves
qemu_rv_start_s(mhartid); ////
}
#endif

Expand Down
19 changes: 15 additions & 4 deletions boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# CONFIG_DISABLE_OS_API is not set
# CONFIG_NSH_DISABLE_LOSMART is not set
CONFIG_16550_ADDRWIDTH=0
CONFIG_16550_REGINCR=4
CONFIG_16550_UART0=y
CONFIG_16550_UART0_BASE=0x10000000
CONFIG_16550_UART0_CLOCK=3686400
Expand All @@ -31,9 +32,9 @@ CONFIG_ARCH_HEAP_VBASE=0xC0200000
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_KERNEL_STACKSIZE=3072
CONFIG_ARCH_PGPOOL_MAPPING=y
CONFIG_ARCH_PGPOOL_PBASE=0x80400000
CONFIG_ARCH_PGPOOL_PBASE=0x40600000
CONFIG_ARCH_PGPOOL_SIZE=4194304
CONFIG_ARCH_PGPOOL_VBASE=0x80400000
CONFIG_ARCH_PGPOOL_VBASE=0x40600000
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARCH_TEXT_NPAGES=128
Expand All @@ -44,10 +45,21 @@ CONFIG_ARCH_USE_S_MODE=y
CONFIG_BOARD_LOOPSPERMSEC=6366
CONFIG_BUILD_KERNEL=y
CONFIG_DEBUG_ASSERTIONS=y
CONFIG_DEBUG_ASSERTIONS_EXPRESSION=y
CONFIG_DEBUG_BINFMT=y
CONFIG_DEBUG_BINFMT_ERROR=y
CONFIG_DEBUG_BINFMT_INFO=y
CONFIG_DEBUG_BINFMT_WARN=y
CONFIG_DEBUG_ERROR=y
CONFIG_DEBUG_FEATURES=y
CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_SCHED=y
CONFIG_DEBUG_SCHED_ERROR=y
CONFIG_DEBUG_SCHED_INFO=y
CONFIG_DEBUG_SCHED_WARN=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEBUG_WARN=y
CONFIG_DEV_ZERO=y
CONFIG_ELF=y
CONFIG_EXAMPLES_HELLO=m
Expand Down Expand Up @@ -77,7 +89,7 @@ CONFIG_NSH_FILE_APPS=y
CONFIG_NSH_READLINE=y
CONFIG_PATH_INITIAL="/system/bin"
CONFIG_RAM_SIZE=1048576
CONFIG_RAM_START=0x80100000
CONFIG_RAM_START=0x40200000
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_RISCV_SEMIHOSTING_HOSTFS=y
CONFIG_RR_INTERVAL=200
Expand All @@ -88,7 +100,6 @@ CONFIG_STACK_COLORATION=y
CONFIG_START_MONTH=12
CONFIG_START_YEAR=2021
CONFIG_SYMTAB_ORDEREDBYNAME=y
CONFIG_SYSLOG_TIMESTAMP=y
CONFIG_SYSTEM_NSH=y
CONFIG_SYSTEM_NSH_PROGNAME="init"
CONFIG_TESTING_GETPRIME=y
Expand Down
2 changes: 1 addition & 1 deletion boards/risc-v/qemu-rv/rv-virt/configs/nsh64/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ CONFIG_NSH_SYMTAB_ARRAYNAME="g_symtab"
CONFIG_NSH_SYMTAB_COUNTNAME="g_nsymbols"
CONFIG_PATH_INITIAL="/system/bin"
CONFIG_RAM_SIZE=33554432
CONFIG_RAM_START=0x80000000
CONFIG_RAM_START=0x40200000
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_RISCV_SEMIHOSTING_HOSTFS=y
CONFIG_RR_INTERVAL=200
Expand Down
12 changes: 8 additions & 4 deletions boards/risc-v/qemu-rv/rv-virt/scripts/ld-kernel64.script
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@

MEMORY
{
kflash (rx) : ORIGIN = 0x80000000, LENGTH = 2048K /* w/ cache */
ksram (rwx) : ORIGIN = 0x80200000, LENGTH = 2048K /* w/ cache */
pgram (rwx) : ORIGIN = 0x80400000, LENGTH = 4096K /* w/ cache */
/* Previously 0x80000000 */
kflash (rx) : ORIGIN = 0x40200000, LENGTH = 2048K /* w/ cache */
/* Previously 0x80200000 */
ksram (rwx) : ORIGIN = 0x40400000, LENGTH = 2048K /* w/ cache */
/* Previously 0x80400000 */
pgram (rwx) : ORIGIN = 0x40600000, LENGTH = 4096K /* w/ cache */
}

OUTPUT_ARCH("riscv")
Expand All @@ -42,7 +45,8 @@ __pgheap_size = LENGTH(pgram);

SECTIONS
{
. = 0x80000000;
/* Previously 0x80000000 */
. = 0x40200000;

.text :
{
Expand Down
3 changes: 2 additions & 1 deletion boards/risc-v/qemu-rv/rv-virt/scripts/ld.script
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

SECTIONS
{
. = 0x80000000;
/* Previously 0x80000000 */
. = 0x40200000;

.text :
{
Expand Down
1 change: 1 addition & 0 deletions sched/init/nx_bringup.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ static inline void nx_start_application(void)

ret = exec_spawn(CONFIG_INIT_FILEPATH, argv, NULL,
CONFIG_INIT_SYMTAB, CONFIG_INIT_NEXPORTS, NULL, &attr);
sinfo("ret=%d\n", ret);////
#endif
posix_spawnattr_destroy(&attr);
DEBUGASSERT(ret > 0);
Expand Down
2 changes: 1 addition & 1 deletion tools/Unix.mk
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ tools/mkconfig$(HOSTEXEEXT):
include/nuttx/config.h: $(TOPDIR)/.config tools/mkconfig$(HOSTEXEEXT)
$(Q) grep -v "CONFIG_BASE_DEFCONFIG" "$(TOPDIR)/.config" > "$(TOPDIR)/.config.tmp"
$(Q) if ! cmp -s "$(TOPDIR)/.config.tmp" "$(TOPDIR)/.config.orig" ; then \
sed -i.bak "/CONFIG_BASE_DEFCONFIG/ { /-dirty/! s/\"$$/-dirty\"/ }" "$(TOPDIR)/.config"; \
sed -i.bak "/CONFIG_BASE_DEFCONFIG/s/\"$$/-dirty\"/" "$(TOPDIR)/.config"; \
else \
sed -i.bak "s/-dirty//g" "$(TOPDIR)/.config"; \
fi
Expand Down