Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

kernel.h 3.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. * 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. /** \file kernel.h
  13. * \version \$Id$
  14. * \author Sam Hocevar <sam@zoy.org>
  15. * \brief Kernel features
  16. *
  17. * This file contains replacement functions for the standard C library
  18. * that must be used when building libcucul and libcaca into a kernel.
  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)
  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 char uint8_t;
  44. typedef unsigned short uint16_t;
  45. typedef unsigned long int uint32_t;
  46. typedef long int intptr_t;
  47. typedef long unsigned int uintptr_t;
  48. typedef unsigned int size_t;
  49. typedef struct file
  50. {
  51. void *mem;
  52. } FILE;
  53. struct timeval {
  54. int tv_sec;
  55. int tv_usec;
  56. };
  57. struct timezone {
  58. int tz_minuteswest;
  59. int tz_dsttime;
  60. };
  61. /* Multiboot kernel entry point */
  62. void cmain(unsigned long int magic, unsigned long int addr);
  63. /* The application's entry point */
  64. int main(int argc, char *argv[]);
  65. /* stdlib.h functions */
  66. void *malloc(size_t size);
  67. void free(void *ptr);
  68. void *realloc(void *ptr, size_t size);
  69. char *getenv(const char *name);
  70. int rand(void);
  71. int abs(int j);
  72. void exit(int status);
  73. /* string.h functions */
  74. void *memset(void *s, int c, size_t n);
  75. void *memcpy(void *dest, const void *src, size_t n);
  76. size_t strlen(const char *s);
  77. int strcasecmp(const char *s1, const char *s2);
  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. int fclose(FILE *fp);
  88. int printf(const char *format, ...);
  89. int sprintf(char *str, const char *format, ...);
  90. int sscanf(const char *str, const char *format, ...);
  91. /* unistd.h functions */
  92. void usleep(unsigned long usec);
  93. /* time.h functions */
  94. int gettimeofday(struct timeval *tv, struct timezone *tz);
  95. /* math.h functions */
  96. double cos(double x);
  97. double sin(double x);
  98. double sqrt(double x);