|
| 1 | +#include "otg.h" |
| 2 | +#include <stdint.h> |
| 3 | +#include <stdnoreturn.h> |
| 4 | + |
| 5 | +/* Image Build Information {{{1 |
| 6 | + * ----------------------- |
| 7 | + */ |
| 8 | +#define APE_IMAGE_NAME "OTG NCSI" |
| 9 | +#define APE_VER_MAJOR 1 |
| 10 | +#define APE_VER_MINOR 3 |
| 11 | +#define APE_VER_PATCH 7 |
| 12 | + |
| 13 | +// Originally these used dates/times in the format "Dec 3 2014" and "15:25:28" |
| 14 | +// respectively. We don't use dates/times since this needlessly affects build |
| 15 | +// determinism. We use something else meaningful instead. Note that these strings |
| 16 | +// must remain exactly 11 and 8 characters long, respectively. |
| 17 | +#define BUILD_DATE "OTG OTG OTG" |
| 18 | +#define BUILD_TIME "HAMSTROK" |
| 19 | +static_assert(sizeof(BUILD_DATE) == (11+1), "build date"); |
| 20 | +static_assert(sizeof(BUILD_TIME) == ( 8+1), "build time"); |
| 21 | + |
| 22 | +/* Globals {{{1 |
| 23 | + * ------- |
| 24 | + */ |
| 25 | +#ifdef PROPRIETARY |
| 26 | +/* scrubbed */ |
| 27 | +/* scrubbed */ |
| 28 | +#endif |
| 29 | + |
| 30 | +/* ISRs {{{1 |
| 31 | + * ---- |
| 32 | + */ |
| 33 | +extern isr_table g_isrTable; |
| 34 | + |
| 35 | +noreturn void AHang(void) { |
| 36 | + for(;;); |
| 37 | +} |
| 38 | + |
| 39 | +INTERRUPT void ISR_Exception(isr_args *args) { |
| 40 | + ISR_GET_REGS(); |
| 41 | + |
| 42 | +#ifdef PROPRIETARY |
| 43 | +/* scrubbed */ |
| 44 | +/* scrubbed */ |
| 45 | +/* scrubbed */ |
| 46 | +/* scrubbed */ |
| 47 | +/* scrubbed */ |
| 48 | +/* scrubbed */ |
| 49 | +/* scrubbed */ |
| 50 | +/* scrubbed */ |
| 51 | +/* scrubbed */ |
| 52 | +/* scrubbed */ |
| 53 | +/* scrubbed */ |
| 54 | +/* scrubbed */ |
| 55 | +/* scrubbed */ |
| 56 | +/* scrubbed */ |
| 57 | +/* scrubbed */ |
| 58 | +/* scrubbed */ |
| 59 | +/* scrubbed */ |
| 60 | +/* scrubbed */ |
| 61 | +/* scrubbed */ |
| 62 | +/* scrubbed */ |
| 63 | +/* scrubbed */ |
| 64 | +/* scrubbed */ |
| 65 | +/* scrubbed */ |
| 66 | +/* scrubbed */ |
| 67 | +/* scrubbed */ |
| 68 | +/* scrubbed */ |
| 69 | +/* scrubbed */ |
| 70 | +/* scrubbed */ |
| 71 | +/* scrubbed */ |
| 72 | +/* scrubbed */ |
| 73 | +/* scrubbed */ |
| 74 | +/* scrubbed */ |
| 75 | +/* scrubbed */ |
| 76 | +/* scrubbed */ |
| 77 | +/* scrubbed */ |
| 78 | +/* scrubbed */ |
| 79 | +/* scrubbed */ |
| 80 | +/* scrubbed */ |
| 81 | +#endif |
| 82 | +} |
| 83 | + |
| 84 | +INTERRUPT void ISR_SysTick(isr_args *args) { |
| 85 | + ISR_GET_REGS(); |
| 86 | +} |
| 87 | + |
| 88 | +INTERRUPT void ISR_SVCall(isr_args *args) { |
| 89 | + ISR_GET_REGS(); |
| 90 | +} |
| 91 | + |
| 92 | +/* Main {{{1 |
| 93 | + * ---- |
| 94 | + */ |
| 95 | +#ifdef PROPRIETARY |
| 96 | +/* scrubbed */ |
| 97 | +/* scrubbed */ |
| 98 | +/* scrubbed */ |
| 99 | +/* scrubbed */ |
| 100 | +/* scrubbed */ |
| 101 | +/* scrubbed */ |
| 102 | +/* scrubbed */ |
| 103 | +/* scrubbed */ |
| 104 | +/* scrubbed */ |
| 105 | +#endif |
| 106 | + |
| 107 | +/* Init {{{1 |
| 108 | + * ---- |
| 109 | + */ |
| 110 | +#ifdef PROPRIETARY |
| 111 | +/* scrubbed */ |
| 112 | +/* scrubbed */ |
| 113 | +/* scrubbed */ |
| 114 | +/* scrubbed */ |
| 115 | +/* scrubbed */ |
| 116 | +/* scrubbed */ |
| 117 | +/* scrubbed */ |
| 118 | +/* scrubbed */ |
| 119 | +/* scrubbed */ |
| 120 | +/* scrubbed */ |
| 121 | +/* scrubbed */ |
| 122 | +/* scrubbed */ |
| 123 | +/* scrubbed */ |
| 124 | +/* scrubbed */ |
| 125 | +/* scrubbed */ |
| 126 | +/* scrubbed */ |
| 127 | +/* scrubbed */ |
| 128 | +/* scrubbed */ |
| 129 | +/* scrubbed */ |
| 130 | +/* scrubbed */ |
| 131 | +/* scrubbed */ |
| 132 | +/* scrubbed */ |
| 133 | +/* scrubbed */ |
| 134 | +/* scrubbed */ |
| 135 | +/* scrubbed */ |
| 136 | +/* scrubbed */ |
| 137 | +/* scrubbed */ |
| 138 | +/* scrubbed */ |
| 139 | +/* scrubbed */ |
| 140 | +/* scrubbed */ |
| 141 | +/* scrubbed */ |
| 142 | +/* scrubbed */ |
| 143 | +/* scrubbed */ |
| 144 | +/* scrubbed */ |
| 145 | +/* scrubbed */ |
| 146 | +/* scrubbed */ |
| 147 | +/* scrubbed */ |
| 148 | +/* scrubbed */ |
| 149 | +/* scrubbed */ |
| 150 | +/* scrubbed */ |
| 151 | +/* scrubbed */ |
| 152 | +/* scrubbed */ |
| 153 | +/* scrubbed */ |
| 154 | +/* scrubbed */ |
| 155 | +/* scrubbed */ |
| 156 | +/* scrubbed */ |
| 157 | +/* scrubbed */ |
| 158 | +#endif |
| 159 | + |
| 160 | +NO_INLINE void AStart(void) { |
| 161 | +#ifdef PROPRIETARY |
| 162 | +/* scrubbed */ |
| 163 | +/* scrubbed */ |
| 164 | +/* scrubbed */ |
| 165 | +/* scrubbed */ |
| 166 | +/* scrubbed */ |
| 167 | +/* scrubbed */ |
| 168 | +/* scrubbed */ |
| 169 | +/* scrubbed */ |
| 170 | +/* scrubbed */ |
| 171 | +/* scrubbed */ |
| 172 | +/* scrubbed */ |
| 173 | +/* scrubbed */ |
| 174 | +#endif |
| 175 | +} |
| 176 | + |
| 177 | + |
| 178 | +/* Image Headers and Entrypoint {{{1 |
| 179 | + * ---------------------------- |
| 180 | + */ |
| 181 | +__attribute__((section(".textstart"), naked)) noreturn void AEntrypoint(isr_args *args) { |
| 182 | + asm( |
| 183 | + "ldr sp, =" STRINGIFY(STACK_END) "\n" |
| 184 | + "bl AStart\n" |
| 185 | + "bl AHang\n" |
| 186 | + ); |
| 187 | +} |
| 188 | + |
| 189 | +extern int _ScratchTextStart, _ScratchTextEnd, _ScratchTextSize, _ScratchTextOffset, _ScratchTextOffsetFlags; |
| 190 | +extern int _TextStart, _TextEnd, _TextSize, _TextOffset, _TextOffsetFlags; |
| 191 | +extern int _DataStart, _DataEnd, _DataSize, _DataOffset, _DataOffsetFlags; |
| 192 | +extern int _BSSStart, _BSSEnd, _BSSSize, _BSSOffset, _BSSOffsetFlags; |
| 193 | +extern int _AEntrypointM; |
| 194 | + |
| 195 | +const __attribute__((section(".header"))) ape_header gAPE_header = { |
| 196 | + .magic = "BCM\x1A", |
| 197 | + .unk04 = 0x03070700, // Unknown, not read by boot ROM. |
| 198 | + .imageName = APE_IMAGE_NAME " " STRINGIFY(APE_VER_MAJOR) "." STRINGIFY(APE_VER_MINOR) "." STRINGIFY(APE_VER_PATCH), |
| 199 | + .imageVersion = (APE_VER_MAJOR<<24) | (APE_VER_MINOR<<16) | (APE_VER_PATCH<<8), |
| 200 | + |
| 201 | + // Use the entrypoint vector with the thumb flag masked out; it's actually |
| 202 | + // completely inconsequential since the boot ROM will add it back in, but |
| 203 | + // the original images don't set it so we don't either. |
| 204 | + .entrypoint = (uint32_t)&_AEntrypointM, |
| 205 | + |
| 206 | + .unk020 = 0x00, // Unknown, not read by boot ROM. |
| 207 | + .headerSize = sizeof(ape_header)/4, |
| 208 | + .unk022 = 0x04, // Unknown, not read by boot ROM. |
| 209 | + .numSections = 4, |
| 210 | + .headerChecksum = 0xDEADBEEF, // Checksums are fixed later in apestamp. |
| 211 | + |
| 212 | + .sections = { |
| 213 | + [0] = { // "Scratchcode" |
| 214 | + .loadAddr = (uint32_t)&_ScratchTextStart, |
| 215 | + .offsetFlags = (uint32_t)&_ScratchTextOffsetFlags, |
| 216 | + .uncompressedSize = (uint32_t)&_ScratchTextSize, |
| 217 | + .compressedSize = 0, |
| 218 | + .checksum = 0xDEADBEEF, |
| 219 | + }, |
| 220 | + |
| 221 | + [1] = { // "Maincode" |
| 222 | + .loadAddr = (uint32_t)&_TextStart, |
| 223 | + .offsetFlags = (uint32_t)&_TextOffsetFlags, |
| 224 | + .uncompressedSize = (uint32_t)&_TextSize, |
| 225 | + .compressedSize = 0, |
| 226 | + .checksum = 0xDEADBEEF, |
| 227 | + }, |
| 228 | + |
| 229 | + [2] = { // "Data" |
| 230 | + .loadAddr = (uint32_t)&_DataStart, |
| 231 | + .offsetFlags = (uint32_t)&_DataOffsetFlags, |
| 232 | + .uncompressedSize = (uint32_t)&_DataSize, |
| 233 | + .compressedSize = 0, |
| 234 | + .checksum = 0xDEADBEEF, |
| 235 | + }, |
| 236 | + |
| 237 | + [3] = { // "BSS" |
| 238 | + .loadAddr = (uint32_t)&_BSSStart, |
| 239 | + .offsetFlags = (uint32_t)&_BSSOffsetFlags, |
| 240 | + .uncompressedSize = (uint32_t)&_BSSSize, |
| 241 | + .compressedSize = 0, |
| 242 | + .checksum = 0, |
| 243 | + }, |
| 244 | + }, |
| 245 | +}; |
| 246 | + |
| 247 | +__attribute__((section(".isrtable"))) isr_table g_isrTable = { |
| 248 | + .stackEnd = (void*)STACK_END, |
| 249 | + .reset = AEntrypoint, |
| 250 | + .nmi = ISR_Exception, |
| 251 | + .hardFault = ISR_Exception, |
| 252 | + .memManage = ISR_Exception, |
| 253 | + .busFault = ISR_Exception, |
| 254 | + .usageFault = ISR_Exception, |
| 255 | + .svCall = ISR_SVCall, |
| 256 | + .debugMon = ISR_Exception, |
| 257 | + .pendSV = ISR_Exception, |
| 258 | + .sysTick = ISR_SysTick, |
| 259 | + .ext = { |
| 260 | + [EXTINT_HANDLE_EVENT] = ISR_Exception, |
| 261 | + [EXTINT_03H] = ISR_Exception, |
| 262 | + [EXTINT_H2B] = ISR_Exception, |
| 263 | + [EXTINT_0AH] = ISR_Exception, |
| 264 | + [EXTINT_RX_PACKET_EVEN_PORTS] = ISR_Exception, |
| 265 | + [EXTINT_SMBUS_0] = ISR_Exception, |
| 266 | + [EXTINT_SMBUS_1] = ISR_Exception, |
| 267 | + [EXTINT_RMU_EGRESS] = ISR_Exception, |
| 268 | + [EXTINT_GEN_STATUS_CHANGE] = ISR_Exception, |
| 269 | + [EXTINT_VOLTAGE_SOURCE_CHANGE] = ISR_Exception, |
| 270 | + [EXTINT_LINK_STATUS_CHANGE_EVEN_PORTS] = ISR_Exception, |
| 271 | + [EXTINT_LINK_STATUS_CHANGE_ODD_PORTS] = ISR_Exception, |
| 272 | + [EXTINT_RX_PACKET_ODD_PORTS] = ISR_Exception, |
| 273 | + }, |
| 274 | +}; |
| 275 | + |
| 276 | +__attribute__((section(".trailingcrc"))) uint32_t g_trailingCRC = 0xDEADBEEF; |
0 commit comments