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
26 # =========================================================================== #
27 # Setup canonical %cs:%eip, segment registers %ds, %es, %fs, %gs, %ss and
29 # =========================================================================== #
34 ljmp $0x0, $canonized_label; canonized_label:
45 # =========================================================================== #
46 # Make memory map for kernel
47 # =========================================================================== #
52 mov $(MemoryMapAdr + 4), %di
57 mov $0x0534D4150, %edx
71 ### int 0x15 + %ah = 0x88
76 ### %ax = available memory starting at 0x100000 in KB
80 ### some bioses do not clear cf, do it manually
83 movl $3, (MemoryMapAdr + 0) # num
87 movl %eax, (MemoryMapAdr + 4) # base (low)
88 movl %eax, (MemoryMapAdr + 8) # base (high)
89 movl $0x080000, (MemoryMapAdr + 12) # len (low)
90 movl %eax, (MemoryMapAdr + 16) # len (high)
91 movl %ebx, (MemoryMapAdr + 20) # type
92 # reserved harware memory
93 movl $0x080000, (MemoryMapAdr + 24) # base (low)
94 movl %eax, (MemoryMapAdr + 28) # base (high)
95 movl $0x080000, (MemoryMapAdr + 32) # len (low)
96 movl %eax, (MemoryMapAdr + 36) # len (high)
97 movl %eax, (MemoryMapAdr + 40) # type
99 movl $0x100000, (MemoryMapAdr + 44) # base (low)
100 movl %eax, (MemoryMapAdr + 48) # base (high)
101 #movl $0x700000, (MemoryMapAdr + 52) # len (low)
102 movl %eax, (MemoryMapAdr + 56) # len (high)
103 movl %ebx, (MemoryMapAdr + 60) # type
113 movl %eax, (MemoryMapAdr + 52) # len (low)
117 mov $msg_mapmem_failed, %si
124 # =========================================================================== #
126 # =========================================================================== #
146 # =========================================================================== #
147 # Reset disk controller (%dl and %dh initialized by bios) and read Kernel
149 # =========================================================================== #
151 movl $(kernel_code_end - kernel_code_start), KernelSizeAdr
154 mov current_sector, %ax
158 mov current_sector, %ax
160 add $(BUFFER / 16), %ax
164 # %cx = Cylider+Sector; %es = 64k buf
174 jnc readsectors__success
176 /* zero if sectors not readed */
178 jnz readsectors__success
180 mov $msg_kernel_read_failed, %si
184 readsectors__success:
186 mov current_sector, %ax
188 mov %ax, current_sector
189 cmp $((kernel_code_end - kernel_code_start + 511) / 512), %ax
193 # =========================================================================== #
195 # =========================================================================== #
196 mov $msg_protected_mode, %si
200 # =========================================================================== #
201 # Switch to protected mode
202 # =========================================================================== #
208 # =========================================================================== #
209 # 32 bit stage begins
210 # =========================================================================== #
216 # =========================================================================== #
217 # Setup data segments %ds, %es, %fs, %gs and stack %sp
218 # =========================================================================== #
227 # =========================================================================== #
228 # Copy Kernel from buffer
229 # =========================================================================== #
233 mov BUFFER(%eax), %bh
234 mov %bh, ImageBase(%eax)
236 cmp $(kernel_code_end - kernel_code_start), %eax
239 # =========================================================================== #
240 # Jump to Kernel code (never returns)
241 # =========================================================================== #
245 # =========================================================================== #
246 # ================================ routines ================================= #
247 # =========================================================================== #
249 # =========================================================================== #
250 # Print asciiz string
251 # input: %si = String
252 # =========================================================================== #
268 # =========================================================================== #
270 # input: %ax = LBA %dl = disk
271 # output: %ch = cylider %cl = sector %dh = head %dl = disk
272 # =========================================================================== #
288 mov $msg_chs_error, %si
292 mov %dx, BootDiskDxAdr
293 mov %cx, BootDiskCxAdr
297 # CYL = LBA / ( HPC * SPT )
298 # TEMP = LBA % ( HPC * SPT )
300 # SECT = TEMP % SPT + 1
302 # %ax = FREE %bx = FREE %cx = GSPT %dx = HPC-1
306 # %ax = FREE %bx = FREE %cx = SPT %dx = HPC-1
310 # %ax = FREE %bx = FREE %cx = SPT %dx = HPC
312 mul %cx; # overflow in %dx
315 # %ax = FREE %bx = FREE %cx = SPT %dx = (HPC * SPT)
322 # %ax = TEMP %bx = FREE %cx = SPT %dx = CYL
328 # %ax = HEAD %bx = CYL %cx = FREE %dx = SECT
334 # %ax = HEAD %bx = FREE %cx = CYL&SECT %dx = FREE
338 # %ax = FREE %bx = FREE %cx = CYL&SECT %dx = HEAD&DISK
344 # =========================================================================== #
345 # =========================================================================== #
346 # =========================================================================== #
348 msg_mapmem_failed: .asciz "1"
349 msg_chs_error: .asciz "3"
350 msg_kernel_read_failed: .asciz "4"
351 msg_protected_mode: .asciz ">5"
356 .byte 0x00, 0x00, 0, 0, 0, 0b00000000, 0b00000000, 0 # null dsc
357 .byte 0xff, 0xff, 0, 0, 0, 0b10011010, 0b11001111, 0 # code dsc
358 .byte 0xff, 0xff, 0, 0, 0, 0b10010010, 0b11001111, 0 # data dsc
360 .word (gdt_info - gdt_begin - 1)
363 .fill _start + 510 - .
367 .incbin "../BlackBox.bin"
370 .fill _start + (1440 * 1024) - .