Compare commits
4 Commits
f437724cb1
...
817995394b
| Author | SHA1 | Date |
|---|---|---|
|
|
817995394b | |
|
|
c5c9782535 | |
|
|
3b42ce5386 | |
|
|
02b5c8890a |
|
|
@ -21,13 +21,16 @@ 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 |0|
|
;get memory map |x|
|
||||||
;enable paging |0|
|
;enable paging |x|
|
||||||
;read filesystem |0|
|
;read filesystem |x|
|
||||||
;load kernel |0|
|
;load kernel |x|
|
||||||
;parse ELF format |0|
|
;parse ELF format |x|
|
||||||
;pass memory and video information to kernel|0|
|
;pass memory and video information to kernel|x|
|
||||||
;relocate and jump to kernel |0|
|
;relocate and jump to kernel |x|
|
||||||
|
|
||||||
|
;TODO 7/4/26
|
||||||
|
;Remember to ZERO THE BSS
|
||||||
|
|
||||||
jump:
|
jump:
|
||||||
jmp short start
|
jmp short start
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,10 @@ 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);
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,12 @@
|
||||||
#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
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
@ -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 "KVFS"
|
#define MODULE_NAME "RAMFS"
|
||||||
|
|
||||||
fileops_t ramfs_ops =
|
fileops_t ramfs_ops =
|
||||||
{
|
{
|
||||||
|
|
@ -21,16 +21,22 @@ 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;//one page is 4096 bytes
|
root_dir.size = PAGE_SIZE_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){
|
vfile_t *resolve_path(char *pathname, vfile_t *start, uint32_t get_last_child){
|
||||||
const uint32_t MAX_TOKENS = PAGE_SIZE_BYTES/4;
|
const uint32_t MAX_TOKENS = PAGE_SIZE_BYTES/4;
|
||||||
|
|
||||||
if(!start){
|
if(!start){
|
||||||
|
|
@ -57,19 +63,52 @@ vfile_t *resolve_path(char *pathname, vfile_t *start){
|
||||||
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;
|
||||||
for(int i = 0; i < pathname_entries - 1; i++){
|
char *current_path = pathname;
|
||||||
printf("%s", path_tokens[i]);
|
for(int i = 0; i < pathname_entries - !get_last_child; i++){
|
||||||
|
entry = search_dir(path_tokens[i], entry);
|
||||||
|
current_path += strlen(path_tokens[i]) + 1;
|
||||||
|
|
||||||
|
if(!entry){
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
printf("END\n");
|
if(entry->flags & FS_FILE_MOUNT){
|
||||||
|
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){
|
||||||
resolve_path("test/test1/test2", &root_dir);
|
if(!path){
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +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"
|
||||||
|
#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
|
||||||
|
|
@ -13,9 +14,17 @@
|
||||||
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,9 +69,11 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ 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);
|
||||||
|
|
|
||||||
|
|
@ -379,7 +379,8 @@ 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");
|
// asm("sti"); // TODO: Make it so that instead of sti(), restore interrupt flag
|
||||||
|
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);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue