nightloader/stage_1/start.asm

79 lines
1.2 KiB
NASM
Raw Normal View History

2023-04-24 20:00:51 +00:00
section .text
org 0x7c00
start:
push dx
mov ax, 0
mov ds, ax
mov es, ax
mov gs, ax
mov fs, ax
mov ax, 0x7e00
mov ss, ax
mov sp, 256
mov bp, 256
mov ax, 0x7c00
add ax, 446
; ax now points to the start of the partition table
mov di, 0
.search_partition:
mov bx, ax
add bx, 4
mov cl, [bx]
cmp cl, 0x9d
je .found_partition
inc di
cmp di, 4
je .no_boot_partition
add ax, 16
.found_partition:
mov bx, ax
add bx, 14
mov cx, [bx] ; more than 65536 sectors will NOT be
; supported for the bootloader's partition!
mov bx, 0x8000
mov es, bx
mov di, 0x0000
mov bx, ax
inc bx
; bx now points to the CHS-address of the first sector
; of the bootloader's partition.
mov dx, [bx]
mov ah, dh ; head
mov bl, dl ; sector
add bx, 2
; bx now points to the CHS-cylinder of the first sector
; of the bootloader's partition.
mov al, [bx] ; cylinder
call load_sectors
.no_boot_partition:
hlt
%include "gdt.asm"
%include "utility.asm"