diff --git a/Ubiquitous/XiZi_AIoT/Makefile b/Ubiquitous/XiZi_AIoT/Makefile index 65ec7a2b8..ddd3dab82 100755 --- a/Ubiquitous/XiZi_AIoT/Makefile +++ b/Ubiquitous/XiZi_AIoT/Makefile @@ -129,6 +129,7 @@ clean: @rm -rf build @rm -rf temp.txt @rm -rf services/app/bin + @rm -f services/app/*.o @rm -rf services/tools/mkfs/mkfs @rm -rf services/app/fs.img @rm -rf services/app/user.map diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a72/context_switch.S b/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a72/context_switch.S index 383aee1ab..fe6faae02 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a72/context_switch.S +++ b/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a72/context_switch.S @@ -26,25 +26,31 @@ History: .global context_switch context_switch: - # Save store original context to stack - stp x29, lr, [sp, #-16]! - stp x27, x28, [sp, #-16]! - stp x25, x26, [sp, #-16]! - stp x23, x24, [sp, #-16]! - stp x21, x22, [sp, #-16]! - stp x19, x20, [sp, #-16]! - # Switch stacks - mov x19, sp - str x19, [x0] - mov sp, x1 + mov x9, sp + mov x10, sp - # restore context from stack - ldp x19, x20, [sp], #16 - ldp x21, x22, [sp], #16 - ldp x23, x24, [sp], #16 - ldp x25, x26, [sp], #16 - ldp x27, x28, [sp], #16 - ldp x29, lr, [sp], #16 + sub x9, x9, #16 * 7 + stp x10/*sp*/, x18, [x9, #16 * 0] + stp x19, x20, [x9, #16 * 1] + stp x21, x22, [x9, #16 * 2] + stp x23, x24, [x9, #16 * 3] + stp x25, x26, [x9, #16 * 4] + stp x27, x28, [x9, #16 * 5] + stp x29, x30, [x9, #16 * 6] + str x9, [x0] + mov x9, x1 + + ldp x10/*sp*/, x18, [x9, #16 * 0] + ldp x19, x20, [x9, #16 * 1] + ldp x21, x22, [x9, #16 * 2] + ldp x23, x24, [x9, #16 * 3] + ldp x25, x26, [x9, #16 * 4] + ldp x27, x28, [x9, #16 * 5] + ldp x29, x30, [x9, #16 * 6] + add x9, x9, #16 * 7 + + mov sp, x9 + ret \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a72/core.h b/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a72/core.h index afac3c096..d44c18e94 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a72/core.h +++ b/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a72/core.h @@ -77,7 +77,7 @@ Modification: __attribute__((always_inline)) static inline uint64_t EL0_mode() // Set ARM mode to EL0 { - uint64_t val; + uint64_t val = 0; __asm__ __volatile__( "mrs %0, spsr_el1" @@ -126,7 +126,7 @@ extern void task_prepare_enter(void); __attribute__((__always_inline__)) static inline void arch_init_context(struct context* ctx) { memset(ctx, 0, sizeof(*ctx)); - ctx->x30 = (uint64_t)(task_prepare_enter); + ctx->x30 = (uintptr_t)(task_prepare_enter + 4); } struct trapframe { diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a72/preboot_for_ok1028a-c/include/cortex_a72.h b/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a72/preboot_for_ok1028a-c/include/cortex_a72.h index 1f85cdb5c..3358e8d12 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a72/preboot_for_ok1028a-c/include/cortex_a72.h +++ b/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a72/preboot_for_ok1028a-c/include/cortex_a72.h @@ -63,10 +63,10 @@ Modification: #define ISB() __asm__ volatile("isb\n\t") #define _ARM_MRS(coproc, opcode1, Rt, CRn, CRm, opcode2) \ - asm volatile("mrc p" #coproc ", " #opcode1 ", %[output], c" #CRn ", c" #CRm ", " #opcode2 "\n" : [output] "=r"(Rt)) + __asm__ volatile("mrc p" #coproc ", " #opcode1 ", %[output], c" #CRn ", c" #CRm ", " #opcode2 "\n" : [output] "=r"(Rt)) #define _ARM_MSR(coproc, opcode1, Rt, CRn, CRm, opcode2) \ - asm volatile("mcr p" #coproc ", " #opcode1 ", %[input], c" #CRn ", c" #CRm ", " #opcode2 "\n" ::[input] "r"(Rt)) + __asm__ volatile("mcr p" #coproc ", " #opcode1 ", %[input], c" #CRn ", c" #CRm ", " #opcode2 "\n" ::[input] "r"(Rt)) // #define WriteReg(value, address) (*(volatile unsigned int*)(address) = (value)) // #define ReadReg(address) (*(volatile unsigned int*)(address)) diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a72/preboot_for_ok1028a-c/nxp_ls1028.lds b/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a72/preboot_for_ok1028a-c/nxp_ls1028.lds index e39565950..722ddf1e7 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a72/preboot_for_ok1028a-c/nxp_ls1028.lds +++ b/Ubiquitous/XiZi_AIoT/hardkernel/arch/arm/armv8-a/cortex-a72/preboot_for_ok1028a-c/nxp_ls1028.lds @@ -45,24 +45,13 @@ ENTRY( _ENTRY ) ENTRY( _boot_start ) MEMORY { - /** - phy_ddr3 (rwx) : ORIGIN = 0x0000000040000000, LENGTH = 0x8000000 - vir_ddr3 (rwx) : ORIGIN = 0xffffff8040010000, LENGTH = 0x8000000 - */ phy_ddr3 (rwx) : ORIGIN = 0x0000000040000000, LENGTH = 1024M vir_ddr3 (rwx) : ORIGIN = 0x0000006040635000, LENGTH = 1024M - /* vir_ddr3 (rwx) : ORIGIN = 0xffffffE040635000, LENGTH = 1024M */ } SECTIONS { - /* - * ensure that entry.S / _entry is at 0x40000000(physical address), - * where qemu's -kernel jumps. - * 0x40000000(PA) is 0xffffff8040000000(VA); - */ - .start_sec : { . = ALIGN(0x1000); /* initialization start checkpoint. */ @@ -102,19 +91,21 @@ SECTIONS .data : { *(.data .data.*) - . = ALIGN(1000); + . = ALIGN(0x1000); PROVIDE(_binary_fs_img_start = .); *(.rawdata_fs_img*) PROVIDE(_binary_fs_img_end = .); + . = ALIGN(0x1000); PROVIDE(_binary_init_start = .); *(.rawdata_init*) PROVIDE(_binary_init_end = .); + . = ALIGN(0x1000); PROVIDE(_binary_default_fs_start = .); *(.rawdata_memfs*) PROVIDE(_binary_default_fs_end = .); } > vir_ddr3 - . = ALIGN(1000); + . = ALIGN(0x1000); PROVIDE(kernel_data_begin = .); _image_size = . - 0x0000006040000000; diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/clock/arm/armv8-a/cortex-a72/ok1028a-c/clock.c b/Ubiquitous/XiZi_AIoT/hardkernel/clock/arm/armv8-a/cortex-a72/ok1028a-c/clock.c index dc5669207..6a87e4c05 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/clock/arm/armv8-a/cortex-a72/ok1028a-c/clock.c +++ b/Ubiquitous/XiZi_AIoT/hardkernel/clock/arm/armv8-a/cortex-a72/ok1028a-c/clock.c @@ -1,3 +1,15 @@ +/* + * 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. + */ + #include "actracer.h" #include "core.h" #include "generic_timer.h" diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/clock/arm/armv8-a/cortex-a72/ok1028a-c/include/generic_timer.h b/Ubiquitous/XiZi_AIoT/hardkernel/clock/arm/armv8-a/cortex-a72/ok1028a-c/include/generic_timer.h index 1bdc394ee..fe84893a1 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/clock/arm/armv8-a/cortex-a72/ok1028a-c/include/generic_timer.h +++ b/Ubiquitous/XiZi_AIoT/hardkernel/clock/arm/armv8-a/cortex-a72/ok1028a-c/include/generic_timer.h @@ -1,3 +1,14 @@ +/* + * 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. + */ #pragma once #include @@ -7,37 +18,37 @@ static inline uint64_t r_cntv_ctl_el0() { uint64_t x; - asm volatile("mrs %0, cntv_ctl_el0" : "=r"(x)); + __asm__ volatile("mrs %0, cntv_ctl_el0" : "=r"(x)); return x; } static inline void w_cntv_ctl_el0(uint64_t x) { - asm volatile("msr cntv_ctl_el0, %0" : : "r"(x)); + __asm__ volatile("msr cntv_ctl_el0, %0" : : "r"(x)); } static inline uint64_t r_cntv_tval_el0() { uint64_t x; - asm volatile("mrs %0, cntv_tval_el0" : "=r"(x)); + __asm__ volatile("mrs %0, cntv_tval_el0" : "=r"(x)); return x; } static inline void w_cntv_tval_el0(uint64_t x) { - asm volatile("msr cntv_tval_el0, %0" : : "r"(x)); + __asm__ volatile("msr cntv_tval_el0, %0" : : "r"(x)); } static inline uint64_t r_cntvct_el0() { uint64_t x; - asm volatile("mrs %0, cntvct_el0" : "=r"(x)); + __asm__ volatile("mrs %0, cntvct_el0" : "=r"(x)); return x; } static inline uint64_t r_cntfrq_el0() { uint64_t x; - asm volatile("mrs %0, cntfrq_el0" : "=r"(x)); + __asm__ volatile("mrs %0, cntfrq_el0" : "=r"(x)); return x; } \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/imx6q-sabrelite/trap_common.c b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/imx6q-sabrelite/trap_common.c index 47dede1b9..f76b56719 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/imx6q-sabrelite/trap_common.c +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/imx6q-sabrelite/trap_common.c @@ -89,7 +89,7 @@ static void _sys_irq_init(int cpu_id) gic_init(); } /* active hardware irq responser */ - xizi_trap_driver.switch_hw_irqtbl((uint32_t*)&_vector_jumper); + xizi_trap_driver.switch_hw_irqtbl((uintptr_t*)&_vector_jumper); } static void _cpu_irq_enable(void) @@ -117,7 +117,7 @@ static void _single_irq_disable(int irq, int cpu) } #define VBAR -static inline uint32_t* _switch_hw_irqtbl(uint32_t* new_tbl_base) +static inline uintptr_t* _switch_hw_irqtbl(uintptr_t* new_tbl_base) { // get old irq table base addr uint32_t old_tbl_base = 0; @@ -132,7 +132,7 @@ static inline uint32_t* _switch_hw_irqtbl(uint32_t* new_tbl_base) sctlr &= ~(1 << 13); _ARM_MCR(15, 0, sctlr, 1, 0, 0); - return (uint32_t*)old_tbl_base; + return (uintptr_t*)old_tbl_base; } static void _bind_irq_handler(int irq, irq_handler_t handler) diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/error_debug.c b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/error_debug.c index fea86cde0..f32c42814 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/error_debug.c +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/error_debug.c @@ -51,7 +51,7 @@ Modification: void dump_tf(struct trapframe* tf) { KPrintf(" sp: 0x%x\n", tf->sp); - KPrintf(" pc: 0x%x\n", tf->pc); + KPrintf(" pc: 0x%x\n", tf->pc); KPrintf(" spsr: 0x%x\n", tf->spsr); KPrintf(" x0: 0x%x\n", tf->x0); KPrintf(" x1: 0x%x\n", tf->x1); diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/gicv3/gicv3.c b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/gicv3/gicv3.c index 49d493a64..b585dadb6 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/gicv3/gicv3.c +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/gicv3/gicv3.c @@ -14,8 +14,7 @@ History: Author: AIIT XUOS Lab Modification: *************************************************/ -#include "string.h" -#include +#include #include "core.h" #include "gicv3_common_opa.h" @@ -169,19 +168,10 @@ void gic_init() gicdinit(); } -static inline uint64_t cpuid() +void gicv3inithart(uint32_t cpu_id) { - uint64_t x; - __asm__ volatile("mrs %0, mpidr_el1" : "=r"(x)); - return x & 0xff; -} - -void gicv3inithart() -{ - uint32_t cpu = cpuid(); - giccinit(); - gicrinit(cpu); + gicrinit(cpu_id); gic_enable(); } @@ -259,7 +249,6 @@ void gic_setup_ppi(uint32_t cpuid, uint32_t intid) void gic_setup_spi(uint32_t cpuid, uint32_t intid) { gic_set_prio0(intid); - // all interrupts are handled by cpu0  gic_set_target(intid, cpuid); gic_clear_pending(intid); gic_enable_int(intid); diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/gicv3/gicv3_common_opa.h b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/gicv3/gicv3_common_opa.h index cf0b8ca60..68d072b52 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/gicv3/gicv3_common_opa.h +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/gicv3/gicv3_common_opa.h @@ -144,7 +144,7 @@ void gic_set_irq_priority(uint32_t irq_id, uint32_t priority); void gic_setup_spi(uint32_t cpuid, uint32_t intid); -void gicv3inithart(); +void gicv3inithart(uint32_t cpu_id); //! @brief Send a software generated interrupt to a specific CPU. //! //! @param irq_id The interrupt number to send. diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/gicv3/gicv3_registers.h b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/gicv3/gicv3_registers.h index 7d365b7c8..cad07f367 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/gicv3/gicv3_registers.h +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/gicv3/gicv3_registers.h @@ -27,6 +27,8 @@ Modification: #ifndef __LINUX_IRQCHIP_ARM_GIC_H #define __LINUX_IRQCHIP_ARM_GIC_H +#include "memlayout.h" + // clang-format off // interrupt controller GICv3 #define GICV3 (DEV_VRTMEM_BASE + 0x08000000L) diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/ok1028a-c/exception_registers.h b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/ok1028a-c/exception_registers.h index f5a5695ef..c09a91a8e 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/ok1028a-c/exception_registers.h +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/ok1028a-c/exception_registers.h @@ -8,57 +8,50 @@ static inline void w_vbar_el1(uint64_t x) { - asm volatile("msr vbar_el1, %0" : : "r"(x)); + __asm__ volatile("msr vbar_el1, %0" : : "r"(x)); } -static inline uint64_t -r_esr_el1() +static inline uint64_t r_esr_el1() { uint64_t x; - asm volatile("mrs %0, esr_el1" : "=r"(x)); + __asm__ volatile("mrs %0, esr_el1" : "=r"(x)); return x; } -static inline void -w_esr_el1(uint64_t x) +static inline void w_esr_el1(uint64_t x) { - asm volatile("msr esr_el1, %0" : : "r"(x)); + __asm__ volatile("msr esr_el1, %0" : : "r"(x)); } -static inline uint64_t -r_elr_el1() +static inline uint64_t r_elr_el1() { uint64_t x; - asm volatile("mrs %0, elr_el1" : "=r"(x)); + __asm__ volatile("mrs %0, elr_el1" : "=r"(x)); return x; } -static inline uint64_t -r_far_el1() +static inline uint64_t r_far_el1() { uint64_t x; - asm volatile("mrs %0, far_el1" : "=r"(x)); + __asm__ volatile("mrs %0, far_el1" : "=r"(x)); return x; } -static inline uint64_t -daif() +static inline uint64_t daif() { uint64_t x; - asm volatile("mrs %0, daif" : "=r"(x)); + __asm__ volatile("mrs %0, daif" : "=r"(x)); return x; } // enable interrupts(irq) -static inline void -intr_on() +static inline void intr_on() { - asm volatile("msr daifclr, #0xf" ::: "memory"); + __asm__ volatile("msr daifclr, #0xf" ::: "memory"); } // disable interrupts(irq) -static inline void -intr_off() +static inline void intr_off() { - asm volatile("msr daifset, #0xf" ::: "memory"); + __asm__ volatile("msr daifset, #0xf" ::: "memory"); } \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/ok1028a-c/trap.c b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/ok1028a-c/trap.c index d7889c530..10b8cbd8c 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/ok1028a-c/trap.c +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/ok1028a-c/trap.c @@ -41,7 +41,7 @@ extern void iabort_handler(struct trapframe* r); void kernel_abort_handler(struct trapframe* tf) { uint64_t esr = r_esr_el1(); - switch ((esr & 0x3F) >> 26) { + switch ((esr >> 26) & 0x3F) { case 0b100100: case 0b100101: dabort_handler(tf); @@ -49,6 +49,11 @@ void kernel_abort_handler(struct trapframe* tf) case 0b100001: iabort_handler(tf); default: + uint64_t ec = (esr >> 26) & 0x3f; + uint64_t iss = esr & 0x1ffffff; + ERROR("esr %p %p %p\n", esr, ec, iss); + ERROR("elr = %p far = %p\n", r_elr_el1(), r_far_el1()); + ERROR("Current Task: %s.\n", cur_cpu()->task->name); panic("Unimplemented Error Occured.\n"); } panic("Return from abort handler.\n"); @@ -63,17 +68,10 @@ extern void context_switch(struct context**, struct context*); void syscall_arch_handler(struct trapframe* tf) { uint64_t ec = (r_esr_el1() >> 0x1A) & 0x3F; - w_esr_el1(0); if (ec == 0b010101) { + w_esr_el1(0); software_irq_dispatch(tf); } else { - printf("USYSCALL: unexpected ec %p", r_esr_el1()); - printf(" elr=%p far=%p\n", r_elr_el1(), r_far_el1()); - // kill error task - xizi_enter_kernel(); - assert(cur_cpu()->task == NULL); - sys_exit(cur_cpu()->task); - context_switch(&cur_cpu()->task->thread_context.context, cur_cpu()->scheduler); - panic("dabort end should never be reashed.\n"); + kernel_abort_handler(tf); } } \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/ok1028a-c/trap_common.c b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/ok1028a-c/trap_common.c index e11c01f20..620b64867 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/ok1028a-c/trap_common.c +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/ok1028a-c/trap_common.c @@ -60,16 +60,6 @@ extern uint64_t _vector_jumper; extern uint64_t _vector_start; extern uint64_t _vector_end; -// void init_cpu_mode_stacks(int cpu_id) -// { -// uint32_t modes[] = { ARM_MODE_EL0_t, ARM_MODE_EL1_t, ARM_MODE_EL2_t, ARM_MODE_EL3_t }; -// // initialize the stacks for different mode -// for (int i = 0; i < sizeof(modes) / sizeof(uint64_t); i++) { -// memset(mode_stack_pages[cpu_id][i], 0, MODE_STACK_SIZE); -// init_stack(modes[i], (uint64_t)mode_stack_pages[cpu_id][i]); -// } -// } - extern void alltraps(); static void _sys_irq_init(int cpu_id) { @@ -77,15 +67,13 @@ static void _sys_irq_init(int cpu_id) xizi_trap_driver.switch_hw_irqtbl((uintptr_t*)alltraps); if (cpu_id == 0) { - xizi_trap_driver.switch_hw_irqtbl((uintptr_t*)alltraps); gic_init(); } - gicv3inithart(); + gicv3inithart(cpu_id); } static void _cpu_irq_enable(void) { - // arm_set_interrupt_state(true); intr_on(); } diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/trampoline.S b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/trampoline.S index 573cb5bfa..90b7e431e 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/trampoline.S +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv8-a/cortex-a72/trampoline.S @@ -32,117 +32,6 @@ Modification: #include "core.h" -.global trap_irq_enter -.global trap_return -.global usertrapret -.global init_stack - -trap_return: - // Restore registers - ldp x1, x2, [sp], #16 - ldp x3, x0, [sp], #16 - msr sp_el0, x1 - msr spsr_el1, x2 - msr elr_el1, x3 - - ldp x1, x2, [sp], #16 - ldp x3, x4, [sp], #16 - ldp x5, x6, [sp], #16 - ldp x7, x8, [sp], #16 - ldp x9, x10, [sp], #16 - ldp x11, x12, [sp], #16 - ldp x13, x14, [sp], #16 - ldp x15, x16, [sp], #16 - ldp x17, x18, [sp], #16 - ldp x19, x20, [sp], #16 - ldp x21, x22, [sp], #16 - ldp x23, x24, [sp], #16 - ldp x25, x26, [sp], #16 - ldp x27, x28, [sp], #16 - ldp x29, x30, [sp], #16 - - eret - -user_trap_swi_enter: - // Save trapframe to swi stack - stp x29, x30, [sp, #-16]! - stp x27, x28, [sp, #-16]! - stp x25, x26, [sp, #-16]! - stp x23, x24, [sp, #-16]! - stp x21, x22, [sp, #-16]! - stp x19, x20, [sp, #-16]! - stp x17, x18, [sp, #-16]! - stp x15, x16, [sp, #-16]! - stp x13, x14, [sp, #-16]! - stp x11, x12, [sp, #-16]! - stp x9, x10, [sp, #-16]! - stp x7, x8, [sp, #-16]! - stp x5, x6, [sp, #-16]! - stp x3, x4, [sp, #-16]! - stp x1, x2, [sp, #-16]! - - // mrs x2, spsr_el1 - //str x2, [sp, #-8] - //str x30, [sp, #-8] - //stp sp, elr_el1, [sp, #-16]! - //str sp, [sp, #-8] - - // Call syscall handler - mov x0, sp - bl software_irq_dispatch - b trap_return - -trap_irq_enter: - // Build trapframe. - stp x29, x30, [sp, #-16]! - stp x27, x28, [sp, #-16]! - stp x25, x26, [sp, #-16]! - stp x23, x24, [sp, #-16]! - stp x21, x22, [sp, #-16]! - stp x19, x20, [sp, #-16]! - stp x17, x18, [sp, #-16]! - stp x15, x16, [sp, #-16]! - stp x13, x14, [sp, #-16]! - stp x11, x12, [sp, #-16]! - stp x9, x10, [sp, #-16]! - stp x7, x8, [sp, #-16]! - stp x5, x6, [sp, #-16]! - stp x3, x4, [sp, #-16]! - stp x1, x2, [sp, #-16]! - - mrs x3, elr_el1 - mrs x2, spsr_el1 - mrs x1, sp_el0 - stp x3, x0, [sp, #-16]! - stp x1, x2, [sp, #-16]! - - //Call trap(struct trapframe*) - mov x0, sp - bl intr_irq_dispatch - b trap_return - - - -// Help forkret to call trap_return in an expected way -//usertrapret: - // Overlay stack pointer in trap_return -// mov sp, x0 -// b trap_return - - -init_stack: - mrs x2, spsr_el1 - bic x2, x2, #SPSR_MODE_MASK - orr x2, x2, x0 - msr spsr_el1, x2 - mov sp, x1 - bic x2, x2, #SPSR_MODE_MASK - orr x2, x2, #ARM_MODE_EL1_t - msr spsr_el1, x2 - ret - -.section ".text" - .macro savereg msr daifset, #0xf // make room to save registers. @@ -197,7 +86,6 @@ init_stack: .endm .macro usavereg - msr daifset, #0xf sub sp, sp, #272 stp x0, x1, [sp, #16 * 0] @@ -298,43 +186,39 @@ el1sync: savereg mov x0, sp - bl kernel_abort_handler + bl kernel_abort_handler + b . - restorereg - - eret el1irq: savereg mov x0, sp # this should never happen by design - bl kernel_intr_handler - - restorereg - - eret + bl kernel_intr_handler + b . el0sync: + msr daifset, #0xf usavereg mov x0, sp bl syscall_arch_handler urestorereg + msr daifclr, #0xf eret + el0irq: + msr daifset, #0xf usavereg mov x0, sp bl intr_irq_dispatch -trapret: +.global trap_return +trap_return: urestorereg + msr daifclr, #0xf - eret - -.global usertrapret -usertrapret: - mov sp, x0 - b trapret + eret \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/bootmmu.c b/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/bootmmu.c index 168c558da..e18b2b4c9 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/bootmmu.c +++ b/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/bootmmu.c @@ -54,19 +54,14 @@ extern uint64_t kernel_data_begin[]; #define L3_PDE_INDEX(idx) ((idx << LEVEL3_PDE_SHIFT) & L3_IDX_MASK) uint64_t boot_l2pgdir[NUM_LEVEL2_PDE] __attribute__((aligned(0x1000))) = { 0 }; -// uint64_t boot_lowspace_l2pgdir[NUM_LEVEL2_PDE] __attribute__((aligned(0x4000))) = { 0 }; -// uint64_t boot_highspace_l2pgdir[NUM_LEVEL2_PDE] __attribute__((aligned(0x4000))) = { 0 }; uint64_t boot_dev_l3pgdir[NUM_LEVEL3_PDE] __attribute__((aligned(0x1000))) = { 0 }; -// uint64_t boot_identical_dev_l3pgdir[NUM_LEVEL3_PDE] __attribute__((aligned(0x4000))) = { 0 }; uint64_t boot_virt_dev_l3pgdir[NUM_LEVEL3_PDE] __attribute__((aligned(0x1000))) = { 0 }; uint64_t boot_kern_l3pgdir[NUM_LEVEL3_PDE] __attribute__((aligned(0x1000))) = { 0 }; -// uint64_t boot_identical_kern_l3pgdir[NUM_LEVEL3_PDE] __attribute__((aligned(0x4000))) = { 0 }; uint64_t boot_virt_kern_l3pgdir[NUM_LEVEL3_PDE] __attribute__((aligned(0x1000))) = { 0 }; uint64_t boot_dev_l4pgdirs[NUM_LEVEL3_PDE][NUM_LEVEL4_PTE] __attribute__((aligned(0x1000))) = { 0 }; uint64_t boot_kern_l4pgdirs[NUM_LEVEL3_PDE][NUM_LEVEL4_PTE] __attribute__((aligned(0x1000))) = { 0 }; -// uint64_t boot_mem_l4pgdirs[NUM_LEVEL3_PDE][NUM_LEVEL4_PTE] __attribute__((aligned(0x1000))) = { 0 }; static void build_boot_pgdir() { @@ -74,37 +69,25 @@ static void build_boot_pgdir() // dev mem boot_l2pgdir[(dev_phy_mem_base >> LEVEL2_PDE_SHIFT) & IDX_MASK] = (uint64_t)boot_dev_l3pgdir | L2_TYPE_TAB | L2_PTE_VALID; boot_l2pgdir[(MMIO_P2V_WO(dev_phy_mem_base) >> LEVEL2_PDE_SHIFT) & IDX_MASK] = (uint64_t)boot_dev_l3pgdir | L2_TYPE_TAB | L2_PTE_VALID; - // boot_lowspace_l2pgdir[(dev_phy_mem_base >> LEVEL2_PDE_SHIFT) & IDX_MASK] = (uint64_t)boot_identical_dev_l3pgdir | L2_TYPE_TAB | L2_PTE_VALID; - // boot_highspace_l2pgdir[(MMIO_P2V_WO(dev_phy_mem_base) >> LEVEL2_PDE_SHIFT) & IDX_MASK] = (uint64_t)boot_identical_dev_l3pgdir | L2_TYPE_TAB | L2_PTE_VALID; uint64_t cur_mem_paddr = (uint64_t)DEV_PHYMEM_BASE & ((uint64_t)IDX_MASK << (uint64_t)LEVEL2_PDE_SHIFT); for (size_t i = 0; i < NUM_LEVEL3_PDE; i++) { boot_dev_l3pgdir[i] = (uint64_t)boot_dev_l4pgdirs[i] | L3_TYPE_TAB | L3_PTE_VALID; - // boot_identical_dev_l3pgdir[i] = (uint64_t)boot_dev_l4pgdirs[i] | L3_TYPE_TAB | L3_PTE_VALID; - // boot_virt_dev_l3pgdir[i] = (uint64_t)boot_dev_l4pgdirs[i] | L3_TYPE_TAB | L3_PTE_VALID; for (size_t j = 0; j < NUM_LEVEL4_PTE; j++) { - // boot_dev_l4pgdirs[i][j] = dev_phy_mem_base | L4_TYPE_PAGE | L4_PTE_DEV | L4_PTE_AF; boot_dev_l4pgdirs[i][j] = cur_mem_paddr | L4_TYPE_PAGE | L4_PTE_DEV | L4_PTE_AF; - // dev_phy_mem_base += PAGE_SIZE; cur_mem_paddr += PAGE_SIZE; } } // identical mem - // uint64_t phy_mem_base = PHY_MEM_BASE; boot_l2pgdir[(PHY_MEM_BASE >> LEVEL2_PDE_SHIFT) & IDX_MASK] = (uint64_t)boot_kern_l3pgdir | L2_TYPE_TAB | L2_PTE_VALID; boot_l2pgdir[(P2V_WO(PHY_MEM_BASE) >> LEVEL2_PDE_SHIFT) & IDX_MASK] = (uint64_t)boot_kern_l3pgdir | L2_TYPE_TAB | L2_PTE_VALID; - // boot_lowspace_l2pgdir[(PHY_MEM_BASE >> LEVEL2_PDE_SHIFT) & IDX_MASK] = (uint64_t)boot_identical_kern_l3pgdir | L2_TYPE_TAB | L2_PTE_VALID; - // boot_highspace_l2pgdir[(KERN_MEM_BASE >> LEVEL2_PDE_SHIFT) & IDX_MASK] = (uint64_t)boot_identical_kern_l3pgdir | L2_TYPE_TAB | L2_PTE_VALID; cur_mem_paddr = (uint64_t)PHY_MEM_BASE & ((uint64_t)IDX_MASK << (uint64_t)LEVEL2_PDE_SHIFT); for (size_t i = 0; i < NUM_LEVEL3_PDE; i++) { boot_kern_l3pgdir[i] = (uint64_t)boot_kern_l4pgdirs[i] | L3_TYPE_TAB | L3_PTE_VALID; - // boot_identical_kern_l3pgdir[i] = (uint64_t)boot_kern_l4pgdirs[i] | L3_TYPE_TAB | L3_PTE_VALID; - // boot_kern_l3pgdir[i] = (uint64_t)boot_kern_l4pgdirs[i] | L3_TYPE_TAB | L3_PTE_VALID; - // boot_virt_kern_l3pgdir[i] = (uint64_t)boot_kern_l4pgdirs[i] | L3_TYPE_TAB | L3_PTE_VALID; for (size_t j = 0; j < NUM_LEVEL4_PTE; j++) { boot_kern_l4pgdirs[i][j] = cur_mem_paddr | L4_TYPE_PAGE | L4_PTE_AF; @@ -112,34 +95,12 @@ static void build_boot_pgdir() cur_mem_paddr += PAGE_SIZE; } } - - // dev mem - // uint64_t dev_mem_end_pgd = PGD_INDEX(DEV_PHYMEM_BASE + DEV_MEM_SZ); - // for (uint64_t i = PGD_INDEX(DEV_PHYMEM_BASE); i < dev_mem_end_idx; i++) { - // boot_pgdir[i] = (uint64_t)boot_dev_l3dir[used_boot_dev_l3dir_idx] | L3_TYPE_SEC | L3_SECT_DEV | L3_SECT_AP0; - // boot_pgdir[PGD_INDEX(MMIO_P2V_WO(PGD_INDEX_TO_PA(i)))] = (uint64_t)boot_dev_l3dir[used_boot_dev_l3dir_idx] | L3_TYPE_SEC | L3_SECT_DEV | L3_SECT_AP0; - // used_boot_dev_l3dir_idx++; - - // for (int64_t j = 0; j < 0b111111111; j++) { - // boot_dev_l3dir[i][j] = (uint64_t)boot_dev_l4dir[used_boot_dev_l4dir_idx] | (); - // // uint64_t dev_mem_end_pmd = PMD_INDEX(DEV_PHYMEM_BASE + DEV_MEM_SZ); - // // for (uint64_t j = PMD_INDEX(DEV_PHYMEM_BASE); j < dev_mem_end_pmd; j++) { - // // boot_pmd[j] = PGD_INDEX_TO_PA(j) | L4_TYPE_SEC | L4_SECT_DEV | L4_SECT_AP0; - // // boot_pmd[PGD_INDEX(MMIO_P2V_WO(PGD_INDEX_TO_PA(j)))] = PGD_INDEX_TO_PA(j) | L4_TYPE_SEC | L4_SECT_DEV | L4_SECT_AP0; - // // } - // for (uint64_t k = 0; k < 0b111111111; k++) { - // boot_dev_l4dir[j][k] = DEV_PHYMEM_BASE - // } - // } - // } } static void load_boot_pgdir() { uint64_t val; - // TTBR0_W((uintptr_t)boot_lowspace_l2pgdir); - // TTBR1_W((uintptr_t)boot_highspace_l2pgdir); TTBR0_W((uintptr_t)boot_l2pgdir); TTBR1_W(0); @@ -167,7 +128,6 @@ void bootmain() __asm__ __volatile__("add sp, sp, %0" ::"r"(KERN_MEM_BASE - PHY_MEM_BASE)); if (!_bss_inited) { memset(&kernel_data_begin, 0x00, (size_t)((uint64_t)kernel_data_end - (uint64_t)kernel_data_begin)); - uintptr_t kde = (uintptr_t)kernel_data_end; _bss_inited = true; } main(); diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/include/mmu.h b/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/include/mmu.h index f5d20847b..e68042bc1 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/include/mmu.h +++ b/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/include/mmu.h @@ -31,7 +31,6 @@ Modification: #include #include "memlayout.h" -#include "page_table_entry.h" // #define TCR_SH1_INNER (0b11 << 28) // #define TCR_ORGN1_IRGN1_WRITEBACK_WRITEALLOC ((0b01 << 26) | (0b01 << 24)) diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/include/page_table_entry.h b/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/include/page_table_entry.h deleted file mode 100644 index 2742e3452..000000000 --- a/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/include/page_table_entry.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2008-2012, Freescale Semiconductor, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * o Redistributions of source code must retain the above copyright notice, this list - * of conditions and the following disclaimer. - * - * o Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * o Neither the name of Freescale Semiconductor, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * @file page_table_entry.h - * @brief mmu related configure and registers - * @version 1.0 - * @author AIIT XUOS Lab - * @date 2024-04-25 - */ - -/************************************************* -File name: page_table_entry.h -Description: mmu related configure and registers -Others: take imx_platform_sdk sdk/core/src/mmu.c for references - https://github.com/flit/imx6_platform_sdk -History: -Author: AIIT XUOS Lab -Modification: -1. modify the L1-level page table name and properties name to apply hardkernel implementation -*************************************************/ -#pragma once - -#include - -typedef union { - uintptr_t entry; - struct { - uint64_t desc_type : 2; // (Invalid, PageTable, Section, SuperSection)/(Invalid, Table, Block) - //uint64_t B : 1; // Bufferable - // uint64_t C : 1; // Cacheable - uint64_t XN : 1; // Execute-not - //uint64_t Domain : 4; // Domain - uint64_t _impl_defined : 1; // Implementation defined, should be zero. - uint64_t AP1_0 : 2; // Access permissions AP - uint64_t TEX : 3; // TEX remap ==attr_idx The memory type, Device or Normal. - uint64_t AP2 : 1; // Access permissions AP[2] - uint64_t S : 1; // Shareable - uint64_t NG : 1; // Not-global - uint64_t _zero : 1; // Should be zero. - uint64_t NS : 1; // Non-secure - uint64_t section_addr :36 ; // Section Physical base address - uint64_t AF : 1; // Access flag - }; -} __attribute__((packed)) PageDirEntry; - -typedef union { - uint64_t entry; - struct { - uint64_t desc_type : 2; // (Invalid, Reserved,4kb, 16kb 64kb ) - // uint64_t B : 1; // Bufferable - //uint64_t C : 1; // Cacheable - uint64_t AP1_0 : 2;//Access permissions - uint64_t TEX : 3;//TEX remap ==attr_idx The memory type, Device or Normal. - uint64_t AP2 : 1; - uint64_t S : 1; // Shareable - uint64_t NG : 1; // Not-global - uint64_t page_addr :36 ; - uint64_t AF : 1; // Access flag - }; -} __attribute__((packed)) PageTblEntry; diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/mmu.c b/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/mmu.c index b97ac5a82..336d074e6 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/mmu.c +++ b/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/mmu.c @@ -41,13 +41,13 @@ static struct MmuDriverRightGroup right_group; void load_pgdir(uintptr_t pgdir_paddr) { /* get cache driver */ - // struct ICacheDone* p_icache_done = AchieveResource(&right_group.icache_driver_tag); - // struct DCacheDone* p_dcache_done = AchieveResource(&right_group.dcache_driver_tag); + struct ICacheDone* p_icache_done = AchieveResource(&right_group.icache_driver_tag); + struct DCacheDone* p_dcache_done = AchieveResource(&right_group.dcache_driver_tag); TTBR0_W((uint64_t)pgdir_paddr); CLEARTLB(0); - // p_icache_done->invalidateall(); - // p_dcache_done->flushall(); + p_icache_done->invalidateall(); + p_dcache_done->flushall(); } __attribute__((always_inline)) inline static void _tlb_flush(uintptr_t va) diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/ok1028a-c/memlayout.h b/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/ok1028a-c/memlayout.h index a385e6181..46c5074e6 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/ok1028a-c/memlayout.h +++ b/Ubiquitous/XiZi_AIoT/hardkernel/mmu/arm/armv8-a/cortex-a72/ok1028a-c/memlayout.h @@ -82,7 +82,4 @@ Modification: #define V2P_WO(x) ((x) - KERN_OFFSET) // same as V2P, but without casts #define P2V_WO(x) ((x) + KERN_OFFSET) // same as P2V, but without casts - -#define TIMER0_IRQ 27 - // clang-format on \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/services/Makefile b/Ubiquitous/XiZi_AIoT/services/Makefile index 640d3cbaa..02fc50759 100644 --- a/Ubiquitous/XiZi_AIoT/services/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/Makefile @@ -1,5 +1,4 @@ -SRC_DIR := -# SRC_DIR := fs shell lib boards tools app +SRC_DIR := fs shell lib boards semaphore drivers tools app include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_AIoT/services/app/Makefile b/Ubiquitous/XiZi_AIoT/services/app/Makefile index f3c003c85..fa47dbd09 100644 --- a/Ubiquitous/XiZi_AIoT/services/app/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/app/Makefile @@ -10,6 +10,12 @@ cflags = -std=c11 -O2 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs - board_specs = stub.o #cflags = -Wall -g -std=c11 endif +ifeq ($(BOARD), ok1028a-c) +toolchain ?= aarch64-none-elf- +user_ldflags = -N -Ttext 0 +cflags = -Wall -g -std=c11 -mtune=cortex-a72 -ffreestanding -fno-common -fno-stack-protector -fno-pie -no-pie -nostdlib -static -fno-builtin -nodefaultlibs -Wno-unused +board_specs = stub.o +endif cc = ${toolchain}gcc ld = ${toolchain}g++ @@ -29,7 +35,7 @@ INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell \ ifeq ($(BOARD), imx6q-sabrelite) all: init test_fault simple_client simple_server shell fs_server semaphore_server test_ipc_null test_thread test_irq_hdlr test_irq_block test_irq_send eth_driver epit_server readme.txt | bin else -all: init test_fault simple_client simple_server shell fs_server test_irq_hdlr readme.txt | bin +all: init test_fault simple_client simple_server shell fs_server readme.txt | bin endif ../tools/mkfs/mkfs ./fs.img $^ @mv $(filter-out readme.txt, $^) bin diff --git a/Ubiquitous/XiZi_AIoT/services/app/shell_port.c b/Ubiquitous/XiZi_AIoT/services/app/shell_port.c index ce2453519..785ad8b6e 100644 --- a/Ubiquitous/XiZi_AIoT/services/app/shell_port.c +++ b/Ubiquitous/XiZi_AIoT/services/app/shell_port.c @@ -56,10 +56,10 @@ int main(void) printf("session connect faield\n"); return -1; } - shellTask(&shell); free_session(&session_fs); + exit(0); return 0; } diff --git a/Ubiquitous/XiZi_AIoT/services/app/simple_server.c b/Ubiquitous/XiZi_AIoT/services/app/simple_server.c index 0a2ba417c..2ae2d9e12 100755 --- a/Ubiquitous/XiZi_AIoT/services/app/simple_server.c +++ b/Ubiquitous/XiZi_AIoT/services/app/simple_server.c @@ -44,4 +44,5 @@ int main(int argc, char* argv[]) // never reached exit(0); + return 0; } diff --git a/Ubiquitous/XiZi_AIoT/services/app/test_irq_handler.c b/Ubiquitous/XiZi_AIoT/services/app/test_irq_handler.c index 60e97b726..c7836afa9 100644 --- a/Ubiquitous/XiZi_AIoT/services/app/test_irq_handler.c +++ b/Ubiquitous/XiZi_AIoT/services/app/test_irq_handler.c @@ -52,4 +52,5 @@ int main() ipc_server_loop(&IpcSwIntrHandler); exit(0); + return 0; } \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/services/boards/imx6q-sabrelite/Makefile b/Ubiquitous/XiZi_AIoT/services/boards/imx6q-sabrelite/Makefile index 4d66a2163..54bf014fb 100644 --- a/Ubiquitous/XiZi_AIoT/services/boards/imx6q-sabrelite/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/boards/imx6q-sabrelite/Makefile @@ -1,15 +1,23 @@ ifeq ($(BOARD), imx6q-sabrelite) toolchain ?= arm-none-eabi- +user_ldflags = -N -Ttext 0 +cflags = -march=armv7-a -std=c11 -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie endif ifeq ($(BOARD), zynq7000-zc702) toolchain ?= arm-xilinx-eabi- +user_ldflags = -N -Ttext 0 +cflags = -march=armv7-a -std=c11 -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie endif +ifeq ($(BOARD), ok1028a-c) +toolchain ?= aarch64-none-elf- +user_ldflags = -N -Ttext 0 +cflags = -Wall -g -std=c11 -mtune=cortex-a72 -ffreestanding -fno-common -fno-stack-protector -fno-pie -no-pie -nostdlib -static -fno-builtin -nodefaultlibs -Wno-unused +endif + cc = ${toolchain}gcc ld = ${toolchain}g++ objdump = ${toolchain}objdump -user_ldflags = -N -Ttext 0 -cflags = -march=armv7-a -std=c11 -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie c_useropts = -O2 INC_DIR = -I$(KERNEL_ROOT)/services/fs/libfs \ diff --git a/Ubiquitous/XiZi_AIoT/services/boards/ok1028a-c/Makefile b/Ubiquitous/XiZi_AIoT/services/boards/ok1028a-c/Makefile new file mode 100644 index 000000000..7dae63969 --- /dev/null +++ b/Ubiquitous/XiZi_AIoT/services/boards/ok1028a-c/Makefile @@ -0,0 +1,38 @@ +ifeq ($(BOARD), imx6q-sabrelite) +toolchain ?= arm-none-eabi- +user_ldflags = -N -Ttext 0 +cflags = -march=armv7-a -std=c11 -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie +endif +ifeq ($(BOARD), zynq7000-zc702) +toolchain ?= arm-xilinx-eabi- +user_ldflags = -N -Ttext 0 +cflags = -march=armv7-a -std=c11 -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie +endif +ifeq ($(BOARD), ok1028a-c) +toolchain ?= aarch64-none-elf- +user_ldflags = -N -Ttext 0 +cflags = -Wall -g -std=c11 -mtune=cortex-a72 -ffreestanding -fno-common -fno-stack-protector -fno-pie -no-pie -nostdlib -static -fno-builtin -nodefaultlibs -Wno-unused +endif + +cc = ${toolchain}gcc +ld = ${toolchain}g++ +objdump = ${toolchain}objdump + +c_useropts = -O2 + +INC_DIR = -I$(KERNEL_ROOT)/services/fs/libfs \ + -I$(KERNEL_ROOT)/services/lib/ipc \ + -I$(KERNEL_ROOT)/services/lib/memory \ + -I$(KERNEL_ROOT)/services/lib/serial \ + -I$(KERNEL_ROOT)/services/lib/usyscall \ + -I$(KERNEL_ROOT)/services/boards/$(BOARD) \ + -I$(KERNEL_ROOT)/services/app + +board: libserial.o arch_usyscall.o stub.o + @mv $^ $(KERNEL_ROOT)/services/app + +%.o: %.c + @echo "cc $^" + @${cc} ${cflags} ${c_useropts} ${INC_DIR} -o $@ -c $^ + +include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_AIoT/services/boards/ok1028a-c/arch_usyscall.c b/Ubiquitous/XiZi_AIoT/services/boards/ok1028a-c/arch_usyscall.c new file mode 100644 index 000000000..cd1bf7b40 --- /dev/null +++ b/Ubiquitous/XiZi_AIoT/services/boards/ok1028a-c/arch_usyscall.c @@ -0,0 +1,33 @@ +/* + * 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. + */ +#include "usyscall.h" + +int syscall(int sys_num, intptr_t a1, intptr_t a2, intptr_t a3, intptr_t a4) +{ + int ret = -1; + + __asm__ volatile( + "mov x0, %1;\ + mov x1, %2;\ + mov x2, %3;\ + mov x3, %4;\ + mov x4, %5;\ + svc #0;\ + dsb ish;\ + isb;\ + mov %0, x0" + : "=r"(ret) + : "r"(sys_num), "r"(a1), "r"(a2), "r"(a3), "r"(a4) + : "memory", "r0", "r1", "r2", "r3", "r4"); + + return ret; +} \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/services/boards/ok1028a-c/libserial.c b/Ubiquitous/XiZi_AIoT/services/boards/ok1028a-c/libserial.c new file mode 100644 index 000000000..57cb02b86 --- /dev/null +++ b/Ubiquitous/XiZi_AIoT/services/boards/ok1028a-c/libserial.c @@ -0,0 +1,113 @@ +/* + * 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. + */ + +/// this file is only used for debug +#include "libserial.h" +#include "usyscall.h" + +#define USER_UART_BASE 0x6FFFF000 + +#define UART0_BASE (0x09000000ULL) +#define UART0_REG(reg) ((volatile uint32_t*)(USER_UART_BASE + reg)) + +// the UART control registers. +// pl011 +#define DR 0x00 +#define FR 0x18 +#define FR_RXFE (1 << 4) // recieve fifo empty +#define FR_TXFF (1 << 5) // transmit fifo full +#define FR_RXFF (1 << 6) // recieve fifo full +#define FR_TXFE (1 << 7) // transmit fifo empty +#define IBRD 0x24 +#define FBRD 0x28 +#define LCRH 0x2c +#define LCRH_FEN (1 << 4) +#define LCRH_WLEN_8BIT (3 << 5) +#define CR 0x30 +#define IMSC 0x38 +#define INT_RX_ENABLE (1 << 4) +#define INT_TX_ENABLE (1 << 5) +#define ICR 0x44 + +#define UART_READ_REG(reg) (*(UART0_REG(reg))) +#define UART_WRITE_REG(reg, v) (*(UART0_REG(reg)) = (v)) + +#define UART_TX_BUF_SIZE 32 +static char uart_tx_buf[UART_TX_BUF_SIZE]; +uint64_t uart_tx_w; // write next to uart_tx_buf[uart_tx_w % UART_TX_BUF_SIZE] +uint64_t uart_tx_r; // read next from uart_tx_buf[uart_tx_r % UART_TX_BUF_SIZE] + +bool init_uart_mmio() +{ + static int mapped = 0; + if (mapped == 0) { + if (-1 == mmap(USER_UART_BASE, UART0_BASE, 4096, true)) { + return false; + } + mapped = 1; + } + return true; +} + +// if the UART is idle, and a character is waiting +// in the transmit buffer, send it. +// caller must hold uart_tx_lock. +// called from both the top- and bottom-half. +void uartstart() +{ + while (1) { + if (uart_tx_w == uart_tx_r) { + // transmit buffer is empty. + return; + } + + if (UART_READ_REG(FR) & FR_TXFF) { + // the UART transmit holding register is full, + // so we cannot give it another byte. + // it will interrupt when it's ready for a new byte. + return; + } + + int c = uart_tx_buf[uart_tx_r % UART_TX_BUF_SIZE]; + uart_tx_r += 1; + + // maybe uartputc() is waiting for space in the buffer. + + UART_WRITE_REG(DR, c); + } +} + +// add a character to the output buffer and tell the +// UART to start sending if it isn't already. +// blocks if the output buffer is full. +// because it may block, it can't be called +// from interrupts; it's only suitable for use +// by write(). +void putc(char c) +{ + while (uart_tx_w == uart_tx_r + UART_TX_BUF_SIZE) + ; + uart_tx_buf[uart_tx_w % UART_TX_BUF_SIZE] = c; + uart_tx_w += 1; + uartstart(); + return; +} + +// read one input character from the UART. +// return -1 if none is waiting. +char getc(void) +{ + if (UART_READ_REG(FR) & FR_RXFE) + return 0xFF; + else + return UART_READ_REG(DR); +} \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/services/boards/ok1028a-c/stub.c b/Ubiquitous/XiZi_AIoT/services/boards/ok1028a-c/stub.c new file mode 100644 index 000000000..c2c3af9d4 --- /dev/null +++ b/Ubiquitous/XiZi_AIoT/services/boards/ok1028a-c/stub.c @@ -0,0 +1,91 @@ +/* + * 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. + */ + +#include +#include +#include + +// _exit: 用于退出程序 +void _exit(int status) +{ + while (1) { } +} + +// _sbrk: 用于增加程序的数据空间 +void* _sbrk(ptrdiff_t incr) +{ + extern char end; /* Defined by the linker */ + static char* heap_end; + char* prev_heap_end; + + if (heap_end == 0) { + heap_end = &end; + } + prev_heap_end = heap_end; + + // 在这里,你应该添加一些检查来确保堆不会与栈或其他内存区域冲突 + // 例如,检查 incr 是否会导致堆超出预定的内存区域 + + heap_end += incr; + return (void*)prev_heap_end; +} + +// _write: 用于将数据写入文件描述符 +ssize_t _write(int file, const void* ptr, size_t len) +{ + // 在这里,你需要实现将数据写入文件描述符的逻辑 + // 如果你的系统不支持文件系统,你可以将数据发送到串口或其他输出 + + return len; // 假设所有数据都被写入 +} + +// _close: 用于关闭文件描述符 +int _close(int file) +{ + return -1; // 表示失败,因为没有实际关闭文件的功能 +} + +// _fstat: 用于获取文件状态 +int _fstat(int file, struct stat* st) +{ + return 0; // 表示成功 +} + +// _isatty: 检查文件描述符是否指向TTY设备 +int _isatty(int file) +{ + return 1; // 表示是TTY设备 +} + +// _lseek: 用于重新定位文件读/写的位置 +off_t _lseek(int file, off_t offset, int whence) +{ + return -1; // 表示失败,因为不支持文件定位 +} + +// _read: 用于从文件描述符读取数据 +ssize_t _read(int file, void* ptr, size_t len) +{ + return 0; // 表示没有数据被读取 +} + +// _kill: 发送信号给进程 +int _kill(int pid, int sig) +{ + return -1; // 表示失败,因为不支持信号 +} + +// _getpid: 获取进程ID +int _getpid() +{ + return 1; // 返回假设的进程ID +} diff --git a/Ubiquitous/XiZi_AIoT/services/boards/zynq7000-zc702/Makefile b/Ubiquitous/XiZi_AIoT/services/boards/zynq7000-zc702/Makefile index 64cf9c5e2..e54d4cefa 100644 --- a/Ubiquitous/XiZi_AIoT/services/boards/zynq7000-zc702/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/boards/zynq7000-zc702/Makefile @@ -9,6 +9,12 @@ user_ldflags = --start-group,-lgcc,-lc,--end-group cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie #cflags = -Wall -g -std=c11 endif +ifeq ($(BOARD), ok1028a-c) +toolchain ?= aarch64-none-elf- +user_ldflags = -N -Ttext 0 +cflags = -Wall -g -std=c11 -mtune=cortex-a72 -ffreestanding -fno-common -fno-stack-protector -fno-pie -no-pie -nostdlib -static -fno-builtin -nodefaultlibs -Wno-unused +endif + cc = ${toolchain}gcc ld = ${toolchain}g++ objdump = ${toolchain}objdump diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/clock/Makefile b/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/clock/Makefile index a1c797551..bc2cc672d 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/clock/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/clock/Makefile @@ -1,15 +1,23 @@ ifeq ($(BOARD), imx6q-sabrelite) toolchain ?= arm-none-eabi- +cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie +user_ldflags = -N -Ttext 0 endif ifeq ($(BOARD), zynq7000-zc702) toolchain ?= arm-xilinx-eabi- +cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie +user_ldflags = -N -Ttext 0 +endif +ifeq ($(BOARD), ok1028a-c) +toolchain ?= aarch64-none-elf- +user_ldflags = -N -Ttext 0 +cflags = -Wall -g -std=c11 -mtune=cortex-a72 -ffreestanding -fno-common -fno-stack-protector -fno-pie -no-pie -nostdlib -static -fno-builtin -nodefaultlibs -Wno-unused endif cc = ${toolchain}gcc ld = ${toolchain}g++ objdump = ${toolchain}objdump -user_ldflags = -N -Ttext 0 -cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie + c_useropts = -O2 INC_DIR = -I$(KERNEL_ROOT)/services/app \ diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/gpio/Makefile b/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/gpio/Makefile index 0203d8bad..101f4a799 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/gpio/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/gpio/Makefile @@ -1,15 +1,23 @@ ifeq ($(BOARD), imx6q-sabrelite) toolchain ?= arm-none-eabi- +cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie +user_ldflags = -N -Ttext 0 endif ifeq ($(BOARD), zynq7000-zc702) toolchain ?= arm-xilinx-eabi- +cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie +user_ldflags = -N -Ttext 0 endif +ifeq ($(BOARD), ok1028a-c) +toolchain ?= aarch64-none-elf- +user_ldflags = -N -Ttext 0 +cflags = -Wall -g -std=c11 -mtune=cortex-a72 -ffreestanding -fno-common -fno-stack-protector -fno-pie -no-pie -nostdlib -static -fno-builtin -nodefaultlibs -Wno-unused +endif + cc = ${toolchain}gcc ld = ${toolchain}g++ objdump = ${toolchain}objdump -user_ldflags = -N -Ttext 0 -cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie c_useropts = -O2 INC_DIR = -I$(KERNEL_ROOT)/services/app \ diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/lib/Makefile b/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/lib/Makefile index d26a76275..5b751cf63 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/lib/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/lib/Makefile @@ -1,15 +1,22 @@ ifeq ($(BOARD), imx6q-sabrelite) toolchain ?= arm-none-eabi- +cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie +user_ldflags = -N -Ttext 0 endif ifeq ($(BOARD), zynq7000-zc702) toolchain ?= arm-xilinx-eabi- +cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie +user_ldflags = -N -Ttext 0 endif +ifeq ($(BOARD), ok1028a-c) +toolchain ?= aarch64-none-elf- +user_ldflags = -N -Ttext 0 +cflags = -Wall -g -std=c11 -mtune=cortex-a72 -ffreestanding -fno-common -fno-stack-protector -fno-pie -no-pie -nostdlib -static -fno-builtin -nodefaultlibs -Wno-unused +endif + cc = ${toolchain}gcc ld = ${toolchain}g++ objdump = ${toolchain}objdump -user_ldflags = -N -Ttext 0 - -cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie c_useropts = -O2 INC_DIR = -I$(KERNEL_ROOT)/services/app \ diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/ok1028a-c/Makefile b/Ubiquitous/XiZi_AIoT/services/drivers/ok1028a-c/Makefile new file mode 100644 index 000000000..b14224115 --- /dev/null +++ b/Ubiquitous/XiZi_AIoT/services/drivers/ok1028a-c/Makefile @@ -0,0 +1,3 @@ +SRC_DIR := + +include $(KERNEL_ROOT)/compiler.mk \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/services/fs/fs_server/Makefile b/Ubiquitous/XiZi_AIoT/services/fs/fs_server/Makefile index 5c15614f5..6b2d71673 100644 --- a/Ubiquitous/XiZi_AIoT/services/fs/fs_server/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/fs/fs_server/Makefile @@ -9,6 +9,12 @@ user_ldflags = --start-group,-lgcc,-lc,--end-group cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie #cflags = -Wall -g -std=c11 endif +ifeq ($(BOARD), ok1028a-c) +toolchain ?= aarch64-none-elf- +user_ldflags = -N +cflags = -Wall -g -std=c11 -mtune=cortex-a72 -ffreestanding -fno-common -fno-stack-protector -fno-pie -no-pie -nostdlib -static -fno-builtin -nodefaultlibs -Wno-unused +endif + cc = ${toolchain}gcc ld = ${toolchain}g++ objdump = ${toolchain}objdump diff --git a/Ubiquitous/XiZi_AIoT/services/fs/fs_server/block_io.c b/Ubiquitous/XiZi_AIoT/services/fs/fs_server/block_io.c index eca003213..864aeda4c 100644 --- a/Ubiquitous/XiZi_AIoT/services/fs/fs_server/block_io.c +++ b/Ubiquitous/XiZi_AIoT/services/fs/fs_server/block_io.c @@ -63,7 +63,8 @@ uint32_t BlockAlloc() } } - Error("BlockAlloc: out of blocks"); + printf("BlockAlloc: out of blocks, bit idx: %d, total size: %d\n", bit_index, sb.size); + Error(""); 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 f84e109df..3bfc42b89 100644 --- a/Ubiquitous/XiZi_AIoT/services/fs/fs_server/fs_server.c +++ b/Ubiquitous/XiZi_AIoT/services/fs/fs_server/fs_server.c @@ -63,11 +63,12 @@ int IPC_DO_SERVE_FUNC(Ipc_ls)(char* path) } if (!(ip = InodeSeek(dp, path))) { - printf("ls: find target Inode failed, ip: %x(%d), dp: %x(%d)\n", ip, ip->inum, dp, dp->inum); + printf("ls: find target Inode failed, dp: %p(%d), path: %s\n", dp, dp->inum, path); return -1; } + if (ip->type != FS_DIRECTORY) { - printf("ls: not a dir\n"); + printf("ls: not a dir, ip: %d\n", ip->inum); return -1; } @@ -364,4 +365,5 @@ int main(int argc, char* argv[]) // never reached exit(0); + return 0; } diff --git a/Ubiquitous/XiZi_AIoT/services/fs/fs_server/include/block_io.h b/Ubiquitous/XiZi_AIoT/services/fs/fs_server/include/block_io.h index 8fd07762b..f457436fd 100644 --- a/Ubiquitous/XiZi_AIoT/services/fs/fs_server/include/block_io.h +++ b/Ubiquitous/XiZi_AIoT/services/fs/fs_server/include/block_io.h @@ -24,7 +24,7 @@ #define BITS 8 // Bitmap size of one block -#define BITMAP_SIZE (BLOCK_SIZE * BITS * NR_BIT_BLOCKS) +#define BITMAP_SIZE (BLOCK_SIZE * BITS) // Inode size of one block #define INODE_SIZE (BLOCK_SIZE / sizeof(struct Inode)) diff --git a/Ubiquitous/XiZi_AIoT/services/fs/libfs/Makefile b/Ubiquitous/XiZi_AIoT/services/fs/libfs/Makefile index 69365fd69..b6a06fe88 100644 --- a/Ubiquitous/XiZi_AIoT/services/fs/libfs/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/fs/libfs/Makefile @@ -1,14 +1,19 @@ ifeq ($(BOARD), imx6q-sabrelite) toolchain ?= arm-none-eabi- +cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie user_ldflags = -N -Ttext 0 -cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie endif ifeq ($(BOARD), zynq7000-zc702) toolchain ?= arm-xilinx-eabi- -user_ldflags = --start-group,-lgcc,-lc,--end-group -cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie -#cflags = -Wall -g -std=c11 +cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie +user_ldflags = -N -Ttext 0 endif +ifeq ($(BOARD), ok1028a-c) +toolchain ?= aarch64-none-elf- +user_ldflags = -N +cflags = -Wall -g -std=c11 -mtune=cortex-a72 -ffreestanding -fno-common -fno-stack-protector -fno-pie -no-pie -nostdlib -static -fno-builtin -nodefaultlibs -Wno-unused +endif + cc = ${toolchain}gcc ld = ${toolchain}g++ objdump = ${toolchain}objdump diff --git a/Ubiquitous/XiZi_AIoT/services/lib/ipc/Makefile b/Ubiquitous/XiZi_AIoT/services/lib/ipc/Makefile index fbcfc9073..0a2c315f7 100644 --- a/Ubiquitous/XiZi_AIoT/services/lib/ipc/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/lib/ipc/Makefile @@ -9,6 +9,12 @@ user_ldflags = --start-group,-lgcc,-lc,--end-group cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie #cflags = -Wall -g -std=c11 endif +ifeq ($(BOARD), ok1028a-c) +toolchain ?= aarch64-none-elf- +user_ldflags = -N -Ttext 0 +cflags = -Wall -g -std=c11 -mtune=cortex-a72 -ffreestanding -fno-common -fno-stack-protector -fno-pie -no-pie -nostdlib -static -fno-builtin -nodefaultlibs -Wno-unused +endif + cc = ${toolchain}gcc ld = ${toolchain}g++ objdump = ${toolchain}objdump diff --git a/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.c b/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.c index 83a6e2cfe..7fdb4506d 100644 --- a/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.c +++ b/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.c @@ -79,7 +79,7 @@ struct IpcMsg* new_ipc_msg(struct Session* session, const int argc, const int* a bool ipc_msg_set_nth_arg(struct IpcMsg* msg, const int arg_num, const void* const data, const int len) { if (arg_num >= msg->header.nr_args) { - printf("[%s] IPC: arg_num out of msg range, arg_num: %d, nr_args: %lu\n", __func__, arg_num, msg->header.nr_args); + printf("[%s] IPC: arg_num out of msg range, arg_num: %d, nr_args: %u\n", __func__, arg_num, msg->header.nr_args); return false; } struct IpcArgInfo* nth_arg_info = IPCMSG_ARG_INFO(msg, arg_num); diff --git a/Ubiquitous/XiZi_AIoT/services/lib/memory/Makefile b/Ubiquitous/XiZi_AIoT/services/lib/memory/Makefile index bc5bcdd18..811b23061 100644 --- a/Ubiquitous/XiZi_AIoT/services/lib/memory/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/lib/memory/Makefile @@ -1,15 +1,23 @@ ifeq ($(BOARD), imx6q-sabrelite) toolchain ?= arm-none-eabi- +cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie +user_ldflags = -N -Ttext 0 endif ifeq ($(BOARD), zynq7000-zc702) toolchain ?= arm-xilinx-eabi- +cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie +user_ldflags = -N -Ttext 0 endif +ifeq ($(BOARD), ok1028a-c) +toolchain ?= aarch64-none-elf- +user_ldflags = -N -Ttext 0 +cflags = -Wall -g -std=c11 -mtune=cortex-a72 -ffreestanding -fno-common -fno-stack-protector -fno-pie -no-pie -nostdlib -static -fno-builtin -nodefaultlibs -Wno-unused +endif + cc = ${toolchain}gcc ld = ${toolchain}g++ objdump = ${toolchain}objdump -user_ldflags = -N -Ttext 0 -cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie c_useropts = -O2 INC_DIR = -I$(KERNEL_ROOT)/services/app \ diff --git a/Ubiquitous/XiZi_AIoT/services/lib/memory/libmem.c b/Ubiquitous/XiZi_AIoT/services/lib/memory/libmem.c index feb746b5f..6df9eddc6 100644 --- a/Ubiquitous/XiZi_AIoT/services/lib/memory/libmem.c +++ b/Ubiquitous/XiZi_AIoT/services/lib/memory/libmem.c @@ -41,7 +41,7 @@ #define PUT_NOTAG(p, val) (*(unsigned int*)(p) = (val)) // Store predecessor or successor pointer for free blocks -#define SET_PTR(p, ptr) (*(unsigned int*)(p) = (unsigned int)(ptr)) +#define SET_PTR(p, ptr) (*(uintptr_t*)(p) = (uintptr_t)(ptr)) // Read the size and allocation bit from address p #define GET_SIZE(p) (GET(p) & ~0x7) diff --git a/Ubiquitous/XiZi_AIoT/services/lib/serial/Makefile b/Ubiquitous/XiZi_AIoT/services/lib/serial/Makefile index ababb7389..4c19c8422 100644 --- a/Ubiquitous/XiZi_AIoT/services/lib/serial/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/lib/serial/Makefile @@ -1,15 +1,24 @@ ifeq ($(BOARD), imx6q-sabrelite) toolchain ?= arm-none-eabi- +cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie +user_ldflags = -N -Ttext 0 endif ifeq ($(BOARD), zynq7000-zc702) toolchain ?= arm-xilinx-eabi- +cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie +user_ldflags = -N -Ttext 0 endif +ifeq ($(BOARD), ok1028a-c) +toolchain ?= aarch64-none-elf- +user_ldflags = -N -Ttext 0 +cflags = -Wall -g -std=c11 -mtune=cortex-a72 -ffreestanding -fno-common -fno-stack-protector -fno-pie -no-pie -nostdlib -static -fno-builtin -nodefaultlibs -Wno-unused +endif + cc = ${toolchain}gcc ld = ${toolchain}g++ objdump = ${toolchain}objdump -user_ldflags = -N -Ttext 0 -cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie + c_useropts = -O2 INC_DIR = -I$(KERNEL_ROOT)/services/app \ diff --git a/Ubiquitous/XiZi_AIoT/services/lib/usyscall/Makefile b/Ubiquitous/XiZi_AIoT/services/lib/usyscall/Makefile index 71972c252..39f64140e 100644 --- a/Ubiquitous/XiZi_AIoT/services/lib/usyscall/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/lib/usyscall/Makefile @@ -1,15 +1,22 @@ ifeq ($(BOARD), imx6q-sabrelite) toolchain ?= arm-none-eabi- +cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie +user_ldflags = -N -Ttext 0 endif ifeq ($(BOARD), zynq7000-zc702) toolchain ?= arm-xilinx-eabi- +cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie +user_ldflags = -N -Ttext 0 endif +ifeq ($(BOARD), ok1028a-c) +toolchain ?= aarch64-none-elf- +user_ldflags = -N -Ttext 0 +cflags = -Wall -g -std=c11 -mtune=cortex-a72 -ffreestanding -fno-common -fno-stack-protector -fno-pie -no-pie -nostdlib -static -fno-builtin -nodefaultlibs -Wno-unused +endif + cc = ${toolchain}gcc ld = ${toolchain}g++ objdump = ${toolchain}objdump -user_ldflags = -N -Ttext 0 - -cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie c_useropts = -O2 INC_DIR = -I$(KERNEL_ROOT)/services/app \ diff --git a/Ubiquitous/XiZi_AIoT/services/semaphore/Makefile b/Ubiquitous/XiZi_AIoT/services/semaphore/Makefile index 9a1651097..7aaa281e2 100644 --- a/Ubiquitous/XiZi_AIoT/services/semaphore/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/semaphore/Makefile @@ -9,6 +9,12 @@ user_ldflags = --start-group,-lgcc,-lc,--end-group cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie #cflags = -Wall -g -std=c11 endif +ifeq ($(BOARD), ok1028a-c) +toolchain ?= aarch64-none-elf- +user_ldflags = -N -Ttext 0 +cflags = -Wall -g -std=c11 -mtune=cortex-a72 -ffreestanding -fno-common -fno-stack-protector -fno-pie -no-pie -nostdlib -static -fno-builtin -nodefaultlibs -Wno-unused +endif + cc = ${toolchain}gcc ld = ${toolchain}g++ objdump = ${toolchain}objdump diff --git a/Ubiquitous/XiZi_AIoT/services/shell/letter-shell/Makefile b/Ubiquitous/XiZi_AIoT/services/shell/letter-shell/Makefile index 7a195298f..f9781be81 100644 --- a/Ubiquitous/XiZi_AIoT/services/shell/letter-shell/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/shell/letter-shell/Makefile @@ -1,14 +1,19 @@ ifeq ($(BOARD), imx6q-sabrelite) toolchain ?= arm-none-eabi- +cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie user_ldflags = -N -Ttext 0 -cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie endif ifeq ($(BOARD), zynq7000-zc702) toolchain ?= arm-xilinx-eabi- -user_ldflags = --start-group,-lgcc,-lc,--end-group -cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie -#cflags = -Wall -g -std=c11 -Wno-unused +cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie +user_ldflags = -N -Ttext 0 endif +ifeq ($(BOARD), ok1028a-c) +toolchain ?= aarch64-none-elf- +user_ldflags = -N -Ttext 0 +cflags = -Wall -g -std=c11 -mtune=cortex-a72 -ffreestanding -fno-common -fno-stack-protector -fno-pie -no-pie -nostdlib -static -fno-builtin -nodefaultlibs -Wno-unused +endif + cc = ${toolchain}gcc ld = ${toolchain}g++ objdump = ${toolchain}objdump diff --git a/Ubiquitous/XiZi_AIoT/services/shell/letter-shell/shell.c b/Ubiquitous/XiZi_AIoT/services/shell/letter-shell/shell.c index 5813d3b37..34b99616e 100644 --- a/Ubiquitous/XiZi_AIoT/services/shell/letter-shell/shell.c +++ b/Ubiquitous/XiZi_AIoT/services/shell/letter-shell/shell.c @@ -1735,7 +1735,7 @@ void shellKill(int pid) */ void shellLs(const char* path, ...) { - if (*path == '\0') { + if ((uintptr_t*)path == (uintptr_t*)shellLs || *path == '\0') { path = "."; } ls(&session_fs, (char*)path); diff --git a/Ubiquitous/XiZi_AIoT/services/shell/letter-shell/shell_ext.c b/Ubiquitous/XiZi_AIoT/services/shell/letter-shell/shell_ext.c index c8158e769..804058755 100644 --- a/Ubiquitous/XiZi_AIoT/services/shell/letter-shell/shell_ext.c +++ b/Ubiquitous/XiZi_AIoT/services/shell/letter-shell/shell_ext.c @@ -8,6 +8,8 @@ * @copyright (c) 2019 Letter * */ +#include +#include #include "shell_ext.h" #include "shell.h" @@ -251,7 +253,7 @@ unsigned int shellExtParsePara(Shell* shell, char* string) */ int shellExtRun(Shell* shell, ShellCommand* command, int argc, char* argv[]) { - unsigned int params[8] = { 0 }; + uintptr_t params[8] = { 0 }; int paramNum = command->attr.attrs.paramNum > (argc - 1) ? command->attr.attrs.paramNum : (argc - 1); for (int i = 0; i < argc - 1; i++) { params[i] = shellExtParsePara(shell, argv[i + 1]); diff --git a/Ubiquitous/XiZi_AIoT/services/tools/mkfs/mkfs.c b/Ubiquitous/XiZi_AIoT/services/tools/mkfs/mkfs.c index 027d9dd5c..d76cc62f0 100755 --- a/Ubiquitous/XiZi_AIoT/services/tools/mkfs/mkfs.c +++ b/Ubiquitous/XiZi_AIoT/services/tools/mkfs/mkfs.c @@ -263,8 +263,8 @@ void balloc(int used) uchar buf[BLOCK_SIZE]; int i; printf("balloc: first %d blocks have been allocated\n", used); - bzero(buf, BLOCK_SIZE); for (int bmsec = 0; bmsec < bitblocks; bmsec++) { + bzero(buf, BLOCK_SIZE); for (i = 0; i < ((used > NR_BIT_PER_BYTE * BLOCK_SIZE) ? NR_BIT_PER_BYTE * BLOCK_SIZE : used); i++) { buf[i / NR_BIT_PER_BYTE] = buf[i / NR_BIT_PER_BYTE] | (0x1 << (i % NR_BIT_PER_BYTE)); } diff --git a/Ubiquitous/XiZi_AIoT/softkernel/load_apps.S b/Ubiquitous/XiZi_AIoT/softkernel/load_apps.S index 5316df458..71d5278bd 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/load_apps.S +++ b/Ubiquitous/XiZi_AIoT/softkernel/load_apps.S @@ -28,18 +28,18 @@ Modification: 1. first version *************************************************/ .section .rawdata_fs_img -# .globl user_apps -# user_apps: -# .incbin "../services/app/fs.img" +.globl user_apps +user_apps: + .incbin "../services/app/fs.img" -# .section .rawdata_init -# .globl initapp -# initapp: -# .incbin "../services/app/bin/init" +.section .rawdata_init +.globl initapp +initapp: + .incbin "../services/app/bin/init" -# .section .rawdata_memfs -# .globl memfs -# memfs: -# .incbin "../services/app/bin/fs_server" +.section .rawdata_memfs +.globl memfs +memfs: + .incbin "../services/app/bin/fs_server" .end diff --git a/Ubiquitous/XiZi_AIoT/softkernel/memory/pagetable_level3.c b/Ubiquitous/XiZi_AIoT/softkernel/memory/pagetable_level3.c index 8105d30b7..f0795177f 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/memory/pagetable_level3.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/memory/pagetable_level3.c @@ -48,8 +48,8 @@ uintptr_t* _page_walk(uintptr_t* pgdir, uintptr_t vaddr, bool alloc) uintptr_t* l3_pde_vaddr; if (*l2_pde_ptr != 0) { - uintptr_t l3_pde_paddr = (*l2_pde_ptr) & ~pde_attr; - l3_pde_vaddr = (uintptr_t*)P2V(l3_pde_paddr); + uintptr_t l3_table_paddr = (*l2_pde_ptr) & ~pde_attr; + l3_pde_vaddr = (uintptr_t*)P2V(l3_table_paddr); } else { if (!alloc || !(l3_pde_vaddr = (uintptr_t*)kalloc(sizeof(uintptr_t) * NUM_LEVEL3_PDE))) { return NULL; @@ -63,8 +63,8 @@ uintptr_t* _page_walk(uintptr_t* pgdir, uintptr_t vaddr, bool alloc) uintptr_t* l4_pte_vaddr; if (*l3_pde_ptr != 0) { - uintptr_t l4_pte_paddr = (*l3_pde_ptr) & ~pde_attr; - l4_pte_vaddr = (uintptr_t*)P2V(l4_pte_paddr); + uintptr_t l4_table_paddr = (*l3_pde_ptr) & ~pde_attr; + l4_pte_vaddr = (uintptr_t*)P2V(l4_table_paddr); } else { if (!alloc || !(l4_pte_vaddr = (uintptr_t*)kalloc(sizeof(uintptr_t) * NUM_LEVEL4_PTE))) { return NULL; @@ -79,38 +79,44 @@ uintptr_t* _page_walk(uintptr_t* pgdir, uintptr_t vaddr, bool alloc) void _free_user_pgdir(struct TopLevelPageDirectory* pgdir) { - // uintptr_t low_bound = kern_virtmem_buddy.mem_start, high_bound = kern_virtmem_buddy.mem_end; - // uintptr_t user_low_bound = user_phy_freemem_buddy.mem_start, user_high_bound = user_phy_freemem_buddy.mem_end; - // uintptr_t end_idx = (USER_MEM_TOP >> LEVEL2_PDE_SHIFT) & (NUM_LEVEL2_PDE - 1); + if (pgdir->pd_addr == NULL) { + return; + } - // for (uintptr_t l3_entry_idx = 0; l3_entry_idx < end_idx; l3_entry_idx++) { - // // free each level3 page table - // uintptr_t* l3_pde_paddr = (uintptr_t*)LEVEL3_PDE_ADDR(pgdir->pd_addr[l3_entry_idx]); - // if (l3_pde_paddr != NULL) { - // for (uintptr_t l4_entry_idx = 0; l4_entry_idx < NUM_LEVEL3_PDE; l4_entry_idx++) { - // uintptr_t* l4_pte_paddr = (uintptr_t*)LEVEL4_PTE_ADDR(l3_pde_paddr[l4_entry_idx]); - // if (l4_pte_paddr != NULL) { - // for (uintptr_t page_entry_idx = 0; page_entry_idx < NUM_LEVEL4_PTE; page_entry_idx++) { - // uintptr_t vaddr = (l3_entry_idx << LEVEL2_PDE_SHIFT) | (l4_entry_idx << LEVEL3_PDE_SHIFT) | (page_entry_idx << LEVEL4_PTE_SHIFT); + uintptr_t low_bound = kern_virtmem_buddy.mem_start, high_bound = kern_virtmem_buddy.mem_end; + uintptr_t user_low_bound = user_phy_freemem_buddy.mem_start, user_high_bound = user_phy_freemem_buddy.mem_end; + uintptr_t end_idx = (USER_MEM_TOP >> LEVEL2_PDE_SHIFT) & (NUM_LEVEL2_PDE - 1); - // // get page paddr - // uintptr_t* page_paddr = (uintptr_t*)ALIGNDOWN(((uintptr_t*)P2V(l4_pte_paddr))[page_entry_idx], PAGE_SIZE); - // if (page_paddr != NULL) { - // // Ensure the virtual address is not in the IPC address space - // assert(vaddr < USER_IPC_SPACE_BASE || vaddr >= USER_IPC_SPACE_TOP); + for (uintptr_t l2_entry_idx = 0; l2_entry_idx < end_idx; l2_entry_idx++) { + // free each level3 page table + uintptr_t* l3_table_paddr = (uintptr_t*)ALIGNDOWN(pgdir->pd_addr[l2_entry_idx], PAGE_SIZE); + if (l3_table_paddr != NULL) { + uintptr_t* l3_table_vaddr = P2V(l3_table_paddr); + for (uintptr_t l3_entry_idx = 0; l3_entry_idx < NUM_LEVEL3_PDE; l3_entry_idx++) { + uintptr_t* l4_table_paddr = (uintptr_t*)LEVEL4_PTE_ADDR(l3_table_vaddr[l3_entry_idx]); + if (l4_table_paddr != NULL) { + uintptr_t* l4_table_vaddr = P2V(l4_table_paddr); + for (uintptr_t page_entry_idx = 0; page_entry_idx < NUM_LEVEL4_PTE; page_entry_idx++) { + uintptr_t vaddr = (l2_entry_idx << LEVEL2_PDE_SHIFT) | (l3_entry_idx << LEVEL3_PDE_SHIFT) | (page_entry_idx << LEVEL4_PTE_SHIFT); - // if (LIKELY((uintptr_t)page_paddr >= low_bound && (uintptr_t)page_paddr < high_bound)) { - // kfree(P2V(page_paddr)); - // } else if (LIKELY((uintptr_t)page_paddr >= user_low_bound && (uintptr_t)page_paddr < user_high_bound)) { - // raw_free((char*)page_paddr); - // } - // } - // } - // kfree(P2V(l4_pte_paddr)); - // } - // } - // kfree(P2V(l3_pde_paddr)); - // } - // } - // kfree((char*)pgdir->pd_addr); + // get page paddr + uintptr_t* page_paddr = (uintptr_t*)ALIGNDOWN((l4_table_vaddr)[page_entry_idx], PAGE_SIZE); + if (page_paddr != NULL) { + // Ensure the virtual address is not in the IPC address space + assert(vaddr < USER_IPC_SPACE_BASE || vaddr >= USER_IPC_SPACE_TOP); + + if (LIKELY((uintptr_t)page_paddr >= low_bound && (uintptr_t)page_paddr < high_bound)) { + kfree(P2V(page_paddr)); + } else if (LIKELY((uintptr_t)page_paddr >= user_low_bound && (uintptr_t)page_paddr < user_high_bound)) { + raw_free((char*)page_paddr); + } + } + } + kfree(P2V(l4_table_paddr)); + } + } + kfree(P2V(l3_table_paddr)); + } + } + kfree((char*)pgdir->pd_addr); } diff --git a/Ubiquitous/XiZi_AIoT/softkernel/memory/share_page.c b/Ubiquitous/XiZi_AIoT/softkernel/memory/share_page.c index 06d4aa622..aa9ff1fcf 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/memory/share_page.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/memory/share_page.c @@ -113,11 +113,17 @@ static uintptr_t map_task_share_page(struct Thread* task, const uintptr_t paddr, // time to use buddy if (vaddr >= USER_IPC_USE_ALLOCATOR_WATERMARK) { task->memspace->massive_ipc_allocator = (struct KBuddy*)slab_alloc(&xizi_task_manager.task_buddy_allocator); - KBuddyInit(task->memspace->massive_ipc_allocator, USER_IPC_USE_ALLOCATOR_WATERMARK, USER_IPC_SPACE_TOP); if (!task->memspace->massive_ipc_allocator) { ERROR("Alloc task buddy failed.\n"); return (uintptr_t)NULL; } + if (!KBuddyInit(task->memspace->massive_ipc_allocator, USER_IPC_USE_ALLOCATOR_WATERMARK, USER_IPC_SPACE_TOP)) { + ERROR("Alloc task buddy failed.\n"); + slab_free(&xizi_task_manager.task_buddy_allocator, task->memspace->massive_ipc_allocator); + task->memspace->massive_ipc_allocator = NULL; + return (uintptr_t)NULL; + } + return map_task_share_page(task, paddr, nr_pages); } } diff --git a/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_spawn.c b/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_spawn.c index 052a03ed1..fa5994a01 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_spawn.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_spawn.c @@ -45,7 +45,7 @@ int sys_spawn(char* img_start, char* name, char** argv) // load memspace uintptr_t* entry = load_memspace(pmemspace, img_start); - if (NULL == entry) { + if (pmemspace->pgdir.pd_addr == NULL) { ERROR("Loading memspace from %016x failed.\n", img_start); free_memspace(pmemspace); return -1; diff --git a/Ubiquitous/XiZi_AIoT/softkernel/task/memspace.c b/Ubiquitous/XiZi_AIoT/softkernel/task/memspace.c index 2e25ef22e..a16509eed 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/task/memspace.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/task/memspace.c @@ -127,6 +127,7 @@ uintptr_t* load_memspace(struct MemSpace* pmemspace, char* img_start) // 1. alloc space if ((load_size = xizi_pager.resize_user_pgdir(&pgdir, load_size, ph.vaddr + ph.memsz)) != ph.vaddr + ph.memsz) { + ERROR("Add uspace size failed.\n"); goto error_exec; } // 2. copy inode to space diff --git a/Ubiquitous/XiZi_AIoT/softkernel/task/schedule.c b/Ubiquitous/XiZi_AIoT/softkernel/task/schedule.c index 644149a41..9df773558 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/task/schedule.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/task/schedule.c @@ -42,6 +42,7 @@ struct Thread* max_priority_runnable_task(void) DOUBLE_LIST_FOR_EACH_ENTRY(task, &xizi_task_manager.task_list_head[priority], node) { + assert(task != NULL); if (task->state == READY && !task->dead) { // found a runnable task, stop this look up return task;