fw.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef FW_H
  2. #define FW_H
  3. #include <stdarg.h>
  4. #include <stddef.h>
  5. #include <stdint.h>
  6. #include <stdbool.h>
  7. #include "picorv32.h"
  8. #include "irq.h"
  9. /* Use builtin memcpy and memset optimizations */
  10. #define memset(s,c,n) __builtin_memset(s,c,n)
  11. #define memcpy(d,s,n) __builtin_memcpy(d,s,n)
  12. #define memmove(d,s,n) __builtin_memmove(d,s,n)
  13. extern void *
  14. __memcpy_aligned(void * __restrict, const void * __restrict, size_t);
  15. #define likely(x) __builtin_expect(!!(x), 1)
  16. #define unlikely(x) __builtin_expect(!!(x), 0)
  17. /* Handy composite pointer types */
  18. typedef union xptr {
  19. uint32_t *l;
  20. uint16_t *w;
  21. uint8_t *b;
  22. void *v;
  23. size_t a;
  24. } xptr_t;
  25. typedef union xcptr {
  26. const uint32_t *l;
  27. const uint16_t *w;
  28. const uint8_t *b;
  29. const void *v;
  30. size_t a;
  31. } xcptr_t;
  32. /* The container_of construct: if p is a pointer to member m of
  33. container class c, then return a pointer to the container of which
  34. *p is a member. */
  35. #ifndef container_of
  36. # define container_of(p, c, m) ((c *)((char *)(p) - offsetof(c,m)))
  37. #endif
  38. #define offset_diff(c, m1, m2) ((ptrdiff_t)offsetof(c,m2) - (ptrdiff_t)offsetof(c,m1))
  39. #define min(a,b) (((a) < (b)) ? (a) : (b))
  40. #define max(a,b) (((a) > (b)) ? (a) : (b))
  41. #define no_return void __attribute__((noreturn))
  42. #define __dram_bss __attribute__((section(".dram.bss")))
  43. #define __dram_noinit __attribute__((section(".dram.noinit")))
  44. extern no_return _die(void);
  45. extern no_return exit(int);
  46. extern no_return _exit(int);
  47. extern const uint8_t _end[];
  48. extern void *_sbrk(size_t);
  49. extern int disk_init(void);
  50. extern void mount_abcdrives(void);
  51. extern void read_rtc(void);
  52. #endif /* FW_H */