Skip to content

Commit

Permalink
go32: Coming back to 16-bit mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
meithecatte committed Mar 18, 2023
1 parent fc5f85f commit cc36415
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
6 changes: 5 additions & 1 deletion files/asm32.fth
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
( assembler with more conventional syntax, targeting 16 and 32 bits )

( we want to be able to toggle 32bit outside of :code ;code )
variable 32bit 32bit off

vocabulary Assembler
Assembler definitions
variable 32bit 32bit off

: db ( b -- ) c, ; ( easily overrideable )
: dw ( u -- ) dup lobyte db hibyte db ;
Expand Down Expand Up @@ -316,6 +319,7 @@ exception end-exception bad-operands
0 operand lodsd data32 $AD db ;
0 operand cli $FA db ;
0 operand sti $FB db ;
0 operand ret $C3 db ;
0 operand retf $CB db ;
1 operand lgdt 0 mem-op? or-bad-operands
0 mod-r/m-size $0F db $01 db 0 2 oper-reg ;
Expand Down
52 changes: 42 additions & 10 deletions files/go32.fth
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ exception end-exception a20-locked

( GDT )
: entries 8 u* ;
create gdt 3 entries allot
create gdt 5 entries allot

variable access
$80 constant PRESENT
$10 constant ~SPECIAL ( this bit is 0 in some shit like TSS )
$08 constant EXECUTABLE
$02 constant R/W
$02 constant R/W ( R for code segments, W for data segments )

variable flags
$80 constant GRANULARITY
Expand All @@ -78,9 +78,16 @@ PRESENT ~SPECIAL or R/W or EXECUTABLE or access !
PRESENT ~SPECIAL or R/W or access !
10 entry 32bit-ds

GRANULARITY flags !
PRESENT ~SPECIAL or R/W or EXECUTABLE or access !
18 entry 16bit-cs

PRESENT ~SPECIAL or R/W or access !
20 entry 16bit-ds

( GDTR )
gdt pos !
3 entries 1- pos, ( size )
5 entries 1- pos, ( size )
gdt pos, 0 pos, ( address )

:code lgdt
Expand All @@ -91,23 +98,48 @@ gdt pos, 0 pos, ( address )
lgdt
a20

( pmode transition )
( pmode transitions )
:code finish-pmode-exit
xor ax ax
mov ds ax
mov es ax
mov ss ax
;code

:code do-pmode-exit
mov eax cr0
and al $FE #
mov cr0 eax
jmpf 0 # ' finish-pmode-exit #
previous

32bit on

:code pmode-entry
32bit on
mov eax 32bit-ds #
mov ds eax
mov es eax
mov ss eax
mov byte $B8000. [.#] 2 #
EB db FE db
32bit off
;code
movzx esp sp
ret
previous

:code pmode-exit
mov eax 16bit-ds #
mov ds eax
mov es eax
mov ss eax
jmpf 16bit-cs # ' do-pmode-exit #
previous

32bit off

:code (go32)
push bx
mov eax cr0
or al 1 #
mov cr0 eax
jmpf 32bit-cs # ' pmode-entry #
;code

: go32 ( -- ) cli nmi-off (go32) ;
: go32 ( -- ) cli nmi-off (go32) nmi-on sti ;

0 comments on commit cc36415

Please sign in to comment.