選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

kernel.h 3.6 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. /* Various defines */
  19. #define NULL ((void *)0)
  20. #define BUFSIZ 4096
  21. #define RAND_MAX ((unsigned int)0x8000000)
  22. #define INT_MAX ((int)0x7fffffff)
  23. #define M_PI 3.14159265358979323846
  24. #define __BYTE_ORDER 1
  25. #define __BIG_ENDIAN 2
  26. /* Assembly code for outb and inb */
  27. extern inline void outb(unsigned char val, unsigned short port);
  28. extern inline unsigned char inb(unsigned short port);
  29. extern inline void outb(unsigned char val, unsigned short port)
  30. {
  31. __asm__ __volatile__ ("outb %b0,%w1" : : "a" (val), "Nd" (port));
  32. }
  33. extern inline unsigned char inb(unsigned short port)
  34. {
  35. unsigned char tmp;
  36. __asm__ __volatile__ ("inb %w1,%0" : "=a" (tmp) : "Nd" (port));
  37. return tmp;
  38. }
  39. /* Various typedefs -- some are x86-specific */
  40. #define CUSTOM_INTTYPES
  41. typedef unsigned int size_t;
  42. typedef struct file
  43. {
  44. void *mem;
  45. } FILE;
  46. struct timeval {
  47. int tv_sec;
  48. int tv_usec;
  49. };
  50. struct timezone {
  51. int tz_minuteswest;
  52. int tz_dsttime;
  53. };
  54. /* Multiboot kernel entry point */
  55. void cmain(unsigned long int magic, unsigned long int addr);
  56. /* The application's entry point */
  57. int main(int argc, char *argv[]);
  58. /* stdlib.h functions */
  59. void *malloc(size_t size);
  60. void free(void *ptr);
  61. void *realloc(void *ptr, size_t size);
  62. char *getenv(const char *name);
  63. int rand(void);
  64. int abs(int j);
  65. void exit(int status);
  66. void srand(unsigned int s);
  67. FILE *stdin, *stdout, *stderr;
  68. /* string.h functions */
  69. void *memset(void *s, int c, size_t n);
  70. void *memcpy(void *dest, const void *src, size_t n);
  71. size_t strlen(const char *s);
  72. int strcasecmp(const char *s1, const char *s2);
  73. int memcmp(const void *s1, const void *s2, size_t n);
  74. /* stdarg.h functions */
  75. typedef void * va_list;
  76. #define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a))
  77. #define va_end(v)
  78. int vsnprintf(char *str, size_t size, const char *format, va_list ap);
  79. /* stdio.h functions */
  80. FILE *fopen(const char *path, const char *mode);
  81. int feof(FILE *stream);
  82. char *fgets(char *s, int size, FILE *stream);
  83. size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
  84. int fclose(FILE *fp);
  85. int printf(const char *format, ...);
  86. int fprintf(FILE *stream, const char *format, ...);
  87. int sprintf(char *str, const char *format, ...);
  88. int sscanf(const char *str, const char *format, ...);
  89. /* unistd.h functions */
  90. void usleep(unsigned long usec);
  91. int getpid(void);
  92. /* time.h functions */
  93. int gettimeofday(struct timeval *tv, struct timezone *tz);
  94. int time(void *);
  95. /* math.h functions */
  96. double cos(double x);
  97. double sin(double x);
  98. double sqrt(double x);
  99. /* errno.h functions */
  100. #define ENOENT 2 /* No such file or directory */
  101. #define ENOMEM 12 /* Out of memory */
  102. #define EBUSY 16 /* Device or resource busy */
  103. #define ENODEV 19 /* No such device */
  104. #define EINVAL 22 /* Invalid argument */
  105. #define ENOTTY 25 /* Not a typewriter */
  106. #define ENOSYS 38 /* Function not implemented */
  107. extern int errno;
  108. /* arpa/inet.h functions */
  109. unsigned int htonl(unsigned int hostlong);
  110. unsigned short htons(unsigned short hostlong);