Skip to content

Commit

Permalink
Force 8086-asm; use direct call far real_XMSexec instead of push/push…
Browse files Browse the repository at this point in the history
…/retf.

Fixes #15
  • Loading branch information
bartoldeman committed Dec 18, 2019
1 parent a98a53f commit 415cbc9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
3 changes: 1 addition & 2 deletions include/cswap.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ extern unsigned char far dosCMDNAME[128];
/*extern unsigned char far dosCMDTAIL[128];*/
#define dosCMDTAIL ((char far*)MK_FP(_psp, 0x80))

extern word residentCS;

extern int cdecl XMSexec(void);

#ifdef __WATCOMC__
typedef unsigned long xmsfunc(unsigned request, unsigned dx, void *si);
#pragma aux xmsfunc = parm [ax] [dx] [si] modify [bx cx]
extern xmsfunc far *far XMSdriverAdress;
#elif defined(__GNUC__)
extern far void real_XMSexec(void);
extern unsigned far *far XMSdriverAdress;
static inline unsigned long XMSrequest(unsigned request, unsigned dx, void *si)
{
Expand Down
2 changes: 2 additions & 0 deletions include/stuff.inc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
cpu 8086

;; Multi-Push/Pop
;; Both take the registers in the same order, "F"==Flags
;; Push pushes left to right; pop right to left
Expand Down
22 changes: 14 additions & 8 deletions shell/cswap.asm
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ mySP DW 0

execRetval dw 0

; global real_XMSexec
%ifidn __OUTPUT_FORMAT__,elf
cglobal real_XMSexec
%endif
real_XMSexec:
int 21h ; shrink/free: first thing done from resident code

Expand Down Expand Up @@ -320,7 +322,6 @@ XMSrequest:
;; SS at the end of the XMSexec function
cglobal XMSexec
XMSexec:
cextern residentCS
; save ALL registers needed later
%ifidn __OUTPUT_FORMAT__,elf ; GCC: need to preserve es
push es
Expand All @@ -345,7 +346,12 @@ XMSexec:
mov bx,[SwapResidentSize]

mov dx, ds
mov cx, [residentCS]
%ifidn __OUTPUT_FORMAT__,elf ; GCC/ELF: can't use seg so use pointer from C
cextern preal_XMSexec
mov cx, [cs:preal_XMSexec+2]
%else
mov cx, seg mySS
%endif
mov ds, cx

mov [mySS],ss ; 2E
Expand All @@ -355,11 +361,11 @@ XMSexec:
mov sp,localStack

push dx ; save DS of transient portion
push cs ; save segment of transient portion
push WORD ret_from_resident
push cx
push WORD real_XMSexec
retf
%ifidn __OUTPUT_FORMAT__,elf ; GCC/ELF: can't use direct call far
call far [cs:preal_XMSexec]
%else
call far real_XMSexec
%endif

ret_from_resident:
mov ax,[execRetval]
Expand Down
6 changes: 5 additions & 1 deletion shell/cswapc.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ static enum {
,INIT_FAILED
,INIT_SUCCEEDED
} initialized = INIT_NO;
word residentCS;
#ifdef __GNUC__
/* For other compilers this is defined in cswap.asm but NASM can't deal
with relocations in ELF */
void far * far preal_XMSexec __attribute__((section(".text"))) = real_XMSexec;
#endif

int XMSisactive(void)
{ return initialized == INIT_SUCCEEDED;
Expand Down
3 changes: 0 additions & 3 deletions shell/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ int initialize(void)
/* Set up the host environment of COMMAND.COM */

/* Give us shell privileges */
#ifdef FEATURE_XMS_SWAP
residentCS = _CS;
#endif
myPID = _psp;
termAddr = pspTermAddr;
pspTermAddr = terminateFreeCOMHook;
Expand Down

0 comments on commit 415cbc9

Please sign in to comment.