Cleaned up conditional jump handling

This commit is contained in:
Jeff Parsons 2015-05-04 19:26:06 -07:00 • committed by jeffpar
commit 2784934491
10 changed files with 135 additions and 50 deletions

View file

@ -1,7 +1,7 @@
all: tests.json
tests.rom: tests.nasm
nasm -f bin tests.nasm -l tests.lst -o tests.rom
tests.com: tests.nasm
nasm -f bin tests.nasm -l tests.lst -o tests.com
tests.json: tests.rom
node ../../../modules/filedump/bin/filedump --file=tests.rom --output=tests.json --overwrite
tests.json: tests.com
node ../../../modules/filedump/bin/filedump --file=tests.com --output=tests.json --overwrite

View file

@ -1,21 +1,85 @@
cpu 386
org 0x0000
;
; This file is designed to run as a ROM replacement, but it has a .COM extension because it's
; also designed to run as a COM file under DOS (hence the "org 0x100").
;
org 0x100
section .text
bits 16
DPL0 equ 0
DPL1 equ 1
DPL2 equ 2
DPL3 equ 3
ACC_TYPE_SEG equ 0x1000
ACC_TYPE_CODE equ 0x0800
ACC_TYPE_READABLE equ 0x0200
ACC_TYPE_WRITABLE equ 0x0200
ACC_TYPE_CODE_READABLE equ 0x1a00
ACC_TYPE_DATA_WRITABLE equ 0x1200
EXT_BIG equ 0x0040
SEG_CODE_REAL equ 0xf000
SEG_CODE_PROT equ 0x0008
SEG_DATA_PROT equ 0x0010
CR0_MSW_PE equ 0x0001
;
; descDT defines a descriptor, given a base (%1), limit (%2), type (%3), dpl (%4), and bigness (%5)
;
%macro defDesc 1-5 0,0,0,0
dw (%2 & 0x0000ffff)
dw (%1 & 0x0000ffff)
dw ((%1 & 0x00ff0000) >> 16) | %3 | (%4 << 13)
dw ((%2 & 0x000f0000) >> 16) | %5 | ((%1 & 0xff000000) >> 16)
%endmacro
start: mov eax,0x44332211
mov ecx,0x88776655
mul ecx
div ecx
jnz near goProt
call dword 0xf000:start
times 32768 nop
times 0xfff0-($-$$) nop
romGDT: defDesc 0
defDesc 0x000f0000,0x0000ffff,ACC_TYPE_CODE_READABLE,0
defDesc 0x00000000,0x000fffff,ACC_TYPE_DATA_WRITABLE,0
goProt: lgdt [cs:romGDT]
mov eax,cr0
or eax,CR0_MSW_PE
mov cr0,eax
jmp dword SEG_CODE_PROT:inProt
inProt: mov ax,SEG_DATA_PROT
mov ds,ax
;
; Do some protected-mode tests...
;
goReal: mov eax,cr0
and eax,~CR0_MSW_PE
mov cr0,eax
jmp dword SEG_CODE_REAL:inReal
inReal: or eax,1
jnz start
;
; Fill the remaining space with NOPs until we get to target offset 0xFFF0.
;
; Note that we subtract 0x100 from the target offset because we're ORG'ed at 0x100.
;
times 0xfff0-0x100-($-$$) nop
bits 16
jmp 0xf000:start
jmp SEG_CODE_REAL:start
db 0x20
db '04/04/15'