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

Last change on this file since 2144 was 2144, checked in by Sam Hocevar, 13 years ago
  • Disable file operations in kernel mode.
  • Implement strchr() in kernel.c.
  • Check for snprintf() at configure time.
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1/*
2 *  libcucul      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 2144 2007-12-16 14:29:19Z 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 libcucul and libcaca into a kernel.
19 */
20
21/* Various defines */
22#define NULL ((void *)0)
23#define BUFSIZ 4096
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
29
30/* Assembly code for outb and inb */
31extern inline void outb(unsigned char val, unsigned short port);
32extern inline unsigned char inb(unsigned short port);
33
34extern inline void outb(unsigned char val, unsigned short port)
35{
36    __asm__ __volatile__ ("outb %b0,%w1" : : "a" (val), "Nd" (port));
37}
38
39extern inline unsigned char inb(unsigned short port)
40{
41    unsigned char tmp;
42    __asm__ __volatile__ ("inb %w1,%0" : "=a" (tmp) : "Nd" (port));
43    return tmp;
44}
45
46/* Various typedefs -- some are x86-specific */
47#define CUSTOM_INTTYPES
48typedef unsigned int size_t;
49
50typedef struct file
51{
52    void *mem;
53} FILE;
54
55struct timeval {
56    int tv_sec;
57    int tv_usec;
58};
59
60struct timezone {
61    int tz_minuteswest;
62    int tz_dsttime;
63};
64
65/* Multiboot kernel entry point */
66void cmain(unsigned long int magic, unsigned long int addr);
67
68/* The application's entry point */
69int main(int argc, char *argv[]);
70
71/* stdlib.h functions */
72void *malloc(size_t size);
73void free(void *ptr);
74void *realloc(void *ptr, size_t size);
75char *getenv(const char *name);
76int rand(void);
77int abs(int j);
78void exit(int status);
79void srand(unsigned int s);
80FILE *stdin, *stdout, *stderr;
81
82/* string.h functions */
83void *memset(void *s, int c, size_t n);
84void *memcpy(void *dest, const void *src, size_t n);
85size_t strlen(const char *s);
86int strcmp(const char *s1, const char *s2);
87int strcasecmp(const char *s1, const char *s2);
88int memcmp(const void *s1, const void *s2, size_t n);
89char *strdup(const char *s);
90char *strchr(const char *s, int c);
91
92/* stdarg.h functions */
93typedef void * va_list;
94#define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a))
95#define va_end(v)
96int vsnprintf(char *str, size_t size, const char *format, va_list ap);
97
98/* stdio.h functions */
99FILE *fopen(const char *path, const char *mode);
100int feof(FILE *stream);
101char *fgets(char *s, int size, FILE *stream);
102size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
103int fclose(FILE *fp);
104int printf(const char *format, ...);
105int fprintf(FILE *stream, const char *format, ...);
106int fflush(FILE *stream);
107int sprintf(char *str, const char *format, ...);
108int sscanf(const char *str, const char *format, ...);
109
110/* unistd.h functions */
111void usleep(unsigned long usec);
112int getpid(void);
113
114/* time.h functions */
115int gettimeofday(struct timeval *tv, struct timezone *tz);
116int time(void *);
117
118/* math.h functions */
119double cos(double x);
120double sin(double x);
121double sqrt(double x);
122
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 */
131extern int errno;
132
133/* arpa/inet.h functions */
134unsigned int htonl(unsigned int hostlong);
135unsigned short htons(unsigned short hostlong);
136
Note: See TracBrowser for help on using the repository browser.