summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2020-09-06 13:44:20 -0400
committerBenji Dial <benji6283@gmail.com>2020-09-06 13:44:20 -0400
commit73bb0e48640b842824a0b45fe4854df8ff7faf7b (patch)
tree077dec8a426db1e835393964da4736e91ff4c69d /src/user
parentcbc85f6e897808b29e2f712156e2fa4d073d8277 (diff)
downloadportland-os-73bb0e48640b842824a0b45fe4854df8ff7faf7b.tar.gz
bugfixes, init program, hello world
Diffstat (limited to 'src/user')
-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
8 files changed, 59 insertions, 37 deletions
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