:: limine / stage1 / cd / bootsect.asm 1.7 KB raw

1
org 0x7c00
2
bits 16
3
4
jmp skip_bpb
5
nop
6
7
; El Torito Boot Information Table
8
; ↓ Set by mkisofs
9
times 8-($-$$) db 0
10
boot_info:
11
    bi_PVD      dd 0
12
    bi_boot_LBA dd 0
13
    bi_boot_len dd 0
14
    bi_checksum dd 0
15
    bi_reserved times 40 db 0
16
17
times 90-($-$$) db 0
18
19
skip_bpb:
20
    cli
21
    cld
22
    jmp 0x0000:.initialise_cs
23
  .initialise_cs:
24
    xor si, si
25
    mov ds, si
26
    mov es, si
27
    mov ss, si
28
    mov sp, 0x7c00
29
    sti
30
31
    ; int 13h?
32
    mov ah, 0x41
33
    mov bx, 0x55aa
34
    int 0x13
35
    jc err.0
36
    cmp bx, 0xaa55
37
    jne err.1
38
39
    ; --- Load the decompressor ---
40
    mov eax, dword [bi_boot_LBA]
41
    add eax, 1
42
    mov ecx, stage2.fullsize / 2048
43
    ; DECOMPRESSOR_LOCATION = 0x70000 = 0x7000:0x0000
44
    push 0x7000
45
    pop es
46
    xor bx, bx
47
    call read_2k_sectors
48
    jc err.2
49
50
    ; Enable GDT
51
    lgdt [gdt]
52
    cli
53
    mov eax, cr0
54
    or al, 1
55
    mov cr0, eax
56
57
    jmp 0x08:pmode
58
59
err:
60
  .2:
61
    inc si
62
  .1:
63
    inc si
64
  .0:
65
    add si, '0' | (0x4f << 8)
66
67
    push 0xb800
68
    pop es
69
    mov word [es:0], si
70
71
    sti
72
    .h: hlt
73
    jmp .h
74
75
%include 'read_2k_sectors.asm'
76
%include '../gdt.asm'
77
78
bits 32
79
pmode:
80
    mov eax, 0x10
81
    mov ds, ax
82
    mov es, ax
83
    mov fs, ax
84
    mov gs, ax
85
    mov ss, ax
86
87
    ; Time to handle control over to the decompressor
88
    push 2
89
    and edx, 0xff
90
    push edx  ; Boot drive
91
    push stage2.size
92
    push (stage2 - decompressor) + 0x70000
93
    call 0x70000
94
95
; Align stage2 to 2K ON DISK
96
times 2048-($-$$) db 0
97
decompressor:
98
%strcat DECOMPRESSOR_PATH BUILDDIR, '/decompressor-build/decompressor.bin'
99
incbin DECOMPRESSOR_PATH
100
101
align 16
102
stage2:
103
%strcat STAGE2_PATH BUILDDIR, '/common-bios/stage2.bin.limlz'
104
incbin STAGE2_PATH
105
.size: equ $ - stage2
106
107
times ((($-$$)+2047) & ~2047)-($-$$) db 0
108
.fullsize: equ $ - decompressor
tab: 248 wrap: offon