initial fs code, readme and gitignore changes, etc
This commit is contained in:
parent
3ffab6de1f
commit
2a95f22a7c
|
@ -1,3 +1,4 @@
|
|||
obj/
|
||||
foxdos
|
||||
kernel.map
|
||||
*.swp
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# foxdos docs
|
||||
|
||||
most of the documentation exists in the form of code comments at the moment
|
||||
|
||||
## mothfs
|
||||
|
||||
`tool/inc/fs.h` contains the majority of documentation for the fs. eventually one of us will probably write a more readable version in md or html
|
|
@ -32,10 +32,11 @@ read_sector:
|
|||
push bx
|
||||
push es
|
||||
.retry:
|
||||
mov es, SECTOR_SEG
|
||||
mov bx, SECTOR_SEG
|
||||
mov es, bx
|
||||
mov bx, SECTOR_ADDR
|
||||
call lba2chs
|
||||
mov ax 0x0201
|
||||
mov ax, 0x0201
|
||||
int 0x13
|
||||
jc .retry
|
||||
pop es
|
||||
|
|
|
@ -12,6 +12,8 @@ setint:
|
|||
xor ah, ah
|
||||
shl ax, 2
|
||||
mov di, ax
|
||||
mov ax, word [callerds]
|
||||
mov ds, ax
|
||||
xor ax, ax
|
||||
push es
|
||||
mov es, ax
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
for i in xxd; do which $i || exit; done
|
||||
|
||||
CC='cc -O3 -Iinc'
|
||||
|
||||
for i in bin2h; do [ ! -f "$i" ] && $CC "$i.c" -o "$i"; done
|
||||
|
||||
[ ! -f mkmothfs ] && nasm mfs_hdr.s && \
|
||||
xxd -i mfs_hdr > inc/mfs_hdr.h && \
|
||||
$CC mkmothfs.c
|
|
@ -0,0 +1,58 @@
|
|||
typedef struct {
|
||||
uint32_t jmp; // used to jump past the header
|
||||
uint8_t magic[7]; // 'MOTHFS\0'
|
||||
uint8_t version; // currently fs version 0
|
||||
uint32_t size; // partition size in sectors - sectors always 512b
|
||||
// this means the max size is 'only' 2tb but i would
|
||||
// be surprised if anyone managed to use 2tb in dos
|
||||
|
||||
uint32_t offset; // offset of partition from start of disk
|
||||
uint8_t volname[15]; // name of partition
|
||||
uint8_t reserved; // number of sectors reserved for boot code. these
|
||||
// are stored immediately following this header
|
||||
|
||||
uint32_t abm; // number of sectors reserved for the allocation
|
||||
// bitmap. these immediately follow the boot code
|
||||
// sectors. the root directory is stored in the first
|
||||
// non-reserved sector
|
||||
|
||||
uint8_t bootcode[470];
|
||||
uint16_t signature; // 0xAA55 as usual to make it directly bootable
|
||||
} mothfs_header; // 512 bytes
|
||||
|
||||
typedef struct {
|
||||
uint32_t sector; // sector offset relative to the partition, not the disk
|
||||
uint32_t length; // number of consecutive sectors to address
|
||||
} ptrlen; // 8 bytes
|
||||
|
||||
typedef struct {
|
||||
uint8_t type; // 0 - file
|
||||
// 1 - directory
|
||||
|
||||
uint8_t perms[3]; // unused in foxdos. good for alignment. top bit of
|
||||
// each nibble must be zero
|
||||
|
||||
uint32_t ext; // undefined in version 0 - contains uid, gid, data
|
||||
// for other file types, long filename, etc
|
||||
|
||||
uint8_t name[8]; // filename
|
||||
uint8_t ext[3]; // extension
|
||||
uint8_t lfn; // size of long filename - must be zero in version 0
|
||||
// this is on par with most filesystems
|
||||
|
||||
uint16_t freebytes; // number of bytes unused in last sector of file data
|
||||
uint16_t pad;
|
||||
|
||||
uint32_t data[122];
|
||||
|
||||
// for files - `data` is 61 `ptrlen`s. if not all 60 are used, it must be null
|
||||
// terminated by setting ptrlen.sector to zero. if there is no terminator,
|
||||
// data[60].sector points to a sector containing 64 more `ptrlen`s. if there is
|
||||
// no terminator in that sector, the last `ptrlen` points to another sector of
|
||||
// identical layout. this continues until a sector with a terminator is found
|
||||
|
||||
// for directories - `data` is 122 sector offsets. if not all 121 are used, it
|
||||
// must be null terminated. if there is no terminator, data[121] points to a
|
||||
// sector containing 128 more sector offsets. the rules for this are similar
|
||||
// enough to how files work that i do not want to write it out again
|
||||
} mothfs_file; // 512 bytes
|
|
@ -0,0 +1,73 @@
|
|||
; TODO implement boot via chs for old bioses (even ones
|
||||
; as new as 1996 lack support for lba via bios call)
|
||||
[bits 16]
|
||||
[org 0x7C00]
|
||||
|
||||
jmp entry
|
||||
times 4 - ($-$$) db 0
|
||||
|
||||
db "MOTHFS",0
|
||||
db 0
|
||||
sz: dd 32768 ; 32768 * 512 = 16mb disk image
|
||||
off: dd 1 ; immediately follows mbr
|
||||
db "mkmothfs",0,0,0,0,0,0,0
|
||||
rsv: db 127 ; 64kb of boot code
|
||||
abm: dd 4096 ; 16mb/(512*8)
|
||||
|
||||
entry:
|
||||
push cs
|
||||
pop ds
|
||||
push dx
|
||||
|
||||
; enable a20 a few different ways
|
||||
in al, 0xEE
|
||||
|
||||
; bios call
|
||||
mov ax, 0x2401 ; l is real
|
||||
int 0x15
|
||||
|
||||
; fast a20 gate
|
||||
in al, 0x92
|
||||
or al, 2
|
||||
out 0x92, al
|
||||
|
||||
mov eax, [off]
|
||||
mov dword [dapw], eax
|
||||
|
||||
; check for lba support
|
||||
mov ah, 0x41
|
||||
mov bx, 0x55AA
|
||||
int 0x13 ; dl is drive number - mbr should pass this value
|
||||
jc .nde
|
||||
shr cx, 2 ; wikipedia says bit 1 is disk packet support
|
||||
jnc .nde
|
||||
|
||||
; load kernel flat binary into hma using lba
|
||||
pop dx
|
||||
mov ah, 0x42
|
||||
mov si, dap
|
||||
int 0x13
|
||||
|
||||
; jump to FFFF:0010, the start of HMA. this limits the kernel
|
||||
; size to 65520 bytes but we are actually loading 496 bytes
|
||||
; less than that and even that should be more than enough for
|
||||
; foxdos and any more would probably blow up some garbage bios
|
||||
mov ax, 0xFFFF
|
||||
push ax
|
||||
mov ax, 16
|
||||
push ax
|
||||
retf
|
||||
|
||||
.nde: mov eax, [sz]
|
||||
add eax, [off]
|
||||
cmp eax, 0xFB0400 ; max chs sectors
|
||||
jg $ ; too big to use chs
|
||||
jmp $ ; TODO load via chs
|
||||
|
||||
dap: dw 0x10 ; size of disk packet
|
||||
dw 127 ; foxdos will always load 127 segments
|
||||
dw 16, 0xFFFF ; offset:segment to start of HMA - foxdos loads high
|
||||
dapw: dd 0, 0
|
||||
|
||||
times 510 - ($-$$) db 0
|
||||
dw 0xAA55
|
|
@ -0,0 +1,10 @@
|
|||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <mfs_hdr.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if(argc < 100) return !!printf("need arguments: ?\n");
|
||||
|
||||
}
|
Loading…
Reference in New Issue