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

Last change on this file since 1048 was 1048, checked in by Jean-Yves Lamoureux, 14 years ago
  • Updated kernel 'driver', still not working, but most of the work is done
  • Property svn:keywords set to Id
File size: 3.2 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 1048 2006-09-17 12:44:18Z jylam $
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#ifndef __KERNEL_H_
21#define __KERNEL_H_
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 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 stdint;
82int stdout;
83int stderr;
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);
90int memcmp(const char *s1, const char *s2, size_t n);
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);
101size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
102int fclose(FILE *fp);
103int printf(const char *format, ...);
104int sprintf(char *str, const char *format, ...);
105int sscanf(const char *str, const char *format, ...);
106
107/* unistd.h functions */
108void usleep(unsigned long usec);
109int getpid(void);
110
111
112/* time.h functions */
113int gettimeofday(struct timeval *tv, struct timezone *tz);
114int time(void *);
115
116/* math.h functions */
117double cos(double x);
118double sin(double x);
119double sqrt(double x);
120
121/* arpa/inet.h functions */
122unsigned int htonl(unsigned int hostlong);
123unsigned short htons(unsigned short hostlong);
124
125#endif /* __KERNEL_H_ */
Note: See TracBrowser for help on using the repository browser.