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

Last change on this file since 1052 was 1052, checked in by Sam Hocevar, 14 years ago
  • Added errno support to the kernel.
  • Property svn:keywords set to Id
File size: 3.5 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 1052 2006-09-18 06:59:48Z 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);
79int stdint;
80int stdout;
81int stderr;
82
83/* string.h functions */
84void *memset(void *s, int c, size_t n);
85void *memcpy(void *dest, const void *src, size_t n);
86size_t strlen(const char *s);
87int strcasecmp(const char *s1, const char *s2);
88int memcmp(const char *s1, const char *s2, size_t n);
89/* stdarg.h functions */
90typedef void * va_list;
91#define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a))
92#define va_end(v)
93int vsnprintf(char *str, size_t size, const char *format, va_list ap);
94
95/* stdio.h functions */
96FILE *fopen(const char *path, const char *mode);
97int feof(FILE *stream);
98char *fgets(char *s, int size, FILE *stream);
99size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
100int fclose(FILE *fp);
101int printf(const char *format, ...);
102int sprintf(char *str, const char *format, ...);
103int sscanf(const char *str, const char *format, ...);
104
105/* unistd.h functions */
106void usleep(unsigned long usec);
107int getpid(void);
108
109/* time.h functions */
110int gettimeofday(struct timeval *tv, struct timezone *tz);
111int time(void *);
112
113/* math.h functions */
114double cos(double x);
115double sin(double x);
116double sqrt(double x);
117
118/* errno.h functions */
119#define ENOENT   2 /* No such file or directory */
120#define ENOMEM  12 /* Out of memory */
121#define EBUSY   16 /* Device or resource busy */
122#define ENODEV  19 /* No such device */
123#define EINVAL  22 /* Invalid argument */
124#define ENOTTY  25 /* Not a typewriter */
125#define ENOSYS  38 /* Function not implemented */
126extern int errno;
127
128/* arpa/inet.h functions */
129unsigned int htonl(unsigned int hostlong);
130unsigned short htons(unsigned short hostlong);
131
Note: See TracBrowser for help on using the repository browser.