2020-04-15 11:14:58 +03:00
|
|
|
org 0x7c00
|
2019-05-30 16:59:25 +03:00
|
|
|
bits 16
|
|
|
|
|
2020-08-26 23:45:32 +03:00
|
|
|
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
|
2020-09-06 06:15:55 +03:00
|
|
|
mov esp, 0x4000
|
2020-01-22 06:12:55 +03:00
|
|
|
sti
|
2020-08-29 21:02:16 +03:00
|
|
|
|
2020-08-26 23:45:32 +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.
|
2020-08-26 23:45:32 +03:00
|
|
|
; 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
|
|
|
|
2020-08-26 23:45:32 +03:00
|
|
|
.continue:
|
2020-01-22 06:12:55 +03:00
|
|
|
mov si, LoadingMsg
|
|
|
|
call simple_print
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-09-06 06:15:55 +03:00
|
|
|
; ****************** Load stage 1.5 ******************
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-09-06 06:15:55 +03:00
|
|
|
mov si, Stage15Msg
|
2020-01-22 06:12:55 +03:00
|
|
|
call simple_print
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-09-06 06:15:55 +03:00
|
|
|
mov eax, dword [stage15_sector]
|
2020-01-22 06:12:55 +03:00
|
|
|
mov ebx, 0x7e00
|
|
|
|
mov ecx, 1
|
|
|
|
call read_sectors
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-01-22 06:12:55 +03:00
|
|
|
jc err_reading_disk
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-01-22 06:12:55 +03:00
|
|
|
mov si, DoneMsg
|
|
|
|
call simple_print
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-01-22 06:12:55 +03:00
|
|
|
jmp 0x7e00
|
2019-05-30 16:59:25 +03:00
|
|
|
|
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
|
2019-05-30 16:59:25 +03:00
|
|
|
|
|
|
|
halt:
|
2020-01-22 06:12:55 +03:00
|
|
|
hlt
|
|
|
|
jmp halt
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2019-05-30 17:25:23 +03:00
|
|
|
; Data
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-08-29 21:02:16 +03:00
|
|
|
LoadingMsg db 0x0D, 0x0A, 'Limine', 0x0D, 0x0A, 0x0A, 0x00
|
2020-09-06 06:15:55 +03:00
|
|
|
Stage15Msg db 'Loading stage 1.5...', 0x00
|
2020-08-26 23:45:32 +03:00
|
|
|
ErrReadDiskMsg db 0x0D, 0x0A, 'Disk read error, system halted', 0x00
|
|
|
|
ErrEnableA20Msg db 0x0D, 0x0A, 'A20 enable error, system halted', 0x00
|
2019-05-30 17:25:23 +03:00
|
|
|
DoneMsg db ' DONE', 0x0D, 0x0A, 0x00
|
2019-05-30 16:59:25 +03:00
|
|
|
|
|
|
|
times 0xda-($-$$) db 0
|
|
|
|
times 6 db 0
|
|
|
|
|
2019-05-30 17:25:23 +03:00
|
|
|
; Includes
|
2019-05-30 16:59:25 +03:00
|
|
|
|
|
|
|
%include 'simple_print.inc'
|
|
|
|
%include 'disk.inc'
|
|
|
|
|
2020-04-15 11:14:58 +03:00
|
|
|
times 0x1b0-($-$$) db 0
|
2020-09-06 06:15:55 +03:00
|
|
|
stage15_sector: dd 1
|
2020-04-15 11:14:58 +03:00
|
|
|
|
2019-05-30 16:59:25 +03:00
|
|
|
times 0x1b8-($-$$) db 0
|
|
|
|
times 510-($-$$) db 0
|
|
|
|
dw 0xaa55
|
2019-05-30 17:25:23 +03:00
|
|
|
|
2020-09-06 04:35:32 +03:00
|
|
|
; ********************* Stage 1.5 *********************
|
2019-05-30 17:25:23 +03:00
|
|
|
|
2020-09-06 04:35:32 +03:00
|
|
|
stage15:
|
|
|
|
push es
|
2020-09-06 06:15:55 +03:00
|
|
|
push 0x7000
|
2020-09-06 04:35:32 +03:00
|
|
|
pop es
|
2020-09-06 06:15:55 +03:00
|
|
|
mov eax, dword [stage15_sector]
|
2020-04-15 11:14:58 +03:00
|
|
|
inc eax
|
2020-09-06 04:35:32 +03:00
|
|
|
xor ebx, ebx
|
2020-01-22 06:12:55 +03:00
|
|
|
mov ecx, 62
|
|
|
|
call read_sectors
|
2020-09-06 04:35:32 +03:00
|
|
|
pop es
|
2020-01-22 06:12:55 +03:00
|
|
|
jc err_reading_disk
|
2019-05-30 17:25:23 +03:00
|
|
|
|
2020-01-22 06:12:55 +03:00
|
|
|
call enable_a20
|
|
|
|
jc err_enabling_a20
|
2019-05-30 17:25:23 +03:00
|
|
|
|
2020-09-06 04:35:32 +03:00
|
|
|
call load_gdt
|
2019-05-30 17:25:23 +03:00
|
|
|
|
2020-01-22 06:12:55 +03:00
|
|
|
cli
|
2019-05-30 17:25:23 +03:00
|
|
|
|
2020-01-22 06:12:55 +03:00
|
|
|
mov eax, cr0
|
|
|
|
or al, 1
|
|
|
|
mov cr0, eax
|
2019-05-30 17:25:23 +03:00
|
|
|
|
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
|
2019-05-30 17:25:23 +03:00
|
|
|
|
2020-08-11 18:43:39 +03:00
|
|
|
and edx, 0xff
|
|
|
|
push edx
|
|
|
|
|
2020-09-06 04:35:32 +03:00
|
|
|
push stage2.size
|
2020-09-06 06:15:55 +03:00
|
|
|
push (stage2 - 0x8000) + 0x70000
|
2020-09-06 04:35:32 +03:00
|
|
|
|
2020-09-06 06:15:55 +03:00
|
|
|
call 0x70000
|
2019-05-30 17:25:23 +03:00
|
|
|
|
2019-05-30 17:35:49 +03:00
|
|
|
bits 16
|
2019-05-30 17:25:23 +03:00
|
|
|
%include 'a20_enabler.inc'
|
|
|
|
%include 'gdt.inc'
|
|
|
|
|
|
|
|
times 1024-($-$$) db 0
|
2020-04-15 11:14:58 +03:00
|
|
|
|
2020-09-06 04:35:32 +03:00
|
|
|
incbin '../decompressor/decompressor.bin'
|
|
|
|
|
|
|
|
align 16
|
|
|
|
stage2:
|
|
|
|
incbin '../stage2.bin.gz'
|
|
|
|
.size: equ $ - stage2
|
2020-04-15 11:14:58 +03:00
|
|
|
|
|
|
|
times 32768-($-$$) db 0
|