5 * Bootloader configuration
10 .set BUFFER, 0x8000 # 0x80000 - 0x8000 = 480k
14 * Kernel configuration (sync with Kernel.odc!)
17 .set KernelSizeAdr, 0x7e00
18 .set BootDiskAdr, 0x7e04
19 .set BootDiskDxAdr, 0x7e06
20 .set BootDiskCxAdr, 0x7e08
21 .set MemoryMapAdr, 0x7e0A
22 .set ImageBase, 0x100000
24 # =========================================================================== #
26 # =========================================================================== #
32 # 1. Setup canonical %cs:%eip, segment registers %ds, %es, %fs, %gs, %ss and stack %sp
34 ljmp $0x0, $canonized_label; canonized_label:
50 # 3. Reset disk controller (%dl and %dh initialized by bios) and read Kernel into buffer
51 movl $(kernel_code_end - kernel_code_start), KernelSizeAdr
54 mov current_sector, %ax
58 mov current_sector, %ax
60 add $(BUFFER / 16), %ax
64 mov current_sector, %ax
66 mov %ax, current_sector
67 cmp $((kernel_code_end - kernel_code_start + 511) / 512), %ax
70 # 4. Disable interrupts and load GDT
71 mov $msg_protected_mode, %si
76 # 5. Switch to protected mode
82 # =========================================================================== #
84 # =========================================================================== #
88 # 6. Setup data segments %ds, %es, %fs, %gs and stack %sp
96 # 7. Copy Kernel from buffer
100 mov %bh, ImageBase(%eax)
102 cmp $(kernel_code_end - kernel_code_start), %eax
108 # =========================================================================== #
109 # Print asciiz string
110 # input: %si = String
111 # =========================================================================== #
127 # =========================================================================== #
128 # Make memory map for kernel
129 # =========================================================================== #
134 movl $0, MemoryMapAdr
136 mov $(MemoryMapAdr + 4), %di
140 mov $0x0534D4150, %edx
154 mov $msg_mapmem_failed, %si
159 # =========================================================================== #
161 # input: %ax = LBA %dl = disk
162 # output: %ch = cylider %cl = sector %dh = head %dl = disk
163 # =========================================================================== #
179 mov $msg_chs_error, %si
184 mov %dx, BootDiskDxAdr
185 mov %cx, BootDiskCxAdr
189 # CYL = LBA / ( HPC * SPT )
190 # TEMP = LBA % ( HPC * SPT )
192 # SECT = TEMP % SPT + 1
194 # %ax = FREE %bx = FREE %cx = GSPT %dx = HPC-1
198 # %ax = FREE %bx = FREE %cx = SPT %dx = HPC-1
202 # %ax = FREE %bx = FREE %cx = SPT %dx = HPC
204 mul %cx; # overflow in %dx
207 # %ax = FREE %bx = FREE %cx = SPT %dx = (HPC * SPT)
214 # %ax = TEMP %bx = FREE %cx = SPT %dx = CYL
220 # %ax = HEAD %bx = CYL %cx = FREE %dx = SECT
226 # %ax = HEAD %bx = FREE %cx = CYL&SECT %dx = FREE
230 # %ax = FREE %bx = FREE %cx = CYL&SECT %dx = HEAD&DISK
236 # =========================================================================== #
237 # Read sectors to buffer
238 # input: %cx = Cylider+Sector; %es = 64k buf
239 # =========================================================================== #
252 jnc readsectors__success
254 /* zero if sectors not readed */
256 jnz readsectors__success
258 mov $msg_kernel_read_failed, %si
263 readsectors__success:
266 # =========================================================================== #
268 # =========================================================================== #
293 # =========================================================================== #
294 # =========================================================================== #
295 # =========================================================================== #
297 msg_mapmem_failed: .asciz "1"
298 msg_chs_error: .asciz "3"
299 msg_kernel_read_failed: .asciz "4"
300 msg_protected_mode: .asciz ">5"
305 .byte 0x00, 0x00, 0, 0, 0, 0b00000000, 0b00000000, 0 # null dsc
306 .byte 0xff, 0xff, 0, 0, 0, 0b10011010, 0b11001111, 0 # code dsc
307 .byte 0xff, 0xff, 0, 0, 0, 0b10010010, 0b11001111, 0 # data dsc
309 .word (gdt_info - gdt_begin - 1)
312 .fill _start + 510 - .
316 .incbin "../BlackBox.bin"
319 .fill _start + (1440 * 1024) - .