Skip to content

Commit

Permalink
kernel, main: add debugger_present variable and skip ints 0, 1, 3, 6
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
ecm-pushbx authored and PerditionC committed May 22, 2022
1 parent 7ff6c06 commit 4973354
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
4 changes: 4 additions & 0 deletions hdr/kconfig.h
Expand Up @@ -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;
20 changes: 20 additions & 0 deletions kernel/kernel.asm
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions kernel/main.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 */
Expand All @@ -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);

Expand Down
17 changes: 15 additions & 2 deletions sys/fdkrncfg.c
Expand Up @@ -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";

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 4973354

Please sign in to comment.