~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/openbios/arch/amd64/lib.c

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* lib.c
 
2
 * tag: simple function library
 
3
 *
 
4
 * Copyright (C) 2003 Stefan Reinauer
 
5
 *
 
6
 * See the file "COPYING" for further information about
 
7
 * the copyright and warranty status of this work.
 
8
 */
 
9
 
 
10
#include "config.h"
 
11
#include "asm/types.h"
 
12
#include <stdarg.h>
 
13
#include "libc/stdlib.h"
 
14
#include "libc/vsprintf.h"
 
15
#include "kernel/kernel.h"
 
16
 
 
17
/* Format a string and print it on the screen, just like the libc
 
18
 * function printf.
 
19
 */
 
20
int printk( const char *fmt, ... )
 
21
{
 
22
        char *p, buf[512];
 
23
        va_list args;
 
24
        int i;
 
25
 
 
26
        va_start(args, fmt);
 
27
        i = vsnprintf(buf, sizeof(buf), fmt, args);
 
28
        va_end(args);
 
29
 
 
30
        for( p=buf; *p; p++ )
 
31
                putchar(*p);
 
32
        return i;
 
33
}
 
34
 
 
35
// dumb quick memory allocator until we get a decent thing here.
 
36
 
 
37
#define MEMSIZE 128*1024
 
38
static char memory[MEMSIZE];
 
39
static void *memptr=memory;
 
40
static int memsize=MEMSIZE;
 
41
 
 
42
void *malloc(int size)
 
43
{
 
44
        void *ret=(void *)0;
 
45
        if(memsize>=size) {
 
46
                memsize-=size;
 
47
                ret=memptr;
 
48
                memptr+=size;
 
49
        }
 
50
        return ret;
 
51
}
 
52
 
 
53
void free(void *ptr)
 
54
{
 
55
        /* Nothing yet */
 
56
}