Skip to content

Commit

Permalink
init DOS_PSP with PGROUP [#172][skip CI]
Browse files Browse the repository at this point in the history
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 95432f8.
Which probably shouldn't have been back-ported to master as a start.
  • Loading branch information
stsp committed Oct 15, 2023
1 parent 6eaa59b commit 33a4188
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions fdpp/kernel.ld
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ SECTIONS
{
/* these GROUPs play the same role as GROUPS (segments) in OMF */
/* TINY model, all segments are equal */
_PGROUP = .;
_LGROUP = .;
_DGROUP = .;
_IGROUP = .;

. = SIZEOF_HEADERS;
. = ALIGN(0x100);
/* Target PSP section. */
.ptext SIZEOF_HEADERS : {
.ptext : {
_PGROUP = .;
*(PSP)
. = ALIGN(0x100);
}

/* Target low data+text sections. */
.ltext 0x200 : {
.ltext : {
*(_IRQTEXT)
*(_LOWTEXT)
*(_IO_TEXT)
Expand Down
1 change: 1 addition & 0 deletions kernel/glob_asm.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions kernel/kernel.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit 33a4188

Please sign in to comment.