1 ;; Org is set at 0 so that there is no padding before the sled.
2 ;; This code should be run from RAM; the address doesn't really matter.
5 code_size_guess == 0xB2
10 ;; MSP430f5510 definitions
21 ;; Format of payload: (all values MSP-endian)
23 ;; number of blocks: 1 byte
24 ;; checksum: 1 byte (byte such that two's complement sum of payload bytes == 0xff)
25 ;; repeat: (total of (payload length - 3) bytes)
26 ;; (start_address >> 8): 2 bytes
27 ;; block data: 512 bytes
29 ;; The shortest possible payload would thus be <<0x00 0xFF>>
30 ;; A payload that writes 0's to 0xFE00-0xFFFF would be:
31 ;; <<0x01 0x00 0xFE 0x00 0x00*512>>
33 ;; Assumptions/caveats:
34 ;; 1) Assume RAM is in low memory. It will fail miserably otherwise
35 ;; 2) All this code is very carefully written to be position-independent
39 ;; r4: start of payload
40 ;; r5: address of start
42 ;; the next two instructions must be the first two instructions after start
44 add #(code_size_guess + start - .), r5
47 bis.b #FLASH_LED+FAIL_LED, &LED_PORT+4
48 bic.b #FLASH_LED+FAIL_LED, &LED_PORT+2
60 rla r9, 1 ; Add r9*514 (r9<<1 + r9 << 9)
72 bis.b #FAIL_LED, &LED_PORT+2
81 ;; r10: dwords remaining
90 bis #FLASH_LED, &LED_PORT+2
93 rlam.a #4, r7 ; multiply by 256 to recover real address
99 mov #FWPW+ERASE, &FCTL1
104 ;; not sure whether I need to bounce LOCK here
106 mov #FWPW+BLKWRT+WRT, &FCTL1
111 add #4, r7 ; This was originally 2 incd insns
118 mov #FWPW+LOCK, &FCTL3
122 bic.b #FLASH_LED, &LED_PORT+2
123 bic.b #FAIL_LED, &LED_PORT+2
133 .if (payload-start) != code_size_guess
135 .print "Payload guess wrong"