Compare commits

..

No commits in common. "817995394b9d9054c89c8bb78b2ab4186ebfad69" and "f437724cb1f374ff3644a724eec28b04354d15de" have entirely different histories.

9 changed files with 19 additions and 98 deletions

View File

@ -21,16 +21,13 @@ bits 16
;Load part2 |x| ;Load part2 |x|
;Get video mode information |0| ;Get video mode information |0|
;Set video mode |0| ;Set video mode |0|
;get memory map |x| ;get memory map |0|
;enable paging |x| ;enable paging |0|
;read filesystem |x| ;read filesystem |0|
;load kernel |x| ;load kernel |0|
;parse ELF format |x| ;parse ELF format |0|
;pass memory and video information to kernel|x| ;pass memory and video information to kernel|0|
;relocate and jump to kernel |x| ;relocate and jump to kernel |0|
;TODO 7/4/26
;Remember to ZERO THE BSS
jump: jump:
jmp short start jmp short start

View File

@ -83,10 +83,6 @@ void vprintf(char *string, va_list vars){
num = va_arg(vars, int32_t); num = va_arg(vars, int32_t);
printf((char[]){num, 0}); printf((char[]){num, 0});
continue; continue;
case 'b':
string++;
num = va_arg(vars, int32_t);
printf(num ? "true" : "false");
} }
} }
outb(com_ports[0], *string); outb(com_ports[0], *string);

View File

@ -57,7 +57,7 @@ extern void kmain(kernel_info_t *kernel_info){
pic_init(0x20); pic_init(0x20);
pic_setmask(0x0, PIC1_DATA); pic_setmask(0x0, PIC1_DATA);
pic_setmask(0x0, PIC2_DATA); pic_setmask(0x0, PIC2_DATA);
vfs_init();
fcreate("/dev", FS_FILE_IS_DIR); fcreate("/dev", FS_FILE_IS_DIR);
fcreate("/dev/disk", FS_FILE_IS_DIR); fcreate("/dev/disk", FS_FILE_IS_DIR);
fcreate("/tmp", FS_FILE_IS_DIR); fcreate("/tmp", FS_FILE_IS_DIR);

View File

@ -4,12 +4,6 @@
#include "../drivers/serial.h" #include "../drivers/serial.h"
#include "interrupts.h" #include "interrupts.h"
#define true 1
#define false 0
#define null 0
#define MLOG_DEBUG 1 #define MLOG_DEBUG 1
#define MLOG_PRINT 2 #define MLOG_PRINT 2
#define MLOG_WARN 3 #define MLOG_WARN 3

View File

@ -1,13 +0,0 @@
#include <stdatomic.h>
typedef struct spinlock{
atomic_flag lock;
}spinlock_t;
inline void spinlock_acquire(spinlock_t spinlock){
// atomic_compare_exchange_strong(&spinlock.lock, &spinlock.unlocked, spinlock.locked);
while(atomic_flag_test_and_set_explicit(&spinlock.lock, memory_order_acquire));
}
inline void spinlock_release(spinlock_t spinlock){
atomic_flag_clear_explicit(&spinlock.lock, memory_order_release);
}

View File

@ -3,7 +3,7 @@
#include "../shared/kstdlib.h" #include "../shared/kstdlib.h"
#include "../shared/memory.h" #include "../shared/memory.h"
#include "../shared/string.h" #include "../shared/string.h"
#define MODULE_NAME "RAMFS" #define MODULE_NAME "KVFS"
fileops_t ramfs_ops = fileops_t ramfs_ops =
{ {
@ -21,22 +21,16 @@ vfile_t root_dir = {"/", FS_FILE_IS_DIR | FS_FILE_SYSTEM, &ramfs_ops};
void ramfs_init(){ void ramfs_init(){
mlog(MODULE_NAME, "Initializing VFS\n", MLOG_PRINT); mlog(MODULE_NAME, "Initializing VFS\n", MLOG_PRINT);
root_dir.private = kmalloc(1); root_dir.private = kmalloc(1);
root_dir.size = PAGE_SIZE_BYTES; root_dir.size = PAGE_SIZE_BYTES;//one page is 4096 bytes
// printf("Sizeof VFILE_T: %d", sizeof(vfile_t)); // printf("Sizeof VFILE_T: %d", sizeof(vfile_t));
} }
vfile_t *search_dir(char *subname, vfile_t *directory){ vfile_t *search_dir(char *subname, vfile_t *directory){
vfile_t **children = (vfile_t **)directory->private;
for(int i = 0; i < directory->size / sizeof(vfile_t *); i++){
if(!strcmp(children[i], subname)){
return children[i];
}
}
return 0;
} }
//resolves the path relative to start //resolves the path relative to start
vfile_t *resolve_path(char *pathname, vfile_t *start, uint32_t get_last_child){ vfile_t *resolve_path(char *pathname, vfile_t *start){
const uint32_t MAX_TOKENS = PAGE_SIZE_BYTES/4; const uint32_t MAX_TOKENS = PAGE_SIZE_BYTES/4;
if(!start){ if(!start){
@ -63,52 +57,19 @@ vfile_t *resolve_path(char *pathname, vfile_t *start, uint32_t get_last_child){
path_tokens[pathname_entries++] = pathtok; path_tokens[pathname_entries++] = pathtok;
} }
// vfile_t **buffer = (vfile_t **)start->private; vfile_t **buffer = (vfile_t **)start->private;
printf("START\n");
vfile_t *entry = start; vfile_t *entry = start;
char *current_path = pathname; for(int i = 0; i < pathname_entries - 1; i++){
for(int i = 0; i < pathname_entries - !get_last_child; i++){ printf("%s", path_tokens[i]);
entry = search_dir(path_tokens[i], entry);
current_path += strlen(path_tokens[i]) + 1;
if(!entry){
break;
} }
if(entry->flags & FS_FILE_MOUNT){ printf("END\n");
if(!get_last_child){
entry = 0;
break;
}
entry->fileops->rfopen(current_path, entry);
}
}
kfree(path);
kfree(path_tokens);
return entry;
} }
char *get_filename(char *path){
char *filename = path + strlen(path) - 1;//get last character in pathname
while(*filename != '/' || filename == path) filename--;
filename += filename != path;//if the new filename is at the beginning of the path, don't adjust for '/' character
return filename;
}
void ramfs_resize(vfile_t *file, uint32_t new_size_bytes){
if(new_size_bytes == file->size) return;
uint32_t new_size_pages = (new_size_bytes + PAGE_SIZE_BYTES - 1)/PAGE_SIZE_BYTES;
printf("New page count: %d from %d\n", new_size_pages, new_size_bytes);
}
vfile_t *ramfs_create(char *path, FS_FILE_FLAGS flags){ vfile_t *ramfs_create(char *path, FS_FILE_FLAGS flags){
if(!path){ resolve_path("test/test1/test2", &root_dir);
return 0;
}
vfile_t *parent = resolve_path(path, &root_dir, false);
if(!parent){
mlog(MODULE_NAME, "Could not locate parent directory for %s\n", MLOG_PRINT, path);
}
get_filename(path);
ramfs_resize(parent, 8191);
return 0; return 0;
} }

View File

@ -3,7 +3,6 @@
#include "../shared/kstdlib.h" #include "../shared/kstdlib.h"
#include "../shared/memory.h" #include "../shared/memory.h"
#include "../shared/string.h" #include "../shared/string.h"
#include "../shared/spinlock.h"
#define MODULE_NAME "KVFS" #define MODULE_NAME "KVFS"
// !TODO: Modify code to become thread-safe // !TODO: Modify code to become thread-safe
@ -14,17 +13,9 @@
// return; // return;
// } // }
spinlock_t vfs_lock;
void vfs_init(){
spinlock_release(vfs_lock);
}
vfile_t *fcreate(char *path, FS_FILE_FLAGS flags){ vfile_t *fcreate(char *path, FS_FILE_FLAGS flags){
// return 0; // return 0;
spinlock_acquire(vfs_lock);
vfile_t *returnable = vfcreate(get_root_dir(), path, flags); vfile_t *returnable = vfcreate(get_root_dir(), path, flags);
spinlock_release(vfs_lock);
return 0; return 0;
} }
@ -69,11 +60,9 @@ vfile_t *vfcreate(vfile_t *parent_dir, char *relpath, FS_FILE_FLAGS flags){
} }
int fdelete(vfile_t *file_entry){ int fdelete(vfile_t *file_entry){
spinlock_acquire(vfs_lock);
if(!file_entry || !file_entry->fileops || !file_entry->fileops->delete){ if(!file_entry || !file_entry->fileops || !file_entry->fileops->delete){
return 0; return 0;
} }
spinlock_release(vfs_lock);
return file_entry->fileops->delete(file_entry); return file_entry->fileops->delete(file_entry);
} }

View File

@ -37,8 +37,6 @@ typedef struct virtual_file{
}vfile_t; }vfile_t;
void vfs_init();
// vfile_t *rfopen(char *name, vfile_t dir); // vfile_t *rfopen(char *name, vfile_t dir);
vfile_t *fcreate(char *path, FS_FILE_FLAGS flags); vfile_t *fcreate(char *path, FS_FILE_FLAGS flags);
int fdelete(vfile_t* file_entry); int fdelete(vfile_t* file_entry);

View File

@ -379,8 +379,7 @@ int ata_read(vfile_t *file, uint8_t *ptr, uint32_t offset, uint32_t count) {
transferring_pid = cpid; transferring_pid = cpid;
outb(bm_base, 0x09); outb(bm_base, 0x09);
// asm("sti"); // TODO: Make it so that instead of sti(), restore interrupt flag asm("sti");
if(!api(MODULE_API_IS_INTERRUPT)) asm("sti");
uint8_t status = inb(ctrl_base); uint8_t status = inb(ctrl_base);
uint8_t bm_status = inb(bm_base + 2); uint8_t bm_status = inb(bm_base + 2);