doc: document file system

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-07-18 11:28:07 +02:00
parent 4b8036b192
commit f2fdc0aada
17 changed files with 217 additions and 86 deletions

View file

@ -13,6 +13,7 @@ SRCS = kernel.asm \
isr.inc \
pic.inc \
idt.inc \
heap.inc \
dev/console.inc \
dev/at/pit.inc \
dev/at/cga.inc \

3
kernel/conf/devices Normal file
View file

@ -0,0 +1,3 @@
console c 0 0
fd0 b 0 0
fd1 b 0 1

View file

@ -49,25 +49,50 @@ floppy_strategy:
ret
floppy_open:
push ebp
mov ebp, esp
mov eax, [ebp+4]
cmp al, FLOPPY_MAX
jb @f
mov eax, ENXIO
jmp .end
@@:
xor eax, eax
.end:
pop ebp
ret
floppy_close:
xor eax, eax
ret
floppy_ioctl:
mov eax, ENODEV
ret
floppy_dump:
ret
floppy_psize:
ret
floppy_irq:
iret
floppy_device:
db 'floppy', 0, 0
dd floppy_init
db 0
db 0
db FLOPPY_BDEV_MAJOR
db FLOPPY_CDEV_MAJOR
szMsgFloppy0Found db "floppy0: Found", 0
szMsgFloppy1Found db "floppy1: Found", 0
floppy_blockdev:
dd floppy_open
dd floppy_strategy
dd floppy_ioctl
dd floppy_close
dd floppy_dump
dd floppy_psize
szMsgFloppy0Found db "floppy: fd0 found", 0
szMsgFloppy1Found db "floppy: fd1 found", 0

View file

@ -28,6 +28,12 @@ kbd_init:
@@:
ret
kbd_open:
ret
kbd_close:
ret
kbd_getc:
in al, KBD_STATP
and al, KBS_DIB

View file

@ -1,6 +1,4 @@
;; File: console.inc
console_probe:
ret
console_write:
mov eax, uConsoleLock

View file

@ -7,7 +7,6 @@ DEFN Device
struc BlkDev {
.open dd ?
.close dd ?
.strategy dd ?
.ioctl dd ?
.close dd ?

2
kernel/fork.inc Normal file
View file

@ -0,0 +1,2 @@
fork:
ret

View file

@ -1,7 +1,8 @@
;; File: fat.inc
;;
;;
;; Usefull links:
;; - <Spec at https://academy.cba.mit.edu/classes/networking_communications/SD/FAT.pdf>
;; - <Microsoft FAT Specification at https://academy.cba.mit.edu/classes/networking_communications/SD/FAT.pdf>
FAT_SECTOR_SIZE = 512
FAT_MDIR_SIZE = 32
@ -59,6 +60,27 @@ struc FATFS_BootSector32 {
}
DEFN FATFS_BootSector32
struc FATFS_Dirent {
.name db 8 dup(?)
.ext db 3 dup(?)
.attr db ?
.reserved db 0
.crt_time_tenth db ?
.crt_time dw ?
.crt_date dw ?
.lst_acc_date dw ?
.fst_clus_hi dw ?
.wrt_time dw ?
.wrt_date dw ?
.fst_clus_lo dw ?
.file_size dd ?
}
DEFN FATFS_Dirent
; ------------------------------------------------------------------------
;; Section: Implementation
szVfsFatName db 'FATFS', 0
vfs_fatfs:

View file

@ -1,27 +1,86 @@
;; File: stpdfs.inc
;;
;; > ┌──────────┬───────────┬──────┬───┬──────┬────┬───┬────┐
;; > │Boot block│Super block│Inodes│...│Inodes│Data│...│Data│
;; > └──────────┴───────────┴──────┴───┴──────┴────┴───┴────┘
;; Constant: STPDFS_SB_MAGIC
;; Superblock magic number, MUST BE `0x44505453` (STPD)
STPDFS_SB_MAGIC = 0x44505453
;; Constant: STPDFS_SB_REV
;; StupidFS revision, currently `0x1`
STPDFS_SB_REV = 1
;; Constant: STPDFS_BSIZE
;; StupidFS block size (512)
STPDFS_BSIZE = 512
;; Constant: STPDFS_BADINO
;; StupidFS bad inode
STPDBOOT_BADINO = 0
;; Constant: STPDFS_ROOTINO
;; StupidFS root inode
STPDFS_ROOTINO = 1
;; Constant: STPDFS_NDIRECT
STPDFS_NDIRECT = 7
;; Constant: STPDFS_NAME_MAX
STPDFS_NAME_MAX = 28
;; Enum: StupidFS State
;; STPDFS_CLEANLY_UNMOUNTED - 0
;; STPDFS_ERROR - 1
;; STPDFS_DIRTY - 1
STPDFS_CLEANLY_UNMOUNTED = 0
STPDFS_ERROR = 1
STPDFS_DIRTY = 1
;; Struc: StpdFS_FreeList
;;
;; > ┌──────────┐
;; > block 99
;; > ├──────────┤
;; > block 98
;; > ├──────────┤
;; > ...
;; > ├──────────┤
;; > block 2
;; > ├──────────┤
;; > block 1
;; > ├──────────┤ ┌──────────┐
;; > block 0 ├───►│ block 99
;; > └──────────┘ ├──────────┤
;; > ...
;; > ├──────────┤ ┌──────────┐
;; > block 0 ├───►│ block 99
;; > └──────────┘ ├──────────┤
;; > ...
;; > ├──────────┤
;; > block 0
;; > └──────────┘
;;
struc StpdFS_FreeList {
.free dd 100 dup(?)
.nfree db ?
}
;; Struc: StpdFS_Sb
;; .magic - See <STPDFS_SB_MAGIC>
;; .isize - Size in block of the i-node list
;; .fsize - Size in block of the entire volume
;; .freelist - See <StpdFS_FreeList>
;; .rev - See <STPDFS_SB_REV>
;; .state - See <StupidFS State>
;; .time - Last access time (64bit UNIX timestamp)
struc StpdFS_Sb {
.magic dd ?
.isize dd ?
.fsize dd ?
.free dd 100 dup(?)
.nfree db ?
.freelist StpdFS_FreeList
.rev db ?
.state dw ?
.time dq ?
}
DEFN StpdFS_Sb
;; Struc: StpdFS_Inode
struc StpdFS_Inode {
.mode dw ?
.nlink dw ?
@ -35,6 +94,22 @@ struc StpdFS_Inode {
}
DEFN StpdFS_Inode
;; Struc: StpdFS_Dirent
;; StupidFS dir entry
;;
;; .inode - address of i-node
;; .name - null terminated file name (see <STPDFS_NAME_MAX>)
struc StpdFS_Dirent {
.inode dd ?
.name db STPDFS_NAME_MAX dup(?)
}
DEFN StpdFS_Dirent
; ------------------------------------------------------------------------
;; Section: Implementation
szVfsStpdFSName db 'StupidFS', 0
vops_stpdfs:

View file

@ -1,9 +1,15 @@
;; File: xv6fs.inc
;;
;; > ┌──────────┬───────────┬───┬───┬───┬──────┬───┬──────┬──────┬───┬──────┬────┬───┬────┐
;; > │Boot block│Super block│Log│...│Log│Inodes│...│Inodes│Bitmap│...│Bitmap│Data│...│Data│
;; > └──────────┴───────────┴───┴───┴───┴──────┴───┴──────┴──────┴───┴──────┴────┴───┴────┘
;;
;; Usefull links:
;; - <https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/fs.h>
;; - <xv6 book at https://pdos.csail.mit.edu/6.1810/2023/xv6/book-riscv-rev3.pdf>
;; Constant: XV6FS_BSIZE
;; xv6 Filesystem block size (1024)
XV6FS_BSIZE = 1024
XV6FS_ROOTINO = 1
XV6FS_MAGIC = 0x10203040
@ -13,6 +19,7 @@ XV6FS_MAXFILE = (XV6FS_NDIRECT + XV6FS_NINDIRECT)
XV6FS_IPB = (XV6FS_BSIZE / 64)
XV6FS_DIRSIZE = 14
;; Struc: Xv6FS_Sb
struc Xv6FS_Sb {
.magic dd ?
.size dd ?
@ -25,6 +32,7 @@ struc Xv6FS_Sb {
}
DEFN Xv6FS_Sb
;; Struc: Xv6FS_Inode
struc Xv6FS_Inode {
.type dw ?
.major dw ?
@ -35,11 +43,17 @@ struc Xv6FS_Inode {
}
DEFN Xv6FS_Inode
;; Struc: Xv6FS_Dirent
struc Xv6FS_Dirent {
.inum dw ?
.name db XV6FS_DIRSIZE dup(?)
}
; ------------------------------------------------------------------------
;; Section: Implementation
szVfsXv6FSName db 'xv6FS', 0
vops_xv6fs:

27
kernel/heap.inc Normal file
View file

@ -0,0 +1,27 @@
;; File: heap.inc
;; Function: heap_init
heap_init:
push ebp
mov ebp, esp
sub esp, 4
mov [ebp-4], eax
mov ecx, KERNEL_VIRT_BASE
add eax, ecx
push eax
push ecx
mov esi, szMsgHeapInit
call klog
; TODO
leave
ret
heap_alloc:
ret
heap_free:
ret
szMsgHeapInit db "HEAP: initialize %x - %x", 0

View file

@ -6,15 +6,13 @@
include 'sys/bootinfo.inc'
include 'sys/cpu.inc'
include 'sys/errno.inc'
include 'sys/process.inc'
org KBASE
use32
jmp short kmain
db 'STPDKRNL'
db 32 dup(0)
;; Function: kmain
;;
;; Parameters:
@ -56,6 +54,9 @@ kmain:
add ebx, KERNEL_VIRT_BASE
call pmm_free_range
mov eax, [boot_structure.low_mem]
call heap_init
call pic_init
; clear tss
@ -109,6 +110,7 @@ kmain:
include 'isr.inc'
include 'idt.inc'
include 'pic.inc'
include 'heap.inc'
include 'vfs.inc'
include 'fs/fat.inc'
include 'fs/stpdfs.inc'

View file

@ -14,6 +14,7 @@ struc BootInfo {
.kernel_start dd ?
.kernel_size dd ?
.high_mem dd ?
.low_mem dd ?
}
virtual at 0
BootInfo BootInfo

View file

@ -1,2 +1,2 @@
ENXIO = 6
ENODEV = 19

27
kernel/sys/process.inc Normal file
View file

@ -0,0 +1,27 @@
struc ProcessGroup {
}
struc Context {
.flags dd ?
.regs dd ?
}
struc Process {
.pagedir dd ?
.parent dd ?
.context Context
.next dd ?
}
PROCESS_STATE_IDL = 0
PROCESS_STATE_RUN = 1
PROCESS_STATE_SLEEP = 2
PROCESS_STATE_STOP = 3
PROCESS_STATE_ZOMBIE = 4
PZERO = 22
PWAIT = 24
PLOCK = 36
PPAUSE = 40
PUSER = 50

View file

@ -1,71 +0,0 @@
#include <stdlib.h>
#include <stdio.h>
#include <sodium.h>
static char *prg_name;
struct kernel_header {
uint8_t jump[3];
uint8_t magic[8];
uint8_t signature[32];
};
static void
do_keygen()
{
uint8_t pk[crypto_sign_ed25519_PUBLICKEYBYTES];
uint8_t sk[crypto_sign_ed25519_SECRETKEYBYTES];
}
static void
usage(int retcode)
{
if (retcode == EXIT_FAILURE)
{
fprintf(stderr, "Try '%s -h' form more information.\n", prg_name);
}
else
{
printf("Usage: %s [-hV] [sign|verify|keygen]\n", prg_name);
printf("\t-h\tdisplay this help and exit\n");
printf("\t-V\toutput version information\n");
printf("\nReport bugs to <%s>\n", MK_BUGREPORT);
}
exit(retcode);
}
static void
version(void)
{
printf("%s commit %s\n", prg_name, MK_COMMIT);
exit(EXIT_SUCCESS);
}
int
main(int argc, char **argv)
{
prg_name = argv[0];
if (sodium_init() < 0) abort();
while ((argc > 1) && (argv[1][0] == '-'))
{
switch (argv[1][1])
{
case 'h':
usage(EXIT_SUCCESS);
break;
case 'V':
version();
}
argv++;
argc--;
}
if (argc <= 1) usage(EXIT_FAILURE);
return (EXIT_SUCCESS);
}

View file

@ -107,7 +107,7 @@ main(int argc, char **argv)
c = argv[1][2] - '0';
argv++;
argc--;
if (c != 0 && c != 1 && c != 2 && c != 3)
if (c < 0 && c > 3)
{
usage(EXIT_FAILURE);
}