hos/rmmod/rmmod.asm

160 lines
2.8 KiB
NASM

; rmmod.asm
; real mode module for HOS
; Author: Josh Holtrop
; Date: 09/20/04
%define VIRT_OFFSET 0xC0000000
; the bootstrap process will jump us to 0x0:0x5010 so we'd better be ready for it
[org 0x5000]
[bits 16]
;HOS module header, better be 16 bytes!
dd 0x4D534F48 ; magic identifier "HOSM"
dd 1 ; real mode module
dd start ; start address
dd 0 ; reserved
; ebx = return address
; ecx = where to store real mode parameter table
start:
jmp 0:start_refreshed
start_refreshed:
mov ax, cs ; 0
mov ds, ax
mov es, ax
mov ss, ax
mov esp, 0x7000
mov [dat_rmadd], ecx
mov [dat_retn], ebx
; begin real-mode code initialization, etc...
; get ready to go back to pmode and return to kernel initialization
mov ebx, [dat_retn]
lgdt [gdtrlin32]
mov eax, cr0
or eax, 0x01
mov cr0, eax
jmp KERNEL_CODE_LIN32:segmented_start
[bits 32]
segmented_start:
lgdt [gdtrbs32]
jmp KERNEL_CODE_BS32:offset_continue+VIRT_OFFSET
offset_continue:
mov cx, KERNEL_DATA_BS32
mov ss, cx
mov ds, cx
mov es, cx
mov gs, cx
mov fs, cx
jmp ebx
[bits 16]
; putString(int position, char *str)
putString:
push bp
mov bp, sp
push ds
push es
push edi
push esi
push eax
mov ax, 0xb800
mov es, ax
xor ax, ax
mov ds, ax
mov ax, [bp + 4]
mov di, ax
shl di, 1
mov ax, [bp + 6]
mov si, ax
putString_loop:
lodsb
stosb
cmp al, 0
jz putString_loop_done
mov al, 0x07
stosb
jmp putString_loop
putString_loop_done:
pop eax
pop esi
pop edi
pop es
pop ds
pop bp
ret
;-------------------------------------------------------
gdtrlin32:
dw gdt_endlin32-gdtlin32-1
dd gdtlin32
gdtlin32: ;null descriptor
dd 0
dd 0
KERNEL_CODE_LIN32 equ $-gdtlin32
db 0xff ;limit 7:0
db 0xff ;limit 15:8
db 0x00 ;base 7:0
db 0x00 ;base 15:8
db 0x00 ;base 23:16
db 0x9a ;access
db 0xcf ;flags / limit 19:16
db 0x00 ;base 31:24
KERNEL_DATA_LIN32 equ $-gdtlin32
db 0xff ;limit 7:0
db 0xff ;limit 15:8
db 0x00 ;base 7:0
db 0x00 ;base 15:8
db 0x00 ;base 23:16
db 0x92 ;access
db 0xcf ;flags / limit 19:16
db 0x00 ;base 31:24
gdt_endlin32:
;-------------------------------------------------------
gdtrbs32:
dw gdt_endbs32-gdtbs32-1
dd gdtbs32
gdtbs32: ;null descriptor
dd 0
dd 0
;a base of 0x4000_0000, when added to 0xC000_0000 will produce 0x0000_0000 physical before paging in effect
KERNEL_CODE_BS32 equ $-gdtbs32
db 0xff ;limit 7:0
db 0xff ;limit 15:8
db 0x00 ;base 7:0
db 0x00 ;base 15:8
db 0x00 ;base 23:16
db 0x9a ;access
db 0xcf ;flags / limit 19:16
db 0x40 ;base 31:24
KERNEL_DATA_BS32 equ $-gdtbs32
db 0xff ;limit 7:0
db 0xff ;limit 15:8
db 0x00 ;base 7:0
db 0x00 ;base 15:8
db 0x00 ;base 23:16
db 0x92 ;access
db 0xcf ;flags / limit 19:16
db 0x40 ;base 31:24
gdt_endbs32:
dat_rmadd dd 0
dat_initrd dd 0
dat_retn dd 0