Add basic ls
This commit is contained in:
+1
-1
@@ -56,7 +56,7 @@ void kernel_main() {
|
||||
kernel->stdin = keyboard_init();
|
||||
kernel->stdout = vga_init();
|
||||
|
||||
fs_node_t *bin = fs_open_by(kernel->root, "terminal");
|
||||
fs_node_t *bin = path_open_file(kernel->root, kernel->cwd, "bin/terminal");
|
||||
|
||||
ASSERT(bin, "kernel: terminal not found");
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ syscall_entry:
|
||||
push r14
|
||||
push r15
|
||||
|
||||
mov r8, r10 ; arg4
|
||||
mov rcx, rdx ; arg3
|
||||
mov rdx, rsi ; arg2
|
||||
mov rsi, rdi ; arg1
|
||||
|
||||
+28
-1
@@ -145,11 +145,36 @@ static uint64_t spawn(const char *path, uint64_t argc, const char **argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint64_t readdir(const char *path, uint64_t index, uint64_t max, char *to) {
|
||||
fs_node_t *dir = path_open_directory(current_process->root, current_process->cwd, path);
|
||||
if (!dir) {
|
||||
return (uint64_t)-1;
|
||||
}
|
||||
fs_node_t *item = fs_open_at(dir, index);
|
||||
if (!item) {
|
||||
if (dir != current_process->root) {
|
||||
fs_close(dir);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
uint64_t length = string_length(item->name);
|
||||
uint64_t size = length > max - 1 ? max - 1 : length;
|
||||
memory_copy(item->name, size, to);
|
||||
to[size] = '\0';
|
||||
|
||||
fs_close(item);
|
||||
if (dir != current_process->root) {
|
||||
fs_close(dir);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
static void exit() {
|
||||
process_switch_to(¤t_process->kernel_rsp, current_process->parent->kernel_rsp, VIRT_TO_PHYS(current_process->parent->pml4));
|
||||
}
|
||||
|
||||
uint64_t syscall_dispatch(uint64_t func, uint64_t arg1, uint64_t arg2, uint64_t arg3) {
|
||||
uint64_t syscall_dispatch(uint64_t func, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4) {
|
||||
switch (func) {
|
||||
case SYSCALL_READ:
|
||||
return read(arg1, arg2, (char *)arg3);
|
||||
@@ -161,6 +186,8 @@ uint64_t syscall_dispatch(uint64_t func, uint64_t arg1, uint64_t arg2, uint64_t
|
||||
return chdir((const char *)arg1);
|
||||
case SYSCALL_SPAWN:
|
||||
return spawn((const char *)arg1, arg2, (const char **)arg3);
|
||||
case SYSCALL_READDIR:
|
||||
return readdir((const char *)arg1, arg2, arg3, (char *)arg4);
|
||||
case SYSCALL_EXIT:
|
||||
exit();
|
||||
return 0;
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
#define SYSCALL_GETCWD 2
|
||||
#define SYSCALL_CHDIR 3
|
||||
#define SYSCALL_SPAWN 4
|
||||
#define SYSCALL_READDIR 5
|
||||
#define SYSCALL_EXIT 60
|
||||
|
||||
void syscall_init();
|
||||
|
||||
uint64_t syscall_dispatch(uint64_t func, uint64_t arg1, uint64_t arg2, uint64_t arg3);
|
||||
uint64_t syscall_dispatch(uint64_t func, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4);
|
||||
|
||||
Reference in New Issue
Block a user