Skip to content

Commit

Permalink
sys: fix, work on DOS versions that clobber di in int 25h/26h
Browse files Browse the repository at this point in the history
Running on DR-DOS v7.03, the int 25h call zeroes di leading to a crash
here when di is expected to preserve the stack pointer. So push di twice
and pop it twice. The second pop always gets the saved sp, regardless of
whether int 21h or int 25h/26h are used.

Refer to SvarDOS/edrdos#57 (comment)
  • Loading branch information
ecm-pushbx committed May 19, 2024
1 parent 1ce349e commit ceaaaea
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion country
Submodule country updated 1 files
+1 −6 Makefile
2 changes: 1 addition & 1 deletion share
7 changes: 6 additions & 1 deletion sys/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ int int86(int ivec, union REGS *in, union REGS *out)
{
/* must save sp for int25/26 */
asm("mov %5, (1f+1); jmp 0f; 0:push %%ds; mov %%di, %%dx; mov %%sp, %%di;"
"1:int $0x00; mov %%di, %%sp; pop %%ds; sbb %0, %0" :
"push %%di; push %%di;"
/* push twice to work both for int 25h/26h and int 21h */
"1:int $0x00; pop %%di; pop %%di;"
/* second pop always reads the correct SP value.
the first pop may read the FL left on stack. */
"mov %%di, %%sp; pop %%ds; sbb %0, %0" :
"=r"(out->x.cflag),
"=a"(out->x.ax), "=b"(out->x.bx), "=c"(out->x.cx), "=d"(out->x.dx) :
"q"((unsigned char)ivec), "a"(in->x.ax), "b"(in->x.bx),
Expand Down

0 comments on commit ceaaaea

Please sign in to comment.