From 49733547f194a0af8b589dcae5925d5f5668e252 Mon Sep 17 00:00:00 2001 From: "C. Masloch" Date: Sat, 21 May 2022 15:22:48 +0200 Subject: [PATCH] kernel, main: add debugger_present variable and skip ints 0, 1, 3, 6 Also adds a CheckDebugger byte to the CONFIG block and support for reading and writing this setting in the SYS CONFIG program. Default is 0 (no check assume absent). --- hdr/kconfig.h | 4 ++++ kernel/kernel.asm | 20 ++++++++++++++++++++ kernel/main.c | 14 +++++++++----- sys/fdkrncfg.c | 17 +++++++++++++++-- 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/hdr/kconfig.h b/hdr/kconfig.h index 74ac683..160a34a 100644 --- a/hdr/kconfig.h +++ b/hdr/kconfig.h @@ -46,4 +46,8 @@ typedef struct _KernelConfig { unsigned short Version_Revision; unsigned short Version_Release; + unsigned char CheckDebugger; + /* 0 = do not check (assume absent), + 1 = do check by running breakpoint, + 2 = assume present */ } KernelConfig; diff --git a/kernel/kernel.asm b/kernel/kernel.asm index aefa6eb..29a0173 100644 --- a/kernel/kernel.asm +++ b/kernel/kernel.asm @@ -76,6 +76,7 @@ Version_Major db 2 Version_Revision dw 41 ; REVISION_SEQ Version_Release dw 1 ; 0=release build, >0=svn# +CheckDebugger: db 0 ; 0 = no check, 1 = check, 2 = assume present configend: kernel_config_size: equ configend - config_signature ; must be below-or-equal the size of struct _KernelConfig @@ -253,6 +254,25 @@ extern _InitKernelConfig %endif mov ds, ax ; => init data segment +check_debugger_present: +extern _debugger_present + + mov al, 1 ; assume debugger present + cmp byte [di - kernel_config_size + (CheckDebugger - config_signature)], 1 + ja .skip_ints_00_06 ; 2 means assume present + jb .absent ; 0 means assume absent + clc ; 1 means check + int3 ; break to debugger + jc .skip_ints_00_06 + ; The debugger should set CY here to indicate its + ; presence. The flag set is checked later to skip + ; overwriting the interrupt vectors 00h, 01h, 03h, + ; and 06h. This logic is taken from lDOS init. +.absent: + xor ax, ax ; no debugger present +.skip_ints_00_06: + mov byte [_debugger_present], al + jmp _FreeDOSmain %if XCPU != 86 diff --git a/kernel/main.c b/kernel/main.c index 4b5cdb9..ffd14e8 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -69,6 +69,9 @@ __segment DosTextSeg = 0; struct lol FAR *LoL = &DATASTART; struct _KernelConfig InitKernelConfig = { 0xFF }; +UBYTE debugger_present = 0xFF; /* initialised in kernel.asm + do NOT set 0 here or compiler may + move it into bss that we zero out */ VOID ASMCFUNC FreeDOSmain(void) { @@ -235,10 +238,10 @@ STATIC void setup_int_vectors(void) } vectors[] = { /* all of these are in the DOS DS */ - { 0x0, FP_OFF(int0_handler) }, /* zero divide */ - { 0x1, FP_OFF(empty_handler) }, /* single step */ - { 0x3, FP_OFF(empty_handler) }, /* debug breakpoint */ - { 0x6, FP_OFF(int6_handler) }, /* invalid opcode */ + { 0x80 | 0x0, FP_OFF(int0_handler) }, /* zero divide */ + { 0x80 | 0x1, FP_OFF(empty_handler) }, /* single step */ + { 0x80 | 0x3, FP_OFF(empty_handler) }, /* debug breakpoint */ + { 0x80 | 0x6, FP_OFF(int6_handler) }, /* invalid opcode */ { 0x19, FP_OFF(int19_handler) }, /* BIOS bootstrap loader, vdisk */ { 0x20, FP_OFF(int20_handler) }, { 0x21, FP_OFF(int21_handler) }, /* primary DOS API */ @@ -264,7 +267,8 @@ STATIC void setup_int_vectors(void) setvec(i, empty_handler); /* note: int 31h segment should be DOS DS */ HaltCpuWhileIdle = 0; for (pvec = vectors; pvec < vectors + (sizeof vectors/sizeof *pvec); pvec++) - setvec(pvec->intno, (intvec)MK_FP(FP_SEG(empty_handler), pvec->handleroff)); + if ((pvec->intno & 0x80) == 0 || debugger_present == 0) + setvec(pvec->intno & 0x7F, (intvec)MK_FP(FP_SEG(empty_handler), pvec->handleroff)); pokeb(0, 0x30 * 4, 0xea); pokel(0, 0x30 * 4 + 1, (ULONG)cpm_entry); diff --git a/sys/fdkrncfg.c b/sys/fdkrncfg.c index 3c32782..7bec735 100644 --- a/sys/fdkrncfg.c +++ b/sys/fdkrncfg.c @@ -13,7 +13,7 @@ * merged into SYS by tom ehlert * ***************************************************************************/ -char VERSION[] = "v1.02"; +char VERSION[] = "v1.03"; char PROGRAM[] = "SYS CONFIG"; char KERNEL[] = "KERNEL.SYS"; @@ -93,7 +93,8 @@ void showUsage(void) printf(" Current Options are: DLASORT=0|1, SHOWDRIVEASSIGNMENT=0|1\n" " SKIPCONFIGSECONDS=#, FORCELBA=0|1\n" " GLOBALENABLELBASUPPORT=0|1\n" - " BootHarddiskSeconds=0|seconds to wait\n"); + " BootHarddiskSeconds=0|seconds to wait\n" + " CheckDebugger=0|1|2\n"); } /* simply reads in current configuration values, exiting program @@ -215,6 +216,13 @@ void displayConfigSettings(KernelConfig * cfg) cfg->BootHarddiskSeconds); } + if (cfg->ConfigSize >= 13) + { + printf + ("CheckDebugger=%d : *0=no, 1=check, 2=assume\n", + cfg->CheckDebugger); + } + #if 0 /* we assume that SYS is as current as the kernel */ /* Print value any options added that are unknown as hex dump */ @@ -482,6 +490,11 @@ int FDKrnConfigMain(int argc, char **argv) setSByteOption(&(cfg.BootHarddiskSeconds), cptr, 0, 127, &updates, "BootHarddiskSeconds"); } + else if (memicmp(argptr, "CheckDebugger", 5) == 0) + { + setByteOption(&(cfg.CheckDebugger), + cptr, 2, &updates, "CheckDebugger"); + } else { illegal_arg: