kernel: deep refactoring and cleanup
This large commit address several issues - removed 386 directory: Jehanne is 64bit only - simplified kernel options management - rewritten boot process - ported memory related stuff from 9front's 9/pc64 - removed devacpi - removed old code - deep refactor of awake syscall - removed MCACHE support for mount - fix libc's setjmp/longjmp
This commit is contained in:
@ -3,50 +3,46 @@
|
||||
#include "mem.h"
|
||||
#include "dat.h"
|
||||
#include "fns.h"
|
||||
#include "error.h"
|
||||
|
||||
enum
|
||||
{
|
||||
Hdrspc = 64, /* leave room for high-level headers */
|
||||
Tlrspc = 16, /* extra room at the end for pad/crc/mac */
|
||||
Bdead = 0x51494F42, /* "QIOB" */
|
||||
};
|
||||
|
||||
struct
|
||||
{
|
||||
Lock;
|
||||
uint32_t bytes;
|
||||
uint32_t limit;
|
||||
|
||||
} ialloc;
|
||||
|
||||
static Block*
|
||||
_allocb(int size, int align)
|
||||
_allocb(int size)
|
||||
{
|
||||
Block *b;
|
||||
uint8_t *p;
|
||||
int n;
|
||||
uintptr_t addr;
|
||||
|
||||
if(align <= 0)
|
||||
align = BLOCKALIGN;
|
||||
n = align + ROUNDUP(size+Hdrspc, align) + sizeof(Block);
|
||||
if((p = jehanne_malloc(n)) == nil)
|
||||
size += Tlrspc;
|
||||
if((b = mallocz(sizeof(Block)+size+Hdrspc, 0)) == nil)
|
||||
return nil;
|
||||
|
||||
b = (Block*)(p + n - sizeof(Block)); /* block at end of allocated space */
|
||||
b->base = p;
|
||||
b->next = nil;
|
||||
b->list = nil;
|
||||
b->free = 0;
|
||||
b->free = nil;
|
||||
b->flag = 0;
|
||||
|
||||
/* align base and bounds of data */
|
||||
b->lim = (uint8_t*)(PTR2UINT(b) & ~(align-1));
|
||||
/* align start of data portion by rounding up */
|
||||
addr = (uintptr_t)b;
|
||||
addr = ROUND(addr + sizeof(Block), BLOCKALIGN);
|
||||
b->base = (uint8_t*)addr;
|
||||
|
||||
/* align start of writable data, leaving space below for added headers */
|
||||
b->rp = b->lim - ROUNDUP(size, align);
|
||||
b->wp = b->rp;
|
||||
/* align end of data portion by rounding down */
|
||||
b->lim = (uint8_t*)b + msize(b);
|
||||
addr = (uintptr_t)b->lim;
|
||||
addr &= ~(BLOCKALIGN-1);
|
||||
b->lim = (uint8_t*)addr;
|
||||
|
||||
if(b->rp < b->base || b->lim - b->rp < size)
|
||||
/* leave sluff at beginning for added headers */
|
||||
b->rp = b->lim - ROUND(size, BLOCKALIGN);
|
||||
if(b->rp < b->base)
|
||||
panic("_allocb");
|
||||
b->wp = b->rp;
|
||||
|
||||
return b;
|
||||
}
|
||||
@ -58,80 +54,44 @@ allocb(int size)
|
||||
|
||||
/*
|
||||
* Check in a process and wait until successful.
|
||||
* Can still error out of here, though.
|
||||
*/
|
||||
if(up == nil)
|
||||
panic("allocb without up: %#p\n", getcallerpc());
|
||||
if((b = _allocb(size, 0)) == nil){
|
||||
mallocsummary();
|
||||
panic("allocb: no memory for %d bytes\n", size);
|
||||
panic("allocb without up: %#p", getcallerpc());
|
||||
while((b = _allocb(size)) == nil){
|
||||
if(up->nlocks || m->ilockdepth || !islo()){
|
||||
xsummary();
|
||||
mallocsummary();
|
||||
panic("allocb: no memory for %d bytes", size);
|
||||
}
|
||||
if(!waserror()){
|
||||
resrcwait("no memory for allocb", nil);
|
||||
poperror();
|
||||
}
|
||||
}
|
||||
jehanne_setmalloctag(b->base, getcallerpc());
|
||||
setmalloctag(b, getcallerpc());
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
Block*
|
||||
allocbalign(int size, int align)
|
||||
{
|
||||
Block *b;
|
||||
|
||||
/*
|
||||
* Check in a process and wait until successful.
|
||||
* Can still error out of here, though.
|
||||
*/
|
||||
if(up == nil)
|
||||
panic("allocbalign without up: %#p\n", getcallerpc());
|
||||
if((b = _allocb(size, align)) == nil){
|
||||
mallocsummary();
|
||||
panic("allocbalign: no memory for %d bytes\n", size);
|
||||
}
|
||||
jehanne_setmalloctag(b->base, getcallerpc());
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
void
|
||||
ialloclimit(uint32_t limit)
|
||||
{
|
||||
ialloc.limit = limit;
|
||||
}
|
||||
|
||||
Block*
|
||||
iallocb(int size)
|
||||
{
|
||||
Block *b;
|
||||
static int m1, m2, mp;
|
||||
|
||||
if(ialloc.bytes > ialloc.limit){
|
||||
if((m1++%10000)==0){
|
||||
if(mp++ > 1000){
|
||||
active.exiting = 1;
|
||||
exit(0);
|
||||
if((b = _allocb(size)) == nil){
|
||||
static uint32_t nerr;
|
||||
if((nerr++%10000)==0){
|
||||
if(nerr > 10000000){
|
||||
xsummary();
|
||||
mallocsummary();
|
||||
panic("iallocb: out of memory");
|
||||
}
|
||||
iprint("iallocb: limited %lud/%lud\n",
|
||||
ialloc.bytes, ialloc.limit);
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
if((b = _allocb(size, 0)) == nil){
|
||||
if((m2++%10000)==0){
|
||||
if(mp++ > 1000){
|
||||
active.exiting = 1;
|
||||
exit(0);
|
||||
}
|
||||
iprint("iallocb: no memory %lud/%lud\n",
|
||||
ialloc.bytes, ialloc.limit);
|
||||
iprint("iallocb: no memory for %d bytes\n", size);
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
setmalloctag(b, getcallerpc());
|
||||
b->flag = BINTR;
|
||||
jehanne_setmalloctag(b->base, getcallerpc());
|
||||
|
||||
ilock(&ialloc);
|
||||
ialloc.bytes += b->lim - b->base;
|
||||
iunlock(&ialloc);
|
||||
|
||||
return b;
|
||||
}
|
||||
@ -140,7 +100,6 @@ void
|
||||
freeb(Block *b)
|
||||
{
|
||||
void *dead = (void*)Bdead;
|
||||
uint8_t *p;
|
||||
|
||||
if(b == nil)
|
||||
return;
|
||||
@ -149,17 +108,10 @@ freeb(Block *b)
|
||||
* drivers which perform non cache coherent DMA manage their own buffer
|
||||
* pool of uncached buffers and provide their own free routine.
|
||||
*/
|
||||
if(b->free) {
|
||||
if(b->free != nil) {
|
||||
b->free(b);
|
||||
return;
|
||||
}
|
||||
if(b->flag & BINTR) {
|
||||
ilock(&ialloc);
|
||||
ialloc.bytes -= b->lim - b->base;
|
||||
iunlock(&ialloc);
|
||||
}
|
||||
|
||||
p = b->base;
|
||||
|
||||
/* poison the block in case someone is still holding onto it */
|
||||
b->next = dead;
|
||||
@ -168,7 +120,7 @@ freeb(Block *b)
|
||||
b->lim = dead;
|
||||
b->base = dead;
|
||||
|
||||
jehanne_free(p);
|
||||
free(b);
|
||||
}
|
||||
|
||||
void
|
||||
@ -180,10 +132,10 @@ checkb(Block *b, char *msg)
|
||||
panic("checkb b %s %#p", msg, b);
|
||||
if(b->base == dead || b->lim == dead || b->next == dead
|
||||
|| b->rp == dead || b->wp == dead){
|
||||
jehanne_print("checkb: base %#p lim %#p next %#p\n",
|
||||
print("checkb: base %#p lim %#p next %#p\n",
|
||||
b->base, b->lim, b->next);
|
||||
jehanne_print("checkb: rp %#p wp %#p\n", b->rp, b->wp);
|
||||
panic("checkb dead: %s\n", msg);
|
||||
print("checkb: rp %#p wp %#p\n", b->rp, b->wp);
|
||||
panic("checkb dead: %s", msg);
|
||||
}
|
||||
|
||||
if(b->base > b->lim)
|
||||
@ -197,9 +149,3 @@ checkb(Block *b, char *msg)
|
||||
if(b->wp > b->lim)
|
||||
panic("checkb 4 %s %#p %#p", msg, b->wp, b->lim);
|
||||
}
|
||||
|
||||
void
|
||||
iallocsummary(void)
|
||||
{
|
||||
jehanne_print("ialloc %lud/%lud\n", ialloc.bytes, ialloc.limit);
|
||||
}
|
||||
|
Reference in New Issue
Block a user