diff --git a/kernel/src/fs/vfs.h b/kernel/src/fs/vfs.h new file mode 100644 index 0000000..9a58668 --- /dev/null +++ b/kernel/src/fs/vfs.h @@ -0,0 +1,37 @@ +#pragma once + +#include +#include + +struct vnode; + +#define VN_FILE 1 +#define VN_DIR 2 + +typedef uint32_t vnode_type_t; + +typedef struct vnode_ops { + int (*read)(struct vnode* vn, void* buf, size_t size); +} vnode_ops_t; + +typedef struct vnode { + char name[256]; + vnode_type_t type; + struct vnode* parent; + struct vnode* child; + struct vnode* next; + + struct vnode_ops* ops; + void* internal; +} vnode_t; + +typedef struct fs { + char name[32]; + int (*mount)(struct vnode** root); +} fs_t; + +void vfs_init(void); +int vfs_mount(char *path, fs_t* fs); +int vfs_unmount(char *path); +int vfs_open(const char* path, vnode_t** result); +int vfs_read(vnode_t* vn, void* buf, size_t size); diff --git a/kernel/src/lib/string.c b/kernel/src/lib/string.c index 216e6dd..1e39b6a 100644 --- a/kernel/src/lib/string.c +++ b/kernel/src/lib/string.c @@ -1,4 +1,5 @@ #include +#include #include int strlen(const char *str) { @@ -16,14 +17,14 @@ int strcmp(const char *s1, const char *s2) { return *s1 - *s2; } -char *strcpy(char *dest, const char *src) -{ - if (dest == NULL || src == NULL) - return NULL; - - char *temp = dest; - while((*dest++ = *src++) != '\0'); - return temp; +char *strcpy(char *dest, const char *src) { + if (dest == NULL || src == NULL) + return NULL; + + char *temp = dest; + while ((*dest++ = *src++) != '\0') + ; + return temp; } char *strchr(const char *s, int c) { @@ -35,23 +36,36 @@ char *strchr(const char *s, int c) { } char *strrchr(const char *s, int c) { - const char *p = NULL; + const char *p = NULL; - for (;;) { - if (*s == (char)c) - p = s; - if (*s++ == '\0') - return (char *)p; - } + for (;;) { + if (*s == (char)c) + p = s; + if (*s++ == '\0') + return (char *)p; + } } int oct2bin(unsigned char *str, int size) { - int n = 0; - unsigned char *c = str; - while (size-- > 0) { - n *= 8; - n += *c - '0'; - c++; - } - return n; + int n = 0; + unsigned char *c = str; + while (size-- > 0) { + n *= 8; + n += *c - '0'; + c++; + } + return n; +} + +char *strdup(const char *str) { + if (str == NULL) + return NULL; + + int len = strlen(str); + char *dup = (char *)malloc(len + 1); + if (dup == NULL) + return NULL; + + strcpy(dup, str); + return dup; } \ No newline at end of file diff --git a/kernel/src/lib/string.h b/kernel/src/lib/string.h index da1cdd6..ecfd14d 100644 --- a/kernel/src/lib/string.h +++ b/kernel/src/lib/string.h @@ -5,4 +5,5 @@ int strcmp(const char *s1, const char *s2); char *strchr(const char *s, int c); char *strcpy(char *dest, const char *src); char *strrchr(const char *s, int c); -int oct2bin(unsigned char *str, int size); \ No newline at end of file +int oct2bin(unsigned char *str, int size); +char *strdup(const char *str); \ No newline at end of file diff --git a/kernel/src/main.c b/kernel/src/main.c index 6e60f5a..4e122bd 100644 --- a/kernel/src/main.c +++ b/kernel/src/main.c @@ -18,11 +18,13 @@ #include #include #include -#include +#include #include #include #include #include +#include +#include __attribute__(( used, section(".limine_requests"))) static volatile LIMINE_BASE_REVISION(3); @@ -84,12 +86,22 @@ void kmain(void) { while (1) asm("hlt"); } - + syscall_init(); pit_init(1000); sched_init(); + + vfs_init(); + if (hellofs_init() < 0) { + log("kernel - Failed to initialize HelloFS\n"); + } else { + log("kernel - HelloFS initialized successfully\n"); + } - panic("No working initialization program found. (This is normal due to Soaplin's current state, so please do not report this as a bug)"); + + + panic("No working initialization program found. (This is normal due to " + "Soaplin's current state, so please do not report this as a bug)"); log("kernel - Soaplin initialized sucessfully.\n"); diff --git a/kernel/src/sys/arch/x86_64/rtc.c b/kernel/src/sys/arch/x86_64/rtc.c index c5468d8..7836045 100644 --- a/kernel/src/sys/arch/x86_64/rtc.c +++ b/kernel/src/sys/arch/x86_64/rtc.c @@ -4,38 +4,40 @@ char bcd; unsigned char read_register(unsigned char reg) { - __asm__ volatile("cli"); - outb(RTC_COMMAND, reg); - return inb(RTC_DATA); - __asm__ volatile("sti"); + __asm__ volatile("cli"); + outb(RTC_COMMAND, reg); + return inb(RTC_DATA); + __asm__ volatile("sti"); } void write_register(unsigned char reg, unsigned char value) { - __asm__ volatile("cli"); - outb(RTC_COMMAND, reg); - outb(RTC_DATA, value); - __asm__ volatile("sti"); + __asm__ volatile("cli"); + outb(RTC_COMMAND, reg); + outb(RTC_DATA, value); + __asm__ volatile("sti"); } unsigned char bcd2bin(unsigned char in_bcd) { - return (bcd) ? ((in_bcd >> 4) * 10) + (in_bcd & 0x0F) : in_bcd; + return (bcd) ? ((in_bcd >> 4) * 10) + (in_bcd & 0x0F) : in_bcd; } int rtc_init() { - __asm__ volatile("cli"); - unsigned char status; - status = read_register(RTC_STATUS); - status |= 0x02; // 24 hour clock - status |= 0x10; // update ended interrupts - status &= ~0x20; // no alarm interrupts - status &= ~0x40; // no periodic interrupt - bcd = !(status & 0x04); // check if data type is BCD - write_register(RTC_STATUS, status); + __asm__ volatile("cli"); + unsigned char status; + status = read_register(RTC_STATUS); + status |= 0x02; // 24 hour clock + status |= 0x10; // update ended interrupts + status &= ~0x20; // no alarm interrupts + status &= ~0x40; // no periodic interrupt + bcd = !(status & 0x04); // check if data type is BCD + write_register(RTC_STATUS, status); - outb(0x70, 0x8B); // select register B, and disable NMI - char prev=inb(0x71); // read the current value of register B - outb(0x70, 0x8B); // set the index again (a read will reset the index to register D) - outb(0x71, prev | 0x40); // write the previous value ORed with 0x40. This turns on bit 6 of register B - __asm__ volatile("sti"); - return 0; + outb(0x70, 0x8B); // select register B, and disable NMI + char prev = inb(0x71); // read the current value of register B + outb(0x70, + 0x8B); // set the index again (a read will reset the index to register D) + outb(0x71, prev | 0x40); // write the previous value ORed with 0x40. This + // turns on bit 6 of register B + __asm__ volatile("sti"); + return 0; } \ No newline at end of file diff --git a/kernel/src/sys/arch/x86_64/rtc.h b/kernel/src/sys/arch/x86_64/rtc.h old mode 100755 new mode 100644 index 8f34e7e..51fb46c --- a/kernel/src/sys/arch/x86_64/rtc.h +++ b/kernel/src/sys/arch/x86_64/rtc.h @@ -1,17 +1,17 @@ #ifndef __TIME_H #define __TIME_H -#define RTC_COMMAND 0x70 -#define RTC_DATA 0x71 -#define RTC_STATUS 0x0B +#define RTC_COMMAND 0x70 +#define RTC_DATA 0x71 +#define RTC_STATUS 0x0B -#define RTC_SECONDS 0x00 -#define RTC_MINUTES 0x02 -#define RTC_HOURS 0x04 -#define RTC_DAY_OF_WEEK 0x06 -#define RTC_DAY 0x07 -#define RTC_MONTH 0x08 -#define RTC_YEAR 0x09 +#define RTC_SECONDS 0x00 +#define RTC_MINUTES 0x02 +#define RTC_HOURS 0x04 +#define RTC_DAY_OF_WEEK 0x06 +#define RTC_DAY 0x07 +#define RTC_MONTH 0x08 +#define RTC_YEAR 0x09 int rtc_init(); diff --git a/kernel/src/sys/error_handling/panic.c b/kernel/src/sys/errhnd/panic.c similarity index 99% rename from kernel/src/sys/error_handling/panic.c rename to kernel/src/sys/errhnd/panic.c index 095c1bf..8c244e0 100644 --- a/kernel/src/sys/error_handling/panic.c +++ b/kernel/src/sys/errhnd/panic.c @@ -65,10 +65,9 @@ void __panic_display_ascii_art() { "halt the PC.\n"); } - void panic(char *msg) { __panic_display_ascii_art(); - + log("\n"); log("%s\n", msg); log("\n"); diff --git a/kernel/src/sys/error_handling/panic.h b/kernel/src/sys/errhnd/panic.h similarity index 100% rename from kernel/src/sys/error_handling/panic.h rename to kernel/src/sys/errhnd/panic.h