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 OS_TEMP equ 0xDFC00000
heap_tabs equ (page_tabs+ (HEAP_BASE shr 10))
kernel_tabs equ (page_tabs+ (OS_BASE shr 10)) ;0xFDE00000 kernel_tabs equ (page_tabs+ (OS_BASE shr 10)) ;0xFDE00000
master_tab equ (page_tabs+ (page_tabs shr 10)) ;0xFDFF70000 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_DRAW_MOUSE equ (OS_BASE+0x000FFF5)
DONT_SWITCH equ (OS_BASE+0x000FFFF) DONT_SWITCH equ (OS_BASE+0x000FFFF)
TMP_STACK_TOP equ 0x006CC00 ;TMP_STACK_TOP equ 0x006CC00
FONT_II equ (OS_BASE+0x006DC00) FONT_II equ (OS_BASE+0x006DC00)
FONT_I equ (OS_BASE+0x006E600) FONT_I equ (OS_BASE+0x006E600)
@ -296,8 +297,6 @@ TMP_BUFF equ (OS_BASE+0x0090000)
VGABasePtr equ (OS_BASE+0x00A0000) VGABasePtr equ (OS_BASE+0x00A0000)
;RAMDISK equ (OS_BASE+0x0100000)
RAMDISK_FAT equ (OS_BASE+0x0180000) RAMDISK_FAT equ (OS_BASE+0x0180000)
FLOPPY_FAT equ (OS_BASE+0x0182000) 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); md_t *new_md = (md_t*)slab_alloc(md_slab,0);
link_initialize(&new_md->link); 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->base = md->base;
new_md->size = size; 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; idx0 = (size>>12) - 1 < 32 ? (size>>12) - 1 : 31;
mask = sheap.availmask & ( -1<<idx0 ); mask = sheap.availmask & ( -1<<idx0 );
//printf("smask %x size %x idx0 %x mask %x\n",sheap.availmask, size, idx0, mask);
if(mask) if(mask)
{ {
md_t *tmp;
idx0 = _bsf(mask); idx0 = _bsf(mask);
ASSERT( !list_empty(&sheap.list[idx0])) 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); 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])) if(list_empty(&sheap.list[idx0]))
_reset_smask(idx0); _reset_smask(idx0);
} md = tmp;
else break;
};
tmp = (md_t*)tmp->link.next;
};
};
if( !md)
{ {
md_t *lmd; md_t *lmd;
lmd = find_large_md((size+0x3FFFFF)&~0x3FFFFF); 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); md_t *new_md = (md_t*)slab_alloc(md_slab,0);
link_initialize(&new_md->link); 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->base = md->base;
new_md->size = size; new_md->size = size;
@ -191,9 +206,30 @@ md_t* __fastcall find_small_md(size_t size)
md->base+= size; md->base+= size;
md->size-= 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]); 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);
};
};
_set_smask(idx1); _set_smask(idx1);
safe_sti(efl); safe_sti(efl);
@ -282,6 +318,8 @@ void* __stdcall alloc_kernel_space(size_t size)
size = (size+4095)&~4095; size = (size+4095)&~4095;
md = find_small_md(size); md = find_small_md(size);
// printf("alloc_kernel_space: %x size %x\n\n",md->base, size);
if( md ) if( md )
return (void*)md->base; return (void*)md->base;
return NULL; return NULL;

View File

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

View File

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

View File

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

View File

@ -55,10 +55,10 @@ void init_mm()
size_t core_size; size_t core_size;
pages = mem_amount >> FRAME_WIDTH; 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); 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); 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) if(top > z->base+z->count)
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++) for (i = base; i < top; i++)
zone_mark_unavailable(z, i - z->base); 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) if(top > z->base+z->count)
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++) { for (i = base; i < top; i++) {
z->frames[i-z->base].refcount = 0; z->frames[i-z->base].refcount = 0;
@ -586,6 +586,9 @@ addr_t alloc_page() //obsolete
v = zone_frame_alloc(&z_core, 0); v = zone_frame_alloc(&z_core, 0);
spinlock_unlock(&z_core.lock); spinlock_unlock(&z_core.lock);
safe_sti(efl); safe_sti(efl);
//printf("alloc_page: %x\n", v << FRAME_WIDTH);
restore_edx(edx); restore_edx(edx);
return (v << FRAME_WIDTH); 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)); v = zone_frame_alloc(&z_core, to_order(count));
spinlock_unlock(&z_core.lock); spinlock_unlock(&z_core.lock);
safe_sti(efl); safe_sti(efl);
//printf("alloc_pages: %x count %x\n", v << FRAME_WIDTH, count);
restore_edx(edx); restore_edx(edx);
return (v << FRAME_WIDTH); return (v << FRAME_WIDTH);

View File

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

View File

@ -51,7 +51,7 @@ static inline void list_prepend(link_t *link, link_t *head)
head->next = link; 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->prev = old->prev;
new->next = old; new->next = old;

View File

@ -399,13 +399,14 @@ __setvars:
mov edi,BOOT_VAR mov edi,BOOT_VAR
mov ecx,0x10000 / 4 mov ecx,0x10000 / 4
rep movsd rep movsd
xor edi, edi xor edi, edi
xor eax, eax xor eax, eax
mov ecx,0x10000 / 4 mov ecx,0x10000 / 4
rep stosd rep stosd
mov edi, SLOT_BASE mov edi, 0x40000
mov ecx,0x10000 / 4 mov ecx, (0x90000-0x40000)/4
rep stosd rep stosd
mov dword [_sys_pdbr], eax mov dword [_sys_pdbr], eax
@ -849,9 +850,9 @@ include 'detect/disks.inc'
;protect io permission map ;protect io permission map
mov esi, [default_io_map] mov esi, [default_io_map]
stdcall map_page,esi,(tss._io_map_0-OS_BASE), PG_MAP ; stdcall map_page,esi,(tss._io_map_0-OS_BASE), PG_MAP
add esi, 0x1000 ; add esi, 0x1000
stdcall map_page,esi,(tss._io_map_1-OS_BASE), PG_MAP ; stdcall map_page,esi,(tss._io_map_1-OS_BASE), PG_MAP
; stdcall map_page,tss._io_map_0,\ ; stdcall map_page,tss._io_map_0,\
; (tss._io_map_0-OS_BASE), PG_MAP ; (tss._io_map_0-OS_BASE), PG_MAP
@ -2320,16 +2321,22 @@ sys_background:
cmp ebx,2 ; SET PIXEL cmp ebx,2 ; SET PIXEL
jnz nosb2 jnz nosb2
cmp ecx,[mem_BACKGROUND] mov ebx, [mem_BACKGROUND]
jae nosb2 add ebx, 4095
and ebx, -4096
sub ebx, 4
cmp ecx, ebx
ja @F
mov eax,[img_background] mov eax,[img_background]
mov ebx,[eax+ecx] mov ebx,[eax+ecx]
and ebx,0xFF000000 ;255*256*256*256 and ebx,0xFF000000 ;255*256*256*256
and edx,0x00FFFFFF ;255*256*256+255*256+255 and edx,0x00FFFFFF ;255*256*256+255*256+255
add edx,ebx add edx,ebx
mov [eax+ecx],edx mov [eax+ecx],edx
; mov [bgrchanged],1 @@:
ret ret
nosb2: nosb2:
cmp ebx,3 ; DRAW BACKGROUND cmp ebx,3 ; DRAW BACKGROUND
@ -2474,19 +2481,24 @@ sys_getbackground:
mov ax,[BgrDataHeight] mov ax,[BgrDataHeight]
mov [esp+36],eax mov [esp+36],eax
ret ret
nogb1: nogb1:
cmp eax,2 ; PIXEL cmp eax,2 ; PIXEL
jnz nogb2 jnz nogb2
; mov edx,0x160000-16 mov ecx, [mem_BACKGROUND]
; cmp edx,ebx add ecx, 4095
; jbe nogb2 and ecx, -4096
; mov eax, [ebx+IMG_BACKGROUND] sub ecx, 4
cmp ebx, ecx
ja @F
mov eax,[img_background] mov eax,[img_background]
mov eax,[ebx+eax] mov eax,[ebx+eax]
and eax, 0xFFFFFF and eax, 0xFFFFFF
mov [esp+36],eax mov [esp+36],eax
@@:
ret ret
nogb2: nogb2:

View File

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