This commit is contained in:
2025-05-16 15:49:50 +03:00
parent 2e372ae9c4
commit 44d09ab13f
2 changed files with 11 additions and 7 deletions
+1
View File
@@ -41,6 +41,7 @@ switchProcess:
mov eax, [esi + 20] ; PCB.RING находится по смещению 20 mov eax, [esi + 20] ; PCB.RING находится по смещению 20
cmp eax, 3 cmp eax, 3
je .ring3 je .ring3
sti
ret ; Для ring 0 просто возвращаемся ret ; Для ring 0 просто возвращаемся
.ring3: .ring3:
jmp trapret ; Для ring 3 переходим через trapret jmp trapret ; Для ring 3 переходим через trapret
+10 -7
View File
@@ -125,21 +125,21 @@ void idle()
while (1) {} while (1) {}
} }
void task1(int arg1, char* arg2) void task1()
{ {
while (1) { while (1) {
if (arg1 == 42) printf("task1\n");
printf("task1 0x%x %s\n", arg1, arg2);
else
printf("ZHOPA %s\n", arg2);
} }
} }
void task2(int arg1, int arg2) void task2()
{ {
while (1) { arg1++; printf("task2 %X %X\n", arg1, arg2); } int a = 0;
while (1) { a++; printf("task2 %X\n", a); }
} }
void jump_usermode2(void) ;
void scheduler_init() void scheduler_init()
{ {
task_create((EntryPoint)idle, NULL, 0, 0); task_create((EntryPoint)idle, NULL, 0, 0);
@@ -149,6 +149,7 @@ void scheduler_init()
task_create((EntryPoint)task1, args1, 2, 0); task_create((EntryPoint)task1, args1, 2, 0);
void* args2[] = {(void*)69, (void*)420}; void* args2[] = {(void*)69, (void*)420};
task_create((EntryPoint)task2, args2, 2, 0); task_create((EntryPoint)task2, args2, 2, 0);
jump_usermode2();
} }
#include "../include/string.h" #include "../include/string.h"
@@ -201,6 +202,8 @@ void jump_usermode2(void) {
(code_pte & 0x2) ? "writable" : "read-only", (code_pte & 0x2) ? "writable" : "read-only",
(code_pte & 0x4) ? "user" : "supervisor"); (code_pte & 0x4) ? "user" : "supervisor");
task_create(user_code_virt, NULL, 0, 3);
// Switch to user mode with interrupts enabled // Switch to user mode with interrupts enabled
asm volatile ( asm volatile (
"pushf\n" "pushf\n"