From f5590e7f5d7abb77ce31e5b7436a8d3a8c2037ec Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sat, 18 Aug 2018 19:44:23 +0200 Subject: [PATCH] move kernel constants/macros to its own include --- inc/kernel.inc | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ inc/main.inc | 30 ------------------------- kernel.asm | 31 ------------------------- main.asm | 1 + 4 files changed, 62 insertions(+), 61 deletions(-) create mode 100644 inc/kernel.inc diff --git a/inc/kernel.inc b/inc/kernel.inc new file mode 100644 index 0000000..bdff4cd --- /dev/null +++ b/inc/kernel.inc @@ -0,0 +1,61 @@ +// "kernel" constants: +constant K_BASE(0x8000) // k0 is set to this. + +constant K_DUMP(0x0400) // we save registers and state here + // when handling interrupts + +constant K_REASON(0x0600) +constant K_CAUSE(0x0604) +constant K_STATUS(0x0608) +constant K_IN_MAIN(0x060C) +constant K_EPC(0x0610) +constant K_ERRORPC(0x0614) +constant K_BADVADDR(0x0618) + +constant K_64DRIVE_MAGIC(0x0700) +constant K_CI_BASE(0x0704) +constant K_CONSOLE_AVAILABLE(0x0708) + +constant K_STACK(0x0C00 - 0x10) +constant K_XXD(0x0C00) // size: 0x400 (any larger and you overwrite kernel code) + +// note this gets subtracted by 0x10 and the stack grows *backwards.* +constant K_STACK_INIT_BASE(0x803F) + +// internal interrupt enum: (0 means no known interrupt/exception) +constant K_INT_TLB_REFILL(1) +constant K_INT_XTLB_REFILL(2) +constant K_INT_CACHE_ERROR(3) +constant K_INT_OTHER(4) + +macro KDumpString(name) { + // does not include error/console-checking! + // note: this first instruction must be okay to be in a delay slot. + la a2, {name} + jal Drive64WriteDirect + lli a3, {name}X - {name} +} + +macro KMaybeDumpString(str) { + lw t1, K_CONSOLE_AVAILABLE(k0) + beqz t1,+ + KDumpString({str}) ++ +} + +macro KString(name, str) { + align(16) +{name}: + db {str}, 0 + align(16) +{name}X: +} + +macro KStringLine(name, str) { + align(16) +{name}: + db {str}, 10, 0 + align(16) +{name}X: +} + diff --git a/inc/main.inc b/inc/main.inc index 3acc208..b15a209 100644 --- a/inc/main.inc +++ b/inc/main.inc @@ -5,36 +5,6 @@ constant K_DEBUG(1) // slows down interrupt handling to enable debug routines constant UNCACHED(0xA0000000) constant ADDR_MASK(0x1FFFFFFF) -// "kernel" constants: -constant K_BASE(0x8000) // k0 is set to this. - -constant K_DUMP(0x0400) // we save registers and state here - // when handling interrupts - -constant K_REASON(0x0600) -constant K_CAUSE(0x0604) -constant K_STATUS(0x0608) -constant K_IN_MAIN(0x060C) -constant K_EPC(0x0610) -constant K_ERRORPC(0x0614) -constant K_BADVADDR(0x0618) - -constant K_64DRIVE_MAGIC(0x0700) -constant K_CI_BASE(0x0704) -constant K_CONSOLE_AVAILABLE(0x0708) - -constant K_STACK(0x0C00 - 0x10) -constant K_XXD(0x0C00) // size: 0x400 (any larger and you overwrite kernel code) - -// note this gets subtracted by 0x10 and the stack grows *backwards.* -constant K_STACK_INIT_BASE(0x803F) - -// internal interrupt enum: (0 means no known interrupt/exception) -constant K_INT_TLB_REFILL(1) -constant K_INT_XTLB_REFILL(2) -constant K_INT_CACHE_ERROR(3) -constant K_INT_OTHER(4) - constant BLAH_BASE(0x803F) constant BLAH_COUNTS(0x0010) constant BLAH_SP_TASK(0x0040) diff --git a/kernel.asm b/kernel.asm index c8f17f4..5f805ab 100644 --- a/kernel.asm +++ b/kernel.asm @@ -1,37 +1,6 @@ // not really a kernel, // just handling some low-level stuff like interrupts. -macro KDumpString(name) { - // does not include error/console-checking! - // note: this first instruction must be okay to be in a delay slot. - la a2, {name} - jal Drive64WriteDirect - lli a3, {name}X - {name} -} - -macro KMaybeDumpString(str) { - lw t1, K_CONSOLE_AVAILABLE(k0) - beqz t1,+ - KDumpString({str}) -+ -} - -macro KString(name, str) { - align(16) -{name}: - db {str}, 0 - align(16) -{name}X: -} - -macro KStringLine(name, str) { - align(16) -{name}: - db {str}, 10, 0 - align(16) -{name}X: -} - Start: mtc0 r0, CP0_Cause // clear cause lui gp, K_BASE diff --git a/main.asm b/main.asm index 8aaa931..f4b9384 100644 --- a/main.asm +++ b/main.asm @@ -18,6 +18,7 @@ insert "bin/6102.bin" include "inc/main.inc" +include "inc/kernel.inc" include "kernel.asm" nops(0x80010000)