2020-04-15 11:14:58 +03:00
|
|
|
org 0x7c00
|
2019-05-30 16:59:25 +03:00
|
|
|
bits 16
|
|
|
|
|
2020-01-22 06:12:55 +03:00
|
|
|
start:
|
2020-09-06 08:25:34 +03:00
|
|
|
jmp .skip_bpb ; Workaround for some BIOSes that require this stub
|
|
|
|
nop
|
|
|
|
|
|
|
|
; Some BIOSes will do a funny and decide to overwrite bytes of code in
|
|
|
|
; the section where a FAT BPB would be, potentially overwriting
|
|
|
|
; bootsector code.
|
2022-07-13 21:17:34 +03:00
|
|
|
; Avoid that by filling the BPB area with dummy values.
|
|
|
|
; Some of the values have to be set to certain values in order
|
|
|
|
; to boot on even quirkier machines.
|
|
|
|
; Source: https://github.com/freebsd/freebsd-src/blob/82a21151cf1d7a3e9e95b9edbbf74ac10f386d6a/stand/i386/boot2/boot1.S
|
|
|
|
.bpb:
|
|
|
|
times 3-($-$$) db 0
|
|
|
|
.bpb_oem_id: db "LIMINE "
|
|
|
|
.bpb_sector_size: dw 512
|
|
|
|
.bpb_sects_per_cluster: db 0
|
|
|
|
.bpb_reserved_sects: dw 0
|
|
|
|
.bpb_fat_count: db 0
|
|
|
|
.bpb_root_dir_entries: dw 0
|
|
|
|
.bpb_sector_count: dw 0
|
|
|
|
.bpb_media_type: db 0
|
|
|
|
.bpb_sects_per_fat: dw 0
|
|
|
|
.bpb_sects_per_track: dw 18
|
|
|
|
.bpb_heads_count: dw 2
|
|
|
|
.bpb_hidden_sects: dd 0
|
|
|
|
.bpb_sector_count_big: dd 0
|
|
|
|
.bpb_drive_num: db 0
|
|
|
|
.bpb_reserved: db 0
|
|
|
|
.bpb_signature: db 0
|
|
|
|
.bpb_volume_id: dd 0
|
|
|
|
.bpb_volume_label: db "LIMINE "
|
|
|
|
.bpb_filesystem_type: times 8 db 0
|
2020-09-06 08:25:34 +03:00
|
|
|
|
|
|
|
.skip_bpb:
|
2020-01-22 06:12:55 +03:00
|
|
|
cli
|
2020-01-22 07:02:12 +03:00
|
|
|
cld
|
2020-01-22 06:12:55 +03:00
|
|
|
jmp 0x0000:.initialise_cs
|
|
|
|
.initialise_cs:
|
2021-09-21 15:39:43 +03:00
|
|
|
xor si, si
|
|
|
|
mov ds, si
|
|
|
|
mov es, si
|
|
|
|
mov ss, si
|
2020-09-25 23:42:01 +03:00
|
|
|
mov sp, 0x7c00
|
2020-01-22 06:12:55 +03:00
|
|
|
sti
|
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
|
2021-05-21 00:19:24 +03:00
|
|
|
; an incorrect value.
|
|
|
|
cmp dl, 0x80
|
2021-09-21 15:39:43 +03:00
|
|
|
jb err.0
|
2021-05-23 05:15:36 +03:00
|
|
|
; Values above 0x8f are dubious so we assume we weren't booted properly
|
|
|
|
; for those either
|
|
|
|
cmp dl, 0x8f
|
2021-09-21 15:39:43 +03:00
|
|
|
ja err.1
|
2020-08-29 21:02:16 +03:00
|
|
|
|
2020-08-26 23:45:32 +03:00
|
|
|
.continue:
|
2020-09-06 08:25:34 +03:00
|
|
|
; Make sure int 13h extensions are supported
|
|
|
|
mov ah, 0x41
|
|
|
|
mov bx, 0x55aa
|
|
|
|
int 0x13
|
2021-09-21 15:39:43 +03:00
|
|
|
jc err.2
|
2020-09-06 08:25:34 +03:00
|
|
|
cmp bx, 0xaa55
|
2021-09-21 15:39:43 +03:00
|
|
|
jne err.3
|
2019-05-30 16:59:25 +03:00
|
|
|
|
2020-12-06 18:43:38 +03:00
|
|
|
push 0x7000
|
2020-09-06 04:35:32 +03:00
|
|
|
pop es
|
2020-12-06 18:43:38 +03:00
|
|
|
mov di, stage2_locs
|
|
|
|
mov eax, dword [di]
|
|
|
|
mov ebp, dword [di+4]
|
2020-09-06 08:25:34 +03:00
|
|
|
xor bx, bx
|
2020-12-06 18:43:38 +03:00
|
|
|
xor ecx, ecx
|
|
|
|
mov cx, word [di-4]
|
|
|
|
call read_sectors
|
2021-09-21 15:39:43 +03:00
|
|
|
jc err.4
|
2020-12-06 18:43:38 +03:00
|
|
|
mov eax, dword [di+8]
|
|
|
|
mov ebp, dword [di+12]
|
|
|
|
add bx, cx
|
|
|
|
mov cx, word [di-2]
|
2020-01-22 06:12:55 +03:00
|
|
|
call read_sectors
|
2021-09-21 15:39:43 +03:00
|
|
|
jc err.5
|
2019-05-30 17:25:23 +03:00
|
|
|
|
2020-12-06 18:43:38 +03:00
|
|
|
lgdt [gdt]
|
2019-05-30 17:25:23 +03:00
|
|
|
|
2020-01-22 06:12:55 +03:00
|
|
|
cli
|
|
|
|
mov eax, cr0
|
2020-10-15 12:35:49 +03:00
|
|
|
bts ax, 0
|
2020-01-22 06:12:55 +03:00
|
|
|
mov cr0, eax
|
2019-05-30 17:25:23 +03:00
|
|
|
|
2020-12-06 18:43:38 +03:00
|
|
|
jmp 0x08:vector
|
2020-10-15 12:35:49 +03:00
|
|
|
|
|
|
|
times 0xda-($-$$) db 0
|
|
|
|
times 6 db 0
|
|
|
|
|
|
|
|
; Includes
|
|
|
|
|
2021-02-25 03:24:54 +03:00
|
|
|
%include 'disk.asm'
|
|
|
|
%include '../gdt.asm'
|
2019-05-30 17:25:23 +03:00
|
|
|
|
2021-05-23 05:15:36 +03:00
|
|
|
err:
|
2021-09-21 15:39:43 +03:00
|
|
|
.5:
|
|
|
|
inc si
|
|
|
|
.4:
|
|
|
|
inc si
|
|
|
|
.3:
|
|
|
|
inc si
|
|
|
|
.2:
|
|
|
|
inc si
|
|
|
|
.1:
|
|
|
|
inc si
|
|
|
|
.0:
|
|
|
|
add si, '0' | (0x4f << 8)
|
|
|
|
|
2021-05-23 05:15:36 +03:00
|
|
|
push 0xb800
|
|
|
|
pop es
|
2021-09-21 15:39:43 +03:00
|
|
|
mov word [es:0], si
|
|
|
|
|
|
|
|
sti
|
2021-05-23 05:15:36 +03:00
|
|
|
.h: hlt
|
|
|
|
jmp .h
|
|
|
|
|
2020-11-05 03:04:49 +03:00
|
|
|
bits 32
|
|
|
|
vector:
|
2020-12-06 18:43:38 +03:00
|
|
|
mov eax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
|
|
|
mov fs, ax
|
|
|
|
mov gs, ax
|
|
|
|
mov ss, ax
|
|
|
|
|
|
|
|
and edx, 0xff
|
|
|
|
|
2020-11-05 03:04:49 +03:00
|
|
|
push 0
|
|
|
|
|
|
|
|
push edx
|
|
|
|
|
|
|
|
push stage2.size
|
|
|
|
push (stage2 - decompressor) + 0x70000
|
|
|
|
|
|
|
|
call 0x70000
|
|
|
|
|
2020-12-06 18:43:38 +03:00
|
|
|
times 0x1a4-($-$$) db 0
|
|
|
|
stage2_size_a: dw 0
|
|
|
|
stage2_size_b: dw 0
|
|
|
|
stage2_locs:
|
|
|
|
stage2_loc_a: dq 0
|
|
|
|
stage2_loc_b: dq 0
|
2020-10-15 12:35:49 +03:00
|
|
|
|
|
|
|
times 0x1b8-($-$$) db 0
|
|
|
|
times 510-($-$$) db 0
|
|
|
|
dw 0xaa55
|
|
|
|
|
|
|
|
; ********************* Stage 2 *********************
|
2020-04-15 11:14:58 +03:00
|
|
|
|
2020-10-15 12:35:49 +03:00
|
|
|
decompressor:
|
2022-01-16 08:09:36 +03:00
|
|
|
%strcat DECOMPRESSOR_PATH BUILDDIR, '/decompressor-build/decompressor.bin'
|
2021-11-20 10:32:06 +03:00
|
|
|
incbin DECOMPRESSOR_PATH
|
2020-09-06 04:35:32 +03:00
|
|
|
|
|
|
|
align 16
|
|
|
|
stage2:
|
2022-02-03 12:38:43 +03:00
|
|
|
%strcat STAGE2_PATH BUILDDIR, '/common-bios/stage2.bin.gz'
|
2021-11-20 10:32:06 +03:00
|
|
|
incbin STAGE2_PATH
|
2020-09-06 04:35:32 +03:00
|
|
|
.size: equ $ - stage2
|