I'm testing SYSENTER performance and it turns out that each call takes 54.602287 cycles (1M calls).
0. Is this code correct?
1. Is this treated fast enough?
1.5. I test this due to interest to online judge of special problems with lots of interactives. Usual solutions compile the interactive lib together, making it easily attacked.
2. I run on virtualbox. Does that lead to difference to real computer?
2.5. I was searching for address of HPET but failed and fall back to RDTSC.
org $7c00
cli
in al,0x92
or al,0000_0010B
out 0x92,al
lgdt [gdt_ptr]
mov eax, cr0
inc eax
mov cr0, eax
mov ax, 16
mov ds, ax
mov ss, ax
jmp 8:x32
use32
x32: mov ecx, $174
xor edx, edx
mov eax, 8
wrmsr
mov eax, 0x7c00
inc ecx
wrmsr
mov eax, intx
inc ecx
wrmsr
mov edx, run
sysexit ; Yes I use SYSEXIT to go to ring3
intx: sysexit
run: rdtsc
mov esi, eax
mov edi, edx
mov ebx, 1000000
mov edx, .lp
.lp: sub ebx, 1
jz .ok
sysenter
.ok: rdtsc
sub eax, esi
sbb edx, edi
mov ebx, $b8100
call print
mov eax, edx
call print
jmp $
print: mov cl, al
and cl, $F
cmp cl, 10
jb .ov
add cl, 7
.ov: add cl, 48
mov [ebx], cl
sub ebx, 2
shr eax, 4
jnz print
sub ebx, 2
ret
align 8
GDT_BASE:
dd 0, 0
dd $FFFF, $00CF9A00
dd $FFFF, $00CF9200
dd $FFFF, $00CF9A00 ; No actual protection here
dd $FFFF, $00CF9200
GDT_LIMIT = $-GDT_BASE-1
align 8
gdt_ptr:
dw GDT_LIMIT
dd GDT_BASE
db $7dfe-$ dup $90
dw $aa55