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

Last change on this file since 1065 was 1065, checked in by Sam Hocevar, 14 years ago
  • Added an fprintf stub to the kernel.
  • Property svn:keywords set to Id
File size: 3.6 KB
RevLine 
[568]1/*
[672]2 *  libcucul      Canvas for ultrafast compositing of Unicode letters
3 *  libcaca       Colour ASCII-Art library
[568]4 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
5 *                All Rights Reserved
6 *
[769]7 *  $Id: kernel.h 1065 2006-09-19 08:26:43Z sam $
8 *
[568]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
[769]15/*
[568]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)
[578]25#define M_PI 3.14159265358979323846
[568]26#define __BYTE_ORDER 1
27#define __BIG_ENDIAN 2
28
[573]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
[568]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);
[1048]78void srand(unsigned int s);
[1065]79FILE *stdin, *stdout, *stderr;
[568]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 strcasecmp(const char *s1, const char *s2);
[1053]86int memcmp(const void *s1, const void *s2, size_t n);
87
[568]88/* stdarg.h functions */
89typedef void * va_list;
90#define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a))
91#define va_end(v)
92int vsnprintf(char *str, size_t size, const char *format, va_list ap);
93
94/* stdio.h functions */
95FILE *fopen(const char *path, const char *mode);
96int feof(FILE *stream);
97char *fgets(char *s, int size, FILE *stream);
[1048]98size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
[568]99int fclose(FILE *fp);
100int printf(const char *format, ...);
[1065]101int fprintf(FILE *stream, const char *format, ...);
[568]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);
[1048]107int getpid(void);
[568]108
109/* time.h functions */
110int gettimeofday(struct timeval *tv, struct timezone *tz);
[1048]111int time(void *);
[568]112
[578]113/* math.h functions */
114double cos(double x);
115double sin(double x);
116double sqrt(double x);
117
[1052]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
[1048]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.