1) small heap
2) malloc
3) background image

git-svn-id: svn://kolibrios.org@861 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2008-09-11 20:26:49 +00:00
parent d10c087a12
commit f806f6b7f8
10 changed files with 172 additions and 118 deletions

View File

@ -195,6 +195,7 @@ app_page_tabs equ 0xDF800000
OS_TEMP equ 0xDFC00000
heap_tabs equ (page_tabs+ (HEAP_BASE shr 10))
kernel_tabs equ (page_tabs+ (OS_BASE shr 10)) ;0xFDE00000
master_tab equ (page_tabs+ (page_tabs shr 10)) ;0xFDFF70000
@ -280,7 +281,7 @@ MOUSE_BACKGROUND equ (OS_BASE+0x000FFF4)
DONT_DRAW_MOUSE equ (OS_BASE+0x000FFF5)
DONT_SWITCH equ (OS_BASE+0x000FFFF)
TMP_STACK_TOP equ 0x006CC00
;TMP_STACK_TOP equ 0x006CC00
FONT_II equ (OS_BASE+0x006DC00)
FONT_I equ (OS_BASE+0x006E600)
@ -296,8 +297,6 @@ TMP_BUFF equ (OS_BASE+0x0090000)
VGABasePtr equ (OS_BASE+0x00A0000)
;RAMDISK equ (OS_BASE+0x0100000)
RAMDISK_FAT equ (OS_BASE+0x0180000)
FLOPPY_FAT equ (OS_BASE+0x0182000)

View File

@ -110,7 +110,7 @@ md_t* __fastcall find_large_md(size_t size)
md_t *new_md = (md_t*)slab_alloc(md_slab,0);
link_initialize(&new_md->link);
list_insert(&md->adj, &new_md->adj);
list_insert(&new_md->adj, &md->adj);
new_md->base = md->base;
new_md->size = size;
@ -144,19 +144,34 @@ md_t* __fastcall find_small_md(size_t size)
idx0 = (size>>12) - 1 < 32 ? (size>>12) - 1 : 31;
mask = sheap.availmask & ( -1<<idx0 );
//printf("smask %x size %x idx0 %x mask %x\n",sheap.availmask, size, idx0, mask);
if(mask)
{
md_t *tmp;
idx0 = _bsf(mask);
ASSERT( !list_empty(&sheap.list[idx0]))
md = (md_t*)sheap.list[idx0].next;
tmp = (md_t*)sheap.list[idx0].next;
list_remove((link_t*)md);
if(list_empty(&sheap.list[idx0]))
_reset_smask(idx0);
}
else
while((link_t*)tmp != &sheap.list[idx0])
{
if(tmp->size >= size)
{
//printf("remove tmp %x\n", tmp);
list_remove((link_t*)tmp);
if(list_empty(&sheap.list[idx0]))
_reset_smask(idx0);
md = tmp;
break;
};
tmp = (md_t*)tmp->link.next;
};
};
if( !md)
{
md_t *lmd;
lmd = find_large_md((size+0x3FFFFF)&~0x3FFFFF);
@ -181,7 +196,7 @@ md_t* __fastcall find_small_md(size_t size)
md_t *new_md = (md_t*)slab_alloc(md_slab,0);
link_initialize(&new_md->link);
list_insert(&md->adj, &new_md->adj);
list_insert(&new_md->adj, &md->adj);
new_md->base = md->base;
new_md->size = size;
@ -191,9 +206,30 @@ md_t* __fastcall find_small_md(size_t size)
md->base+= size;
md->size-= size;
idx1 = (md->size>>22) - 1 < 32 ? (md->size>>22) - 1 : 31;
idx1 = (md->size>>12) - 1 < 32 ? (md->size>>12) - 1 : 31;
//printf("insert md %x, base %x size %x idx %x\n", md,md->base, md->size,idx1);
if( idx1 < 31)
list_prepend(&md->link, &sheap.list[idx1]);
else
{
if( list_empty(&sheap.list[31]))
list_prepend(&md->link, &sheap.list[31]);
else
{
md_t *tmp = (md_t*)sheap.list[31].next;
while((link_t*)tmp != &sheap.list[31])
{
if(md->base < tmp->base)
break;
tmp = (md_t*)tmp->link.next;
}
list_insert(&md->link, &tmp->link);
};
};
list_prepend(&md->link, &sheap.list[idx1]);
_set_smask(idx1);
safe_sti(efl);
@ -282,6 +318,8 @@ void* __stdcall alloc_kernel_space(size_t size)
size = (size+4095)&~4095;
md = find_small_md(size);
// printf("alloc_kernel_space: %x size %x\n\n",md->base, size);
if( md )
return (void*)md->base;
return NULL;

View File

@ -36,14 +36,14 @@ void init()
module_t *mod;
int i;
printf ("mods_count = %d, mods_addr = 0x%x\n",
(u32_t) boot_mbi->mods_count, (u32_t) boot_mbi->mods_addr);
// printf ("mods_count = %d, mods_addr = 0x%x\n",
// (u32_t) boot_mbi->mods_count, (u32_t) boot_mbi->mods_addr);
for (i = 0, mod = (module_t *) boot_mbi->mods_addr;
i < boot_mbi->mods_count;i++, mod++)
{
pg_balloc = mod->mod_end;
printf (" mod_start = 0x%x, mod_end = 0x%x, string = %s\n",
(u32_t) mod->mod_start,(u32_t) mod->mod_end, (char *) mod->string);
// printf (" mod_start = 0x%x, mod_end = 0x%x, string = %s\n",
// (u32_t) mod->mod_start,(u32_t) mod->mod_end, (char *) mod->string);
};
mod--;
rd_base = mod->mod_start+OS_BASE;
@ -51,7 +51,7 @@ void init()
rd_fat_end = rd_base + 512 + 4278;
rd_root = rd_base + 512*19;
rd_root_end = rd_base + 512*33;
printf(" rd_base = %x\n", rd_base);
// printf(" rd_base = %x\n", rd_base);
}
if (CHECK_FLAG (boot_mbi->flags, 6))
@ -59,8 +59,8 @@ void init()
memory_map_t *mmap;
u32_t page;
printf ("mmap_addr = 0x%x, mmap_length = 0x%x\n",
(unsigned) boot_mbi->mmap_addr, (unsigned) boot_mbi->mmap_length);
// printf ("mmap_addr = 0x%x, mmap_length = 0x%x\n",
// (unsigned) boot_mbi->mmap_addr, (unsigned) boot_mbi->mmap_length);
for (mmap = (memory_map_t *) boot_mbi->mmap_addr;
(u32_t) mmap < boot_mbi->mmap_addr + boot_mbi->mmap_length;
@ -68,7 +68,7 @@ void init()
+ mmap->size + sizeof (mmap->size)))
{
u32_t page;
/*
printf (" size = 0x%x, base_addr = 0x%x%x,"
" length = 0x%x%x, type = 0x%x\n",
(unsigned) mmap->size,
@ -77,7 +77,7 @@ void init()
(unsigned) mmap->length_high,
(unsigned) mmap->length_low,
(unsigned) mmap->type);
*/
if( mmap->type != 1)
continue;
page = (mmap->base_addr_low+mmap->length_low)&(~4095);

View File

@ -986,8 +986,8 @@ init_malloc:
stdcall kernel_alloc, 0x40000
mov [mst.top], eax
mov [mst.topsize], 128*1024
mov dword [eax+4], (128*1024) or 1
mov [mst.topsize], 256*1024
mov dword [eax+4], (256*1024) or 1
mov eax, mst.smallbins
@@:
mov [eax+8], eax

View File

@ -31,27 +31,9 @@ map_space: ;not implemented
align 4
proc free_page
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
ret
endp
proc map_io_mem stdcall, base:dword, size:dword, flags:dword
@ -145,36 +127,17 @@ release_pages:
shr esi, 10
add esi, page_tabs
; mov ebp, [pg_data.pages_free]
; mov ebx, [page_start]
; mov edx, sys_pgmap
@@:
xor eax, eax
xchg eax, [esi]
push eax
invlpg [edi]
pop eax
; 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
; mov ebx, eax
.next:
add edi, 0x1000
add esi, 4
dec ecx
jnz @B
; mov [pg_data.pages_free], ebp
and [pg_data.pg_mutex],0
popad
ret
@ -440,8 +403,6 @@ proc page_fault_handler
mov ebx, [.err_addr]
mov eax, [.err_code]
; xchg bx, bx
cmp ebx, HEAP_BASE
jb .user_space ;ñòðàíèöà â ïàìÿòè ïðèëîæåíèÿ ;
@ -451,40 +412,66 @@ proc page_fault_handler
cmp ebx, page_tabs
jb .lfb
cmp ebx, OS_BASE
jb .core_tabs
cmp ebx, heap_tabs
jb .user_tabs
cmp ebx, OS_BASE
jb .heap_tab
jmp .core_tabs
; cmp ebx, kernel_tabs
; jb .alloc;.app_tabs ;òàáëèöû ñòðàíèö ïðèëîæåíèÿ ;
;ïðîñòî ñîçäàäèì îäíó
.lfb:
shr ebx, 22
mov edx, [_sys_pdbr + ebx*4]
mov [master_tab + ebx*4], edx
jmp .exit
.core_tabs:
.user_tabs:
shr ebx, 12
and ebx, 0x3FF
mov edx, [master_tab + ebx*4]
test edx, PG_MAP
jnz .fail
call _alloc_page
test eax, eax
jz .fail
lea edx, [eax + PG_UW]
lea edi, [eax + OS_BASE]
mov ecx, 1024
xor eax, eax
cld
rep stosd
mov [master_tab + ebx*4], edx
jmp .exit
.heap_tab:
shr ebx, 12
and ebx, 0x3FF
mov edx, [master_tab + ebx*4]
test edx, PG_MAP
jz .check_ptab ;òàáëèöà ñòðàíèö íå ñîçäàíà
jmp .fail
align 4
.kernel_heap:
mov ecx, ebx
shr ebx, 22
mov edx, [master_tab + ebx*4]
test edx, PG_MAP
jz .check_ptab ;òàáëèöà ñòðàíèö íå ñîçäàíà
shr ecx, 12
mov eax, [page_tabs+ecx*4]
jmp .fail
.check_ptab:
mov edx, [_sys_pdbr + ebx*4]

View File

@ -55,10 +55,10 @@ void init_mm()
size_t core_size;
pages = mem_amount >> FRAME_WIDTH;
printf("last page = %x total pages = %x\n",mem_amount, pages);
// printf("last page = %x total pages = %x\n",mem_amount, pages);
conf_size = pages*sizeof(frame_t);
printf("conf_size = %x free mem start =%x\n",conf_size, pg_balloc);
// printf("conf_size = %x free mem start =%x\n",conf_size, pg_balloc);
zone_create(&z_core, 0, pages);
@ -153,7 +153,7 @@ static void zone_reserve(zone_t *z, pfn_t base, count_t count)
if(top > z->base+z->count)
top = z->base+z->count;
printf("zone reserve base %x top %x\n", base, top);
// printf("zone reserve base %x top %x\n", base, top);
for (i = base; i < top; i++)
zone_mark_unavailable(z, i - z->base);
@ -174,7 +174,7 @@ static void zone_release(zone_t *z, pfn_t base, count_t count)
if(top > z->base+z->count)
top = z->base+z->count;
printf("zone release base %x top %x\n", base, top);
// printf("zone release base %x top %x\n", base, top);
for (i = base; i < top; i++) {
z->frames[i-z->base].refcount = 0;
@ -586,6 +586,9 @@ addr_t alloc_page() //obsolete
v = zone_frame_alloc(&z_core, 0);
spinlock_unlock(&z_core.lock);
safe_sti(efl);
//printf("alloc_page: %x\n", v << FRAME_WIDTH);
restore_edx(edx);
return (v << FRAME_WIDTH);
};
@ -604,6 +607,9 @@ addr_t __stdcall alloc_pages(count_t count) //obsolete
v = zone_frame_alloc(&z_core, to_order(count));
spinlock_unlock(&z_core.lock);
safe_sti(efl);
//printf("alloc_pages: %x count %x\n", v << FRAME_WIDTH, count);
restore_edx(edx);
return (v << FRAME_WIDTH);

View File

@ -356,66 +356,77 @@ proc create_app_space stdcall, app_size:dword,img_base:dword,img_size:dword
mov eax, [app_size]
add eax, 4095
and eax, NOT(4095)
and eax, not 4095
mov [app_size], eax
mov ebx, eax
shr eax, 12
mov [app_pages], eax
add ebx, 0x3FFFFF
and ebx, NOT(0x3FFFFF)
and ebx, not 0x3FFFFF
shr ebx, 22
mov [app_tabs], ebx
mov ecx, [img_size]
add ecx, 4095
and ecx, NOT(4095)
and ecx, not 4095
mov [img_size], ecx
shr ecx, 12
mov [img_pages], ecx
if GREEDY_KERNEL
lea eax, [ecx+ebx+2] ;only image size
else
lea eax, [eax+ebx+2] ;all requested memory
end if
; if GREEDY_KERNEL
; lea eax, [ecx+ebx+2] ;only image size
; else
; lea eax, [eax+ebx+2] ;all requested memory
; end if
; cmp eax, [pg_data.pages_free]
; ja .fail
call _alloc_page
test eax, eax
jz .fail
mov [dir_addr], eax
jz .fail
lea edi, [eax + OS_BASE]
mov ecx, (OS_BASE shr 20)/4
xor eax, eax
cld
rep stosd
;lea edi, [eax + OS_BASE]
;mov ecx, (OS_BASE shr 20)/4
;xor eax, eax
;cld
;rep stosd
mov ecx, 1024-(OS_BASE shr 20)/4
mov esi, _sys_pdbr+(OS_BASE shr 20)
rep movsd
;mov ecx, 1024-(OS_BASE shr 20)/4
;mov esi, _sys_pdbr+(OS_BASE shr 20)
;rep movsd
lea edi, [eax+OS_BASE]
mov ecx, 512
xor eax, eax
cld
rep stosd
mov ecx, 512
mov esi, _sys_pdbr+(HEAP_BASE shr 20)
rep movsd
mov edi, [dir_addr]
lea eax, [edi+PG_SW]
mov [edi+OS_BASE+(page_tabs shr 20)], eax
and eax, -4096
mov eax, edi
call set_cr3
mov edx, [app_tabs]
xor edi, edi
mov edx, [app_tabs]
mov edi, master_tab
@@:
call _alloc_page
test eax, eax
jz .fail
stdcall map_page_table, edi, eax
add edi, 0x00400000
dec edx
jnz @B
or eax, PG_UW
stosd
dec edx
jnz @B
mov edi, page_tabs

View File

@ -51,7 +51,7 @@ static inline void list_prepend(link_t *link, link_t *head)
head->next = link;
}
static inline list_insert(link_t *old, link_t *new)
static inline list_insert(link_t *new, link_t *old)
{
new->prev = old->prev;
new->next = old;

View File

@ -399,14 +399,15 @@ __setvars:
mov edi,BOOT_VAR
mov ecx,0x10000 / 4
rep movsd
xor edi, edi
xor eax, eax
mov ecx,0x10000 / 4
rep stosd
mov edi, SLOT_BASE
mov ecx,0x10000 / 4
rep stosd
mov edi, 0x40000
mov ecx, (0x90000-0x40000)/4
rep stosd
mov dword [_sys_pdbr], eax
mov dword [_sys_pdbr+4], eax
@ -634,7 +635,7 @@ __setvars:
call rerouteirqs
; Initialize system V86 machine
call init_sys_v86
call init_sys_v86
; TIMER SET TO 1/100 S
@ -849,9 +850,9 @@ include 'detect/disks.inc'
;protect io permission map
mov esi, [default_io_map]
stdcall map_page,esi,(tss._io_map_0-OS_BASE), PG_MAP
add esi, 0x1000
stdcall map_page,esi,(tss._io_map_1-OS_BASE), PG_MAP
; stdcall map_page,esi,(tss._io_map_0-OS_BASE), PG_MAP
; add esi, 0x1000
; stdcall map_page,esi,(tss._io_map_1-OS_BASE), PG_MAP
; stdcall map_page,tss._io_map_0,\
; (tss._io_map_0-OS_BASE), PG_MAP
@ -2316,21 +2317,27 @@ sys_background:
sbgrr:
ret
nosb1:
nosb1:
cmp ebx,2 ; SET PIXEL
jnz nosb2
cmp ecx,[mem_BACKGROUND]
jae nosb2
mov ebx, [mem_BACKGROUND]
add ebx, 4095
and ebx, -4096
sub ebx, 4
cmp ecx, ebx
ja @F
mov eax,[img_background]
mov ebx,[eax+ecx]
and ebx,0xFF000000 ;255*256*256*256
and edx,0x00FFFFFF ;255*256*256+255*256+255
add edx,ebx
mov [eax+ecx],edx
; mov [bgrchanged],1
@@:
ret
nosb2:
nosb2:
cmp ebx,3 ; DRAW BACKGROUND
jnz nosb3
@ -2474,19 +2481,24 @@ sys_getbackground:
mov ax,[BgrDataHeight]
mov [esp+36],eax
ret
nogb1:
nogb1:
cmp eax,2 ; PIXEL
jnz nogb2
; mov edx,0x160000-16
; cmp edx,ebx
; jbe nogb2
; mov eax, [ebx+IMG_BACKGROUND]
mov ecx, [mem_BACKGROUND]
add ecx, 4095
and ecx, -4096
sub ecx, 4
cmp ebx, ecx
ja @F
mov eax,[img_background]
mov eax,[ebx+eax]
and eax, 0xFFFFFF
mov [esp+36],eax
@@:
ret
nogb2:

View File

@ -15,7 +15,8 @@ KERNEL_SRC:= \
core/heap.inc \
core/taskman.inc \
core/sys32.inc \
core/dll.inc
core/dll.inc \
data32.inc
PE_SRC:= \
init.c \