tons more work on modularizing the code
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
; SOFTWARE.
|
||||
|
||||
%ifndef __INC_E820MEMORY_MAP
|
||||
|
||||
; Address Range Descriptor Structure
|
||||
;
|
||||
@@ -116,6 +117,7 @@ struc AddressRangeDescStruct_t
|
||||
.ExtType resd 1
|
||||
endstruc
|
||||
|
||||
ALIGN 4, db 0x90
|
||||
GetMemoryMap:
|
||||
__CDECL16_ENTRY
|
||||
push es ; save segment register
|
||||
@@ -158,4 +160,7 @@ GetMemoryMap:
|
||||
.endp:
|
||||
pop es
|
||||
__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
|
||||
; SOFTWARE.
|
||||
|
||||
%ifndef __INC_A20ENABLE
|
||||
;
|
||||
;INT 0x15 Function 2400 - Disable A20
|
||||
;Returns:
|
||||
@@ -66,6 +67,7 @@
|
||||
; Bit 3 - power on password bytes (CMOS bytes 0x38-0x3f or 0x36-0x3f). 0: accessible, 1: inaccessible
|
||||
; Bits 4-5 - Manufacturer defined
|
||||
; Bits 6-7 - 00: HDD activity LED off; any other value is "on"
|
||||
ALIGN 4, db 0x90
|
||||
EnableA20:
|
||||
__CDECL16_ENTRY
|
||||
push ds
|
||||
@@ -136,4 +138,7 @@ EnableA20:
|
||||
pop es
|
||||
pop ds
|
||||
__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
|
||||
; SOFTWARE.
|
||||
|
||||
%ifndef __INC_EXT_READ
|
||||
;Offset Size Description
|
||||
; 0 1 size of packet (16 bytes)
|
||||
; 1 1 always 0
|
||||
@@ -52,25 +53,28 @@ endstruc
|
||||
; successfully transferred
|
||||
;
|
||||
;
|
||||
; uint8_t read_disk_raw(uint16_t buf_segment, uint16_t buf_offset, uint32_t lba)
|
||||
; TODO: this needs validation
|
||||
; uint8_t read_stage2_raw(uint16_t buf_segment, uint16_t buf_offset,
|
||||
; uint32_t lba,
|
||||
; uint16_t count, uint16_t drive_num)
|
||||
ALIGN 4, db 0x90
|
||||
read_disk_raw:
|
||||
__CDECL16_ENTRY
|
||||
.func:
|
||||
.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 ; uint8_t* kmemset(void* dest, uint8_t val, size_t len);
|
||||
add sp, 0x6
|
||||
call kmemset
|
||||
add sp, 0x06
|
||||
|
||||
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 ax, [bp + 6]
|
||||
@@ -81,10 +85,26 @@ read_disk_raw:
|
||||
|
||||
mov si, lba_packet
|
||||
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
|
||||
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
|
||||
.endp:
|
||||
%endif
|
||||
.endf:
|
||||
__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
|
||||
; SOFTWARE.
|
||||
|
||||
%ifndef __INC_VIDEO
|
||||
; Sets output to 80x25 16 color text mode via BIOS call
|
||||
; also clears screen
|
||||
; void SetTextMode(void)
|
||||
ALIGN 4, db 0x90
|
||||
SetTextMode:
|
||||
.prolog:
|
||||
__CDECL16_ENTRY
|
||||
@@ -39,6 +41,7 @@ SetTextMode:
|
||||
ret
|
||||
|
||||
; disables blinking text mode cursor
|
||||
ALIGN 4, db 0x90
|
||||
disable_cursor:
|
||||
__CDECL16_ENTRY
|
||||
.func:
|
||||
@@ -51,4 +54,7 @@ disable_cursor:
|
||||
out dx, al
|
||||
.endp:
|
||||
__CDECL16_EXIT
|
||||
ret
|
||||
ret
|
||||
|
||||
%endif
|
||||
%define __INC_VIDEO
|
||||
@@ -21,6 +21,7 @@
|
||||
%macro __CDECL16_ENTRY 0
|
||||
push bp
|
||||
mov bp, sp
|
||||
sub sp, 0x20
|
||||
|
||||
push si
|
||||
push di
|
||||
@@ -37,4 +38,4 @@
|
||||
mov sp, bp
|
||||
pop bp
|
||||
%endmacro
|
||||
%endif
|
||||
%endif
|
||||
@@ -18,8 +18,12 @@
|
||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
; SOFTWARE.
|
||||
|
||||
%ifndef __INC_STEVIA_CONFIG
|
||||
|
||||
%define SECTOR_SIZE 512
|
||||
%define STAGE2_SECTOR_COUNT 0x40
|
||||
; 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
|
||||
; SOFTWARE.
|
||||
|
||||
%ifndef __INC_ENTRY
|
||||
|
||||
; 8KiB from 0x2500 -> 0x500
|
||||
%define EARLY_STACK_START 0x2500
|
||||
%define MBR_ENTRY 0x7A00
|
||||
%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
|
||||
; SOFTWARE.
|
||||
|
||||
%ifndef __INC_ERROR_CODES
|
||||
|
||||
; Errors
|
||||
; 12 Errors, 5 in use
|
||||
@@ -76,4 +77,7 @@
|
||||
%define STEVIA_DEBUG_OK 'W'
|
||||
%define STEVIA_DEBUG_ERR 'X'
|
||||
%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
|
||||
; SOFTWARE.
|
||||
|
||||
%ifndef __INC_BPD_OFFSET_BX
|
||||
|
||||
; BPB Information
|
||||
; Off. Hex Off. Size Description
|
||||
@@ -88,4 +89,7 @@
|
||||
%define bsVolumeSerial bx+0x43
|
||||
%define bsVolumeLabel bx+0x47
|
||||
%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
|
||||
; SOFTWARE.
|
||||
|
||||
%ifndef __INC_FAT32_STRUCT
|
||||
|
||||
; ## FAT32 Info ##
|
||||
; total_sectors = bsSectorsHuge
|
||||
@@ -230,4 +231,5 @@ endstruc
|
||||
; LFN == RO | HIDDEN | SYSTEM | VOLID == 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
|
||||
; 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:
|
||||
__CDECL16_ENTRY
|
||||
.func:
|
||||
@@ -28,9 +35,14 @@ InitFATDriver:
|
||||
mov dword [fat32_state + FAT32_State_t.active_dir_cluster_32], eax
|
||||
|
||||
.calc_active_part:
|
||||
mov ax, word [partition_offset]
|
||||
mov bx, partition_table
|
||||
add bx, ax ; bx points to the partition that was booted from
|
||||
mov bx, [partition_offset_ptr]
|
||||
mov ax, [bx + 0]
|
||||
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 dword [fat32_state + FAT32_State_t.active_drive_lba_32], eax
|
||||
@@ -72,6 +84,7 @@ InitFATDriver:
|
||||
; returns first cluster of file if found
|
||||
; halts/errors if file is not found
|
||||
; uint32_t SearchFATDIR(uint8_t* SFN);
|
||||
ALIGN 4, db 0x90
|
||||
SearchFATDIR:
|
||||
__CDECL16_ENTRY
|
||||
.file_lookup:
|
||||
@@ -173,9 +186,16 @@ SearchFATDIR:
|
||||
; uint32_t NextCluster(uint32_t active_cluster);
|
||||
; 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
|
||||
ALIGN 4, db 0x90
|
||||
NextCluster:
|
||||
__CDECL16_ENTRY
|
||||
.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 si, fat32_nc_data
|
||||
.calc_offset:
|
||||
@@ -213,7 +233,14 @@ NextCluster:
|
||||
add eax, ecx ; fat_sector + first_fat_sector
|
||||
mov dword [si + FAT32_NextClusterData_t.fat_sector], eax
|
||||
.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
|
||||
|
||||
mov ax, fat_buffer
|
||||
@@ -221,10 +248,11 @@ NextCluster:
|
||||
|
||||
xor ax, 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 ; read_disk_raw(0, fat_buffer, fat_sector)
|
||||
add sp, 0x8
|
||||
|
||||
call read_disk_raw
|
||||
add sp, 0xC
|
||||
; 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:
|
||||
; next_cluster = fat_buffer[entry_offset]
|
||||
mov ebx, dword [si + FAT32_NextClusterData_t.entry_offset]
|
||||
@@ -235,6 +263,7 @@ NextCluster:
|
||||
ret
|
||||
|
||||
; uint32_t ClusterToLBA(uint32_t cluster)
|
||||
ALIGN 4, db 0x90
|
||||
ClusterToLBA:
|
||||
__CDECL16_ENTRY
|
||||
.func:
|
||||
@@ -249,25 +278,42 @@ ClusterToLBA:
|
||||
ret
|
||||
|
||||
; uint8_t ReadFATCluster(uint16_t seg, uint16_t offset, uint32_t cluster)
|
||||
ALIGN 4, db 0x90
|
||||
ReadFATCluster:
|
||||
__CDECL16_ENTRY
|
||||
.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]
|
||||
push dword eax
|
||||
call ClusterToLBA ; uint32_t ClusterToLBA(uint32_t cluster)
|
||||
add sp, 0x4 ; eax == LBA
|
||||
|
||||
|
||||
push dword eax ;uint32_t lba
|
||||
movzx ax, [bp - 2]
|
||||
push ax
|
||||
|
||||
mov dx, [bp + 4] ; seg
|
||||
push dx ; uint16_t buf_offset
|
||||
mov ax, 0x1
|
||||
push ax
|
||||
|
||||
mov dx, [bp + 6] ; offset
|
||||
push dx ; unit16_t segment
|
||||
; load correct fat
|
||||
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)
|
||||
add sp, 0x8
|
||||
mov ax, fat_buffer
|
||||
push ax
|
||||
|
||||
xor ax, ax
|
||||
push ax
|
||||
call read_disk_raw
|
||||
add sp, 0xC
|
||||
.endp:
|
||||
__CDECL16_EXIT
|
||||
ret
|
||||
|
||||
%endif
|
||||
%define __INC_FAT32_SYS
|
||||
@@ -17,15 +17,18 @@
|
||||
; 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
|
||||
; SOFTWARE.
|
||||
|
||||
%ifndef __INC_KMEM_FUNC
|
||||
%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:
|
||||
__CDECL16_ENTRY
|
||||
.func:
|
||||
mov cx, [bp + 8] ; size_t len
|
||||
mov al, [bp + 6] ; uint8_t val
|
||||
mov di, [bp + 4] ; void * ptr
|
||||
mov di, [bp + 4] ; void * dst
|
||||
|
||||
cld
|
||||
rep stosb
|
||||
@@ -36,6 +39,7 @@ kmemset:
|
||||
|
||||
; uint8_t* kmemset(uint8_t* dest, uint8_t* src, uint8_t len);
|
||||
; not overlap safe
|
||||
ALIGN 4, db 0x90
|
||||
kmemcpy:
|
||||
__CDECL16_ENTRY
|
||||
.func:
|
||||
@@ -48,4 +52,7 @@ kmemcpy:
|
||||
mov ax, di ; return pointer to dest
|
||||
.endf:
|
||||
__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
|
||||
; SOFTWARE.
|
||||
|
||||
%ifndef __INC_MEM
|
||||
|
||||
|
||||
; ## Generic Low mem map (from osdev wiki) ##
|
||||
; 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)
|
||||
;0x3048
|
||||
%define fat32_bpb 0x3050
|
||||
%define fat32_bpb_SIZE 33
|
||||
%define fat32_bpb 0x304A
|
||||
%define fat32_bpb_SIZE 36
|
||||
|
||||
; copy of FAT32 EBPB, 54 bytes
|
||||
;0x306A
|
||||
%define fat32_ebpb 0x30A0
|
||||
%define fat32_ebpb 0x306E
|
||||
%define fat32_ebpb_SIZE 54
|
||||
|
||||
; FAT32 FSInfo, 512 bytes
|
||||
@@ -69,18 +71,18 @@
|
||||
|
||||
; some stored state for the fat32 driver
|
||||
;0x32A2
|
||||
%define fat32_state 0x32B0
|
||||
%define fat32_state 0x34B0
|
||||
%define fat32_state_SIZE 32
|
||||
|
||||
; next free space is 0x32D0
|
||||
%define fat32_nc_data 0x32D0
|
||||
%define fat32_nc_data 0x35D0
|
||||
%define fat32_nc_data_size 16
|
||||
|
||||
; lba_packet for raw_disk_read
|
||||
%define lba_packet 0x4000
|
||||
|
||||
%define BIOSMemoryMap 0x4200
|
||||
%define SteviaInfo 0x4400
|
||||
%define SteviaInfo 0x5200
|
||||
|
||||
|
||||
; High memory addresses for loading kernel (for use with unreal mode and 32bit override)
|
||||
@@ -110,8 +112,5 @@ struc SteviaInfoStruct_t
|
||||
.EBPBDataPtr resd 1
|
||||
endstruc
|
||||
|
||||
%macro DEBUG_HCF 0
|
||||
DEBUG_LOOP:
|
||||
hlt
|
||||
jmp short DEBUG_LOOP
|
||||
%endmacro
|
||||
%endif
|
||||
%define __INC_MEM
|
||||
@@ -18,6 +18,8 @@
|
||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
; SOFTWARE.
|
||||
|
||||
%ifndef __INC_PART_TABLE
|
||||
|
||||
; Partition table entry format
|
||||
; Off. Size. Description
|
||||
;0x00 1 Drive attributes (bit 7 set = active or bootable)
|
||||
@@ -41,4 +43,7 @@ struc PartTable_t
|
||||
.partition2 resb 16
|
||||
.partition3 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
|
||||
; SOFTWARE.
|
||||
|
||||
%ifndef __INC_ERROR_FUNC
|
||||
|
||||
%macro ERROR 1
|
||||
xor ax, ax
|
||||
mov al, %1
|
||||
jmp error
|
||||
%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
|
||||
ALIGN 4, db 0x90
|
||||
error:
|
||||
; fs = 0xb800 => fs:0x0000 = 0xb8000
|
||||
mov dx, 0xB800
|
||||
@@ -47,4 +57,7 @@ error:
|
||||
|
||||
.stop:
|
||||
hlt
|
||||
jmp short error.stop
|
||||
jmp short error.stop
|
||||
|
||||
%endif
|
||||
%define __INC_ERROR_FUNC
|
||||
Reference in New Issue
Block a user