Compare commits
2 Commits
3da2af2d2d
...
a8b24c7b01
| Author | SHA1 | Date | |
|---|---|---|---|
| a8b24c7b01 | |||
| 58fc4a08dd |
@@ -193,6 +193,62 @@ hcf:
|
||||
;
|
||||
; ##############################
|
||||
|
||||
; int read_mbr(int boot_drive, void* dst)
|
||||
; destination buffer needs 512 bytes of space
|
||||
read_mbr:
|
||||
__CDECL16_PROC_ENTRY
|
||||
.func:
|
||||
__BOCHS_MAGIC_DEBUG
|
||||
; read mbr on boot drive to memory (for the partition table)
|
||||
movzx ax, byte [bp - 4]
|
||||
push ax ; drive_num (2)
|
||||
push 0x01 ; count (2)
|
||||
|
||||
push dword 0x0 ; lba (4)
|
||||
|
||||
push word [bp - 6] ; offset = dst
|
||||
push __STAGE2_SEGMENT ; this segment
|
||||
__CDECL16_CALL read_disk_raw, 12
|
||||
; TODO: this needs error checking, zero checking, check the sig a bunch of stuff...
|
||||
.endf:
|
||||
__CDECL16_PROC_EXIT
|
||||
.error:
|
||||
ERROR STEVIA_DEBUG_ERR
|
||||
|
||||
; int read_vbr(int boot_drive, void* mbr, void* buf)
|
||||
read_vbr:
|
||||
__CDECL16_PROC_ENTRY
|
||||
.func:
|
||||
__BOCHS_MAGIC_DEBUG
|
||||
; read vbr on boot partition to memory (for fat bpb/ebpb)
|
||||
.calc_part_offset:
|
||||
mov bx, [bp - 6]
|
||||
add bx, 0x1B8 ; offset to partition table in mbr
|
||||
mov cx, 4 ; only checking 4 entries
|
||||
.find_active_L0:
|
||||
mov al, byte [bx + PartEntry_t.attributes]
|
||||
test al, 0x80 ; 0x80 == 1000_0000b
|
||||
jnz read_vbr.active_found
|
||||
add bx, 0x10 ; add 16 bytes to offset
|
||||
loop read_vbr.find_active_L0
|
||||
jmp read_vbr.error
|
||||
.active_found:
|
||||
movzx ax, byte [bp - 4]
|
||||
push ax ; drive_num (2)
|
||||
push 0x01 ; count (2)
|
||||
|
||||
mov eax, dword [bx + PartEntry_t.lba_start]
|
||||
push dword eax ; lba (4)
|
||||
|
||||
push word [bp - 6] ; offset = dst
|
||||
push __STAGE2_SEGMENT ; this segment
|
||||
__CDECL16_CALL read_disk_raw, 12
|
||||
; vbr (with fat bpb/ebpb) is at the buffer now
|
||||
.endf:
|
||||
__CDECL16_PROC_EXIT
|
||||
.error:
|
||||
ERROR STEVIA_DEBUG_ERR
|
||||
|
||||
; set ds and es segments back to the base of the loader
|
||||
%ifnmacro __TINY_DS_ES
|
||||
%macro __TINY_DS_ES 0
|
||||
|
||||
@@ -85,10 +85,6 @@ init:
|
||||
%include "util/kmem_func.nasm"
|
||||
%include "util/error_func.nasm"
|
||||
|
||||
; ###############
|
||||
; End Section
|
||||
; ###############
|
||||
|
||||
;
|
||||
; byte boot_drive @ bp - 2
|
||||
; word part_offset @ bp - 4
|
||||
@@ -96,7 +92,7 @@ init:
|
||||
ALIGN 4, db 0x90
|
||||
main:
|
||||
mov byte [bp - 2], dl ; boot_drive
|
||||
mov word [bp - 4], si ; part_offset
|
||||
mov word [bp - 4], si ; part_offset (i.e offset into partition table our boot partition is
|
||||
mov word [bp - 6], bx ; partition_table
|
||||
|
||||
.load_fs_data:
|
||||
|
||||
Reference in New Issue
Block a user