merge kolibri-acpi #2151

git-svn-id: svn://kolibrios.org@2154 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2011-09-04 16:41:24 +00:00
parent 6e00c935d0
commit 1804fc6d05
6 changed files with 138 additions and 237 deletions

View File

@ -593,20 +593,6 @@ virtual at 0
display_t display_t display_t display_t
end virtual end virtual
struc HEAP_DATA
{
.mutex rd 1
.refcount rd 1
.heap_base rd 1
.heap_top rd 1
.app_mem rd 1
}
HEAP_DATA_SIZE equ 20
virtual at 0
HEAP_DATA HEAP_DATA
end virtual
struc BOOT_DATA struc BOOT_DATA
{ .bpp dd ? { .bpp dd ?
.scanline dd ? .scanline dd ?

View File

@ -9,17 +9,17 @@ $Revision$
struc MEM_BLOCK struc MEM_BLOCK
{ .next_block dd ? {
.list LHEAD
.next_block dd ? ;+8
.prev_block dd ? ;+4 .prev_block dd ? ;+4
.list_fd dd ? ;+8
.list_bk dd ? ;+12
.base dd ? ;+16 .base dd ? ;+16
.size dd ? ;+20 .size dd ? ;+20
.flags dd ? ;+24 .flags dd ? ;+24
.handle dd ? ;+28 .handle dd ? ;+28
.sizeof:
} }
MEM_LIST_OFFSET equ 8
FREE_BLOCK equ 4 FREE_BLOCK equ 4
USED_BLOCK equ 8 USED_BLOCK equ 8
DONT_FREE_BLOCK equ 10h DONT_FREE_BLOCK equ 10h
@ -28,12 +28,11 @@ virtual at 0
MEM_BLOCK MEM_BLOCK MEM_BLOCK MEM_BLOCK
end virtual end virtual
MEM_BLOCK_SIZE equ 8*4
block_next equ MEM_BLOCK.next_block block_next equ MEM_BLOCK.next_block
block_prev equ MEM_BLOCK.prev_block block_prev equ MEM_BLOCK.prev_block
list_fd equ MEM_BLOCK.list_fd list_fd equ MEM_BLOCK.list.next
list_bk equ MEM_BLOCK.list_bk list_bk equ MEM_BLOCK.list.prev
block_base equ MEM_BLOCK.base block_base equ MEM_BLOCK.base
block_size equ MEM_BLOCK.size block_size equ MEM_BLOCK.size
block_flags equ MEM_BLOCK.flags block_flags equ MEM_BLOCK.flags
@ -47,37 +46,6 @@ macro calc_index op
@@: @@:
} }
macro remove_from_list op
{ mov edx, [op+list_fd]
mov ecx, [op+list_bk]
test edx, edx
jz @f
mov [edx+list_bk], ecx
@@:
test ecx, ecx
jz @f
mov [ecx+list_fd], edx
@@:
mov [op+list_fd],0
mov [op+list_bk],0
}
macro remove_from_free op
{
remove_from_list op
mov eax, [op+block_size]
calc_index eax
cmp [mem_block_list+eax*4], op
jne @f
mov [mem_block_list+eax*4], edx
@@:
cmp [mem_block_list+eax*4], 0
jne @f
btr [mem_block_mask], eax
@@:
}
macro remove_from_used op macro remove_from_used op
{ {
mov edx, [op+list_fd] mov edx, [op+list_fd]
@ -88,25 +56,25 @@ macro remove_from_used op
mov [op+list_bk], 0 mov [op+list_bk], 0
} }
;Initial heap state
;
;+heap_size terminator USED_BLOCK
;+4096*MEM_BLOCK.sizeof free space FREE_BLOCK
;HEAP_BASE heap_descriptors USED_BLOCK
;
align 4 align 4
proc init_kernel_heap proc init_kernel_heap
mov ecx, 64 mov ecx, 64
mov edi, mem_block_list mov edi, mem_block_list
xor eax, eax @@:
cld mov eax, edi
rep stosd stosd
stosd
loop @B
mov ecx, 512/4 mov eax, mem_used.fd
mov edi, mem_block_map
not eax
rep stosd
mov [mem_block_start], mem_block_map
mov [mem_block_end], mem_block_map+512
mov [mem_block_arr], HEAP_BASE
mov eax, mem_used.fd-MEM_LIST_OFFSET
mov [mem_used.fd], eax mov [mem_used.fd], eax
mov [mem_used.bk], eax mov [mem_used.bk], eax
@ -121,26 +89,34 @@ proc init_kernel_heap
dec ecx dec ecx
jnz .l1 jnz .l1
mov edi, HEAP_BASE mov edi, HEAP_BASE ;descriptors
mov ebx, HEAP_BASE+MEM_BLOCK_SIZE mov ebx, HEAP_BASE+MEM_BLOCK.sizeof ;free space
mov ecx, HEAP_BASE+MEM_BLOCK.sizeof*2 ;terminator
xor eax, eax xor eax, eax
mov [edi+block_next], ebx mov [edi+block_next], ebx
mov [edi+block_prev], eax mov [edi+block_prev], eax
mov [edi+list_fd], eax mov [edi+list_fd], eax
mov [edi+list_bk], eax mov [edi+list_bk], eax
mov [edi+block_base], HEAP_BASE mov [edi+block_base], HEAP_BASE
mov [edi+block_size], 4096*MEM_BLOCK_SIZE mov [edi+block_size], 4096*MEM_BLOCK.sizeof
mov [edi+block_flags], USED_BLOCK mov [edi+block_flags], USED_BLOCK
mov [ebx+block_next], eax mov [ecx+block_next], eax
mov [ebx+block_prev], eax mov [ecx+block_prev], ebx
mov [ebx+list_fd], eax mov [edi+list_fd], eax
mov [ebx+list_bk], eax mov [edi+list_bk], eax
mov [ebx+block_base], HEAP_BASE+4096*MEM_BLOCK_SIZE mov [edi+block_base], eax
mov [edi+block_size], eax
mov [edi+block_flags], USED_BLOCK
mov [ebx+block_next], ecx
mov [ebx+block_prev], edi
mov [ebx+block_base], HEAP_BASE+4096*MEM_BLOCK.sizeof
mov ecx, [pg_data.kernel_pages] mov ecx, [pg_data.kernel_pages]
shl ecx, 12 shl ecx, 12
sub ecx, HEAP_BASE-OS_BASE+4096*MEM_BLOCK_SIZE sub ecx, HEAP_BASE-OS_BASE+4096*MEM_BLOCK.sizeof
mov [heap_size], ecx mov [heap_size], ecx
mov [heap_free], ecx mov [heap_free], ecx
mov [ebx+block_size], ecx mov [ebx+block_size], ecx
@ -149,12 +125,25 @@ proc init_kernel_heap
mov [mem_block_mask], eax mov [mem_block_mask], eax
mov [mem_block_mask+4],0x80000000 mov [mem_block_mask+4],0x80000000
mov [mem_block_list+63*4], ebx mov ecx, mem_block_list+63*8
mov byte [mem_block_map], 0xFC list_add ebx, ecx
mov ecx, 4096-3-1
mov eax, HEAP_BASE+MEM_BLOCK.sizeof*4
mov [next_memblock], HEAP_BASE+MEM_BLOCK.sizeof*3
@@:
mov [eax-MEM_BLOCK.sizeof], eax
add eax, MEM_BLOCK.sizeof
loop @B
mov [eax-MEM_BLOCK.sizeof], dword 0
mov ecx, heap_mutex mov ecx, heap_mutex
call mutex_init call mutex_init
mov [heap_blocks], 4095 mov [heap_blocks], 4094
mov [free_blocks], 4094 mov [free_blocks], 4093
ret ret
endp endp
@ -191,11 +180,18 @@ get_small_block:
bsf edi, edx bsf edi, edx
jz .high_mask jz .high_mask
add ebx, edi add ebx, edi
mov edi, [mem_block_list+ebx*4] lea ecx, [mem_block_list+ebx*8]
.check_size: mov edi, ecx
.next:
mov edi, [edi+list_fd]
cmp edi, ecx
je .err
cmp eax, [edi+block_size] cmp eax, [edi+block_size]
ja .next ja .next
ret ret
.err:
xor edi, edi
ret
.high_mask: .high_mask:
add esi, 4 add esi, 4
@ -204,65 +200,23 @@ get_small_block:
add ebx, 32 add ebx, 32
mov edx, [esi] mov edx, [esi]
jmp .find jmp .find
.next:
mov edi, [edi+list_fd]
test edi, edi
jnz .check_size
.err:
xor edi, edi
ret
align 4
alloc_mem_block:
mov ebx, [mem_block_start]
mov ecx, [mem_block_end]
.l1:
bsf eax,[ebx];
jnz found
add ebx,4
cmp ebx, ecx
jb .l1
xor eax,eax
ret
found:
btr [ebx], eax
mov [mem_block_start],ebx
sub ebx, mem_block_map
lea eax,[eax+ebx*8]
shl eax, 5
add eax, [mem_block_arr]
dec [free_blocks]
ret
align 4 align 4
free_mem_block: free_mem_block:
mov dword [eax], 0 mov ebx, [next_memblock]
mov dword [eax+4], 0 mov [eax], ebx
mov dword [eax+8], 0 mov [next_memblock], eax
mov dword [eax+12], 0 xor ebx, ebx
mov dword [eax+16], 0
; mov dword [eax+20], 0
mov dword [eax+24], 0
mov dword [eax+28], 0
sub eax, [mem_block_arr] mov dword [eax+4], ebx
shr eax, 5 mov dword [eax+8], ebx
mov dword [eax+12], ebx
mov ebx, mem_block_map mov dword [eax+16], ebx
bts [ebx], eax ; mov dword [eax+20], 0 ;don't clear block size
mov dword [eax+24], ebx
mov dword [eax+28], ebx
inc [free_blocks] inc [free_blocks]
shr eax, 3
and eax, not 3
add eax, ebx
cmp [mem_block_start], eax
ja @f
ret
@@:
mov [mem_block_start], eax
ret
.err:
xor eax, eax
ret ret
align 4 align 4
@ -273,9 +227,6 @@ proc alloc_kernel_space stdcall, size:dword
push esi push esi
push edi push edi
mov ecx, heap_mutex
call mutex_lock
mov eax, [size] mov eax, [size]
add eax, 4095 add eax, 4095
and eax, not 4095 and eax, not 4095
@ -284,12 +235,17 @@ proc alloc_kernel_space stdcall, size:dword
cmp eax, [heap_free] cmp eax, [heap_free]
ja .error ja .error
mov ecx, heap_mutex
call mutex_lock
mov eax, [size]
call get_small_block ; eax call get_small_block ; eax
test edi, edi test edi, edi
jz .error jz .error_unlock
cmp [edi+block_flags], FREE_BLOCK cmp [edi+block_flags], FREE_BLOCK
jne .error jne .error_unlock
mov [block_ind], ebx ;index of allocated block mov [block_ind], ebx ;index of allocated block
@ -297,11 +253,13 @@ proc alloc_kernel_space stdcall, size:dword
cmp eax, [size] cmp eax, [size]
je .m_eq_size je .m_eq_size
call alloc_mem_block mov esi, [next_memblock] ;new memory block
and eax, eax test esi, esi
jz .error jz .error_unlock
mov esi, eax ;esi - splitted block dec [free_blocks]
mov eax, [esi]
mov [next_memblock], eax
mov [esi+block_next], edi mov [esi+block_next], edi
mov eax, [edi+block_prev] mov eax, [edi+block_prev]
@ -309,10 +267,8 @@ proc alloc_kernel_space stdcall, size:dword
mov [edi+block_prev], esi mov [edi+block_prev], esi
mov [esi+list_fd], 0 mov [esi+list_fd], 0
mov [esi+list_bk], 0 mov [esi+list_bk], 0
and eax, eax
jz @f
mov [eax+block_next], esi mov [eax+block_next], esi
@@:
mov ebx, [edi+block_base] mov ebx, [edi+block_base]
mov [esi+block_base], ebx mov [esi+block_base], ebx
mov edx, [size] mov edx, [size]
@ -321,34 +277,23 @@ proc alloc_kernel_space stdcall, size:dword
sub [edi+block_size], edx sub [edi+block_size], edx
mov eax, [edi+block_size] mov eax, [edi+block_size]
shr eax, 12 calc_index eax
sub eax, 1
cmp eax, 63
jna @f
mov eax, 63
@@:
cmp eax, [block_ind] cmp eax, [block_ind]
je .m_eq_ind je .m_eq_ind
remove_from_list edi list_del edi
mov ecx, [block_ind] mov ecx, [block_ind]
mov [mem_block_list+ecx*4], edx lea edx, [mem_block_list+ecx*8]
cmp edx, [edx]
test edx, edx
jnz @f jnz @f
btr [mem_block_mask], ecx btr [mem_block_mask], ecx
@@: @@:
mov edx, [mem_block_list+eax*4]
mov [edi+list_fd], edx
test edx, edx
jz @f
mov [edx+list_bk], edi
@@:
mov [mem_block_list+eax*4], edi
bts [mem_block_mask], eax bts [mem_block_mask], eax
lea edx, [mem_block_list+eax*8] ;edx= list head
list_add edi, edx
.m_eq_ind: .m_eq_ind:
mov ecx, mem_used.fd-MEM_LIST_OFFSET mov ecx, mem_used.fd
mov edx, [ecx+list_fd] mov edx, [ecx+list_fd]
mov [esi+list_fd], edx mov [esi+list_fd], edx
mov [esi+list_bk], ecx mov [esi+list_bk], ecx
@ -366,13 +311,13 @@ proc alloc_kernel_space stdcall, size:dword
pop ebx pop ebx
ret ret
.m_eq_size: .m_eq_size:
remove_from_list edi list_del edi
mov [mem_block_list+ebx*4], edx lea edx, [mem_block_list+ebx*8]
and edx, edx cmp edx, [edx]
jnz @f jnz @f
btr [mem_block_mask], ebx btr [mem_block_mask], ebx
@@: @@:
mov ecx, mem_used.fd-MEM_LIST_OFFSET mov ecx, mem_used.fd
mov edx, [ecx+list_fd] mov edx, [ecx+list_fd]
mov [edi+list_fd], edx mov [edi+list_fd], edx
mov [edi+list_bk], ecx mov [edi+list_bk], ecx
@ -389,9 +334,11 @@ proc alloc_kernel_space stdcall, size:dword
pop esi pop esi
pop ebx pop ebx
ret ret
.error:
.error_unlock:
mov ecx, heap_mutex mov ecx, heap_mutex
call mutex_unlock call mutex_unlock
.error:
xor eax, eax xor eax, eax
pop edi pop edi
pop esi pop esi
@ -401,9 +348,6 @@ endp
align 4 align 4
proc free_kernel_space stdcall uses ebx ecx edx esi edi, base:dword proc free_kernel_space stdcall uses ebx ecx edx esi edi, base:dword
push ebx
push esi
push edi
mov ecx, heap_mutex mov ecx, heap_mutex
call mutex_lock call mutex_lock
@ -411,7 +355,7 @@ proc free_kernel_space stdcall uses ebx ecx edx esi edi, base:dword
mov eax, [base] mov eax, [base]
mov esi, [mem_used.fd] mov esi, [mem_used.fd]
@@: @@:
cmp esi, mem_used.fd-MEM_LIST_OFFSET cmp esi, mem_used.fd
je .fail je .fail
cmp [esi+block_base], eax cmp [esi+block_base], eax
@ -426,31 +370,28 @@ proc free_kernel_space stdcall uses ebx ecx edx esi edi, base:dword
add [heap_free], eax add [heap_free], eax
mov edi, [esi+block_next] mov edi, [esi+block_next]
test edi, edi
jz .prev
cmp [edi+block_flags], FREE_BLOCK cmp [edi+block_flags], FREE_BLOCK
jne .prev jne .prev
remove_from_free edi list_del edi
mov edx, [edi+block_next] mov edx, [edi+block_next]
mov [esi+block_next], edx mov [esi+block_next], edx
test edx, edx
jz @f
mov [edx+block_prev], esi mov [edx+block_prev], esi
@@:
mov ecx, [edi+block_size] mov ecx, [edi+block_size]
add [esi+block_size], ecx add [esi+block_size], ecx
calc_index ecx
lea edx, [mem_block_list+ecx*8]
cmp edx, [edx]
jne @F
btr [mem_block_mask], ecx
@@:
mov eax, edi mov eax, edi
call free_mem_block call free_mem_block
.prev: .prev:
mov edi, [esi+block_prev] mov edi, [esi+block_prev]
test edi, edi
jz .insert
cmp [edi+block_flags], FREE_BLOCK cmp [edi+block_flags], FREE_BLOCK
jne .insert jne .insert
@ -458,10 +399,8 @@ proc free_kernel_space stdcall uses ebx ecx edx esi edi, base:dword
mov edx, [esi+block_next] mov edx, [esi+block_next]
mov [edi+block_next], edx mov [edi+block_next], edx
test edx, edx
jz @f
mov [edx+block_prev], edi mov [edx+block_prev], edi
@@:
mov eax, esi mov eax, esi
call free_mem_block call free_mem_block
@ -470,70 +409,41 @@ proc free_kernel_space stdcall uses ebx ecx edx esi edi, base:dword
add eax, ecx add eax, ecx
mov [edi+block_size], eax mov [edi+block_size], eax
calc_index eax calc_index eax ;new index
calc_index ecx calc_index ecx ;old index
cmp eax, ecx cmp eax, ecx
je .m_eq je .m_eq
push ecx push ecx
remove_from_list edi list_del edi
pop ecx pop ecx
cmp [mem_block_list+ecx*4], edi lea edx, [mem_block_list+ecx*8]
jne @f cmp edx, [edx]
mov [mem_block_list+ecx*4], edx jne .add_block
@@:
cmp [mem_block_list+ecx*4], 0
jne @f
btr [mem_block_mask], ecx btr [mem_block_mask], ecx
@@: .add_block:
mov esi, [mem_block_list+eax*4]
mov [mem_block_list+eax*4], edi
mov [edi+list_fd], esi
test esi, esi
jz @f
mov [esi+list_bk], edi
@@:
bts [mem_block_mask], eax bts [mem_block_mask], eax
lea edx, [mem_block_list+eax*8]
list_add edi, edx
.m_eq: .m_eq:
mov ecx, heap_mutex mov ecx, heap_mutex
call mutex_unlock call mutex_unlock
xor eax, eax xor eax, eax
not eax not eax
pop edi
pop esi
pop ebx
ret ret
.insert: .insert:
remove_from_used esi remove_from_used esi
mov [esi+block_flags], FREE_BLOCK
mov eax, [esi+block_size] mov eax, [esi+block_size]
calc_index eax calc_index eax
mov edi, esi
jmp .add_block
mov edi, [mem_block_list+eax*4]
mov [mem_block_list+eax*4], esi
mov [esi+list_fd], edi
test edi, edi
jz @f
mov [edi+list_bk], esi
@@:
bts [mem_block_mask], eax
mov [esi+block_flags],FREE_BLOCK
mov ecx, heap_mutex
call mutex_unlock
xor eax, eax
not eax
pop edi
pop esi
pop ebx
ret
.fail: .fail:
mov ecx, heap_mutex mov ecx, heap_mutex
call mutex_unlock call mutex_unlock
xor eax, eax xor eax, eax
pop edi
pop esi
pop ebx
ret ret
endp endp
@ -621,7 +531,7 @@ proc kernel_free stdcall, base:dword
mov eax, [base] mov eax, [base]
mov esi, [mem_used.fd] mov esi, [mem_used.fd]
@@: @@:
cmp esi, mem_used.fd-MEM_LIST_OFFSET cmp esi, mem_used.fd
je .fail je .fail
cmp [esi+block_base], eax cmp [esi+block_base], eax

View File

@ -193,7 +193,7 @@ iglobal
dd file_system_lfn ; 70-Common file system interface, version 2 dd file_system_lfn ; 70-Common file system interface, version 2
dd syscall_window_settings ; 71-Window settings dd syscall_window_settings ; 71-Window settings
dd sys_sendwindowmsg ; 72-Send window message dd sys_sendwindowmsg ; 72-Send window message
dd blit_32 ; blitter; dd blit_32 ; 73-blitter;
times 255 - ( ($-servetable2) /4 ) dd undefined_syscall times 255 - ( ($-servetable2) /4 ) dd undefined_syscall
dd sys_end ; -1-end application dd sys_end ; -1-end application

View File

@ -297,18 +297,15 @@ align 16
cur_saved_data rb 4096 cur_saved_data rb 4096
fpu_data: rb 512 fpu_data: rb 512
mem_block_map rb 512 mem_block_list rd 64*2
mem_block_list rd 64
large_block_list rd 31
mem_block_mask rd 2 mem_block_mask rd 2
large_block_mask rd 1
mem_used.fd rd 1 mem_used.fd rd 1
mem_used.bk rd 1 mem_used.bk rd 1
mem_block_arr rd 1 mem_hash_cnt rd 64
mem_block_start rd 1
mem_block_end rd 1 next_memblock rd 1
heap_mutex MUTEX heap_mutex MUTEX
heap_size rd 1 heap_size rd 1

View File

@ -226,7 +226,7 @@ B32:
mov fs,ax mov fs,ax
mov gs,ax mov gs,ax
mov ss,ax mov ss,ax
mov esp,0x3ec00 ; Set stack mov esp,0x5ec00 ; Set stack
; CLEAR 0x280000 - HEAP_BASE ; CLEAR 0x280000 - HEAP_BASE

View File

@ -128,3 +128,11 @@ macro list_add_tail new, head
__list_add new, eax, head __list_add new, eax, head
} }
macro list_del entry
{
mov edx, [entry+list_fd]
mov ecx, [entry+list_bk]
mov [edx+list_bk], ecx
mov [ecx+list_fd], edx
}