aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md6
-rw-r--r--src/kernel/fs/dev.c12
-rw-r--r--src/kernel/fs/ext2.c37
-rw-r--r--src/kernel/fs/ext2.h1
-rw-r--r--src/kernel/fs/vfs.c5
-rw-r--r--src/kernel/graphics/vesa.c10
-rw-r--r--src/kernel/kernel.c6
-rw-r--r--src/kernel/memory/paging.c3
-rw-r--r--src/kernel/syscall/actions/sys_fork.c1
-rw-r--r--src/kernel/syscall/actions/sys_read.c8
-rw-r--r--src/kernel/syscall/actions/sys_write.c9
-rw-r--r--src/kernel/syscall/syscall.c5
-rw-r--r--src/userspace/libc/unistd.h4
-rw-r--r--src/userspace/libc/unistd/read.c2
-rw-r--r--src/userspace/libc/unistd/write.c2
-rw-r--r--src/userspace/programs/init.c7
-rw-r--r--src/userspace/programs/sh.c2
17 files changed, 68 insertions, 52 deletions
diff --git a/README.md b/README.md
index b4ae13b..ee4a004 100644
--- a/README.md
+++ b/README.md
@@ -40,10 +40,10 @@
Melvix is released under the MIT License and uses parts of the following 3rd party projects:
Knowledge:
-* [virtix - FS inspiration](https://github.com/16Bitt/virtix/) - [MIT License](https://github.com/16Bitt/virtix/blob/85a3c58f3d3b8932354e85a996a79c377139c201/LICENSE)
-* [studix - memory inspiration](https://github.com/orodley/studix) - [MIT License](https://github.com/orodley/studix/blob/d1b1d006010120551df58ff3faaf97484dfa9806/LICENSE)
-* [James Molloy's tutorials](http://jamesmolloy.co.uk/tutorial_html/)
* [OSDev wiki](https://wiki.osdev.org) - Very helpful!
+* [James Molloy's tutorials](http://jamesmolloy.co.uk/tutorial_html/)
+* [virtix - memory + tasking inspiration](https://github.com/16Bitt/virtix/) - [MIT License](https://github.com/16Bitt/virtix/blob/85a3c58f3d3b8932354e85a996a79c377139c201/LICENSE)
+* [studix - FS inspiration](https://github.com/orodley/studix) - [MIT License](https://github.com/orodley/studix/blob/d1b1d006010120551df58ff3faaf97484dfa9806/LICENSE)
Resources:
* [Spleen font](https://github.com/fcambus/spleen) - [MIT License](https://github.com/fcambus/spleen/blob/5759e9abb130b89ba192edc5324b12ef07b7dad3/LICENSE)
diff --git a/src/kernel/fs/dev.c b/src/kernel/fs/dev.c
index 968dcfe..52d8e01 100644
--- a/src/kernel/fs/dev.c
+++ b/src/kernel/fs/dev.c
@@ -12,14 +12,14 @@ void dev_make(char *name, read read, write write)
{
struct fs_node *dev_node = (struct fs_node *)kmalloc(sizeof(struct fs_node));
strcpy(dev_node->name, "/dev");
- ext2_root->open(dev_node);
+ fs_open(dev_node);
if (dev_node->inode == 0) {
warn("Can't make device, no path for /dev");
return;
}
- ext2_root->close(dev_node);
+ fs_close(dev_node);
char *path = (char *)kmalloc(strlen(name) + strlen("/dev/") + 2);
strcpy(path, "/dev/");
@@ -28,7 +28,7 @@ void dev_make(char *name, read read, write write)
// TODO: Touch dev files in the vfs instead of opening it via ext2
struct fs_node *node = (struct fs_node *)kmalloc(sizeof(struct fs_node));
strcpy(node->name, path);
- ext2_root->open(node);
+ fs_open(node);
kfree(path);
if (node->inode == 0) {
@@ -78,7 +78,7 @@ void dev_stdin()
dev_make("stdout", (read)stdin_read, NULL);
struct fs_node *node = (struct fs_node *)kmalloc(sizeof(struct fs_node));
strcpy(node->name, "/dev/stdin");
- ext2_root->open(node);
+ fs_open(node);
node->dev->block_size = 0;
node->length = 0xFFFFFFFF;
}
@@ -94,7 +94,7 @@ void dev_stdout()
dev_make("stdout", NULL, (write)stdout_write);
struct fs_node *node = (struct fs_node *)kmalloc(sizeof(struct fs_node));
strcpy(node->name, "/dev/stdout");
- ext2_root->open(node);
+ fs_open(node);
node->dev->block_size = 0;
}
@@ -109,6 +109,6 @@ void dev_stderr()
dev_make("stderr", NULL, (write)stderr_write);
struct fs_node *node = (struct fs_node *)kmalloc(sizeof(struct fs_node));
strcpy(node->name, "/dev/stderr");
- ext2_root->open(node);
+ fs_open(node);
node->dev->block_size = 0;
} \ No newline at end of file
diff --git a/src/kernel/fs/ext2.c b/src/kernel/fs/ext2.c
index 91e90fb..3956fd4 100644
--- a/src/kernel/fs/ext2.c
+++ b/src/kernel/fs/ext2.c
@@ -265,11 +265,9 @@ void ext2_vfs_open(struct fs_node *node)
if (node->inode != 0) {
struct ext2_file *file = kmalloc(sizeof *file);
+ ext2_node_init(node);
ext2_open_inode(node->inode, file);
-
node->impl = file;
-
- // TODO: More file metadata
}
}
@@ -281,7 +279,7 @@ void ext2_vfs_close(struct fs_node *node)
uint32_t ext2_vfs_read(struct fs_node *node, size_t offset, size_t size, char *buf)
{
if (offset != ((struct ext2_file *)node->impl)->pos) {
- panic("Seeking is currently unsupported for Ext2 files\n");
+ panic("Seeking is currently unsupported for Ext2 files");
return 0;
}
@@ -290,7 +288,7 @@ uint32_t ext2_vfs_read(struct fs_node *node, size_t offset, size_t size, char *b
uint32_t ext2_vfs_write(struct fs_node *node, size_t offset, size_t size, char *buf)
{
- panic("Writing to Ext2 is currently unsupported\n");
+ warn(RED "Writing to Ext2 is currently unsupported" RES);
return 0;
}
@@ -324,6 +322,22 @@ struct fs_node *ext2_vfs_find_dir(struct fs_node *node, char *name)
}
}
+void ext2_node_init(struct fs_node *node)
+{
+ node->permissions = 0;
+ node->uid = 0;
+ node->gid = 0;
+ node->length = 0;
+ node->read = ext2_vfs_read;
+ node->write = ext2_vfs_write;
+ node->open = ext2_vfs_open;
+ node->close = ext2_vfs_close;
+ node->read_dir = ext2_vfs_read_dir;
+ node->find_dir = ext2_vfs_find_dir;
+ node->node_ptr = NULL;
+ node->impl = NULL;
+}
+
void ext2_mount(struct fs_node *mountpoint)
{
assert(mountpoint->node_ptr == NULL && (mountpoint->type & MOUNTPOINT_NODE) == 0);
@@ -331,20 +345,9 @@ void ext2_mount(struct fs_node *mountpoint)
struct fs_node *ext2_root = (struct fs_node *)kmalloc(sizeof(struct fs_node));
strcpy(ext2_root->name, "/.");
- ext2_root->permissions = 0;
- ext2_root->uid = 0;
- ext2_root->gid = 0;
ext2_root->inode = ROOT_INODE;
- ext2_root->length = 0;
ext2_root->type = DIR_NODE;
- ext2_root->read = ext2_vfs_read;
- ext2_root->write = ext2_vfs_write;
- ext2_root->open = ext2_vfs_open;
- ext2_root->close = ext2_vfs_close;
- ext2_root->read_dir = ext2_vfs_read_dir;
- ext2_root->find_dir = ext2_vfs_find_dir;
- ext2_root->node_ptr = NULL;
- ext2_root->impl = NULL;
+ ext2_node_init(ext2_root);
mountpoint->type |= MOUNTPOINT_NODE;
mountpoint->node_ptr = ext2_root;
diff --git a/src/kernel/fs/ext2.h b/src/kernel/fs/ext2.h
index 1e89c27..f98531e 100644
--- a/src/kernel/fs/ext2.h
+++ b/src/kernel/fs/ext2.h
@@ -141,6 +141,7 @@ uint32_t ext2_find_in_dir(uint32_t dir_inode, const char *name);
uint32_t ext2_look_up_path(char *path);
uint8_t *read_file(char *path);
+void ext2_node_init(struct fs_node *node);
void ext2_mount(struct fs_node *mountpoint);
#endif \ No newline at end of file
diff --git a/src/kernel/fs/vfs.c b/src/kernel/fs/vfs.c
index fd44f30..2b4cda4 100644
--- a/src/kernel/fs/vfs.c
+++ b/src/kernel/fs/vfs.c
@@ -1,6 +1,7 @@
#include <stdint.h>
#include <stddef.h>
#include <kernel/fs/vfs.h>
+#include <kernel/fs/ext2.h>
#include <kernel/lib/stdlib.h>
struct fs_node *fs_root = NULL;
@@ -25,12 +26,16 @@ void fs_open(struct fs_node *node)
{
if (node->open != NULL)
node->open(node);
+ else // TODO: Better ext2 default open workaround
+ ext2_root->open(node);
}
void fs_close(struct fs_node *node)
{
if (node->close != NULL)
node->close(node);
+ else
+ ext2_root->open(node);
}
struct dirent *fs_read_dir(struct fs_node *node, uint32_t index)
diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c
index c6c828b..1e8c9c1 100644
--- a/src/kernel/graphics/vesa.c
+++ b/src/kernel/graphics/vesa.c
@@ -6,7 +6,6 @@
#include <kernel/memory/alloc.h>
#include <kernel/memory/paging.h>
#include <kernel/fs/dev.h>
-#include <kernel/fs/ext2.h>
void vbe_error()
{
@@ -179,10 +178,11 @@ void set_optimal_resolution()
}
dev_make("fb", NULL, (write)fb_write);
- struct fs_node *node = (struct fs_node *)kmalloc(sizeof(struct fs_node));
- strcpy(node->name, "/dev/fb");
- ext2_root->open(node);
- node->dev->block_size = 0;
+ /* struct fs_node *node = (struct fs_node *)kmalloc(sizeof(struct fs_node)); */
+ /* strcpy(node->name, "/dev/fb"); */
+ /* fs_open(node); */
+ /* node->write = (write)fb_write; */
+ /* node->dev->block_size = 0; */
if (vbe_height > 1440)
vesa_set_font(32);
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index c2f0972..40db307 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -70,13 +70,13 @@ void kernel_main(uint32_t magic, uint32_t multiboot_address, uint32_t esp)
struct fs_node *test = (struct fs_node *)kmalloc(sizeof(struct fs_node));
strcpy(test->name, "/etc/test");
- ext2_root->open(test);
+ fs_open(test);
uint32_t size = ((struct ext2_file *)test->impl)->inode.size;
char buf[size];
- ext2_root->read(test, 0, size, buf);
+ fs_read(test, 0, size, buf);
buf[size - 1] = '\0';
log("Content of /etc/test: %s", buf);
- ext2_root->close(test);
+ fs_close(test);
dev_stdin();
dev_stdout();
diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c
index add400e..f355449 100644
--- a/src/kernel/memory/paging.c
+++ b/src/kernel/memory/paging.c
@@ -88,12 +88,11 @@ void paging_map(struct page_directory *dir, uint32_t phys, uint32_t virt)
short id = virt >> 22;
struct page_table *tab = paging_make_table();
- dir->tables[id] = ((struct page_table *)((uint32_t)tab | 3 | 4)); // RW
+ dir->tables[id] = ((struct page_table *)((uint32_t)tab | 3)); // RW
for (int i = 0; i < 1024; i++) {
tab->pages[i].frame = phys >> 12;
tab->pages[i].present = 1;
- tab->pages[i].user = 1; // TODO: Remove all-user paging!
phys += 4096;
}
}
diff --git a/src/kernel/syscall/actions/sys_fork.c b/src/kernel/syscall/actions/sys_fork.c
index af64ff9..5e2ee80 100644
--- a/src/kernel/syscall/actions/sys_fork.c
+++ b/src/kernel/syscall/actions/sys_fork.c
@@ -3,6 +3,7 @@
#include <kernel/memory/paging.h>
#include <kernel/tasks/process.h>
#include <kernel/lib/lib.h>
+#include <kernel/system.h>
uint32_t sys_fork(struct regs *r)
{
diff --git a/src/kernel/syscall/actions/sys_read.c b/src/kernel/syscall/actions/sys_read.c
index a954f56..8931ede 100644
--- a/src/kernel/syscall/actions/sys_read.c
+++ b/src/kernel/syscall/actions/sys_read.c
@@ -8,15 +8,15 @@ uint32_t sys_read(char *path, uint32_t offset, uint32_t count, char *buf)
{
struct fs_node *node = (struct fs_node *)umalloc(sizeof(struct fs_node));
strcpy(node->name, path);
- ext2_root->open(node);
+ fs_open(node);
if (node->inode != 0) {
uint32_t size = ((struct ext2_file *)node->impl)->inode.size;
- ext2_root->read(node, 0, size, buf);
+ fs_read(node, 0, size, buf);
buf[size - 1] = '\0';
- ext2_root->close(node);
+ fs_close(node);
return size;
} else {
- ext2_root->close(node);
+ fs_close(node);
return -1;
}
} \ No newline at end of file
diff --git a/src/kernel/syscall/actions/sys_write.c b/src/kernel/syscall/actions/sys_write.c
index d79ef37..28a5929 100644
--- a/src/kernel/syscall/actions/sys_write.c
+++ b/src/kernel/syscall/actions/sys_write.c
@@ -3,20 +3,21 @@
#include <kernel/fs/ext2.h>
#include <kernel/lib/stdlib.h>
#include <kernel/memory/alloc.h>
+#include <kernel/system.h>
uint32_t sys_write(char *path, uint32_t offset, uint32_t count, char *buf)
{
struct fs_node *node = (struct fs_node *)umalloc(sizeof(struct fs_node));
strcpy(node->name, path);
- ext2_root->open(node);
+ fs_open(node);
if (node->inode != 0) {
uint32_t size = ((struct ext2_file *)node->impl)->inode.size;
- ext2_root->write(node, 0, size, buf);
+ fs_write(node, 0, size, buf);
buf[size - 1] = '\0';
- ext2_root->close(node);
+ fs_close(node);
return size;
} else {
- ext2_root->close(node);
+ fs_close(node);
return -1;
}
} \ No newline at end of file
diff --git a/src/kernel/syscall/syscall.c b/src/kernel/syscall/syscall.c
index d09ee33..53f94cd 100644
--- a/src/kernel/syscall/syscall.c
+++ b/src/kernel/syscall/syscall.c
@@ -32,7 +32,10 @@ void syscall_handler(struct regs *r)
log("[SYSCALL] %d at [0x%x] with 0x%x 0x%x 0x%x 0x%x", r->eax, location, r->ebx, r->ecx,
r->edx, r->esi, r->edi);
- r->eax = location(r->ebx, r->ecx, r->edx, r->esi, r->edi);
+ if (r->eax == 2) // TODO: Fix hardcoded fork parameters
+ r->eax = location(r);
+ else
+ r->eax = location(r->ebx, r->ecx, r->edx, r->esi, r->edi);
sti();
}
diff --git a/src/userspace/libc/unistd.h b/src/userspace/libc/unistd.h
index e8b97be..f9644f1 100644
--- a/src/userspace/libc/unistd.h
+++ b/src/userspace/libc/unistd.h
@@ -11,8 +11,8 @@ u32 fork();
u32 get_pid();
-u32 sys_read(char *path, u32 offset, u32 count, char *buf);
+u32 read(char *path, u32 offset, u32 count, char *buf);
-u32 sys_write(char *path, u32 offset, u32 count, char *buf);
+u32 write(char *path, u32 offset, u32 count, char *buf);
#endif \ No newline at end of file
diff --git a/src/userspace/libc/unistd/read.c b/src/userspace/libc/unistd/read.c
index c01baa7..0f8b914 100644
--- a/src/userspace/libc/unistd/read.c
+++ b/src/userspace/libc/unistd/read.c
@@ -1,7 +1,7 @@
#include <stdint.h>
#include <syscall.h>
-u32 sys_read(char *path, u32 offset, u32 count, char *buf)
+u32 read(char *path, u32 offset, u32 count, char *buf)
{
return syscall_read(path, offset, count, buf);
} \ No newline at end of file
diff --git a/src/userspace/libc/unistd/write.c b/src/userspace/libc/unistd/write.c
index c3eec3d..7cae9cd 100644
--- a/src/userspace/libc/unistd/write.c
+++ b/src/userspace/libc/unistd/write.c
@@ -1,7 +1,7 @@
#include <stdint.h>
#include <syscall.h>
-u32 sys_write(char *path, u32 offset, u32 count, char *buf)
+u32 write(char *path, u32 offset, u32 count, char *buf)
{
return syscall_write(path, offset, count, buf);
} \ No newline at end of file
diff --git a/src/userspace/programs/init.c b/src/userspace/programs/init.c
index 4127e19..732c104 100644
--- a/src/userspace/programs/init.c
+++ b/src/userspace/programs/init.c
@@ -1,13 +1,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <syscall.h>
+#include <unistd.h>
#include <gui.h>
void main()
{
- gui_init();
- gui_screen_clear();
- printf("Initializing userspace...\n");
+ /* gui_init(); */
+ /* gui_screen_clear(); */
+ //printf("Initializing userspace...\n");
syscall_exec("/bin/sh");
while (1) {
diff --git a/src/userspace/programs/sh.c b/src/userspace/programs/sh.c
index 6913e05..f22a528 100644
--- a/src/userspace/programs/sh.c
+++ b/src/userspace/programs/sh.c
@@ -1,9 +1,11 @@
#include <stdio.h>
+#include <unistd.h>
#include <syscall.h>
#include <gui.h>
void main()
{
+ write("/dev/fb", 0, 5, "hallo");
printf("[~] ");
while (1) {