From c58d3fcbd145cc75350a347991f4736e3a914a01 Mon Sep 17 00:00:00 2001 From: "Evgeny Grechnikov (Diamond)" Date: Wed, 28 Mar 2007 14:51:04 +0000 Subject: [PATCH] Normal stack handling for sysenter/syscall; trap gate for int 0x40 git-svn-id: svn://kolibrios.org@434 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/const.inc | 1 + kernel/trunk/core/sched.inc | 6 +++++ kernel/trunk/core/sys32.inc | 25 +++++++++------------ kernel/trunk/core/syscall.inc | 41 +++++++++++++++++------------------ kernel/trunk/kernel.asm | 3 ++- 5 files changed, 39 insertions(+), 37 deletions(-) diff --git a/kernel/trunk/const.inc b/kernel/trunk/const.inc index 10dd2ab28a..4a9ec49d3f 100644 --- a/kernel/trunk/const.inc +++ b/kernel/trunk/const.inc @@ -146,6 +146,7 @@ window_data equ (OS_BASE+0x0000000) CURRENT_TASK equ (OS_BASE+0x0003000) TASK_COUNT equ (OS_BASE+0x0003004) +CURRENT_RING0_ESP equ (OS_BASE+0x0003008) TASK_BASE equ (OS_BASE+0x0003010) TASK_DATA equ (OS_BASE+0x0003020) TASK_EVENT equ (OS_BASE+0x0003020) diff --git a/kernel/trunk/core/sched.inc b/kernel/trunk/core/sched.inc index ebc0091150..6cc8de4793 100644 --- a/kernel/trunk/core/sched.inc +++ b/kernel/trunk/core/sched.inc @@ -159,6 +159,12 @@ find_next_task: mov [CURRENT_TASK],ebx mov [TASK_BASE],edi + push ebx + shl ebx, 8 + mov ebx, [SLOT_BASE + ebx + APPDATA.pl0_stack] + add ebx, RING0_STACK_SIZE + mov [CURRENT_RING0_ESP], ebx + pop ebx cmp al, 5 jne .noevents diff --git a/kernel/trunk/core/sys32.inc b/kernel/trunk/core/sys32.inc index 51ca925ee7..e40cc49f9c 100644 --- a/kernel/trunk/core/sys32.inc +++ b/kernel/trunk/core/sys32.inc @@ -42,23 +42,18 @@ build_interrupt_table: mov esi, sys_int mov ecx, 0x40 @@: - mov eax, [esi] - mov [edi], ax ; lower part of offset - mov [edi+2], word os_code ; segment selector - shr eax, 16 - mov [edi+4], word 10001110b shl 8 ; interrupt descriptor - mov [edi+6], ax - add esi, 4 - add edi, 8 - dec ecx - jnz @b + lodsd + mov [edi], ax ; lower part of offset + mov [edi+2], word os_code ; segment selector + mov ax, word 10001110b shl 8 ; type: interrupt gate + mov [edi+4], eax + add edi, 8 + loop @b ;mov edi,8*0x40+idts+8 - mov [edi + 0], word (i40 and ((1 shl 16)-1)) - mov [edi + 2], word os_code - mov [edi + 4], word 11101110b*256 - mov [edi + 6], word (i40 shr 16) - + mov dword [edi], (i40 and 0xFFFF) or (os_code shl 16) + mov dword [edi+4], (11101111b shl 8) or (i40 and 0xFFFF0000) + ; type: trap gate ret iglobal diff --git a/kernel/trunk/core/syscall.inc b/kernel/trunk/core/syscall.inc index b512d47db8..8d1d6497b6 100644 --- a/kernel/trunk/core/syscall.inc +++ b/kernel/trunk/core/syscall.inc @@ -14,6 +14,8 @@ $Revision$ align 32 i40: +; diamond, 27.03.2007: handler does not require disabled interrupts +; so interrupts remain enabled when calling int 0x40 push ds es pushad cld @@ -31,7 +33,7 @@ i40: mov edi, [esp+28] ; enable interupts - a task switch or an IRQ _CAN_ interrupt i40 handler - sti +; sti push eax and edi,0xff call dword [servetable+edi*4] @@ -49,10 +51,10 @@ i40: ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -uglobal -times 100 db ? -sysenter_stack: -endg +;uglobal +;times 100 db ? +;sysenter_stack: +;endg align 32 SYSENTER_VAR equ 0 @@ -65,11 +67,8 @@ sysenter_entry: ; mov eax, [ss:SLOT_BASE + eax + APPDATA.pl0_stack] ; lea esp, [eax + RING0_STACK_SIZE] ; configure ESP ; mov eax, [ss:sysenter_stack - 4] ; eax - original eax, from app + mov esp, [ss:CURRENT_RING0_ESP] - mov esp, [ss:CURRENT_TASK] - shl esp, 8 - mov esp, [ss:SLOT_BASE + esp + APPDATA.pl0_stack] - add esp, RING0_STACK_SIZE ; configure ESP sti ;------------------ push ds es @@ -106,9 +105,15 @@ sysenter_entry: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; align 32 syscall_entry: + ; cli syscall clear IF - xchg ecx, [esp] - mov [SYSENTER_VAR + 4], esp + xchg esp, [ss:CURRENT_RING0_ESP] + push ecx + lea ecx, [esp+4] + xchg ecx, [ss:CURRENT_RING0_ESP] + sti + push ecx + mov ecx, [ecx] ; mov [ss:sysenter_stack - 4], eax ; mov eax, [ss:CURRENT_TASK] @@ -117,12 +122,6 @@ syscall_entry: ; lea esp, [eax + RING0_STACK_SIZE] ; configure ESP ; mov eax, [ss:sysenter_stack - 4] ; eax - original eax, from app - mov esp, [ss:CURRENT_TASK] - shl esp, 8 - mov esp, [ss:SLOT_BASE + esp + APPDATA.pl0_stack] - add esp, RING0_STACK_SIZE ; configure ESP - - sti ;------------------ push ds es pushad @@ -148,10 +147,10 @@ syscall_entry: pop es ds ;------------------ - cli - mov esp, [SYSENTER_VAR + 4] - xchg ecx, [esp] - sysret + mov ecx, [ss:esp+4] + pop esp + sysret + iglobal ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; SYSTEM FUNCTIONS TABLE ;; diff --git a/kernel/trunk/kernel.asm b/kernel/trunk/kernel.asm index 9358d20bb0..cae0cba44f 100644 --- a/kernel/trunk/kernel.asm +++ b/kernel/trunk/kernel.asm @@ -441,7 +441,8 @@ B32: mov eax, os_code wrmsr mov ecx, MSR_SYSENTER_ESP - mov eax, sysenter_stack ; Check it +; mov eax, sysenter_stack ; Check it + xor eax, eax wrmsr mov ecx, MSR_SYSENTER_EIP mov eax, sysenter_entry