tons more work on modularizing the code
This commit is contained in:
@@ -10,7 +10,7 @@ floppy_bootsig_check: disabled=0
|
|||||||
floppya: type=1_44
|
floppya: type=1_44
|
||||||
# no floppyb
|
# no floppyb
|
||||||
ata0: enabled=true, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
|
ata0: enabled=true, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
|
||||||
ata0-master: type=disk, path=".\disk.img", mode=flat, cylinders=0, heads=0, spt=0, sect_size=512, model="Stevia Disk", biosdetect=auto, translation=auto
|
ata0-master: type=disk, path=".\disk.img", mode=flat, cylinders=0, heads=0, spt=0, sect_size=512, model="Stevia Disk", biosdetect=auto, translation=lba
|
||||||
ata0-slave: type=none
|
ata0-slave: type=none
|
||||||
ata1: type=none
|
ata1: type=none
|
||||||
ata1-master: type=none
|
ata1-master: type=none
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
; SOFTWARE.
|
; SOFTWARE.
|
||||||
|
|
||||||
|
%ifndef __INC_E820MEMORY_MAP
|
||||||
|
|
||||||
; Address Range Descriptor Structure
|
; Address Range Descriptor Structure
|
||||||
;
|
;
|
||||||
@@ -116,6 +117,7 @@ struc AddressRangeDescStruct_t
|
|||||||
.ExtType resd 1
|
.ExtType resd 1
|
||||||
endstruc
|
endstruc
|
||||||
|
|
||||||
|
ALIGN 4, db 0x90
|
||||||
GetMemoryMap:
|
GetMemoryMap:
|
||||||
__CDECL16_ENTRY
|
__CDECL16_ENTRY
|
||||||
push es ; save segment register
|
push es ; save segment register
|
||||||
@@ -158,4 +160,7 @@ GetMemoryMap:
|
|||||||
.endp:
|
.endp:
|
||||||
pop es
|
pop es
|
||||||
__CDECL16_EXIT
|
__CDECL16_EXIT
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
%endif
|
||||||
|
%define __INC_E820MEMORY_MAP
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
; SOFTWARE.
|
; SOFTWARE.
|
||||||
|
|
||||||
|
%ifndef __INC_A20ENABLE
|
||||||
;
|
;
|
||||||
;INT 0x15 Function 2400 - Disable A20
|
;INT 0x15 Function 2400 - Disable A20
|
||||||
;Returns:
|
;Returns:
|
||||||
@@ -66,6 +67,7 @@
|
|||||||
; Bit 3 - power on password bytes (CMOS bytes 0x38-0x3f or 0x36-0x3f). 0: accessible, 1: inaccessible
|
; Bit 3 - power on password bytes (CMOS bytes 0x38-0x3f or 0x36-0x3f). 0: accessible, 1: inaccessible
|
||||||
; Bits 4-5 - Manufacturer defined
|
; Bits 4-5 - Manufacturer defined
|
||||||
; Bits 6-7 - 00: HDD activity LED off; any other value is "on"
|
; Bits 6-7 - 00: HDD activity LED off; any other value is "on"
|
||||||
|
ALIGN 4, db 0x90
|
||||||
EnableA20:
|
EnableA20:
|
||||||
__CDECL16_ENTRY
|
__CDECL16_ENTRY
|
||||||
push ds
|
push ds
|
||||||
@@ -136,4 +138,7 @@ EnableA20:
|
|||||||
pop es
|
pop es
|
||||||
pop ds
|
pop ds
|
||||||
__CDECL16_EXIT
|
__CDECL16_EXIT
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
%endif
|
||||||
|
%define __INC_A20ENABLE
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
; SOFTWARE.
|
; SOFTWARE.
|
||||||
|
|
||||||
|
%ifndef __INC_EXT_READ
|
||||||
;Offset Size Description
|
;Offset Size Description
|
||||||
; 0 1 size of packet (16 bytes)
|
; 0 1 size of packet (16 bytes)
|
||||||
; 1 1 always 0
|
; 1 1 always 0
|
||||||
@@ -52,25 +53,28 @@ endstruc
|
|||||||
; successfully transferred
|
; successfully transferred
|
||||||
;
|
;
|
||||||
;
|
;
|
||||||
; uint8_t read_disk_raw(uint16_t buf_segment, uint16_t buf_offset, uint32_t lba)
|
; uint8_t read_stage2_raw(uint16_t buf_segment, uint16_t buf_offset,
|
||||||
; TODO: this needs validation
|
; uint32_t lba,
|
||||||
|
; uint16_t count, uint16_t drive_num)
|
||||||
|
ALIGN 4, db 0x90
|
||||||
read_disk_raw:
|
read_disk_raw:
|
||||||
__CDECL16_ENTRY
|
__CDECL16_ENTRY
|
||||||
.func:
|
.func:
|
||||||
mov ax, 0x10
|
mov ax, 0x10
|
||||||
push ax ; len = 16 bytes
|
push ax ; len = 16 bytes
|
||||||
xor ax, ax
|
xor ax, ax
|
||||||
push ax ; val = 0
|
push ax ; val = 0
|
||||||
mov ax, lba_packet
|
mov ax, lba_packet
|
||||||
push ax ; dest = lba_packet address
|
push ax ; dest = lba_packet address
|
||||||
|
call kmemset
|
||||||
call kmemset ; uint8_t* kmemset(void* dest, uint8_t val, size_t len);
|
add sp, 0x06
|
||||||
add sp, 0x6
|
|
||||||
|
|
||||||
mov byte [lba_packet + LBAPkt_t.size], 0x10
|
mov byte [lba_packet + LBAPkt_t.size], 0x10
|
||||||
mov word [lba_packet + LBAPkt_t.xfer_size], 0x0001
|
|
||||||
|
|
||||||
mov dword eax, [bp + 8]
|
mov ax, [bp + 12]
|
||||||
|
mov word [lba_packet + LBAPkt_t.xfer_size], ax
|
||||||
|
|
||||||
|
mov eax, [bp + 8]
|
||||||
mov dword [lba_packet + LBAPkt_t.lower_lba], eax
|
mov dword [lba_packet + LBAPkt_t.lower_lba], eax
|
||||||
|
|
||||||
mov ax, [bp + 6]
|
mov ax, [bp + 6]
|
||||||
@@ -81,10 +85,26 @@ read_disk_raw:
|
|||||||
|
|
||||||
mov si, lba_packet
|
mov si, lba_packet
|
||||||
mov ah, 0x42
|
mov ah, 0x42
|
||||||
mov dl, byte [fat32_ebpb + FAT32_ebpb_t.drive_number_8]
|
|
||||||
|
;BUG: still working on getting this passed down correctly, going to hard set it for now.
|
||||||
|
movzx dx, byte [bp + 14]
|
||||||
|
and dx, 0x00ff
|
||||||
|
;xor dl, dl
|
||||||
|
;mov dl, 0x80
|
||||||
|
|
||||||
int 0x13
|
int 0x13
|
||||||
jnc read_disk_raw.endp
|
jnc .endf
|
||||||
|
|
||||||
|
%ifdef __STEVIA_MBR
|
||||||
|
ERROR MBR_ERROR_DISK_READ_ERR
|
||||||
|
%elifsef __STEVIA_VBR
|
||||||
|
ERROR VBR_ERROR_DISK_READ_ERR
|
||||||
|
%else
|
||||||
ERROR STAGE2_MBR_DISK_READ_ERROR
|
ERROR STAGE2_MBR_DISK_READ_ERROR
|
||||||
.endp:
|
%endif
|
||||||
|
.endf:
|
||||||
__CDECL16_EXIT
|
__CDECL16_EXIT
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
%endif
|
||||||
|
%define __INC_EXT_READ
|
||||||
@@ -18,9 +18,11 @@
|
|||||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
; SOFTWARE.
|
; SOFTWARE.
|
||||||
|
|
||||||
|
%ifndef __INC_VIDEO
|
||||||
; Sets output to 80x25 16 color text mode via BIOS call
|
; Sets output to 80x25 16 color text mode via BIOS call
|
||||||
; also clears screen
|
; also clears screen
|
||||||
; void SetTextMode(void)
|
; void SetTextMode(void)
|
||||||
|
ALIGN 4, db 0x90
|
||||||
SetTextMode:
|
SetTextMode:
|
||||||
.prolog:
|
.prolog:
|
||||||
__CDECL16_ENTRY
|
__CDECL16_ENTRY
|
||||||
@@ -39,6 +41,7 @@ SetTextMode:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
; disables blinking text mode cursor
|
; disables blinking text mode cursor
|
||||||
|
ALIGN 4, db 0x90
|
||||||
disable_cursor:
|
disable_cursor:
|
||||||
__CDECL16_ENTRY
|
__CDECL16_ENTRY
|
||||||
.func:
|
.func:
|
||||||
@@ -51,4 +54,7 @@ disable_cursor:
|
|||||||
out dx, al
|
out dx, al
|
||||||
.endp:
|
.endp:
|
||||||
__CDECL16_EXIT
|
__CDECL16_EXIT
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
%endif
|
||||||
|
%define __INC_VIDEO
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
%macro __CDECL16_ENTRY 0
|
%macro __CDECL16_ENTRY 0
|
||||||
push bp
|
push bp
|
||||||
mov bp, sp
|
mov bp, sp
|
||||||
|
sub sp, 0x20
|
||||||
|
|
||||||
push si
|
push si
|
||||||
push di
|
push di
|
||||||
@@ -37,4 +38,4 @@
|
|||||||
mov sp, bp
|
mov sp, bp
|
||||||
pop bp
|
pop bp
|
||||||
%endmacro
|
%endmacro
|
||||||
%endif
|
%endif
|
||||||
@@ -18,8 +18,12 @@
|
|||||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
; SOFTWARE.
|
; SOFTWARE.
|
||||||
|
|
||||||
|
%ifndef __INC_STEVIA_CONFIG
|
||||||
|
|
||||||
%define SECTOR_SIZE 512
|
%define SECTOR_SIZE 512
|
||||||
%define STAGE2_SECTOR_COUNT 0x40
|
%define STAGE2_SECTOR_COUNT 0x40
|
||||||
; 32 KiB
|
; 32 KiB
|
||||||
%define MAX_STAGE2_BYTES (SECTOR_SIZE * STAGE2_SECTOR_COUNT)
|
%define MAX_STAGE2_BYTES (SECTOR_SIZE * STAGE2_SECTOR_COUNT)
|
||||||
|
|
||||||
|
%endif
|
||||||
|
%define __INC_STEVIA_CONFIG
|
||||||
@@ -18,9 +18,13 @@
|
|||||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
; SOFTWARE.
|
; SOFTWARE.
|
||||||
|
|
||||||
|
%ifndef __INC_ENTRY
|
||||||
|
|
||||||
; 8KiB from 0x2500 -> 0x500
|
; 8KiB from 0x2500 -> 0x500
|
||||||
%define EARLY_STACK_START 0x2500
|
%define EARLY_STACK_START 0x2500
|
||||||
%define MBR_ENTRY 0x7A00
|
%define MBR_ENTRY 0x7A00
|
||||||
%define VBR_ENTRY 0x7C00
|
%define VBR_ENTRY 0x7C00
|
||||||
%define STAGE2_ENTRY 0x7E00
|
%define STAGE2_ENTRY 0x7E00
|
||||||
|
|
||||||
|
%endif
|
||||||
|
%define __INC_ENTRY
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
; SOFTWARE.
|
; SOFTWARE.
|
||||||
|
|
||||||
|
%ifndef __INC_ERROR_CODES
|
||||||
|
|
||||||
; Errors
|
; Errors
|
||||||
; 12 Errors, 5 in use
|
; 12 Errors, 5 in use
|
||||||
@@ -76,4 +77,7 @@
|
|||||||
%define STEVIA_DEBUG_OK 'W'
|
%define STEVIA_DEBUG_OK 'W'
|
||||||
%define STEVIA_DEBUG_ERR 'X'
|
%define STEVIA_DEBUG_ERR 'X'
|
||||||
%define STEVIA_DEBUG_UNIMPLEMENTED 'Y'
|
%define STEVIA_DEBUG_UNIMPLEMENTED 'Y'
|
||||||
%define STEVIA_DEBUG_HALT 'Z'
|
%define STEVIA_DEBUG_HALT 'Z'
|
||||||
|
|
||||||
|
%endif
|
||||||
|
%define __INC_ERROR_CODES
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
; SOFTWARE.
|
; SOFTWARE.
|
||||||
|
|
||||||
|
%ifndef __INC_BPD_OFFSET_BX
|
||||||
|
|
||||||
; BPB Information
|
; BPB Information
|
||||||
; Off. Hex Off. Size Description
|
; Off. Hex Off. Size Description
|
||||||
@@ -88,4 +89,7 @@
|
|||||||
%define bsVolumeSerial bx+0x43
|
%define bsVolumeSerial bx+0x43
|
||||||
%define bsVolumeLabel bx+0x47
|
%define bsVolumeLabel bx+0x47
|
||||||
%define bsSystemIdent bx+0x52
|
%define bsSystemIdent bx+0x52
|
||||||
;-- End EBPB
|
;-- End EBPB
|
||||||
|
|
||||||
|
%endif
|
||||||
|
%define __INC_BPD_OFFSET_BX
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
; SOFTWARE.
|
; SOFTWARE.
|
||||||
|
|
||||||
|
%ifndef __INC_FAT32_STRUCT
|
||||||
|
|
||||||
; ## FAT32 Info ##
|
; ## FAT32 Info ##
|
||||||
; total_sectors = bsSectorsHuge
|
; total_sectors = bsSectorsHuge
|
||||||
@@ -230,4 +231,5 @@ endstruc
|
|||||||
; LFN == RO | HIDDEN | SYSTEM | VOLID == 0x0F
|
; LFN == RO | HIDDEN | SYSTEM | VOLID == 0x0F
|
||||||
%define FAT32_ATTR_LFN 0x0F
|
%define FAT32_ATTR_LFN 0x0F
|
||||||
|
|
||||||
|
%endif
|
||||||
|
%define __INC_FAT32_STRUCT
|
||||||
@@ -18,6 +18,13 @@
|
|||||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
; SOFTWARE.
|
; SOFTWARE.
|
||||||
|
|
||||||
|
%ifndef __INC_FAT32_SYS
|
||||||
|
|
||||||
|
%include "partition_table.inc"
|
||||||
|
%include "fat32/bpb_offset_bx.inc"
|
||||||
|
%include "fat32/fat32_structures.inc"
|
||||||
|
|
||||||
|
ALIGN 4, db 0x90
|
||||||
InitFATDriver:
|
InitFATDriver:
|
||||||
__CDECL16_ENTRY
|
__CDECL16_ENTRY
|
||||||
.func:
|
.func:
|
||||||
@@ -28,9 +35,14 @@ InitFATDriver:
|
|||||||
mov dword [fat32_state + FAT32_State_t.active_dir_cluster_32], eax
|
mov dword [fat32_state + FAT32_State_t.active_dir_cluster_32], eax
|
||||||
|
|
||||||
.calc_active_part:
|
.calc_active_part:
|
||||||
mov ax, word [partition_offset]
|
mov bx, [partition_offset_ptr]
|
||||||
mov bx, partition_table
|
mov ax, [bx + 0]
|
||||||
add bx, ax ; bx points to the partition that was booted from
|
mov bx, ax
|
||||||
|
mov ax, [bx + 0]
|
||||||
|
|
||||||
|
mov dx, partition_table
|
||||||
|
add dx, ax ; dx points to the partition that was booted from
|
||||||
|
mov bx, dx ; set bx, should point at our partition
|
||||||
|
|
||||||
mov eax, dword [bx + PartEntry_t.lba_start]
|
mov eax, dword [bx + PartEntry_t.lba_start]
|
||||||
mov dword [fat32_state + FAT32_State_t.active_drive_lba_32], eax
|
mov dword [fat32_state + FAT32_State_t.active_drive_lba_32], eax
|
||||||
@@ -72,6 +84,7 @@ InitFATDriver:
|
|||||||
; returns first cluster of file if found
|
; returns first cluster of file if found
|
||||||
; halts/errors if file is not found
|
; halts/errors if file is not found
|
||||||
; uint32_t SearchFATDIR(uint8_t* SFN);
|
; uint32_t SearchFATDIR(uint8_t* SFN);
|
||||||
|
ALIGN 4, db 0x90
|
||||||
SearchFATDIR:
|
SearchFATDIR:
|
||||||
__CDECL16_ENTRY
|
__CDECL16_ENTRY
|
||||||
.file_lookup:
|
.file_lookup:
|
||||||
@@ -173,9 +186,16 @@ SearchFATDIR:
|
|||||||
; uint32_t NextCluster(uint32_t active_cluster);
|
; uint32_t NextCluster(uint32_t active_cluster);
|
||||||
; if eax >= 0x0FFFFFF8 then there are no more clusters (end of chain)
|
; if eax >= 0x0FFFFFF8 then there are no more clusters (end of chain)
|
||||||
; if eax == 0x0FFFFFF7 then this is a cluster that is marked as bad
|
; if eax == 0x0FFFFFF7 then this is a cluster that is marked as bad
|
||||||
|
ALIGN 4, db 0x90
|
||||||
NextCluster:
|
NextCluster:
|
||||||
__CDECL16_ENTRY
|
__CDECL16_ENTRY
|
||||||
.func:
|
.func:
|
||||||
|
mov bx, [boot_drive_ptr]
|
||||||
|
mov ax, [bx + 0]
|
||||||
|
mov bx, ax
|
||||||
|
movzx ax, byte [bx + 0] ; 67h override would probably work but this is the 16bit way to do it
|
||||||
|
mov byte [bp - 2], al ; save boot drive as a local for easy access
|
||||||
|
|
||||||
mov dword edx, [bp + 4]
|
mov dword edx, [bp + 4]
|
||||||
mov si, fat32_nc_data
|
mov si, fat32_nc_data
|
||||||
.calc_offset:
|
.calc_offset:
|
||||||
@@ -213,7 +233,14 @@ NextCluster:
|
|||||||
add eax, ecx ; fat_sector + first_fat_sector
|
add eax, ecx ; fat_sector + first_fat_sector
|
||||||
mov dword [si + FAT32_NextClusterData_t.fat_sector], eax
|
mov dword [si + FAT32_NextClusterData_t.fat_sector], eax
|
||||||
.load_fat_table:
|
.load_fat_table:
|
||||||
; load correct fat
|
movzx ax, [bp - 2]
|
||||||
|
push ax
|
||||||
|
|
||||||
|
mov ax, 0x1
|
||||||
|
push ax
|
||||||
|
|
||||||
|
; load correct fat
|
||||||
|
mov eax, dword [si + FAT32_NextClusterData_t.fat_sector]
|
||||||
push dword eax
|
push dword eax
|
||||||
|
|
||||||
mov ax, fat_buffer
|
mov ax, fat_buffer
|
||||||
@@ -221,10 +248,11 @@ NextCluster:
|
|||||||
|
|
||||||
xor ax, ax
|
xor ax, ax
|
||||||
push ax
|
push ax
|
||||||
; uint8_t read_disk_raw(uint16_t buf_segment, uint16_t buf_offset, uint16_t lower_lower_lba, uint16_t upper_lower_lba)
|
call read_disk_raw
|
||||||
call read_disk_raw ; read_disk_raw(0, fat_buffer, fat_sector)
|
add sp, 0xC
|
||||||
add sp, 0x8
|
; uint8_t read_stage2_raw(uint16_t buf_segment, uint16_t buf_offset,
|
||||||
|
; uint32_t lba,
|
||||||
|
; uint16_t count, uint16_t drive_num)
|
||||||
.read_cluster:
|
.read_cluster:
|
||||||
; next_cluster = fat_buffer[entry_offset]
|
; next_cluster = fat_buffer[entry_offset]
|
||||||
mov ebx, dword [si + FAT32_NextClusterData_t.entry_offset]
|
mov ebx, dword [si + FAT32_NextClusterData_t.entry_offset]
|
||||||
@@ -235,6 +263,7 @@ NextCluster:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
; uint32_t ClusterToLBA(uint32_t cluster)
|
; uint32_t ClusterToLBA(uint32_t cluster)
|
||||||
|
ALIGN 4, db 0x90
|
||||||
ClusterToLBA:
|
ClusterToLBA:
|
||||||
__CDECL16_ENTRY
|
__CDECL16_ENTRY
|
||||||
.func:
|
.func:
|
||||||
@@ -249,25 +278,42 @@ ClusterToLBA:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
; uint8_t ReadFATCluster(uint16_t seg, uint16_t offset, uint32_t cluster)
|
; uint8_t ReadFATCluster(uint16_t seg, uint16_t offset, uint32_t cluster)
|
||||||
|
ALIGN 4, db 0x90
|
||||||
ReadFATCluster:
|
ReadFATCluster:
|
||||||
__CDECL16_ENTRY
|
__CDECL16_ENTRY
|
||||||
.func:
|
.func:
|
||||||
|
mov bx, [boot_drive_ptr]
|
||||||
|
mov ax, [bx + 0]
|
||||||
|
mov bx, ax
|
||||||
|
movzx ax, byte [bx + 0] ; 67h override would probably work but this is the 16bit way to do it
|
||||||
|
mov byte [bp - 2], al ; save boot drive as a local for easy access
|
||||||
|
|
||||||
mov dword eax, [bp + 8]
|
mov dword eax, [bp + 8]
|
||||||
push dword eax
|
push dword eax
|
||||||
call ClusterToLBA ; uint32_t ClusterToLBA(uint32_t cluster)
|
call ClusterToLBA ; uint32_t ClusterToLBA(uint32_t cluster)
|
||||||
add sp, 0x4 ; eax == LBA
|
add sp, 0x4 ; eax == LBA
|
||||||
|
|
||||||
|
|
||||||
push dword eax ;uint32_t lba
|
movzx ax, [bp - 2]
|
||||||
|
push ax
|
||||||
|
|
||||||
mov dx, [bp + 4] ; seg
|
mov ax, 0x1
|
||||||
push dx ; uint16_t buf_offset
|
push ax
|
||||||
|
|
||||||
mov dx, [bp + 6] ; offset
|
; load correct fat
|
||||||
push dx ; unit16_t segment
|
mov eax, dword [si + FAT32_NextClusterData_t.fat_sector]
|
||||||
|
push dword eax
|
||||||
|
|
||||||
call read_disk_raw ; uint8_t read_disk_raw(uint16_t buf_segment, uint16_t buf_offset, uint32_t lba)
|
mov ax, fat_buffer
|
||||||
add sp, 0x8
|
push ax
|
||||||
|
|
||||||
|
xor ax, ax
|
||||||
|
push ax
|
||||||
|
call read_disk_raw
|
||||||
|
add sp, 0xC
|
||||||
.endp:
|
.endp:
|
||||||
__CDECL16_EXIT
|
__CDECL16_EXIT
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
%endif
|
||||||
|
%define __INC_FAT32_SYS
|
||||||
@@ -17,15 +17,18 @@
|
|||||||
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
; SOFTWARE.
|
; SOFTWARE.
|
||||||
|
|
||||||
|
%ifndef __INC_KMEM_FUNC
|
||||||
%include 'cdecl16.inc'
|
%include 'cdecl16.inc'
|
||||||
|
|
||||||
; uint8_t* kmemset(void* dest, uint8_t val, uint8_t len);
|
; uint8_t* kmemset_byte(void* dst, uint8_t val, uint16_t len);
|
||||||
|
ALIGN 4, db 0x90
|
||||||
kmemset:
|
kmemset:
|
||||||
__CDECL16_ENTRY
|
__CDECL16_ENTRY
|
||||||
.func:
|
.func:
|
||||||
mov cx, [bp + 8] ; size_t len
|
mov cx, [bp + 8] ; size_t len
|
||||||
mov al, [bp + 6] ; uint8_t val
|
mov al, [bp + 6] ; uint8_t val
|
||||||
mov di, [bp + 4] ; void * ptr
|
mov di, [bp + 4] ; void * dst
|
||||||
|
|
||||||
cld
|
cld
|
||||||
rep stosb
|
rep stosb
|
||||||
@@ -36,6 +39,7 @@ kmemset:
|
|||||||
|
|
||||||
; uint8_t* kmemset(uint8_t* dest, uint8_t* src, uint8_t len);
|
; uint8_t* kmemset(uint8_t* dest, uint8_t* src, uint8_t len);
|
||||||
; not overlap safe
|
; not overlap safe
|
||||||
|
ALIGN 4, db 0x90
|
||||||
kmemcpy:
|
kmemcpy:
|
||||||
__CDECL16_ENTRY
|
__CDECL16_ENTRY
|
||||||
.func:
|
.func:
|
||||||
@@ -48,4 +52,7 @@ kmemcpy:
|
|||||||
mov ax, di ; return pointer to dest
|
mov ax, di ; return pointer to dest
|
||||||
.endf:
|
.endf:
|
||||||
__CDECL16_EXIT
|
__CDECL16_EXIT
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
%endif
|
||||||
|
%define __INC_KMEM_FUNC
|
||||||
@@ -18,6 +18,8 @@
|
|||||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
; SOFTWARE.
|
; SOFTWARE.
|
||||||
|
|
||||||
|
%ifndef __INC_MEM
|
||||||
|
|
||||||
|
|
||||||
; ## Generic Low mem map (from osdev wiki) ##
|
; ## Generic Low mem map (from osdev wiki) ##
|
||||||
; start end size type description
|
; start end size type description
|
||||||
@@ -54,12 +56,12 @@
|
|||||||
|
|
||||||
; copy of FAT32 BPB, 33 bytes (+1 to the next value to align to uint16_t)
|
; copy of FAT32 BPB, 33 bytes (+1 to the next value to align to uint16_t)
|
||||||
;0x3048
|
;0x3048
|
||||||
%define fat32_bpb 0x3050
|
%define fat32_bpb 0x304A
|
||||||
%define fat32_bpb_SIZE 33
|
%define fat32_bpb_SIZE 36
|
||||||
|
|
||||||
; copy of FAT32 EBPB, 54 bytes
|
; copy of FAT32 EBPB, 54 bytes
|
||||||
;0x306A
|
;0x306A
|
||||||
%define fat32_ebpb 0x30A0
|
%define fat32_ebpb 0x306E
|
||||||
%define fat32_ebpb_SIZE 54
|
%define fat32_ebpb_SIZE 54
|
||||||
|
|
||||||
; FAT32 FSInfo, 512 bytes
|
; FAT32 FSInfo, 512 bytes
|
||||||
@@ -69,18 +71,18 @@
|
|||||||
|
|
||||||
; some stored state for the fat32 driver
|
; some stored state for the fat32 driver
|
||||||
;0x32A2
|
;0x32A2
|
||||||
%define fat32_state 0x32B0
|
%define fat32_state 0x34B0
|
||||||
%define fat32_state_SIZE 32
|
%define fat32_state_SIZE 32
|
||||||
|
|
||||||
; next free space is 0x32D0
|
; next free space is 0x32D0
|
||||||
%define fat32_nc_data 0x32D0
|
%define fat32_nc_data 0x35D0
|
||||||
%define fat32_nc_data_size 16
|
%define fat32_nc_data_size 16
|
||||||
|
|
||||||
; lba_packet for raw_disk_read
|
; lba_packet for raw_disk_read
|
||||||
%define lba_packet 0x4000
|
%define lba_packet 0x4000
|
||||||
|
|
||||||
%define BIOSMemoryMap 0x4200
|
%define BIOSMemoryMap 0x4200
|
||||||
%define SteviaInfo 0x4400
|
%define SteviaInfo 0x5200
|
||||||
|
|
||||||
|
|
||||||
; High memory addresses for loading kernel (for use with unreal mode and 32bit override)
|
; High memory addresses for loading kernel (for use with unreal mode and 32bit override)
|
||||||
@@ -110,8 +112,5 @@ struc SteviaInfoStruct_t
|
|||||||
.EBPBDataPtr resd 1
|
.EBPBDataPtr resd 1
|
||||||
endstruc
|
endstruc
|
||||||
|
|
||||||
%macro DEBUG_HCF 0
|
%endif
|
||||||
DEBUG_LOOP:
|
%define __INC_MEM
|
||||||
hlt
|
|
||||||
jmp short DEBUG_LOOP
|
|
||||||
%endmacro
|
|
||||||
@@ -18,6 +18,8 @@
|
|||||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
; SOFTWARE.
|
; SOFTWARE.
|
||||||
|
|
||||||
|
%ifndef __INC_PART_TABLE
|
||||||
|
|
||||||
; Partition table entry format
|
; Partition table entry format
|
||||||
; Off. Size. Description
|
; Off. Size. Description
|
||||||
;0x00 1 Drive attributes (bit 7 set = active or bootable)
|
;0x00 1 Drive attributes (bit 7 set = active or bootable)
|
||||||
@@ -41,4 +43,7 @@ struc PartTable_t
|
|||||||
.partition2 resb 16
|
.partition2 resb 16
|
||||||
.partition3 resb 16
|
.partition3 resb 16
|
||||||
.partition4 resb 16
|
.partition4 resb 16
|
||||||
endstruc
|
endstruc
|
||||||
|
|
||||||
|
%endif
|
||||||
|
%define __INC_PART_TABLE
|
||||||
@@ -18,13 +18,23 @@
|
|||||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
; SOFTWARE.
|
; SOFTWARE.
|
||||||
|
|
||||||
|
%ifndef __INC_ERROR_FUNC
|
||||||
|
|
||||||
%macro ERROR 1
|
%macro ERROR 1
|
||||||
xor ax, ax
|
xor ax, ax
|
||||||
mov al, %1
|
mov al, %1
|
||||||
jmp error
|
jmp error
|
||||||
%endmacro
|
%endmacro
|
||||||
|
|
||||||
|
%macro DEBUG_HCF 0
|
||||||
|
DEBUG_LOOP:
|
||||||
|
cli
|
||||||
|
hlt
|
||||||
|
jmp short DEBUG_LOOP
|
||||||
|
%endmacro
|
||||||
|
|
||||||
; pass error as ascii character in al, errors a-zA-Z or 0-9
|
; pass error as ascii character in al, errors a-zA-Z or 0-9
|
||||||
|
ALIGN 4, db 0x90
|
||||||
error:
|
error:
|
||||||
; fs = 0xb800 => fs:0x0000 = 0xb8000
|
; fs = 0xb800 => fs:0x0000 = 0xb8000
|
||||||
mov dx, 0xB800
|
mov dx, 0xB800
|
||||||
@@ -47,4 +57,7 @@ error:
|
|||||||
|
|
||||||
.stop:
|
.stop:
|
||||||
hlt
|
hlt
|
||||||
jmp short error.stop
|
jmp short error.stop
|
||||||
|
|
||||||
|
%endif
|
||||||
|
%define __INC_ERROR_FUNC
|
||||||
179
src/mbr/mbr.nasm
179
src/mbr/mbr.nasm
@@ -23,17 +23,37 @@
|
|||||||
[CPU KATMAI]
|
[CPU KATMAI]
|
||||||
jmp short init
|
jmp short init
|
||||||
nop
|
nop
|
||||||
%include "cdecl16.inc" ; include calling convention macros for cdecl16
|
|
||||||
%include "entry.inc" ; defines with entry points for various stages & stack
|
|
||||||
init:
|
|
||||||
cli ; We do not want to be interrupted
|
|
||||||
|
|
||||||
xor ax, ax ; 0 AX
|
; ###############
|
||||||
mov ds, ax ; Set segment registers to 0
|
;
|
||||||
mov es, ax ; *
|
; Headers/Includes/Definitions
|
||||||
|
;
|
||||||
mov ss, ax ; Set Stack Segment to 0
|
; ###############
|
||||||
mov sp, EARLY_STACK_START
|
|
||||||
|
%define __STEVIA_MBR
|
||||||
|
|
||||||
|
%include "cdecl16.inc"
|
||||||
|
%include "entry.inc"
|
||||||
|
%include "config.inc"
|
||||||
|
%include "mem.inc"
|
||||||
|
%include "error_codes.inc"
|
||||||
|
%include "partition_table.inc"
|
||||||
|
|
||||||
|
; ###############
|
||||||
|
; End Section
|
||||||
|
; ###############
|
||||||
|
|
||||||
|
ALIGN 4, db 0x90
|
||||||
|
init:
|
||||||
|
cli ; We do not want to be interrupted
|
||||||
|
|
||||||
|
xor ax, ax ; 0 AX
|
||||||
|
mov ds, ax ; Set segment registers to 0
|
||||||
|
|
||||||
|
mov ss, ax ; Set Stack Segment to 0
|
||||||
|
mov sp, EARLY_STACK_START ; Setup stack
|
||||||
|
mov bp, sp ; base ptr = stack ptr
|
||||||
|
sub sp, 0x20 ; local varible space
|
||||||
|
|
||||||
mov ch, 0x01 ; 256 WORDs in MBR (512 bytes), 0x0100 in cx
|
mov ch, 0x01 ; 256 WORDs in MBR (512 bytes), 0x0100 in cx
|
||||||
mov si, 0x7C00 ; Current MBR Address (loaded here by BIOS)
|
mov si, 0x7C00 ; Current MBR Address (loaded here by BIOS)
|
||||||
@@ -43,16 +63,28 @@ init:
|
|||||||
sti
|
sti
|
||||||
|
|
||||||
jmp 0:main
|
jmp 0:main
|
||||||
nop
|
|
||||||
|
|
||||||
%include "config.inc"
|
; ###############
|
||||||
%include "memory.inc"
|
;
|
||||||
|
; Extra/Shared Functions
|
||||||
|
;
|
||||||
|
; ###############
|
||||||
|
|
||||||
%include "kmem_func.inc"
|
%include "kmem_func.inc"
|
||||||
%include "partition_table.inc"
|
%include "util/error_func.inc"
|
||||||
%include "errors.inc"
|
|
||||||
|
|
||||||
|
; ###############
|
||||||
|
; End Section
|
||||||
|
; ###############
|
||||||
|
|
||||||
|
;
|
||||||
|
; bp - 2 : uint8_t boot_drive
|
||||||
|
; bp - 4 : uint16_t part_offset
|
||||||
|
;
|
||||||
|
|
||||||
|
ALIGN 4, db 0x90
|
||||||
main:
|
main:
|
||||||
mov [boot_drive], dl ; BIOS passes drive number in DL
|
mov byte [bp - 2], dl ; BIOS passes drive number in DL
|
||||||
|
|
||||||
.check_disk:
|
.check_disk:
|
||||||
cmp dl, 0x80
|
cmp dl, 0x80
|
||||||
@@ -62,7 +94,7 @@ main:
|
|||||||
.check_extentions:
|
.check_extentions:
|
||||||
xor ax, ax
|
xor ax, ax
|
||||||
mov bx, 0x55AA
|
mov bx, 0x55AA
|
||||||
mov dl, byte [boot_drive]
|
mov dl, byte [bp - 2]
|
||||||
int 0x13
|
int 0x13
|
||||||
jnc main.find_active
|
jnc main.find_active
|
||||||
ERROR MBR_ERROR_NO_INT32E ; no extended function support
|
ERROR MBR_ERROR_NO_INT32E ; no extended function support
|
||||||
@@ -83,25 +115,30 @@ main:
|
|||||||
mov ax, bx
|
mov ax, bx
|
||||||
sub ax, DiskSig ; leaves us with the offset relative from start of table
|
sub ax, DiskSig ; leaves us with the offset relative from start of table
|
||||||
; this gives us an offset from the begining of the partition table
|
; this gives us an offset from the begining of the partition table
|
||||||
mov word [part_offset], ax ; update part_offset
|
mov word [bp - 4], ax ; update part_offset
|
||||||
.read_data:
|
.read_data:
|
||||||
;uint8_t read_disk_raw(size_t count, uint16_t buf_segment, uint16_t buf_offset,
|
movzx ax, byte [bp - 2]
|
||||||
; uint16_t lower_lower_lba, uint16_t upper_lower_lba)
|
push ax ; drive_num
|
||||||
mov eax, dword [bx + PartEntry_t.lba_start]
|
|
||||||
ror eax, 16
|
|
||||||
push ax
|
|
||||||
|
|
||||||
ror eax, 16
|
mov ax, 0x1
|
||||||
push ax
|
push ax ; count
|
||||||
|
|
||||||
mov ax, VBR_ENTRY
|
mov dword eax, dword [bx + PartEntry_t.lba_start]
|
||||||
push ax
|
push dword eax ; lba
|
||||||
|
|
||||||
xor ax, ax
|
xor ax, ax
|
||||||
push ax ; segment = 0
|
push ax ; offset = 0
|
||||||
|
|
||||||
|
mov ax, VBR_ENTRY
|
||||||
|
shr ax, 4
|
||||||
|
push ax ; segment = 7C0
|
||||||
|
|
||||||
|
; uint8_t read_stage2_raw(uint16_t buf_segment, uint16_t buf_offset,
|
||||||
|
; uint32_t lba,
|
||||||
|
; uint16_t count, uint16_t drive_num)
|
||||||
|
call read_disk_raw
|
||||||
|
add sp, 0xC
|
||||||
|
|
||||||
call read_vbr_raw
|
|
||||||
add sp, 0x8
|
|
||||||
|
|
||||||
jnc main.goto_vbr
|
jnc main.goto_vbr
|
||||||
ERROR MBR_ERROR_DISK_READ_ERR ; error in LBA read
|
ERROR MBR_ERROR_DISK_READ_ERR ; error in LBA read
|
||||||
@@ -120,86 +157,16 @@ main:
|
|||||||
call kmemcpy ; copy partition table to memory
|
call kmemcpy ; copy partition table to memory
|
||||||
add sp, 0x6
|
add sp, 0x6
|
||||||
|
|
||||||
xor ah, ah ; Set Video mode BIOS function
|
mov si, word [bp - 4]
|
||||||
mov al, 0x02 ; 16 color 80x25 Text mode
|
mov dl, byte [bp - 2]
|
||||||
int 0x10 ; Call video interrupt
|
|
||||||
|
|
||||||
mov ah, 0x05 ; Select active display page BIOS function
|
|
||||||
xor al, al ; page 0
|
|
||||||
int 0x10 ; call video interrupt
|
|
||||||
|
|
||||||
mov si, word [part_offset]
|
|
||||||
mov dl, byte [boot_drive]
|
|
||||||
jmp 0:0x7C00
|
jmp 0:0x7C00
|
||||||
|
|
||||||
; Wrapper for AH=0x42 INT13h (Extended Read)
|
; ###############
|
||||||
;
|
;
|
||||||
; BIOS call details
|
; BIOS Functions
|
||||||
; AH = 42h
|
|
||||||
; DL = drive number
|
|
||||||
; DS:SI -> disk address packet
|
|
||||||
;
|
;
|
||||||
; Return:
|
; ###############
|
||||||
; CF clear if successful
|
%include 'BIOS/func/ext_read.inc'
|
||||||
; AH = 00h
|
|
||||||
; CF set on error
|
|
||||||
; AH = error code
|
|
||||||
; disk address packet's block count field set to number of blocks
|
|
||||||
; successfully transferred
|
|
||||||
;
|
|
||||||
;
|
|
||||||
; uint8_t read_disk_raw(uint16_t buf_segment, uint16_t buf_offset, uint16_t lower_lower_lba, uint16_t upper_lower_lba)
|
|
||||||
read_vbr_raw:
|
|
||||||
__CDECL16_ENTRY
|
|
||||||
.func:
|
|
||||||
mov ax, 0x10
|
|
||||||
push ax ; len = 16 bytes
|
|
||||||
xor ax, ax
|
|
||||||
push ax ; val = 0
|
|
||||||
mov ax, lba_packet
|
|
||||||
push ax ; dest = lba_packet address
|
|
||||||
call kmemset
|
|
||||||
add sp, 0x06
|
|
||||||
|
|
||||||
mov byte [lba_packet + LBAPkt_t.size], 0x10
|
|
||||||
mov word [lba_packet + LBAPkt_t.xfer_size], 0x0001
|
|
||||||
|
|
||||||
mov ax, [bp + 10]
|
|
||||||
shl eax, 16
|
|
||||||
mov ax, [bp + 8]
|
|
||||||
mov dword [lba_packet + LBAPkt_t.lower_lba], eax
|
|
||||||
|
|
||||||
mov ax, [bp + 6]
|
|
||||||
mov word [lba_packet + LBAPkt_t.offset], ax
|
|
||||||
|
|
||||||
mov ax, [bp + 4]
|
|
||||||
mov word [lba_packet + LBAPkt_t.segment], ax
|
|
||||||
|
|
||||||
mov si, lba_packet
|
|
||||||
mov ah, 0x42
|
|
||||||
mov dl, byte [boot_drive]
|
|
||||||
int 0x13
|
|
||||||
jnc .endf
|
|
||||||
|
|
||||||
ERROR MBR_ERROR_INT13h_EREAD_ERR
|
|
||||||
.endf:
|
|
||||||
__CDECL16_EXIT
|
|
||||||
ret
|
|
||||||
|
|
||||||
; #############
|
|
||||||
;
|
|
||||||
; Locals
|
|
||||||
;
|
|
||||||
; #############
|
|
||||||
|
|
||||||
boot_drive:
|
|
||||||
db 0x00
|
|
||||||
mbr_reserved1:
|
|
||||||
db 0x00
|
|
||||||
|
|
||||||
; OFFSET from BEGINING of partition table, ie. DiskSig (-6 from PartEntry1)
|
|
||||||
part_offset:
|
|
||||||
dw 0x0000
|
|
||||||
|
|
||||||
%assign bytes_remaining (440 - ($ - $$))
|
%assign bytes_remaining (440 - ($ - $$))
|
||||||
%warning MBR has bytes_remaining bytes remaining for code (MAX: 440 bytes)
|
%warning MBR has bytes_remaining bytes remaining for code (MAX: 440 bytes)
|
||||||
|
|||||||
@@ -23,11 +23,27 @@
|
|||||||
[CPU KATMAI]
|
[CPU KATMAI]
|
||||||
jmp short init
|
jmp short init
|
||||||
nop
|
nop
|
||||||
|
|
||||||
; boot drive in dl
|
; boot drive in dl
|
||||||
; active partition offset in si
|
; active partition offset in si
|
||||||
|
|
||||||
|
; ###############
|
||||||
|
;
|
||||||
|
; Headers/Includes/Definitions
|
||||||
|
;
|
||||||
|
; ###############
|
||||||
|
%define __STEVIA_STAGE2
|
||||||
|
|
||||||
|
|
||||||
%include "cdecl16.inc"
|
%include "cdecl16.inc"
|
||||||
%include "entry.inc"
|
%include "entry.inc"
|
||||||
|
%include "config.inc"
|
||||||
|
%include "mem.inc"
|
||||||
|
%include "error_codes.inc"
|
||||||
|
|
||||||
|
; ###############
|
||||||
|
; End Section
|
||||||
|
; ###############
|
||||||
|
ALIGN 4, db 0x90
|
||||||
init:
|
init:
|
||||||
cli ; We do not want to be interrupted
|
cli ; We do not want to be interrupted
|
||||||
|
|
||||||
@@ -37,32 +53,36 @@ init:
|
|||||||
mov fs, ax ; *
|
mov fs, ax ; *
|
||||||
mov gs, ax ; *
|
mov gs, ax ; *
|
||||||
|
|
||||||
mov ss, ax ; Set Stack Segment to 0
|
mov ss, ax ; Set Stack Segment to 0
|
||||||
mov sp, EARLY_STACK_START ; Set Stack Pointer
|
mov sp, EARLY_STACK_START ; Set Stack Pointer
|
||||||
|
|
||||||
add sp, 0x4
|
|
||||||
mov ax, 0xDEAD
|
|
||||||
push word ax
|
|
||||||
mov ax, 0xBEEF
|
|
||||||
push word ax ; mark top of stack for debuging
|
|
||||||
|
|
||||||
mov bp, sp
|
mov bp, sp
|
||||||
|
sub sp, 0x20 ; 32 bytes for local varibles
|
||||||
|
|
||||||
sti
|
sti
|
||||||
|
|
||||||
jmp 0:main
|
jmp 0:main
|
||||||
|
|
||||||
%include "config.inc"
|
|
||||||
%include "error_codes.inc"
|
|
||||||
%include "memory.inc"
|
|
||||||
%include "kmem_func.inc"
|
|
||||||
%include "partition_table.inc"
|
|
||||||
|
|
||||||
%include "fat32/bpb.inc"
|
; ###############
|
||||||
%include "fat32/fat32_structures.inc"
|
;
|
||||||
|
; Extra/Shared Functions
|
||||||
|
;
|
||||||
|
; ###############
|
||||||
|
|
||||||
|
%include "kmem_func.inc"
|
||||||
|
%include "util/error_func.inc"
|
||||||
|
|
||||||
|
; ###############
|
||||||
|
; End Section
|
||||||
|
; ###############
|
||||||
|
|
||||||
main:
|
main:
|
||||||
mov byte [fat32_ebpb + FAT32_ebpb_t.drive_number_8], dl
|
lea ax, [bp - 2]
|
||||||
mov word [partition_offset], si
|
mov [boot_drive_ptr], ax
|
||||||
|
lea ax, [bp - 4]
|
||||||
|
mov [partition_offset_ptr], ax
|
||||||
|
mov byte [bp - 2], dl ; boot_drive (probably 0x80)
|
||||||
|
mov word [bp - 4], si ; partition_offset
|
||||||
|
|
||||||
mov eax, dword [STAGE2_SIG]
|
mov eax, dword [STAGE2_SIG]
|
||||||
cmp eax, 0xDEADBEEF
|
cmp eax, 0xDEADBEEF
|
||||||
@@ -138,7 +158,7 @@ hcf:
|
|||||||
;
|
;
|
||||||
; ###############
|
; ###############
|
||||||
|
|
||||||
%include 'fat32/fat32_func_old.inc'
|
%include 'fat32/fat32_sys.inc'
|
||||||
|
|
||||||
; ###############
|
; ###############
|
||||||
;
|
;
|
||||||
@@ -306,18 +326,13 @@ NewLine_cstr:
|
|||||||
db StrCRLF_NUL
|
db StrCRLF_NUL
|
||||||
BootTarget_str:
|
BootTarget_str:
|
||||||
db "BOOTI686BIN"
|
db "BOOTI686BIN"
|
||||||
|
boot_drive_ptr:
|
||||||
; #############
|
db 0x00
|
||||||
;
|
stage2_resb_1:
|
||||||
; Locals
|
db 0x00
|
||||||
;
|
partition_offset_ptr:
|
||||||
; #############
|
|
||||||
|
|
||||||
partition_offset:
|
|
||||||
dw 0x0000
|
dw 0x0000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; GDT documentation below:
|
; GDT documentation below:
|
||||||
;
|
;
|
||||||
; Pr: Present bit. This must be 1 for all valid selectors.
|
; Pr: Present bit. This must be 1 for all valid selectors.
|
||||||
|
|||||||
173
src/vbr/vbr.nasm
173
src/vbr/vbr.nasm
@@ -30,36 +30,59 @@ phy_ebpb_start:
|
|||||||
; fill eBPB area with 0x00 since we skip writing this part to disk
|
; fill eBPB area with 0x00 since we skip writing this part to disk
|
||||||
times 54 db 0x00
|
times 54 db 0x00
|
||||||
|
|
||||||
|
; ###############
|
||||||
|
;
|
||||||
|
; Headers/Includes/Definitions
|
||||||
|
;
|
||||||
|
; ###############
|
||||||
|
%define __STEVIA_VBR
|
||||||
|
|
||||||
|
|
||||||
%include "cdecl16.inc"
|
%include "cdecl16.inc"
|
||||||
%include "entry.inc"
|
%include "entry.inc"
|
||||||
|
%include "config.inc"
|
||||||
|
%include "mem.inc"
|
||||||
|
%include "error_codes.inc"
|
||||||
|
%include "fat32/bpb_offset_bx.inc"
|
||||||
|
|
||||||
|
; ###############
|
||||||
|
; End Section
|
||||||
|
; ###############
|
||||||
|
|
||||||
|
ALIGN 4, db 0x90
|
||||||
init:
|
init:
|
||||||
cli ; We do not want to be interrupted
|
cli ; We do not want to be interrupted
|
||||||
|
|
||||||
xor ax, ax ; 0 AX
|
xor ax, ax ; 0 AX
|
||||||
mov ds, ax ; Set segment registers to 0
|
mov ds, ax ; Set segment registers to 0
|
||||||
mov es, ax ; *
|
|
||||||
|
|
||||||
mov ss, ax ; Set Stack Segment to 0
|
mov ss, ax ; Set Stack Segment to 0
|
||||||
mov sp, EARLY_STACK_START ; Setup stack
|
mov sp, EARLY_STACK_START ; Setup stack
|
||||||
mov bp, sp ; base ptr = stack ptr
|
mov bp, sp ; base ptr = stack ptr
|
||||||
|
sub sp, 0x20 ; local varible space
|
||||||
|
|
||||||
mov bx, VBR_ENTRY ; move Bx to the new start of the initial boot sector
|
mov bx, VBR_ENTRY ; move Bx to the new start of the initial boot sector
|
||||||
sti ; all done with inital setup and relocation, reenable interupts
|
sti ; all done with inital setup and relocation, reenable interupts
|
||||||
|
|
||||||
jmp 0:main ; fix up cs:ip just in case and jump to relocated code
|
jmp 0:main ; fix up cs:ip just in case and jump to relocated code
|
||||||
nop
|
|
||||||
|
|
||||||
%include "config.inc"
|
; ###############
|
||||||
%include "memory.inc"
|
;
|
||||||
|
; Extra/Shared Functions
|
||||||
|
;
|
||||||
|
; ###############
|
||||||
|
|
||||||
%include "kmem_func.inc"
|
%include "kmem_func.inc"
|
||||||
%include "partition_table.inc"
|
%include "util/error_func.inc"
|
||||||
%include "errors.inc"
|
|
||||||
|
|
||||||
%include "fat32/bpb.inc"
|
; ###############
|
||||||
|
; End Section
|
||||||
|
; ###############
|
||||||
|
|
||||||
|
ALIGN 4, db 0x90
|
||||||
main:
|
main:
|
||||||
mov [bsDriveNumber], dl ; BIOS passes drive number in DL
|
mov byte [bp - 2], dl ; boot_drive
|
||||||
mov [partition_offset], si ; save passed partition entry offset
|
mov [bp - 4], si ; part_offset
|
||||||
|
|
||||||
.check_FAT_size: ; we only support a very specific setup of FAT32
|
.check_FAT_size: ; we only support a very specific setup of FAT32
|
||||||
cmp dword [bsSectorHuge], 0 ; SectorsHuge will not be set if FAT12/16
|
cmp dword [bsSectorHuge], 0 ; SectorsHuge will not be set if FAT12/16
|
||||||
@@ -69,24 +92,39 @@ main:
|
|||||||
|
|
||||||
; read sectors 1-63 to stage2 entry point
|
; read sectors 1-63 to stage2 entry point
|
||||||
.load_stage2:
|
.load_stage2:
|
||||||
xor ax, ax
|
mov ax, (fat32_bpb_SIZE + fat32_ebpb_SIZE) ; size in byte
|
||||||
push ax ; upper_lower_lba = 0
|
push ax
|
||||||
|
mov ax, (phy_bpb_start - 0x3) ; start of bpb - 0x3 for the jump short main at the start
|
||||||
|
push ax
|
||||||
|
mov ax, fat32_bpb ; defined in memory.inc, destination
|
||||||
|
push ax
|
||||||
|
call kmemcpy ; copy bpb to memory
|
||||||
|
add sp, 0x6
|
||||||
|
|
||||||
mov ax , 1
|
mov bx, fat32_bpb ; bx now points to aligned memory structure
|
||||||
push ax ; lower_lower_lba = 1
|
|
||||||
|
movzx ax, byte [bp - 2]
|
||||||
|
push ax ; drive_num
|
||||||
|
|
||||||
|
mov ax, STAGE2_SECTOR_COUNT
|
||||||
|
push ax ; count
|
||||||
|
|
||||||
|
mov dword eax, 0x1
|
||||||
|
push dword eax ; lba
|
||||||
|
|
||||||
xor ax, ax
|
xor ax, ax
|
||||||
push ax ; offset = 0
|
push ax ; offset = 0
|
||||||
|
|
||||||
; 07E0:0
|
; 07E0:0 = 0x00007e00
|
||||||
mov ax, STAGE2_ENTRY
|
mov ax, STAGE2_ENTRY
|
||||||
shr ax, 4
|
shr ax, 4
|
||||||
push ax ; segment = 7E0
|
push ax ; segment = 7E0
|
||||||
|
|
||||||
;uint8_t read_stage2_raw(uint16_t buf_segment, uint16_t buf_offset,
|
; uint8_t read_stage2_raw(uint16_t buf_segment, uint16_t buf_offset,
|
||||||
; uint16_t lower_lower_lba, uint16_t upper_lower_lba)
|
; uint32_t lba,
|
||||||
call read_stage2_raw
|
; uint16_t count, uint16_t drive_num)
|
||||||
add sp, 0x8
|
call read_disk_raw
|
||||||
|
add sp, 0xC
|
||||||
|
|
||||||
.check_sig:
|
.check_sig:
|
||||||
mov ax, 0x7E0
|
mov ax, 0x7E0
|
||||||
@@ -97,97 +135,16 @@ main:
|
|||||||
ERROR VBR_ERROR_NO_SIGNATURE ; no signature present in stage2
|
ERROR VBR_ERROR_NO_SIGNATURE ; no signature present in stage2
|
||||||
|
|
||||||
.sig_ok:
|
.sig_ok:
|
||||||
mov ax, fat32_bpb_SIZE ; size in byte
|
mov si, [bp - 4]
|
||||||
push ax
|
mov dx, [bp - 2]
|
||||||
mov ax, phy_bpb_start ; start of bpb
|
|
||||||
push ax
|
|
||||||
mov ax, fat32_bpb ; defined in memory.inc, destination
|
|
||||||
push ax
|
|
||||||
call kmemcpy ; copy bpb to memory
|
|
||||||
add sp, 0x6
|
|
||||||
|
|
||||||
mov ax, fat32_ebpb_SIZE ; 72 bytes of data
|
|
||||||
push ax
|
|
||||||
mov ax, phy_ebpb_start ; start of ebpb
|
|
||||||
push ax
|
|
||||||
mov ax, fat32_ebpb ; defined in memory.inc, destination
|
|
||||||
push ax
|
|
||||||
call kmemcpy ; copy ebpb to memory
|
|
||||||
add sp, 0x6
|
|
||||||
|
|
||||||
mov si, [partition_offset]
|
|
||||||
mov dl, [bsDriveNumber]
|
|
||||||
jmp 0:0x7E00
|
jmp 0:0x7E00
|
||||||
|
|
||||||
stop:
|
; ###############
|
||||||
hlt
|
|
||||||
jmp short stop
|
|
||||||
|
|
||||||
; Wrapper for AH=0x42 INT13h (Extended Read)
|
|
||||||
;
|
;
|
||||||
; BIOS call details
|
; Required BIOS functions
|
||||||
; AH = 42h
|
|
||||||
; DL = drive number
|
|
||||||
; DS:SI -> disk address packet
|
|
||||||
;
|
;
|
||||||
; Return:
|
; ###############
|
||||||
; CF clear if successful
|
%include 'BIOS/func/ext_read.inc'
|
||||||
; AH = 00h
|
|
||||||
; CF set on error
|
|
||||||
; AH = error code
|
|
||||||
; disk address packet's block count field set to number of blocks
|
|
||||||
; successfully transferred
|
|
||||||
;
|
|
||||||
;
|
|
||||||
; uint8_t read_disk_raw(uint16_t buf_segment, uint16_t buf_offset,
|
|
||||||
; uint16_t lower_lower_lba, uint16_t upper_lower_lba)
|
|
||||||
read_stage2_raw:
|
|
||||||
__CDECL16_ENTRY
|
|
||||||
.func:
|
|
||||||
mov ax, 0x10
|
|
||||||
push ax ; len = 16 bytes
|
|
||||||
xor ax, ax
|
|
||||||
push ax ; val = 0
|
|
||||||
mov ax, lba_packet
|
|
||||||
push ax ; dest = lba_packet address
|
|
||||||
call kmemset
|
|
||||||
add sp, 0x06
|
|
||||||
|
|
||||||
mov byte [lba_packet + LBAPkt_t.size], 0x10
|
|
||||||
mov word [lba_packet + LBAPkt_t.xfer_size], STAGE2_SECTOR_COUNT
|
|
||||||
|
|
||||||
mov ax, [bp + 10]
|
|
||||||
shl eax, 16
|
|
||||||
mov ax, [bp + 8]
|
|
||||||
mov dword [lba_packet + LBAPkt_t.lower_lba], eax
|
|
||||||
|
|
||||||
mov ax, [bp + 6]
|
|
||||||
mov word [lba_packet + LBAPkt_t.offset], ax
|
|
||||||
|
|
||||||
mov ax, [bp + 4]
|
|
||||||
mov word [lba_packet + LBAPkt_t.segment], ax
|
|
||||||
|
|
||||||
mov si, lba_packet
|
|
||||||
mov ah, 0x42
|
|
||||||
mov dl, byte [bsDriveNumber]
|
|
||||||
int 0x13
|
|
||||||
jnc .endf
|
|
||||||
|
|
||||||
ERROR VBR_ERROR_DISK_READ_ERR
|
|
||||||
.endf:
|
|
||||||
__CDECL16_EXIT
|
|
||||||
ret
|
|
||||||
; Data
|
|
||||||
|
|
||||||
; #############
|
|
||||||
;
|
|
||||||
; Locals
|
|
||||||
;
|
|
||||||
; #############
|
|
||||||
|
|
||||||
; offset from the begining of sector 0 to the active partition.
|
|
||||||
partition_offset:
|
|
||||||
dw 0x0000
|
|
||||||
|
|
||||||
%assign bytes_remaining (420 - ($ - $$))
|
%assign bytes_remaining (420 - ($ - $$))
|
||||||
%warning VBR has bytes_remaining bytes remaining for code (MAX: 420 bytes)
|
%warning VBR has bytes_remaining bytes remaining for code (MAX: 420 bytes)
|
||||||
|
|||||||
Reference in New Issue
Block a user