From d08f862229499ad1a1d70f48432c09a69b9edb49 Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Fri, 12 Sep 2008 10:56:47 +0000 Subject: [PATCH] fixed ASSERT conditions git-svn-id: svn://kolibrios.org@862 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/branches/kolibri_pe/core/heap.c | 92 ++++++++++++++-------- kernel/branches/kolibri_pe/core/init.c | 36 ++++----- kernel/branches/kolibri_pe/core/memory.inc | 5 +- kernel/branches/kolibri_pe/core/mm.c | 12 +-- kernel/branches/kolibri_pe/include/core.h | 7 ++ kernel/branches/kolibri_pe/kernel.asm | 3 + kernel/branches/kolibri_pe/makefile | 17 +++- 7 files changed, 112 insertions(+), 60 deletions(-) diff --git a/kernel/branches/kolibri_pe/core/heap.c b/kernel/branches/kolibri_pe/core/heap.c index b7c21522e5..6eee756e75 100644 --- a/kernel/branches/kolibri_pe/core/heap.c +++ b/kernel/branches/kolibri_pe/core/heap.c @@ -49,8 +49,8 @@ int __fastcall init_heap(addr_t base, size_t size) ASSERT(base != 0); ASSERT(size != 0) - ASSERT(base & 0x3FFFFF == 0); - ASSERT(size & 0x3FFFFF == 0); + ASSERT((base & 0x3FFFFF) == 0); + ASSERT((size & 0x3FFFFF) == 0); for (i = 0; i < 32; i++) { @@ -84,18 +84,36 @@ md_t* __fastcall find_large_md(size_t size) count_t idx0; u32_t mask; - ASSERT(size & 0x3FFFFF == 0); + ASSERT((size & 0x3FFFFF) == 0); idx0 = (size>>22) - 1 < 32 ? (size>>22) - 1 : 31; mask = lheap.availmask & ( -1<size >= size) + { + DBG("remove large tmp %x\n", tmp); - ASSERT( !list_empty(&lheap.list[idx0])) + md = tmp; + break; + }; + }; + tmp = (md_t*)tmp->link.next; + } + else + { + idx0 = _bsf(mask); - md = (md_t*)lheap.list[idx0].next; + ASSERT( !list_empty(&lheap.list[idx0])) + + md = (md_t*)lheap.list[idx0].next; + }; } else return NULL; @@ -137,44 +155,53 @@ md_t* __fastcall find_small_md(size_t size) count_t idx0; u32_t mask; - ASSERT(size & 0xFFF == 0); + ASSERT((size & 0xFFF) == 0); efl = safe_cli(); idx0 = (size>>12) - 1 < 32 ? (size>>12) - 1 : 31; mask = sheap.availmask & ( -1<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; - }; + md_t *tmp = (md_t*)sheap.list[31].next; + while((link_t*)tmp != &sheap.list[31]) + { + if(tmp->size >= size) + { + md = tmp; + break; + }; + tmp = (md_t*)tmp->link.next; + }; + } + else + { + idx0 = _bsf(mask); + ASSERT( !list_empty(&sheap.list[idx0])) + md = (md_t*)sheap.list[idx0].next; + } }; - if( !md) + if(md) + { + DBG("remove md %x\n", md); + + list_remove((link_t*)md); + if(list_empty(&sheap.list[idx0])) + _reset_smask(idx0); + } + else { md_t *lmd; lmd = find_large_md((size+0x3FFFFF)&~0x3FFFFF); + + DBG("get large md %x\n", lmd); + if( !lmd) { safe_sti(efl); @@ -208,7 +235,7 @@ md_t* __fastcall find_small_md(size_t size) 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); + DBG("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]); @@ -302,7 +329,7 @@ void* __fastcall mem_alloc(size_t size, u32_t flags) if( md ) { phm = phis_alloc(size>>12); - map_phm(md->base, phm, flags); + map_phm(md->base , phm, flags); return (void*)md->base; } return NULL; @@ -319,7 +346,8 @@ void* __stdcall alloc_kernel_space(size_t size) md = find_small_md(size); - // printf("alloc_kernel_space: %x size %x\n\n",md->base, size); + DBG("alloc_kernel_space: %x size %x\n\n",md->base, size); + if( md ) return (void*)md->base; return NULL; diff --git a/kernel/branches/kolibri_pe/core/init.c b/kernel/branches/kolibri_pe/core/init.c index af6c6d5ce6..7f75e25f35 100644 --- a/kernel/branches/kolibri_pe/core/init.c +++ b/kernel/branches/kolibri_pe/core/init.c @@ -24,11 +24,11 @@ void init() u32_t last_page = 0; if (CHECK_FLAG (boot_mbi->flags, 1)) - printf ("boot_device = 0x%x\n", (unsigned) boot_mbi->boot_device); + DBG ("boot_device = 0x%x\n", (unsigned) boot_mbi->boot_device); /* Is the command line passed? */ if (CHECK_FLAG (boot_mbi->flags, 2)) - printf ("cmdline = %s\n", (char *) boot_mbi->cmdline); + DBG ("cmdline = %s\n", (char *) boot_mbi->cmdline); /* Are mods_* valid? */ if (CHECK_FLAG (boot_mbi->flags, 3)) @@ -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); + DBG ("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); + DBG (" 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; @@ -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); + DBG("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,16 +68,16 @@ 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, - (unsigned) mmap->base_addr_high, - (unsigned) mmap->base_addr_low, - (unsigned) mmap->length_high, - (unsigned) mmap->length_low, - (unsigned) mmap->type); - */ + + DBG (" size = 0x%x, base_addr = 0x%x%x," + " length = 0x%x%x, type = 0x%x\n", + (unsigned) mmap->size, + (unsigned) mmap->base_addr_high, + (unsigned) mmap->base_addr_low, + (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); diff --git a/kernel/branches/kolibri_pe/core/memory.inc b/kernel/branches/kolibri_pe/core/memory.inc index a711c955d2..298bdd7db0 100644 --- a/kernel/branches/kolibri_pe/core/memory.inc +++ b/kernel/branches/kolibri_pe/core/memory.inc @@ -461,17 +461,16 @@ proc page_fault_handler jmp .fail - align 4 .kernel_heap: shr ebx, 22 mov edx, [master_tab + ebx*4] + test edx, PG_MAP jz .check_ptab ;таблица страниц не создана - - jmp .fail + jmp .exit .check_ptab: mov edx, [_sys_pdbr + ebx*4] diff --git a/kernel/branches/kolibri_pe/core/mm.c b/kernel/branches/kolibri_pe/core/mm.c index 410898f07b..ea071618ac 100644 --- a/kernel/branches/kolibri_pe/core/mm.c +++ b/kernel/branches/kolibri_pe/core/mm.c @@ -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); + DBG("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); + DBG("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); + DBG("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); + DBG("zone release base %x top %x\n", base, top); for (i = base; i < top; i++) { z->frames[i-z->base].refcount = 0; @@ -587,7 +587,7 @@ addr_t alloc_page() //obsolete spinlock_unlock(&z_core.lock); safe_sti(efl); - //printf("alloc_page: %x\n", v << FRAME_WIDTH); + DBG("alloc_page: %x\n", v << FRAME_WIDTH); restore_edx(edx); return (v << FRAME_WIDTH); @@ -608,7 +608,7 @@ addr_t __stdcall alloc_pages(count_t count) //obsolete spinlock_unlock(&z_core.lock); safe_sti(efl); - //printf("alloc_pages: %x count %x\n", v << FRAME_WIDTH, count); + DBG("alloc_pages: %x count %x\n", v << FRAME_WIDTH, count); restore_edx(edx); diff --git a/kernel/branches/kolibri_pe/include/core.h b/kernel/branches/kolibri_pe/include/core.h index ecda562042..b8c4832daf 100644 --- a/kernel/branches/kolibri_pe/include/core.h +++ b/kernel/branches/kolibri_pe/include/core.h @@ -18,11 +18,18 @@ extern void panic_printf(char *fmt, ...) __attribute__((noreturn)); if (!(expr)) { \ panic("assertion failed (%s), caller=%p\n", #expr, CALLER); \ } + +#define DBG(format,...) printf(format,##__VA_ARGS__) + #else + # define panic(format, ...) \ panic_printf("Kernel panic: " format, ##__VA_ARGS__); # define ASSERT(expr) + +# define DBG(format,...) + #endif diff --git a/kernel/branches/kolibri_pe/kernel.asm b/kernel/branches/kolibri_pe/kernel.asm index 18c7e13a21..49c61a8216 100644 --- a/kernel/branches/kolibri_pe/kernel.asm +++ b/kernel/branches/kolibri_pe/kernel.asm @@ -2321,6 +2321,7 @@ nosb1: cmp ebx,2 ; SET PIXEL jnz nosb2 + mov ebx, [mem_BACKGROUND] add ebx, 4095 and ebx, -4096 @@ -2486,6 +2487,7 @@ nogb1: cmp eax,2 ; PIXEL jnz nogb2 + mov ecx, [mem_BACKGROUND] add ecx, 4095 and ecx, -4096 @@ -2500,6 +2502,7 @@ nogb1: mov [esp+36],eax @@: ret + nogb2: cmp eax,4 ; TILED / STRETCHED diff --git a/kernel/branches/kolibri_pe/makefile b/kernel/branches/kolibri_pe/makefile index 9870b6eb67..07e793d842 100644 --- a/kernel/branches/kolibri_pe/makefile +++ b/kernel/branches/kolibri_pe/makefile @@ -26,7 +26,22 @@ PE_SRC:= \ spinlock.c \ boot/boot.asm \ boot/start.asm + +#include +#include +#include +#include +#include +#include +H_SRC:= \ + include/types.h \ + include/atomic.h \ + include/spinlock.h \ + include/link.h \ + include/core.h \ + include/mm.h \ + include/slab.h PE_OBJS = $(patsubst %.s, bin/%.obj, $(patsubst %.asm, bin/%.obj,\ $(patsubst %.c, bin/%.obj, $(PE_SRC)))) @@ -40,7 +55,7 @@ kernel.gz :kernel.mnt kernel.mnt: kernel.obj $(PE_OBJS) Makefile ld.x ld $(LDFLAGS) -T ld.x -o $@ kernel.obj $(PE_OBJS) -bin/%.obj : core/%.c Makefile +bin/%.obj : core/%.c $(H_SRC) Makefile $(CC) $(CFLAGS) -o $@ $< bin/%.obj: %.asm