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

Last change on this file since 1415 was 1415, checked in by Sam Hocevar, 14 years ago
  • Implemented strcmp() and strdup() and added an fflush() stub to the kernel code.
  • Property svn:keywords set to Id
File size: 3.7 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 1415 2006-11-16 11:23:56Z 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 int size_t;
48
49typedef struct file
50{
51    void *mem;
52} FILE;
53
54struct timeval {
55    int tv_sec;
56    int tv_usec;
57};
58
59struct timezone {
60    int tz_minuteswest;
61    int tz_dsttime;
62};
63
64/* Multiboot kernel entry point */
65void cmain(unsigned long int magic, unsigned long int addr);
66
67/* The application's entry point */
68int main(int argc, char *argv[]);
69
70/* stdlib.h functions */
71void *malloc(size_t size);
72void free(void *ptr);
73void *realloc(void *ptr, size_t size);
74char *getenv(const char *name);
75int rand(void);
76int abs(int j);
77void exit(int status);
78void srand(unsigned int s);
79FILE *stdin, *stdout, *stderr;
80
81/* string.h functions */
82void *memset(void *s, int c, size_t n);
83void *memcpy(void *dest, const void *src, size_t n);
84size_t strlen(const char *s);
85int strcmp(const char *s1, const char *s2);
86int strcasecmp(const char *s1, const char *s2);
87int memcmp(const void *s1, const void *s2, size_t n);
88char *strdup(const char *s);
89
90/* stdarg.h functions */
91typedef void * va_list;
92#define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a))
93#define va_end(v)
94int vsnprintf(char *str, size_t size, const char *format, va_list ap);
95
96/* stdio.h functions */
97FILE *fopen(const char *path, const char *mode);
98int feof(FILE *stream);
99char *fgets(char *s, int size, FILE *stream);
100size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
101int fclose(FILE *fp);
102int printf(const char *format, ...);
103int fprintf(FILE *stream, const char *format, ...);
104int fflush(FILE *stream);
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);
110int getpid(void);
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/* errno.h functions */
122#define ENOENT   2 /* No such file or directory */
123#define ENOMEM  12 /* Out of memory */
124#define EBUSY   16 /* Device or resource busy */
125#define ENODEV  19 /* No such device */
126#define EINVAL  22 /* Invalid argument */
127#define ENOTTY  25 /* Not a typewriter */
128#define ENOSYS  38 /* Function not implemented */
129extern int errno;
130
131/* arpa/inet.h functions */
132unsigned int htonl(unsigned int hostlong);
133unsigned short htons(unsigned short hostlong);
134
Note: See TracBrowser for help on using the repository browser.