source: libcaca/trunk/kernel/kernel.h @ 3620

Last change on this file since 3620 was 3620, checked in by Sam Hocevar, 11 years ago

Add atexit() and EOF to the kernel.

  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1/*
2 *  libcaca      Canvas for ultrafast compositing of Unicode letters
3 *  libcaca       Colour ASCII-Art library
4 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
5 *                All Rights Reserved
6 *
7 *  $Id: kernel.h 3620 2009-08-03 23:19:34Z sam $
8 *
9 *  This library is free software. It comes without any warranty, to
10 *  the extent permitted by applicable law. You can redistribute it
11 *  and/or modify it under the terms of the Do What The Fuck You Want
12 *  To Public License, Version 2, as published by Sam Hocevar. See
13 *  http://sam.zoy.org/wtfpl/COPYING for more details.
14 */
15
16/*
17 *  This file contains replacement functions for the standard C library
18 *  that must be used when building libcaca and libcaca into a kernel.
19 */
20
21/* Various defines */
22#define NULL ((void *)0)
23#define EOF (-1)
24#define BUFSIZ 4096
25#define RAND_MAX ((unsigned int)0x8000000)
26#define INT_MAX ((int)0x7fffffff)
27#define M_PI 3.14159265358979323846
28#define __BYTE_ORDER 1
29#define __BIG_ENDIAN 2
30
31/* Assembly code for outb and inb */
32extern inline void outb(unsigned char val, unsigned short port);
33extern inline unsigned char inb(unsigned short port);
34
35extern inline void outb(unsigned char val, unsigned short port)
36{
37    __asm__ __volatile__ ("outb %b0,%w1" : : "a" (val), "Nd" (port));
38}
39
40extern inline unsigned char inb(unsigned short port)
41{
42    unsigned char tmp;
43    __asm__ __volatile__ ("inb %w1,%0" : "=a" (tmp) : "Nd" (port));
44    return tmp;
45}
46
47/* Various typedefs -- some are x86-specific */
48#define CUSTOM_INTTYPES
49typedef unsigned int size_t;
50
51typedef struct file
52{
53    void *mem;
54} FILE;
55
56struct timeval {
57    int tv_sec;
58    int tv_usec;
59};
60
61struct timezone {
62    int tz_minuteswest;
63    int tz_dsttime;
64};
65
66/* Multiboot kernel entry point */
67void cmain(unsigned long int magic, unsigned long int addr);
68
69/* The application's entry point */
70int main(int argc, char *argv[]);
71
72/* stdlib.h functions */
73void *malloc(size_t size);
74void free(void *ptr);
75void *realloc(void *ptr, size_t size);
76char *getenv(const char *name);
77int rand(void);
78int abs(int j);
79void exit(int status);
80void srand(unsigned int s);
81int atexit(void (*function)(void));
82FILE *stdin, *stdout, *stderr;
83
84/* string.h functions */
85void *memset(void *s, int c, size_t n);
86void *memcpy(void *dest, const void *src, size_t n);
87size_t strlen(const char *s);
88int strcmp(const char *s1, const char *s2);
89int strcasecmp(const char *s1, const char *s2);
90int memcmp(const void *s1, const void *s2, size_t n);
91char *strdup(const char *s);
92char *strchr(const char *s, int c);
93
94/* stdarg.h functions */
95typedef void * va_list;
96#define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a))
97#define va_end(v)
98int vsnprintf(char *str, size_t size, const char *format, va_list ap);
99
100/* stdio.h functions */
101FILE *fopen(const char *path, const char *mode);
102int feof(FILE *stream);
103char *fgets(char *s, int size, FILE *stream);
104size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
105int fclose(FILE *fp);
106int printf(const char *format, ...);
107int fprintf(FILE *stream, const char *format, ...);
108int fflush(FILE *stream);
109int sprintf(char *str, const char *format, ...);
110int sscanf(const char *str, const char *format, ...);
111
112/* unistd.h functions */
113void usleep(unsigned long usec);
114int getpid(void);
115
116/* time.h functions */
117int gettimeofday(struct timeval *tv, struct timezone *tz);
118int time(void *);
119
120/* math.h functions */
121double cos(double x);
122double sin(double x);
123double sqrt(double x);
124
125/* errno.h functions */
126#define ENOENT   2 /* No such file or directory */
127#define ENOMEM  12 /* Out of memory */
128#define EBUSY   16 /* Device or resource busy */
129#define ENODEV  19 /* No such device */
130#define EINVAL  22 /* Invalid argument */
131#define ENOTTY  25 /* Not a typewriter */
132#define ENOSYS  38 /* Function not implemented */
133extern int errno;
134
135/* arpa/inet.h functions */
136unsigned int htonl(unsigned int hostlong);
137unsigned short htons(unsigned short hostlong);
138
Note: See TracBrowser for help on using the repository browser.