Fast calls

* multi thread program support
* MSR protect
* fast_call_test update
---------------------------
old code:
	int 0x40

code for Intel SYSENTER:
	push	ebp
	mov	ebp, esp
	push	..ret_point
	sysenter
 ..ret_point:
	pop	edx
	pop	ecx

code for AMD SYSCALL:
	push	ecx
	syscall
	pop	ecx

recommendation: use mcall from macros.inc

git-svn-id: svn://kolibrios.org@477 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Iliya Mihailov (Ghost) 2007-05-07 12:54:32 +00:00
parent 4869fa5f70
commit 2432006d40
7 changed files with 68 additions and 82 deletions

View File

@ -48,26 +48,14 @@ i40:
;; ;; ;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;uglobal
;times 100 db ?
;sysenter_stack:
;endg
align 32 align 32
SYSENTER_VAR equ 0
sysenter_entry: sysenter_entry:
; Íàñòðàèâàåì ñòåê ; Íàñòðàèâàåì ñòåê
; cli sysenter clear IF
; push eax
; mov eax, [ss:CURRENT_TASK]
; shl eax, 8
; 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:tss._esp0] mov esp, [ss:tss._esp0]
sti sti
;------------------ push ebp ; save app esp + 4
mov ebp, [ebp] ; ebp - original ebp
;------------------
pushad pushad
cld cld
@ -85,8 +73,13 @@ sysenter_entry:
popad popad
;------------------ ;------------------
mov edx, [SYSENTER_VAR] ; eip xchg ecx, [ss:esp] ; â âåðøèí ñòåêà - app ecx, ecx - app esp + 4
mov ecx, [SYSENTER_VAR + 4] ; esp sub ecx, 4
xchg edx, [ecx] ; edx - return point, & save original edx
push edx
mov edx, [ss:esp + 4]
mov [ecx + 4], edx ; save original ecx
pop edx
sysexit sysexit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -3298,12 +3298,24 @@ ret
wrmsr_instr: wrmsr_instr:
;now counter in ecx ;now counter in ecx
;(edx:eax) esi:edi => edx:esi ;(edx:eax) esi:edi => edx:esi
mov eax,esi ; Fast Call MSR can't be destroy
wrmsr ; Íî MSR_AMD_EFER ìîæíî èçìåíÿòü, ò.ê. â ýòîì ðåãèñòðå ëèø
mov [esp+36],eax ; âêëþ÷àþòñÿ/âûêëþ÷àþòñÿ ðàñøèðåííûå âîçìîæíîñòè
mov [esp+24],edx ;ret in ebx? cmp ecx, MSR_SYSENTER_CS
je @f
cmp ecx, MSR_SYSENTER_ESP
je @f
cmp ecx, MSR_SYSENTER_EIP
je @f
cmp ecx, MSR_AMD_STAR
je @f
mov eax, esi
wrmsr
@@:
ret ret
cache_disable: cache_disable:
mov eax,cr0 mov eax,cr0
or eax,01100000000000000000000000000000b or eax,01100000000000000000000000000000b

View File

@ -129,16 +129,42 @@ macro __mov reg,a { ; mike.dld
end if end if
} }
macro mcall a,b,c,d,e,f { ; mike.dld __CPU_type equ p5
SYSENTER_VAR equ 0
macro mcall a,b,c,d,e,f { ; mike.dld, updated by Ghost for Fast System Calls
local ..ret_point
__mov eax,a __mov eax,a
__mov ebx,b __mov ebx,b
__mov ecx,c __mov ecx,c
__mov edx,d __mov edx,d
__mov esi,e __mov esi,e
__mov edi,f __mov edi,f
int 0x40
}
if __CPU_type eq p5
int 0x40
else
if __CPU_type eq p6
push ebp
mov ebp, esp
push ..ret_point ; it may be 2 or 5 byte
sysenter
..ret_point:
pop edx
pop ecx
else
if __CPU_type eq k6
push ecx
syscall
pop ecx
else
display 'ERROR : unknown CPU type'
int 0x40
end if
end if
end if
}
; language for programs ; language for programs
@ -263,4 +289,4 @@ EVM_EXIT = 1000b
EVM_BACKGROUND = 10000b EVM_BACKGROUND = 10000b
EVM_MOUSE = 100000b EVM_MOUSE = 100000b
EVM_IPC = 1000000b EVM_IPC = 1000000b
EVM_STACK = 10000000b EVM_STACK = 10000000b

View File

@ -4,7 +4,6 @@
; Compile with FASM for Kolibri ; Compile with FASM for Kolibri
; ;
; ;
SYSENTER_VAR equ 0
use32 use32
org 0x0 org 0x0
db 'MENUET01' db 'MENUET01'
@ -20,6 +19,7 @@ include 'debug.inc'
START: print 'Please wait' START: print 'Please wait'
; ÷åðåç áûñòðûé âûçîâ (SYSENTER) ; ÷åðåç áûñòðûé âûçîâ (SYSENTER)
__CPU_type equ p6
test1: mov eax, 1 test1: mov eax, 1
cpuid cpuid
test edx, 0x800 test edx, 0x800
@ -34,12 +34,10 @@ test1: mov eax, 1
mov [old_tsc + 4], edx mov [old_tsc + 4], edx
mov ebx, 0x100000 mov ebx, 0x100000
mov dword[SYSENTER_VAR], .ret_p
mov [SYSENTER_VAR + 4], esp
align 32 align 32
.nxt: mov eax, 19 ; ôóíêöèÿ ïóñòûøêà .nxt: mcall 19 ; ôóíêöèÿ ïóñòûøêà
sysenter ; ïîðòÿòñÿ ecx, edx ; ïîðòÿòñÿ ecx, edx
.ret_p: dec ebx dec ebx
jnz .nxt jnz .nxt
xor eax, eax xor eax, eax
@ -56,6 +54,7 @@ test1: mov eax, 1
;---------------------------------------------- ;----------------------------------------------
; ÷åðåç áûñòðûé âûçîâ (SYSCALL) ; ÷åðåç áûñòðûé âûçîâ (SYSCALL)
__CPU_type equ k6
test2: xor eax, eax test2: xor eax, eax
cpuid cpuid
cmp ecx, "cAMD" cmp ecx, "cAMD"
@ -75,12 +74,9 @@ test2: xor eax, eax
mov ebx, 0x100000 mov ebx, 0x100000
align 32 align 32
.nxt: mov eax, 19 .nxt: mcall 19 ; ôóíêöèÿ ïóñòûøêà
push ecx
syscall
pop ecx
.ret_p: dec ebx dec ebx
jnz .nxt jnz .nxt
xor eax, eax xor eax, eax
@ -96,6 +92,7 @@ test2: xor eax, eax
.end: print ' <- Fast call (SYSCALL)' .end: print ' <- Fast call (SYSCALL)'
;---------------------------------------------- ;----------------------------------------------
; ÷åðåç øëþç ïðåðûâàíèÿ ; ÷åðåç øëþç ïðåðûâàíèÿ
__CPU_type equ p5
xor eax, eax xor eax, eax
cpuid cpuid
rdtsc rdtsc
@ -104,8 +101,7 @@ test2: xor eax, eax
test3: mov ebx, 0x100000 test3: mov ebx, 0x100000
align 32 align 32
.nxt: mov eax, 19 ; ôóíêöèÿ ïóñòûøêà .nxt: mcall 19 ; ôóíêöèÿ ïóñòûøêà
int 0x40
dec ebx dec ebx
jnz .nxt jnz .nxt
@ -121,42 +117,7 @@ test3: mov ebx, 0x100000
debug_print_hex eax debug_print_hex eax
print ' <- Interrupt' print ' <- Interrupt'
call show_alive mcall -1
mov eax, -1
int 0x40
;--------------------------------------------- ;---------------------------------------------
show_alive:
; ÷åðåç áûñòðûé âûçîâ, íàñòðàèâàåì ðåãèñòðû äëÿ âîçâðàòà
mov eax, 63
mov ebx, 1
mov esi, msg_Ok
.nxt: mov cl, [esi]
test cl, cl
jz .end
mov dword[SYSENTER_VAR], .ret_p
mov [SYSENTER_VAR + 4], esp
sysenter ; ïîðòÿòñÿ ecx, edx
.ret_p: inc esi
jmp .nxt
.end: ret
; ÷åðåç øëþç ïðåðûâàíèÿ
; mov eax, 63
; mov ebx, 1
; mov esi, msg_Ok
; @@: mov cl, [esi]
; test cl, cl
; jz @f
; int 0x40
; inc esi
; jmp @b
; @@: ret
old_tsc: dd 0, 0 old_tsc: dd 0, 0
msg_Ok db 'Alive!', 10, 13, 0
I_END: I_END:

View File

@ -0,0 +1,2 @@
@fasm pcidev.asm pcidev
@pause

View File

@ -1,4 +0,0 @@
@erase lang.inc
@echo lang fix en >lang.inc
@fasm pcidev.asm pcidev
@pause

View File

@ -1,4 +0,0 @@
@erase lang.inc
@echo lang fix ge >lang.inc
@fasm pcidev.asm pcidev
@pause