diff --git a/grubshit/aaa b/grubshit/aaa index ab2434a..7bcfafb 100755 Binary files a/grubshit/aaa and b/grubshit/aaa differ diff --git a/grubshit/aaa.asm b/grubshit/aaa.asm index 4a0fd19..6301d3a 100644 --- a/grubshit/aaa.asm +++ b/grubshit/aaa.asm @@ -11,5 +11,5 @@ _start: ;tell linker entry point section .data -msg db 'Hello, world!',0xa ;our dear string +msg db 'Hello, world!',0x0 ;our dear string len equ $ - msg ;length of our dear string diff --git a/grubshit/aaa.o b/grubshit/aaa.o index ca2e1f3..62feea2 100644 Binary files a/grubshit/aaa.o and b/grubshit/aaa.o differ diff --git a/include/task.h b/include/task.h index 7f1cae5..14899dd 100644 --- a/include/task.h +++ b/include/task.h @@ -38,7 +38,7 @@ typedef struct __attribute__((packed)) TrapFrame { uint32_t gs,fs,es,ds; uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; - uint32_t interrupt, error; + //uint32_t interrupt, error; uint32_t eip, cs, eflags, usermode_esp, usermode_ss; @@ -65,5 +65,6 @@ void scheduler_init(); void schedule(); void scheduler_lock(); void scheduler_unlock(); +void handle_syscall(TrapFrame *tf); #endif \ No newline at end of file diff --git a/src/tasking/sys_exit.asm b/src/tasking/sys_exit.asm index 896ff49..df61e26 100644 --- a/src/tasking/sys_exit.asm +++ b/src/tasking/sys_exit.asm @@ -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 diff --git a/src/tasking/task.c b/src/tasking/task.c index 067e3cb..504a0c1 100644 --- a/src/tasking/task.c +++ b/src/tasking/task.c @@ -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)); +} \ No newline at end of file