Merge branch rk3568_dev of https://www.gitlink.org.cn/tuyuyang/xiuos with commit 6bc856b7a6 into local
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
ifneq ($(findstring $(BOARD), ok1028a-c), )
|
||||
ifneq ($(findstring $(BOARD), 3568), )
|
||||
SRC_DIR := armv8-a
|
||||
endif
|
||||
ifneq ($(findstring $(BOARD), imx6q-sabrelite zynq7000-zc702), )
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
SRC_DIR := cortex-a72
|
||||
SRC_DIR := cortex-a55
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
+24
-3
@@ -28,13 +28,16 @@ Modification:
|
||||
*************************************************/
|
||||
#include <stdint.h>
|
||||
|
||||
#include "exception_registers.h"
|
||||
|
||||
#include "assert.h"
|
||||
#include "core.h"
|
||||
#include "exception_registers.h"
|
||||
#include "multicores.h"
|
||||
#include "syscall.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "mmu.h"
|
||||
|
||||
extern void dabort_handler(struct trapframe* r);
|
||||
extern void iabort_handler(struct trapframe* r);
|
||||
|
||||
@@ -73,7 +76,6 @@ void syscall_arch_handler(struct trapframe* tf)
|
||||
|
||||
uint64_t esr = r_esr_el1();
|
||||
uint64_t ec = (esr >> 0x1A) & 0x3F;
|
||||
w_esr_el1(0);
|
||||
switch (ec) {
|
||||
case 0B010101:
|
||||
software_irq_dispatch(tf);
|
||||
@@ -87,11 +89,30 @@ void syscall_arch_handler(struct trapframe* tf)
|
||||
iabort_handler(tf);
|
||||
break;
|
||||
default: {
|
||||
ERROR("USYSCALL: unexpected ec: %016lx", esr);
|
||||
ERROR("USYSCALL: unexpected\n");
|
||||
ERROR(" esr: %016lx\n", esr);
|
||||
ERROR(" elr = %016lx far = %016lx\n", r_elr_el1(), r_far_el1());
|
||||
w_esr_el1(0);
|
||||
extern void dump_tf(struct trapframe * tf);
|
||||
dump_tf(tf);
|
||||
|
||||
uint32_t sctlr = 0;
|
||||
SCTLR_R(sctlr);
|
||||
DEBUG("SCTLR: %x\n", sctlr);
|
||||
uint32_t spsr = 0;
|
||||
__asm__ volatile("mrs %0, spsr_el1" : "=r"(spsr)::"memory");
|
||||
DEBUG("SPSR: %x\n", spsr);
|
||||
uint64_t tcr = 0;
|
||||
__asm__ volatile("mrs %0, tcr_el1" : "=r"(tcr)::"memory");
|
||||
DEBUG("TCR: %x\n", tcr);
|
||||
uint64_t mair = 0;
|
||||
__asm__ volatile("mrs %0, mair_el1" : "=r"(mair)::"memory");
|
||||
DEBUG("MAIR: %x\n", mair);
|
||||
|
||||
// kill error task
|
||||
xizi_enter_kernel();
|
||||
assert(cur_cpu()->task != NULL);
|
||||
ERROR("Error Task: %s\n", cur_cpu()->task->name);
|
||||
sys_exit(cur_cpu()->task);
|
||||
context_switch(&cur_cpu()->task->thread_context.context, cur_cpu()->scheduler);
|
||||
panic("dabort end should never be reashed.\n");
|
||||
+1
-1
@@ -29,7 +29,7 @@ Modification:
|
||||
#include <string.h>
|
||||
|
||||
#include "core.h"
|
||||
#include "cortex_a72.h"
|
||||
#include "cortex_a55.h"
|
||||
#include "exception_registers.h"
|
||||
#include "gicv3_common_opa.h"
|
||||
#include "trap_common.h"
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
SRC_FILES := trampoline.S $(BOARD)/trap_common.c $(BOARD)/trap.c error_debug.c hard_spinlock.S
|
||||
|
||||
ifeq ($(BOARD), ok1028a-c)
|
||||
ifeq ($(BOARD), 3568)
|
||||
SRC_DIR := gicv3
|
||||
SRC_FILES += $(BOARD)/
|
||||
endif
|
||||
+43
-39
@@ -39,51 +39,53 @@ Modification:
|
||||
2. Modify iabort and dabort handler(in dabort_handler() and iabort_handler())
|
||||
*************************************************/
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "exception_registers.h"
|
||||
|
||||
#include "assert.h"
|
||||
#include "core.h"
|
||||
#include "log.h"
|
||||
#include "multicores.h"
|
||||
#include "spinlock.h"
|
||||
#include "task.h"
|
||||
#include "trap_common.h"
|
||||
|
||||
void dump_tf(struct trapframe* tf)
|
||||
{
|
||||
KPrintf(" sp: 0x%x\n", tf->sp);
|
||||
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);
|
||||
KPrintf(" x2: 0x%x\n", tf->x2);
|
||||
KPrintf(" x3: 0x%x\n", tf->x3);
|
||||
KPrintf(" x4: 0x%x\n", tf->x4);
|
||||
KPrintf(" x5: 0x%x\n", tf->x5);
|
||||
KPrintf(" x6: 0x%x\n", tf->x6);
|
||||
KPrintf(" x7: 0x%x\n", tf->x7);
|
||||
KPrintf(" x8: 0x%x\n", tf->x8);
|
||||
KPrintf(" x9: 0x%x\n", tf->x9);
|
||||
KPrintf(" x10: 0x%x\n", tf->x10);
|
||||
KPrintf(" x11: 0x%x\n", tf->x11);
|
||||
KPrintf(" x12: 0x%x\n", tf->x12);
|
||||
KPrintf(" x13: 0x%x\n", tf->x13);
|
||||
KPrintf(" x14: 0x%x\n", tf->x14);
|
||||
KPrintf(" x15: 0x%x\n", tf->x15);
|
||||
KPrintf(" x16: 0x%x\n", tf->x16);
|
||||
KPrintf(" x17: 0x%x\n", tf->x17);
|
||||
KPrintf(" x18: 0x%x\n", tf->x18);
|
||||
KPrintf(" x19: 0x%x\n", tf->x19);
|
||||
KPrintf(" x20: 0x%x\n", tf->x20);
|
||||
KPrintf(" x21: 0x%x\n", tf->x21);
|
||||
KPrintf(" x22: 0x%x\n", tf->x22);
|
||||
KPrintf(" x23: 0x%x\n", tf->x23);
|
||||
KPrintf(" x24: 0x%x\n", tf->x24);
|
||||
KPrintf(" x25: 0x%x\n", tf->x25);
|
||||
KPrintf(" x26: 0x%x\n", tf->x26);
|
||||
KPrintf(" x27: 0x%x\n", tf->x27);
|
||||
KPrintf(" x28: 0x%x\n", tf->x28);
|
||||
KPrintf(" x29: 0x%x\n", tf->x29);
|
||||
KPrintf(" x30: 0x%x\n", tf->x30);
|
||||
KPrintf(" sp: 0x%016lx\n", tf->sp);
|
||||
KPrintf(" pc: 0x%016lx\n", tf->pc);
|
||||
KPrintf(" spsr: 0x%016lx\n", tf->spsr);
|
||||
KPrintf(" x0: 0x%016lx\n", tf->x0);
|
||||
KPrintf(" x1: 0x%016lx\n", tf->x1);
|
||||
KPrintf(" x2: 0x%016lx\n", tf->x2);
|
||||
KPrintf(" x3: 0x%016lx\n", tf->x3);
|
||||
KPrintf(" x4: 0x%016lx\n", tf->x4);
|
||||
KPrintf(" x5: 0x%016lx\n", tf->x5);
|
||||
KPrintf(" x6: 0x%016lx\n", tf->x6);
|
||||
KPrintf(" x7: 0x%016lx\n", tf->x7);
|
||||
KPrintf(" x8: 0x%016lx\n", tf->x8);
|
||||
KPrintf(" x9: 0x%016lx\n", tf->x9);
|
||||
KPrintf(" x10: 0x%016lx\n", tf->x10);
|
||||
KPrintf(" x11: 0x%016lx\n", tf->x11);
|
||||
KPrintf(" x12: 0x%016lx\n", tf->x12);
|
||||
KPrintf(" x13: 0x%016lx\n", tf->x13);
|
||||
KPrintf(" x14: 0x%016lx\n", tf->x14);
|
||||
KPrintf(" x15: 0x%016lx\n", tf->x15);
|
||||
KPrintf(" x16: 0x%016lx\n", tf->x16);
|
||||
KPrintf(" x17: 0x%016lx\n", tf->x17);
|
||||
KPrintf(" x18: 0x%016lx\n", tf->x18);
|
||||
KPrintf(" x19: 0x%016lx\n", tf->x19);
|
||||
KPrintf(" x20: 0x%016lx\n", tf->x20);
|
||||
KPrintf(" x21: 0x%016lx\n", tf->x21);
|
||||
KPrintf(" x22: 0x%016lx\n", tf->x22);
|
||||
KPrintf(" x23: 0x%016lx\n", tf->x23);
|
||||
KPrintf(" x24: 0x%016lx\n", tf->x24);
|
||||
KPrintf(" x25: 0x%016lx\n", tf->x25);
|
||||
KPrintf(" x26: 0x%016lx\n", tf->x26);
|
||||
KPrintf(" x27: 0x%016lx\n", tf->x27);
|
||||
KPrintf(" x28: 0x%016lx\n", tf->x28);
|
||||
KPrintf(" x29: 0x%016lx\n", tf->x29);
|
||||
KPrintf(" x30: 0x%016lx\n", tf->x30);
|
||||
}
|
||||
|
||||
void dabort_reason(struct trapframe* r)
|
||||
@@ -91,8 +93,9 @@ void dabort_reason(struct trapframe* r)
|
||||
uint32_t fault_status, fault_address;
|
||||
__asm__ __volatile__("mrs %0, esr_el1" : "=r"(fault_status));
|
||||
__asm__ __volatile__("mrs %0, far_el1" : "=r"(fault_address));
|
||||
LOG("program counter: 0x%x caused\n", r->pc);
|
||||
LOG("data abort at 0x%x, status 0x%x\n", fault_address, fault_status);
|
||||
w_esr_el1(0);
|
||||
LOG("program counter: 0x%016lx caused\n", r->pc);
|
||||
LOG("data abort at 0x%016lx, status 0x%016lx\n", fault_address, fault_status);
|
||||
if ((fault_status & 0x3f) == 0x21) // Alignment failure
|
||||
KPrintf("reason: alignment\n");
|
||||
else if ((fault_status & 0x3f) == 0x4) // Translation fault, level 0
|
||||
@@ -131,8 +134,9 @@ void iabort_reason(struct trapframe* r)
|
||||
uint32_t fault_status, fault_address;
|
||||
__asm__ __volatile__("mrs %0, esr_el1" : "=r"(fault_status));
|
||||
__asm__ __volatile__("mrs %0, far_el1" : "=r"(fault_address));
|
||||
LOG("program counter: 0x%x caused\n", r->pc);
|
||||
LOG("data abort at 0x%x, status 0x%x\n", fault_address, fault_status);
|
||||
LOG("program counter: 0x%016lx caused\n", r->pc);
|
||||
LOG("data abort at 0x%016lx, status 0x%016lx\n", fault_address, fault_status);
|
||||
w_esr_el1(0);
|
||||
if ((fault_status & 0x3f) == 0x21) // Alignment failure
|
||||
KPrintf("reason: alignment\n");
|
||||
else if ((fault_status & 0x3f) == 0x4) // Translation fault, level 0
|
||||
+2
-2
@@ -30,8 +30,8 @@ Modification:
|
||||
|
||||
// clang-format off
|
||||
// interrupt controller GICv3
|
||||
#define GICV3 MMIO_P2V_WO(0x08000000ULL)
|
||||
#define GICV3_REDIST MMIO_P2V_WO(0x080a0000ULL)
|
||||
#define GICV3 MMIO_P2V_WO(0xFD400000ULL)
|
||||
#define GICV3_REDIST MMIO_P2V_WO(0xFD460000ULL)
|
||||
|
||||
#define D_CTLR 0x0
|
||||
#define D_TYPER 0x4
|
||||
+35
-41
@@ -55,62 +55,56 @@ Modification:
|
||||
#define UNLOCKED 0xFF
|
||||
// int spinlock_lock(spinlock_t * lock, uint64_t timeout)
|
||||
.global _spinlock_lock
|
||||
.func _spinlock_lock
|
||||
.func _spinlock_lock
|
||||
_spinlock_lock:
|
||||
mov w2, #1
|
||||
mov w2, #1
|
||||
sevl
|
||||
1:
|
||||
wfe
|
||||
|
||||
sevl
|
||||
wfe
|
||||
2:
|
||||
ldaxrb w1, [x0] // check if the spinlock is currently unlocked
|
||||
cmp w1, #UNLOCKED
|
||||
bne 1b
|
||||
|
||||
ldaxrb w1, [x0] // check if the spinlock is currently unlocked
|
||||
cmp w1, #UNLOCKED
|
||||
bne _spinlock_lock
|
||||
mrs x1, mpidr_el1 // get our CPU ID
|
||||
and x1, x1, #0xFFF
|
||||
lsr x1, x1, #8
|
||||
stxrb w2, w1, [x0]
|
||||
cmp x2, #0
|
||||
bne 2b // check if the write was successful, if the write failed, start over
|
||||
|
||||
mrs x1, mpidr_el1 // get our CPU ID
|
||||
and x1, x1, #3
|
||||
stxrb w2, w1, [x0]
|
||||
cmp x2, #0
|
||||
bne _spinlock_lock // check if the write was successful, if the write failed, start over
|
||||
dmb ish // Ensure that accesses to shared resource have completed
|
||||
|
||||
dmb ish // Ensure that accesses to shared resource have completed
|
||||
|
||||
mov x0, #0
|
||||
ret
|
||||
|
||||
.endfunc
|
||||
mov x0, #0
|
||||
ret
|
||||
.endfunc
|
||||
|
||||
|
||||
// void spinlock_unlock(spinlock_t * lock)
|
||||
.global _spinlock_unlock
|
||||
.func _spinlock_unlock
|
||||
_spinlock_unlock:
|
||||
mrs x1, mpidr_el1 // get our CPU ID
|
||||
and x1, x1, #0xFFF
|
||||
lsr x1, x1, #8
|
||||
|
||||
mrs x1, mpidr_el1 // get our CPU ID
|
||||
and x1, x1, #3
|
||||
ldr w2, [x0]
|
||||
cmp w1, w2
|
||||
bne 1f //doesn't match,jump to 1
|
||||
|
||||
ldr w2, [x0]
|
||||
cmp w1, w2
|
||||
bne 1f //doesn't match,jump to 1
|
||||
|
||||
|
||||
dmb ish
|
||||
|
||||
mov w1, #UNLOCKED
|
||||
str w1, [x0]
|
||||
|
||||
dsb ish //Ensure that no instructions following the barrier execute until
|
||||
// all memory accesses prior to the barrier have completed.
|
||||
|
||||
|
||||
sevl // send event to wake up other cores waiting on spinlock
|
||||
|
||||
mov x0, #0 // return success
|
||||
ret
|
||||
dmb ish
|
||||
mov w1, #UNLOCKED
|
||||
str w1, [x0]
|
||||
dsb ish //Ensure that no instructions following the barrier execute until
|
||||
// all memory accesses prior to the barrier have completed.
|
||||
sevl // send event to wake up other cores waiting on spinlock
|
||||
|
||||
mov x0, #0 // return success
|
||||
ret
|
||||
1:
|
||||
mov x0, #1 //doesn't match, so exit with failure
|
||||
ret
|
||||
|
||||
mov x0, #1 //doesn't match, so exit with failure
|
||||
ret
|
||||
.endfunc
|
||||
|
||||
.end
|
||||
+18
-20
@@ -143,13 +143,13 @@ Modification:
|
||||
.balign 0x800
|
||||
alltraps:
|
||||
// Current EL with sp0
|
||||
b .
|
||||
b badtrap
|
||||
.balign 0x80
|
||||
b .
|
||||
b badtrap
|
||||
.balign 0x80
|
||||
b .
|
||||
b badtrap
|
||||
.balign 0x80
|
||||
b .
|
||||
b badtrap
|
||||
|
||||
// Current EL with spx
|
||||
.balign 0x80
|
||||
@@ -157,9 +157,9 @@ alltraps:
|
||||
.balign 0x80
|
||||
b el1irq
|
||||
.balign 0x80
|
||||
b .
|
||||
b badtrap
|
||||
.balign 0x80
|
||||
b .
|
||||
b badtrap
|
||||
|
||||
// Lower EL using aarch64
|
||||
.balign 0x80
|
||||
@@ -167,32 +167,34 @@ alltraps:
|
||||
.balign 0x80
|
||||
b el0irq
|
||||
.balign 0x80
|
||||
b .
|
||||
b badtrap
|
||||
.balign 0x80
|
||||
b .
|
||||
b badtrap
|
||||
|
||||
// Lower EL using aarch32
|
||||
.balign 0x80
|
||||
b .
|
||||
b badtrap
|
||||
.balign 0x80
|
||||
b .
|
||||
b badtrap
|
||||
.balign 0x80
|
||||
b .
|
||||
b badtrap
|
||||
.balign 0x80
|
||||
b .
|
||||
b badtrap
|
||||
|
||||
badtrap:
|
||||
savereg
|
||||
mov x0, sp
|
||||
bl kernel_intr_handler
|
||||
b .
|
||||
|
||||
el1sync:
|
||||
msr daifset, #0xf
|
||||
savereg
|
||||
|
||||
mov x0, sp
|
||||
bl kernel_abort_handler
|
||||
b .
|
||||
|
||||
el1irq:
|
||||
msr daifset, #0xf
|
||||
usavereg
|
||||
|
||||
mov x0, sp
|
||||
bl intr_irq_dispatch
|
||||
|
||||
@@ -201,9 +203,7 @@ el1irq:
|
||||
eret
|
||||
|
||||
el0sync:
|
||||
msr daifset, #0xf
|
||||
usavereg
|
||||
|
||||
mov x0, sp
|
||||
bl syscall_arch_handler
|
||||
|
||||
@@ -212,9 +212,7 @@ el0sync:
|
||||
eret
|
||||
|
||||
el0irq:
|
||||
msr daifset, #0xf
|
||||
usavereg
|
||||
|
||||
mov x0, sp
|
||||
bl intr_irq_dispatch
|
||||
|
||||
@@ -59,7 +59,7 @@ __attribute__((optimize("O0"))) void spinlock_init(struct spinlock* lock, char*
|
||||
}
|
||||
|
||||
extern int _spinlock_lock(struct spinlock* lock, uint32_t timeout);
|
||||
extern void _spinlock_unlock(struct spinlock* lock);
|
||||
extern int _spinlock_unlock(struct spinlock* lock);
|
||||
|
||||
__attribute__((optimize("O0"))) void spinlock_lock(struct spinlock* lock)
|
||||
{
|
||||
@@ -88,7 +88,9 @@ __attribute__((optimize("O0"))) void spinlock_unlock(struct spinlock* lock)
|
||||
_double_list_del(p_lock_node->prev, p_lock_node->next);
|
||||
_spinlock_unlock(&request_lock);
|
||||
|
||||
_spinlock_unlock(lock);
|
||||
if (_spinlock_unlock(lock) != 0) {
|
||||
ERROR("Core %d trying to unlock a lock belongs to %d.\n", cur_cpuid(), lock->owner_cpu);
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((optimize("O0"))) bool spinlock_try_lock(struct spinlock* lock)
|
||||
|
||||
Reference in New Issue
Block a user