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

Last change on this file since 573 was 573, checked in by Sam Hocevar, 14 years ago
  • Added assembly code for inb() and outb().
  • Print a small message at kernel boot time just to check that the kernel was properly loaded.
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1/*
2 *  libcucul      Unicode canvas library
3 *  libcaca       ASCII-Art library
4 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
5 *                All Rights Reserved
6 *
7 *  This library is free software; you can redistribute it and/or
8 *  modify it under the terms of the Do What The Fuck You Want To
9 *  Public License, Version 2, as published by Sam Hocevar. See
10 *  http://sam.zoy.org/wtfpl/COPYING for more details.
11 */
12
13/** \file kernel.h
14 *  \version \$Id: kernel.h 573 2006-03-09 15:35:00Z sam $
15 *  \author Sam Hocevar <sam@zoy.org>
16 *  \brief Kernel features
17 *
18 *  This file contains replacement functions for the standard C library
19 *  that must be used when building libcucul and libcaca into a kernel.
20 */
21
22/* Various defines */
23#define NULL ((void *)0)
24#define BUFSIZ 4096
25#define RAND_MAX ((unsigned int)0x8000000)
26#define INT_MAX ((int)0x7fffffff)
27#define __BYTE_ORDER 1
28#define __BIG_ENDIAN 2
29
30/* Assembly code for outb and inb */
31extern inline void outb(unsigned char val, unsigned short port);
32extern inline unsigned char inb(unsigned short port);
33
34extern inline void outb(unsigned char val, unsigned short port)
35{
36    __asm__ __volatile__ ("outb %b0,%w1" : : "a" (val), "Nd" (port));
37}
38
39extern 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
48typedef unsigned char uint8_t;
49typedef unsigned short uint16_t;
50typedef unsigned long int uint32_t;
51typedef long int intptr_t;
52typedef long unsigned int uintptr_t;
53
54typedef unsigned int size_t;
55
56typedef struct file
57{
58    void *mem;
59} FILE;
60
61struct timeval {
62    int tv_sec;
63    int tv_usec;
64};
65
66struct timezone {
67    int tz_minuteswest;
68    int tz_dsttime;
69};
70
71/* Multiboot kernel entry point */
72void cmain(unsigned long int magic, unsigned long int addr);
73
74/* The application's entry point */
75int main(int argc, char *argv[]);
76
77/* stdlib.h functions */
78void *malloc(size_t size);
79void free(void *ptr);
80void *realloc(void *ptr, size_t size);
81char *getenv(const char *name);
82int rand(void);
83int abs(int j);
84void exit(int status);
85
86/* string.h functions */
87void *memset(void *s, int c, size_t n);
88void *memcpy(void *dest, const void *src, size_t n);
89size_t strlen(const char *s);
90int strcasecmp(const char *s1, const char *s2);
91
92/* stdarg.h functions */
93typedef void * va_list;
94#define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a))
95#define va_end(v)
96int vsnprintf(char *str, size_t size, const char *format, va_list ap);
97
98/* stdio.h functions */
99FILE *fopen(const char *path, const char *mode);
100int feof(FILE *stream);
101char *fgets(char *s, int size, FILE *stream);
102int fclose(FILE *fp);
103int printf(const char *format, ...);
104int sprintf(char *str, const char *format, ...);
105int sscanf(const char *str, const char *format, ...);
106
107/* unistd.h functions */
108void usleep(unsigned long usec);
109
110/* time.h functions */
111int gettimeofday(struct timeval *tv, struct timezone *tz);
112
Note: See TracBrowser for help on using the repository browser.