13
12
* http://sam.zoy.org/wtfpl/COPYING for more details.
17
* This file contains replacement functions for the standard C library
18
* that must be used when building libcaca and libcaca into a kernel.
22
#define NULL ((void *)0)
24
#define RAND_MAX ((unsigned int)0x8000000)
25
#define INT_MAX ((int)0x7fffffff)
26
#define M_PI 3.14159265358979323846
27
#define __BYTE_ORDER 1
28
#define __BIG_ENDIAN 2
30
/* Assembly code for outb and inb */
31
extern inline void outb(unsigned char val, unsigned short port);
32
extern inline unsigned char inb(unsigned short port);
34
extern inline void outb(unsigned char val, unsigned short port)
36
__asm__ __volatile__ ("outb %b0,%w1" : : "a" (val), "Nd" (port));
39
extern inline unsigned char inb(unsigned short port)
42
__asm__ __volatile__ ("inb %w1,%0" : "=a" (tmp) : "Nd" (port));
46
/* Various typedefs -- some are x86-specific */
47
#define CUSTOM_INTTYPES
48
typedef unsigned int size_t;
65
/* Multiboot kernel entry point */
66
void cmain(unsigned long int magic, unsigned long int addr);
18
extern void init_gdt(void);
21
void putcar(unsigned char c);
24
void disable_interrupt(char i);
25
void enable_interrupt(char i);
27
#define cli __asm__("cli" : : )
28
#define sti __asm__("sti" : : )
30
#define rdtsc(low, high) \
31
__asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
68
33
/* The application's entry point */
69
34
int main(int argc, char *argv[]);
71
/* stdlib.h functions */
72
void *malloc(size_t size);
74
void *realloc(void *ptr, size_t size);
75
char *getenv(const char *name);
78
void exit(int status);
79
void srand(unsigned int s);
80
FILE *stdin, *stdout, *stderr;
82
/* string.h functions */
83
void *memset(void *s, int c, size_t n);
84
void *memcpy(void *dest, const void *src, size_t n);
85
size_t strlen(const char *s);
86
int strcmp(const char *s1, const char *s2);
87
int strcasecmp(const char *s1, const char *s2);
88
int memcmp(const void *s1, const void *s2, size_t n);
89
char *strdup(const char *s);
90
char *strchr(const char *s, int c);
92
/* stdarg.h functions */
93
typedef void * va_list;
94
#define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a))
96
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
98
/* stdio.h functions */
99
FILE *fopen(const char *path, const char *mode);
100
int feof(FILE *stream);
101
char *fgets(char *s, int size, FILE *stream);
102
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
103
int fclose(FILE *fp);
104
int printf(const char *format, ...);
105
int fprintf(FILE *stream, const char *format, ...);
106
int fflush(FILE *stream);
107
int sprintf(char *str, const char *format, ...);
108
int sscanf(const char *str, const char *format, ...);
110
/* unistd.h functions */
111
void usleep(unsigned long usec);
114
/* time.h functions */
115
int gettimeofday(struct timeval *tv, struct timezone *tz);
118
/* math.h functions */
119
double cos(double x);
120
double sin(double x);
121
double sqrt(double x);
123
/* errno.h functions */
124
#define ENOENT 2 /* No such file or directory */
125
#define ENOMEM 12 /* Out of memory */
126
#define EBUSY 16 /* Device or resource busy */
127
#define ENODEV 19 /* No such device */
128
#define EINVAL 22 /* Invalid argument */
129
#define ENOTTY 25 /* Not a typewriter */
130
#define ENOSYS 38 /* Function not implemented */
133
/* arpa/inet.h functions */
134
unsigned int htonl(unsigned int hostlong);
135
unsigned short htons(unsigned short hostlong);