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

Last change on this file since 977 was 769, checked in by Sam Hocevar, 14 years ago
  • Removed \file directives from all files except caca.h and cucul.h, to remove redundencies in the Doxygen documentation.
  • Property svn:keywords set to Id
File size: 3.0 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 769 2006-04-14 07:30:53Z sam $
8 *
9 *  This library is free software; you can redistribute it and/or
10 *  modify it under the terms of the Do What The Fuck You Want To
11 *  Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15/*
16 *  This file contains replacement functions for the standard C library
17 *  that must be used when building libcucul and libcaca into a kernel.
18 */
19
20/* Various defines */
21#define NULL ((void *)0)
22#define BUFSIZ 4096
23#define RAND_MAX ((unsigned int)0x8000000)
24#define INT_MAX ((int)0x7fffffff)
25#define M_PI 3.14159265358979323846
26#define __BYTE_ORDER 1
27#define __BIG_ENDIAN 2
28
29/* Assembly code for outb and inb */
30extern inline void outb(unsigned char val, unsigned short port);
31extern inline unsigned char inb(unsigned short port);
32
33extern inline void outb(unsigned char val, unsigned short port)
34{
35    __asm__ __volatile__ ("outb %b0,%w1" : : "a" (val), "Nd" (port));
36}
37
38extern inline unsigned char inb(unsigned short port)
39{
40    unsigned char tmp;
41    __asm__ __volatile__ ("inb %w1,%0" : "=a" (tmp) : "Nd" (port));
42    return tmp;
43}
44
45/* Various typedefs -- some are x86-specific */
46#define CUSTOM_INTTYPES
47typedef unsigned char uint8_t;
48typedef unsigned short uint16_t;
49typedef unsigned long int uint32_t;
50typedef long int intptr_t;
51typedef long unsigned int uintptr_t;
52
53typedef unsigned int size_t;
54
55typedef struct file
56{
57    void *mem;
58} FILE;
59
60struct timeval {
61    int tv_sec;
62    int tv_usec;
63};
64
65struct timezone {
66    int tz_minuteswest;
67    int tz_dsttime;
68};
69
70/* Multiboot kernel entry point */
71void cmain(unsigned long int magic, unsigned long int addr);
72
73/* The application's entry point */
74int main(int argc, char *argv[]);
75
76/* stdlib.h functions */
77void *malloc(size_t size);
78void free(void *ptr);
79void *realloc(void *ptr, size_t size);
80char *getenv(const char *name);
81int rand(void);
82int abs(int j);
83void exit(int status);
84
85/* string.h functions */
86void *memset(void *s, int c, size_t n);
87void *memcpy(void *dest, const void *src, size_t n);
88size_t strlen(const char *s);
89int strcasecmp(const char *s1, const char *s2);
90
91/* stdarg.h functions */
92typedef void * va_list;
93#define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a))
94#define va_end(v)
95int vsnprintf(char *str, size_t size, const char *format, va_list ap);
96
97/* stdio.h functions */
98FILE *fopen(const char *path, const char *mode);
99int feof(FILE *stream);
100char *fgets(char *s, int size, FILE *stream);
101int fclose(FILE *fp);
102int printf(const char *format, ...);
103int sprintf(char *str, const char *format, ...);
104int sscanf(const char *str, const char *format, ...);
105
106/* unistd.h functions */
107void usleep(unsigned long usec);
108
109/* time.h functions */
110int gettimeofday(struct timeval *tv, struct timezone *tz);
111
112/* math.h functions */
113double cos(double x);
114double sin(double x);
115double sqrt(double x);
116
Note: See TracBrowser for help on using the repository browser.