25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kernel.h 3.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * libcaca 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$
  8. *
  9. * This library is free software. It comes without any warranty, to
  10. * the extent permitted by applicable law. You can redistribute it
  11. * and/or modify it under the terms of the Do What The Fuck You Want
  12. * To Public License, Version 2, as published by Sam Hocevar. See
  13. * http://sam.zoy.org/wtfpl/COPYING for more details.
  14. */
  15. /*
  16. * This file contains replacement functions for the standard C library
  17. * that must be used when building libcaca and libcaca into a kernel.
  18. */
  19. /* Various defines */
  20. #define NULL ((void *)0)
  21. #define EOF (-1)
  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. /* Assembly code for outb and inb */
  29. extern inline void outb(unsigned char val, unsigned short port);
  30. extern inline unsigned char inb(unsigned short port);
  31. extern inline void outb(unsigned char val, unsigned short port)
  32. {
  33. __asm__ __volatile__ ("outb %b0,%w1" : : "a" (val), "Nd" (port));
  34. }
  35. extern inline unsigned char inb(unsigned short port)
  36. {
  37. unsigned char tmp;
  38. __asm__ __volatile__ ("inb %w1,%0" : "=a" (tmp) : "Nd" (port));
  39. return tmp;
  40. }
  41. /* Various typedefs -- some are x86-specific */
  42. #define CUSTOM_INTTYPES
  43. typedef unsigned int size_t;
  44. typedef struct file
  45. {
  46. void *mem;
  47. } FILE;
  48. struct timeval {
  49. int tv_sec;
  50. int tv_usec;
  51. };
  52. struct timezone {
  53. int tz_minuteswest;
  54. int tz_dsttime;
  55. };
  56. /* Multiboot kernel entry point */
  57. void cmain(unsigned long int magic, unsigned long int addr);
  58. /* The application's entry point */
  59. int main(int argc, char *argv[]);
  60. /* stdlib.h functions */
  61. void *malloc(size_t size);
  62. void free(void *ptr);
  63. void *realloc(void *ptr, size_t size);
  64. char *getenv(const char *name);
  65. int rand(void);
  66. int abs(int j);
  67. void exit(int status);
  68. void srand(unsigned int s);
  69. int atexit(void (*function)(void));
  70. FILE *stdin, *stdout, *stderr;
  71. /* string.h functions */
  72. void *memset(void *s, int c, size_t n);
  73. void *memcpy(void *dest, const void *src, size_t n);
  74. void *memmove(void *dest, const void *src, size_t n);
  75. size_t strlen(const char *s);
  76. int strcmp(const char *s1, const char *s2);
  77. int strcasecmp(const char *s1, const char *s2);
  78. int memcmp(const void *s1, const void *s2, size_t n);
  79. char *strdup(const char *s);
  80. char *strchr(const char *s, int c);
  81. /* stdarg.h functions */
  82. typedef void * va_list;
  83. #define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a))
  84. #define va_end(v)
  85. int vsnprintf(char *str, size_t size, const char *format, va_list ap);
  86. /* stdio.h functions */
  87. FILE *fopen(const char *path, const char *mode);
  88. int feof(FILE *stream);
  89. char *fgets(char *s, int size, FILE *stream);
  90. size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
  91. int fclose(FILE *fp);
  92. int printf(const char *format, ...);
  93. int fprintf(FILE *stream, const char *format, ...);
  94. int fflush(FILE *stream);
  95. int sprintf(char *str, const char *format, ...);
  96. int sscanf(const char *str, const char *format, ...);
  97. /* unistd.h functions */
  98. void usleep(unsigned long usec);
  99. int getpid(void);
  100. /* time.h functions */
  101. int gettimeofday(struct timeval *tv, struct timezone *tz);
  102. int time(void *);
  103. /* math.h functions */
  104. double cos(double x);
  105. double sin(double x);
  106. double sqrt(double x);
  107. /* errno.h functions */
  108. #define ENOENT 2 /* No such file or directory */
  109. #define ENOMEM 12 /* Out of memory */
  110. #define EBUSY 16 /* Device or resource busy */
  111. #define ENODEV 19 /* No such device */
  112. #define EINVAL 22 /* Invalid argument */
  113. #define ENOTTY 25 /* Not a typewriter */
  114. #define ENOSYS 38 /* Function not implemented */
  115. extern int errno;
  116. /* arpa/inet.h functions */
  117. unsigned int htonl(unsigned int hostlong);
  118. unsigned short htons(unsigned short hostlong);