Starting with writing docs ended with me fixing a critical bug
This commit is contained in:
parent
4266211e57
commit
2e6f8a289b
|
|
@ -0,0 +1,14 @@
|
||||||
|
#define MODULE_API_REGISTER 0
|
||||||
|
#define MODULE_API_ADDFUNC 1
|
||||||
|
#define MODULE_API_DELFUNC 2
|
||||||
|
#define MODULE_API_ADDINT 3
|
||||||
|
#define MODULE_API_DELINT 4
|
||||||
|
#define MODULE_API_PRINT 5
|
||||||
|
#define MODULE_API_READ 6 //read from virtual file
|
||||||
|
#define MODULE_API_WRITE 7 //write to virtual file
|
||||||
|
#define MODULE_API_CREAT 8 //create a virtual file and assigns it to the the proper module (requires having a read and write function passed)
|
||||||
|
#define MODULE_API_DELET 9
|
||||||
|
|
||||||
|
# Kimi's OS Kernel Module API
|
||||||
|
|
||||||
|
On boot time, the bootloader will search the filesystem for the files `idm.elf` and `ifsm.elf` in the root directory. These are the only two modules loaded at boot time. Afterwards, the kernel will search the folder
|
||||||
13
makefile
13
makefile
|
|
@ -11,7 +11,7 @@ all: bootloader tools kernel
|
||||||
cp bin/bootloader.bin image.bin
|
cp bin/bootloader.bin image.bin
|
||||||
qemu-img resize -f raw image.bin 512M
|
qemu-img resize -f raw image.bin 512M
|
||||||
./diskwrite -v -l idm.elf ifsm.elf kernel.elf -o image.bin
|
./diskwrite -v -l idm.elf ifsm.elf kernel.elf -o image.bin
|
||||||
# ./diskwrite -v idm.elf -o image.bin
|
# ./diskwrite -v -o image.bin
|
||||||
# ./diskwrite -v -l kernel.elf idm.elf -o image.bin
|
# ./diskwrite -v -l kernel.elf idm.elf -o image.bin
|
||||||
qemu-system-i386 -hda image.bin --no-reboot --no-shutdown -m 32m -smp 2 -serial mon:stdio -D intlog.txt -d int
|
qemu-system-i386 -hda image.bin --no-reboot --no-shutdown -m 32m -smp 2 -serial mon:stdio -D intlog.txt -d int
|
||||||
tools:
|
tools:
|
||||||
|
|
@ -19,7 +19,16 @@ tools:
|
||||||
|
|
||||||
bootloader:
|
bootloader:
|
||||||
$(AS) src/bootloader/main.s $(BL_ASFLAGS) -o bin/bootloader.bin
|
$(AS) src/bootloader/main.s $(BL_ASFLAGS) -o bin/bootloader.bin
|
||||||
|
run:
|
||||||
|
qemu-system-i386 -hda image.bin --no-reboot --no-shutdown -m 32m -smp 2 -serial mon:stdio -D intlog.txt -d int
|
||||||
|
|
||||||
|
test: bootloader tools kernel
|
||||||
|
cp bin/bootloader.bin image.bin
|
||||||
|
qemu-img resize -f raw image.bin 512M
|
||||||
|
./diskwrite -v -o image.bin
|
||||||
|
fsck.fat image.bin
|
||||||
|
sudo cp kernel.elf test/kernel.elf
|
||||||
|
make run
|
||||||
# kernel: $(OBJS)
|
# kernel: $(OBJS)
|
||||||
kernel:
|
kernel:
|
||||||
nasm src/kernel/entry.s -o bin/kernel/entry.o -f elf32
|
nasm src/kernel/entry.s -o bin/kernel/entry.o -f elf32
|
||||||
|
|
|
||||||
|
|
@ -61,13 +61,13 @@ fat_bpb:
|
||||||
dd 1048576
|
dd 1048576
|
||||||
fat_ebpb32:
|
fat_ebpb32:
|
||||||
.sectors_per_fat:
|
.sectors_per_fat:
|
||||||
dd 1024
|
dd 2048
|
||||||
.flags:
|
.flags:
|
||||||
dw 0
|
dw 0
|
||||||
.version:
|
.version:
|
||||||
db 0, 1
|
db 0, 1
|
||||||
.root_dir_cluster:
|
.root_dir_cluster:
|
||||||
dd 2
|
dd 2
|
||||||
.fs_info_sector:
|
.fs_info_sector:
|
||||||
dw 1
|
dw 1
|
||||||
.backup_boot:
|
.backup_boot:
|
||||||
|
|
@ -508,6 +508,7 @@ open_file:
|
||||||
add si, ax
|
add si, ax
|
||||||
xor cx, cx
|
xor cx, cx
|
||||||
mov ax, [fat_ebpb32.root_dir_cluster]
|
mov ax, [fat_ebpb32.root_dir_cluster]
|
||||||
|
sub ax, 2
|
||||||
mov cl, [fat_bpb.sectors_per_cluster]
|
mov cl, [fat_bpb.sectors_per_cluster]
|
||||||
mul cx
|
mul cx
|
||||||
add si, ax
|
add si, ax
|
||||||
|
|
@ -562,11 +563,13 @@ read_file:
|
||||||
;args: esi = first cluster in chain
|
;args: esi = first cluster in chain
|
||||||
;edi = pointer to data
|
;edi = pointer to data
|
||||||
push esi
|
push esi
|
||||||
|
sub esi, 2
|
||||||
xor ecx, ecx
|
xor ecx, ecx
|
||||||
xor edx, edx
|
xor edx, edx
|
||||||
mov eax, esi
|
mov eax, esi
|
||||||
mov cl, [fat_bpb.sectors_per_cluster]
|
mov cl, [fat_bpb.sectors_per_cluster]
|
||||||
mul ecx; eax = offset from file table
|
mul ecx; eax = offset from file table
|
||||||
|
; jmp $
|
||||||
|
|
||||||
push eax
|
push eax
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
|
|
@ -895,7 +898,7 @@ fs_module_struct:
|
||||||
.type: dd 2
|
.type: dd 2
|
||||||
.flags: db 0
|
.flags: db 0
|
||||||
.next_entry: dd 0
|
.next_entry: dd 0
|
||||||
kernel_file: db "kernel", 0, 0, "elf"
|
kernel_file: db "kernel", 0x0, 0x0, "elf"
|
||||||
disk_module_file: db "idm", 0, 0, 0, 0, 0, "elf"
|
disk_module_file: db "idm", 0, 0, 0, 0, 0, "elf"
|
||||||
fs_module_file: db "ifsm", 0, 0, 0, 0, "elf"
|
fs_module_file: db "ifsm", 0, 0, 0, 0, "elf"
|
||||||
loaded_fat_block: dd 0
|
loaded_fat_block: dd 0
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,30 @@
|
||||||
#include "../shared/kstdlib.h"
|
#include "../shared/kstdlib.h"
|
||||||
|
|
||||||
#define MODULE_PRESENT 0x80
|
#define MODULE_PRESENT 0x80
|
||||||
|
//semver is represented by hexadecimal
|
||||||
|
//first two digits are the major number
|
||||||
|
//second two digits are the minor number
|
||||||
|
//no patch number
|
||||||
|
#define MODULE_API_VERSION 0x0100
|
||||||
|
|
||||||
|
#define MODULE_API_REGISTER 0
|
||||||
|
#define MODULE_API_ADDFUNC 1
|
||||||
|
#define MODULE_API_DELFUNC 2
|
||||||
|
#define MODULE_API_ADDINT 3
|
||||||
|
#define MODULE_API_DELINT 4
|
||||||
|
#define MODULE_API_PRINT 5
|
||||||
|
#define MODULE_API_READ 6 //read from virtual file
|
||||||
|
#define MODULE_API_WRITE 7 //write to virtual file
|
||||||
|
#define MODULE_API_CREAT 8 //create a virtual file and assigns it to the the proper module (requires having a read and write function passed)
|
||||||
|
#define MODULE_API_DELET 9
|
||||||
|
|
||||||
|
|
||||||
typedef struct module{
|
typedef struct module{
|
||||||
void *init_entry;
|
void *init_entry;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
char name[16];
|
char name[16];
|
||||||
uint8_t flags;
|
uint8_t flags;
|
||||||
|
void (*fini)(void);
|
||||||
}module_t;
|
}module_t;
|
||||||
|
|
||||||
void init_modules(kernel_info_t *kernel_info);
|
void init_modules(kernel_info_t *kernel_info);
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
KOS_MAPI_FP api;
|
KOS_MAPI_FP api;
|
||||||
|
|
||||||
void init(KOS_MAPI_FP module_api){
|
void init(KOS_MAPI_FP module_api, uint32_t api_version){
|
||||||
uint16_t *t = (void *)0xb8000;
|
uint16_t *t = (void *)0xb8000;
|
||||||
*t = 0xf000;
|
*t = 0xf000;
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
KOS_MAPI_FP api;
|
KOS_MAPI_FP api;
|
||||||
|
|
||||||
void init(KOS_MAPI_FP module_api){
|
void init(KOS_MAPI_FP module_api, uint32_t api_version){
|
||||||
uint16_t *t = (void *)0xb8002;
|
uint16_t *t = (void *)0xb8002;
|
||||||
*t = 0xf000;
|
*t = 0xf000;
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1 +1,9 @@
|
||||||
typedef void (*KOS_MAPI_FP)(unsigned int function, ...);
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef void (*KOS_MAPI_FP)(unsigned int function, ...);
|
||||||
|
typedef struct module{
|
||||||
|
void *init_entry;
|
||||||
|
uint32_t id;
|
||||||
|
char name[16];
|
||||||
|
uint8_t flags;
|
||||||
|
}module_t;
|
||||||
|
|
@ -132,7 +132,7 @@ void write_cluster_value(fat_info *info, uint32_t value, uint32_t cluster){
|
||||||
//read cluster - returns next cluster in chain
|
//read cluster - returns next cluster in chain
|
||||||
uint32_t read_cluster(fat_info *info, uint32_t cluster, buffer_t buffer, size_t size, FILE *disk){
|
uint32_t read_cluster(fat_info *info, uint32_t cluster, buffer_t buffer, size_t size, FILE *disk){
|
||||||
// uint8_t *new_buffer = calloc(4096, 1 * (info->bpb.bytes_per_sector * info->bpb.sectors_per_cluster));
|
// uint8_t *new_buffer = calloc(4096, 1 * (info->bpb.bytes_per_sector * info->bpb.sectors_per_cluster));
|
||||||
read_sector(disk, info->bpb.reserved_sectors + info->file_table_size_sectors + info->bpb.partition_start + (cluster * info->bpb.sectors_per_cluster), info->bpb.sectors_per_cluster, buffer);
|
read_sector(disk, info->bpb.reserved_sectors + info->file_table_size_sectors + info->bpb.partition_start + ((cluster - 2) * info->bpb.sectors_per_cluster), info->bpb.sectors_per_cluster, buffer);
|
||||||
// memcpy(buffer, new_buffer, size);
|
// memcpy(buffer, new_buffer, size);
|
||||||
return info->file_table[cluster];
|
return info->file_table[cluster];
|
||||||
}
|
}
|
||||||
|
|
@ -154,7 +154,7 @@ int write_file(fat_info *info, file_t *file, buffer_t buffer, size_t size, FILE
|
||||||
printf("start: %d count: %d\n", cluster, clusters);
|
printf("start: %d count: %d\n", cluster, clusters);
|
||||||
// return -1;
|
// return -1;
|
||||||
for(uint32_t i = 0; i < clusters; i++){
|
for(uint32_t i = 0; i < clusters; i++){
|
||||||
write_sector(disk, info->bpb.reserved_sectors + info->file_table_size_sectors + info->bpb.partition_start + (cluster * info->bpb.sectors_per_cluster), info->bpb.sectors_per_cluster, new_buffer + i * info->bpb.sectors_per_cluster * info->bpb.bytes_per_sector);
|
write_sector(disk, info->bpb.reserved_sectors + info->file_table_size_sectors + info->bpb.partition_start + ((cluster - 2) * info->bpb.sectors_per_cluster), info->bpb.sectors_per_cluster, new_buffer + i * info->bpb.sectors_per_cluster * info->bpb.bytes_per_sector);
|
||||||
uint32_t next_cluster = info->file_table[cluster];
|
uint32_t next_cluster = info->file_table[cluster];
|
||||||
if(next_cluster == -1){
|
if(next_cluster == -1){
|
||||||
next_cluster = find_free_cluster(info);
|
next_cluster = find_free_cluster(info);
|
||||||
|
|
@ -169,9 +169,9 @@ int write_file(fat_info *info, file_t *file, buffer_t buffer, size_t size, FILE
|
||||||
}
|
}
|
||||||
|
|
||||||
int create_file(char *path, fat_info *info, FILE *file, FILE *disk){
|
int create_file(char *path, fat_info *info, FILE *file, FILE *disk){
|
||||||
file_t *root_files = calloc(4096, sizeof(file_t));
|
file_t *root_files = calloc(info->bpb.sectors_per_cluster * 512, sizeof(file_t));
|
||||||
// read_file(info, 0, (buffer_t)root_files, (uint32_t)4096, disk);
|
// read_file(info, 0, (buffer_t)root_files, (uint32_t)4096, disk);
|
||||||
read_cluster(info, info->bpb.root_dir_cluster, (buffer_t)root_files, 4096, disk);
|
read_cluster(info, info->bpb.root_dir_cluster, (buffer_t)root_files, info->bpb.sectors_per_cluster * 512, disk);
|
||||||
uint32_t index = 0;
|
uint32_t index = 0;
|
||||||
while(root_files[index].filename[0]){
|
while(root_files[index].filename[0]){
|
||||||
index++;
|
index++;
|
||||||
|
|
@ -231,6 +231,8 @@ int detect_repair_fs(FILE *file, fat_info *info){
|
||||||
info->file_table = calloc(info->bpb.sectors_per_fat * info->bpb.fat_count * info->bpb.bytes_per_sector, 1);
|
info->file_table = calloc(info->bpb.sectors_per_fat * info->bpb.fat_count * info->bpb.bytes_per_sector, 1);
|
||||||
read_sector(file, info->bpb.reserved_sectors, info->bpb.sectors_per_fat * info->bpb.fat_count, (buffer_t)info->file_table);
|
read_sector(file, info->bpb.reserved_sectors, info->bpb.sectors_per_fat * info->bpb.fat_count, (buffer_t)info->file_table);
|
||||||
if(!info->file_table[info->bpb.root_dir_cluster]){
|
if(!info->file_table[info->bpb.root_dir_cluster]){
|
||||||
|
info->file_table[0] = -1;
|
||||||
|
info->file_table[1] = -1;
|
||||||
info->file_table[info->bpb.root_dir_cluster] = -1;
|
info->file_table[info->bpb.root_dir_cluster] = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -272,11 +274,11 @@ int main(int argc, char **argv){
|
||||||
files[filec++] = argv[i];
|
files[filec++] = argv[i];
|
||||||
verbose && printf("IF: %s\n", argv[i]);
|
verbose && printf("IF: %s\n", argv[i]);
|
||||||
}
|
}
|
||||||
if(filec == 0){
|
|
||||||
printf("Nothing to do, no files to write\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
detect_repair_fs(output_file, &info);
|
detect_repair_fs(output_file, &info);
|
||||||
|
// if(filec == 0){
|
||||||
|
// printf("Nothing to do, no files to write\n");
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
for(int i = 0; i < filec; i++){
|
for(int i = 0; i < filec; i++){
|
||||||
printf("\033[1;34mWriting file %d in list: %s\033[0m\n", i, files[i]);
|
printf("\033[1;34mWriting file %d in list: %s\033[0m\n", i, files[i]);
|
||||||
FILE *f = fopen(files[i], "r");
|
FILE *f = fopen(files[i], "r");
|
||||||
|
|
@ -288,8 +290,8 @@ int main(int argc, char **argv){
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
if(list_root_dir){
|
if(list_root_dir){
|
||||||
buffer_t buf = calloc(4096, 1);
|
buffer_t buf = calloc(info.bpb.sectors_per_cluster * 512, 1);
|
||||||
read_cluster(&info, 2, buf, 4096, output_file);
|
read_cluster(&info, 2, buf, info.bpb.sectors_per_cluster * 512, output_file);
|
||||||
file_t *root = (void *)buf;
|
file_t *root = (void *)buf;
|
||||||
uint32_t index = 0;
|
uint32_t index = 0;
|
||||||
while(root[index].filename[0]){
|
while(root[index].filename[0]){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue