Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

126 рядки
3.2 KiB

  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$
  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. * This file contains replacement functions for the standard C library
  16. * that must be used when building libcucul and libcaca into a kernel.
  17. */
  18. #ifndef __KERNEL_H_
  19. #define __KERNEL_H_
  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. /* 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 stdint;
  70. int stdout;
  71. int stderr;
  72. /* string.h functions */
  73. void *memset(void *s, int c, size_t n);
  74. void *memcpy(void *dest, const void *src, size_t n);
  75. size_t strlen(const char *s);
  76. int strcasecmp(const char *s1, const char *s2);
  77. int memcmp(const char *s1, const char *s2, size_t n);
  78. /* stdarg.h functions */
  79. typedef void * va_list;
  80. #define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a))
  81. #define va_end(v)
  82. int vsnprintf(char *str, size_t size, const char *format, va_list ap);
  83. /* stdio.h functions */
  84. FILE *fopen(const char *path, const char *mode);
  85. int feof(FILE *stream);
  86. char *fgets(char *s, int size, FILE *stream);
  87. size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
  88. int fclose(FILE *fp);
  89. int printf(const char *format, ...);
  90. int sprintf(char *str, const char *format, ...);
  91. int sscanf(const char *str, const char *format, ...);
  92. /* unistd.h functions */
  93. void usleep(unsigned long usec);
  94. int getpid(void);
  95. /* time.h functions */
  96. int gettimeofday(struct timeval *tv, struct timezone *tz);
  97. int time(void *);
  98. /* math.h functions */
  99. double cos(double x);
  100. double sin(double x);
  101. double sqrt(double x);
  102. /* arpa/inet.h functions */
  103. unsigned int htonl(unsigned int hostlong);
  104. unsigned short htons(unsigned short hostlong);
  105. #endif /* __KERNEL_H_ */