diff --git a/rtl/inc/systemh.inc b/rtl/inc/systemh.inc index fb83798478..95b56afd9b 100644 --- a/rtl/inc/systemh.inc +++ b/rtl/inc/systemh.inc @@ -567,8 +567,8 @@ const {$endif cpui386} {$ifdef cpui8086} { will be detected at startup } - { 0=8086, 1=80286, 2=80386 } - Test8086 : byte = 0; + { 0=8086/8088/80186/80188/NEC V20/NEC V30, 1=80286, 2=80386 or newer } + Test8086 : byte = 0; public name '__Test8086'; { Always 387 or newer. Emulated if needed. } Test8087 : byte = 3; { will be detected at startup } diff --git a/rtl/msdos/prt0stm.asm b/rtl/msdos/prt0stm.asm index a935458534..62ca355590 100644 --- a/rtl/msdos/prt0stm.asm +++ b/rtl/msdos/prt0stm.asm @@ -19,6 +19,7 @@ extern PASCALMAIN extern dos_psp extern dos_version + extern __Test8086 extern _edata ; defined by WLINK, indicates start of BSS extern _end ; defined by WLINK, indicates end of BSS @@ -68,6 +69,37 @@ no_bss: xchg al, ah mov word [dos_version], ax + ; detect CPU + xor bx, bx ; 0=8086/8088/80186/80188/NEC V20/NEC V30 + ; on pre-286 processors, bits 12..15 of the FLAGS registers are always set + pushf + pop ax + and ah, 0fh + push ax + popf + pushf + pop ax + and ah, 0f0h + cmp ah, 0f0h + je cpu_detect_done + ; at this point we have a 286 or higher + inc bx + ; on a true 286 in real mode, bits 12..15 are always clear + pushf + pop ax + or ah, 0f0h + push ax + popf + pushf + pop ax + and ah, 0f0h + jz cpu_detect_done + ; we have a 386+ + inc bx + +cpu_detect_done: + mov [__Test8086], bl + ; allocate max heap ; TODO: also support user specified heap size ; try to resize our main DOS memory block until the end of the data segment