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 */ |
---|
32 | extern inline void outb(unsigned char val, unsigned short port); |
---|
33 | extern inline unsigned char inb(unsigned short port); |
---|
34 | |
---|
35 | extern inline void outb(unsigned char val, unsigned short port) |
---|
36 | { |
---|
37 | __asm__ __volatile__ ("outb %b0,%w1" : : "a" (val), "Nd" (port)); |
---|
38 | } |
---|
39 | |
---|
40 | extern 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 |
---|
49 | typedef unsigned int size_t; |
---|
50 | |
---|
51 | typedef struct file |
---|
52 | { |
---|
53 | void *mem; |
---|
54 | } FILE; |
---|
55 | |
---|
56 | struct timeval { |
---|
57 | int tv_sec; |
---|
58 | int tv_usec; |
---|
59 | }; |
---|
60 | |
---|
61 | struct timezone { |
---|
62 | int tz_minuteswest; |
---|
63 | int tz_dsttime; |
---|
64 | }; |
---|
65 | |
---|
66 | /* Multiboot kernel entry point */ |
---|
67 | void cmain(unsigned long int magic, unsigned long int addr); |
---|
68 | |
---|
69 | /* The application's entry point */ |
---|
70 | int main(int argc, char *argv[]); |
---|
71 | |
---|
72 | /* stdlib.h functions */ |
---|
73 | void *malloc(size_t size); |
---|
74 | void free(void *ptr); |
---|
75 | void *realloc(void *ptr, size_t size); |
---|
76 | char *getenv(const char *name); |
---|
77 | int rand(void); |
---|
78 | int abs(int j); |
---|
79 | void exit(int status); |
---|
80 | void srand(unsigned int s); |
---|
81 | int stdint; |
---|
82 | int stdout; |
---|
83 | int stderr; |
---|
84 | |
---|
85 | /* string.h functions */ |
---|
86 | void *memset(void *s, int c, size_t n); |
---|
87 | void *memcpy(void *dest, const void *src, size_t n); |
---|
88 | size_t strlen(const char *s); |
---|
89 | int strcasecmp(const char *s1, const char *s2); |
---|
90 | int memcmp(const char *s1, const char *s2, size_t n); |
---|
91 | /* stdarg.h functions */ |
---|
92 | typedef void * va_list; |
---|
93 | #define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a)) |
---|
94 | #define va_end(v) |
---|
95 | int vsnprintf(char *str, size_t size, const char *format, va_list ap); |
---|
96 | |
---|
97 | /* stdio.h functions */ |
---|
98 | FILE *fopen(const char *path, const char *mode); |
---|
99 | int feof(FILE *stream); |
---|
100 | char *fgets(char *s, int size, FILE *stream); |
---|
101 | size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); |
---|
102 | int fclose(FILE *fp); |
---|
103 | int printf(const char *format, ...); |
---|
104 | int sprintf(char *str, const char *format, ...); |
---|
105 | int sscanf(const char *str, const char *format, ...); |
---|
106 | |
---|
107 | /* unistd.h functions */ |
---|
108 | void usleep(unsigned long usec); |
---|
109 | int getpid(void); |
---|
110 | |
---|
111 | |
---|
112 | /* time.h functions */ |
---|
113 | int gettimeofday(struct timeval *tv, struct timezone *tz); |
---|
114 | int time(void *); |
---|
115 | |
---|
116 | /* math.h functions */ |
---|
117 | double cos(double x); |
---|
118 | double sin(double x); |
---|
119 | double sqrt(double x); |
---|
120 | |
---|
121 | /* arpa/inet.h functions */ |
---|
122 | unsigned int htonl(unsigned int hostlong); |
---|
123 | unsigned short htons(unsigned short hostlong); |
---|
124 | |
---|
125 | #endif /* __KERNEL_H_ */ |
---|