tasking: start handling syscalls

This commit is contained in:
2025-06-19 17:58:49 +03:00
parent 5fa2393fd6
commit 93f174827b
6 changed files with 18 additions and 88 deletions
+4 -21
View File
@@ -1,6 +1,7 @@
; TODO: maybe put it near idt.c?
global sys_exit_handler
extern printf
extern handle_syscall
sys_exit_handler:
; Сохраняем регистры Ring 3
pusha
@@ -16,27 +17,9 @@ sys_exit_handler:
mov fs, ax
mov gs, ax
mov eax, [esp+44] ; System call number
mov ebx, [esp+32] ; Arg1
mov ecx, [esp+40] ; Arg2
mov edx, [esp+36] ; Arg3
mov esi, [esp+28] ; Arg4
mov edi, [esp+24] ; Arg5
; Print debug information
push edi ; arg5
push esi ; arg4
push edx ; arg3
push ecx ; arg2
push ebx ; arg1
push eax ; syscall number
push syscall_debug_fmt
; Выполняем действие
;push sys_exit_msg
call printf
;add esp, 4
add esp, 28
push esp
call handle_syscall
add esp, 0x44
; Восстанавливаем сегменты Ring 3
pop gs
+11 -65
View File
@@ -155,68 +155,14 @@ void scheduler_init()
jump_usermode2();*/
}
#include "../include/string.h"
extern void test_user_function(void);
extern void second_user_function(void);
void jump_usermode2(void) {
scheduler_lock();
void* code_phys = alloc_page();
if (!code_phys) {
printf("No memory for user code\n");
while (1);
}
void *second_code_phys = alloc_page();
// Temporarily map code_phys into kernel space
uint32_t kernel_temp_virt = 0xC0500000;
uint32_t kernel_temp_virt2 = 0xC0600000;
map_page(code_phys, (void*)kernel_temp_virt, 0x3); // R/W in kernel
map_page(second_code_phys, (void*)kernel_temp_virt2, 0x3); // R/W in kernel
// Copy user code
memcpy((void*)kernel_temp_virt, test_user_function, 4096); // Use memcpy
memcpy((void*)kernel_temp_virt2, second_user_function, 4096); // Use memcpy
printf("Copied code at 0x%x: 0x%x 0x%x 0x%x\n",
kernel_temp_virt,
*(uint32_t*)kernel_temp_virt,
*(uint32_t*)(kernel_temp_virt + 4),
*(uint32_t*)(kernel_temp_virt + 8));
// Unmap temporary kernel mapping
unmap_page((void*)kernel_temp_virt);
unmap_page((void*)kernel_temp_virt2);
printf("Copied code to 0x%x (virt 0x%x)\n",
(uint32_t)code_phys, kernel_temp_virt);
uint32_t* proc_pd = create_page_dir();
uint32_t* proc2_pd = create_page_dir();
/*Process* p_task1 = task_create(0x400000, NULL, 3, proc_pd);
Process* p_task2 = task_create(0x400000, NULL, 0, 3, proc2_pd);
if (map_page_in_directory(p_task1->pagedir,
code_phys,
(void*)0x400000,
PAGE_PRESENT | PAGE_RW | PAGE_USER) != 0) { // PAGE_USER is critical, PAGE_RW for now, can be R-X
printf("jump_usermode2: Failed to map user code into task's PD for PID %d\n", p_task1->pid);
// TODO: Terminate/cleanup p_task1, free code_phys_task1
return;
}
if (map_page_in_directory(p_task2->pagedir,
second_code_phys,
(void*)0x400000,
PAGE_PRESENT | PAGE_RW | PAGE_USER) != 0) { // PAGE_USER is critical, PAGE_RW for now, can be R-X
printf("jump_usermode2: Failed to map user code into task's PD for PID %d\n", p_task2->pid);
// TODO: Terminate/cleanup p_task1, free code_phys_task1
return;
}*/
scheduler_unlock();
}
void handle_syscall(TrapFrame *tf)
{
printf("========SYSCALL========\n");
printf("EAX: %X\n", tf->eax);
printf("EBX: %X\n", tf->ebx);
printf("ECX: %s\n", tf->ecx);
printf("EDX: %X\n", tf->edx);
printf("======== END SYSCALL========\n");
printf("SIZEOF TRAPFRAME: %X\n", sizeof(tf));
printf("SIZEOF *TRAPFRAME: %X\n", sizeof(*tf));
}