FDOS / freecom

FreeDOS Command Shell (command.com)
http://www.freedos.org/
GNU General Public License v2.0
158 stars 38 forks source link

cswap.asm XMS handling not 8086-clean #15

Closed ecm-pushbx closed 4 years ago

ecm-pushbx commented 5 years ago

While testing my XMS implementation for 8086tiny https://github.com/ecm-pushbx/8086tiny/commit/55bf20380ed1310ac681855c43495fe067ef37fa I came upon several different, reproducable errors produced by different versions of FreeCOM. With a hack to make FreeCOM fail its XMS allocation, everything seemed to work and my own program (lDebug symbolic) successfully used the XMS interface.

I eventually chased the error to the handler that saves to XMS then is meant to jump into the resident portion: https://github.com/FDOS/freecom/blob/274b4a9b74e2371a384e7041dd026dd16dec34dc/shell/cswap.asm#L405

        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

Push with an immediate is a 186+ instruction, but FreeCOM doesn't check for an 186 machine before using it.This likely wasn't noticed because XMS with actual extended memory requires a 286 at least.

ecm-pushbx commented 5 years ago

I suggest that the NASM directive "cpu 8086" should be used to catch these and possibly additional bugs.

ecm-pushbx commented 5 years ago

I disabled my first workaround and implemented the push imm16 instruction in my fork of 8086tiny. Now the XMS swapping works. Refer to https://github.com/ecm-pushbx/8086tiny/commit/c09ef85f799358560c1acb2f00fc63fe688a6f8f

bartoldeman commented 4 years ago

Indeed XMS on a 8086 is nonsense. But forcing cpu 8086 is not a bad idea in other places and there is a better way in any case (a "call far" instruction).

Some code in the cswap.asm is still not 8088-safe but for the above reason I'm not going to fix it (namely that early models did not disable interrupts for one instruction past mov ss, ...)