moved stuff around
This commit is contained in:
129
boot/boot.s
Normal file
129
boot/boot.s
Normal file
@@ -0,0 +1,129 @@
|
||||
.code16
|
||||
.text
|
||||
.global _start
|
||||
_start:
|
||||
ljmp $0x07C0, $something
|
||||
|
||||
something:
|
||||
cli
|
||||
cld
|
||||
|
||||
mov %cs, %ax
|
||||
mov %ax, %ds
|
||||
mov %ax, %es
|
||||
|
||||
# stack stuff
|
||||
mov $0x0000, %ax
|
||||
mov %ax, %ss
|
||||
mov $0xFFF0, %sp
|
||||
|
||||
# copy the first 12 bytes of our MBR table entry
|
||||
mov %dl, (disk_number)
|
||||
mov $mbr_entry, %di
|
||||
mov $12, %cx
|
||||
rep movsb
|
||||
|
||||
mov $0, %ah
|
||||
int $0x13
|
||||
|
||||
mov $0x08, %ah
|
||||
int $0x13
|
||||
and 0b00111111, %cl
|
||||
mov %cl, (total_sectors)
|
||||
mov %ch, (total_cylinders)
|
||||
mov %dh, (total_heads)
|
||||
|
||||
mov $0x1000, %ax
|
||||
mov %ax, %es
|
||||
mov $0x0000, %bx
|
||||
|
||||
mov (disk_number), %dl
|
||||
mov $0, %ch #cylinder
|
||||
mov $0, %dh #head
|
||||
mov $2, %cl #sector
|
||||
|
||||
load_sector:
|
||||
mov $1, %al
|
||||
mov $0x02, %ah
|
||||
int $0x13
|
||||
|
||||
mov (kernel_sectors), %ax
|
||||
cmp $0xffff, %ax
|
||||
jne check_last_sector
|
||||
mov %es:20, %eax
|
||||
shr $9, %eax
|
||||
inc %eax
|
||||
|
||||
check_last_sector:
|
||||
dec %ax
|
||||
mov %ax, kernel_sectors
|
||||
cmp $0, %ax
|
||||
je done
|
||||
|
||||
move: # inc our offset. If it hits 0, we've moved a segment, inc that too.
|
||||
add $512, %bx
|
||||
cmp $0, %bx
|
||||
jnz read_next_sector
|
||||
mov %es, %ax
|
||||
add $1000, %ax
|
||||
mov %ax, %es
|
||||
|
||||
read_next_sector: # find the next valid sector, head, cylinder combo on the disk
|
||||
inc %cl
|
||||
mov (total_sectors), %al
|
||||
cmp %al, %cl
|
||||
jle load_sector
|
||||
mov $1, %cl #go back to sector 1.. of the next head
|
||||
|
||||
inc %dh #next head
|
||||
mov (total_heads), %al
|
||||
cmp %al, %dh
|
||||
jle load_sector
|
||||
mov $0, %dh # go back to head 0.. of the next cylinder
|
||||
|
||||
inc %ch # next cylinder
|
||||
mov (total_cylinders), %al
|
||||
cmp %al, %ch
|
||||
jle load_sector
|
||||
# no more disk... fall through
|
||||
done:
|
||||
mov $0, %ah
|
||||
int $0x13
|
||||
|
||||
mov $0x1000, %ax
|
||||
mov %ax, %ds
|
||||
ljmp $0x1000, $0x0000
|
||||
|
||||
disk_number:
|
||||
.byte 0
|
||||
total_cylinders:
|
||||
.byte 0
|
||||
total_heads:
|
||||
.byte 0
|
||||
total_sectors:
|
||||
.byte 0
|
||||
|
||||
kernel_sectors:
|
||||
.word 0xFFFF
|
||||
|
||||
mbr_entry:
|
||||
partition_status:
|
||||
.byte 0
|
||||
partition_start_chs:
|
||||
.byte 0
|
||||
.byte 0
|
||||
.byte 0
|
||||
partition_type:
|
||||
.byte 0
|
||||
partition_stop_chs:
|
||||
.byte 0
|
||||
.byte 0
|
||||
.byte 0
|
||||
partition_start_lba:
|
||||
.long 0
|
||||
partition_start_length:
|
||||
.long 0
|
||||
|
||||
.org 510
|
||||
magic:
|
||||
.word 0xAA55
|
||||
Reference in New Issue
Block a user