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(base != 0);
|
||||||
ASSERT(size != 0)
|
ASSERT(size != 0)
|
||||||
ASSERT(base & 0x3FFFFF == 0);
|
ASSERT((base & 0x3FFFFF) == 0);
|
||||||
ASSERT(size & 0x3FFFFF == 0);
|
ASSERT((size & 0x3FFFFF) == 0);
|
||||||
|
|
||||||
for (i = 0; i < 32; i++)
|
for (i = 0; i < 32; i++)
|
||||||
{
|
{
|
||||||
@ -84,18 +84,36 @@ md_t* __fastcall find_large_md(size_t size)
|
|||||||
count_t idx0;
|
count_t idx0;
|
||||||
u32_t mask;
|
u32_t mask;
|
||||||
|
|
||||||
ASSERT(size & 0x3FFFFF == 0);
|
ASSERT((size & 0x3FFFFF) == 0);
|
||||||
|
|
||||||
idx0 = (size>>22) - 1 < 32 ? (size>>22) - 1 : 31;
|
idx0 = (size>>22) - 1 < 32 ? (size>>22) - 1 : 31;
|
||||||
mask = lheap.availmask & ( -1<<idx0 );
|
mask = lheap.availmask & ( -1<<idx0 );
|
||||||
|
|
||||||
if(mask)
|
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
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -137,44 +155,53 @@ md_t* __fastcall find_small_md(size_t size)
|
|||||||
count_t idx0;
|
count_t idx0;
|
||||||
u32_t mask;
|
u32_t mask;
|
||||||
|
|
||||||
ASSERT(size & 0xFFF == 0);
|
ASSERT((size & 0xFFF) == 0);
|
||||||
|
|
||||||
efl = safe_cli();
|
efl = safe_cli();
|
||||||
|
|
||||||
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);
|
DBG("smask %x size %x idx0 %x mask %x\n",sheap.availmask, size, idx0, mask);
|
||||||
|
|
||||||
if(mask)
|
if(mask)
|
||||||
{
|
{
|
||||||
md_t *tmp;
|
if(idx0 == 31)
|
||||||
|
|
||||||
idx0 = _bsf(mask);
|
|
||||||
|
|
||||||
ASSERT( !list_empty(&sheap.list[idx0]))
|
|
||||||
|
|
||||||
tmp = (md_t*)sheap.list[idx0].next;
|
|
||||||
|
|
||||||
while((link_t*)tmp != &sheap.list[idx0])
|
|
||||||
{
|
{
|
||||||
if(tmp->size >= size)
|
md_t *tmp = (md_t*)sheap.list[31].next;
|
||||||
{
|
while((link_t*)tmp != &sheap.list[31])
|
||||||
//printf("remove tmp %x\n", tmp);
|
{
|
||||||
list_remove((link_t*)tmp);
|
if(tmp->size >= size)
|
||||||
if(list_empty(&sheap.list[idx0]))
|
{
|
||||||
_reset_smask(idx0);
|
md = tmp;
|
||||||
md = tmp;
|
break;
|
||||||
break;
|
};
|
||||||
};
|
tmp = (md_t*)tmp->link.next;
|
||||||
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;
|
md_t *lmd;
|
||||||
lmd = find_large_md((size+0x3FFFFF)&~0x3FFFFF);
|
lmd = find_large_md((size+0x3FFFFF)&~0x3FFFFF);
|
||||||
|
|
||||||
|
DBG("get large md %x\n", lmd);
|
||||||
|
|
||||||
if( !lmd)
|
if( !lmd)
|
||||||
{
|
{
|
||||||
safe_sti(efl);
|
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;
|
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)
|
if( idx1 < 31)
|
||||||
list_prepend(&md->link, &sheap.list[idx1]);
|
list_prepend(&md->link, &sheap.list[idx1]);
|
||||||
@ -302,7 +329,7 @@ void* __fastcall mem_alloc(size_t size, u32_t flags)
|
|||||||
if( md )
|
if( md )
|
||||||
{
|
{
|
||||||
phm = phis_alloc(size>>12);
|
phm = phis_alloc(size>>12);
|
||||||
map_phm(md->base, phm, flags);
|
map_phm(md->base , phm, flags);
|
||||||
return (void*)md->base;
|
return (void*)md->base;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -319,7 +346,8 @@ void* __stdcall alloc_kernel_space(size_t size)
|
|||||||
|
|
||||||
md = find_small_md(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 )
|
if( md )
|
||||||
return (void*)md->base;
|
return (void*)md->base;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -24,11 +24,11 @@ void init()
|
|||||||
u32_t last_page = 0;
|
u32_t last_page = 0;
|
||||||
|
|
||||||
if (CHECK_FLAG (boot_mbi->flags, 1))
|
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? */
|
/* Is the command line passed? */
|
||||||
if (CHECK_FLAG (boot_mbi->flags, 2))
|
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? */
|
/* Are mods_* valid? */
|
||||||
if (CHECK_FLAG (boot_mbi->flags, 3))
|
if (CHECK_FLAG (boot_mbi->flags, 3))
|
||||||
@ -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",
|
DBG ("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",
|
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);
|
(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;
|
||||||
@ -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",
|
DBG("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,16 +68,16 @@ 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,"
|
DBG (" 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,
|
||||||
(unsigned) mmap->base_addr_high,
|
(unsigned) mmap->base_addr_high,
|
||||||
(unsigned) mmap->base_addr_low,
|
(unsigned) mmap->base_addr_low,
|
||||||
(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);
|
||||||
|
@ -461,17 +461,16 @@ proc page_fault_handler
|
|||||||
|
|
||||||
jmp .fail
|
jmp .fail
|
||||||
|
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
.kernel_heap:
|
.kernel_heap:
|
||||||
|
|
||||||
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 ;òàáëèöà ñòðàíèö íå ñîçäàíà
|
||||||
|
|
||||||
|
jmp .exit
|
||||||
jmp .fail
|
|
||||||
|
|
||||||
.check_ptab:
|
.check_ptab:
|
||||||
mov edx, [_sys_pdbr + ebx*4]
|
mov edx, [_sys_pdbr + ebx*4]
|
||||||
|
@ -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);
|
DBG("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);
|
DBG("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);
|
DBG("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);
|
DBG("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;
|
||||||
@ -587,7 +587,7 @@ addr_t alloc_page() //obsolete
|
|||||||
spinlock_unlock(&z_core.lock);
|
spinlock_unlock(&z_core.lock);
|
||||||
safe_sti(efl);
|
safe_sti(efl);
|
||||||
|
|
||||||
//printf("alloc_page: %x\n", v << FRAME_WIDTH);
|
DBG("alloc_page: %x\n", v << FRAME_WIDTH);
|
||||||
|
|
||||||
restore_edx(edx);
|
restore_edx(edx);
|
||||||
return (v << FRAME_WIDTH);
|
return (v << FRAME_WIDTH);
|
||||||
@ -608,7 +608,7 @@ addr_t __stdcall alloc_pages(count_t count) //obsolete
|
|||||||
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);
|
DBG("alloc_pages: %x count %x\n", v << FRAME_WIDTH, count);
|
||||||
|
|
||||||
restore_edx(edx);
|
restore_edx(edx);
|
||||||
|
|
||||||
|
@ -18,11 +18,18 @@ extern void panic_printf(char *fmt, ...) __attribute__((noreturn));
|
|||||||
if (!(expr)) { \
|
if (!(expr)) { \
|
||||||
panic("assertion failed (%s), caller=%p\n", #expr, CALLER); \
|
panic("assertion failed (%s), caller=%p\n", #expr, CALLER); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define DBG(format,...) printf(format,##__VA_ARGS__)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
# define panic(format, ...) \
|
# define panic(format, ...) \
|
||||||
panic_printf("Kernel panic: " format, ##__VA_ARGS__);
|
panic_printf("Kernel panic: " format, ##__VA_ARGS__);
|
||||||
|
|
||||||
# define ASSERT(expr)
|
# define ASSERT(expr)
|
||||||
|
|
||||||
|
# define DBG(format,...)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -2321,6 +2321,7 @@ nosb1:
|
|||||||
|
|
||||||
cmp ebx,2 ; SET PIXEL
|
cmp ebx,2 ; SET PIXEL
|
||||||
jnz nosb2
|
jnz nosb2
|
||||||
|
|
||||||
mov ebx, [mem_BACKGROUND]
|
mov ebx, [mem_BACKGROUND]
|
||||||
add ebx, 4095
|
add ebx, 4095
|
||||||
and ebx, -4096
|
and ebx, -4096
|
||||||
@ -2486,6 +2487,7 @@ nogb1:
|
|||||||
|
|
||||||
cmp eax,2 ; PIXEL
|
cmp eax,2 ; PIXEL
|
||||||
jnz nogb2
|
jnz nogb2
|
||||||
|
|
||||||
mov ecx, [mem_BACKGROUND]
|
mov ecx, [mem_BACKGROUND]
|
||||||
add ecx, 4095
|
add ecx, 4095
|
||||||
and ecx, -4096
|
and ecx, -4096
|
||||||
@ -2500,6 +2502,7 @@ nogb1:
|
|||||||
mov [esp+36],eax
|
mov [esp+36],eax
|
||||||
@@:
|
@@:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
nogb2:
|
nogb2:
|
||||||
|
|
||||||
cmp eax,4 ; TILED / STRETCHED
|
cmp eax,4 ; TILED / STRETCHED
|
||||||
|
@ -27,6 +27,21 @@ PE_SRC:= \
|
|||||||
boot/boot.asm \
|
boot/boot.asm \
|
||||||
boot/start.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,\
|
PE_OBJS = $(patsubst %.s, bin/%.obj, $(patsubst %.asm, bin/%.obj,\
|
||||||
$(patsubst %.c, bin/%.obj, $(PE_SRC))))
|
$(patsubst %.c, bin/%.obj, $(PE_SRC))))
|
||||||
@ -40,7 +55,7 @@ kernel.gz :kernel.mnt
|
|||||||
kernel.mnt: kernel.obj $(PE_OBJS) Makefile ld.x
|
kernel.mnt: kernel.obj $(PE_OBJS) Makefile ld.x
|
||||||
ld $(LDFLAGS) -T ld.x -o $@ kernel.obj $(PE_OBJS)
|
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 $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
bin/%.obj: %.asm
|
bin/%.obj: %.asm
|
||||||
|
Loading…
Reference in New Issue
Block a user