summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/include/hilbert/kernel/application.hpp13
-rw-r--r--kernel/include/hilbert/kernel/panic.hpp2
-rw-r--r--kernel/include/hilbert/kernel/utility.hpp4
-rw-r--r--kernel/makefile3
-rw-r--r--kernel/source/application.asm1
-rw-r--r--kernel/source/application.cpp10
-rw-r--r--kernel/source/syscall.cpp47
7 files changed, 62 insertions, 18 deletions
diff --git a/kernel/include/hilbert/kernel/application.hpp b/kernel/include/hilbert/kernel/application.hpp
index 56c2a15..a4b59ff 100644
--- a/kernel/include/hilbert/kernel/application.hpp
+++ b/kernel/include/hilbert/kernel/application.hpp
@@ -22,7 +22,8 @@ namespace hilbert::kernel::application {
socket_listener_closed,
other_end_closed,
already_exists,
- not_sized
+ not_sized,
+ not_readable
};
struct [[gnu::packed]] cpu_state {
@@ -57,10 +58,10 @@ namespace hilbert::kernel::application {
class process;
class thread;
- class file_stream;
- class socket;
- class socket_stream_end;
- class socket_listener;
+ struct file_stream;
+ struct socket;
+ struct socket_stream_end;
+ struct socket_listener;
struct generic_stream_ptr {
bool is_socket;
@@ -93,7 +94,7 @@ namespace hilbert::kernel::application {
//saves running thread state, and switches to new task. when the thread is
//resumed, returns to caller.
- extern "C" void yield();
+ extern "C" void yield(cpu_state &save_state_into);
extern "C" [[noreturn]] void resume_next_thread();
diff --git a/kernel/include/hilbert/kernel/panic.hpp b/kernel/include/hilbert/kernel/panic.hpp
index 0478142..3aadddb 100644
--- a/kernel/include/hilbert/kernel/panic.hpp
+++ b/kernel/include/hilbert/kernel/panic.hpp
@@ -1,5 +1,5 @@
#pragma once
namespace hilbert::kernel {
- [[noreturn]] void panic(uint32_t code);
+ extern "C" [[noreturn]] void panic(uint32_t code);
}
diff --git a/kernel/include/hilbert/kernel/utility.hpp b/kernel/include/hilbert/kernel/utility.hpp
index 0247fee..b7f1a1b 100644
--- a/kernel/include/hilbert/kernel/utility.hpp
+++ b/kernel/include/hilbert/kernel/utility.hpp
@@ -381,6 +381,10 @@ namespace hilbert::kernel::utility {
count = written;
}
+ void clear() {
+ count = 0;
+ }
+
};
template <class t>
diff --git a/kernel/makefile b/kernel/makefile
index 9ec5be6..6d32537 100644
--- a/kernel/makefile
+++ b/kernel/makefile
@@ -10,7 +10,8 @@ build/%.asm.o: source/%.asm
build/%.cpp.o: source/%.cpp
@mkdir -p $(@D)
- $(HILBERT_CC) -c -ffreestanding -mcmodel=kernel -I ${LIMINE_DIR} $^ -o $@
+ $(HILBERT_CC) -c -ffreestanding -fno-exceptions -fno-rtti \
+ -mcmodel=kernel -I ${LIMINE_DIR} -I ${MINTSUKI_HEADERS_DIR} $^ -o $@
build/kernel.elf: $(SOURCES:%=build/%.o)
$(HILBERT_LD) -T link.ld $^ -o $@
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;
}