Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TODO: Support for RISC-V Star64 JH7110 SBC (Branch star64e) #36

Closed
wants to merge 134 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 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
d794e95
Ignore initrd
lupyuen Jul 22, 2023
a2c117a
Loading RAM Disk
lupyuen Jul 22, 2023
1e5f221
Loading RAM Disk
lupyuen Jul 22, 2023
f7cf230
RAM Disk boots OK on Star64 yay! Disable info log
lupyuen Jul 22, 2023
e26103d
Ignore init.S
lupyuen Jul 26, 2023
e5751b6
Fix User Address Space and I/O Address Space. Same result
lupyuen Jul 27, 2023
46c1a0f
Change RAM Base to 0x40200000
lupyuen Jul 27, 2023
4d36dd3
Console Output is stuck
lupyuen Jul 27, 2023
6087f17
No Console Output from NuttX Shell
lupyuen Jul 28, 2023
ea607bd
Log Console Output
lupyuen Jul 28, 2023
3d1efea
Log Console Output
lupyuen Jul 28, 2023
7ee9fb9
Disable ACLINT
lupyuen Jul 28, 2023
2ff7d88
UART0 IRQ becomes 32
lupyuen Jul 28, 2023
f3efcb6
Log IRQ
lupyuen Jul 28, 2023
150b431
Clean
lupyuen Jul 28, 2023
fd11cba
Log IRQ
lupyuen Jul 28, 2023
eba8bbc
Change IRQ to 57, Ext IRQ is 32
lupyuen Jul 28, 2023
b1c349b
Log IRQ
lupyuen Jul 28, 2023
c03eba3
Extend to 127 IRQs
lupyuen Jul 28, 2023
4d76f70
Extend to 127 IRQs
lupyuen Jul 28, 2023
c8f0e3a
Fixing UART Interrupt
lupyuen Jul 28, 2023
121b08f
Fixing UART Interrupt
lupyuen Jul 28, 2023
bf3475d
Debug Exception
lupyuen Jul 28, 2023
a3f4121
Debug Exception
lupyuen Jul 28, 2023
2979e5f
Debug Exception
lupyuen Jul 28, 2023
715fab2
Debug Exception
lupyuen Jul 28, 2023
ea7e9a0
Debug Exception
lupyuen Jul 28, 2023
4ccd58d
Debug Exception
lupyuen Jul 28, 2023
c003d2e
Debug Exception
lupyuen Jul 28, 2023
c3c12d0
Debug Exception
lupyuen Jul 28, 2023
89d7fda
Fix PLIC for Hart 1 S-Mode
lupyuen Jul 28, 2023
c2d256a
IRQ 57 OK yay!
lupyuen Jul 28, 2023
e6f5ed7
Remove logs
lupyuen Jul 28, 2023
0678e84
Remove logs
lupyuen Jul 28, 2023
a5027d5
IRQ 57 OK yay!
lupyuen Jul 28, 2023
7923912
responds to UART Input yay
lupyuen Jul 29, 2023
1d5a79c
responds to UART Input yay
lupyuen Jul 29, 2023
9094e95
Interrupt triggered repeatedly
lupyuen Jul 29, 2023
9104a64
Shows 0 forever
lupyuen Jul 29, 2023
ba4231e
Checking claim
lupyuen Jul 29, 2023
652648d
Why UART_IIR_INTSTATUS = 0
lupyuen Jul 29, 2023
9d715b3
Log UART Interrupt Status. 056789
lupyuen Jul 29, 2023
37124df
Log UART Interrupt Status. 056789
lupyuen Jul 29, 2023
06e6b5a
Log riscv_dispatch_irq. Seems OK
lupyuen Jul 30, 2023
476eea0
Fix delay
lupyuen Jul 30, 2023
93dc2ab
Fixing interrupt
lupyuen Jul 30, 2023
7cd0b5f
Delay enable IRQ
lupyuen Jul 30, 2023
a74a89c
Remove logs
lupyuen Jul 30, 2023
84e2349
Remove logs. NSH OK yay!
lupyuen Jul 30, 2023
866da12
Hart 1 Machine Mode doesn't work
lupyuen Jul 30, 2023
fcbaf15
PLIC Pending not used. Why?
lupyuen Aug 2, 2023
3c7bc6d
Console shows garbage
lupyuen Aug 2, 2023
9e40490
No more spurious UART interrupts yay! dlm=0, dll=13, baud=115200
lupyuen Aug 2, 2023
52bf1bb
Fixed UART Clock. NuttX Shell OK yay!
lupyuen Aug 2, 2023
3665d8e
Clean up
lupyuen Aug 2, 2023
6a0e96e
Clean up
lupyuen Aug 2, 2023
2848615
Clean up
lupyuen Aug 2, 2023
6447666
Clean up
lupyuen Aug 2, 2023
744e509
Clean up
lupyuen Aug 2, 2023
0653453
Clean up
lupyuen Aug 2, 2023
3e6c144
Clean up
lupyuen Aug 2, 2023
f63aa11
Clean up
lupyuen Aug 2, 2023
f95f62e
Clean up. Tested OK
lupyuen Aug 2, 2023
2464d7a
Clean up. Tested OK
lupyuen Aug 2, 2023
7ee02d6
Add 16550_WAIT_LCR to Kconfig. Tested OK
lupyuen Aug 2, 2023
5551808
Clean up
lupyuen Aug 3, 2023
9d6374e
Clean up. Tested OK
lupyuen Aug 3, 2023
fba309c
Delete files. Tested OK
lupyuen Aug 3, 2023
b820d9a
Clean up. Tested OK
lupyuen Aug 3, 2023
448f698
Clean up
lupyuen Aug 3, 2023
2a60e77
Clean up
lupyuen Aug 3, 2023
371fb8f
Clean up. Tested OK
lupyuen Aug 3, 2023
5761496
Clean up. Tested OK
lupyuen Aug 3, 2023
4a4f926
Clean up. Tested OK
lupyuen Aug 3, 2023
d820351
Rename config to nsh. Tested OK
lupyuen Aug 3, 2023
8d54b0a
Clean up. Tested OK
lupyuen Aug 3, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ uImage
.vscode
.DS_Store
tools/gdb/__pycache__
initrd
init.S
4 changes: 1 addition & 3 deletions arch/risc-v/include/qemu-rv/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

/* Map RISC-V exception code to NuttX IRQ */

#define QEMU_RV_IRQ_UART0 (RISCV_IRQ_MEXT + 10)

#define NR_IRQS (QEMU_RV_IRQ_UART0 + 1)
#define NR_IRQS (RISCV_IRQ_SEXT + 127)

#endif /* __ARCH_RISCV_INCLUDE_QEMU_RV_IRQ_H */
14 changes: 1 addition & 13 deletions arch/risc-v/src/qemu-rv/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,4 @@ HEAD_ASRC = qemu_rv_head.S
# Specify our C code within this directory to be included
CHIP_CSRCS = qemu_rv_start.c qemu_rv_irq_dispatch.c qemu_rv_irq.c
CHIP_CSRCS += qemu_rv_timerisr.c qemu_rv_allocateheap.c

ifeq ($(CONFIG_BUILD_KERNEL),y)
CHIP_CSRCS += qemu_rv_mm_init.c
CMN_ASRCS += qemu_rv_exception_m.S
endif

ifeq ($(CONFIG_MM_PGALLOC),y)
CHIP_CSRCS += qemu_rv_pgalloc.c
endif

ifeq ($(CONFIG_DRIVERS_VIRTIO_NET),y)
CHIP_CSRCS += qemu_rv_virtio.c
endif
CHIP_CSRCS += qemu_rv_mm_init.c qemu_rv_pgalloc.c
1 change: 0 additions & 1 deletion arch/risc-v/src/qemu-rv/chip.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

#include "qemu_rv_memorymap.h"

#include "hardware/qemu_rv_clint.h"
#include "hardware/qemu_rv_memorymap.h"
#include "hardware/qemu_rv_plic.h"

Expand Down
43 changes: 0 additions & 43 deletions arch/risc-v/src/qemu-rv/hardware/qemu_rv_clint.h

This file was deleted.

2 changes: 0 additions & 2 deletions arch/risc-v/src/qemu-rv/hardware/qemu_rv_memorymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

/* Register Base Address ****************************************************/

#define QEMU_RV_CLINT_BASE 0x02000000
#define QEMU_RV_ACLINT_BASE 0x02f00000
#define QEMU_RV_PLIC_BASE 0x0c000000

#endif /* __ARCH_RISCV_SRC_QEMU_RV_HARDWARE_QEMU_RV_MEMORYMAP_H */
28 changes: 15 additions & 13 deletions arch/risc-v/src/qemu-rv/hardware/qemu_rv_plic.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,21 @@
* Pre-processor Definitions
****************************************************************************/

/* Interrupt Priority */

#define QEMU_RV_PLIC_PRIORITY (QEMU_RV_PLIC_BASE + 0x000000)
#define QEMU_RV_PLIC_PENDING1 (QEMU_RV_PLIC_BASE + 0x001000)

#ifdef CONFIG_ARCH_USE_S_MODE
# define QEMU_RV_PLIC_ENABLE1 (QEMU_RV_PLIC_BASE + 0x002080)
# define QEMU_RV_PLIC_ENABLE2 (QEMU_RV_PLIC_BASE + 0x002084)
# define QEMU_RV_PLIC_THRESHOLD (QEMU_RV_PLIC_BASE + 0x201000)
# define QEMU_RV_PLIC_CLAIM (QEMU_RV_PLIC_BASE + 0x201004)
#else
# define QEMU_RV_PLIC_ENABLE1 (QEMU_RV_PLIC_BASE + 0x002000)
# define QEMU_RV_PLIC_ENABLE2 (QEMU_RV_PLIC_BASE + 0x002004)
# define QEMU_RV_PLIC_THRESHOLD (QEMU_RV_PLIC_BASE + 0x200000)
# define QEMU_RV_PLIC_CLAIM (QEMU_RV_PLIC_BASE + 0x200004)
#endif

/* Hart 1 S-Mode Interrupt Enable */

#define QEMU_RV_PLIC_ENABLE1 (QEMU_RV_PLIC_BASE + 0x002100)
#define QEMU_RV_PLIC_ENABLE2 (QEMU_RV_PLIC_BASE + 0x002104)

/* Hart 1 S-Mode Priority Threshold */

#define QEMU_RV_PLIC_THRESHOLD (QEMU_RV_PLIC_BASE + 0x202000)

/* Hart 1 S-Mode Claim / Complete */

#define QEMU_RV_PLIC_CLAIM (QEMU_RV_PLIC_BASE + 0x202004)

#endif /* __ARCH_RISCV_SRC_QEMU_RV_HARDWARE_QEMU_RV_PLIC_H */
4 changes: 0 additions & 4 deletions arch/risc-v/src/qemu-rv/qemu_rv_allocateheap.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@
*
****************************************************************************/

#ifdef CONFIG_BUILD_KERNEL
void up_allocate_kheap(void **heap_start, size_t *heap_size)
#else
void up_allocate_heap(void **heap_start, size_t *heap_size)
#endif /* CONFIG_BUILD_KERNEL */
{
#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP)
/* Get the size and position of the user-space heap.
Expand Down
105 changes: 0 additions & 105 deletions arch/risc-v/src/qemu-rv/qemu_rv_exception_m.S

This file was deleted.

46 changes: 38 additions & 8 deletions arch/risc-v/src/qemu-rv/qemu_rv_head.S
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,40 @@
.global __start

__start:
/* Begin Test */

/* Load mhartid (cpuid) */
/* 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 */
.quad _ebss - __start /* Effective size of kernel image */
.quad 0 /* Kernel flags, little-endian */
.long 2 /* 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:

/* 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.
*/

csrr a0, mhartid
addi a0, a0, -1

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

Expand All @@ -60,14 +90,14 @@ __start:
li t1, 1
#endif

/* If a0 (mhartid) >= t1 (the number of CPUs), stop here */
/* If a0 (hartid) >= t1 (the number of CPUs), stop here */

blt a0, t1, 3f
csrw mie, zero
csrw sie, zero
wfi

3:
/* To get g_cpu_basestack[mhartid], must get g_cpu_basestack first */
/* To get g_cpu_basestack[hartid], must get g_cpu_basestack first */

la t0, g_cpu_basestack

Expand Down Expand Up @@ -96,12 +126,12 @@ __start:

2:

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

csrw mie, zero
csrw sie, zero

la t0, __trap_vec
csrw mtvec, t0
csrw stvec, t0

/* Jump to qemu_rv_start */

Expand Down
18 changes: 5 additions & 13 deletions arch/risc-v/src/qemu-rv/qemu_rv_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void up_irqinitialize(void)

int id;

for (id = 1; id <= 52; id++)
for (id = 1; id <= NR_IRQS; id++)
{
putreg32(1, (uintptr_t)(QEMU_RV_PLIC_PRIORITY + 4 * id));
}
Expand Down Expand Up @@ -150,24 +150,16 @@ void up_enable_irq(int irq)

if (irq == RISCV_IRQ_SOFT)
{
/* Read m/sstatus & set machine software interrupt enable in m/sie */
/* Read sstatus & set machine software interrupt enable in sie */

SET_CSR(CSR_IE, IE_SIE);
}
else if (irq == RISCV_IRQ_TIMER)
{
/* Read m/sstatus & set timer interrupt enable in m/sie */
/* Read sstatus & set timer interrupt enable in sie */

SET_CSR(CSR_IE, IE_TIE);
}
#ifdef CONFIG_BUILD_KERNEL
else if (irq == RISCV_IRQ_MTIMER)
{
/* Read m/sstatus & set timer interrupt enable in m/sie */

SET_CSR(mie, MIE_MTIE);
}
#endif
else if (irq > RISCV_IRQ_EXT)
{
extirq = irq - RISCV_IRQ_EXT;
Expand All @@ -190,11 +182,11 @@ irqstate_t up_irq_enable(void)
{
irqstate_t oldstat;

/* Enable external interrupts (mie/sie) */
/* Enable external interrupts (sie) */

SET_CSR(CSR_IE, IE_EIE);

/* Read and enable global interrupts (M/SIE) in m/sstatus */
/* Read and enable global interrupts (sie) in sstatus */

oldstat = READ_AND_SET_CSR(CSR_STATUS, STATUS_IE);

Expand Down
6 changes: 1 addition & 5 deletions arch/risc-v/src/qemu-rv/qemu_rv_irq_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@
* Pre-processor Definitions
****************************************************************************/

#ifdef CONFIG_ARCH_RV32
# define RV_IRQ_MASK 27
#else
# define RV_IRQ_MASK 59
#endif
#define RV_IRQ_MASK 59

/****************************************************************************
* Public Functions
Expand Down
Loading