diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a55/core.h b/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a55/core.h index d3259cab0..c9667450f 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a55/core.h +++ b/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a55/core.h @@ -73,7 +73,7 @@ Modification: #include "cortex_a55.h" -#define NR_CPU 2 // maximum number of CPUs +#define NR_CPU 4 // maximum number of CPUs __attribute__((always_inline)) static inline uint64_t EL0_mode() // Set ARM mode to EL0 { diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/hardkernel_init.c b/Ubiquitous/XiZi_AIoT/hardkernel/hardkernel_init.c index 13f6fe7ab..d2d0a6f14 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/hardkernel_init.c +++ b/Ubiquitous/XiZi_AIoT/hardkernel/hardkernel_init.c @@ -220,6 +220,7 @@ bool secondary_cpu_hardkernel_init(int cpu_id, struct TraceTag* _hardkernel_tag) p_icache_driver->enable(); p_dcache_driver->enable(); // clock + p_clock_driver->sys_clock_init(); p_intr_driver->single_irq_enable(p_clock_driver->get_clock_int(), cpu_id, 0); // mmu secondary_cpu_load_kern_pgdir(&init_mmu_tag, &init_intr_tag); diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a55/hard_spinlock.S b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a55/hard_spinlock.S index ff7fba64c..94c30939c 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a55/hard_spinlock.S +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a55/hard_spinlock.S @@ -55,64 +55,56 @@ Modification: #define UNLOCKED 0xFF // int spinlock_lock(spinlock_t * lock, uint64_t timeout) .global _spinlock_lock - .func _spinlock_lock +.func _spinlock_lock _spinlock_lock: -mov w2, #1 + mov w2, #1 + sevl +1: + wfe -sevl -wfe +2: + ldaxrb w1, [x0] // check if the spinlock is currently unlocked + cmp w1, #UNLOCKED + bne 1b -ldaxrb w1, [x0] // check if the spinlock is currently unlocked -cmp w1, #UNLOCKED -bne _spinlock_lock + mrs x1, mpidr_el1 // get our CPU ID + and x1, x1, #0xFFF + lsr x1, x1, #8 + stxrb w2, w1, [x0] + cmp x2, #0 + bne 2b // check if the write was successful, if the write failed, start over -mrs x1, mpidr_el1 // get our CPU ID -and x1, x1, #0xFFF -lsr x1, x1, #8 -stxrb w2, w1, [x0] -cmp x2, #0 -bne _spinlock_lock // check if the write was successful, if the write failed, start over + dmb ish // Ensure that accesses to shared resource have completed -dmb ish // Ensure that accesses to shared resource have completed - -mov x0, #0 -ret - - .endfunc + mov x0, #0 + ret +.endfunc // void spinlock_unlock(spinlock_t * lock) .global _spinlock_unlock .func _spinlock_unlock _spinlock_unlock: + mrs x1, mpidr_el1 // get our CPU ID + and x1, x1, #0xFFF + lsr x1, x1, #8 -mrs x1, mpidr_el1 // get our CPU ID -and x1, x1, #0xFFF -lsr x1, x1, #8 + ldr w2, [x0] + cmp w1, w2 + bne 1f //doesn't match,jump to 1 -ldr w2, [x0] -cmp w1, w2 -bne 1f //doesn't match,jump to 1 - - -dmb ish - -mov w1, #UNLOCKED -str w1, [x0] - -dsb ish //Ensure that no instructions following the barrier execute until - // all memory accesses prior to the barrier have completed. - - -sevl // send event to wake up other cores waiting on spinlock - -mov x0, #0 // return success -ret + dmb ish + mov w1, #UNLOCKED + str w1, [x0] + dsb ish //Ensure that no instructions following the barrier execute until + // all memory accesses prior to the barrier have completed. + sevl // send event to wake up other cores waiting on spinlock + mov x0, #0 // return success + ret 1: -mov x0, #1 //doesn't match, so exit with failure -ret - + mov x0, #1 //doesn't match, so exit with failure + ret .endfunc .end diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a55/trampoline.S b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a55/trampoline.S index 00941a0e9..82b11c0c7 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a55/trampoline.S +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a55/trampoline.S @@ -182,25 +182,19 @@ alltraps: b badtrap badtrap: - msr daifset, #0xf savereg - mov x0, sp bl kernel_intr_handler b . el1sync: - msr daifset, #0xf savereg - mov x0, sp bl kernel_abort_handler b . el1irq: - msr daifset, #0xf usavereg - mov x0, sp bl intr_irq_dispatch @@ -209,9 +203,7 @@ el1irq: eret el0sync: - msr daifset, #0xf usavereg - mov x0, sp bl syscall_arch_handler @@ -220,9 +212,7 @@ el0sync: eret el0irq: - msr daifset, #0xf usavereg - mov x0, sp bl intr_irq_dispatch diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/spinlock.c b/Ubiquitous/XiZi_AIoT/hardkernel/intr/spinlock.c index 0f2e09764..1153e5c78 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/spinlock.c +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/spinlock.c @@ -59,7 +59,7 @@ __attribute__((optimize("O0"))) void spinlock_init(struct spinlock* lock, char* } extern int _spinlock_lock(struct spinlock* lock, uint32_t timeout); -extern void _spinlock_unlock(struct spinlock* lock); +extern int _spinlock_unlock(struct spinlock* lock); __attribute__((optimize("O0"))) void spinlock_lock(struct spinlock* lock) { @@ -88,7 +88,9 @@ __attribute__((optimize("O0"))) void spinlock_unlock(struct spinlock* lock) _double_list_del(p_lock_node->prev, p_lock_node->next); _spinlock_unlock(&request_lock); - _spinlock_unlock(lock); + if (_spinlock_unlock(lock) != 0) { + ERROR("Core %d trying to unlock a lock belongs to %d.\n", cur_cpuid(), lock->owner_cpu); + } } __attribute__((optimize("O0"))) bool spinlock_try_lock(struct spinlock* lock) diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a55/3568/memlayout.h b/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a55/3568/memlayout.h index c58331610..650eb2080 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a55/3568/memlayout.h +++ b/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a55/3568/memlayout.h @@ -35,9 +35,9 @@ Modification: /* A55 physical memory layout */ #define PHY_MEM_BASE (0x0000000010000000ULL) -#define PHY_USER_FREEMEM_BASE (0x0000000030000000ULL) -#define PHY_USER_FREEMEM_TOP (0x0000000040000000ULL) -#define PHY_MEM_STOP (0x0000000040000000ULL) +#define PHY_USER_FREEMEM_BASE (0x0000000040000000ULL) +#define PHY_USER_FREEMEM_TOP (0x0000000050000000ULL) +#define PHY_MEM_STOP (0x0000000050000000ULL) /* PTE-PAGE_SIZE */ #define LEVEL4_PTE_SHIFT 12 @@ -58,7 +58,7 @@ Modification: #define NUM_TOPLEVEL_PDE NUM_LEVEL2_PDE #define PAGE_SIZE LEVEL4_PTE_SIZE -#define MAX_NR_FREE_PAGES ((PHY_MEM_STOP - PHY_MEM_BASE) >> LEVEL4_PTE_SHIFT) +#define MAX_NR_FREE_PAGES ((PHY_USER_FREEMEM_BASE - PHY_MEM_BASE) >> LEVEL4_PTE_SHIFT) /* Deivce memory layout */ #define DEV_PHYMEM_BASE (0x00000000F0000000ULL) diff --git a/Ubiquitous/XiZi_AIoT/services/app/Makefile b/Ubiquitous/XiZi_AIoT/services/app/Makefile index bb27401a7..2b5808fe6 100644 --- a/Ubiquitous/XiZi_AIoT/services/app/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/app/Makefile @@ -43,9 +43,9 @@ INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell \ -I$(KERNEL_ROOT)/services/app ifeq ($(BOARD), imx6q-sabrelite) -all: init test_fault simple_client simple_server shell fs_server semaphore_server test_semaphore test_ipc_null test_thread test_irq_hdlr test_irq_block test_irq_send eth_driver epit_server test_net lwip readme.txt | bin +all: test_fault simple_client simple_server shell fs_server semaphore_server test_semaphore test_ipc_null test_thread test_irq_hdlr test_irq_block test_irq_send eth_driver epit_server test_net lwip readme.txt | bin else -all: init test_fault simple_client simple_server shell fs_server semaphore_server test_ipc_null test_thread test_semaphore test_net lwip readme.txt eth_hal | bin +all: test_fault simple_client simple_server shell fs_server semaphore_server test_ipc_null test_thread test_semaphore test_net lwip readme.txt eth_hal | bin endif ../tools/mkfs/mkfs ./fs.img $^ @mv $(filter-out readme.txt, $^) bin @@ -97,10 +97,6 @@ shell: shell_port.o libserial.o printf.o shell_cmd_list.o shell.o shell_ext.o li @${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs} @${objdump} -S $@ > $@.asm -init: init.o libfs.o libipc.o session.o libserial.o printf.o usyscall.o arch_usyscall.o libmem.o - @${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs} - @${objdump} -S $@ > $@.asm - test_fault: test_fault.o libserial.o printf.o usyscall.o arch_usyscall.o @${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs} @${objdump} -S $@ > $@.asm diff --git a/Ubiquitous/XiZi_AIoT/services/app/init.c b/Ubiquitous/XiZi_AIoT/services/app/init.c deleted file mode 100755 index 08a76a846..000000000 --- a/Ubiquitous/XiZi_AIoT/services/app/init.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2020 AIIT XUOS Lab - * XiUOS is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ -// init: The initial user-level program -#include - -#include "libfs.h" -#include "libserial.h" -#include "usyscall.h" - -int main(int argc, char* argv[]) -{ - struct Session session; - printf("init: connecting MemFS\n"); - while (connect_session(&session, "MemFS", 8092) < 0) { - yield(SYS_TASK_YIELD_NO_REASON); - } - printf("init: connect MemFS success\n"); - - int fd; - char* shell_task_param[2] = { "/shell", 0 }; - if ((fd = open(&session, shell_task_param[0])) < 0) { - printf("Open %s failed\n", shell_task_param[0]); - exit(1); - } - - if (spawn(&session, fd, read, fsize, shell_task_param[0], shell_task_param) < 0) { - printf("Syscall Spawn shell failed\n"); - } - - close(&session, fd); - - exit(0); - return 0; -} diff --git a/Ubiquitous/XiZi_AIoT/services/fs/fs_server/fs_server.c b/Ubiquitous/XiZi_AIoT/services/fs/fs_server/fs_server.c index ae460ce13..3bfc42b89 100644 --- a/Ubiquitous/XiZi_AIoT/services/fs/fs_server/fs_server.c +++ b/Ubiquitous/XiZi_AIoT/services/fs/fs_server/fs_server.c @@ -349,7 +349,6 @@ IPC_SERVER_REGISTER_INTERFACES(IpcFsServer, 10, int main(int argc, char* argv[]) { - printf("MemFS Start\n"); sys_state_info info; get_memblock_info(&info); diff --git a/Ubiquitous/XiZi_AIoT/softkernel/load_apps.S b/Ubiquitous/XiZi_AIoT/softkernel/load_apps.S index 71d5278bd..597d60af0 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/load_apps.S +++ b/Ubiquitous/XiZi_AIoT/softkernel/load_apps.S @@ -35,7 +35,7 @@ user_apps: .section .rawdata_init .globl initapp initapp: - .incbin "../services/app/bin/init" + .incbin "../services/app/bin/shell" .section .rawdata_memfs .globl memfs diff --git a/Ubiquitous/XiZi_AIoT/softkernel/main.c b/Ubiquitous/XiZi_AIoT/softkernel/main.c index d8eb21680..593064ec0 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/main.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/main.c @@ -45,7 +45,7 @@ static struct TraceTag hardkernel_tag, softkernel_tag; static volatile int core_para_init = 0; static void sync_cores() { - while (core_para_init != 0xF) ; + while (core_para_init != ((1 << NR_CPU) - 1)) ; return; } @@ -92,8 +92,8 @@ int main(void) } /* start first task */ - char* init_task_param[2] = { "/app/init", 0 }; - sys_spawn((char*)_binary_init_start, "init", init_task_param); + char* init_task_param[2] = { "/app/shell", 0 }; + sys_spawn((char*)_binary_init_start, "shell", init_task_param); char* fs_server_task_param[2] = { "/app/fs_server", 0 }; sys_spawn((char*)_binary_default_fs_start, "memfs", fs_server_task_param); } diff --git a/Ubiquitous/XiZi_AIoT/softkernel/memory/kalloc.c b/Ubiquitous/XiZi_AIoT/softkernel/memory/kalloc.c index b68bd7390..1e799cc12 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/memory/kalloc.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/memory/kalloc.c @@ -49,7 +49,7 @@ bool module_phymem_init() return true; } -char* kalloc(size_t size) +char* kalloc(uintptr_t size) { char* mem_alloc = KBuddyAlloc(&kern_virtmem_buddy, size); if (mem_alloc == NULL) { diff --git a/Ubiquitous/XiZi_AIoT/softkernel/task/task.c b/Ubiquitous/XiZi_AIoT/softkernel/task/task.c index ef52dc65a..ecf749347 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/task/task.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/task/task.c @@ -303,13 +303,11 @@ static void _scheduler(struct SchedulerRightGroup right_group) /* if there's not a runnable task, wait for one */ if (next_task == NULL) { xizi_leave_kernel(); - // there is no task to run, into low power mode - cpu_into_low_power(); + /* leave kernel for other cores, so they may create a runnable task */ xizi_enter_kernel(); - // activate cpu - cpu_leave_low_power(); + continue; }