diff --git a/src/arch/riscv64/include/plic.h b/src/arch/riscv64/include/plic.h index 3b0b301269a297877a244be51a3c23aeb6caab94..b239af0debd0cd85e97057cc4f0ad7cb565ba494 100644 --- a/src/arch/riscv64/include/plic.h +++ b/src/arch/riscv64/include/plic.h @@ -23,7 +23,7 @@ /* interrupt pending */ #define PLIC_PENDING (PLIC_ADDR + 0x1000) -#if CONFIG_NX_PLATFORM_K210 +#ifdef CONFIG_NX_PLATFORM_K210 /* interrupt enable for each hart */ #define __PLIC_ENABLE(hart) (PLIC_ADDR + 0x2000 + (hart) * 0x80) diff --git a/src/arch/riscv64/kernel/plic.c b/src/arch/riscv64/kernel/plic.c index 71a1f9aebef586eb3562e39c3daa9adaee90c002..34521419a3d65498571f218ed228e1353a726e77 100644 --- a/src/arch/riscv64/kernel/plic.c +++ b/src/arch/riscv64/kernel/plic.c @@ -94,7 +94,7 @@ NX_Error PLIC_Complete(NX_U32 hart, int irqno) *(NX_U32 *)PLIC_CLAIM(hart) = irqno; -#if CONFIG_NX_PLATFORM_K210 +#ifdef CONFIG_NX_PLATFORM_K210 WriteCSR(sip, ReadCSR(sip) & ~SIP_SSIE); /* clear software pending bit */ sbi_set_mie(); /* enable machine interrupt after complete */ #endif @@ -111,13 +111,12 @@ void PLIC_Init(NX_Bool bootCore) { /* priority must be > threshold to trigger an interrupt */ Write32(PLIC_THRESHOLD(hart), 0); - - /* set all interrupt priority */ - int irqno; - for (irqno = 1; irqno < NX_NR_IRQS; irqno++) - { - PLIC_SetPriority(irqno, 0); - } + } + /* set all interrupt priority */ + int irqno; + for (irqno = 1; irqno < NX_NR_IRQS; irqno++) + { + PLIC_SetPriority(irqno, 0); } } /* Enable supervisor external interrupts. */ diff --git a/src/arch/riscv64/port/context.c b/src/arch/riscv64/port/context.c index a7366bd16933343ffe6a96378aec60752aeb3a43..adfdeb8ab0d420807bd9e8f248bcb922faa5e162 100644 --- a/src/arch/riscv64/port/context.c +++ b/src/arch/riscv64/port/context.c @@ -42,8 +42,12 @@ NX_PRIVATE void *NX_HalContextInit(void *startEntry, void *exitEntry, void *arg, * return to supervisor mode, * enable interrupt */ +#ifdef CONFIG_NX_PLATFORM_K210 + /* NOTICE: in k210, SSTATUS_SUM mean disable Supervisor Access User memroy */ + context->sstatus = SSTATUS_SPP | SSTATUS_SPIE; +#else context->sstatus = SSTATUS_SUM | SSTATUS_SPP | SSTATUS_SPIE; - +#endif return (void *)stack; } diff --git a/src/arch/riscv64/port/mmu.c b/src/arch/riscv64/port/mmu.c index f0c495847e6828e4f1881ed3c46979940723321f..51ab5f68eed766af77b706063d35f5dc36f8c602 100644 --- a/src/arch/riscv64/port/mmu.c +++ b/src/arch/riscv64/port/mmu.c @@ -78,6 +78,7 @@ NX_PRIVATE MMU_PTE *PageWalk(MMU_PDE *pageTable, NX_Addr virAddr, NX_Bool allocP pageTable = (MMU_PDE *)NX_PageAlloc(1); if (pageTable == NX_NULL) { + NX_LOG_E("riscv64 mmu-sv39: page walk with no enough memory!"); return NX_NULL; } NX_MemZero(NX_Phy2Virt(pageTable), NX_PAGE_SIZE); diff --git a/src/arch/riscv64/port/smp.c b/src/arch/riscv64/port/smp.c index b30bef45ac5608dc03dd8cacac829a652aa6c058..e62afe29b50da521e8c7d9fca8cd8602d6315809 100644 --- a/src/arch/riscv64/port/smp.c +++ b/src/arch/riscv64/port/smp.c @@ -56,26 +56,32 @@ NX_PRIVATE NX_UArch NX_HalCoreGetIndex(void) NX_PRIVATE NX_Error NX_HalCoreBootApp(NX_UArch bootCoreId) { -#ifdef CONFIG_NX_PLATFORM_K210 - return NX_ENORES; /* not support smp on k210 */ -#else + NX_LOG_I("boot core is:%d", bootCoreId); NX_UArch coreId; for (coreId = 0; coreId < NX_MULTI_CORES_NR; coreId++) { +#ifndef CONFIG_NX_PLATFORM_K210 NX_LOG_I("core#%d state:%d", coreId, sbi_hsm_hart_status(coreId)); +#endif if (bootCoreId == coreId) /* skip boot core */ { NX_LOG_I("core#%d is boot core, skip it", coreId); continue; } NX_LOG_I("wakeup app core:%d", coreId); +#ifdef CONFIG_NX_PLATFORM_K210 + NX_UArch mask = 1 << coreId; + sbi_send_ipi(&mask); +#else sbi_hsm_hart_start(coreId, MEM_KERNEL_BASE, 0); +#endif NX_MemoryBarrier(); +#ifndef CONFIG_NX_PLATFORM_K210 NX_LOG_I("core#%d state:%d after wakeup", coreId, sbi_hsm_hart_status(coreId)); +#endif } return NX_EOK; -#endif } NX_PRIVATE NX_Error NX_HalCoreEnterApp(NX_UArch appCoreId) diff --git a/src/platform/i386/nxos.ld b/src/platform/i386/nxos.ld index 455eadea1344fd6360dffd30f045c0a17fbf4858..6763417f96a547a1673f0713fc9bf234a42e67bc 100644 --- a/src/platform/i386/nxos.ld +++ b/src/platform/i386/nxos.ld @@ -77,6 +77,14 @@ SECTIONS { . = ALIGN(4); __NX_DataStart = .; + .data : + { + *(.data) + *(.data.*) + *(.rodata) + *(.rodata.*) + } + .romdisk ALIGN(8) : { PROVIDE(__NX_RomdiskStart = .); @@ -86,13 +94,6 @@ SECTIONS { . = ALIGN(8); - .data : - { - *(.data) - *(.data.*) - *(.rodata) - *(.rodata.*) - } __NX_DataEnd = .; /* bss segement */ diff --git a/src/platform/k210/cmd.mk b/src/platform/k210/cmd.mk index 5dd8dc1af6b4a227daedb7030abc9eed6ed72e40..08adcaec3f562459650e06a208afe52b6ef5f121 100644 --- a/src/platform/k210/cmd.mk +++ b/src/platform/k210/cmd.mk @@ -26,8 +26,7 @@ DUMP := $(CROSS_COMPILE)objdump OC := $(CROSS_COMPILE)objcopy K210_BIN := k210.bin -K210_ASM := k210.S -K210_DEV ?= /dev/ttyUSB0 +UART ?= /dev/ttyUSB0 KFLASH := ./tools/kflash.py # @@ -44,9 +43,9 @@ run: $(DD) if=$(NXOS_NAME).bin of=$(K210_BIN) bs=128k seek=1 echo "K210 run..." ifeq ($(HOSTOS),linux) - $(SU) chmod 777 $(K210_DEV) + $(SU) chmod 777 $(UART) endif - $(PYTHON) $(KFLASH) -p $(K210_DEV) -b 1500000 -t $(K210_BIN) + $(PYTHON) $(KFLASH) -p $(UART) -b 1500000 -t $(K210_BIN) # # Clear target file @@ -54,7 +53,8 @@ endif clean: -$(RM) $(NXOS_NAME).elf -$(RM) $(K210_BIN) - -$(RM) $(K210_ASM) + -$(RM) $(NXOS_NAME).dump.S + -$(RM) $(NXOS_NAME).bin # # prepare tools diff --git a/src/platform/k210/nxos.ld b/src/platform/k210/nxos.ld index 23bc4162d222f068a1089630544e8725109c47b2..58f2571661517eb0eaa13f4280312fb46e78bf27 100644 --- a/src/platform/k210/nxos.ld +++ b/src/platform/k210/nxos.ld @@ -78,6 +78,14 @@ SECTIONS . = ALIGN(8); __NX_DataStart = .; + .data : + { + *(.data) + *(.data.*) + *(.rodata) + *(.rodata.*) + } + .romdisk ALIGN(8) : { PROVIDE(__NX_RomdiskStart = .); @@ -86,13 +94,6 @@ SECTIONS } . = ALIGN(8); - .data : - { - *(.data) - *(.data.*) - *(.rodata) - *(.rodata.*) - } __NX_DataEnd = .; /* bss segement */ diff --git a/src/platform/qemu_riscv64/nxos.ld b/src/platform/qemu_riscv64/nxos.ld index aff105f9b6bbc1e5c8a14baa0bcb86ba385ad954..4679f162be6ef1dcf1bdd1f18760d84a18bc670b 100644 --- a/src/platform/qemu_riscv64/nxos.ld +++ b/src/platform/qemu_riscv64/nxos.ld @@ -77,6 +77,14 @@ SECTIONS . = ALIGN(8); __NX_DataStart = .; + .data : + { + *(.data) + *(.data.*) + *(.rodata) + *(.rodata.*) + } + .romdisk ALIGN(8) : { PROVIDE(__NX_RomdiskStart = .); @@ -86,13 +94,6 @@ SECTIONS . = ALIGN(8); - .data : - { - *(.data) - *(.data.*) - *(.rodata) - *(.rodata.*) - } __NX_DataEnd = .; /* bss segement */ diff --git a/src/time/clock.c b/src/time/clock.c index 2428bfa538a6e76afa1b4aa69d6889153f143459..672822bae9c63d8ad496401b26f1ba50b2c80010 100644 --- a/src/time/clock.c +++ b/src/time/clock.c @@ -27,7 +27,7 @@ NX_IMPORT NX_Error NX_HalInitClock(void); /* NOTE: must add NX_VOLATILE here, avoid compiler optimization */ -NX_PRIVATE NX_VOLATILE NX_ClockTick SystemClockTicks; +NX_PRIVATE NX_VOLATILE NX_ClockTick SystemClockTicks = 0; NX_PRIVATE NX_IRQ_DelayWork TimerWork; NX_PRIVATE NX_IRQ_DelayWork SchedWork;