]> git.ameliathe1st.gay Git - voyage-au-centre-des-fichiers.git/commitdiff
Implemented yield syscall and added uses of it. Not tested well yet
authorAmelia Coutard <eliottulio.coutard@gmail.com>
Sun, 6 Aug 2023 00:35:21 +0000 (02:35 +0200)
committerAmelia Coutard <eliottulio.coutard@gmail.com>
Sun, 6 Aug 2023 00:35:21 +0000 (02:35 +0200)
kernel/src/ring3.S
kernel/src/ring3.cpp
kernel/src/ring3.hpp
test_module/src/test.S
test_module/src/test.cpp

index 3019544b0eb2246fe77a350bc44869a0b5d268e7..43c819288f33cf1b0a51884fa20fa4e65da2ccc8 100644 (file)
@@ -93,6 +93,7 @@ incorrect_syscall:
 syscalls_call_table:
        .quad syscall_print
        .quad syscall_print_low_mmap
+       .quad syscall_yield
 syscalls_call_table_end:
 .set syscall_n, (syscalls_call_table_end - syscalls_call_table) >> 3 # Because / 8 *doesn't work* !
 .globl syscall_n
index 286a5bf70802d9507f478df353c6ac4fcfb52e71..b173ac490d1ddeeab83e1e83ce56e97675f33711 100644 (file)
@@ -60,6 +60,14 @@ extern "C" void os::syscall_print_low_mmap() {
        });
 }
 
+extern "C" void os::syscall_yield() {
+       if (os::processes.present(os::current_pid + 1)) {
+               os::current_pid += 1;
+       } else {
+               os::current_pid = 0;
+       }
+}
+
 extern "C" void os::syscall_rax_error_handler() {
        os::assert(false, "Incorrect %rax for syscall.");
 }
index 66fa2870f8a9ab0b632add96ad447d4346d5c70a..a66f9028e7eb7a12bf46837b625e8f57aeacbab5 100644 (file)
@@ -46,6 +46,7 @@ extern "C" void syscall_64bit_handler();
 
 extern "C" void syscall_print(char c);
 extern "C" void syscall_print_low_mmap();
+extern "C" void syscall_yield();
 extern "C" void syscall_rax_error_handler();
 
 void set_ring0_stack(tss& tss, std::uint64_t stack);
index be3f7b9cb661c02ad4bdacf146b6c1480f716a9b..348de63e641aa23ba73b255b715a4dcfe4c0b744 100644 (file)
@@ -24,3 +24,9 @@ check_mem:
        mov $1, %rax
        syscall
        ret
+
+.globl yield
+yield:
+       mov $2, %rax
+       syscall
+       ret
index 4f6294dbb61c74c8b1feb07afa2c65908a775a4b..bf45ddf290ee5b42da42f1e7267008c1a9b16f5c 100644 (file)
@@ -15,6 +15,7 @@
 
 extern "C" void print(char c);
 extern "C" void check_mem();
+extern "C" void yield();
 
 void printstr(const char* str) {
        for (size_t i = 0; str[i] != '\0'; i++) {
@@ -23,12 +24,15 @@ void printstr(const char* str) {
 }
 
 extern "C" void _start() {
-       const char* str = "ACAB cependant.\n";
-       for (size_t i = 0; i < 16; i++) {
-               printstr(str);
-       }
-       printstr("Mem:\n");
+       printstr("Mem prg 1:\n");
        check_mem();
        printstr("Done.\n");
-       while (true) {}
+       printstr("Prg 1.\n");
+       yield();
+       printstr("Prg 1 again.\n");
+
+       while (true) {
+               yield();
+               printstr("Prg 1 again.\n");
+       }
 }