rulimine/src/bootsect/bootsect.asm

153 lines
2.5 KiB
NASM
Raw Normal View History

org 0x7c00
bits 16
jmp start ; Workaround for some BIOSes that require this stub
nop
2020-01-22 06:12:55 +03:00
start:
cli
2020-01-22 07:02:12 +03:00
cld
2020-01-22 06:12:55 +03:00
jmp 0x0000:.initialise_cs
.initialise_cs:
xor ax, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov esp, 0x4000
2020-01-22 06:12:55 +03:00
sti
2020-08-29 21:02:16 +03:00
; Some BIOSes don't pass the correct boot drive number,
; so we need to do the job
.check_drive:
2020-08-29 21:02:16 +03:00
; Limine isn't made for floppy disks, these are dead anyways.
; So if the value the BIOS passed is <0x80, just assume it has passed
; an incorrect value
test dl, 0x80
jz .fix_drive
; Drive numbers from 0x80..0x8f should be valid
test dl, 0x70
jz .continue
.fix_drive:
; Try to fix up the mess the BIOS have done
mov dl, 0x80
2020-08-29 21:02:16 +03:00
.continue:
2020-01-22 06:12:55 +03:00
mov si, LoadingMsg
call simple_print
; ****************** Load stage 1.5 ******************
mov si, Stage15Msg
2020-01-22 06:12:55 +03:00
call simple_print
mov eax, dword [stage15_sector]
2020-01-22 06:12:55 +03:00
mov ebx, 0x7e00
mov ecx, 1
call read_sectors
2020-01-22 06:12:55 +03:00
jc err_reading_disk
2020-01-22 06:12:55 +03:00
mov si, DoneMsg
call simple_print
2020-01-22 06:12:55 +03:00
jmp 0x7e00
2019-07-08 22:41:17 +03:00
err_reading_disk:
2020-01-22 06:12:55 +03:00
mov si, ErrReadDiskMsg
call simple_print
jmp halt
2019-07-08 22:41:17 +03:00
err_enabling_a20:
2020-01-22 06:12:55 +03:00
mov si, ErrEnableA20Msg
call simple_print
jmp halt
halt:
2020-01-22 06:12:55 +03:00
hlt
jmp halt
; Data
2020-08-29 21:02:16 +03:00
LoadingMsg db 0x0D, 0x0A, 'Limine', 0x0D, 0x0A, 0x0A, 0x00
Stage15Msg db 'Loading stage 1.5...', 0x00
ErrReadDiskMsg db 0x0D, 0x0A, 'Disk read error, system halted', 0x00
ErrEnableA20Msg db 0x0D, 0x0A, 'A20 enable error, system halted', 0x00
DoneMsg db ' DONE', 0x0D, 0x0A, 0x00
times 0xda-($-$$) db 0
times 6 db 0
; Includes
%include 'simple_print.inc'
%include 'disk.inc'
times 0x1b0-($-$$) db 0
stage15_sector: dd 1
times 0x1b8-($-$$) db 0
times 510-($-$$) db 0
dw 0xaa55
; ********************* Stage 1.5 *********************
stage15:
push es
push 0x7000
pop es
mov eax, dword [stage15_sector]
inc eax
xor ebx, ebx
2020-01-22 06:12:55 +03:00
mov ecx, 62
call read_sectors
pop es
2020-01-22 06:12:55 +03:00
jc err_reading_disk
2020-01-22 06:12:55 +03:00
call enable_a20
jc err_enabling_a20
call load_gdt
2020-01-22 06:12:55 +03:00
cli
2020-01-22 06:12:55 +03:00
mov eax, cr0
or al, 1
mov cr0, eax
2020-01-22 06:12:55 +03:00
jmp 0x18:.pmode
bits 32
.pmode:
mov ax, 0x20
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
and edx, 0xff
push edx
push stage2.size
push (stage2 - 0x8000) + 0x70000
call 0x70000
2019-05-30 17:35:49 +03:00
bits 16
%include 'a20_enabler.inc'
%include 'gdt.inc'
times 1024-($-$$) db 0
incbin '../decompressor/decompressor.bin'
align 16
stage2:
incbin '../stage2.bin.gz'
.size: equ $ - stage2
times 32768-($-$$) db 0