From: Lunaixsky Date: Sun, 6 Oct 2024 17:09:32 +0000 (+0100) Subject: fix compilation issues in aarch64 ports X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/commitdiff_plain/c7a60d29f54d6de10a8388d26af441c8bc48a803?ds=sidebyside fix compilation issues in aarch64 ports * fix: corrected syntax of sys with encoding space. * fix: corrected syntax of inline asm constrain list. * fix: corrected the #include name error * fix: corrected the use of asm directive to load symbol to reg * fix: replace the invalid ldr into sp by using add to deduce the value * ref: remove the sp_el1_saved from exec_param as no longer needed * fix: add couple missing headers * fix: other general fixes with type conversions --- diff --git a/lunaix-os/arch/aarch64/LBuild b/lunaix-os/arch/aarch64/LBuild index 52b3479..6dae924 100644 --- a/lunaix-os/arch/aarch64/LBuild +++ b/lunaix-os/arch/aarch64/LBuild @@ -11,11 +11,19 @@ sources([ "exception/handler.c" ]) +sources([ + "soc/gic.c", +]) + sources([ "fault.c", "trace.c" ]) +headers([ + "includes" +]) + compile_opts([ "-mlittle-endian", "-mgeneral-regs-only", diff --git a/lunaix-os/arch/aarch64/boot/init.c b/lunaix-os/arch/aarch64/boot/init.c index b4256a7..d10675e 100644 --- a/lunaix-os/arch/aarch64/boot/init.c +++ b/lunaix-os/arch/aarch64/boot/init.c @@ -32,7 +32,7 @@ extern void aa64_vbase(); static inline void setup_evbar() { - set_sysreg(VBAR_EL1, aa64_vbase); + set_sysreg(VBAR_EL1, __ptr(aa64_vbase)); } static inline void diff --git a/lunaix-os/arch/aarch64/boot/kremap.c b/lunaix-os/arch/aarch64/boot/kremap.c index a230ece..b91d1d5 100644 --- a/lunaix-os/arch/aarch64/boot/kremap.c +++ b/lunaix-os/arch/aarch64/boot/kremap.c @@ -1,4 +1,6 @@ #include + +#include #include #include @@ -17,10 +19,10 @@ kremap() init_pt_alloc(&alloc, to_kphysical(&kpt), sizeof(kpt)); init_ptw_state(&ptw, &alloc, kpt_alloc_table(&alloc)); - pte = mkpte(boot_start, KERNEL_DATA); + pte = mkpte(bootsec_start, KERNEL_DATA); pte = pte_mkexec(pte); - nr = leaf_count(boot_end - boot_start); - kpt_set_ptes(&ptw, boot_start, pte, LFT_SIZE, nr); + nr = leaf_count(bootsec_end - bootsec_start); + kpt_set_ptes(&ptw, bootsec_start, pte, LFT_SIZE, nr); kpt_mktable_at(&ptw, VMAP, L0T_SIZE); kpt_mktable_at(&ptw, PMAP, L2T_SIZE); diff --git a/lunaix-os/arch/aarch64/boot/start.S b/lunaix-os/arch/aarch64/boot/start.S index f2aa88a..13878da 100644 --- a/lunaix-os/arch/aarch64/boot/start.S +++ b/lunaix-os/arch/aarch64/boot/start.S @@ -1,5 +1,5 @@ .section .boot.data - .align 16 + .align 4 stack_end: .skip 512 stack_top: @@ -15,12 +15,13 @@ mov x3, xzr */ start_: - ldr sp, =stack_top + adr x4, stack_top + mov sp, x4 mov fp, xzr - ldr x4, =aarch64_init + adr x4, aarch64_init bl x4 // x0: ptr to boot_handoff - ldr x4, =kernel_bootstrap + adr x4, kernel_bootstrap bl x4 \ No newline at end of file diff --git a/lunaix-os/arch/aarch64/exception/context.S b/lunaix-os/arch/aarch64/exception/context.S index fd85849..e30f72d 100644 --- a/lunaix-os/arch/aarch64/exception/context.S +++ b/lunaix-os/arch/aarch64/exception/context.S @@ -1,6 +1,6 @@ #define __ASM__ #include -#include "hart_field.inc" +#include "hart_fields.inc" .section .text @@ -8,12 +8,12 @@ .globl _aa64_switch_task _aa64_evec_prehandle: - # reservation for struct exec_param - sub sp, sp, #8 # push sp_el1 - sub sp, sp, #16 # push {sp_el0, link} - sub sp, sp, #16 # push {spsr, parent_hart} + // reservation for struct exec_param + sub sp, sp, #8 // push xzr + sub sp, sp, #16 // push {sp_el0, link} + sub sp, sp, #16 // push {spsr, parent_hart} - stp lr, fp, [sp, #-16]! # push {x31-x1} + stp lr, fp, [sp, #-16]! //push {x31-x1} stp x28, x27, [sp, #-16]! stp x26, x25, [sp, #-16]! stp x24, x23, [sp, #-16]! @@ -28,7 +28,7 @@ stp x6, x5, [sp, #-16]! stp x4, x3, [sp, #-16]! stp x2, x1, [sp, #-16]! - stp x0, xzr, [sp, #-16]! # push {x0, xzr} + stp x0, xzr, [sp, #-16]! // push {x0, xzr} add x1, sp, #hart_execp @@ -41,14 +41,11 @@ mrs x0, SPSR_EL1 str x0, [x1, #execp_spsr] - sub x0, sp, #hart_end - str x0, [x1, #execp_spel1_saved] - mov x0, sp bl handle_exception do_eret: - mov sp, x0 + add sp, x0, xzr add x1, x0, #hart_execp @@ -80,12 +77,12 @@ ldp x27, x28, [sp, #16]! ldp fp, lr, [sp, #16]! - # sp now point to the start of exec_param + // sp now point to the start of exec_param - ldr sp, [sp, #execp_spel1_saved] + sub sp, sp, #execp_end eret _aa64_switch_task: - # TODO + // TODO b do_eret \ No newline at end of file diff --git a/lunaix-os/arch/aarch64/exception/entries.S b/lunaix-os/arch/aarch64/exception/entries.S index ec96927..b7cbef8 100644 --- a/lunaix-os/arch/aarch64/exception/entries.S +++ b/lunaix-os/arch/aarch64/exception/entries.S @@ -3,17 +3,17 @@ #include .macro aa64_exception_entry type - .align 128 + .align 7 .type _exception_entry_t\type, @function - # each handler has at most 128 bytes (32 insts) + // each handler has at most 128 bytes (32 insts) _exception_entry_t\type: stp x1, x0, [sp, #-16] - # re-purpose the [63, 56] of ESR to exception - # type identifier + // re-purpose the [63, 56] of ESR to exception + // type identifier - mov x0, =\type + mov x0, #\type lsl x0, x0, #56 mrs x1, ESR_EL1 orr x0, x0, x1 @@ -28,7 +28,7 @@ .section .text .globl aa64_vbase - .align 128 + .align 7 aa64_vbase: aa64_exception_entry EXCEPTION_SYNC diff --git a/lunaix-os/arch/aarch64/exception/hart_fields.inc b/lunaix-os/arch/aarch64/exception/hart_fields.inc index 62629bc..5e9d63b 100644 --- a/lunaix-os/arch/aarch64/exception/hart_fields.inc +++ b/lunaix-os/arch/aarch64/exception/hart_fields.inc @@ -16,8 +16,8 @@ execp_link: .struct execp_link + 8 execp_spel0_saved: .struct execp_spel0_saved + 8 -execp_spel1_saved: - .struct execp_spel1_saved + 8 +execp_rsvd: + .struct execp_rsvd + 8 execp_syndrome: .struct execp_syndrome + 8 execp_end: diff --git a/lunaix-os/arch/aarch64/includes/asm/aa64_asm.h b/lunaix-os/arch/aarch64/includes/asm/aa64_asm.h index 51dcf5e..f617cfc 100644 --- a/lunaix-os/arch/aarch64/includes/asm/aa64_asm.h +++ b/lunaix-os/arch/aarch64/includes/asm/aa64_asm.h @@ -1,8 +1,14 @@ #ifndef __LUNAIX_AA64_ASM_H #define __LUNAIX_AA64_ASM_H +#define __const_expr_sign # +#define __comma() , +#define __const_expr() __const_expr_sign + #define __sr_encode(op0, op1, crn, crm, op2) \ s##op0##_##op1##_c##crn##_c##crm##_##op2 +#define __sysop_encode(op1, crn, crm, op2) \ + "#" #op1 ",C" #crn ",C" #crm ",#" #op2 #ifndef __ASM__ diff --git a/lunaix-os/arch/aarch64/includes/asm/aa64_msrs.h b/lunaix-os/arch/aarch64/includes/asm/aa64_msrs.h index b49d102..f1da5f2 100644 --- a/lunaix-os/arch/aarch64/includes/asm/aa64_msrs.h +++ b/lunaix-os/arch/aarch64/includes/asm/aa64_msrs.h @@ -41,5 +41,14 @@ #define SCTRL_A (1UL << 1) #define SCTRL_M (1UL << 0) +#define sysreg_flagging(reg, set, unset) \ + ({ \ + unsigned long _x; \ + _x = read_sysreg(reg); \ + _x = (_x & ~(unset)) | (set); \ + set_sysreg(reg, _x); \ + _x; \ + }) + #endif #endif /* __LUNAIX_AA64_MSRS_H */ diff --git a/lunaix-os/arch/aarch64/includes/asm/aa64_sysinst.h b/lunaix-os/arch/aarch64/includes/asm/aa64_sysinst.h index eaea541..230c455 100644 --- a/lunaix-os/arch/aarch64/includes/asm/aa64_sysinst.h +++ b/lunaix-os/arch/aarch64/includes/asm/aa64_sysinst.h @@ -3,22 +3,22 @@ #include "aa64_asm.h" -#define tlbi_alle1 __sr_encode(1, 4, 8, 7, 4) -#define tlbi_aside1 __sr_encode(1, 0, 8, 7, 2) -#define tlbi_rvaae1 __sr_encode(1, 0, 8, 6, 3) -#define tlbi_rvae1 __sr_encode(1, 0, 8, 6, 1) -#define tlbi_vaae1 __sr_encode(1, 0, 8, 7, 3) -#define tlbi_vae1 __sr_encode(1, 0, 8, 7, 1) +#define tlbi_alle1 __sysop_encode(4, 8, 7, 4) +#define tlbi_aside1 __sysop_encode(0, 8, 7, 2) +#define tlbi_rvaae1 __sysop_encode(0, 8, 6, 3) +#define tlbi_rvae1 __sysop_encode(0, 8, 6, 1) +#define tlbi_vaae1 __sysop_encode(0, 8, 7, 3) +#define tlbi_vae1 __sysop_encode(0, 8, 7, 1) #define sys_a0(op) \ - ({ asm ("sys " stringify(op)); }) + ({ asm ("sys " op); }) #define sys_a1(op, xt) \ - ({ asm ("sys " stringify(op) ", %0" :: "r"(xt)); }) + ({ asm ("sys " op ", %0" :: "r"(xt)); }) #define sysl(op) \ ({ unsigned long _x; \ - asm ("sysl %0, " stringify(op):"=r"(_x)); \ + asm ("sysl %0, " op :"=r"(_x)); \ _x; \ }) diff --git a/lunaix-os/arch/aarch64/includes/asm/abi.h b/lunaix-os/arch/aarch64/includes/asm/abi.h index 7f8d83d..cc18bba 100644 --- a/lunaix-os/arch/aarch64/includes/asm/abi.h +++ b/lunaix-os/arch/aarch64/includes/asm/abi.h @@ -4,8 +4,13 @@ #include #ifndef __ASM__ + #define align_stack(ptr) ((ptr) & ~15) +#define store_retval(retval) current_thread->hstate->registers.x[0] = (retval) +#define store_retval_to(th, retval) (th)->hstate->registers.x[0] = (retval) + + static inline void must_inline noret switch_context() { // TODO @@ -29,6 +34,20 @@ abi_get_retaddrat(ptr_t fp) return ((ptr_t*)fp)[1]; } +static inline ptr_t must_inline +abi_get_callframe() +{ + ptr_t val; + asm volatile("mov %0, fp" : "=r"(val)); + return val; +} + +static inline void must_inline +j_usr(ptr_t sp, ptr_t pc) +{ + // TODO +} + #endif #endif /* __LUNAIX_AA64_ABI_H */ diff --git a/lunaix-os/arch/aarch64/includes/asm/bits.h b/lunaix-os/arch/aarch64/includes/asm/bits.h index a30f254..29ed7bf 100644 --- a/lunaix-os/arch/aarch64/includes/asm/bits.h +++ b/lunaix-os/arch/aarch64/includes/asm/bits.h @@ -11,8 +11,8 @@ unsigned long _r; \ asm ("ubfm %0, %1, %2, %3" \ : "=r"(_r) \ - : "r"(from) \ - "i"(l) "i"(h)); \ + : "r"(from), \ + "i"(l),"i"(h)); \ _r; \ }) @@ -21,8 +21,8 @@ unsigned long _r = to; \ asm ("bfi %0, %1, %2, %3" \ : "=r"(_r) \ - : "r"(from) \ - "i"(l) \ + : "r"(from), \ + "i"(l), \ "i"(h - l + 1)); \ _r; \ }) diff --git a/lunaix-os/arch/aarch64/includes/asm/hart.h b/lunaix-os/arch/aarch64/includes/asm/hart.h index ae84ddd..fa1f4bf 100644 --- a/lunaix-os/arch/aarch64/includes/asm/hart.h +++ b/lunaix-os/arch/aarch64/includes/asm/hart.h @@ -15,7 +15,7 @@ struct regcontext union { reg_t x[31]; struct { - reg_t x[29]; + reg_t x_[29]; reg_t fp; reg_t lr; }; @@ -29,7 +29,7 @@ struct exec_param reg_t link; struct { reg_t sp_el0; - reg_t sp_el1; + reg_t rsvd; }; reg_t syndrome; @@ -73,10 +73,7 @@ hart_pc(struct hart_state* hstate) static inline ptr_t hart_sp(struct hart_state* hstate) { - if (spsr_from_el0(hstate->execp.spsr)) { - return hstate->execp.sp_el0; - } - return hstate->execp.sp_el1; + return __ptr(&hstate[-1]); } static inline bool diff --git a/lunaix-os/arch/aarch64/includes/asm/tlb.h b/lunaix-os/arch/aarch64/includes/asm/tlb.h index 11690d3..d59f846 100644 --- a/lunaix-os/arch/aarch64/includes/asm/tlb.h +++ b/lunaix-os/arch/aarch64/includes/asm/tlb.h @@ -7,17 +7,17 @@ #include #define pack_va(asid, ttl, va) \ - (((asid & 0xffff) << 48) | \ - ((ttl & 0b1111) << 44) | \ - (pfn(va) & ((1 << 44) - 1))) + (((asid & 0xffffUL) << 48) | \ + ((ttl & 0b1111UL) << 44) | \ + (pfn(va) & ((1UL << 44) - 1))) #define pack_rva(asid, ttl, base, n, scale) \ - (((asid & 0xffff) << 48) | \ - ((_MMU_TG & 0b11) << 46) | \ - ((n & 0x1f) << 39) | \ - ((scale & 0b11) << 37) | \ - ((ttl & 0b1111) << 44) | \ - (pfn(base)& ((1 << 37) - 1))) + (((asid & 0xffffUL) << 48) | \ + ((_MMU_TG & 0b11UL) << 46) | \ + ((n & 0x1fUL) << 39) | \ + ((scale & 0b11UL) << 37) | \ + ((ttl & 0b1111UL) << 44) | \ + (pfn(base)& ((1UL << 37) - 1))) /** * @brief Invalidate an entry of all address space diff --git a/lunaix-os/arch/aarch64/includes/linking/base_defs.ld.inc b/lunaix-os/arch/aarch64/includes/linking/base_defs.ld.inc index 827c6b3..5a7f42a 100644 --- a/lunaix-os/arch/aarch64/includes/linking/base_defs.ld.inc +++ b/lunaix-os/arch/aarch64/includes/linking/base_defs.ld.inc @@ -2,7 +2,7 @@ #define __LUNAIX_BASE_DEFS_LD_INC #define __LD__ -#include +#include #define KEXEC_BASE KERNEL_IMG #define PAGE_GRAN 4K diff --git a/lunaix-os/arch/aarch64/includes/sys/elf.h b/lunaix-os/arch/aarch64/includes/sys/elf.h new file mode 100644 index 0000000..1d945f9 --- /dev/null +++ b/lunaix-os/arch/aarch64/includes/sys/elf.h @@ -0,0 +1,6 @@ +#ifndef __LUNAIX_ARCH_ELF_H +#define __LUNAIX_ARCH_ELF_H + +#include + +#endif /* __LUNAIX_ARCH_ELF_H */ diff --git a/lunaix-os/arch/aarch64/includes/sys/failsafe.h b/lunaix-os/arch/aarch64/includes/sys/failsafe.h new file mode 100644 index 0000000..8bc3570 --- /dev/null +++ b/lunaix-os/arch/aarch64/includes/sys/failsafe.h @@ -0,0 +1,29 @@ +#ifndef __LUNAIX_ARCH_FAILSAFE_H +#define __LUNAIX_ARCH_FAILSAFE_H + +#define STACK_SANITY 0xbeefc0de + +#ifndef __ASM__ + +#include + +static inline bool +check_bootstack_sanity() +{ + extern unsigned int __kinit_stack_end[]; + + return ( __kinit_stack_end[0] + | __kinit_stack_end[1] + | __kinit_stack_end[2] + | __kinit_stack_end[3]) == STACK_SANITY; +} + +static inline void must_inline noret +failsafe_diagnostic() { + // TODO + unreachable; +} + +#endif + +#endif /* __LUNAIX_FAILSAFE_H */ diff --git a/lunaix-os/arch/aarch64/includes/sys/syscall_utils.h b/lunaix-os/arch/aarch64/includes/sys/syscall_utils.h new file mode 100644 index 0000000..4a43eb8 --- /dev/null +++ b/lunaix-os/arch/aarch64/includes/sys/syscall_utils.h @@ -0,0 +1,12 @@ +#ifndef __LUNAIX_ARCH_SYSCALL_UTILS_H +#define __LUNAIX_ARCH_SYSCALL_UTILS_H + +#include + +static inline void +convert_valist(va_list* ap_ref, sc_va_list syscall_ap) +{ + memcpy(ap_ref, syscall_ap, sizeof(*ap_ref)); +} + +#endif /* __LUNAIX_SYSCALL_UTILS_H */ diff --git a/lunaix-os/arch/aarch64/trace.c b/lunaix-os/arch/aarch64/trace.c index 1930003..7370a37 100644 --- a/lunaix-os/arch/aarch64/trace.c +++ b/lunaix-os/arch/aarch64/trace.c @@ -5,16 +5,16 @@ static inline char* __type_name(reg_t syndrome) { - switch (hart_vector_stamp(syndrome)) + switch (BITS_GET(syndrome, SYNDROME_ETYPE)) { - case EXCEPTION_SYNC: - return "sync"; - case EXCEPTION_IRQ: - return "async (irq)"; - case EXCEPTION_FIQ: - return "async (fiq)"; - case EXCEPTION_SERR: - return "async (serr)"; + case EXCEPTION_SYNC: + return "sync"; + case EXCEPTION_IRQ: + return "async (irq)"; + case EXCEPTION_FIQ: + return "async (fiq)"; + case EXCEPTION_SERR: + return "async (serr)"; } return "unknwon"; @@ -50,7 +50,7 @@ trace_print_transition_full(struct hart_state* hstate) trace_log(" esr=0x%016lx, spsr=0x%016lx", syndrome, execp->spsr); trace_log(" sp_el0=0x%016lx, sp_el1=0x%016lx", - execp->sp_el0, execp->sp_el1); + execp->sp_el0, hart_sp(hstate)); trace_log(" pc=0x%016lx", execp->link); }