rom.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Headers to the various functions in the rom (as we discover them)
  2. #ifndef _ROM_H_
  3. #define _ROM_H_
  4. // SHA1 is assumed to match the netbsd sha1.h headers
  5. #define SHA1_DIGEST_LENGTH 20
  6. #define SHA1_DIGEST_STRING_LENGTH 41
  7. typedef struct {
  8. uint32_t state[5];
  9. uint32_t count[2];
  10. uint8_t buffer[64];
  11. } SHA1_CTX;
  12. extern void SHA1Transform(uint32_t[5], const uint8_t[64]);
  13. extern void SHA1Init(SHA1_CTX *);
  14. extern void SHA1Final(uint8_t[SHA1_DIGEST_LENGTH], SHA1_CTX *);
  15. extern void SHA1Update(SHA1_CTX *, const uint8_t *, unsigned int);
  16. // MD5 is assumed to match the NetBSD md5.h header
  17. #define MD5_DIGEST_LENGTH 16
  18. typedef struct
  19. {
  20. uint32_t state[5];
  21. uint32_t count[2];
  22. uint8_t buffer[64];
  23. } MD5_CTX;
  24. extern void MD5Init(MD5_CTX *);
  25. extern void MD5Update(MD5_CTX *, const unsigned char *, unsigned int);
  26. extern void MD5Final(unsigned char[MD5_DIGEST_LENGTH], MD5_CTX *);
  27. // base64_encode/decode derived by Cal
  28. // Appears to match base64.h from netbsd wpa utils.
  29. extern unsigned char * base64_encode(const unsigned char *src, size_t len, size_t *out_len);
  30. extern unsigned char * base64_decode(const unsigned char *src, size_t len, size_t *out_len);
  31. // Unfortunately it that seems to require the ROM memory management to be
  32. // initialized because it uses mem_malloc
  33. extern void mem_init(void * start_addr);
  34. // Interrupt Service Routine functions
  35. typedef void (*ets_isr_fn) (void *arg, uint32_t sp);
  36. extern int ets_isr_attach (unsigned int interrupt, ets_isr_fn, void *arg);
  37. extern void ets_isr_mask (unsigned intr);
  38. extern void ets_isr_unmask (unsigned intr);
  39. // Cycle-counter
  40. extern unsigned int xthal_get_ccount (void);
  41. extern int xthal_set_ccompare (unsigned int timer_number, unsigned int compare_value);
  42. // 2, 3 = reset (module dependent?), 4 = wdt
  43. int rtc_get_reset_reason (void);
  44. // Hardware exception handling
  45. struct exception_frame
  46. {
  47. uint32_t epc;
  48. uint32_t ps;
  49. uint32_t sar;
  50. uint32_t unused;
  51. union {
  52. struct {
  53. uint32_t a0;
  54. // note: no a1 here!
  55. uint32_t a2;
  56. uint32_t a3;
  57. uint32_t a4;
  58. uint32_t a5;
  59. uint32_t a6;
  60. uint32_t a7;
  61. uint32_t a8;
  62. uint32_t a9;
  63. uint32_t a10;
  64. uint32_t a11;
  65. uint32_t a12;
  66. uint32_t a13;
  67. uint32_t a14;
  68. uint32_t a15;
  69. };
  70. uint32_t a_reg[15];
  71. };
  72. uint32_t cause;
  73. };
  74. /**
  75. * C-level exception handler callback prototype.
  76. *
  77. * Does not need an RFE instruction - it is called through a wrapper which
  78. * performs state capture & restore, as well as the actual RFE.
  79. *
  80. * @param ef An exception frame containing the relevant state from the
  81. * exception triggering. This state may be manipulated and will
  82. * be applied on return.
  83. * @param cause The exception cause number.
  84. */
  85. typedef void (*exception_handler_fn) (struct exception_frame *ef, uint32_t cause);
  86. /**
  87. * Sets the exception handler function for a particular exception cause.
  88. * @param handler The exception handler to install.
  89. * If NULL, reverts to the XTOS default handler.
  90. * @returns The previous exception handler, or NULL if none existed prior.
  91. */
  92. exception_handler_fn _xtos_set_exception_handler (uint32_t cause, exception_handler_fn handler);
  93. #endif