You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kernel.h 2.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. /** \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 __BYTE_ORDER 1
  26. #define __BIG_ENDIAN 2
  27. /* Assembly code for outb and inb */
  28. extern inline void outb(unsigned char val, unsigned short port);
  29. extern inline unsigned char inb(unsigned short port);
  30. extern inline void outb(unsigned char val, unsigned short port)
  31. {
  32. __asm__ __volatile__ ("outb %b0,%w1" : : "a" (val), "Nd" (port));
  33. }
  34. extern inline unsigned char inb(unsigned short port)
  35. {
  36. unsigned char tmp;
  37. __asm__ __volatile__ ("inb %w1,%0" : "=a" (tmp) : "Nd" (port));
  38. return tmp;
  39. }
  40. /* Various typedefs -- some are x86-specific */
  41. #define CUSTOM_INTTYPES
  42. typedef unsigned char uint8_t;
  43. typedef unsigned short uint16_t;
  44. typedef unsigned long int uint32_t;
  45. typedef long int intptr_t;
  46. typedef long unsigned int uintptr_t;
  47. typedef unsigned int size_t;
  48. typedef struct file
  49. {
  50. void *mem;
  51. } FILE;
  52. struct timeval {
  53. int tv_sec;
  54. int tv_usec;
  55. };
  56. struct timezone {
  57. int tz_minuteswest;
  58. int tz_dsttime;
  59. };
  60. /* Multiboot kernel entry point */
  61. void cmain(unsigned long int magic, unsigned long int addr);
  62. /* The application's entry point */
  63. int main(int argc, char *argv[]);
  64. /* stdlib.h functions */
  65. void *malloc(size_t size);
  66. void free(void *ptr);
  67. void *realloc(void *ptr, size_t size);
  68. char *getenv(const char *name);
  69. int rand(void);
  70. int abs(int j);
  71. void exit(int status);
  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. /* stdarg.h functions */
  78. typedef void * va_list;
  79. #define va_start(v,a) v = (void *)((uintptr_t)(&a) + sizeof(a))
  80. #define va_end(v)
  81. int vsnprintf(char *str, size_t size, const char *format, va_list ap);
  82. /* stdio.h functions */
  83. FILE *fopen(const char *path, const char *mode);
  84. int feof(FILE *stream);
  85. char *fgets(char *s, int size, FILE *stream);
  86. int fclose(FILE *fp);
  87. int printf(const char *format, ...);
  88. int sprintf(char *str, const char *format, ...);
  89. int sscanf(const char *str, const char *format, ...);
  90. /* unistd.h functions */
  91. void usleep(unsigned long usec);
  92. /* time.h functions */
  93. int gettimeofday(struct timeval *tv, struct timezone *tz);