syscalls.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* Copyright 2018 Canaan Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #ifndef _BSP_SYSCALLS_H
  16. #define _BSP_SYSCALLS_H
  17. #include <machine/syscall.h>
  18. #include <stddef.h>
  19. #include <stdint.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /**
  26. * @brief Definitions for syscall putchar function
  27. *
  28. * @param[in] c The char to put
  29. *
  30. * @return result
  31. * - Byte On success, returns the written character.
  32. * - EOF On failure, returns EOF and sets the error indicator (see ferror()) on stdout.
  33. */
  34. typedef int (*sys_putchar_t)(char c);
  35. /**
  36. * @brief Definitions for syscall getchar function
  37. *
  38. * @return byte as int type to get
  39. * - Byte The character read as an unsigned char cast to an int
  40. * - EOF EOF on end of file or error, no enough byte to read
  41. */
  42. typedef int (*sys_getchar_t)(void);
  43. extern sys_putchar_t sys_putchar;
  44. extern sys_getchar_t sys_getchar;
  45. /**
  46. * @brief Register putchar function when perform write syscall
  47. *
  48. * @param[in] putchar The user-defined putchar function
  49. *
  50. * @return None
  51. */
  52. void sys_register_putchar(sys_putchar_t putchar);
  53. /**
  54. * @brief Register getchar function when perform read syscall
  55. *
  56. * @param[in] getchar The user-defined getchar function
  57. *
  58. * @return None
  59. */
  60. void sys_register_getchar(sys_getchar_t getchar);
  61. /**
  62. * @brief Flush stdin buffer
  63. *
  64. * @return None
  65. */
  66. void sys_stdin_flush(void);
  67. void __attribute__((noreturn)) sys_exit(int code);
  68. /**
  69. * @brief Get free memory
  70. *
  71. * @return The size of free memory
  72. */
  73. size_t get_free_heap_size(void);
  74. #ifdef __cplusplus
  75. }
  76. #endif
  77. #endif /* _BSP_SYSCALLS_H */