Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ ifdef MULTICORE
CFLAGS += -DMULTICORE
endif

# Force all assembly to go through ASM_BKL_LOCK/ASM_BKL_UNLOCK in asm_std.h.
CFLAGS += -Dk0lock=DO_NOT_USE_K0LOCK -Dk0unlock=DO_NOT_USE_K0UNLOCK

ifdef SOFT_BKL
CFLAGS += -DSOFT_BKL
endif

CFLAGS += -DH2K_KERNEL_PGSIZE=$(H2K_KERNEL_PGSIZE) -DH2K_KERNEL_ADDRBITS=$(H2K_KERNEL_ADDRBITS) -DH2K_GIT_COMMIT=$(H2K_GIT_COMMIT)

CFLAGS += $(KERNEL_CFLAGS) $(H2K_EXTRA_CFLAGS)
Expand Down
3 changes: 3 additions & 0 deletions kernel/build/offsets/offsets.ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ int main(int argc, char **argv)
PRINT_KG_OFFSET(dma_version);
PRINT_KG_OFFSET(core_id);
PRINT_KG_OFFSET(core_count);
#ifdef SOFT_BKL
PRINT_KG_OFFSET(bkl);
#endif

PRINT_KG_SUBSTRUCT_OFFSET(time,next_ticks);
PRINT_KG_SUBSTRUCT_OFFSET(time,last_ticks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,17 @@

s32_t checker_kernel_locked()
{
#if ARCHV >= 3
u32_t syscfg = H2K_get_syscfg();
if ((syscfg & (1<<12)) == 0) {
if (!IS_BKL_LOCKED()) {
FAIL("checker_kernel_locked: Kernel not locked.");
}
#else
#error support less than v3
#endif
return 1;
}

s32_t checker_kernel_unlocked()
{
#if ARCHV >= 3
u32_t syscfg = H2K_get_syscfg();
if ((syscfg & (1<<12)) != 0) {
if (IS_BKL_LOCKED()) {
FAIL("checker_kernel_unlocked: Kernel is Locked.");
}
#else
#error support less than v3
#endif
return 1;
}

3 changes: 3 additions & 0 deletions kernel/data/globals/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ typedef struct {
u32_t last_tlb_index_dma;
u32_t tlb_size_dma;
u32_t dma_tlb_start;
#endif
#ifdef SOFT_BKL
H2K_spinlock_t bkl;
#endif
H2K_spinlock_t tmpmap_lock;
H2K_spinlock_t asid_spinlock;
Expand Down
5 changes: 3 additions & 2 deletions kernel/event/error/error.ref.S
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ FUNC_START H2K_fatal_crash .text.vm.error .p2align 2
{
memw(H2K_GP+#KG_is_nmi_soft) = #1
}
k0lock
// FIXME SOFT_BKL: crash path must NOT block on BKL if lock is already held
ASM_BKL_LOCK(r6, r7, r8, p0)
r2 = htid
r3 = #-1
r3 = togglebit(r3,r2)
Expand Down Expand Up @@ -127,7 +128,7 @@ FUNC_START H2K_fatal_crash .text.vm.error .p2align 2
syscfg = r1
// We should now be in "Single Thread Mode": only one thread active, and that's the one executing here
// Did we possibly nmi a thread holding a lock? We can fix it!
k0unlock
ASM_BKL_UNLOCK(r6, r7, r8, p0)
tlbunlock
// Bit 1: Save off TLB and flush caches
// EJP: for now, let's do this all the time.
Expand Down
2 changes: 1 addition & 1 deletion kernel/event/interrupt/interrupt.ref.S
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ FUNC_START H2K_interrupted_waitmode .text.core.interrupt .p2align 2
p0 = cmp.eq(INTINFO_FN,#0) // really, we shouldn't get NULL interrupt handlers, but if we do...
if (!p0) callr INTINFO_FN
r1:0 = #0
k0lock
ASM_BKL_LOCK(r6, r7, r8, p0)
jump H2K_switch

FUNC_END H2K_interrupted_waitmode
Expand Down
2 changes: 1 addition & 1 deletion kernel/event/interrupt/interrupt.v3opt.S
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ FUNC_START H2K_interrupted_waitmode .text.core.interrupt .falign
{
callr r4
}
k0lock
ASM_BKL_LOCK(r6, r7, r8, p0)
{
r1:0 = combine(#0,#0)
jump H2K_switch
Expand Down
4 changes: 1 addition & 3 deletions kernel/event/interrupt/interrupt.v4opt.S
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ FUNC_START H2K_interrupted_waitmode_or_preempt .text.core.interrupt .p2align 5
jumpr r31
}
1: // We were idle, go back to sleep
{
k0lock
}
ASM_BKL_LOCK(r6, r7, r8, p0)
{
r1:0 = #0
jump H2K_switch
Expand Down
3 changes: 2 additions & 1 deletion kernel/event/interrupt/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <setjmp.h>
#include <max.h>
#include <globals.h>
#include <hw.h>
#include <trace.h>

/*
Expand Down Expand Up @@ -97,7 +98,7 @@ void H2K_switch(H2K_thread_context *from, H2K_thread_context *to)
{
if (from != NULL) FAIL("Unexpected FROM");
if (to != NULL) FAIL("Unexpected TO");
asm volatile (" k0unlock ");
BKL_UNLOCK();
longjmp(env,1);
}

Expand Down
10 changes: 5 additions & 5 deletions kernel/event/popup/popup.v4opt.S
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ FUNC_START H2K_popup_int .text.int.popup .p2align 5
#define NEGONE r13
#define NEWPRIO r14
#define PRIO r15
k0lock
ASM_BKL_LOCK(r6, r7, r8, p0)
{
WAIT_PRIOMASKS = memd(H2K_GP+#KG_lowprio_masks) // share w/ priomask?
HANDLERBASE = add(H2K_GP,#KG_inthandlers)
Expand Down Expand Up @@ -98,7 +98,7 @@ FUNC_START H2K_popup_int .text.int.popup .p2align 5
if (!p1) memd(ME) = PREV_HEAD
}
.Lnohandler:
k0unlock
ASM_BKL_UNLOCK(r6, r7, r8, p0)
jumpr r31
#undef INTNO
#undef ME
Expand Down Expand Up @@ -147,7 +147,7 @@ FUNC_START H2K_popup_wait .text.int.popup .falign
p1 = cmp.eq(INTNO, #L2_CORE_INTERRUPT)
if (p1.new) jump:nt 9f
}
k0lock
ASM_BKL_LOCK(r6, r7, r8, p0)
#define TMP INTHANDLERS_ADDR
{
TMP = memub(ME+#CONTEXT_vmstatus)
Expand Down Expand Up @@ -208,7 +208,7 @@ FUNC_START H2K_popup_wait .text.int.popup .falign
jump H2K_dosched
}
8:
k0unlock
ASM_BKL_UNLOCK(r6, r7, r8, p0)
9:
{
r0 = #-1
Expand All @@ -219,7 +219,7 @@ FUNC_START H2K_popup_wait .text.int.popup .falign
r0 = ME
call H2K_vm_do_work_withlock
}
k0unlock
ASM_BKL_UNLOCK(r6, r7, r8, p0)
{
r0 = #-1
dealloc_return
Expand Down
10 changes: 5 additions & 5 deletions kernel/futex/futex_classic/futex_classic.v4opt.S
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ FUNC_START H2K_futex_wait .text.core.futex .p2align 5
#define LOCKVAL r17
#define TMP r6
#define MASK r7
k0lock
ASM_BKL_LOCK(r6, r7, r8, p0)
{
TMP = memub(ME+#CONTEXT_vmstatus)
r1 = #SAFEMEM_R
Expand Down Expand Up @@ -99,7 +99,7 @@ FUNC_START H2K_futex_wait .text.core.futex .p2align 5
jump H2K_dosched
}
.Lwait_fail:
k0unlock
ASM_BKL_UNLOCK(r6, r7, r8, p0)
{
r0 = #-1
dealloc_return
Expand All @@ -109,7 +109,7 @@ FUNC_START H2K_futex_wait .text.core.futex .p2align 5
r0 = ME
call H2K_vm_do_work_withlock
}
k0unlock
ASM_BKL_UNLOCK(r6, r7, r8, p0)
{
r0 = #-1
dealloc_return
Expand Down Expand Up @@ -175,7 +175,7 @@ FUNC_START H2K_futex_resume .text.core.futex .falign
RING = tableidxw(HASH,#FUTEX_HASHBITS,#32-FUTEX_HASHBITS)
PA_LO_SAV = PA_LO
}
k0lock
ASM_BKL_LOCK(r6, r7, r8, p0)
{
TMP = memw(RING)
}
Expand Down Expand Up @@ -208,7 +208,7 @@ FUNC_START H2K_futex_resume .text.core.futex .falign
jump H2K_check_sanity_unlock
}
.Lresume_unlock_null:
k0unlock
ASM_BKL_UNLOCK(r6, r7, r8, p0)
.Lresume_null:
{
r0 = #0
Expand Down
10 changes: 5 additions & 5 deletions kernel/futex/futex_pi/futex_pi.v4opt.S
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ FUNC_START H2K_futex_lock_pi .text.core.futex .p2align 5
ME_LOCK = combine(r1,r0)
DEST = #H2K_VMSTATUS_VMWORK
}
k0lock
ASM_BKL_LOCK(r6, r7, r8, p0)
{
TMP = memub(ME+#CONTEXT_vmstatus)
r1 = #SAFEMEM_RW
Expand Down Expand Up @@ -316,13 +316,13 @@ FUNC_START H2K_futex_lock_pi .text.core.futex .p2align 5
deallocframe
}
.Ldone:
k0unlock
ASM_BKL_UNLOCK(r6, r7, r8, p0)
{
r0 = #0
dealloc_return
}
.Llpi_unlock_retfail:
k0unlock
ASM_BKL_UNLOCK(r6, r7, r8, p0)
{
r0 = #-1
dealloc_return
Expand All @@ -332,7 +332,7 @@ FUNC_START H2K_futex_lock_pi .text.core.futex .p2align 5
call H2K_vm_do_work_withlock
r0 = ME
}
k0unlock
ASM_BKL_UNLOCK(r6, r7, r8, p0)
{
r0 = #-1
dealloc_return
Expand Down Expand Up @@ -370,7 +370,7 @@ FUNC_START H2K_futex_unlock_pi .text.core.futex .p2align 5
allocframe(#8)
ME_LOCK = combine(r1,r0)
}
k0lock
ASM_BKL_LOCK(r6, r7, r8, p0)
{
r1 = #SAFEMEM_RW
r3:2 = combine(ME,r29)
Expand Down
5 changes: 4 additions & 1 deletion kernel/init/boot/boot.ref.S
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,13 @@ boot_tcm_offset:
.word 0x0

FUNC_START h2_init .text.init.boot .p2align 2
SETCONST(H2K_GP, H2K_kg)
jumpr r31
FUNC_END h2_init

FUNC_START H2K_handle_reset .text.init.boot .p2align 2
call 1f // initialize r31 for future mutex lock
1:
SETCONST(TMP,_SDA_BASE_)
gp = TMP

Expand All @@ -549,6 +552,6 @@ FUNC_START H2K_handle_reset .text.init.boot .p2align 2
STACK_SIZE = #KERNEL_STACK_SIZE
SP += mpyi(STACK_SIZE, TMP)
r1:0 = #0
k0lock
ASM_BKL_LOCK(r6, r7, r8, p0)
jump H2K_switch
FUNC_END H2K_handle_reset
8 changes: 2 additions & 6 deletions kernel/sched/check_sanity/check_sanity.v3opt.S
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ FUNC_START H2K_check_sanity_unlock .text.core.sanity .p2align 5
}
.falign
2:
{
k0unlock
}
ASM_BKL_UNLOCK(r2, r3, r4, p0)
{
jumpr R31;
}
Expand All @@ -196,9 +194,7 @@ FUNC_START H2K_check_sanity_unlock .text.core.sanity .p2align 5
p0 = and(p0,!p1)
if (!p0.new) jump:t 1b;
}
{
k0unlock
}
ASM_BKL_UNLOCK(r2, r3, r4, p0)
{
jumpr R31;
}
Expand Down
6 changes: 2 additions & 4 deletions kernel/sched/check_sanity/check_sanity.v4opt.S
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ FUNC_START H2K_check_sanity_unlock .text.core.sanity .p2align 5
}
.falign
2:
{
k0unlock
}
ASM_BKL_UNLOCK(r2, r3, r4, p0)
{
jumpr R31
}
Expand All @@ -141,6 +139,6 @@ FUNC_START H2K_check_sanity .text.core.sanity .p2align 3
allocframe(#0)
call H2K_check_sanity_unlock
}
k0lock
ASM_BKL_LOCK(r2, r3, r4, p0)
dealloc_return
FUNC_END H2K_check_sanity
6 changes: 2 additions & 4 deletions kernel/sched/check_sanity/check_sanity.v68opt.S
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ FUNC_START H2K_check_sanity_unlock .text.core.sanity .p2align 5
}
.falign
2:
{
k0unlock
}
ASM_BKL_UNLOCK(r2, r3, r4, p0)
{
jumpr R31
}
Expand All @@ -148,6 +146,6 @@ FUNC_START H2K_check_sanity .text.core.sanity .p2align 3
allocframe(#0)
call H2K_check_sanity_unlock
}
k0lock
ASM_BKL_LOCK(r2, r3, r4, p0)
dealloc_return
FUNC_END H2K_check_sanity
6 changes: 2 additions & 4 deletions kernel/sched/check_sanity/check_sanity.v81opt.S
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ FUNC_START H2K_check_sanity_unlock .text.core.sanity .p2align 5
}
.falign
2:
{
k0unlock
}
ASM_BKL_UNLOCK(r2, r3, r4, p0)
{
jumpr R31
}
Expand All @@ -164,6 +162,6 @@ FUNC_START H2K_check_sanity .text.core.sanity .p2align 3
allocframe(#0)
call H2K_check_sanity_unlock
}
k0lock
ASM_BKL_LOCK(r2, r3, r4, p0)
dealloc_return
FUNC_END H2K_check_sanity
4 changes: 1 addition & 3 deletions kernel/sched/resched/resched.v3opt.S
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ FUNC_START H2K_resched .text.core.resched .p2align 3
{
ciad(r0) // clear IAD
}
{
k0lock // BKL_LOCK(&H2K_bkl)
}
ASM_BKL_LOCK(r6, r7, r8, p0) // BKL_LOCK(&H2K_bkl)
{
p0 = cmp.eq(r1,#0) // me == NULL
if (!p0.new) jump:t .H2K_resched_NOTWAIT // if (me != NULL) then JUMP
Expand Down
4 changes: 1 addition & 3 deletions kernel/sched/resched/resched.v4opt.S
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ FUNC_START H2K_resched .text.core.resched .p2align 3
{
ciad(r0) // clear IAD
}
{
k0lock // BKL_LOCK(&H2K_bkl)
}
ASM_BKL_LOCK(r6, r7, r8, p0) // BKL_LOCK(&H2K_bkl)
{
if (!p0) jump .H2K_resched_NOTWAIT // if (me != NULL) then JUMP
r3 = clrbit(r3,r2) // mask = clrbit(-1, hwtnum)
Expand Down
2 changes: 1 addition & 1 deletion kernel/sched/switch/switch.ref.S
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ FUNC_START H2K_switch .text.core.switch .p2align 5
r8 = setbit(r8,r5)
memw(H2K_GP+#KG_wait_mask) = r9
memw(H2K_GP+#KG_priomask) = r8
k0unlock
ASM_BKL_UNLOCK(r6, r7, r8, p0)
// set SGP to NULL
sgp0 = r1

Expand Down
Loading
Loading