aboutsummaryrefslogtreecommitdiff
path: root/src/bringelle.c
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2021-04-10 17:24:13 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2021-04-10 17:24:13 +0200
commit242fe4a5752bf66ae4c00438f5e9ce66b0774c38 (patch)
treed27d2e1fda93643eaaf249e05a6f3a35e07a67f0 /src/bringelle.c
parentc6aa00eea71c91a219dae8688530ff0a3b83bcd4 (diff)
Enable tasks execution and syscalls
Diffstat (limited to 'src/bringelle.c')
-rw-r--r--src/bringelle.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/bringelle.c b/src/bringelle.c
index 5fd315b..8faaecc 100644
--- a/src/bringelle.c
+++ b/src/bringelle.c
@@ -2,10 +2,15 @@
#include "utils/pic.h"
#include "boot/multiboot.h"
#include "utils/mem.h"
+#include "utils/gdt.h"
char show_tics=0;
+extern GDT_TSS TSS;
+
void utask(){
+ char msg[]="Message from the task :D";
+ asm("mov $0x1, %%eax;int $0x30"::"b"(msg));
while(1);
}
@@ -15,14 +20,33 @@ void bringelle(){
// Kernel boot sequence
pic_enable_interrupt();
- print("Interrupts enabled!\n");
-
+ print("Interrupts enabled\n");
+ print("Kernel started !\n");
// Utask
+ print("Launch user task ");
+ show_tics=1;
memcpy((void*)utask,(void*)0x300000, 100); // 100 bytes seems reasonable to load utask
+ asm (
+ "cli \n\t" // Ensure we do not get interrupted
+ "movl %%ss, %%eax \n\t"
+ "movl %%eax, %0 \n\t" // Save kernel ss segment into the TSS
+ "movl %%esp, %1 \n\t" // Save kernel esp into the TSS BEFORE setting up the stack
+ "pushl $0x33 \n\t" // Push task ss which is 0x30 along with prlv which is 0x3
+ "pushl $0x400000 \n\t" // Push task esp
+ "pushfl \n\t" // Retrieve flags
+ "popl %%eax \n\t"
+ "orl $0x200, %%eax \n\t" // Enable interrupt for the user task
+ "and $0xffffbfff, %%eax \n\t" // Clear the NT flags
+ "push %%eax \n\t" // Push task flags
+ "push $0x23 \n\t" // Push task cs which is 0x20 along with prlv which is 0x3
+ "push $0 \n\t" // Push task entry point
+ "mov $0x2B, %%eax \n\t" // GDT entry 0x28 along with prlv which is 0x3
+ "mov %%eax, %%ds \n\t" // Setting up user data segment
+ "iret \n\t" // Launch user task
+ : "=m" (TSS.ss0), "=m" (TSS.esp0)
+ );
- print("Kernel started ");
- show_tics=1;
while(1);
}