/kernel/trunk/boot/bootcode.inc |
---|
39,9 → 39,11 |
dd gdts |
dw 0 |
; Attention! The order first four selectors not to change, is used in Fast System Call |
; must be : os_code, os_data, app_code, app_data, .... |
int_code_l: |
os_code_l: |
dw 0xffff |
dw 0x0000 |
db 0x00 |
50,7 → 52,6 |
int_data_l: |
os_data_l: |
dw 0xffff |
dw 0x0000 |
db 0x00 |
57,6 → 58,20 |
dw 11011111b *256 +10010010b |
db 0x00 |
app_code_l: |
dw 0xFFFF;((0x80000000-std_application_base_address) shr 12) and 0xffff |
dw 0 |
db 0x40 |
db cpl3 |
dw G32+D32+0x6000+0x7; |
app_data_l: |
dw 0xFFFF;(0x80000000-std_application_base_address) shr 12 and 0xffff |
dw 0 |
db 0x40 |
db drw3 |
dw G32+D32+0x6000+0x7; |
; --------------- APM --------------------- |
apm_code_32: |
dw 0x0f ; limit 64kb |
75,20 → 90,6 |
db 0x00 |
; ----------------------------------------- |
app_code_l: |
dw 0xFFFF;((0x80000000-std_application_base_address) shr 12) and 0xffff |
dw 0 |
db 0x40 |
db cpl3 |
dw G32+D32+0x6000+0x7; |
app_data_l: |
dw 0xFFFF;(0x80000000-std_application_base_address) shr 12 and 0xffff |
dw 0 |
db 0x40 |
db drw3 |
dw G32+D32+0x6000+0x7; |
graph_data_l: |
dw 0x7ff |
/kernel/trunk/const.inc |
---|
85,6 → 85,12 |
CAPS_SVM equ 73 ;secure virual machine |
CAPS_ALTMOVCR8 equ 74 ; |
; CPU MSR names |
MSR_SYSENTER_CS equ 0x174 |
MSR_SYSENTER_ESP equ 0x175 |
MSR_SYSENTER_EIP equ 0x176 |
MSR_AMD_EFER equ 0xC0000080 ; Extended Feature Enable Register |
MSR_AMD_STAR equ 0xC0000081 ; SYSCALL/SYSRET Target Address Register |
CR0_PE equ 0x00000001 ;protected mode |
CR0_MP equ 0x00000002 ;monitor fpu |
246,6 → 252,8 |
std_application_base_address equ new_app_base |
RING0_STACK_SIZE equ 0x2000 - 512 ;512 áàéò äëÿ êîíòåêñòà FPU |
PAGES_USED equ 4 |
PG_UNMAP equ 0x000 |
/kernel/trunk/core/syscall.inc |
---|
35,6 → 35,101 |
iretd |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;; ;; |
;; SYSENTER ENTRY ;; |
;; ;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
uglobal |
times 100 db ? |
sysenter_stack: |
endg |
align 32 |
SYSENTER_VAR equ 0 |
sysenter_entry: |
; Íàñòðàèâàåì ñòåê |
cli |
push eax |
mov eax, [ss:CURRENT_TASK] |
shl eax, 8 |
mov eax, [ss:PROC_BASE + eax + APPDATA.pl0_stack] |
lea esp, [ss:eax + RING0_STACK_SIZE] ; configure ESP |
mov eax, [ss:sysenter_stack - 4] ; eax - original eax, from app |
sti |
;------------------ |
push ds es |
pushad |
cld |
mov ax, word os_data |
mov ds, ax |
mov es, ax |
mov eax, ebx |
mov ebx, ecx |
mov ecx, edx |
mov edx, esi |
mov esi, edi |
mov edi, [esp + 28] |
push eax |
and edi, 0xff |
call dword [servetable + edi * 4] |
pop eax |
popad |
pop es ds |
;------------------ |
mov edx, [SYSENTER_VAR] ; eip |
mov ecx, [SYSENTER_VAR + 4] ; esp |
sysexit |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;; ;; |
;; SYSCALL ENTRY ;; |
;; ;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
align 32 |
syscall_entry: |
cli |
xchg ecx, [esp] |
mov [SYSENTER_VAR + 4], esp |
mov [ss:sysenter_stack - 4], eax |
mov eax, [ss:CURRENT_TASK] |
shl eax, 8 |
mov eax, [ss:PROC_BASE + eax + APPDATA.pl0_stack] |
lea esp, [ss:eax + RING0_STACK_SIZE] ; configure ESP |
mov eax, [ss:sysenter_stack - 4] ; eax - original eax, from app |
sti |
;------------------ |
push ds es |
pushad |
cld |
mov ax, word os_data |
mov ds, ax |
mov es, ax |
mov eax, ebx |
mov ebx, ecx |
mov ecx, edx |
mov edx, esi |
mov esi, edi |
mov edi, [esp + 28] |
push eax |
and edi, 0xff |
call dword [servetable + edi * 4] |
pop eax |
popad |
pop es ds |
;------------------ |
mov esp, [SYSENTER_VAR + 4] |
xchg ecx, [esp] |
sysret |
iglobal |
;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;; SYSTEM FUNCTIONS TABLE ;; |
62,7 → 157,7 |
dd sys_cachetodiskette ; 16-FlushFloppyCache |
dd sys_getbutton ; 17-GetButton |
dd sys_system ; 18-System Services |
dd undefined_syscall ; 19-reserved |
dd paleholder;undefined_syscall ; 19-reserved |
dd sys_midi ; 20-ResetMidi and OutputMidi |
dd sys_setup ; 21-SetMidiBase,SetKeymap,SetShiftKeymap,. |
dd sys_settime ; 22-setting date,time,clock and alarm-clock |
/kernel/trunk/kernel.asm |
---|
371,6 → 371,49 |
; btr [cpu_caps], CAPS_MTRR ;test: don't use MTRR |
bts [cpu_caps], CAPS_TSC ;force use rdtsc |
; -------- Fast System Call init ---------- |
; Intel SYSENTER/SYSEXIT (AMD CPU support it too) |
bt [cpu_caps], CAPS_SEP |
jnc .SEnP ; SysEnter not Present |
xor edx, edx |
mov ecx, MSR_SYSENTER_CS |
mov eax, os_code |
wrmsr |
mov ecx, MSR_SYSENTER_ESP |
mov eax, sysenter_stack ; Check it |
wrmsr |
mov ecx, MSR_SYSENTER_EIP |
mov eax, sysenter_entry |
wrmsr |
.SEnP: |
; AMD SYSCALL/SYSRET |
cmp byte[cpu_vendor], 'A' |
jne .noSYSCALL |
mov eax, 0x80000001 |
cpuid |
test edx, 0x800 ; bit_11 - SYSCALL/SYSRET support |
jz .noSYSCALL |
mov ecx, MSR_AMD_EFER |
rdmsr |
or eax, 1 ; bit_0 - System Call Extension (SCE) |
wrmsr |
; !!!! It`s dirty hack, fix it !!! |
; Bits of EDX : |
; Bit 3116 During the SYSRET instruction, this field is copied into the CS register |
; and the contents of this field, plus 8, are copied into the SS register. |
; Bit 150 During the SYSCALL instruction, this field is copied into the CS register |
; and the contents of this field, plus 8, are copied into the SS register. |
; mov edx, (os_code + 16) * 65536 + os_code |
mov edx, 0x1B0013 |
mov eax, syscall_entry |
mov ecx, MSR_AMD_STAR |
wrmsr |
.noSYSCALL: |
; ----------------------------------------- |
; MEMORY MODEL |
call mem_test |
call init_mem |
4826,7 → 4869,9 |
ret |
align 4 |
paleholder: |
ret |
; --------------- APM --------------------- |
apm_entry dp 0 |
apm_vf dd 0 |