more modularization and updating date in MIT licence header
This commit is contained in:
24
include/BIOS/BIOS_sys.inc
Normal file
24
include/BIOS/BIOS_sys.inc
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
; Copyright (c) 2024 Elaina Claus
|
||||||
|
;
|
||||||
|
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
; of this software and associated documentation files (the "Software"), to deal
|
||||||
|
; in the Software without restriction, including without limitation the rights
|
||||||
|
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
; copies of the Software, and to permit persons to whom the Software is
|
||||||
|
; furnished to do so, subject to the following conditions:
|
||||||
|
;
|
||||||
|
; The above copyright notice and this permission notice shall be included in all
|
||||||
|
; copies or substantial portions of the Software.
|
||||||
|
;
|
||||||
|
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
; 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.
|
||||||
|
|
||||||
|
%include 'BIOS/func/a20enable.inc'
|
||||||
|
%include 'BIOS/func/E820_memory_map.inc'
|
||||||
|
%include 'BIOS/func/ext_read.inc'
|
||||||
|
%include 'BIOS/func/video.inc'
|
||||||
161
include/BIOS/func/E820_memory_map.inc
Normal file
161
include/BIOS/func/E820_memory_map.inc
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
; Copyright (c) 2024 Elaina Claus
|
||||||
|
;
|
||||||
|
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
; of this software and associated documentation files (the "Software"), to deal
|
||||||
|
; in the Software without restriction, including without limitation the rights
|
||||||
|
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
; copies of the Software, and to permit persons to whom the Software is
|
||||||
|
; furnished to do so, subject to the following conditions:
|
||||||
|
;
|
||||||
|
; The above copyright notice and this permission notice shall be included in all
|
||||||
|
; copies or substantial portions of the Software.
|
||||||
|
;
|
||||||
|
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
; 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.
|
||||||
|
|
||||||
|
|
||||||
|
; Address Range Descriptor Structure
|
||||||
|
;
|
||||||
|
; Offset in Bytes Name Description
|
||||||
|
; 0 BaseAddrLow Low 32 Bits of Base Address
|
||||||
|
; 4 BaseAddrHigh High 32 Bits of Base Address
|
||||||
|
; 8 LengthLow Low 32 Bits of Length in Bytes
|
||||||
|
; 12 LengthHigh High 32 Bits of Length in Bytes
|
||||||
|
; 16 Type Address type of this range.
|
||||||
|
; Address Range Descriptor Structure
|
||||||
|
;
|
||||||
|
; Offset in Bytes Name Description
|
||||||
|
; 0 BaseAddrLow Low 32 Bits of Base Address
|
||||||
|
; 4 BaseAddrHigh High 32 Bits of Base Address
|
||||||
|
; 8 LengthLow Low 32 Bits of Length in Bytes
|
||||||
|
; 12 LengthHigh High 32 Bits of Length in Bytes
|
||||||
|
; 16 Type Address type of this range.
|
||||||
|
; Input:
|
||||||
|
;
|
||||||
|
; EAX Function Code E820h
|
||||||
|
; EBX Continuation Contains the "continuation value" to get the
|
||||||
|
; next run of physical memory. This is the
|
||||||
|
; value returned by a previous call to this
|
||||||
|
; routine. If this is the first call, EBX
|
||||||
|
; must contain zero.
|
||||||
|
; ES:DI Buffer Pointer Pointer to an Address Range Descriptor
|
||||||
|
; structure which the BIOS is to fill in.
|
||||||
|
; ECX Buffer Size The length in bytes of the structure passed
|
||||||
|
; to the BIOS. The BIOS will fill in at most
|
||||||
|
; ECX bytes of the structure or however much
|
||||||
|
; of the structure the BIOS implements. The
|
||||||
|
; minimum size which must be supported by both
|
||||||
|
; the BIOS and the caller is 20 bytes. Future
|
||||||
|
; implementations may extend this structure.
|
||||||
|
; EDX Signature 'SMAP' - Used by the BIOS to verify the
|
||||||
|
; caller is requesting the system map
|
||||||
|
; information to be returned in ES:DI.
|
||||||
|
;
|
||||||
|
; Output:
|
||||||
|
;
|
||||||
|
; CF Carry Flag Non-Carry - indicates no error
|
||||||
|
; EAX Signature 'SMAP' - Signature to verify correct BIOS
|
||||||
|
; revision.
|
||||||
|
; ES:DI Buffer Pointer Returned Address Range Descriptor pointer.
|
||||||
|
; Same value as on input.
|
||||||
|
; ECX Buffer Size Number of bytes returned by the BIOS in the
|
||||||
|
; address range descriptor. The minimum size
|
||||||
|
; structure returned by the BIOS is 20 bytes.
|
||||||
|
; EBX Continuation Contains the continuation value to get the
|
||||||
|
; next address descriptor. The actual
|
||||||
|
; significance of the continuation value is up
|
||||||
|
; to the discretion of the BIOS. The caller
|
||||||
|
; must pass the continuation value unchanged
|
||||||
|
; as input to the next iteration of the E820
|
||||||
|
; call in order to get the next Address Range
|
||||||
|
; Descriptor. A return value of zero means that
|
||||||
|
; this is the last descriptor
|
||||||
|
;
|
||||||
|
; Address Range Descriptor Structure
|
||||||
|
;
|
||||||
|
; Offset in Bytes Name Description
|
||||||
|
; 0 BaseAddrLow Low 32 Bits of Base Address
|
||||||
|
; 4 BaseAddrHigh High 32 Bits of Base Address
|
||||||
|
; 8 LengthLow Low 32 Bits of Length in Bytes
|
||||||
|
; 12 LengthHigh High 32 Bits of Length in Bytes
|
||||||
|
; 16 Type Address type of this range.
|
||||||
|
;
|
||||||
|
; The BaseAddrLow and BaseAddrHigh together are the 64 bit BaseAddress of this range.
|
||||||
|
; The BaseAddress is the physical address of the start of the range being specified.
|
||||||
|
;
|
||||||
|
; The LengthLow and LengthHigh together are the 64 bit Length of this range.
|
||||||
|
; The Length is the physical contiguous length in bytes of a range being specified.
|
||||||
|
;
|
||||||
|
; The Type field describes the usage of the described address range as defined in the table below.
|
||||||
|
|
||||||
|
; Value Pneumonic Description
|
||||||
|
; 1 AddressRangeMemory This run is available RAM usable by the operating system.
|
||||||
|
; 2 AddressRangeReserved This run of addresses is in use or reserved by the system, and must not be used by the operating system.
|
||||||
|
; Other Undefined Undefined - Reserved for future use.
|
||||||
|
|
||||||
|
; Address Range Descriptor Structure
|
||||||
|
;
|
||||||
|
; Offset in Bytes Name Description
|
||||||
|
; 0 BaseAddrLow u32 - Low 32 Bits of Base Address
|
||||||
|
; 4 BaseAddrHigh u32 - High 32 Bits of Base Address
|
||||||
|
; 8 LengthLow u32 - Low 32 Bits of Length in Bytes
|
||||||
|
; 12 LengthHigh u32 - High 32 Bits of Length in Bytes
|
||||||
|
; 16 Type u32 - Address type of this range.
|
||||||
|
; 20 ExtType u32 - ACPI 3.0 extended type
|
||||||
|
struc AddressRangeDescStruct_t
|
||||||
|
.BaseAddrLow resd 1
|
||||||
|
.BaseAddrHigh resd 1
|
||||||
|
.LengthLow resd 1
|
||||||
|
.LengthHigh resd 1
|
||||||
|
.Type resd 1
|
||||||
|
.ExtType resd 1
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
GetMemoryMap:
|
||||||
|
__CDECL16_ENTRY
|
||||||
|
push es ; save segment register
|
||||||
|
.func:
|
||||||
|
mov dword [SteviaInfo + SteviaInfoStruct_t.MemoryMapEntries], 0
|
||||||
|
|
||||||
|
mov eax, 0xE820 ; select 0xE820 function
|
||||||
|
xor ebx, ebx ; Continuation value, 0 for the first call
|
||||||
|
|
||||||
|
mov dx, (BIOSMemoryMap >> 4)
|
||||||
|
mov es, dx
|
||||||
|
xor di, di ; (BIOSMemoryMap >> 4):0 makes di an index into BIOSMemoryMap
|
||||||
|
|
||||||
|
mov ecx, AddressRangeDescStruct_t_size
|
||||||
|
mov edx, 0x534D4150 ; 'SMAP' magic
|
||||||
|
.loop_L1:
|
||||||
|
int 0x15
|
||||||
|
jc GetMemoryMap.error
|
||||||
|
cmp eax, 0x534D4150
|
||||||
|
jne GetMemoryMap.no_smap_returned
|
||||||
|
.no_error:
|
||||||
|
inc dword [SteviaInfo + SteviaInfoStruct_t.MemoryMapEntries]
|
||||||
|
|
||||||
|
cmp ecx, 20 ; TODO: maybe this could be handled better than just panicing
|
||||||
|
jb GetMemoryMap.nonstandard_e820 ; non-standard entry found
|
||||||
|
|
||||||
|
cmp ebx, 0
|
||||||
|
je GetMemoryMap.endp ; 0 in ebx means we have reached the end of memory ranges
|
||||||
|
|
||||||
|
add di, AddressRangeDescStruct_t_size ; increment di to next descriptor
|
||||||
|
mov edx, eax ; 'SMAP' to edx
|
||||||
|
mov eax, 0xE820 ; select E820 function
|
||||||
|
jmp GetMemoryMap.loop_L1
|
||||||
|
.error:
|
||||||
|
ERROR STAGE2_MM_E820_MISC_ERR
|
||||||
|
.nonstandard_e820:
|
||||||
|
ERROR STAGE2_MM_E820_NONSTANDARD
|
||||||
|
.no_smap_returned:
|
||||||
|
ERROR STAGE2_MM_E820_NO_SMAP
|
||||||
|
.endp:
|
||||||
|
pop es
|
||||||
|
__CDECL16_EXIT
|
||||||
|
ret
|
||||||
@@ -135,138 +135,5 @@ EnableA20:
|
|||||||
.endp:
|
.endp:
|
||||||
pop es
|
pop es
|
||||||
pop ds
|
pop ds
|
||||||
__CDECL16_EXIT
|
|
||||||
ret
|
|
||||||
|
|
||||||
; See memory.inc for a brief description of E820 mmap function
|
|
||||||
GetMemoryMap:
|
|
||||||
__CDECL16_ENTRY
|
|
||||||
push es ; save segment register
|
|
||||||
.func:
|
|
||||||
mov dword [SteviaInfo + SteviaInfoStruct_t.MemoryMapEntries], 0
|
|
||||||
|
|
||||||
mov eax, 0xE820 ; select 0xE820 function
|
|
||||||
xor ebx, ebx ; Continuation value, 0 for the first call
|
|
||||||
|
|
||||||
mov dx, (BIOSMemoryMap >> 4)
|
|
||||||
mov es, dx
|
|
||||||
xor di, di ; (BIOSMemoryMap >> 4):0 makes di an index into BIOSMemoryMap
|
|
||||||
|
|
||||||
mov ecx, AddressRangeDescStruct_t_size
|
|
||||||
mov edx, 0x534D4150 ; 'SMAP' magic
|
|
||||||
.loop_L1:
|
|
||||||
int 0x15
|
|
||||||
jc GetMemoryMap.error
|
|
||||||
cmp eax, 0x534D4150
|
|
||||||
jne GetMemoryMap.no_smap_returned
|
|
||||||
.no_error:
|
|
||||||
inc dword [SteviaInfo + SteviaInfoStruct_t.MemoryMapEntries]
|
|
||||||
|
|
||||||
cmp ecx, 20 ; TODO: maybe this could be handled better than just panicing
|
|
||||||
jb GetMemoryMap.nonstandard_e820 ; non-standard entry found
|
|
||||||
|
|
||||||
cmp ebx, 0
|
|
||||||
je GetMemoryMap.endp ; 0 in ebx means we have reached the end of memory ranges
|
|
||||||
|
|
||||||
add di, AddressRangeDescStruct_t_size ; increment di to next descriptor
|
|
||||||
mov edx, eax ; 'SMAP' to edx
|
|
||||||
mov eax, 0xE820 ; select E820 function
|
|
||||||
jmp GetMemoryMap.loop_L1
|
|
||||||
.error:
|
|
||||||
ERROR STAGE2_MM_E820_MISC_ERR
|
|
||||||
.nonstandard_e820:
|
|
||||||
ERROR STAGE2_MM_E820_NONSTANDARD
|
|
||||||
.no_smap_returned:
|
|
||||||
ERROR STAGE2_MM_E820_NO_SMAP
|
|
||||||
.endp:
|
|
||||||
pop es
|
|
||||||
__CDECL16_EXIT
|
|
||||||
ret
|
|
||||||
|
|
||||||
; Wrapper for AH=0x42 INT13h (Extended Read)
|
|
||||||
;
|
|
||||||
; BIOS call details
|
|
||||||
; AH = 42h
|
|
||||||
; DL = drive number
|
|
||||||
; DS:SI -> disk address packet
|
|
||||||
;
|
|
||||||
; Return:
|
|
||||||
; CF clear if successful
|
|
||||||
; 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, uint32_t lba)
|
|
||||||
; TODO: this needs validation
|
|
||||||
read_disk_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 ; uint8_t* kmemset(void* dest, uint8_t val, size_t len);
|
|
||||||
add sp, 0x6
|
|
||||||
|
|
||||||
mov byte [lba_packet + LBAPkt_t.size], 0x10
|
|
||||||
mov word [lba_packet + LBAPkt_t.xfer_size], 0x0001
|
|
||||||
|
|
||||||
mov dword eax, [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 [fat32_ebpb + FAT32_ebpb_t.drive_number_8]
|
|
||||||
int 0x13
|
|
||||||
jnc read_disk_raw.endp
|
|
||||||
ERROR STAGE2_MBR_DISK_READ_ERROR
|
|
||||||
.endp:
|
|
||||||
__CDECL16_EXIT
|
|
||||||
ret
|
|
||||||
|
|
||||||
; Sets output to 80x25 16 color text mode via BIOS call
|
|
||||||
; also clears screen
|
|
||||||
; void SetTextMode(void)
|
|
||||||
SetTextMode:
|
|
||||||
.prolog:
|
|
||||||
__CDECL16_ENTRY
|
|
||||||
pushf
|
|
||||||
.func:
|
|
||||||
xor ah, ah ; Set Video mode BIOS function
|
|
||||||
mov al, 0x02 ; 16 color 80x25 Text mode
|
|
||||||
int 0x10 ; Call video interrupt
|
|
||||||
|
|
||||||
mov ah, 0x05 ; Select active display page BIOS function
|
|
||||||
xor al, al ; page 0
|
|
||||||
int 0x10 ; call video interrupt
|
|
||||||
.endp:
|
|
||||||
popf
|
|
||||||
__CDECL16_EXIT
|
|
||||||
ret
|
|
||||||
|
|
||||||
; disables blinking text mode cursor
|
|
||||||
disable_cursor:
|
|
||||||
__CDECL16_ENTRY
|
|
||||||
.func:
|
|
||||||
mov dx, 0x3D4
|
|
||||||
mov al, 0xA ; low cursor shape register
|
|
||||||
out dx, al
|
|
||||||
|
|
||||||
inc dx
|
|
||||||
mov al, 0x20 ; bits 6-7 unused, bit 5 disables the cursor, bits 0-4 control the cursor shape
|
|
||||||
out dx, al
|
|
||||||
.endp:
|
|
||||||
__CDECL16_EXIT
|
__CDECL16_EXIT
|
||||||
ret
|
ret
|
||||||
90
include/BIOS/func/ext_read.inc
Normal file
90
include/BIOS/func/ext_read.inc
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
; Copyright (c) 2024 Elaina Claus
|
||||||
|
;
|
||||||
|
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
; of this software and associated documentation files (the "Software"), to deal
|
||||||
|
; in the Software without restriction, including without limitation the rights
|
||||||
|
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
; copies of the Software, and to permit persons to whom the Software is
|
||||||
|
; furnished to do so, subject to the following conditions:
|
||||||
|
;
|
||||||
|
; The above copyright notice and this permission notice shall be included in all
|
||||||
|
; copies or substantial portions of the Software.
|
||||||
|
;
|
||||||
|
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
; 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.
|
||||||
|
|
||||||
|
;Offset Size Description
|
||||||
|
; 0 1 size of packet (16 bytes)
|
||||||
|
; 1 1 always 0
|
||||||
|
; 2 2 number of sectors to transfer (max 127 on some BIOSes)
|
||||||
|
; 4 4 transfer buffer (0xFFFF:0xFFFF)
|
||||||
|
; 8 4 lower 32-bits of starting 48-bit LBA
|
||||||
|
; 12 4 upper 32-bits of starting 48-bit LBA
|
||||||
|
; needs to be aligned to a uint32_t
|
||||||
|
struc LBAPkt_t
|
||||||
|
.size resb 1
|
||||||
|
.res0 resb 1
|
||||||
|
.xfer_size resw 1
|
||||||
|
.offset resw 1
|
||||||
|
.segment resw 1
|
||||||
|
.lower_lba resd 1
|
||||||
|
.upper_lba resd 1
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
; Wrapper for AH=0x42 INT13h (Extended Read)
|
||||||
|
;
|
||||||
|
; BIOS call details
|
||||||
|
; AH = 42h
|
||||||
|
; DL = drive number
|
||||||
|
; DS:SI -> disk address packet
|
||||||
|
;
|
||||||
|
; Return:
|
||||||
|
; CF clear if successful
|
||||||
|
; 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, uint32_t lba)
|
||||||
|
; TODO: this needs validation
|
||||||
|
read_disk_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 ; uint8_t* kmemset(void* dest, uint8_t val, size_t len);
|
||||||
|
add sp, 0x6
|
||||||
|
|
||||||
|
mov byte [lba_packet + LBAPkt_t.size], 0x10
|
||||||
|
mov word [lba_packet + LBAPkt_t.xfer_size], 0x0001
|
||||||
|
|
||||||
|
mov dword eax, [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 [fat32_ebpb + FAT32_ebpb_t.drive_number_8]
|
||||||
|
int 0x13
|
||||||
|
jnc read_disk_raw.endp
|
||||||
|
ERROR STAGE2_MBR_DISK_READ_ERROR
|
||||||
|
.endp:
|
||||||
|
__CDECL16_EXIT
|
||||||
|
ret
|
||||||
54
include/BIOS/func/video.inc
Normal file
54
include/BIOS/func/video.inc
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
; Copyright (c) 2024 Elaina Claus
|
||||||
|
;
|
||||||
|
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
; of this software and associated documentation files (the "Software"), to deal
|
||||||
|
; in the Software without restriction, including without limitation the rights
|
||||||
|
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
; copies of the Software, and to permit persons to whom the Software is
|
||||||
|
; furnished to do so, subject to the following conditions:
|
||||||
|
;
|
||||||
|
; The above copyright notice and this permission notice shall be included in all
|
||||||
|
; copies or substantial portions of the Software.
|
||||||
|
;
|
||||||
|
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
; 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.
|
||||||
|
|
||||||
|
; Sets output to 80x25 16 color text mode via BIOS call
|
||||||
|
; also clears screen
|
||||||
|
; void SetTextMode(void)
|
||||||
|
SetTextMode:
|
||||||
|
.prolog:
|
||||||
|
__CDECL16_ENTRY
|
||||||
|
pushf
|
||||||
|
.func:
|
||||||
|
xor ah, ah ; Set Video mode BIOS function
|
||||||
|
mov al, 0x02 ; 16 color 80x25 Text mode
|
||||||
|
int 0x10 ; Call video interrupt
|
||||||
|
|
||||||
|
mov ah, 0x05 ; Select active display page BIOS function
|
||||||
|
xor al, al ; page 0
|
||||||
|
int 0x10 ; call video interrupt
|
||||||
|
.endp:
|
||||||
|
popf
|
||||||
|
__CDECL16_EXIT
|
||||||
|
ret
|
||||||
|
|
||||||
|
; disables blinking text mode cursor
|
||||||
|
disable_cursor:
|
||||||
|
__CDECL16_ENTRY
|
||||||
|
.func:
|
||||||
|
mov dx, 0x3D4
|
||||||
|
mov al, 0xA ; low cursor shape register
|
||||||
|
out dx, al
|
||||||
|
|
||||||
|
inc dx
|
||||||
|
mov al, 0x20 ; bits 6-7 unused, bit 5 disables the cursor, bits 0-4 control the cursor shape
|
||||||
|
out dx, al
|
||||||
|
.endp:
|
||||||
|
__CDECL16_EXIT
|
||||||
|
ret
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
; Copyright (c) 2023 Elaina Claus
|
; Copyright (c) 2024 Elaina Claus
|
||||||
;
|
;
|
||||||
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
; of this software and associated documentation files (the "Software"), to deal
|
; of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
; Copyright (c) 2023 Elaina Claus
|
; Copyright (c) 2024 Elaina Claus
|
||||||
;
|
;
|
||||||
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
; of this software and associated documentation files (the "Software"), to deal
|
; of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
|
|
||||||
; 8KiB from 0x2500 -> 0x500
|
; 8KiB from 0x2500 -> 0x500
|
||||||
%define 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
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
; Copyright (c) 2023 Elaina Claus
|
; Copyright (c) 2024 Elaina Claus
|
||||||
;
|
;
|
||||||
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
; of this software and associated documentation files (the "Software"), to deal
|
; of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -76,36 +76,4 @@
|
|||||||
%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'
|
||||||
|
|
||||||
|
|
||||||
%macro ERROR 1
|
|
||||||
xor ax, ax
|
|
||||||
mov al, %1
|
|
||||||
jmp error
|
|
||||||
%endmacro
|
|
||||||
|
|
||||||
; pass error as ascii character in al, errors a-zA-Z or 0-9
|
|
||||||
error:
|
|
||||||
; fs = 0xb800 => fs:0x0000 = 0xb8000
|
|
||||||
mov dx, 0xB800
|
|
||||||
mov fs, dx
|
|
||||||
|
|
||||||
mov dx, STEVIA_DEBUG_OK
|
|
||||||
cmp ax, dx
|
|
||||||
jge error.debug_err
|
|
||||||
mov dh, 0x4F ; color 0x4F is white text/red background
|
|
||||||
jmp error.print
|
|
||||||
.debug_err:
|
|
||||||
mov dh, 0x5F ; debug case is white text/purple background
|
|
||||||
|
|
||||||
; the characters are two bytes in the order of 0xb8000: byte c, byte attribute
|
|
||||||
; since x86 is le, we store the attribute in the MSB of dx
|
|
||||||
.print:
|
|
||||||
mov dl, al
|
|
||||||
mov word [fs:0x0000], dx
|
|
||||||
jmp error.stop
|
|
||||||
|
|
||||||
.stop:
|
|
||||||
hlt
|
|
||||||
jmp short error.stop
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
; Copyright (c) 2023 Elaina Claus
|
; Copyright (c) 2024 Elaina Claus
|
||||||
;
|
;
|
||||||
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
; of this software and associated documentation files (the "Software"), to deal
|
; of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
; Copyright (c) 2023 Elaina Claus
|
; Copyright (c) 2024 Elaina Claus
|
||||||
;
|
;
|
||||||
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
; of this software and associated documentation files (the "Software"), to deal
|
; of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -110,103 +110,6 @@ struc SteviaInfoStruct_t
|
|||||||
.EBPBDataPtr resd 1
|
.EBPBDataPtr resd 1
|
||||||
endstruc
|
endstruc
|
||||||
|
|
||||||
; Address Range Descriptor Structure
|
|
||||||
;
|
|
||||||
; Offset in Bytes Name Description
|
|
||||||
; 0 BaseAddrLow Low 32 Bits of Base Address
|
|
||||||
; 4 BaseAddrHigh High 32 Bits of Base Address
|
|
||||||
; 8 LengthLow Low 32 Bits of Length in Bytes
|
|
||||||
; 12 LengthHigh High 32 Bits of Length in Bytes
|
|
||||||
; 16 Type Address type of this range.
|
|
||||||
; Address Range Descriptor Structure
|
|
||||||
;
|
|
||||||
; Offset in Bytes Name Description
|
|
||||||
; 0 BaseAddrLow Low 32 Bits of Base Address
|
|
||||||
; 4 BaseAddrHigh High 32 Bits of Base Address
|
|
||||||
; 8 LengthLow Low 32 Bits of Length in Bytes
|
|
||||||
; 12 LengthHigh High 32 Bits of Length in Bytes
|
|
||||||
; 16 Type Address type of this range.
|
|
||||||
; Input:
|
|
||||||
;
|
|
||||||
; EAX Function Code E820h
|
|
||||||
; EBX Continuation Contains the "continuation value" to get the
|
|
||||||
; next run of physical memory. This is the
|
|
||||||
; value returned by a previous call to this
|
|
||||||
; routine. If this is the first call, EBX
|
|
||||||
; must contain zero.
|
|
||||||
; ES:DI Buffer Pointer Pointer to an Address Range Descriptor
|
|
||||||
; structure which the BIOS is to fill in.
|
|
||||||
; ECX Buffer Size The length in bytes of the structure passed
|
|
||||||
; to the BIOS. The BIOS will fill in at most
|
|
||||||
; ECX bytes of the structure or however much
|
|
||||||
; of the structure the BIOS implements. The
|
|
||||||
; minimum size which must be supported by both
|
|
||||||
; the BIOS and the caller is 20 bytes. Future
|
|
||||||
; implementations may extend this structure.
|
|
||||||
; EDX Signature 'SMAP' - Used by the BIOS to verify the
|
|
||||||
; caller is requesting the system map
|
|
||||||
; information to be returned in ES:DI.
|
|
||||||
;
|
|
||||||
; Output:
|
|
||||||
;
|
|
||||||
; CF Carry Flag Non-Carry - indicates no error
|
|
||||||
; EAX Signature 'SMAP' - Signature to verify correct BIOS
|
|
||||||
; revision.
|
|
||||||
; ES:DI Buffer Pointer Returned Address Range Descriptor pointer.
|
|
||||||
; Same value as on input.
|
|
||||||
; ECX Buffer Size Number of bytes returned by the BIOS in the
|
|
||||||
; address range descriptor. The minimum size
|
|
||||||
; structure returned by the BIOS is 20 bytes.
|
|
||||||
; EBX Continuation Contains the continuation value to get the
|
|
||||||
; next address descriptor. The actual
|
|
||||||
; significance of the continuation value is up
|
|
||||||
; to the discretion of the BIOS. The caller
|
|
||||||
; must pass the continuation value unchanged
|
|
||||||
; as input to the next iteration of the E820
|
|
||||||
; call in order to get the next Address Range
|
|
||||||
; Descriptor. A return value of zero means that
|
|
||||||
; this is the last descriptor
|
|
||||||
;
|
|
||||||
; Address Range Descriptor Structure
|
|
||||||
;
|
|
||||||
; Offset in Bytes Name Description
|
|
||||||
; 0 BaseAddrLow Low 32 Bits of Base Address
|
|
||||||
; 4 BaseAddrHigh High 32 Bits of Base Address
|
|
||||||
; 8 LengthLow Low 32 Bits of Length in Bytes
|
|
||||||
; 12 LengthHigh High 32 Bits of Length in Bytes
|
|
||||||
; 16 Type Address type of this range.
|
|
||||||
;
|
|
||||||
; The BaseAddrLow and BaseAddrHigh together are the 64 bit BaseAddress of this range.
|
|
||||||
; The BaseAddress is the physical address of the start of the range being specified.
|
|
||||||
;
|
|
||||||
; The LengthLow and LengthHigh together are the 64 bit Length of this range.
|
|
||||||
; The Length is the physical contiguous length in bytes of a range being specified.
|
|
||||||
;
|
|
||||||
; The Type field describes the usage of the described address range as defined in the table below.
|
|
||||||
|
|
||||||
; Value Pneumonic Description
|
|
||||||
; 1 AddressRangeMemory This run is available RAM usable by the operating system.
|
|
||||||
; 2 AddressRangeReserved This run of addresses is in use or reserved by the system, and must not be used by the operating system.
|
|
||||||
; Other Undefined Undefined - Reserved for future use.
|
|
||||||
|
|
||||||
; Address Range Descriptor Structure
|
|
||||||
;
|
|
||||||
; Offset in Bytes Name Description
|
|
||||||
; 0 BaseAddrLow u32 - Low 32 Bits of Base Address
|
|
||||||
; 4 BaseAddrHigh u32 - High 32 Bits of Base Address
|
|
||||||
; 8 LengthLow u32 - Low 32 Bits of Length in Bytes
|
|
||||||
; 12 LengthHigh u32 - High 32 Bits of Length in Bytes
|
|
||||||
; 16 Type u32 - Address type of this range.
|
|
||||||
; 20 ExtType u32 - ACPI 3.0 extended type
|
|
||||||
struc AddressRangeDescStruct_t
|
|
||||||
.BaseAddrLow resd 1
|
|
||||||
.BaseAddrHigh resd 1
|
|
||||||
.LengthLow resd 1
|
|
||||||
.LengthHigh resd 1
|
|
||||||
.Type resd 1
|
|
||||||
.ExtType resd 1
|
|
||||||
endstruc
|
|
||||||
|
|
||||||
%macro DEBUG_HCF 0
|
%macro DEBUG_HCF 0
|
||||||
DEBUG_LOOP:
|
DEBUG_LOOP:
|
||||||
hlt
|
hlt
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
; Copyright (c) 2023 Elaina Claus
|
; Copyright (c) 2024 Elaina Claus
|
||||||
;
|
;
|
||||||
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
; of this software and associated documentation files (the "Software"), to deal
|
; of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -41,23 +41,4 @@ struc PartTable_t
|
|||||||
.partition2 resb 16
|
.partition2 resb 16
|
||||||
.partition3 resb 16
|
.partition3 resb 16
|
||||||
.partition4 resb 16
|
.partition4 resb 16
|
||||||
endstruc
|
|
||||||
|
|
||||||
|
|
||||||
;Offset Size Description
|
|
||||||
; 0 1 size of packet (16 bytes)
|
|
||||||
; 1 1 always 0
|
|
||||||
; 2 2 number of sectors to transfer (max 127 on some BIOSes)
|
|
||||||
; 4 4 transfer buffer (0xFFFF:0xFFFF)
|
|
||||||
; 8 4 lower 32-bits of starting 48-bit LBA
|
|
||||||
; 12 4 upper 32-bits of starting 48-bit LBA
|
|
||||||
; needs to be aligned to a uint32_t
|
|
||||||
struc LBAPkt_t
|
|
||||||
.size resb 1
|
|
||||||
.res0 resb 1
|
|
||||||
.xfer_size resw 1
|
|
||||||
.offset resw 1
|
|
||||||
.segment resw 1
|
|
||||||
.lower_lba resd 1
|
|
||||||
.upper_lba resd 1
|
|
||||||
endstruc
|
endstruc
|
||||||
50
include/util/error_func.inc
Normal file
50
include/util/error_func.inc
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
; Copyright (c) 2024 Elaina Claus
|
||||||
|
;
|
||||||
|
; Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
; of this software and associated documentation files (the "Software"), to deal
|
||||||
|
; in the Software without restriction, including without limitation the rights
|
||||||
|
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
; copies of the Software, and to permit persons to whom the Software is
|
||||||
|
; furnished to do so, subject to the following conditions:
|
||||||
|
;
|
||||||
|
; The above copyright notice and this permission notice shall be included in all
|
||||||
|
; copies or substantial portions of the Software.
|
||||||
|
;
|
||||||
|
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
; 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.
|
||||||
|
|
||||||
|
%macro ERROR 1
|
||||||
|
xor ax, ax
|
||||||
|
mov al, %1
|
||||||
|
jmp error
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
; pass error as ascii character in al, errors a-zA-Z or 0-9
|
||||||
|
error:
|
||||||
|
; fs = 0xb800 => fs:0x0000 = 0xb8000
|
||||||
|
mov dx, 0xB800
|
||||||
|
mov fs, dx
|
||||||
|
|
||||||
|
mov dx, STEVIA_DEBUG_OK
|
||||||
|
cmp ax, dx
|
||||||
|
jge error.debug_err
|
||||||
|
mov dh, 0x4F ; color 0x4F is white text/red background
|
||||||
|
jmp error.print
|
||||||
|
.debug_err:
|
||||||
|
mov dh, 0x5F ; debug case is white text/purple background
|
||||||
|
|
||||||
|
; the characters are two bytes in the order of 0xb8000: byte c, byte attribute
|
||||||
|
; since x86 is le, we store the attribute in the MSB of dx
|
||||||
|
.print:
|
||||||
|
mov dl, al
|
||||||
|
mov word [fs:0x0000], dx
|
||||||
|
jmp error.stop
|
||||||
|
|
||||||
|
.stop:
|
||||||
|
hlt
|
||||||
|
jmp short error.stop
|
||||||
@@ -33,7 +33,7 @@ init:
|
|||||||
mov es, ax ; *
|
mov es, ax ; *
|
||||||
|
|
||||||
mov ss, ax ; Set Stack Segment to 0
|
mov ss, ax ; Set Stack Segment to 0
|
||||||
mov sp, STACK_START
|
mov sp, EARLY_STACK_START
|
||||||
|
|
||||||
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)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ init:
|
|||||||
mov gs, ax ; *
|
mov gs, ax ; *
|
||||||
|
|
||||||
mov ss, ax ; Set Stack Segment to 0
|
mov ss, ax ; Set Stack Segment to 0
|
||||||
mov sp, STACK_START ; Set Stack Pointer
|
mov sp, EARLY_STACK_START ; Set Stack Pointer
|
||||||
|
|
||||||
add sp, 0x4
|
add sp, 0x4
|
||||||
mov ax, 0xDEAD
|
mov ax, 0xDEAD
|
||||||
@@ -52,7 +52,7 @@ init:
|
|||||||
jmp 0:main
|
jmp 0:main
|
||||||
|
|
||||||
%include "config.inc"
|
%include "config.inc"
|
||||||
%include "errors.inc"
|
%include "error_codes.inc"
|
||||||
%include "memory.inc"
|
%include "memory.inc"
|
||||||
%include "kmem_func.inc"
|
%include "kmem_func.inc"
|
||||||
%include "partition_table.inc"
|
%include "partition_table.inc"
|
||||||
@@ -146,7 +146,7 @@ hcf:
|
|||||||
;
|
;
|
||||||
; ###############
|
; ###############
|
||||||
|
|
||||||
%include 'BIOS/BIOS_func.inc'
|
%include 'BIOS/BIOS_sys.inc'
|
||||||
|
|
||||||
; ##############################
|
; ##############################
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ init:
|
|||||||
mov es, ax ; *
|
mov es, ax ; *
|
||||||
|
|
||||||
mov ss, ax ; Set Stack Segment to 0
|
mov ss, ax ; Set Stack Segment to 0
|
||||||
mov sp, 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
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user