166 lines
3.0 KiB
NASM
166 lines
3.0 KiB
NASM
; rmmod.asm
|
|
; real mode module for HOS
|
|
; Author: Josh Holtrop
|
|
; Date: 09/20/04
|
|
; Modified: 01/04/05
|
|
|
|
%define VIRT_OFFSET 0xC0000000
|
|
|
|
%include "rmmod.inc"
|
|
|
|
; 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...
|
|
|
|
call con_clear
|
|
|
|
; ccall vesa_get_info, es, vbe_info_block
|
|
jmp no_vesa
|
|
|
|
vesa_present:
|
|
ccall con_putstring, txt_vesa
|
|
mov ax, [VideoModePtr]
|
|
mov es, ax
|
|
mov si, [VideoModePtr + 2]
|
|
|
|
jmp end_rmmod
|
|
|
|
no_vesa:
|
|
ccall con_putstring, txt_novesa
|
|
|
|
|
|
|
|
|
|
|
|
end_rmmod: ; get ready to go back to pmode and return to kernel initialization
|
|
; call con_getkey
|
|
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]
|
|
|
|
%include "conio.inc"
|
|
|
|
;-------------------------------------------------------
|
|
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:
|
|
|
|
|
|
txt_vesa: db "VESA found. Please select:", 10, 0
|
|
txt_novesa: db "VESA not found, using 80x25 console mode... press any key", 10, 0
|
|
|
|
dat_rmadd: dd 0
|
|
dat_initrd: dd 0
|
|
dat_retn: dd 0
|
|
|
|
vbe_info_block:
|
|
VbeSignature: db "VBE2"
|
|
VbeVersion: dw 0
|
|
OemStringPtr dd 0
|
|
Capabilities: times 4 db 0
|
|
VideoModePtr: dd 0
|
|
TotalMemory: dw 0
|
|
OemSoftwareRev: dw 0
|
|
OemVendorName: dd 0
|
|
OemProductName: dd 0
|
|
OemProductRev: dd 0
|
|
Reserved: times 478 db 0
|
|
|
|
|