summaryrefslogtreecommitdiffstats
path: root/qemu/roms/openbios/arch/x86/lib.c
blob: eeb901b4a8ec5eaa5f1ca82cc12bf41101bc3c2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* 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.
 */

#include "config.h"
#include "asm/types.h"
#include <stdarg.h>
#include "libc/stdlib.h"
#include "libc/vsprintf.h"
#include "kernel/kernel.h"

/* Format a string and print it on the screen, just like the libc
 * function printf.
 */
int printk( const char *fmt, ... )
{
        char *p, buf[512];
	va_list args;
	int i;

	va_start(args, fmt);
        i = vsnprintf(buf, sizeof(buf), fmt, args);
	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 = (void *)((unsigned long)memptr + size);
	}
	return ret;
}

void free(void *ptr)
{
	/* Nothing yet */
}