initial buddy allocator

git-svn-id: svn://kolibrios.org@843 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2008-08-05 14:17:58 +00:00
parent 059b851217
commit 28b0948e61
6 changed files with 51 additions and 207 deletions

View File

@ -332,7 +332,7 @@ end virtual
LAST_PAGE equ 0x0340000
sys_pgmap equ (OS_BASE+LAST_PAGE)
;sys_pgmap equ (OS_BASE+LAST_PAGE)
twdw equ 0x3000 ;(CURRENT_TASK-window_data)

View File

@ -577,7 +577,7 @@ proc kernel_alloc stdcall, size:dword
push ebx
stdcall alloc_pages, ebx
pop ecx ; yes ecx!!!
and eax, eax
test eax, eax
jz .err
mov edi, eax

View File

@ -8,97 +8,6 @@
$Revision$
align 4
proc alloc_page
pushfd
cli
push ebx
mov ebx, [page_start]
mov ecx, [page_end]
.l1:
bsf eax,[ebx];
jnz .found
add ebx,4
cmp ebx, ecx
jb .l1
pop ebx
popfd
xor eax,eax
ret
.found:
btr [ebx], eax
mov [page_start],ebx
sub ebx, sys_pgmap
lea eax, [eax+ebx*8]
shl eax, 12
dec [pg_data.pages_free]
pop ebx
popfd
ret
endp
align 4
proc alloc_pages stdcall, count:dword
pushfd
push ebx
push edi
cli
mov eax, [count]
add eax, 7
shr eax, 3
mov [count], eax
cmp eax, [pg_data.pages_free]
ja .fail
mov ecx, [page_start]
mov ebx, [page_end]
.find:
mov edx, [count]
mov edi, ecx
.match:
cmp byte [ecx], 0xFF
jne .next
dec edx
jz .ok
inc ecx
cmp ecx,ebx
jb .match
.fail:
xor eax, eax
pop edi
pop ebx
popfd
ret
.next:
inc ecx
cmp ecx, ebx
jb .find
pop edi
pop ebx
popfd
xor eax, eax
ret
.ok:
sub ecx, edi
inc ecx
push esi
mov esi, edi
xor eax, eax
rep stosb
sub esi, sys_pgmap
shl esi, 3+12
mov eax, esi
mov ebx, [count]
shl ebx, 3
sub [pg_data.pages_free], ebx
pop esi
pop edi
pop ebx
popfd
ret
endp
align 4
proc map_page stdcall,lin_addr:dword,phis_addr:dword,flags:dword
push ebx
@ -123,23 +32,24 @@ map_space: ;not implemented
align 4
proc free_page
;arg: eax page address
pushfd
cli
shr eax, 12 ;page index
bts dword [sys_pgmap], eax ;that's all!
cmc
adc [pg_data.pages_free], 0
shr eax, 3
and eax, not 3 ;dword offset from page_map
add eax, sys_pgmap
cmp [page_start], eax
ja @f
popfd
ret
@@:
mov [page_start], eax
popfd
; pushfd
; cli
; shr eax, 12 ;page index
; bts dword [sys_pgmap], eax ;that's all!
; cmc
; adc [pg_data.pages_free], 0
; shr eax, 3
; and eax, not 3 ;dword offset from page_map
; add eax, sys_pgmap
; cmp [page_start], eax
; ja @f
; popfd
; ret
;@@:
; mov [page_start], eax
; popfd
ret
endp
@ -235,9 +145,9 @@ release_pages:
shr esi, 10
add esi, page_tabs
mov ebp, [pg_data.pages_free]
mov ebx, [page_start]
mov edx, sys_pgmap
; mov ebp, [pg_data.pages_free]
; mov ebx, [page_start]
; mov edx, sys_pgmap
@@:
xor eax, eax
xchg eax, [esi]
@ -245,20 +155,20 @@ release_pages:
invlpg [edi]
pop eax
test eax, 1
jz .next
; test eax, 1
; jz .next
shr eax, 12
bts [edx], eax
cmc
adc ebp, 0
shr eax, 3
and eax, -4
add eax, edx
cmp eax, ebx
jae .next
; shr eax, 12
; bts [edx], eax
; cmc
; adc ebp, 0
; shr eax, 3
; and eax, -4
; add eax, edx
; cmp eax, ebx
; jae .next
mov ebx, eax
; mov ebx, eax
.next:
add edi, 0x1000
add esi, 4
@ -530,7 +440,7 @@ proc page_fault_handler
mov ebx, [.err_addr]
mov eax, [.err_code]
; xchg bx, bx
; xchg bx, bx
cmp ebx, HEAP_BASE
jb .user_space ;ñòðàíèöà â ïàìÿòè ïðèëîæåíèÿ ;
@ -1308,12 +1218,14 @@ endp
align 4
_balloc: ; gcc fastcall
@balloc@4:
mov eax, [_last_page]
mov eax, [_pg_balloc]
add ecx, 4095
and ecx, -4096
add ecx, eax
mov [_last_page], ecx
mov [_pg_balloc], ecx
add eax, OS_BASE
ret

View File

@ -191,8 +191,8 @@ proc fs_execute
mov ebx, cr3
mov [save_cr3], ebx
stdcall create_app_space,[hdr_mem],[file_base],[file_size]
mov ecx, -30 ; no memory
stdcall create_app_space,[hdr_mem],[file_base],[file_size]
mov ecx, -30 ; no memory
test eax, eax
jz .failed
@ -380,8 +380,8 @@ proc create_app_space stdcall, app_size:dword,img_base:dword,img_size:dword
else
lea eax, [eax+ebx+2] ;all requested memory
end if
cmp eax, [pg_data.pages_free]
ja .fail
; cmp eax, [pg_data.pages_free]
; ja .fail
call alloc_page
test eax, eax

View File

@ -110,7 +110,7 @@ kernel_file db 'KERNEL MNT'
align 4
_last_page dd LAST_PAGE
_pg_balloc dd LAST_PAGE
;supported videomodes
mode_1280_1024_32:
@ -290,6 +290,8 @@ large_block_list rd 31
mem_block_mask rd 2
large_block_mask rd 1
_z_core rd 50
mem_used.fd rd 1
mem_used.bk rd 1

View File

@ -293,76 +293,8 @@ MEM_WB equ 6 ;write-back memory
MEM_WC equ 1 ;write combined memory
MEM_UC equ 0 ;uncached memory
align 4
init_mem:
mov ecx, [BOOT_VAR + 0x9100]
mov esi, BOOT_VAR + 0x9104
xor eax, eax
@@:
cmp dword [esi+16], 1
jne .next
mov edx, [esi+8]
cmp eax, [esi+8]
ja .next
mov eax, [esi+8]
.next:
add esi, 20
loop @B
and eax, -4096
mov [MEM_AMOUNT], eax
mov [pg_data.mem_amount], eax
shr eax, 12
mov edx, eax
mov [pg_data.pages_count], eax
shr eax, 3
and eax, -4
mov [pg_data.pagemap_size], eax
mov ecx, eax
fastcall _balloc
ret
align 4
init_page_map:
mov edi, sys_pgmap
mov ecx, [pg_data.pagemap_size]
shr ecx, 2
or eax, -1
cld
rep stosd
xchg bx, bx
mov ecx, [_last_page]
mov edx, [pg_data.pages_count]
shr ecx, 12
sub edx, ecx
mov [pg_data.pages_free], edx
mov edi, sys_pgmap
mov ebx, ecx
shr ecx, 5
xor eax, eax
rep stosd
not eax
mov ecx, ebx
and ecx, 31
shl eax, cl
mov [edi], eax
mov [page_start], edi;
mov ebx, sys_pgmap
add ebx, [pg_data.pagemap_size]
mov [page_end], ebx
mov [pg_data.pg_mutex], 0
ret
include 'core/mm.asm'
align 4
@ -398,8 +330,6 @@ high_code:
; MEMORY MODEL
call init_mem
mov ecx, 1280*1024
fastcall _balloc
mov [_display_data], eax
@ -437,8 +367,8 @@ high_code:
call init_kernel_heap ; FIXME initialize heap after pager
call init_page_map
call _init_mm
mov [pg_data.pg_mutex], 0
; SAVE REAL MODE VARIABLES
mov ax, [BOOT_VAR + 0x9031]
@ -797,7 +727,7 @@ no_lib_load:
cld
rep movsd
mov dword [SLOT_BASE+256+APPDATA.fpu_handler], eax
mov dword [SLOT_BASE+256+APPDATA.fpu_handler], eax
mov dword [SLOT_BASE+256+APPDATA.sse_handler], eax
mov ebx, SLOT_BASE+256+APP_OBJ_OFFSET
@ -815,7 +745,7 @@ no_lib_load:
mov [TASK_DATA+TASKDATA.pid], 1 ; process id number
mov [TASK_DATA+TASKDATA.mem_start], 0 ; process base address
call init_cursors
call init_cursors
mov eax, [def_cursor]
mov [SLOT_BASE+APPDATA.cursor],eax
mov [SLOT_BASE+APPDATA.cursor+256],eax