clean up magic constants
This commit is contained in:
parent
be42a9c3ec
commit
3a0664e186
|
@ -28,7 +28,7 @@ pixel-on-real-screen: # x: int, y: int, color: int
|
||||||
c1/shift 4/subop/left %eax 0xa/imm8
|
c1/shift 4/subop/left %eax 0xa/imm8
|
||||||
03/add-> *(ebp+8) 0/r32/eax
|
03/add-> *(ebp+8) 0/r32/eax
|
||||||
# eax += location of frame buffer
|
# eax += location of frame buffer
|
||||||
03/add-> *0x8128 0/r32/eax # unsafe
|
03/add-> *Video-memory-addr 0/r32/eax
|
||||||
# *eax = color
|
# *eax = color
|
||||||
8b/-> *(ebp+0x10) 1/r32/ecx
|
8b/-> *(ebp+0x10) 1/r32/ecx
|
||||||
88/byte<- *eax 1/r32/CL
|
88/byte<- *eax 1/r32/CL
|
||||||
|
|
|
@ -19,20 +19,19 @@ read-key: # kbd: (addr keyboard) -> result/eax: byte
|
||||||
81 7/subop/compare %ecx 0/imm32
|
81 7/subop/compare %ecx 0/imm32
|
||||||
{
|
{
|
||||||
75/jump-if-!= break/disp8
|
75/jump-if-!= break/disp8
|
||||||
# var read/ecx: byte = keyboard buffer's read index
|
# var buffer-byte-addr/ecx: (addr byte)
|
||||||
8b/-> *0x802c 1/r32/CL # keyboard-buffer-read
|
8b/-> *Keyboard-buffer:read 1/r32/CL
|
||||||
# var next-key/eax: byte = *(keyboard buffer + ecx)
|
81 0/subop/add %ecx Keyboard-buffer:data/imm32
|
||||||
8a/byte-> *(ecx+0x8030) 0/r32/AL # keyboard-buffer-data
|
# var next-key/eax: byte = *buffer-byte-addr
|
||||||
|
8a/byte-> *ecx 0/r32/AL
|
||||||
# if (next-key != 0) lock and remove from keyboard buffer
|
# if (next-key != 0) lock and remove from keyboard buffer
|
||||||
81 7/subop/compare %eax 0/imm32
|
81 7/subop/compare %eax 0/imm32
|
||||||
{
|
{
|
||||||
74/jump-if-= break/disp8
|
74/jump-if-= break/disp8
|
||||||
# TODO: add some instructions in this block to SubX if we ever want to
|
|
||||||
# use bootstrap on baremetal programs
|
|
||||||
fa/disable-interrupts
|
fa/disable-interrupts
|
||||||
c6 0/subop/copy-byte *(ecx+0x8030) 0/imm8 # keyboard-buffer-data
|
c6 0/subop/copy-byte *ecx 0/imm8
|
||||||
ff 0/subop/increment *0x802c # keyboard-buffer-read
|
ff 0/subop/increment *Keyboard-buffer:read
|
||||||
81 4/subop/and *0x802c 0xf/imm32 # keyboard-buffer-read
|
81 4/subop/and *Keyboard-buffer:read 0x0f/imm32
|
||||||
fb/enable-interrupts
|
fb/enable-interrupts
|
||||||
}
|
}
|
||||||
# return
|
# return
|
||||||
|
|
|
@ -27,7 +27,7 @@ draw-grapheme-on-real-screen: # g: grapheme, x: int, y: int, color: int, backgr
|
||||||
# var letter-bitmap/esi = font[g]
|
# var letter-bitmap/esi = font[g]
|
||||||
8b/-> *(ebp+8) 6/r32/esi
|
8b/-> *(ebp+8) 6/r32/esi
|
||||||
c1 4/subop/shift-left %esi 4/imm8
|
c1 4/subop/shift-left %esi 4/imm8
|
||||||
8d/copy-address *(esi+0x8c00) 6/r32/esi # font-start
|
81 0/subop/add %esi Font/imm32
|
||||||
# if (letter-bitmap >= 0x9400) return # characters beyond ASCII currently not supported
|
# if (letter-bitmap >= 0x9400) return # characters beyond ASCII currently not supported
|
||||||
81 7/subop/compare %esi 0x9400/imm32
|
81 7/subop/compare %esi 0x9400/imm32
|
||||||
7d/jump-if->= $draw-grapheme-on-real-screen:end/disp8
|
7d/jump-if->= $draw-grapheme-on-real-screen:end/disp8
|
||||||
|
|
77
boot.subx
77
boot.subx
|
@ -11,28 +11,7 @@
|
||||||
# - sigils only support 32-bit general-purpose registers, so don't work with segment registers or 16-bit or 8-bit registers
|
# - sigils only support 32-bit general-purpose registers, so don't work with segment registers or 16-bit or 8-bit registers
|
||||||
# - metadata like rm32 and r32 can sometimes misleadingly refer to only the bottom 16 bits of the register; pay attention to the register name
|
# - metadata like rm32 and r32 can sometimes misleadingly refer to only the bottom 16 bits of the register; pay attention to the register name
|
||||||
|
|
||||||
# Outline of this file with offsets and the addresses they map to at run-time:
|
# Memory map of a Mu computer:
|
||||||
# -- 16-bit mode code
|
|
||||||
# offset 0 (address 7c00): boot code
|
|
||||||
# -- 16-bit mode data
|
|
||||||
# e0 (address 7c80) global descriptor table
|
|
||||||
# f8 (address 7ca0) <== gdt_descriptor
|
|
||||||
# -- 32-bit mode code
|
|
||||||
# offset 100 (address 7d00): boot code
|
|
||||||
# 1fe (address 7dfe) boot-sector-marker (2 bytes)
|
|
||||||
# offset 200 (address 7e00): interrupt handler code
|
|
||||||
# -- 32-bit mode data
|
|
||||||
# offset 400 (address 8000): handler data
|
|
||||||
# 410 (address 8010): keyboard handler data
|
|
||||||
# 428 (address 8028) <== keyboard buffer
|
|
||||||
# offset 500 (address 8100): video mode data (256 bytes)
|
|
||||||
# 528 (address 8128) <== start of video RAM stored here
|
|
||||||
# offset 600 (address 8200): interrupt descriptor table (1KB)
|
|
||||||
# offset a00 (address 8600): keyboard mappings (1.5KB)
|
|
||||||
# offset 1000 (address 8c00): bitmap font (2KB)
|
|
||||||
# offset 1800 (address 9400): entrypoint for applications (don't forget to adjust survey_baremetal if this changes)
|
|
||||||
|
|
||||||
# Other details of the current memory map:
|
|
||||||
# code: 4 tracks of disk to [0x00007c00, 0x00027400)
|
# code: 4 tracks of disk to [0x00007c00, 0x00027400)
|
||||||
# stack grows down from 0x00070000
|
# stack grows down from 0x00070000
|
||||||
# see below
|
# see below
|
||||||
|
@ -40,6 +19,9 @@
|
||||||
# see 120allocate.subx
|
# see 120allocate.subx
|
||||||
# Consult https://wiki.osdev.org/Memory_Map_(x86) before modifying any of this.
|
# Consult https://wiki.osdev.org/Memory_Map_(x86) before modifying any of this.
|
||||||
|
|
||||||
|
# Magic addresses (TODO):
|
||||||
|
# 0x9400: entrypoint for applications
|
||||||
|
|
||||||
== code
|
== code
|
||||||
|
|
||||||
## 16-bit entry point
|
## 16-bit entry point
|
||||||
|
@ -298,16 +280,12 @@ keyboard-interrupt-handler:
|
||||||
a8/test-bits-in-al 0x01/imm8 # set zf if bit 0 (least significant) is not set
|
a8/test-bits-in-al 0x01/imm8 # set zf if bit 0 (least significant) is not set
|
||||||
74/jump-if-not-set $keyboard-interrupt-handler:epilogue/disp8
|
74/jump-if-not-set $keyboard-interrupt-handler:epilogue/disp8
|
||||||
# - if keyboard buffer is full, return
|
# - if keyboard buffer is full, return
|
||||||
# var index/ecx: byte
|
# var dest-addr/ecx: (addr byte) = (keyboard-buffer + *keyboard-buffer:write)
|
||||||
31/xor %ecx 1/r32/ecx
|
31/xor %ecx 1/r32/ecx
|
||||||
8a/byte-> *Keyboard-buffer:write 1/r32/cl
|
8a/byte-> *Keyboard-buffer:write 1/r32/cl
|
||||||
== data
|
81 0/subop/add %ecx Keyboard-buffer:data/imm32
|
||||||
# al = *(keyboard buffer + index)
|
# al = *dest-addr
|
||||||
#? 8a/byte-> *(ecx+Keyboard-buffer:data) 0/r32/al
|
8a/byte-> *ecx 0/r32/al
|
||||||
8a # copy m8 at r32 to r8
|
|
||||||
81 # 10/mod/*+disp32 000/r8/al 001/rm32/ecx
|
|
||||||
30 80 00 00 # disp32 [label]
|
|
||||||
== code
|
|
||||||
# if (al != 0) return
|
# if (al != 0) return
|
||||||
3c/compare-al-and 0/imm8
|
3c/compare-al-and 0/imm8
|
||||||
75/jump-if-!= $keyboard-interrupt-handler:epilogue/disp8
|
75/jump-if-!= $keyboard-interrupt-handler:epilogue/disp8
|
||||||
|
@ -374,47 +352,29 @@ keyboard-interrupt-handler:
|
||||||
{
|
{
|
||||||
81 7/subop/compare *Keyboard-shift-pressed? 0/imm32
|
81 7/subop/compare *Keyboard-shift-pressed? 0/imm32
|
||||||
74/jump-if-= break/disp8
|
74/jump-if-= break/disp8
|
||||||
== data
|
# sigils don't currently support labels inside *(eax+label)
|
||||||
# al <- *(keyboard shift map + eax)
|
05/add-to-eax Keyboard-shift-map/imm32
|
||||||
#? 8a/byte-> *(eax+Keyboard-shift-map) 0/r32/al
|
8a/byte-> *eax 0/r32/al
|
||||||
8a # copy m8 at rm32 to r8
|
|
||||||
80 # 10/mod/*+disp32 000/r8/al 000/rm32/eax
|
|
||||||
00 87 00 00 # disp32 [label]
|
|
||||||
== code
|
|
||||||
eb/jump $keyboard-interrupt-handler:select-map-done/disp8
|
eb/jump $keyboard-interrupt-handler:select-map-done/disp8
|
||||||
}
|
}
|
||||||
# if (ctrl) use keyboard ctrl map
|
# if (ctrl) al = *(ctrl map + al)
|
||||||
{
|
{
|
||||||
81 7/subop/compare *Keyboard-ctrl-pressed? 0/imm32
|
81 7/subop/compare *Keyboard-ctrl-pressed? 0/imm32
|
||||||
74/jump-if-= break/disp8
|
74/jump-if-= break/disp8
|
||||||
== data
|
05/add-to-eax Keyboard-ctrl-map/imm32
|
||||||
# al <- *(keyboard ctrl map + eax)
|
8a/byte-> *eax 0/r32/al
|
||||||
#? 8a/byte-> *(eax+Keyboard-shift-map) 0/r32/al
|
|
||||||
8a # copy m8 at rm32 to r8
|
|
||||||
80 # 10/mod/*+disp32 000/r8/al 000/rm32/eax
|
|
||||||
00 88 00 00 # disp32 [label]
|
|
||||||
== code
|
|
||||||
eb/jump $keyboard-interrupt-handler:select-map-done/disp8
|
eb/jump $keyboard-interrupt-handler:select-map-done/disp8
|
||||||
}
|
}
|
||||||
== data
|
# otherwise al = *(normal map + al)
|
||||||
# otherwise use keyboard normal map
|
05/add-to-eax Keyboard-normal-map/imm32
|
||||||
# al <- *(keyboard normal map + eax)
|
8a/byte-> *eax 0/r32/al
|
||||||
#? 8a/byte-> *(eax+Keyboard-normal-map) 0/r32/al
|
|
||||||
8a # copy m8 at rm32 to r8
|
|
||||||
80 # 10/mod/*+disp32 000/r8/al 000/rm32/eax
|
|
||||||
00 86 00 00 # disp32 [label]
|
|
||||||
== code
|
|
||||||
$keyboard-interrupt-handler:select-map-done:
|
$keyboard-interrupt-handler:select-map-done:
|
||||||
# - if there's no character mapping, return
|
# - if there's no character mapping, return
|
||||||
{
|
{
|
||||||
3c/compare-al-and 0/imm8
|
3c/compare-al-and 0/imm8
|
||||||
74/jump-if-= break/disp8
|
74/jump-if-= break/disp8
|
||||||
# - store al in keyboard buffer
|
# - store al in keyboard buffer
|
||||||
== data
|
88/<- *ecx 0/r32/al
|
||||||
88 # copy r8 to m8 at r32
|
|
||||||
81 # 10/mod/*+disp32 000/r8/al 001/rm32/ecx
|
|
||||||
30 80 00 00 # disp32 [label]
|
|
||||||
== code
|
|
||||||
# increment index
|
# increment index
|
||||||
fe/increment-byte *Keyboard-buffer:write
|
fe/increment-byte *Keyboard-buffer:write
|
||||||
# clear top nibble of index (keyboard buffer is circular)
|
# clear top nibble of index (keyboard buffer is circular)
|
||||||
|
@ -494,6 +454,7 @@ Video-mode-info:
|
||||||
00 00 # rsv_mask rsv_position
|
00 00 # rsv_mask rsv_position
|
||||||
00 # directcolor_attributes
|
00 # directcolor_attributes
|
||||||
# 28
|
# 28
|
||||||
|
Video-memory-addr:
|
||||||
00 00 00 00 # physbase <== linear frame buffer
|
00 00 00 00 # physbase <== linear frame buffer
|
||||||
|
|
||||||
# 2c
|
# 2c
|
||||||
|
|
2
ex2.subx
2
ex2.subx
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
main:
|
main:
|
||||||
# ecx <- start of video memory
|
# ecx <- start of video memory
|
||||||
8b/-> *0x8128 1/r32/ecx
|
8b/-> *Video-memory-addr 1/r32/ecx
|
||||||
|
|
||||||
# eax <- final pixel of video memory
|
# eax <- final pixel of video memory
|
||||||
8d/copy-address *(ecx + 0x0bffff) 0/r32/eax # 0xbffff = 1024*768 - 1
|
8d/copy-address *(ecx + 0x0bffff) 0/r32/eax # 0xbffff = 1024*768 - 1
|
||||||
|
|
Loading…
Reference in New Issue