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

Last change on this file since 1053 was 1053, checked in by Sam Hocevar, 14 years ago
  • Fixed memcmp() prototype and implementation.
  • 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 1053 2006-09-18 07:11:43Z 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 void *s1, const void *s2, size_t n);
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 sprintf(char *str, const char *format, ...);
104int sscanf(const char *str, const char *format, ...);
105
106/* unistd.h functions */
107void usleep(unsigned long usec);
108int getpid(void);
109
110/* time.h functions */
111int gettimeofday(struct timeval *tv, struct timezone *tz);
112int time(void *);
113
114/* math.h functions */
115double cos(double x);
116double sin(double x);
117double sqrt(double x);
118
119/* errno.h functions */
120#define ENOENT   2 /* No such file or directory */
121#define ENOMEM  12 /* Out of memory */
122#define EBUSY   16 /* Device or resource busy */
123#define ENODEV  19 /* No such device */
124#define EINVAL  22 /* Invalid argument */
125#define ENOTTY  25 /* Not a typewriter */
126#define ENOSYS  38 /* Function not implemented */
127extern int errno;
128
129/* arpa/inet.h functions */
130unsigned int htonl(unsigned int hostlong);
131unsigned short htons(unsigned short hostlong);
132
Note: See TracBrowser for help on using the repository browser.