common.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef COMMON_H
  2. #define COMMON_H
  3. #include "compiler.h"
  4. #include "sections.h"
  5. #include "picorv32.h"
  6. #include "irq.h"
  7. #define min(a,b) Min(a,b)
  8. #define max(a,b) Max(a,b)
  9. /* memcpy() variants */
  10. /* Use builtin memcpy and memset optimizations */
  11. #define memset(s,c,n) __builtin_memset(s,c,n)
  12. #define memcpy(d,s,n) __builtin_memcpy(d,s,n)
  13. #define mempcpy(d,s,n) __builtin_mempcpy(d,s,n)
  14. #define memmove(d,s,n) __builtin_memmove(d,s,n)
  15. extern volatile void *memcpy_bytewise(volatile void *dst,
  16. const volatile void *src, size_t len);
  17. /*
  18. * The odd argument order allows memcpy() and mempcpy() to be implemented
  19. * as tail calls
  20. */
  21. extern void *__memxcpy_aligned(void *retval,
  22. const void * restrict src, size_t len,
  23. void * restrict dst);
  24. extern void *__memxcpy_bytewise(void *retval,
  25. const volatile void * restrict src, size_t len,
  26. void * restrict dst);
  27. extern const size_t __rom_offset;
  28. extern const uint32_t __dram_checksum;
  29. extern const char __datestamp[];
  30. extern char __esplink_start[], __esplink_end[];
  31. extern char __dram_init_start[], __dram_init_end[];
  32. extern char __dram_bss_start[], __dram_bss_end[];
  33. static inline __constfunc size_t _align_down(size_t addr, size_t align)
  34. {
  35. return addr & ~(align - 1);
  36. }
  37. #define align_down(a,l) ((__typeof__(a))_align_down((size_t)(a),(l)))
  38. static inline __constfunc size_t _align_up(size_t addr, size_t align)
  39. {
  40. return _align_down(addr + align - 1, align);
  41. }
  42. #define align_up(a,l) ((__typeof__(a))_align_up((size_t)(a),(l)))
  43. struct esplink_head;
  44. extern struct esplink_head esplink_head;
  45. extern uint32_t esplink[];
  46. extern no_return _die(void);
  47. extern no_return exit(int);
  48. extern no_return _exit(int);
  49. /* Value of an absolute symbol with one more _ than here given */
  50. #define abssymval(x) \
  51. static inline size_t x (void) { \
  52. extern const char _ ## x []; \
  53. return (size_t) _ ## x; \
  54. }
  55. extern const uint8_t _end[];
  56. extern void *_sbrk(ptrdiff_t);
  57. extern uint32_t timer_irq_start;
  58. static inline uint32_t timer_count(void)
  59. {
  60. extern volatile uint32_t timer_irq_count;
  61. return timer_irq_count;
  62. }
  63. extern void init(void);
  64. extern void heap_init(void);
  65. extern void mount_abcdrives(void);
  66. extern void read_rtc(void);
  67. extern void write_rtc(void);
  68. extern volatile bool do_write_rtc;
  69. extern void rtc_abc_init(void);
  70. extern void rtc_abc_io_poll(void);
  71. extern void pun80_init(void);
  72. extern void romcopy_download(void *, size_t, size_t);
  73. extern void romcopy_bzero(void *, size_t);
  74. extern void rom_print_serial(void);
  75. extern qword_t rom_serial;
  76. extern void run_test_image(void);
  77. extern void rom_flash_from_memory(void *, size_t);
  78. extern void rom_flash_from_sdcard(void);
  79. #endif /* COMMON_H */