tasking: start handling syscalls
This commit is contained in:
Binary file not shown.
+1
-1
@@ -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
|
||||
|
||||
Binary file not shown.
+2
-1
@@ -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
|
||||
@@ -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
|
||||
|
||||
+10
-64
@@ -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));
|
||||
}
|
||||
Reference in New Issue
Block a user