120 lines
1.5 KiB
ArmAsm
120 lines
1.5 KiB
ArmAsm
[org 0x100]
|
|
[bits 16]
|
|
|
|
cli
|
|
mov ax, ds
|
|
mov [torm+3], ax
|
|
mov gs, ax
|
|
mov [oldss], ss
|
|
mov [oldsp], sp
|
|
|
|
in al, 0x92
|
|
or al, 2
|
|
out 0x92, al
|
|
|
|
; TODO maybe choose a better entrypoint than the start of hma
|
|
cld
|
|
mov cx, 65280-bindat
|
|
mov si, bindat
|
|
mov ax, 0xFFFF
|
|
mov es, ax
|
|
mov di, 0x10
|
|
rep movsb
|
|
|
|
; relocate jump target
|
|
xor eax, eax
|
|
mov ax, ds
|
|
shl eax, 4
|
|
|
|
add [gdt+2], eax
|
|
add [gdt_end+2], eax
|
|
|
|
mov [gds+2], ax
|
|
mov [gds16+2], ax
|
|
mov [gcs16+2], ax
|
|
shr eax, 16
|
|
mov [gds+4], al
|
|
mov [gds16+4], al
|
|
mov [gcs16+4], al
|
|
|
|
lgdt [gdt]
|
|
mov eax, cr0
|
|
or al, 1
|
|
mov cr0, eax
|
|
ijmp: jmp dsseg:init
|
|
|
|
[bits 32]
|
|
init:
|
|
; retain stack pointer
|
|
; esp = ebp = (ss << 4) + sp
|
|
xor ebp, ebp
|
|
xor ebx, ebx
|
|
mov bp, ss
|
|
mov bx, sp
|
|
shl ebp, 4
|
|
add ebp, ebx
|
|
mov esp, ebp
|
|
|
|
mov ax, data
|
|
mov ds, ax
|
|
mov ss, ax
|
|
mov es, ax
|
|
mov fs, ax
|
|
|
|
call code:0x100000 ; start
|
|
|
|
cli
|
|
jf: jmp cs16:in16
|
|
|
|
[bits 16]
|
|
in16:
|
|
mov ax, ds16
|
|
mov ds, ax
|
|
lidt [idt]
|
|
|
|
mov eax, cr0
|
|
and al, 0xFE
|
|
mov cr0, eax
|
|
|
|
torm: jmp 0:inrm
|
|
|
|
inrm: mov ax, gs
|
|
mov ds, ax
|
|
mov es, ax
|
|
mov fs, ax
|
|
mov ss, [oldss]
|
|
mov sp, [oldsp]
|
|
|
|
sti
|
|
xor ax, ax
|
|
int 21h
|
|
ret
|
|
|
|
idt: dw 0x3FF
|
|
dd 0
|
|
|
|
gdt: dw gdt_end - gdt - 1
|
|
dd gdt
|
|
dw 0
|
|
gcode: dd 0x0000ffff
|
|
code equ gcode - gdt
|
|
db 0, 10011011b, 11001111b, 0
|
|
gdata: dd 0x0000ffff
|
|
data equ gdata - gdt
|
|
db 0, 10010011b, 11001111b, 0
|
|
gds: dd 0x0000ffff
|
|
dsseg equ gds - gdt
|
|
db 0, 10011111b, 01001111b, 0
|
|
gds16: dd 0x0000ffff
|
|
ds16 equ gds16 - gdt
|
|
db 0, 10010111b, 00001111b, 0
|
|
gcs16: dd 0x0000ffff
|
|
cs16 equ gcs16 - gdt
|
|
db 0, 10011111b, 00001111b, 0
|
|
gdt_end:
|
|
|
|
oldss: dw 0
|
|
oldsp: dw 0
|
|
|
|
bindat equ $
|