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) CURRENT_TASK equ (OS_BASE+0x0003000)
TASK_COUNT equ (OS_BASE+0x0003004) TASK_COUNT equ (OS_BASE+0x0003004)
CURRENT_RING0_ESP equ (OS_BASE+0x0003008)
TASK_BASE equ (OS_BASE+0x0003010) TASK_BASE equ (OS_BASE+0x0003010)
TASK_DATA equ (OS_BASE+0x0003020) TASK_DATA equ (OS_BASE+0x0003020)
TASK_EVENT equ (OS_BASE+0x0003020) TASK_EVENT equ (OS_BASE+0x0003020)

View File

@ -159,6 +159,12 @@ find_next_task:
mov [CURRENT_TASK],ebx mov [CURRENT_TASK],ebx
mov [TASK_BASE],edi 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 cmp al, 5
jne .noevents jne .noevents

View File

@ -42,23 +42,18 @@ build_interrupt_table:
mov esi, sys_int mov esi, sys_int
mov ecx, 0x40 mov ecx, 0x40
@@: @@:
mov eax, [esi] lodsd
mov [edi], ax ; lower part of offset mov [edi], ax ; lower part of offset
mov [edi+2], word os_code ; segment selector mov [edi+2], word os_code ; segment selector
shr eax, 16 mov ax, word 10001110b shl 8 ; type: interrupt gate
mov [edi+4], word 10001110b shl 8 ; interrupt descriptor mov [edi+4], eax
mov [edi+6], ax
add esi, 4
add edi, 8 add edi, 8
dec ecx loop @b
jnz @b
;mov edi,8*0x40+idts+8 ;mov edi,8*0x40+idts+8
mov [edi + 0], word (i40 and ((1 shl 16)-1)) mov dword [edi], (i40 and 0xFFFF) or (os_code shl 16)
mov [edi + 2], word os_code mov dword [edi+4], (11101111b shl 8) or (i40 and 0xFFFF0000)
mov [edi + 4], word 11101110b*256 ; type: trap gate
mov [edi + 6], word (i40 shr 16)
ret ret
iglobal iglobal

View File

@ -14,6 +14,8 @@ $Revision$
align 32 align 32
i40: i40:
; diamond, 27.03.2007: handler does not require disabled interrupts
; so interrupts remain enabled when calling int 0x40
push ds es push ds es
pushad pushad
cld cld
@ -31,7 +33,7 @@ i40:
mov edi, [esp+28] mov edi, [esp+28]
; enable interupts - a task switch or an IRQ _CAN_ interrupt i40 handler ; enable interupts - a task switch or an IRQ _CAN_ interrupt i40 handler
sti ; sti
push eax push eax
and edi,0xff and edi,0xff
call dword [servetable+edi*4] call dword [servetable+edi*4]
@ -49,10 +51,10 @@ i40:
;; ;; ;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
uglobal ;uglobal
times 100 db ? ;times 100 db ?
sysenter_stack: ;sysenter_stack:
endg ;endg
align 32 align 32
SYSENTER_VAR equ 0 SYSENTER_VAR equ 0
@ -65,11 +67,8 @@ sysenter_entry:
; mov eax, [ss:SLOT_BASE + eax + APPDATA.pl0_stack] ; mov eax, [ss:SLOT_BASE + eax + APPDATA.pl0_stack]
; lea esp, [eax + RING0_STACK_SIZE] ; configure ESP ; lea esp, [eax + RING0_STACK_SIZE] ; configure ESP
; mov eax, [ss:sysenter_stack - 4] ; eax - original eax, from app ; 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 sti
;------------------ ;------------------
push ds es push ds es
@ -106,9 +105,15 @@ sysenter_entry:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
align 32 align 32
syscall_entry: syscall_entry:
; cli syscall clear IF ; cli syscall clear IF
xchg ecx, [esp] xchg esp, [ss:CURRENT_RING0_ESP]
mov [SYSENTER_VAR + 4], 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 [ss:sysenter_stack - 4], eax
; mov eax, [ss:CURRENT_TASK] ; mov eax, [ss:CURRENT_TASK]
@ -117,12 +122,6 @@ syscall_entry:
; lea esp, [eax + RING0_STACK_SIZE] ; configure ESP ; lea esp, [eax + RING0_STACK_SIZE] ; configure ESP
; mov eax, [ss:sysenter_stack - 4] ; eax - original eax, from app ; 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 push ds es
pushad pushad
@ -148,10 +147,10 @@ syscall_entry:
pop es ds pop es ds
;------------------ ;------------------
cli mov ecx, [ss:esp+4]
mov esp, [SYSENTER_VAR + 4] pop esp
xchg ecx, [esp]
sysret sysret
iglobal iglobal
;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SYSTEM FUNCTIONS TABLE ;; ;; SYSTEM FUNCTIONS TABLE ;;

View File

@ -441,7 +441,8 @@ B32:
mov eax, os_code mov eax, os_code
wrmsr wrmsr
mov ecx, MSR_SYSENTER_ESP mov ecx, MSR_SYSENTER_ESP
mov eax, sysenter_stack ; Check it ; mov eax, sysenter_stack ; Check it
xor eax, eax
wrmsr wrmsr
mov ecx, MSR_SYSENTER_EIP mov ecx, MSR_SYSENTER_EIP
mov eax, sysenter_entry mov eax, sysenter_entry