forked from KolibriOS/kolibrios
fixed ASSERT conditions
git-svn-id: svn://kolibrios.org@862 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
f806f6b7f8
commit
d08f862229
@ -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<<idx0 );
|
||||
|
||||
if(mask)
|
||||
{
|
||||
idx0 = _bsf(mask);
|
||||
if(idx0 == 31)
|
||||
{
|
||||
md_t *tmp = (md_t*)lheap.list[31].next;
|
||||
while((link_t*)tmp != &lheap.list[31])
|
||||
{
|
||||
if(tmp->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<<idx0 );
|
||||
|
||||
//printf("smask %x size %x idx0 %x mask %x\n",sheap.availmask, size, idx0, mask);
|
||||
DBG("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]))
|
||||
|
||||
tmp = (md_t*)sheap.list[idx0].next;
|
||||
|
||||
while((link_t*)tmp != &sheap.list[idx0])
|
||||
if(idx0 == 31)
|
||||
{
|
||||
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;
|
||||
};
|
||||
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;
|
||||
|
@ -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);
|
||||
|
@ -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]
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -27,6 +27,21 @@ PE_SRC:= \
|
||||
boot/boot.asm \
|
||||
boot/start.asm
|
||||
|
||||
#include <types.h>
|
||||
#include <core.h>
|
||||
#include <spinlock.h>
|
||||
#include <link.h>
|
||||
#include <mm.h>
|
||||
#include <slab.h>
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user