Advertisement
SciresM

[WIP] MCU v2.0 firmware initialization documentation

Aug 30th, 2016
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. // MCU v2.0 firmware bootup code documentation
  2. // for hardware reg names/documentation, see
  3. //http://courses.ee.sun.ac.za/Computer_Systems_245/Dokumentasie/RL78%20hardware%20manual%20(registers).pdf
  4. [Select Register Bank 0]
  5. SP = 0xFE00 (== 0xFFE00)
  6. call 1AF:
  7. di
  8. CMC = 0x10
  9. CSC = 0x80
  10. OSMC = 1
  11. CKX = 8
  12. LVIS = 0
  13. LVIM = 0
  14. ax = 0
  15. b = 0xC0
  16. while (b)
  17. {
  18. b -= 2;
  19. *(0xFFE20+b) = ax // zero_out(0xFFE20, 0xC0); // Clear out stack?
  20. }
  21. es = 0
  22. hl = 0x4F8C
  23. de = 0xFD32
  24. branch: 0xD6F.
  25. --
  26. ax = hl (4F8C)
  27. while (ax != 0x4FC2)
  28. {
  29. *(de) = a // (0x4F)
  30. hl++;
  31. de++;
  32. ax = hl
  33. // Set 0xFFD32-0xFFD66 to 0x4F [?]
  34. }
  35. hl = 0xF902
  36. ax = 0xFD32
  37. branch: d81
  38. while (ax != hl)
  39. {
  40. *(hl) = 0
  41. hl++;
  42. //zero_out(0xF902, 0x430);
  43. }
  44. hl = 0x4F81
  45. de = 0xfd68
  46. branch: d93
  47. ax = hl;
  48. while (ax != 0x4F81) { // does undocumented stuff } // This never runs...ax == 0x4F81
  49. hl = 0xfd68;
  50. ax = 0xfd68;
  51. while (ax != hl) { // does undocumented stuff } // Again, weird while loop...nothing!
  52. call 0xCE:
  53. hl = sp
  54. WDTE = 0xAC // Watchdog timer
  55. push hl
  56. hl = 0xF0
  57. cy = hl.7 // cy = 1
  58. pop hl
  59. if (cy)
  60. *(0xff924) |= 1
  61. a = RESF
  62. *(hl + 1) = a
  63. a = *(hl + 1)
  64. a &= 0x10
  65. if (a) // Reset occurred due to Watchdog timer
  66. *(0xFFBDA) |= 2
  67. *(0xFF924) |= 1
  68. else
  69. a = *(hl + 1)
  70. a &= 0x80
  71. if (a) // Reset occurred due to illegal instruction
  72. *(0xFF924) |= 1
  73. a = *(0xFF924)
  74. if (!(a & 1))
  75. ax = 0
  76. ax--; // ax = 0xFFFF
  77. *hl = ax
  78. ax = 0
  79. while (ax != hl) // Wait loop?
  80. (*hl)--;
  81. ax = 0
  82. call 0x1C5: // reset_registers(), maybe?
  83. a = *0xFF924
  84. if (a & 1)
  85. P0 = 3
  86. P3 = 7
  87. P14 = 0
  88. else
  89. P0 = 0
  90. P3 = 6
  91. P14 = 0
  92. PM0 = 0xFF
  93. PM3 = 0xF0
  94. PM14 = 0xFC
  95. a = 0xFF924
  96. if (!(a & 1))
  97. *0xf0510 = 0
  98. P1 = 0xC0
  99. P2 = 0
  100. P4 = 8
  101. P5 = 0
  102. P6 = 0x0
  103. P7 = 0x40
  104. P12 = 0x0
  105. P15 = 0
  106. *F00F2 &= 0xFE
  107. ax = 0x00FF
  108. TT0 = ax
  109. ax = 0
  110. IF0 = ax
  111. IF1 = ax
  112. IF2 = ax
  113. MK0 = 0xFFFF
  114. MK1 = 0xFFFF
  115. MK2 = 0xFFFF
  116. *(0xF0511) = 0xFC
  117. PM1 = 0
  118. PM2 = 0xE9
  119. PM4 = 0xF3
  120. PM5 = 0xF2
  121. PM6 = 0xFC
  122. PM7 = 0x4F
  123. PM12 = 0xFF
  124. PM15 = 0xFF
  125. *(0xf0512) = 0x11
  126. PU0 = 0
  127. PU1 = 0
  128. PU3 = 0
  129. PU4 = 0
  130. PU5 = 2
  131. PU7 = 0x19
  132. PU12 = 0x0
  133. PU14 = 0x0
  134. *(0xf0043) = 0 // PIM3? What is this SFR
  135. *(0xf0047) = 0 // PIM7?
  136. *(0xF0053) = 6 // POM3?
  137. *(0xf0057) = 0 // POM6?
  138. PR00 = 0xFFFF
  139. PR01 = 0xFFFF
  140. PR10 = 0xFFFF
  141. PR11 = 0xFFFE
  142. PR02L = 0xFF
  143. PR12L = 0xFF
  144. EGP0 = 0x31 // External interrupt rising edge enable
  145. EGN0 = 0x60 // External interrupt falling edge enable
  146. *(0xf0538) = 0xA
  147. *(0xf0539) = 0x0
  148. KRM = 0
  149. PER0 &= 0xDF // ADCEN = 0, disables clock supply to A/D converter input, disables A/D SFRs
  150. ADM0 = 0 // Does this do anything? ADCEN just got disabled, so A/D is in reset mode...
  151. PER0 &= 0xFB // SAU0EN = 0, Disables Serial Array unit 0.
  152. x = 0x87 // a is 0, so ax == 0x0087
  153. SRC0 = ax // 0x87
  154. SRC1 = ax // 0x87
  155. SRC2 = ax // 0x87
  156. SRC3 = ax // 0x87
  157. PER0 &= 0xEF // ICA0EN = 0, disables clock supply to IICA0, disables IICA0 SFRs (I2C)
  158. // Given the trends, these must be the I2C registers:
  159. IICCTL00 = 0
  160. *(0xF0501) &= 0xFE
  161. *(0xF0550) = 0
  162. // DMA control register clearing
  163. DRC0 = 0
  164. DRC1 = 0
  165. // Clock output select clearing
  166. CKS0 = 0
  167. CKS1 = 0
  168. *(hl) = 0x0000
  169. // [NOT FINISHED DOCUMENTING YET]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement