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

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

Implement memmove() in the kernel.

  • Property svn:keywords set to Id
File size: 3.9 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 3625 2009-08-03 23:26:28Z 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);
87void *memmove(void *dest, const void *src, size_t n);
88size_t strlen(const char *s);
89int strcmp(const char *s1, const char *s2);
90int strcasecmp(const char *s1, const char *s2);
91int memcmp(const void *s1, const void *s2, size_t n);
92char *strdup(const char *s);
93char *strchr(const char *s, int c);
94
95/* stdarg.h functions */
96typedef void * va_list;
97#define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a))
98#define va_end(v)
99int vsnprintf(char *str, size_t size, const char *format, va_list ap);
100
101/* stdio.h functions */
102FILE *fopen(const char *path, const char *mode);
103int feof(FILE *stream);
104char *fgets(char *s, int size, FILE *stream);
105size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
106int fclose(FILE *fp);
107int printf(const char *format, ...);
108int fprintf(FILE *stream, const char *format, ...);
109int fflush(FILE *stream);
110int sprintf(char *str, const char *format, ...);
111int sscanf(const char *str, const char *format, ...);
112
113/* unistd.h functions */
114void usleep(unsigned long usec);
115int getpid(void);
116
117/* time.h functions */
118int gettimeofday(struct timeval *tv, struct timezone *tz);
119int time(void *);
120
121/* math.h functions */
122double cos(double x);
123double sin(double x);
124double sqrt(double x);
125
126/* errno.h functions */
127#define ENOENT   2 /* No such file or directory */
128#define ENOMEM  12 /* Out of memory */
129#define EBUSY   16 /* Device or resource busy */
130#define ENODEV  19 /* No such device */
131#define EINVAL  22 /* Invalid argument */
132#define ENOTTY  25 /* Not a typewriter */
133#define ENOSYS  38 /* Function not implemented */
134extern int errno;
135
136/* arpa/inet.h functions */
137unsigned int htonl(unsigned int hostlong);
138unsigned short htons(unsigned short hostlong);
139
Note: See TracBrowser for help on using the repository browser.