Normal stack handling for sysenter/syscall; trap gate for int 0x40

git-svn-id: svn://kolibrios.org@434 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Evgeny Grechnikov (Diamond) 2007-03-28 14:51:04 +00:00
parent 84fe57af51
commit c58d3fcbd1
5 changed files with 39 additions and 37 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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 ;;

View File

@ -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