diff --git a/kernel/trunk/core/heap.inc b/kernel/trunk/core/heap.inc index ba593a07cc..b6beb6d2cc 100644 --- a/kernel/trunk/core/heap.inc +++ b/kernel/trunk/core/heap.inc @@ -137,7 +137,7 @@ proc init_kernel_heap mov [edi + MEM_BLOCK.list.next], eax mov [edi + MEM_BLOCK.list.prev], eax mov [edi + MEM_BLOCK.base], HEAP_BASE - mov [edi + MEM_BLOCK.size], 4096*sizeof.MEM_BLOCK + mov [edi + MEM_BLOCK.size], PAGE_SIZE * sizeof.MEM_BLOCK mov [edi + MEM_BLOCK.flags], MEM_BLOCK_USED mov [ecx + MEM_BLOCK.next_block], eax @@ -150,11 +150,11 @@ proc init_kernel_heap mov [ebx + MEM_BLOCK.next_block], ecx mov [ebx + MEM_BLOCK.prev_block], edi - mov [ebx + MEM_BLOCK.base], HEAP_BASE + 4096*sizeof.MEM_BLOCK + mov [ebx + MEM_BLOCK.base], HEAP_BASE + PAGE_SIZE * sizeof.MEM_BLOCK mov ecx, [pg_data.kernel_pages] shl ecx, 12 - sub ecx, HEAP_BASE-OS_BASE + 4096*sizeof.MEM_BLOCK + sub ecx, HEAP_BASE-OS_BASE + PAGE_SIZE * sizeof.MEM_BLOCK mov [heap_size], ecx mov [heap_free], ecx mov [ebx + MEM_BLOCK.size], ecx @@ -166,7 +166,7 @@ proc init_kernel_heap mov ecx, mem_block_list + 63*8 list_add ebx, ecx - mov ecx, 4096-3-1 + mov ecx, PAGE_SIZE -3-1 mov eax, HEAP_BASE + sizeof.MEM_BLOCK*4 mov [next_memblock], HEAP_BASE + sizeof.MEM_BLOCK *3 @@ -268,8 +268,8 @@ proc alloc_kernel_space stdcall, size:dword push edi mov eax, [size] - add eax, 4095 - and eax, not 4095 + add eax, PAGE_SIZE-1 + and eax, -PAGE_SIZE mov [size], eax cmp eax, [heap_free] @@ -461,8 +461,8 @@ proc kernel_alloc stdcall, size:dword push edi mov eax, [size] - add eax, 4095 - and eax, not 4095; + add eax, PAGE_SIZE-1 + and eax, -PAGE_SIZE; mov [size], eax and eax, eax jz .err @@ -502,7 +502,7 @@ proc kernel_alloc stdcall, size:dword jz .err stdcall map_page, edx, eax, dword (PG_GLOBAL + PG_SWR) - add edx, 0x1000 + add edx, PAGE_SIZE dec ebx jnz @B .end: @@ -565,8 +565,8 @@ proc init_heap call mutex_init mov esi, [ebx + PROC.mem_used] - add esi, 4095 - and esi, not 4095 + add esi, PAGE_SIZE-1 + and esi, -PAGE_SIZE mov [ebx + PROC.mem_used], esi mov eax, HEAP_TOP mov [ebx + PROC.heap_base], esi @@ -592,7 +592,7 @@ proc user_alloc stdcall, alloc_size:dword mov ecx, [alloc_size] add ecx, (4095 + PAGE_SIZE) - and ecx, not 4095 + and ecx, -PAGE_SIZE mov esi, [ebx + PROC.heap_base] mov edi, [ebx + PROC.heap_top] .scan: @@ -604,7 +604,7 @@ proc user_alloc stdcall, alloc_size:dword mov eax, [page_tabs + ebx*4] test al, MEM_BLOCK_FREE jz .test_used - and eax, 0xFFFFF000 + and eax, -PAGE_SIZE cmp eax, ecx ;alloc_size jb .m_next jz @f @@ -630,14 +630,14 @@ proc user_alloc stdcall, alloc_size:dword mov edx, [current_process] mov ebx, [alloc_size] - add ebx, 0xFFF - and ebx, not 0xFFF + add ebx, PAGE_SIZE-1 + and ebx, -PAGE_SIZE add [edx + PROC.mem_used], ebx lea ecx, [edx + PROC.heap_lock] call mutex_unlock - lea eax, [esi + 4096] + lea eax, [esi + PAGE_SIZE] pop edi pop esi @@ -647,7 +647,7 @@ proc user_alloc stdcall, alloc_size:dword test al, MEM_BLOCK_USED jz .m_exit - and eax, 0xFFFFF000 ; not PAGESIZE + and eax, -PAGE_SIZE .m_next: add esi, eax jmp .scan @@ -675,9 +675,9 @@ proc user_alloc_at stdcall, address:dword, alloc_size:dword call mutex_lock mov edx, [address] - and edx, not 0xFFF + and edx, -PAGE_SIZE mov [address], edx - sub edx, 0x1000 + sub edx, PAGE_SIZE jb .error mov esi, [ebx + PROC.heap_base] mov edi, [ebx + PROC.heap_top] @@ -690,7 +690,7 @@ proc user_alloc_at stdcall, address:dword, alloc_size:dword shr ebx, 12 mov eax, [page_tabs + ebx*4] mov ecx, eax - and ecx, 0xFFFFF000 + and ecx, -PAGE_SIZE add ecx, esi cmp edx, ecx jb .found @@ -711,7 +711,7 @@ proc user_alloc_at stdcall, address:dword, alloc_size:dword jz .error mov eax, ecx sub eax, edx - sub eax, 0x1000 + sub eax, PAGE_SIZE cmp eax, [alloc_size] jb .error @@ -729,7 +729,7 @@ proc user_alloc_at stdcall, address:dword, alloc_size:dword .nofirst: mov eax, [alloc_size] add eax, 0x1FFF - and eax, not 0xFFF + and eax, -PAGE_SIZE mov ebx, edx add edx, eax shr ebx, 12 @@ -754,8 +754,8 @@ proc user_alloc_at stdcall, address:dword, alloc_size:dword .nothird: mov edx, [current_process] mov ebx, [alloc_size] - add ebx, 0xFFF - and ebx, not 0xFFF + add ebx, PAGE_SIZE-1 + and ebx, -PAGE_SIZE add [edx + PROC.mem_used], ebx lea ecx, [edx + PROC.heap_lock] @@ -792,11 +792,11 @@ proc user_free stdcall, base:dword test al, MEM_BLOCK_DONT_FREE jnz .cantfree - and eax, not 4095 + and eax, -PAGE_SIZE mov ecx, eax or al, MEM_BLOCK_FREE mov [page_tabs + (esi-1)*4], eax - sub ecx, 4096 + sub ecx, PAGE_SIZE mov ebx, ecx shr ecx, 12 jz .released @@ -873,7 +873,7 @@ proc user_unmap stdcall, base:dword, offset:dword, size:dword lea edx, [page_tabs + edx*4] ; unmap offset mov ecx, [size] - add ecx, 4095 + add ecx, PAGE_SIZE-1 shr ecx, 12 ; unmap size in pages shr eax, 12 ; block size + 1 page @@ -884,7 +884,7 @@ proc user_unmap stdcall, base:dword, offset:dword, size:dword ja .error mov ebx, [offset] - and ebx, not 4095 ; is it required ? + and ebx, -PAGE_SIZE ; is it required ? add ebx, [base] .unmap: @@ -898,7 +898,7 @@ proc user_unmap stdcall, base:dword, offset:dword, size:dword invlpg [ebx] ; when we start using call free_page ; empty c-o-w page instead this ? @@: - add ebx, 4096 ; PAGESIZE? + add ebx, PAGE_SIZE add edx, 4 dec ecx jnz .unmap @@ -948,7 +948,7 @@ user_normalize: jz .err and dword[page_tabs + edx*4], 0 add eax, ebx - and eax, not 4095 ; not (PAGESIZE - 1) ? + and eax, -PAGE_SIZE or eax, MEM_BLOCK_FREE mov [page_tabs + esi*4], eax jmp @B @@ -978,7 +978,7 @@ user_realloc: call mutex_lock pop eax - lea ecx, [eax - 0x1000] + lea ecx, [eax - PAGE_SIZE] shr ecx, 12 mov edx, [page_tabs + ecx*4] test dl, MEM_BLOCK_USED @@ -1022,11 +1022,11 @@ user_realloc: cmp ebx, 1 jnz .nofreeall mov eax, [page_tabs + ecx*4] - and eax, not 0xFFF + and eax, -PAGE_SIZE mov edx, [current_process] mov ebx, [edx + PROC.mem_used] sub ebx, eax - add ebx, 0x1000 + add ebx, PAGE_SIZE or al, MEM_BLOCK_FREE mov [page_tabs + ecx*4], eax push esi edi @@ -1174,7 +1174,7 @@ user_realloc: shl eax, 12 push eax mov eax, [page_tabs + ecx*4] - and eax, not 0xFFF + and eax, -PAGE_SIZE or al, MEM_BLOCK_FREE sub edx, ecx mov [page_tabs + ecx*4], eax @@ -1333,8 +1333,8 @@ align 4 test ecx, ecx jz .fail - add ecx, 4095 - and ecx, -4096 + add ecx, PAGE_SIZE-1 + and ecx, -PAGE_SIZE mov [size], ecx mov eax, sizeof.SMEM @@ -1438,7 +1438,7 @@ align 4 or edx, PG_SHARED + PG_UR @@: lodsd - and eax, 0xFFFFF000 + and eax, -PAGE_SIZE or eax, edx stosd loop @B diff --git a/kernel/trunk/core/memory.inc b/kernel/trunk/core/memory.inc index 07d0629396..8dc0e4d5fd 100644 --- a/kernel/trunk/core/memory.inc +++ b/kernel/trunk/core/memory.inc @@ -173,10 +173,10 @@ proc map_io_mem stdcall, base:dword, size:dword, flags:dword push edi mov eax, [size] add eax, [base] - add eax, 4095 - and eax, -4096 + add eax, PAGE_SIZE-1 + and eax, -PAGE_SIZE mov ecx, [base] - and ecx, -4096 + and ecx, -PAGE_SIZE sub eax, ecx mov [size], eax @@ -185,7 +185,7 @@ proc map_io_mem stdcall, base:dword, size:dword, flags:dword jz .fail push eax - mov edi, 0x1000 + mov edi, PAGE_SIZE mov ebx, eax mov ecx, [size] mov edx, [base] @@ -203,7 +203,7 @@ proc map_io_mem stdcall, base:dword, size:dword, flags:dword pop eax mov edx, [base] - and edx, 4095 + and edx, PAGE_SIZE-1 add eax, edx .fail: pop edi @@ -236,8 +236,8 @@ commit_pages: @@: stosd invlpg [ebx] - add eax, 0x1000 - add ebx, 0x1000 + add eax, PAGE_SIZE + add ebx, PAGE_SIZE loop @B pop edi @@ -294,7 +294,7 @@ release_pages: mov ebx, eax .next: - add edi, 0x1000 + add edi, PAGE_SIZE add esi, 4 loop @B @@ -327,7 +327,7 @@ unmap_pages: @@: stosd invlpg [edx] - add edx, 0x1000 + add edx, PAGE_SIZE loop @b pop edi @@ -340,7 +340,7 @@ proc map_page_table stdcall, lin_addr:dword, phis_addr:dword mov ebx, [lin_addr] shr ebx, 22 mov eax, [phis_addr] - and eax, not 0xFFF + and eax, -PAGE_SIZE or eax, PG_UWR mov dword [master_tab + ebx*4], eax mov eax, [lin_addr] @@ -389,7 +389,7 @@ proc create_trampoline_pgmap ; Therefore, allocate memory with kernel_alloc, ; this will allocate physical page and a linear address somewhere, ; and deallocate only linear address with free_kernel_space. - stdcall kernel_alloc, 0x1000 + stdcall kernel_alloc, PAGE_SIZE mov edi, eax mov esi, master_tab mov ecx, 1024 @@ -418,12 +418,12 @@ proc new_mem_resize stdcall, new_size:dword jne .exit mov edi, [new_size] - add edi, 4095 + add edi, PAGE_SIZE-1 and edi, not 4095 mov [new_size], edi mov esi, [ebx + PROC.mem_used] - add esi, 4095 + add esi, PAGE_SIZE-1 and esi, not 4095 cmp edi, esi @@ -447,7 +447,7 @@ proc new_mem_resize stdcall, new_size:dword .next: inc edi - add ebx, 0x1000 + add ebx, PAGE_SIZE cmp edi, esi jb @B @@ -548,7 +548,7 @@ get_pg_addr: shr eax, 12 mov eax, [page_tabs + (eax+(OS_BASE shr 12))*4] @@: - and eax, 0xFFFFF000 + and eax, -PAGE_SIZE ret @@ -606,7 +606,7 @@ proc page_fault_handler stdcall map_page, [.err_addr], eax, PG_UWR mov edi, [.err_addr] - and edi, 0xFFFFF000 + and edi, -PAGE_SIZE mov ecx, 1024 xor eax, eax ;cld ;caller is duty for this @@ -619,7 +619,7 @@ proc page_fault_handler .err_access: ; access denied? this may be a result of copy-on-write protection for DLL ; check list of HDLLs - and ebx, not 0xFFF + and ebx, -PAGE_SIZE mov eax, [current_process] mov eax, [eax + PROC.dlls_list_ptr] test eax, eax @@ -680,7 +680,7 @@ proc page_fault_handler stdcall map_page, [.err_addr], eax, dword PG_SWR pop eax mov edi, [.err_addr] - and edi, -4096 + and edi, -PAGE_SIZE lea esi, [edi+(not tss._io_map_0)+1]; -tss._io_map_0 mov ebx, esi @@ -690,7 +690,7 @@ proc page_fault_handler mov [edx + APPDATA.io_map + ebx*4], eax add esi, [default_io_map] - mov ecx, 4096/4 + mov ecx, PAGE_SIZE/4 ;cld ;caller is duty for this rep movsd jmp .exit @@ -719,14 +719,14 @@ proc map_mem_ipc stdcall, lin_addr:dword,slot:dword,\ shr ebx, 22 mov eax, [eax + PROC.pdt_0 + ebx*4] ;get page table mov esi, [ipc_ptab] - and eax, 0xFFFFF000 + and eax, -PAGE_SIZE jz .exit stdcall map_page, esi, eax, PG_SWR @@: mov edi, [lin_addr] - and edi, 0xFFFFF000 + and edi, -PAGE_SIZE mov ecx, [buf_size] - add ecx, 4095 + add ecx, PAGE_SIZE-1 shr ecx, 12 inc ecx ; ??????????? @@ -749,7 +749,7 @@ proc map_mem_ipc stdcall, lin_addr:dword,slot:dword,\ inc ebx mov eax, [process] mov eax, [eax + PROC.pdt_0 + ebx*4] - and eax, 0xFFFFF000 + and eax, -PAGE_SIZE jz .exit stdcall map_page, esi, eax, PG_SWR @@ -782,14 +782,14 @@ proc map_memEx stdcall, lin_addr:dword,slot:dword,\ shr ebx, 22 mov eax, [eax + PROC.pdt_0 + ebx*4] ;get page table mov esi, [proc_mem_tab] - and eax, 0xFFFFF000 + and eax, -PAGE_SIZE jz .exit stdcall map_page, esi, eax, PG_SWR @@: mov edi, [lin_addr] - and edi, 0xFFFFF000 + and edi, -PAGE_SIZE mov ecx, [buf_size] - add ecx, 4095 + add ecx, PAGE_SIZE-1 shr ecx, 12 inc ecx ; ??????????? @@ -812,7 +812,7 @@ proc map_memEx stdcall, lin_addr:dword,slot:dword,\ inc ebx mov eax, [process] mov eax, [eax + PROC.pdt_0 + ebx*4] - and eax, 0xFFFFF000 + and eax, -PAGE_SIZE jz .exit stdcall map_page, esi, eax, PG_SWR @@ -874,7 +874,7 @@ proc safe_map_page stdcall, slot:dword, req_access:dword, ofs:dword cmp ecx, eax jz .no_hdll mov ebx, [ofs] - and ebx, not 0xFFF + and ebx, -PAGE_SIZE sub ebx, [ecx + HDLL.base] cmp ebx, [ecx + HDLL.size] jb .hdll_found @@ -897,7 +897,7 @@ proc safe_map_page stdcall, slot:dword, req_access:dword, ofs:dword stdcall map_page, edi, eax, [req_access] push esi edi mov esi, ebx - mov ecx, 4096/4 + mov ecx, PAGE_SIZE/4 rep movsd pop edi esi pop ecx ebx @@ -926,12 +926,12 @@ sys_IPC: mov [eax + APPDATA.ipc_size], edx add edx, ecx - add edx, 4095 - and edx, not 4095 + add edx, PAGE_SIZE-1 + and edx, -PAGE_SIZE .touch: mov eax, [ecx] - add ecx, 0x1000 + add ecx, PAGE_SIZE cmp ecx, edx jb .touch diff --git a/kernel/trunk/core/taskman.inc b/kernel/trunk/core/taskman.inc index 550be78db4..762fa82d0d 100644 --- a/kernel/trunk/core/taskman.inc +++ b/kernel/trunk/core/taskman.inc @@ -372,7 +372,7 @@ proc create_process stdcall, app_size:dword mov eax, edi call get_pg_addr - mov [edi - 4096 + PROC.pdt_0_phys], eax + mov [edi - PAGE_SIZE + PROC.pdt_0_phys], eax mov ecx, (OS_BASE shr 20)/4 xor eax, eax @@ -384,9 +384,9 @@ proc create_process stdcall, app_size:dword mov eax, [edi - 8192 + PROC.pdt_0_phys] or eax, PG_SWR - mov [edi - 4096 + (page_tabs shr 20)], eax + mov [edi - PAGE_SIZE + (page_tabs shr 20)], eax - lea edx, [edi-4096] + lea edx, [edi - PAGE_SIZE] mov esi, [app_tabs] .alloc_page_dir: @@ -474,7 +474,7 @@ align 4 mov eax, [esi] test eax, 1 jz .next - and eax, not 0xFFF + and eax, -PAGE_SIZE stdcall map_page, [tmp_task_ptab], eax, PG_SWR stdcall destroy_page_table, [tmp_task_ptab] mov eax, [esi] @@ -730,7 +730,7 @@ proc new_sys_threads jz @F push edx - stdcall user_alloc, 4096 + stdcall user_alloc, PAGE_SIZE pop edx test eax, eax jz .failed1;eax=0 @@ -763,8 +763,8 @@ proc map_process_image stdcall, img_size:dword, file_base:dword, file_size:dword mov edx, [img_size] mov esi, [file_base] mov ecx, [file_size] - add edx, 4095 - add ecx, 4095 + add edx, PAGE_SIZE-1 + add ecx, PAGE_SIZE-1 shr edx, 12 ; total pages shr ecx, 12 ; image pages @@ -774,7 +774,7 @@ proc map_process_image stdcall, img_size:dword, file_base:dword, file_size:dword .map_image: lodsd - and eax, -4096 + and eax, -PAGE_SIZE or eax, PG_UWR stosd dec edx @@ -794,10 +794,10 @@ proc map_process_image stdcall, img_size:dword, file_base:dword, file_size:dword mov edi, [file_size] mov ecx, [img_size] - add edi, 4095 - and edi, -4096 - add ecx, 4095 - and ecx, -4096 + add edi, PAGE_SIZE-1 + and edi, -PAGE_SIZE + add ecx, PAGE_SIZE-1 + and ecx, -PAGE_SIZE sub ecx, edi shr ecx, 2 xor eax, eax @@ -843,8 +843,8 @@ common_app_entry: cmp ecx, 256 jb .copy_cmdline mov edi, [ebp + APP_HDR._emem] - add edi, 4095 - and edi, -4096 + add edi, PAGE_SIZE-1 + and edi, -PAGE_SIZE sub edi, ecx dec edi cmp word [6], '00' @@ -864,7 +864,7 @@ common_app_entry: cmp word [6], '02' jne .try_load_dll ;.cleanup call init_heap - stdcall user_alloc, 4096 + stdcall user_alloc, PAGE_SIZE mov edx, [current_slot] mov [edx + APPDATA.tls_base], eax mov [tls_data_l+2], ax