* 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
"exception/handler.c"
])
+sources([
+ "soc/gic.c",
+])
+
sources([
"fault.c",
"trace.c"
])
+headers([
+ "includes"
+])
+
compile_opts([
"-mlittle-endian",
"-mgeneral-regs-only",
static inline void
setup_evbar()
{
- set_sysreg(VBAR_EL1, aa64_vbase);
+ set_sysreg(VBAR_EL1, __ptr(aa64_vbase));
}
static inline void
#include <lunaix/sections.h>
+
+#include <asm/mm_defs.h>
#include <asm-generic/init_pagetable.h>
#include <asm/boot_stage.h>
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);
.section .boot.data
- .align 16
+ .align 4
stack_end:
.skip 512
stack_top:
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
#define __ASM__
#include <asm/aa64_msrs.h>
-#include "hart_field.inc"
+#include "hart_fields.inc"
.section .text
.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]!
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
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
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
#include <asm/aa64_msrs.h>
.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
.section .text
.globl aa64_vbase
- .align 128
+ .align 7
aa64_vbase:
aa64_exception_entry EXCEPTION_SYNC
.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:
#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__
#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 */
#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; \
})
#include <lunaix/types.h>
#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
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 */
unsigned long _r; \
asm ("ubfm %0, %1, %2, %3" \
: "=r"(_r) \
- : "r"(from) \
- "i"(l) "i"(h)); \
+ : "r"(from), \
+ "i"(l),"i"(h)); \
_r; \
})
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; \
})
union {
reg_t x[31];
struct {
- reg_t x[29];
+ reg_t x_[29];
reg_t fp;
reg_t lr;
};
reg_t link;
struct {
reg_t sp_el0;
- reg_t sp_el1;
+ reg_t rsvd;
};
reg_t syndrome;
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
#include <asm/aa64_sysinst.h>
#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
#define __LUNAIX_BASE_DEFS_LD_INC
#define __LD__
-#include <sys/mm/mempart.h>
+#include <asm/mempart.h>
#define KEXEC_BASE KERNEL_IMG
#define PAGE_GRAN 4K
--- /dev/null
+#ifndef __LUNAIX_ARCH_ELF_H
+#define __LUNAIX_ARCH_ELF_H
+
+#include <sys-generic/elf.h>
+
+#endif /* __LUNAIX_ARCH_ELF_H */
--- /dev/null
+#ifndef __LUNAIX_ARCH_FAILSAFE_H
+#define __LUNAIX_ARCH_FAILSAFE_H
+
+#define STACK_SANITY 0xbeefc0de
+
+#ifndef __ASM__
+
+#include <lunaix/types.h>
+
+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 */
--- /dev/null
+#ifndef __LUNAIX_ARCH_SYSCALL_UTILS_H
+#define __LUNAIX_ARCH_SYSCALL_UTILS_H
+
+#include <klibc/string.h>
+
+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 */
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";
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);
}