~ubuntu-branches/ubuntu/raring/libcaca/raring

« back to all changes in this revision

Viewing changes to kernel/kernel.h

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hocevar
  • Date: 2010-02-08 01:40:59 UTC
  • mfrom: (1.1.8 upstream) (4.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100208014059-9q4av8pze8p7uw3i
Tags: 0.99.beta17-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  libcaca      Canvas for ultrafast compositing of Unicode letters
 
2
 *  libcaca
3
3
 *  libcaca       Colour ASCII-Art library
4
 
 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
 
4
 *  Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
 
5
 *                2009 Jean-Yves Lamoureux <jylam@lnxscene.org>
5
6
 *                All Rights Reserved
6
7
 *
7
 
 *  $Id$
8
 
 *
9
8
 *  This library is free software. It comes without any warranty, to
10
9
 *  the extent permitted by applicable law. You can redistribute it
11
10
 *  and/or modify it under the terms of the Do What The Fuck You Want
13
12
 *  http://sam.zoy.org/wtfpl/COPYING for more details.
14
13
 */
15
14
 
16
 
/*
17
 
 *  This file contains replacement functions for the standard C library
18
 
 *  that must be used when building libcaca and libcaca into a kernel.
19
 
 */
20
 
 
21
 
/* Various defines */
22
 
#define NULL ((void *)0)
23
 
#define BUFSIZ 4096
24
 
#define RAND_MAX ((unsigned int)0x8000000)
25
 
#define INT_MAX ((int)0x7fffffff)
26
 
#define M_PI 3.14159265358979323846
27
 
#define __BYTE_ORDER 1
28
 
#define __BIG_ENDIAN 2
29
 
 
30
 
/* Assembly code for outb and inb */
31
 
extern inline void outb(unsigned char val, unsigned short port);
32
 
extern inline unsigned char inb(unsigned short port);
33
 
 
34
 
extern inline void outb(unsigned char val, unsigned short port)
35
 
{
36
 
    __asm__ __volatile__ ("outb %b0,%w1" : : "a" (val), "Nd" (port));
37
 
}
38
 
 
39
 
extern inline unsigned char inb(unsigned short port)
40
 
{
41
 
    unsigned char tmp;
42
 
    __asm__ __volatile__ ("inb %w1,%0" : "=a" (tmp) : "Nd" (port));
43
 
    return tmp;
44
 
}
45
 
 
46
 
/* Various typedefs -- some are x86-specific */
47
 
#define CUSTOM_INTTYPES
48
 
typedef unsigned int size_t;
49
 
 
50
 
typedef struct file
51
 
{
52
 
    void *mem;
53
 
} FILE;
54
 
 
55
 
struct timeval {
56
 
    int tv_sec;
57
 
    int tv_usec;
58
 
};
59
 
 
60
 
struct timezone {
61
 
    int tz_minuteswest;
62
 
    int tz_dsttime;
63
 
};
64
 
 
65
 
/* Multiboot kernel entry point */
66
 
void cmain(unsigned long int magic, unsigned long int addr);
 
15
 
 
16
 
 
17
 
 
18
extern void init_gdt(void);
 
19
void init_pic(void);
 
20
void init_idt(void);
 
21
void putcar(unsigned char c);
 
22
void dump_gdt(void);
 
23
 
 
24
void disable_interrupt(char i);
 
25
void enable_interrupt(char i);
 
26
 
 
27
#define cli __asm__("cli" : : )
 
28
#define sti __asm__("sti" : : )
 
29
 
 
30
#define rdtsc(low, high) \
 
31
    __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
67
32
 
68
33
/* The application's entry point */
69
34
int main(int argc, char *argv[]);
70
35
 
71
 
/* stdlib.h functions */
72
 
void *malloc(size_t size);
73
 
void free(void *ptr);
74
 
void *realloc(void *ptr, size_t size);
75
 
char *getenv(const char *name);
76
 
int rand(void);
77
 
int abs(int j);
78
 
void exit(int status);
79
 
void srand(unsigned int s);
80
 
FILE *stdin, *stdout, *stderr;
81
 
 
82
 
/* string.h functions */
83
 
void *memset(void *s, int c, size_t n);
84
 
void *memcpy(void *dest, const void *src, size_t n);
85
 
size_t strlen(const char *s);
86
 
int strcmp(const char *s1, const char *s2);
87
 
int strcasecmp(const char *s1, const char *s2);
88
 
int memcmp(const void *s1, const void *s2, size_t n);
89
 
char *strdup(const char *s);
90
 
char *strchr(const char *s, int c);
91
 
 
92
 
/* stdarg.h functions */
93
 
typedef void * va_list;
94
 
#define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a))
95
 
#define va_end(v)
96
 
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
97
 
 
98
 
/* stdio.h functions */
99
 
FILE *fopen(const char *path, const char *mode);
100
 
int feof(FILE *stream);
101
 
char *fgets(char *s, int size, FILE *stream);
102
 
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
103
 
int fclose(FILE *fp);
104
 
int printf(const char *format, ...);
105
 
int fprintf(FILE *stream, const char *format, ...);
106
 
int fflush(FILE *stream);
107
 
int sprintf(char *str, const char *format, ...);
108
 
int sscanf(const char *str, const char *format, ...);
109
 
 
110
 
/* unistd.h functions */
111
 
void usleep(unsigned long usec);
112
 
int getpid(void);
113
 
 
114
 
/* time.h functions */
115
 
int gettimeofday(struct timeval *tv, struct timezone *tz);
116
 
int time(void *);
117
 
 
118
 
/* math.h functions */
119
 
double cos(double x);
120
 
double sin(double x);
121
 
double sqrt(double x);
122
 
 
123
 
/* errno.h functions */
124
 
#define ENOENT   2 /* No such file or directory */
125
 
#define ENOMEM  12 /* Out of memory */
126
 
#define EBUSY   16 /* Device or resource busy */
127
 
#define ENODEV  19 /* No such device */
128
 
#define EINVAL  22 /* Invalid argument */
129
 
#define ENOTTY  25 /* Not a typewriter */
130
 
#define ENOSYS  38 /* Function not implemented */
131
 
extern int errno;
132
 
 
133
 
/* arpa/inet.h functions */
134
 
unsigned int htonl(unsigned int hostlong);
135
 
unsigned short htons(unsigned short hostlong);
136