Patching OS/2 for fast machines

From Computer History Wiki
Jump to: navigation, search

This was just posted today on OS/2 Museum... This is needed for all 1.x series versions of OS/2 for fast machines, regardless if they are being emulated or not.

The crash is a division by zero (trap 0) on a DIV CX instruction where the CX register contains zero. The way around this problem is patching OS/2 and getting rid of the bad loop. The original code sequence looks like this:

    MOV  DX, 3
L1:
    XOR  CX, CX
L2:
    LOOP L2        ; loop 65,536 times
    DEC  DX        ; run the loop 3 times
    JNE  L1
    CLI
    ...            ; read current tick
    STI
    SUB  CX, BX
    MOV  AX, 1F4h  ; 500
    MOV  BX, 0C8h  ; 200
    MUL  BX        ; 500 * 200 = 100,000
    DIV  CX        ; traps if CX = 0
    SHR  CX, 1

This obviously became a problem as far back as 1991, because OS/2 1.30.1 contains slightly different code:

    MOV  BX, 0C8h ; 200
    MUL  BX
    CMP  CX, 0
    JNE  L3
    MOV  CX, 1Fh  ; 31
L3:
    DIV  CX

In other words, if CX is zero, it is forced to a non-zero value to avoid the division by zero trap.

As it turns out, the MOV/MOV/MUL/DIV instruction sequence is quite unique and occurs only in the BASEDD0x.SYS drivers. To avoid the crash, it is sufficient to remove the DIV instruction, replacing it by NOPs.

It's simple enough to do in HEX.

So basically change this:

B8F401BBC800F7E3F7F1

into this:

B8F401BBC800F7E39090