User:Cerisesky
Testing for 32 bit support on x86
I don't know of any official way to test for 32 bit (>386) support. However, I have experimented with different 386 opcodes to determine support for it. A quick warning that this is definitely undefined behaviour though it has been tested on the 8086 using 86box. The way the code works is by attempting to set ds and fs to the same value, and if it can, then 32 bit is supported since fs is only available on 386+. I have tried other opcodes and methods for determining support, but most of them cause some weird issues or cause the cpu to hang on older machines.
cpu 8086
bits 16
; returns 0 if the processor does not support 32 bit mode.
; returns 1 if it does
; destroys the fs register which should be fine since you aren't
; likely to have used it if you don't know if its even available
test_386:
push ax
push bx
mov ax, ds
push ds
cpu 386
pop fs
mov bx, fs
cpu 8086
cmp ax, bx
je .success
.fail:
mov ax, 0
jmp .end
.success:
mov ax, 1
.end:
pop bx
pop ax
ret
Testing for 186 support
Probably not as important but for completeness I also made a test for 186. Works by attempting to push an immediate value to the stack and checking if anything on the stack actually changed. Also undefined behaviour but tested on 8086 in 86box.
cpu 8086
bits 16
; returns 0 if the processor does not support 186 instructions
; returns 1 if it does
test_186:
push bx
push cx
mov bx, sp
cpu 186
push 0
cpu 8086
mov cx, bx
sub cx, sp
mov sp, bx
cmp cx, 2
je .success
.fail:
mov ax, 0
jmp .end
.success:
mov ax, 1
.end:
pop cx
pop bx
ret