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
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
{ .bpp dd ?
.scanline dd ?

View File

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

View File

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

View File

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

View File

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

View File

@ -128,3 +128,11 @@ macro list_add_tail new, 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
}