summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/kernel/elf.c1
-rw-r--r--src/kernel/isrs.asm2
-rw-r--r--src/kernel/log.c20
-rw-r--r--src/kernel/log.h7
-rw-r--r--src/kernel/main.c8
-rw-r--r--src/kernel/panic.c2
-rw-r--r--src/kernel/task.c4
-rw-r--r--src/user/hello/hello.c5
-rw-r--r--src/user/include/knob/block.h8
-rw-r--r--src/user/include/knob/file.h2
-rw-r--r--src/user/include/knob/task.h9
-rw-r--r--src/user/include/pland/syscall.h5
-rw-r--r--src/user/init/main.c38
-rw-r--r--src/user/knob/file.c16
-rw-r--r--src/user/knob/task.c13
15 files changed, 90 insertions, 50 deletions
diff --git a/src/kernel/elf.c b/src/kernel/elf.c
index 8cd659c..bd2f12d 100644
--- a/src/kernel/elf.c
+++ b/src/kernel/elf.c
@@ -107,6 +107,7 @@ bool try_elf_run(const struct drive *d, const char *path) {
}
free_pages(phtable, phtable_pages);
+ d->free_file(d, h);
struct task_state tstate;
tstate.page_directory = pd;
diff --git a/src/kernel/isrs.asm b/src/kernel/isrs.asm
index 56f3c12..1fd6fcb 100644
--- a/src/kernel/isrs.asm
+++ b/src/kernel/isrs.asm
@@ -39,7 +39,7 @@ syscall_isr:
quit_isr:
push dword [active_task]
call delete_task
- push yield_isr.return_to_task
+ mov dword [esp], yield_isr.return_to_task
jmp advance_active_task
yield_isr:
diff --git a/src/kernel/log.c b/src/kernel/log.c
index bc8ff84..39fc1ba 100644
--- a/src/kernel/log.c
+++ b/src/kernel/log.c
@@ -1,20 +1,26 @@
#include "vga.h"
#include "serial.h"
+#include "log.h"
-#define INFO_COM COM1
+#define LOG_COM COM1
-void init_log() {
- vga_set_color(0x30);
- vga_blank();
+static const uint8_t log_mode_colors[] = {
+ 0x30,
+ 0x07,
+ 0x4f
+};
+
+void set_log_mode(enum log_mode mode) {
+ vga_set_color(log_mode_colors[mode]);
}
void logch(char ch) {
if (ch == '\n') {
- sout(INFO_COM, (uint8_t)'\r');
- sout(INFO_COM, (uint8_t)'\n');
+ sout(LOG_COM, (uint8_t)'\r');
+ sout(LOG_COM, (uint8_t)'\n');
}
else
- sout(INFO_COM, (uint8_t)ch);
+ sout(LOG_COM, (uint8_t)ch);
vga_printch(ch);
}
diff --git a/src/kernel/log.h b/src/kernel/log.h
index ff2a7a2..90a94f4 100644
--- a/src/kernel/log.h
+++ b/src/kernel/log.h
@@ -1,7 +1,14 @@
#ifndef LOG_H
#define LOG_H
+enum log_mode {
+ LOG_SYSTEM,
+ LOG_USER,
+ LOG_PANIC
+};
+
void init_log();
+void set_log_mode(enum log_mode mode);
void logch(char ch);
void logsz(const char *sz);
diff --git a/src/kernel/main.c b/src/kernel/main.c
index 1fe8e7b..2f63d71 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -10,8 +10,8 @@
#include "pmap.h"
#include "task.h"
#include "pci.h"
-#include "log.h"
#include "elf.h"
+#include "log.h"
#include "vga.h"
void reset_tree();
@@ -27,7 +27,8 @@ void main() {
init_paging();
init_tasks();
init_serial();
- init_log();
+ set_log_mode(LOG_SYSTEM);
+ vga_blank();
logsz("Portland v0.0.11\n\n");
@@ -146,6 +147,7 @@ void main() {
init_idt();
- vga_set_color(0x07);
+ set_log_mode(LOG_USER);
+ logch('\n');
_start_user_mode();
} \ No newline at end of file
diff --git a/src/kernel/panic.c b/src/kernel/panic.c
index 7793065..a2e68e3 100644
--- a/src/kernel/panic.c
+++ b/src/kernel/panic.c
@@ -3,7 +3,7 @@
#include "vga.h"
void panic(const char *message) {
- vga_set_color(0x4f);
+ set_log_mode(LOG_PANIC);
vga_blank();
logsz("Kernel panic: ");
logsz(message);
diff --git a/src/kernel/task.c b/src/kernel/task.c
index c8a8ac8..80818a7 100644
--- a/src/kernel/task.c
+++ b/src/kernel/task.c
@@ -79,7 +79,9 @@ void advance_active_task() {
if (++active_task == tasks + MAX_TASKS)
active_task = tasks;
if (active_task == prev_task) {
- logsz("No active tasks.\nHalting.");
+ logch('\n');
+ set_log_mode(LOG_SYSTEM);
+ logsz("\nNo active tasks, halting.");
while (1)
asm ("hlt");
}
diff --git a/src/user/hello/hello.c b/src/user/hello/hello.c
new file mode 100644
index 0000000..65e23f0
--- /dev/null
+++ b/src/user/hello/hello.c
@@ -0,0 +1,5 @@
+#include <knob/user.h>
+
+void main() {
+ tell_user_sz("\nHello, world!\nThis is a userspace program that has been started by init.");
+} \ No newline at end of file
diff --git a/src/user/include/knob/block.h b/src/user/include/knob/block.h
deleted file mode 100644
index 53b3deb..0000000
--- a/src/user/include/knob/block.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef KNOB_BLOCK_H
-#define KNOB_BLOCK_H
-
-#include <stdint.h>
-
-void blockcpy(void *to, const void *from, uint32_t count);
-
-#endif \ No newline at end of file
diff --git a/src/user/include/knob/file.h b/src/user/include/knob/file.h
index 6068077..4d0da87 100644
--- a/src/user/include/knob/file.h
+++ b/src/user/include/knob/file.h
@@ -5,6 +5,8 @@
struct file;
+const char *remove_prefix(const char *path, uint8_t *dn_out);
+
struct file *open_file(const char *path);
void close_file(struct file *f);
diff --git a/src/user/include/knob/task.h b/src/user/include/knob/task.h
new file mode 100644
index 0000000..ea5df62
--- /dev/null
+++ b/src/user/include/knob/task.h
@@ -0,0 +1,9 @@
+#ifndef KNOB_TASK_H
+#define KNOB_TASK_H
+
+#include <stdbool.h>
+
+bool try_run_command(const char *path);
+void yield_task();
+
+#endif \ No newline at end of file
diff --git a/src/user/include/pland/syscall.h b/src/user/include/pland/syscall.h
index 01f7151..5858d16 100644
--- a/src/user/include/pland/syscall.h
+++ b/src/user/include/pland/syscall.h
@@ -2,6 +2,7 @@
#define PLAND_SYSCALL_H
#include <stdint.h>
+#include <stdbool.h>
typedef uint32_t _file_handle_t;
typedef uint32_t _task_handle_t;
@@ -120,8 +121,8 @@ static inline uint32_t _file_size(_file_handle_t handle) {
return _sc1(_SCN_FILE_SIZE, handle);
}
-static inline void _start_task(_drive_number_t drive_number, char *path) {
- _sc2(_SCN_START_TASK, drive_number, (uint32_t)path);
+static inline bool _start_task(_drive_number_t drive_number, const char *path) {
+ return (bool)_sc2(_SCN_START_TASK, drive_number, (uint32_t)path);
}
static inline void _log_string(const char *sz) {
diff --git a/src/user/init/main.c b/src/user/init/main.c
index 9a411e7..c301a78 100644
--- a/src/user/init/main.c
+++ b/src/user/init/main.c
@@ -1,29 +1,31 @@
#include <knob/user.h>
#include <knob/file.h>
-#include <knob/heap.h>
+#include <knob/task.h>
void main() {
- tell_user_sz("\n\nThis is a userland program.\n");
-
- tell_user_sz("Opening sd0:TEST.TXT.\n");
- struct file *f = open_file("sd0:TEST.TXT");
+ struct file *f = open_file("SYS/STARTUP.RC");
if (!f) {
- tell_user_sz("Failed to open.\n");
+ tell_user_sz("\nCould not open SYS/STARTUP.RC");
return;
}
- tell_user_sz("Length: ");
- uint32_t size = file_size(f);
- tell_user_n(size);
- tell_user_sz(" bytes\n\nContents:\n");
-
- char *buf = get_block(size + 1);
- read_from_file(f, size, buf);
- buf[size] = '\0';
+ char buf[1024];
+ char *bufp = buf;
+ while (read_from_file(f, 1, bufp)) {
+ if (*bufp == '\n') {
+ if (bufp == buf)
+ continue;
+ *bufp = '\0';
+ try_run_command(buf);
+ bufp = buf;
+ }
+ else
+ ++bufp;
+ }
+ if (bufp != buf) {
+ *bufp = '\0';
+ try_run_command(buf);
+ }
close_file(f);
-
- tell_user_sz(buf);
-
- tell_user_sz("\n\nGoodbye!\n");
}
diff --git a/src/user/knob/file.c b/src/user/knob/file.c
index 8ab7acd..0032cf2 100644
--- a/src/user/knob/file.c
+++ b/src/user/knob/file.c
@@ -9,9 +9,9 @@ struct file {
uint32_t length;
};
-static const char *try_remove_prefix(const char *path, uint8_t *dn_out) {
+const char *remove_prefix(const char *path, uint8_t *dn_out) {
if ((path[0] != 's') || (path[1] != 'd'))
- return 0;
+ goto no_prefix;
const char *num_part = path + 2;
for (uint32_t i = 0; num_part[i]; ++i)
@@ -19,22 +19,20 @@ static const char *try_remove_prefix(const char *path, uint8_t *dn_out) {
uint32_t dn_large;
if (!try_sntoi(num_part, i, &dn_large) || dn_large > 255)
- return 0;
+ goto no_prefix;
*dn_out = (uint8_t)dn_large;
return num_part + i + 1;
}
- return 0;
+no_prefix:
+ *dn_out = current_drive;
+ return path;
}
struct file *open_file(const char *path) {
uint8_t dn;
- const char *path_part = try_remove_prefix(path, &dn);
- if (path_part)
- path = path_part;
- else
- dn = current_drive;
+ path = remove_prefix(path, &dn);
_file_handle_t h = _open_file(dn, path);
if (!h)
diff --git a/src/user/knob/task.c b/src/user/knob/task.c
new file mode 100644
index 0000000..aa18eab
--- /dev/null
+++ b/src/user/knob/task.c
@@ -0,0 +1,13 @@
+#include <stdbool.h>
+#include <pland/syscall.h>
+#include <knob/file.h>
+
+bool try_run_command(const char *path) {
+ uint8_t dn;
+ path = remove_prefix(path, &dn);
+ return _start_task(dn, path);
+}
+
+void yield_task() {
+ _yield_task();
+} \ No newline at end of file