2006-04-26 15:08:19 +00:00
|
|
|
/* lib.c
|
|
|
|
|
* tag: simple function library
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2003 Stefan Reinauer
|
|
|
|
|
*
|
|
|
|
|
* See the file "COPYING" for further information about
|
|
|
|
|
* the copyright and warranty status of this work.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-03-14 17:19:58 +00:00
|
|
|
#include "config.h"
|
2006-04-26 15:08:19 +00:00
|
|
|
#include "asm/types.h"
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include "libc/stdlib.h"
|
|
|
|
|
#include "libc/vsprintf.h"
|
2010-03-14 14:21:02 +00:00
|
|
|
#include "kernel/kernel.h"
|
2006-04-26 15:08:19 +00:00
|
|
|
|
|
|
|
|
/* Format a string and print it on the screen, just like the libc
|
2008-12-11 20:30:53 +00:00
|
|
|
* function printf.
|
2006-04-26 15:08:19 +00:00
|
|
|
*/
|
|
|
|
|
int printk( const char *fmt, ... )
|
|
|
|
|
{
|
2008-11-30 13:44:38 +00:00
|
|
|
char *p, buf[512];
|
2006-04-26 15:08:19 +00:00
|
|
|
va_list args;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
2008-11-30 13:44:38 +00:00
|
|
|
i = vsnprintf(buf, sizeof(buf), fmt, args);
|
2006-04-26 15:08:19 +00:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
|
|
for( p=buf; *p; p++ )
|
|
|
|
|
putchar(*p);
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// dumb quick memory allocator until we get a decent thing here.
|
|
|
|
|
|
|
|
|
|
#define MEMSIZE 128*1024
|
|
|
|
|
static char memory[MEMSIZE];
|
|
|
|
|
static void *memptr=memory;
|
|
|
|
|
static int memsize=MEMSIZE;
|
|
|
|
|
|
|
|
|
|
void *malloc(int size)
|
|
|
|
|
{
|
|
|
|
|
void *ret=(void *)0;
|
|
|
|
|
if(memsize>=size) {
|
|
|
|
|
memsize-=size;
|
|
|
|
|
ret=memptr;
|
|
|
|
|
memptr+=size;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void free(void *ptr)
|
|
|
|
|
{
|
|
|
|
|
/* Nothing yet */
|
|
|
|
|
}
|