Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef __FAT_H__
- #define __FAT_H__
- #include <stdint.h>
- #include <machine.h>
- typedef struct bpb {
- char jmp_code[3];
- char oem[8];
- uint16_t bytes_per_sector;
- uint8_t sectors_per_cluster;
- uint16_t reserved_sectors;
- uint8_t fats;
- uint16_t dir_entries;
- uint16_t logical_sectors;
- uint8_t media_type;
- uint16_t sectors_per_fat;
- uint16_t sectors_per_track;
- uint16_t heads;
- uint32_t hidden_sectors;
- uint32_t large_sectors;
- } bpb_t;
- typedef struct ebr {
- uint8_t drive;
- uint8_t rflags;
- uint8_t signiture;
- uint32_t serial;
- char label[11];
- char identifier[8];
- char boot_code[448];
- uint16_t boot_sign;
- } ebr_t;
- typedef struct fat12_partition_info {
- // see fat12.s for an implementation
- // in assembly for visualization :D
- bpb_t bpb;
- ebr_t ebr;
- char data[];
- } fat12_partition_info_t;
- typedef char fat_t[];
- typedef struct fat_dir_entry {
- char name[11];
- uint8_t attributes;
- uint16_t reserved;
- uint16_t creation_time;
- uint16_t creation_date;
- uint16_t access_date;
- uint16_t caddr_high;
- uint16_t write_time;
- uint16_t write_date;
- uint16_t caddr_low;
- uint32_t size;
- } fat_dir_entry_t;
- const uint8_t fat12_format_stub[122] = {
- 0xEB, 0x3C, 0x90, 0x4D, 0x61, 0x64, 0x4F, 0x53, 0x76, 0x30,
- 0x31, 0x00, 0x02, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x37,
- 0x13, 0x00, 0x00, 0x4D, 0x61, 0x64, 0x4F, 0x53, 0x20, 0x44,
- 0x69, 0x73, 0x6B, 0x20, 0x46, 0x41, 0x54, 0x31, 0x32, 0x20,
- 0x20, 0x20, 0x31, 0xC0, 0x8E, 0xD8, 0x8E, 0xC0, 0x8E, 0xD0,
- 0xBC, 0x7A, 0x8C, 0x8D, 0x36, 0x5E, 0x7C, 0xE8, 0x02, 0x00,
- 0xEB, 0xFE, 0xAC, 0x08, 0xC0, 0x74, 0x06, 0xB4, 0x0E, 0xCD,
- 0x10, 0xEB, 0xF5, 0xC3, 0x4D, 0x61, 0x64, 0x4F, 0x53, 0x20,
- 0x64, 0x69, 0x73, 0x6B, 0x20, 0x6E, 0x6F, 0x74, 0x20, 0x62,
- 0x6F, 0x6F, 0x74, 0x61, 0x62, 0x6C, 0x65, 0x2E, 0x2E, 0x2E,
- 0x0D, 0x0A
- /*
- [bits 16]
- [org 0x7C00]
- ;;;;;;;;;;;;;;;;;;;;;;;;
- ; BIOS Parameter Block
- jmp short boot_code
- nop
- db "MadOSv01" ; OEM identifier
- dw 512 ; Bytes per sector: 512, 1024, 2048 or 4096.
- ; the value 512 should be used for max compat.
- db 1 ; sectors per cluster: 1, 2, 4, 8, 16, 32, 64, and 128.
- dw 0 ; reserved sectors: must not be 0. For FAT12 and FAT16 volumes must be 1
- db 2 ; number of fats: always contain the value 2
- dw 0 ; root directory entries
- dw 0 ; logical sectors
- db 0 ; media descriptor type: 0xF8 -> fixed, 0xF0 -> removable
- dw 0 ; sectors per fat, fat12/fat16 only, number of sectors occupied by one fat
- dw 0 ; sectors per track
- dw 0 ; number of heads / sides on media
- dd 0 ; number of hidden sectors
- dd 0 ; Large amount of sector on media. This field is set if there are more than 65535 sectors in the volume.
- ; Extended Boot Record
- db 0 ; drive number
- db 0 ; reserved / NT flags (maybe use for MadOS, More research needed)
- db 0x29 ; signiture, 0x28 or 0x29 for fat12 /fat16
- dd 0x1337 ; volume serial number
- db "MadOS Disk " ; volume label
- db "FAT12 " ; identifier string
- ; Boot code
- boot_code:
- xor ax, ax
- mov ds, ax
- mov es, ax
- mov ss, ax
- mov sp, boot_code_end + (1024 * 4)
- lea si, [message]
- call print_string
- jmp $
- print_string:
- lodsb
- or al, al
- jz done
- mov ah, 0x0E
- int 0x10
- jmp print_string
- done:
- ret
- message:
- db "MadOS disk not bootable...", 0xd, 0xa
- ;dw 0xAA55 ; bootable partition signiture, uncomment to make the floppy boot
- boot_code_end:
- times 450 - (boot_code_end - boot_code) db 0
- ;;;;;;;;;;;;;;;;;;;;;
- ; DATA AREA START
- ;;;;;;;;;;;;;;;;;;;;;
- ; root directory
- ;;;;;;;;;;;;;;;;;;;;;
- ; END -> FIN
- */
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement