first commit
This commit is contained in:
20
include/config.inc
Executable file
20
include/config.inc
Executable file
@@ -0,0 +1,20 @@
|
||||
; Copyright (C) 2020 Bradley Claus
|
||||
;
|
||||
; This program is free software: you can redistribute it and/or modify
|
||||
; it under the terms of the GNU General Public License as published by
|
||||
; the Free Software Foundation, either version 3 of the License, or
|
||||
; (at your option) any later version.
|
||||
;
|
||||
; This program is distributed in the hope that it will be useful,
|
||||
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
; GNU General Public License for more details.
|
||||
;
|
||||
; You should have received a copy of the GNU General Public License
|
||||
; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
%define SECTOR_SIZE 512
|
||||
%define STAGE2_SECTOR_COUNT 0x40
|
||||
; 32 KiB
|
||||
%define MAX_STAGE2_BYTES (SECTOR_SIZE * STAGE2_SECTOR_COUNT)
|
||||
21
include/entry.inc
Executable file
21
include/entry.inc
Executable file
@@ -0,0 +1,21 @@
|
||||
; Copyright (C) 2020 Bradley Claus
|
||||
;
|
||||
; This program is free software: you can redistribute it and/or modify
|
||||
; it under the terms of the GNU General Public License as published by
|
||||
; the Free Software Foundation, either version 3 of the License, or
|
||||
; (at your option) any later version.
|
||||
;
|
||||
; This program is distributed in the hope that it will be useful,
|
||||
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
; GNU General Public License for more details.
|
||||
;
|
||||
; You should have received a copy of the GNU General Public License
|
||||
; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
; 8KiB from 0x2500 -> 0x500
|
||||
%define STACK_START 0x2500
|
||||
%define MBR_ENTRY 0x7A00
|
||||
%define VBR_ENTRY 0x7C00
|
||||
%define STAGE2_ENTRY 0x7E00
|
||||
95
include/errors.inc
Executable file
95
include/errors.inc
Executable file
@@ -0,0 +1,95 @@
|
||||
; Copyright (C) 2020 Bradley Claus
|
||||
;
|
||||
; This program is free software: you can redistribute it and/or modify
|
||||
; it under the terms of the GNU General Public License as published by
|
||||
; the Free Software Foundation, either version 3 of the License, or
|
||||
; (at your option) any later version.
|
||||
;
|
||||
; This program is distributed in the hope that it will be useful,
|
||||
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
; GNU General Public License for more details.
|
||||
;
|
||||
; You should have received a copy of the GNU General Public License
|
||||
; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
; Errors
|
||||
; 12 Errors, 5 in use
|
||||
%define MBR_ERROR_DISK_T_ERR 'a'
|
||||
%define MBR_ERROR_NO_INT32E 'b'
|
||||
%define MBR_ERROR_NO_NO_BOOT_PART 'c'
|
||||
%define MBR_ERROR_DISK_READ_ERR 'd'
|
||||
%define MBR_ERROR_NO_VBR_SIG 'e'
|
||||
%define MBR_ERROR_RESERVED_f 'f'
|
||||
%define MBR_ERROR_RESERVED_g 'g'
|
||||
%define MBR_ERROR_RESERVED_h 'h'
|
||||
%define MBR_ERROR_RESERVED_i 'i'
|
||||
%define MBR_ERROR_RESERVED_j 'j'
|
||||
%define MBR_ERROR_RESERVED_k 'k'
|
||||
%define MBR_ERROR_RESERVED_l 'l'
|
||||
|
||||
; 12 Error
|
||||
%define VBR_ERROR_WRONG_FAT_SIZE 'm'
|
||||
%define VBR_ERROR_NO_SIGNATURE 'n'
|
||||
%define VBR_ERROR_DISK_READ_ERR 'o'
|
||||
%define VBR_ERROR_RESERVED_p 'p'
|
||||
%define VBR_ERROR_RESERVED_q 'q'
|
||||
%define VBR_ERROR_RESERVED_r 'r'
|
||||
%define VBR_ERROR_RESERVED_s 's'
|
||||
%define VBR_ERROR_RESERVED_t 't'
|
||||
%define VBR_ERROR_RESERVED_u 'u'
|
||||
%define VBR_ERROR_RESERVED_v 'v'
|
||||
%define VBR_ERROR_RESERVED_w 'w'
|
||||
%define VBR_ERROR_RESERVED_x 'x'
|
||||
|
||||
; 26 errors, 8 in use
|
||||
%define STAGE2_A20_FAILED 'A'
|
||||
%define STAGE2_SIGNATURE_MISSING 'B'
|
||||
%define STAGE2_MM_E820_NO_SUPPORT 'C'
|
||||
%define STAGE2_MM_E820_MISC_ERR 'D'
|
||||
%define STAGE2_MM_E820_NONSTANDARD 'E'
|
||||
%define STAGE2_MM_E820_NO_SMAP 'F'
|
||||
%define STAGE2_MBR_DISK_READ_ERROR 'G'
|
||||
%define STAGE2_FAT32_INIT_ERROR 'H'
|
||||
%define STAGE2_FAT32_NO_FILE 'I'
|
||||
%define STAGE2_FAT32_END_OF_CHAIN 'J'
|
||||
%define STAGE2_ERROR_RESERVED_K 'K'
|
||||
%define STAGE2_ERROR_RESERVED_L 'L'
|
||||
%define STAGE2_ERROR_RESERVED_M 'M'
|
||||
%define STAGE2_ERROR_RESERVED_N 'N'
|
||||
%define STAGE2_ERROR_RESERVED_O 'O'
|
||||
%define STAGE2_ERROR_RESERVED_P 'P'
|
||||
%define STAGE2_ERROR_RESERVED_Q 'Q'
|
||||
%define STAGE2_ERROR_RESERVED_R 'R'
|
||||
%define STAGE2_ERROR_RESERVED_S 'S'
|
||||
%define STAGE2_ERROR_RESERVED_T 'T'
|
||||
%define STAGE2_ERROR_RESERVED_U 'U'
|
||||
%define STAGE2_ERROR_RESERVED_V 'V'
|
||||
%define STAGE2_ERROR_RESERVED_W 'W'
|
||||
%define STAGE2_ERROR_RESERVED_X 'X'
|
||||
%define STAGE2_ERROR_RESERVED_Y 'Y'
|
||||
%define STAGE2_ERROR_RESERVED_Z 'Z'
|
||||
|
||||
|
||||
%macro ERROR 1
|
||||
mov al, %1
|
||||
jmp error
|
||||
%endmacro
|
||||
|
||||
; pass error as ascii character in al, errors a-zA-Z or 0-9
|
||||
error:
|
||||
; color 0x4F is white on red
|
||||
; fs = 0xb800 => fs:0x0000 = 0xb8000
|
||||
mov dx, 0xB800
|
||||
mov fs, dx
|
||||
|
||||
; 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
|
||||
mov dh, 0x4F
|
||||
mov dl, al
|
||||
mov word [fs:0x0000], dx
|
||||
|
||||
.stop:
|
||||
hlt
|
||||
jmp short error.stop
|
||||
86
include/fat32/bpb.inc
Executable file
86
include/fat32/bpb.inc
Executable file
@@ -0,0 +1,86 @@
|
||||
; Copyright (C) 2020 Bradley Claus
|
||||
;
|
||||
; This program is free software: you can redistribute it and/or modify
|
||||
; it under the terms of the GNU General Public License as published by
|
||||
; the Free Software Foundation, either version 3 of the License, or
|
||||
; (at your option) any later version.
|
||||
;
|
||||
; This program is distributed in the hope that it will be useful,
|
||||
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
; GNU General Public License for more details.
|
||||
;
|
||||
; You should have received a copy of the GNU General Public License
|
||||
; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
; BPB Information
|
||||
; Off. Hex Off. Size Description
|
||||
; 0 0x00 3 The first three bytes EB 3C 90 disassemble to JMP SHORT 3C NOP. (The 3C value may be different.)
|
||||
; 3 0x03 8 OEM identifier.
|
||||
; 11 0x0B 2 The number of Bytes per sector (remember, all numbers are in the little-endian format).
|
||||
; 13 0x0D 1 Number of sectors per cluster.
|
||||
; 14 0x0E 2 Number of reserved sectors. The boot record sectors are included in this value.
|
||||
; 16 0x10 1 Number of File Allocation Tables (FAT's) on the storage media. Often this value is 2.
|
||||
; 17 0x11 2 Number of directory entries (must be set so that the root directory occupies entire sectors).
|
||||
; 19 0x13 2 The total sectors in the logical volume.
|
||||
; If this value is 0, it means there are more than 65535 sectors in the volume,
|
||||
; and the actual count is stored in the Large Sector Count entry at 0x20.
|
||||
;
|
||||
; 21 0x15 1 This Byte indicates the media descriptor type.
|
||||
; 22 0x16 2 Number of sectors per FAT. FAT12/FAT16 only.
|
||||
; 24 0x18 2 Number of sectors per track.
|
||||
; 26 0x1A 2 Number of heads or sides on the storage media.
|
||||
; 28 0x1C 4 Number of hidden sectors. (i.e. the LBA of the beginning of the partition.)
|
||||
; 32 0x20 4 Large sector count. This field is set if there are more than 65535 sectors in the volume,
|
||||
; resulting in a value which does not fit in the Number of Sectors entry at 0x13.
|
||||
|
||||
;-- BPB (BIOS Parameter Block)
|
||||
%define bsOemName bx+0x03
|
||||
%define bsBytesPerSect bx+0x0B
|
||||
%define bsSecsPerClust bx+0x0D
|
||||
%define bsResSectors bx+0x0E
|
||||
%define bsFATs bx+0x10
|
||||
%define bsRootDirEnts bx+0x11
|
||||
%define bsSectors bx+0x13
|
||||
%define bsMedia bx+0x15
|
||||
%define bsSectPerFAT1216 bx+0x16
|
||||
%define bsSectPerTrack bx+0x18
|
||||
%define bsHeads bx+0x1A
|
||||
%define bsHidden bx+0x1C
|
||||
%define bsSectorHuge bx+0x20
|
||||
;-- End BPB
|
||||
|
||||
; EBPB Information (FAT32)
|
||||
; Off. Hex Off. Size Description
|
||||
; 36 0x024 4 Sectors per FAT. The size of the FAT in sectors.
|
||||
; 40 0x028 2 Flags.
|
||||
; 42 0x02A 2 FAT version number. The high byte is the major version and the low byte is the minor version. FAT drivers should respect this field.
|
||||
; 44 0x02C 4 The cluster number of the root directory. Often this field is set to 2.
|
||||
; 48 0x030 2 The sector number of the FSInfo structure.
|
||||
; 50 0x032 2 The sector number of the backup boot sector.
|
||||
; 52 0x034 12 Reserved. When the volume is formated these bytes should be zero.
|
||||
; 64 0x040 1 Drive number. The values here are identical to the values returned by the BIOS interrupt 0x13. 0x00 for a floppy disk and 0x80 for hard disks.
|
||||
; 65 0x041 1 Flags in Windows NT. Reserved otherwise.
|
||||
; 66 0x042 1 Signature (must be 0x28 or 0x29).
|
||||
; 67 0x043 4 Volume ID 'Serial' number. Used for tracking volumes between computers. You can ignore this if you want.
|
||||
; 71 0x047 11 Volume label string. This field is padded with spaces.
|
||||
; 82 0x052 8 System identifier string. Always "FAT32 ". The spec says never to trust the contents of this string for any use.
|
||||
; 90 0x05A 420 Boot code.
|
||||
; 510 0x1FE 2 Bootable partition signature 0xAA55.
|
||||
|
||||
;-- EBPB (Extended BIOS Parameter Block)
|
||||
%define bsSectorsPerFAT bx+0x24
|
||||
%define bsFlags bx+0x28
|
||||
%define bsFATVersion bx+0x2A
|
||||
%define bsRootDirCluster bx+0x2C
|
||||
%define bsFSInfoCluster bx+0x30
|
||||
%define bsBackupBootSector bx+0x32
|
||||
%define bsReserved1 bx+0x34
|
||||
%define bsDriveNumber bx+0x40
|
||||
%define bsNTFlags bx+0x41
|
||||
%define bsFATSignature bx+0x42
|
||||
%define bsVolumeSerial bx+0x43
|
||||
%define bsVolumeLabel bx+0x47
|
||||
%define bsSystemIdent bx+0x52
|
||||
;-- End EBPB
|
||||
228
include/fat32/fat32_structures.inc
Executable file
228
include/fat32/fat32_structures.inc
Executable file
@@ -0,0 +1,228 @@
|
||||
; Copyright (C) 2020 Bradley Claus
|
||||
;
|
||||
; This program is free software: you can redistribute it and/or modify
|
||||
; it under the terms of the GNU General Public License as published by
|
||||
; the Free Software Foundation, either version 3 of the License, or
|
||||
; (at your option) any later version.
|
||||
;
|
||||
; This program is distributed in the hope that it will be useful,
|
||||
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
; GNU General Public License for more details.
|
||||
;
|
||||
; You should have received a copy of the GNU General Public License
|
||||
; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
; ## FAT32 Info ##
|
||||
; total_sectors = bsSectorsHuge
|
||||
; fat_size = bsSectorsPerFat
|
||||
;
|
||||
; first_data_sector = bsResSectors + (bsFATs * bsSectPerFAT);
|
||||
; total_data_sectors = bsSectorsHuge - (bsResSectors + (bsFATs * bsSectPerFAT));
|
||||
; total_clusters = total_data_sectors / bsSectsPerClust
|
||||
; first_fat_sector = bsResSectors
|
||||
;
|
||||
; ## FAT32 Table information ##
|
||||
;
|
||||
; fat_offset = active_cluster * 4
|
||||
; fat_sector = first_fat_sector + (fat_offset / sector_size)
|
||||
; entry_offset = fat_offset % sector_size
|
||||
;
|
||||
; table_value = fat_table[entry_offset] & 0x0FFF_FFFF
|
||||
;
|
||||
; ## FAT32 Directory Entries ##
|
||||
; root_dir_cluster = bsRootDirCluster
|
||||
; root_dir_sectors = ? (this is varible on FAT32 since the root dir is a cluster chain)
|
||||
; first_sector_of_cluster = ((cluster - 2) * bsSectPerClust) + first_data_sector;
|
||||
|
||||
; BPB Information
|
||||
; Size Description
|
||||
; 8 OEM identifier.
|
||||
; 2 The number of Bytes per sector (remember, all numbers are in the little-endian format).
|
||||
; 1 Number of sectors per cluster.
|
||||
; 2 Number of reserved sectors. The boot record sectors are included in this value.
|
||||
; 1 Number of File Allocation Tables (FAT's) on the storage media. Often this value is 2.
|
||||
; 2 Number of directory entries (must be set so that the root directory occupies entire sectors).
|
||||
; 2 The total sectors in the logical volume.
|
||||
; If this value is 0, it means there are more than 65535 sectors in the volume,
|
||||
; and the actual count is stored in the Large Sector Count entry at 0x20.
|
||||
;
|
||||
; 1 This Byte indicates the media descriptor type.
|
||||
; 2 Number of sectors per FAT. FAT12/FAT16 only.
|
||||
; 2 Number of sectors per track.
|
||||
; 2 Number of heads or sides on the storage media.
|
||||
; 4 Number of hidden sectors. (i.e. the LBA of the beginning of the partition.)
|
||||
; 4 Large sector count. This field is set if there are more than 65535 sectors in the volume,
|
||||
; resulting in a value which does not fit in the Number of Sectors entry at 0x13.
|
||||
|
||||
struc FAT32_bpb_t
|
||||
.ident_8 resb 8
|
||||
.bytes_per_sector_16 resb 2
|
||||
.sectors_per_cluster_8 resb 1
|
||||
.reserved_sectors_16 resb 2
|
||||
.fat_count_8 resb 1
|
||||
.dir_entry_count_16 resb 2
|
||||
.sector_count_16 resb 2
|
||||
.media_desc_8 resb 1
|
||||
.sectors_per_fat_16 resb 2
|
||||
.sectors_per_track_16 resb 2
|
||||
.head_count_16 resb 2
|
||||
.hidden_sectors_32 resb 4
|
||||
.sector_count_32 resb 4
|
||||
endstruc
|
||||
|
||||
; EBPB Information (FAT32)
|
||||
; Size Description
|
||||
; 4 Sectors per FAT. The size of the FAT in sectors.
|
||||
; 2 Flags.
|
||||
; 2 FAT version number. The high byte is the major version and the low byte is the minor version. FAT drivers should respect this field.
|
||||
; 4 The cluster number of the root directory. Often this field is set to 2.
|
||||
; 2 The sector number of the FSInfo structure.
|
||||
; 2 The sector number of the backup boot sector.
|
||||
; 12 Reserved. When the volume is formated these bytes should be zero.
|
||||
; 1 Drive number. The values here are identical to the values returned by the BIOS interrupt 0x13. 0x00 for a floppy disk and 0x80 for hard disks.
|
||||
; 1 Flags in Windows NT. Reserved otherwise.
|
||||
; 1 Signature (must be 0x28 or 0x29).
|
||||
; 4 Volume ID 'Serial' number. Used for tracking volumes between computers. You can ignore this if you want.
|
||||
; 11 Volume label string. This field is padded with spaces.
|
||||
; 8 System identifier string. Always "FAT32 ". The spec says never to trust the contents of this string for any use.
|
||||
|
||||
struc FAT32_ebpb_t
|
||||
.sectors_per_fat_32 resb 4
|
||||
.fat32_flags_16 resb 2
|
||||
.fat32_version_16 resb 2
|
||||
.root_dir_cluster_32 resb 4
|
||||
.fsinfo_sector_16 resb 2
|
||||
.backup_boot_sector_16 resb 2
|
||||
.reserved1 resb 12
|
||||
.drive_number_8 resb 1
|
||||
.nt_flags_8 resb 1
|
||||
.signature_8 resb 1
|
||||
.volume_serial_32 resb 4
|
||||
.volume_label resb 11
|
||||
.system_ident resb 8
|
||||
endstruc
|
||||
|
||||
; ## Standard 8.3 structure ###
|
||||
; Offset Length (Bytes) Description
|
||||
; 0 11 8.3 file name. The first 8 characters are the name and the last 3 are the extension.
|
||||
; 11 1 File Atrributes
|
||||
; READ_ONLY=0x01
|
||||
; HIDDEN=0x02
|
||||
; SYSTEM=0x04
|
||||
; VOLUME_ID=0x08
|
||||
; DIRECTORY=0x10
|
||||
; ARCHIVE=0x20
|
||||
; LFN=READ_ONLY|HIDDEN|SYSTEM|VOLUME_ID == 0x0F
|
||||
;
|
||||
; 12 1 NT Reserved
|
||||
; 13 1 Creation time in tenths of a second.
|
||||
; 14 2 File creation time, Hour 5 bits, Minutes 6 bits, Seconds 5 Bits, multiply seconds by 2
|
||||
; 16 2 File creation date, Year 7 bits, month 4 bits, day 5 bits
|
||||
; 18 2 Last Accessed date. same format at creation date
|
||||
; 20 2 High 16 bits of entry's first cluster
|
||||
; 22 2 Last modification time. same format at creation time
|
||||
; 24 2 Last modification date. same format as creation date
|
||||
; 26 2 Low 16 bits of entry's first cluster
|
||||
; 28 4 File size in bytes
|
||||
|
||||
struc FAT32_SFN_t
|
||||
.label resb 11
|
||||
.attributes_8 resb 1
|
||||
.nt_res_8 resb 1
|
||||
.csec_8 resb 1
|
||||
.ctime_16 resb 2
|
||||
.cdate_16 resb 2
|
||||
.adate_16 resb 2
|
||||
.cluster_16_high resb 2
|
||||
.mtime_16 resb 2
|
||||
.mdate_16 resb 2
|
||||
.cluster_16_low resb 2
|
||||
.size_32 resb 4
|
||||
endstruc
|
||||
|
||||
; ## Long file name (LFN) structure format ##
|
||||
;
|
||||
; 0 1 The order of this entry in the sequence of long file name entries. This value helps you to know where in the file's name the characters from this entry should be placed.
|
||||
; 1 10 The first 5, 2-byte characters of this entry.
|
||||
; 11 1 Attribute. Always equals 0x0F. (the long file name attribute)
|
||||
; 12 1 Long entry type. Zero for name entries.
|
||||
; 13 1 Checksum generated of the short file name when the file was created. The short filename can change without changing the long filename in cases where the partition is mounted on a system which does not support long filenames.
|
||||
; 14 12 The next 6, 2-byte characters of this entry.
|
||||
; 26 2 Always zero.
|
||||
; 28 4 The final 2, 2-byte characters of this entry.
|
||||
;
|
||||
; LFN entries are always placed immediately before their respective 8.3 entry
|
||||
;
|
||||
; LAST_LFN_ENTRY == 0x40
|
||||
; Max of 20 in sequence == 0x14
|
||||
|
||||
struc FAT32_LFN_t
|
||||
.order resb 1
|
||||
.lfn_first5 resb 10
|
||||
.attributes_8 resb 1
|
||||
.zero1 resb 1
|
||||
.checksum resb 1
|
||||
.lfn_next6 resb 12
|
||||
.zero2 resb 2
|
||||
.lfn_last2 resb 4
|
||||
endstruc
|
||||
|
||||
; FSInfo
|
||||
; 0 0x0 4 Lead signature (must be 0x41615252 to indicate a valid FSInfo structure)
|
||||
; 4 0x4 480 Reserved, these bytes should never be used
|
||||
; 484 0x1E4 4 Another signature (must be 0x61417272)
|
||||
; 488 0x1E8 4 Contains the last known free cluster count on the volume. If the value is 0xFFFFFFFF, then the free count is unknown and must be computed.
|
||||
; However, this value might be incorrect and should at least be range checked (<= volume cluster count)
|
||||
;
|
||||
; 492 0x1EC 4 Indicates the cluster number at which the filesystem driver should start looking for available clusters.
|
||||
; If the value is 0xFFFFFFFF, then there is no hint and the driver should start searching at 2.
|
||||
; Typically this value is set to the last allocated cluster number. As the previous field, this value should be range checked.
|
||||
;
|
||||
; 496 0x1F0 12 Reserved
|
||||
; 508 0x1FC 4 Trail signature (0xAA550000)
|
||||
|
||||
struc FAT32_FSInfo_t
|
||||
.head_signature_32 resd 1
|
||||
.reserved1 resb 480
|
||||
.body_signature_32 resd 1
|
||||
.free_cluster_count_32 resd 1
|
||||
.first_avail_cluster_32 resd 1
|
||||
.reserved2 resd 3
|
||||
.tail_signature_32 resd 1
|
||||
endstruc
|
||||
|
||||
|
||||
; 32 bytes
|
||||
struc FAT32_State_t
|
||||
.first_root_dir_sector_32 resd 1
|
||||
.first_data_sector_32 resd 1
|
||||
.first_fat_sector_32 resd 1
|
||||
.fat_size_32 resd 1
|
||||
.active_cluster_32 resd 1
|
||||
.active_FAT_cluster_32 resd 1
|
||||
.active_dir_cluster_32 resd 1
|
||||
.active_drive_lba_32 resd 1
|
||||
endstruc
|
||||
|
||||
; 16 bytes
|
||||
struc FAT32_NextClusterData_t
|
||||
.fat_offset resd 1
|
||||
.fat_sector resd 1
|
||||
.entry_offset resd 1
|
||||
.reserved_1 resd 1
|
||||
endstruc
|
||||
|
||||
; FAT32 Attributes
|
||||
%define FAT32_ATTR_RO 0x01
|
||||
%define FAT32_ATTR_HIDDEN 0x02
|
||||
%define FAT32_ATTR_SYSTEM 0x04
|
||||
%define FAT32_ATTR_VOLID 0x08
|
||||
%define FAT32_ATTR_DIR 0x10
|
||||
%define FAT32_ATTR_ARC 0x20
|
||||
|
||||
; LFN == RO | HIDDEN | SYSTEM | VOLID == 0x0F
|
||||
%define FAT32_ATTR_LFN 0x0F
|
||||
|
||||
|
||||
208
include/memory.inc
Executable file
208
include/memory.inc
Executable file
@@ -0,0 +1,208 @@
|
||||
; Copyright (C) 2020 Bradley Claus
|
||||
;
|
||||
; This program is free software: you can redistribute it and/or modify
|
||||
; it under the terms of the GNU General Public License as published by
|
||||
; the Free Software Foundation, either version 3 of the License, or
|
||||
; (at your option) any later version.
|
||||
;
|
||||
; This program is distributed in the hope that it will be useful,
|
||||
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
; GNU General Public License for more details.
|
||||
;
|
||||
; You should have received a copy of the GNU General Public License
|
||||
; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
; ## Generic Low mem map (from osdev wiki) ##
|
||||
; start end size type description
|
||||
; Low Memory (the first MiB)
|
||||
; 0x00000000 0x000003FF 1 KiB RAM - partially unusable Real Mode IVT (Interrupt Vector Table)
|
||||
; 0x00000400 0x000004FF 256 bytes RAM - partially unusable BDA (BIOS data area)
|
||||
; 0x00000500 0x00007BFF almost 30 KiB RAM - free for use Conventional memory
|
||||
; 0x00007C00 0x00007DFF 512 bytes RAM - partially unusable OS BootSector
|
||||
; 0x00007E00 0x0007FFFF 480.5 KiB RAM - free for use Conventional memory
|
||||
; 0x00080000 0x0009FFFF 128 KiB RAM - partially unusable EBDA (Extended BIOS Data Area)
|
||||
; 0x000A0000 0x000FFFFF 384 KiB various (unusable) Video memory, ROM Area
|
||||
|
||||
; ## A rough overview of high mem ##
|
||||
; Idealy this needs to be probed with the E820 functions
|
||||
; # Start # End # size # description
|
||||
;
|
||||
; 0x00100000 0x00EFFFFF 0x00E00000 (14 MiB) RAM -- free for use (if it exists) Extended memory
|
||||
; 0x00F00000 0x00FFFFFF 0x00100000 (1 MiB) Possible memory mapped hardware ISA Memory Hole 15-16MB
|
||||
; 0x01000000 ???????? ??? (whatever exists) RAM -- free for use More Extended memory
|
||||
; 0xC0000000 (sometimes) 0xFFFFFFFF 0x40000000 (1 GiB) Memory mapped PCI devices, PnP NVRAM?, IO APIC/s, local APIC/s, BIOS, ...
|
||||
; 0x0000000100000000 ??? ??? (whatever exists) RAM -- free for use (PAE/64bit)/More Extended memory
|
||||
; ???????????????? ??? ??? Potentially usable for memory mapped PCI devices in modern hardware (but typically not, due to backward compatibility)
|
||||
|
||||
; 0x2700 -> 0x28FF
|
||||
%define disk_buffer 0x2700
|
||||
; 0x2900 -> 0x2AFF
|
||||
%define fat_buffer 0x2900
|
||||
; 0x2B00 -> 0x2CFF
|
||||
%define dir_buffer 0x2B00
|
||||
|
||||
; copy of partition table, 72 bytes
|
||||
%define partition_table 0x3000
|
||||
%define partition_table_SIZE 72
|
||||
|
||||
; 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
|
||||
|
||||
; copy of FAT32 EBPB, 54 bytes
|
||||
;0x306A
|
||||
%define fat32_ebpb 0x3070
|
||||
%define fat32_ebpb_SIZE 54
|
||||
|
||||
; FAT32 FSInfo, 512 bytes
|
||||
;0x30A2
|
||||
%define fat32_fsinfo 0x30B0
|
||||
%define fat32_fsinfo_SIZE 512
|
||||
|
||||
; some stored state for the fat32 driver
|
||||
;0x32A2
|
||||
%define fat32_state 0x32B0
|
||||
%define fat32_state_SIZE 32
|
||||
|
||||
; next free space is 0x32D0
|
||||
%define fat32_nc_data 0x32D0
|
||||
%define fat32_nc_data_size 16
|
||||
|
||||
; lba_packet for raw_disk_read
|
||||
%define lba_packet 0x4000
|
||||
|
||||
%define BIOSMemoryMap 0x4200
|
||||
%define SteviaInfo 0x4400
|
||||
|
||||
|
||||
; High memory addresses for loading kernel (for use with unreal mode and 32bit override)
|
||||
|
||||
; file load buffer at 16MB
|
||||
%define HMEM_load_buffer 0x1000000
|
||||
|
||||
|
||||
;PhysicalAddress = Segment * 16 + Offset
|
||||
%define SEG_TO_LINEAR(s,o) ((s << 4) + o)
|
||||
|
||||
; Offset = physical / (Segment * 16)
|
||||
%define LINEAR_TO_OFFSET(p,s) ((p / (s << 4)))
|
||||
|
||||
; Seg = (physical - offset) / 16
|
||||
%define LINEAR_TO_SEGMENT(p,o) ((p - o) >> 4)
|
||||
|
||||
; create normalized linear addres from seg:off (16:4)
|
||||
; Segement = linear >> 4 (top 16 bits)
|
||||
; offset = linear & 0x0F (low 4 bits)
|
||||
|
||||
; 20 bytes, passed to loaded kernel
|
||||
struc SteviaInfoStruct_t
|
||||
.MemoryMapPtr resd 1
|
||||
.MemoryMapEntries resd 1
|
||||
.BPBDataPtr resd 1
|
||||
.EBPBDataPtr resd 1
|
||||
endstruc
|
||||
|
||||
; 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
|
||||
|
||||
; moves argument into eax then pushes lower 16bits then upper 16 bits of of argument to stack
|
||||
; eax is clobbered
|
||||
%macro PUSH_DWORD 1
|
||||
mov eax, %1
|
||||
push ax
|
||||
shr eax, 16
|
||||
push ax
|
||||
%endmacro
|
||||
|
||||
; same as PUSH_DWORD except no arguments, pushes EAX directly
|
||||
%macro PUSH_DWORD_EAX 0
|
||||
push ax
|
||||
shr eax, 16
|
||||
push ax
|
||||
%endmacro
|
||||
|
||||
; pops upper 16bits then lower 16bits into eax
|
||||
; eax is clobbered
|
||||
%macro POP_DWORD_EAX 0
|
||||
xor eax, eax
|
||||
pop ax
|
||||
shl eax, 16
|
||||
pop ax
|
||||
%endmacro
|
||||
|
||||
; moves data on stack referenced by bp to eax
|
||||
; stack must be organized as follows (tl;dr push lower 16bits first ie. PUSH_DWORD macro)
|
||||
; MOV_DWORD_EAX 2
|
||||
; STACK TOP (0x0)
|
||||
; upper_uint16 [bp-4]
|
||||
; lower_uint16 [bp-2]
|
||||
; --- [bp] ---
|
||||
; ...
|
||||
; STACK BOTTOM
|
||||
;
|
||||
; first argument == starting offset from bp for lower 16bits
|
||||
%macro MOV_DWORD_EAX 1
|
||||
mov ax, [bp-(%1+2)]
|
||||
shl eax, 16
|
||||
mov ax, [bp-%1]
|
||||
; eax contains dword from stack
|
||||
%endmacro
|
||||
|
||||
%macro DEBUG_HCF 0
|
||||
DEBUG_LOOP:
|
||||
hlt
|
||||
jmp short DEBUG_LOOP
|
||||
%endmacro
|
||||
|
||||
|
||||
; uint8_t* kmemset(void* dest, uint8_t val, size_t len);
|
||||
kmemset:
|
||||
push di ; function uses di, so save it.
|
||||
|
||||
mov cx, [bp - 2] ; size_t len
|
||||
mov al, [bp - 4] ; uint8_t val
|
||||
mov di, [bp - 6] ; void * ptr
|
||||
|
||||
cld
|
||||
rep stosb
|
||||
.endf:
|
||||
mov ax, [bp - 6] ; return pointer to dest
|
||||
pop di ; restore di
|
||||
ret
|
||||
|
||||
; uint8_t* kmemset(uint8_t* dest, uint8_t* src, size_t len);
|
||||
; not overlap safe
|
||||
kmemcpy:
|
||||
push di
|
||||
push si ; di, si are callee save
|
||||
|
||||
mov cx, [bp - 2] ; length
|
||||
mov si, [bp - 4] ; source
|
||||
mov di, [bp - 6] ; dest
|
||||
|
||||
cld ; ensure we are incrementing
|
||||
rep movsb
|
||||
|
||||
.endf:
|
||||
mov ax, [bp - 6] ; return pointer to dest
|
||||
pop si
|
||||
pop di
|
||||
ret
|
||||
59
include/partition_table.inc
Executable file
59
include/partition_table.inc
Executable file
@@ -0,0 +1,59 @@
|
||||
; Copyright (C) 2020 Bradley Claus
|
||||
;
|
||||
; This program is free software: you can redistribute it and/or modify
|
||||
; it under the terms of the GNU General Public License as published by
|
||||
; the Free Software Foundation, either version 3 of the License, or
|
||||
; (at your option) any later version.
|
||||
;
|
||||
; This program is distributed in the hope that it will be useful,
|
||||
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
; GNU General Public License for more details.
|
||||
;
|
||||
; You should have received a copy of the GNU General Public License
|
||||
; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
; Partition table entry format
|
||||
; Off. Size. Description
|
||||
;0x00 1 Drive attributes (bit 7 set = active or bootable)
|
||||
;0x01 3 CHS Address of partition start
|
||||
;0x04 1 Partition type
|
||||
;0x05 3 CHS address of last partition sector
|
||||
;0x08 4 LBA of partition start
|
||||
;0x0C 4 Number of sectors in partition
|
||||
|
||||
struc PartEntry_t
|
||||
.attributes resb 1
|
||||
.chs_start resb 3
|
||||
.part_type resb 1
|
||||
.chs_end resb 3
|
||||
.lba_start resb 4
|
||||
.lba_length resb 4
|
||||
endstruc
|
||||
|
||||
struc PartTable_t
|
||||
.partition1 resb 16
|
||||
.partition2 resb 16
|
||||
.partition3 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
|
||||
Reference in New Issue
Block a user