diff options
Diffstat (limited to 'kernel/boot.s')
| -rw-r--r-- | kernel/boot.s | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/kernel/boot.s b/kernel/boot.s index 96f0e43..21b248c 100644 --- a/kernel/boot.s +++ b/kernel/boot.s @@ -11,6 +11,8 @@ extern syscall_init extern timer_init extern traps_init +%define NRTASKS 64 + ; Multiboot header section .mboothdr mboot_hdr: @@ -80,16 +82,22 @@ gdt: db 0xCF db 0x00 ; empty TSS slots for our C scheduler - times 64 dq 0 + times NRTASKS dq 0 + ; garbage TSS descriptor + dq 0 .end: gdtp: dw (gdt.end-gdt-1) dd gdt +garbage_tss: + times 104 db 0 + flush_gdt: push ebp mov ebp, esp + push ebx ; now, load the GDT lgdt [gdtp] mov ax, 0x10 @@ -100,6 +108,28 @@ flush_gdt: mov ss, ax jmp 0x08:.end .end: + ; finally, we load the task register with + ; a pointer to our dummy TSS. this is + ; necessary since the CPU *must* save the + ; previous task state *somewhere* before + ; switching tasks. to avoid overwriting + ; any sensitive information, we reserve + ; 104 bytes for a *garbage* TSS. + mov eax, 5 + add eax, NRTASKS + shl eax, 3 + mov ebx, eax + add ebx, gdt + mov edx, garbage_tss + mov dword [ebx], 103 ; limit - 1 + mov [ebx+2], dx + shr edx, 16 + mov [ebx+4], dl + mov [ebx+7], dh + mov byte [ebx+5], 0x89 + mov byte [ebx+6], 0x00 + ltr ax + pop ebx pop ebp ret |
