summaryrefslogtreecommitdiff
path: root/kernel/source
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/source')
-rw-r--r--kernel/source/application.asm1
-rw-r--r--kernel/source/application.cpp10
-rw-r--r--kernel/source/syscall.cpp47
3 files changed, 48 insertions, 10 deletions
diff --git a/kernel/source/application.asm b/kernel/source/application.asm
index 632822f..fb19826 100644
--- a/kernel/source/application.asm
+++ b/kernel/source/application.asm
@@ -140,6 +140,7 @@ extern copy_syscall_stack
;returns: pointer to copy
extern resume_next_thread
+extern running_thread
global yield
yield:
diff --git a/kernel/source/application.cpp b/kernel/source/application.cpp
index 0c3fd36..8070019 100644
--- a/kernel/source/application.cpp
+++ b/kernel/source/application.cpp
@@ -239,7 +239,7 @@ namespace hilbert::kernel::application {
void thread::wait_for_socket_stream(socket_stream_end *the_socket_stream) {
waiting_for_socket_stream = the_socket_stream;
the_socket_stream->waiting_to_read.insert(this);
- yield();
+ yield(saved_state);
waiting_for_socket_stream = 0;
}
@@ -247,7 +247,7 @@ namespace hilbert::kernel::application {
socket_listener *the_socket_listener) {
waiting_to_accept_from = the_socket_listener;
the_socket_listener->waiting_to_accept.insert(this);
- yield();
+ yield(saved_state);
waiting_to_accept_from = 0;
return new_socket_stream_id;
}
@@ -256,15 +256,15 @@ namespace hilbert::kernel::application {
socket_listener *the_socket_listener) {
waiting_to_connect_to = the_socket_listener;
the_socket_listener->waiting_to_connect.insert(this);
- yield();
+ yield(saved_state);
waiting_to_connect_to = 0;
return new_socket_stream_id;
}
void thread::wait_for_input() {
- waiting_for_input = false;
+ waiting_for_input = true;
input::waiting_for_input->insert(this);
- yield();
+ yield(saved_state);
waiting_for_input = false;
}
diff --git a/kernel/source/syscall.cpp b/kernel/source/syscall.cpp
index 6b0f13f..f2a6801 100644
--- a/kernel/source/syscall.cpp
+++ b/kernel/source/syscall.cpp
@@ -700,10 +700,44 @@ namespace hilbert::kernel::syscall {
}
- typedef void (*syscall_handler)(
- uint64_t &rax, uint64_t &rdi, uint64_t &rsi, uint64_t &rdx);
+ void start_thread_syscall(
+ uint64_t &rax, uint64_t &rdi, uint64_t &rsi, uint64_t &rdx) {
+
+ uint64_t entry_point = rdi;
+ uint64_t argument = rsi;
+ set_zero(rax, rdi, rsi, rdx);
+
+ auto *p = application::running_thread->owner;
+ auto *t = new application::thread(p, entry_point);
+ t->saved_state.rdi = argument;
+ p->add_thread(t);
+ application::paused_threads->insert(t);
+
+ }
+
+ void clear_socket_read_queue_syscall(
+ uint64_t &rax, uint64_t &rdi, uint64_t &rsi, uint64_t &rdx) {
+
+ unsigned handle = (unsigned)rdi;
+ set_zero(rax, rdi, rsi, rdx);
+
+ auto stream = application::running_thread->owner->get_stream(handle);
+
+ if (stream.is_null() || !stream.is_socket) {
+ rax = 0;
+ return;
+ }
+
+ auto &queue = stream.as_socket_stream->read_queue;
+
+ rax = queue.count;
+ queue.clear();
+
+ }
+
+ void (*handlers[])(
+ uint64_t &rax, uint64_t &rdi, uint64_t &rsi, uint64_t &rdx) = {
- syscall_handler handlers[] = {
&encode_color_syscall,
&get_framebuffer_syscall,
&open_file_syscall,
@@ -723,10 +757,13 @@ namespace hilbert::kernel::syscall {
&start_process_syscall,
&end_this_process_syscall,
&set_stream_length_syscall,
- &get_other_end_process_handle_syscall
+ &get_other_end_process_handle_syscall,
+ &start_thread_syscall,
+ &clear_socket_read_queue_syscall
+
};
- static constexpr int max_syscall_number = 19;
+ static constexpr int max_syscall_number = 20;
}