From 98ce65d99afe369f335f82e8800c9b0d56934d2a Mon Sep 17 00:00:00 2001 From: Stas Sergeev Date: Sat, 14 Oct 2023 02:28:59 +0500 Subject: [PATCH] init DOS_PSP with PGROUP [#172][skip CI] We used to have DOS_PSP=cs, but now we have ELF headers in DOS space. And as we use tiny model, cs:0 inevitably points to them. To not overwrite them with PSP, move DOS_PSP var to kernel.asm and initialize it with PGROUP. This patch makes PGROUP no longer equal to other segments, so this needs a proper segelf support. This can't be done in a master branch where we relocate by a hard-coded value only (0x60). So this patch shows a clear advantage of the segelf scheme usage. Note that even the part of this patch, eg aligning PSP section to 0x100, cannot be back-ported to master because there we store PSP at cs:0 regardless of the linker script, and overwrite whatever is there. And there are the ELF headers now, since commit 95432f82. Which probably shouldn't have been back-ported to master as a start. --- fdpp/kernel.ld | 11 +++++++---- kernel/glob_asm.h | 1 + kernel/kernel.asm | 2 ++ kernel/main.c | 3 --- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/fdpp/kernel.ld b/fdpp/kernel.ld index 4a55230f..94690983 100644 --- a/fdpp/kernel.ld +++ b/fdpp/kernel.ld @@ -5,22 +5,25 @@ SECTIONS _LOADADDR = DEFINED(loadaddr) ? loadaddr : .; /* these GROUPs play the same role as GROUPS (segments) in OMF */ /* TINY model, all segments are equal */ - _PGROUP = ABSOLUTE(.); _LGROUP = ABSOLUTE(.); _DGROUP = ABSOLUTE(.); _IGROUP = ABSOLUTE(.); - _PGROUP~ = . + _LOADADDR; _LGROUP~ = . + _LOADADDR; _DGROUP~ = . + _LOADADDR; _IGROUP~ = . + _LOADADDR; + . = SIZEOF_HEADERS; + . = ALIGN(0x100); /* Target PSP section. */ - .ptext SIZEOF_HEADERS : { + .ptext : { + _PGROUP = ABSOLUTE(.); + _PGROUP~ = . + _LOADADDR; *(PSP) + . = ALIGN(0x100); } /* Target low data+text sections. */ - .ltext 0x200 : { + .ltext : { *(_IRQTEXT) *(_LOWTEXT) *(_IO_TEXT) diff --git a/kernel/glob_asm.h b/kernel/glob_asm.h index fcedbd16..b4e903d2 100644 --- a/kernel/glob_asm.h +++ b/kernel/glob_asm.h @@ -1,5 +1,6 @@ /* grep "ASM " globals.h | grep "extern" | grep ";" | sed 's/extern \(.\+\) ASM \(.\+\);/__ASM(\1, \2) SEMIC/' */ +__ASM(UWORD, DOS_PSP) SEMIC __ASM(UWORD, NetBios) SEMIC __ASM(BYTE *, net_name) SEMIC __ASM(BYTE, net_set_count) SEMIC diff --git a/kernel/kernel.asm b/kernel/kernel.asm index 1a639e24..770e2c14 100644 --- a/kernel/kernel.asm +++ b/kernel/kernel.asm @@ -778,6 +778,8 @@ begin_hma: ; to minimize relocations global _DGROUP_ _DGROUP_ dw DGROUP + global _DOS_PSP +_DOS_PSP dw PGROUP %ifdef WATCOM ; 32 bit multiplication + division diff --git a/kernel/main.c b/kernel/main.c index dd7c5b83..3211eeaf 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -73,8 +73,6 @@ __segment DosTextSeg = 0; #endif -UWORD DOS_PSP; - ASMREF(struct lol) LoL = __ASMADDR(DATASTART); struct _bprm bprm; #define TEXT_SIZE (_InitTextEnd - _HMATextStart) @@ -91,7 +89,6 @@ VOID ASMCFUNC FreeDOSmain(void) DosDataSeg = (__segment) & DATASTART; DosTextSeg = (__segment) & prn_dev; #endif - DOS_PSP = _CS; /* back up kernel code to the top of ram */ lpTop = MK_FP(_SS - (TEXT_SIZE + 15) / 16, 0); fmemcpy(lpTop, _HMATextStart, TEXT_SIZE);