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

Last change on this file since 672 was 672, checked in by Sam Hocevar, 15 years ago
  • Slightly changed header comments.
  • Property svn:keywords set to Id
File size: 3.1 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 *  This library is free software; you can redistribute it and/or
8 *  modify it under the terms of the Do What The Fuck You Want To
9 *  Public License, Version 2, as published by Sam Hocevar. See
10 *  http://sam.zoy.org/wtfpl/COPYING for more details.
11 */
12
13/** \file kernel.h
14 *  \version \$Id: kernel.h 672 2006-03-22 21:15:57Z sam $
15 *  \author Sam Hocevar <sam@zoy.org>
16 *  \brief Kernel features
17 *
18 *  This file contains replacement functions for the standard C library
19 *  that must be used when building libcucul and libcaca into a kernel.
20 */
21
22/* Various defines */
23#define NULL ((void *)0)
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 char uint8_t;
50typedef unsigned short uint16_t;
51typedef unsigned long int uint32_t;
52typedef long int intptr_t;
53typedef long unsigned int uintptr_t;
54
55typedef unsigned int size_t;
56
57typedef struct file
58{
59    void *mem;
60} FILE;
61
62struct timeval {
63    int tv_sec;
64    int tv_usec;
65};
66
67struct timezone {
68    int tz_minuteswest;
69    int tz_dsttime;
70};
71
72/* Multiboot kernel entry point */
73void cmain(unsigned long int magic, unsigned long int addr);
74
75/* The application's entry point */
76int main(int argc, char *argv[]);
77
78/* stdlib.h functions */
79void *malloc(size_t size);
80void free(void *ptr);
81void *realloc(void *ptr, size_t size);
82char *getenv(const char *name);
83int rand(void);
84int abs(int j);
85void exit(int status);
86
87/* string.h functions */
88void *memset(void *s, int c, size_t n);
89void *memcpy(void *dest, const void *src, size_t n);
90size_t strlen(const char *s);
91int strcasecmp(const char *s1, const char *s2);
92
93/* stdarg.h functions */
94typedef void * va_list;
95#define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a))
96#define va_end(v)
97int vsnprintf(char *str, size_t size, const char *format, va_list ap);
98
99/* stdio.h functions */
100FILE *fopen(const char *path, const char *mode);
101int feof(FILE *stream);
102char *fgets(char *s, int size, FILE *stream);
103int fclose(FILE *fp);
104int printf(const char *format, ...);
105int sprintf(char *str, const char *format, ...);
106int sscanf(const char *str, const char *format, ...);
107
108/* unistd.h functions */
109void usleep(unsigned long usec);
110
111/* time.h functions */
112int gettimeofday(struct timeval *tv, struct timezone *tz);
113
114/* math.h functions */
115double cos(double x);
116double sin(double x);
117double sqrt(double x);
118
Note: See TracBrowser for help on using the repository browser.