common.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. static uint32_t mask_lowest_set_bit(uint32_t mask)
  44. {
  45. return mask & (mask-1);
  46. }
  47. static uint32_t lowest_set_bit(uint32_t mask)
  48. {
  49. return mask - mask_lowest_set_bit(mask);
  50. }
  51. static const char *notempty(const char *str)
  52. {
  53. return str ? str : "";
  54. }
  55. struct esplink_head;
  56. extern struct esplink_head esplink_head;
  57. extern uint32_t esplink[];
  58. extern no_return _die(void);
  59. extern no_return exit(int);
  60. extern no_return _exit(int);
  61. /* Value of an absolute symbol with one more _ than here given */
  62. #define abssymval(x) \
  63. static inline size_t x (void) { \
  64. extern const char _ ## x []; \
  65. return (size_t) _ ## x; \
  66. }
  67. extern const uint8_t _end[];
  68. extern void *_sbrk(ptrdiff_t);
  69. extern uint32_t timer_irq_start;
  70. static inline uint32_t timer_count(void)
  71. {
  72. extern volatile uint32_t timer_irq_count;
  73. return timer_irq_count;
  74. }
  75. extern void init(void);
  76. extern void heap_init(void);
  77. extern void mount_abcdrives(void);
  78. extern void read_rtc(void);
  79. extern void write_rtc(void);
  80. extern volatile bool do_write_rtc;
  81. extern void romcopy_download(void *, size_t, size_t);
  82. extern void romcopy_bzero(void *, size_t);
  83. extern void rom_print_serial(void);
  84. extern qword_t rom_serial;
  85. extern void run_test_image(void);
  86. extern void rom_flash_from_memory(void *, size_t);
  87. extern void rom_flash_from_sdcard(void);
  88. extern no_return shutdown(unsigned int);
  89. #endif /* COMMON_H */