1,6 → 1,6 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;; ;; |
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;; |
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;; |
;; Distributed under terms of the GNU General Public License ;; |
;; ;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
167,7 → 167,7 |
@@: |
mov [page_tabs+eax*4], edx |
; push eax |
; invlpg [ebx] |
invlpg [ebx] |
; pop eax |
inc eax |
add ebx, edi |
205,7 → 205,7 |
@@: |
mov [page_tabs+ebx*4], eax |
; push eax |
; invlpg [edi] |
invlpg [edi] |
; pop eax |
add edi, edx |
add eax, edx |
321,8 → 321,17 |
cmp dword [LFBAddress], -1 |
jne @f |
mov [BOOT_VAR+0x901c],byte 2 |
stdcall kernel_alloc, 0x280000 |
mov [LFBAddress], eax |
stdcall alloc_pages, (0x280000 / 4096) |
|
push eax |
call alloc_page |
stdcall map_page_table, LFB_BASE, eax |
pop eax |
or eax, PG_UW |
mov ebx, LFB_BASE |
mov ecx, 0x280000 / 4096 |
call commit_pages |
mov [LFBAddress], dword LFB_BASE |
ret |
@@: |
test [SCR_MODE],word 0100000000000000b |
334,7 → 343,7 |
|
mov edx, LFB_BASE |
mov esi, [LFBAddress] |
mov edi, 0x00800000 |
mov edi, 0x00C00000 |
mov dword [exp_lfb+4], edx |
|
shr edi, 12 |
558,14 → 567,6 |
push ebx ;that is locals: .err_addr = cr2 |
inc [pg_data.pages_faults] |
|
; push eax |
; push edx |
; mov edx, 0x400 ;bochs |
; mov al,0xff ;bochs |
; out dx, al ;bochs |
; pop edx |
; pop eax |
|
mov eax, [pf_err_code] |
|
cmp ebx, OS_BASE ;ebx == .err_addr |
592,6 → 593,11 |
pop ebx ;restore exception number (#PF) |
ret |
|
; xchg bx, bx |
; add esp,12 ;clear in stack: locals(.err_addr) + #PF + ret_to_caller |
; restore_ring3_context |
; iretd |
|
.user_space: |
test eax, PG_MAP |
jnz .err_access ;Ñòðàíèöà ïðèñóòñòâóåò |
614,7 → 620,7 |
test eax, eax |
jz .fail |
|
stdcall map_page,[.err_addr],eax,dword PG_UW |
stdcall map_page,[.err_addr],eax,PG_UW |
|
mov edi, [.err_addr] |
and edi, 0xFFFFF000 |
627,9 → 633,40 |
restore_ring3_context |
iretd |
|
.err_access = .fail |
;íèêîãäà íå ïðîèñõîäèò |
;jmp .fail |
.err_access: |
; access denied? this may be a result of copy-on-write protection for DLL |
; check list of HDLLs |
and ebx, not 0xFFF |
mov eax, [CURRENT_TASK] |
shl eax, 8 |
mov eax, [SLOT_BASE+eax+APPDATA.dlls_list_ptr] |
test eax, eax |
jz .fail |
mov esi, [eax+HDLL.fd] |
.scan_hdll: |
cmp esi, eax |
jz .fail |
mov edx, ebx |
sub edx, [esi+HDLL.base] |
cmp edx, [esi+HDLL.size] |
jb .fault_in_hdll |
.scan_hdll.next: |
mov esi, [esi+HDLL.fd] |
jmp .scan_hdll |
.fault_in_hdll: |
; allocate new page, map it as rw and copy data |
call alloc_page |
test eax, eax |
jz .fail |
stdcall map_page,ebx,eax,PG_UW |
mov edi, ebx |
mov ecx, 1024 |
sub ebx, [esi+HDLL.base] |
mov esi, [esi+HDLL.parent] |
mov esi, [esi+DLLDESCR.data] |
add esi, ebx |
rep movsd |
jmp .exit |
|
.kernel_space: |
test eax, PG_MAP |
677,14 → 714,17 |
jmp .exit |
endp |
|
align 4 |
proc map_mem stdcall, lin_addr:dword,pdir:dword,\ |
ofs:dword,buf_size:dword |
mov eax, [buf_size] |
test eax, eax |
; returns number of mapped bytes |
proc map_mem stdcall, lin_addr:dword,slot:dword,\ |
ofs:dword,buf_size:dword,req_access:dword |
push 0 ; initialize number of mapped bytes |
|
cmp [buf_size], 0 |
jz .exit |
|
mov eax, [pdir] |
mov eax, [slot] |
shl eax, 8 |
mov eax, [SLOT_BASE+eax+APPDATA.dir_table] |
and eax, 0xFFFFF000 |
|
stdcall map_page,[ipc_pdir],eax,PG_UW |
716,10 → 756,11 |
and edx, 0x3FF |
mov esi, [ipc_ptab] |
|
.map: mov eax, [esi+edx*4] |
and eax, 0xFFFFF000 |
jz .exit |
stdcall map_page,edi,eax,PG_UW |
.map: |
stdcall safe_map_page,[slot],[req_access],[ofs] |
jnc .exit |
add dword [ebp-4], 4096 |
add [ofs], 4096 |
dec ecx |
jz .exit |
add edi, 0x1000 |
736,20 → 777,23 |
jmp .map |
|
.exit: |
pop eax |
ret |
endp |
|
align 4 |
proc map_memEx stdcall, lin_addr:dword,pdir:dword,\ |
ofs:dword,buf_size:dword |
mov eax, [buf_size] |
test eax, eax |
proc map_memEx stdcall, lin_addr:dword,slot:dword,\ |
ofs:dword,buf_size:dword,req_access:dword |
push 0 ; initialize number of mapped bytes |
|
cmp [buf_size], 0 |
jz .exit |
|
mov eax, [pdir] |
mov eax, [slot] |
shl eax, 8 |
mov eax, [SLOT_BASE+eax+APPDATA.dir_table] |
and eax, 0xFFFFF000 |
|
stdcall map_page,[proc_mem_pdir],eax,dword PG_UW |
stdcall map_page,[proc_mem_pdir],eax,PG_UW |
mov ebx, [ofs] |
shr ebx, 22 |
mov esi, [proc_mem_pdir] |
758,7 → 802,7 |
and eax, 0xFFFFF000 |
test eax, eax |
jz .exit |
stdcall map_page,edi,eax,dword PG_UW |
stdcall map_page,edi,eax,PG_UW |
|
@@: mov edi, [lin_addr] |
and edi, 0xFFFFF000 |
772,22 → 816,102 |
and edx, 0x3FF |
mov esi, [proc_mem_tab] |
|
.map: mov eax, [esi+edx*4] |
; and eax, 0xFFFFF000 |
; test eax, eax |
; jz .exit |
stdcall map_page,edi,eax,dword PG_UW |
.map: |
stdcall safe_map_page,[slot],[req_access],[ofs] |
jnc .exit |
add dword [ebp-4], 0x1000 |
add edi, 0x1000 |
add [ofs], 0x1000 |
inc edx |
dec ecx |
jnz .map |
.exit: |
pop eax |
ret |
endp |
|
; in: esi+edx*4 = pointer to page table entry |
; in: [slot], [req_access], [ofs] on the stack |
; in: edi = linear address to map |
; out: CF cleared <=> failed |
; destroys: only eax |
proc safe_map_page stdcall, slot:dword, req_access:dword, ofs:dword |
mov eax, [esi+edx*4] |
test al, PG_MAP |
jz .not_present |
test al, PG_WRITE |
jz .resolve_readonly |
; normal case: writable page, just map with requested access |
.map: |
stdcall map_page, edi, eax, [req_access] |
stc |
.fail: |
ret |
.not_present: |
; check for alloc-on-demand page |
test al, 2 |
jz .fail |
; allocate new page, save it to source page table |
push ecx |
call alloc_page |
pop ecx |
test eax, eax |
jz .fail |
or al, PG_UW |
mov [esi+edx*4], eax |
jmp .map |
.resolve_readonly: |
; readonly page, probably copy-on-write |
; check: readonly request of readonly page is ok |
test [req_access], PG_WRITE |
jz .map |
; find control structure for this page |
pushf |
cli |
cld |
push ebx ecx |
mov eax, [slot] |
shl eax, 8 |
mov eax, [SLOT_BASE+eax+APPDATA.dlls_list_ptr] |
test eax, eax |
jz .no_hdll |
mov ecx, [eax+HDLL.fd] |
.scan_hdll: |
cmp ecx, eax |
jz .no_hdll |
mov ebx, [ofs] |
and ebx, not 0xFFF |
sub ebx, [ecx+HDLL.base] |
cmp ebx, [ecx+HDLL.size] |
jb .hdll_found |
mov ecx, [ecx+HDLL.fd] |
jmp .scan_hdll |
.no_hdll: |
pop ecx ebx |
popf |
clc |
ret |
.hdll_found: |
; allocate page, save it in page table, map it, copy contents from base |
mov eax, [ecx+HDLL.parent] |
add ebx, [eax+DLLDESCR.data] |
call alloc_page |
test eax, eax |
jz .no_hdll |
or al, PG_UW |
mov [esi+edx*4], eax |
stdcall map_page, edi, eax, [req_access] |
push esi edi |
mov esi, ebx |
mov ecx, 4096/4 |
rep movsd |
pop edi esi |
pop ecx ebx |
popf |
stc |
ret |
endp |
|
|
|
sys_IPC: |
;input: |
; eax=1 - set ipc buffer area |
870,15 → 994,15 |
mov ecx, [ipc_tmp] |
cmp esi, 0x40000-0x1000 ; size of [ipc_tmp] minus one page |
jbe @f |
push eax esi edi |
push esi edi |
add esi,0x1000 |
stdcall alloc_kernel_space,esi |
mov ecx, eax |
pop edi esi eax |
pop edi esi |
@@: |
mov [used_buf], ecx |
stdcall map_mem, ecx, [SLOT_BASE+eax+0xB8],\ |
edi, esi |
stdcall map_mem, ecx, [dst_slot],\ |
edi, esi, PG_SW |
|
mov edi, [dst_offset] |
add edi, [used_buf] |
986,109 → 1110,99 |
mov [ecx+24], eax |
ret |
.fail: |
mov dword [esp+32], -1 |
or dword [esp+32], -1 |
ret |
|
iglobal |
align 4 |
f68call: |
dd f68.11 |
dd f68.12 |
dd f68.13 |
dd f68.14 |
dd f68.11 ; init_heap |
dd f68.12 ; user_alloc |
dd f68.13 ; user_free |
dd f68.14 ; get_event_ex |
dd f68.fail ;moved to f68.24 |
dd f68.16 |
dd f68.17 |
dd f68.16 ; get_service |
dd f68.17 ; call_service |
dd f68.fail ;moved to f68.25 |
dd f68.19 |
dd f68.20 |
dd f68.21 |
dd f68.22 |
dd f68.23 |
dd f68.19 ; load_dll |
dd f68.20 ; user_realloc |
dd f68.21 ; load_driver |
dd f68.22 ; shmem_open |
dd f68.23 ; shmem_close |
dd f68.24 |
dd f68.25 |
|
endg |
align 4 |
f68: |
cmp eax,4 |
jle sys_sheduler |
cmp ebx,4 |
jbe sys_sheduler |
|
cmp eax, 11 |
cmp ebx, 11 |
jb .fail |
|
cmp eax, 25 |
cmp ebx, 25 |
ja .fail |
|
jmp dword [f68call+eax*4-11*4] |
jmp dword [f68call+ebx*4-11*4] |
.11: |
call init_heap |
mov [esp+36], eax |
mov [esp+32], eax |
ret |
.12: |
stdcall user_alloc, ebx |
mov [esp+36], eax |
stdcall user_alloc, ecx |
mov [esp+32], eax |
ret |
.13: |
stdcall user_free, ebx |
mov [esp+36], eax |
stdcall user_free, ecx |
mov [esp+32], eax |
ret |
.14: |
cmp ebx, OS_BASE |
cmp ecx, OS_BASE |
jae .fail |
mov edi,ebx |
mov edi,ecx |
call get_event_ex |
mov [esp+36], eax |
mov [esp+32], eax |
ret |
.24: |
mov eax, [current_slot] |
xchg ebx, [eax+APPDATA.exc_handler] |
xchg ecx, [eax+APPDATA.except_mask] |
mov [esp+36], ebx ; reg_eax+8 |
mov [esp+24], ecx ; reg_ebx+8 |
ret |
.16: |
test ebx, ebx |
test ecx, ecx |
jz .fail |
cmp ebx, OS_BASE |
cmp ecx, OS_BASE |
jae .fail |
stdcall get_service, ebx |
mov [esp+36], eax |
stdcall get_service, ecx |
mov [esp+32], eax |
ret |
.17: |
call srv_handlerEx ;ebx |
mov [esp+36], eax |
call srv_handlerEx ;ecx |
mov [esp+32], eax |
ret |
.25: |
cmp ebx,32 |
jae .fail |
mov eax, [current_slot] |
btr [eax+APPDATA.except_mask],ebx |
setc byte[esp+36] |
jecxz @f |
bts [eax+APPDATA.except_mask],ebx |
@@: ret |
.19: |
cmp ebx, OS_BASE |
cmp ecx, OS_BASE |
jae .fail |
stdcall load_library, ebx |
mov [esp+36], eax |
stdcall load_library, ecx |
mov [esp+32], eax |
ret |
.20: |
mov eax, ecx |
call user_realloc |
mov [esp+36], eax |
mov eax, edx |
mov ebx, ecx |
call user_realloc ;in: eax = pointer, ebx = new size |
mov [esp+32], eax |
ret |
.21: |
cmp ecx, OS_BASE |
jae .fail |
|
cmp ebx, OS_BASE |
jae .fail |
|
stdcall load_PE, ebx |
|
mov edi, edx |
stdcall load_PE, ecx |
mov esi, eax |
test eax, eax |
jz @F |
|
mov esi, eax |
stdcall eax, DRV_ENTRY |
|
push edi |
push DRV_ENTRY |
call eax |
add esp, 8 |
test eax, eax |
jz @F |
|
1095,28 → 1209,45 |
mov [eax+SRV.entry], esi |
|
@@: |
mov [esp+36], eax |
mov [esp+32], eax |
ret |
.22: |
cmp ebx, OS_BASE |
cmp ecx, OS_BASE |
jae .fail |
|
stdcall shmem_open, ebx, ecx, edx |
mov [esp+28], edx |
mov [esp+36], eax |
stdcall shmem_open, ecx, edx, esi |
mov [esp+24], edx |
mov [esp+32], eax |
ret |
|
.23: |
cmp ebx, OS_BASE |
cmp ecx, OS_BASE |
jae .fail |
|
stdcall shmem_close, ebx |
mov [esp+36], eax |
stdcall shmem_close, ecx |
mov [esp+32], eax |
ret |
.24: |
mov eax, [current_slot] |
xchg ecx, [eax+APPDATA.exc_handler] |
xchg edx, [eax+APPDATA.except_mask] |
mov [esp+32], ecx ; reg_eax+8 |
mov [esp+20], edx ; reg_ebx+8 |
ret |
.25: |
cmp ecx,32 |
jae .fail |
mov eax, [current_slot] |
btr [eax+APPDATA.except_mask],ecx |
setc byte[esp+32] |
jecxz @f |
bts [eax+APPDATA.except_mask],ecx |
@@: |
ret |
|
.fail: |
xor eax, eax |
mov [esp+36], eax |
mov [esp+32], eax |
ret |
|
align 4 |
1156,41 → 1287,52 |
|
mov ecx, 0x2FF |
rdmsr ; |
; has BIOS already initialized MTRRs? |
test ah, 8 |
jnz .skip_init |
; rarely needed, so mainly placeholder |
; main memory - cached |
push eax |
|
xor edx, edx |
xor eax, eax |
mov ecx, 0x2FF |
wrmsr ;disable all MTRR |
|
mov eax, [MEM_AMOUNT] |
; round eax up to next power of 2 |
dec eax |
bsr ecx, eax |
mov eax, 2 |
shl eax, cl |
stdcall set_mtrr, edx,edx,eax,MEM_WB |
stdcall set_mtrr, 1,[LFBAddress],[LFBSize],MEM_WC |
mov ebx, 2 |
shl ebx, cl |
dec ebx |
; base of memory range = 0, type of memory range = MEM_WB |
xor edx, edx |
mov eax, MEM_WB |
mov ecx, 0x200 |
wrmsr |
; mask of memory range = 0xFFFFFFFFF - (size - 1), ebx = size - 1 |
mov eax, 0xFFFFFFFF |
mov edx, 0x0000000F |
sub eax, ebx |
sbb edx, 0 |
or eax, 0x800 |
inc ecx |
wrmsr |
; clear unused MTRRs |
xor eax, eax |
mov ecx, 0x204 |
mov ebx, 6 |
xor edx, edx |
@@: |
wrmsr ;disable unused MTRR |
wrmsr |
inc ecx |
cmp ecx, 0x210 |
jb @b |
; enable MTRRs |
pop eax |
or ah, 8 |
and al, 0xF0 ; default memtype = UC |
mov ecx, 0x2FF |
wrmsr |
inc ecx |
dec ebx |
jnz @b |
.skip_init: |
stdcall set_mtrr, [LFBAddress],[LFBSize],MEM_WC |
|
wbinvd ;again invalidate |
|
pop eax |
or eax, 0x800 ;set default memtype to UC |
and al, 0xF0 |
mov ecx, 0x2FF |
wrmsr ;and enable MTRR |
|
mov eax, cr0 |
and eax, not 0x60000000 |
mov cr0, eax ; enable caching |
1199,13 → 1341,29 |
endp |
|
align 4 |
proc set_mtrr stdcall, reg:dword,base:dword,size:dword,mem_type:dword |
|
proc set_mtrr stdcall, base:dword,size:dword,mem_type:dword |
; find unused register |
mov ecx, 0x201 |
@@: |
rdmsr |
dec ecx |
test ah, 8 |
jz .found |
rdmsr |
mov al, 0 ; clear memory type field |
cmp eax, [base] |
jz .ret |
add ecx, 3 |
cmp ecx, 0x210 |
jb @b |
; no free registers, ignore the call |
.ret: |
ret |
.found: |
; found, write values |
xor edx, edx |
mov eax, [base] |
or eax, [mem_type] |
mov ecx, [reg] |
lea ecx, [0x200+ecx*2] |
wrmsr |
|
mov ebx, [size] |
Property changes: |
Added: svn:mergeinfo |