.data .text ; TODO: will the assembler be able to evaluate these expressions? UART_BASE=0x1000 UART_STATUS=(UART_BASE+0x4) UART_RECV=(UART_BASE+0x8) UART_TRANS=(UART_BASE+0xC) UART_BAUD=(UART_BAUD+0x10) UART_TRANS_EMPTY=0 UART_RECV_NEW=1 TIMEOUT_START=0x13371337 DEFAULT_PROG_START=0x200 STACKSTART=0x500 ; FIXME ;----- main: ; setup stackframe ldil r15, STACKSTART@lo ldih r15, STACKSTART@hi movst r15 ldil r3, TIMEOUT_START@lo ldih r3, TIMEOUT_START@hi timeout_loop: ldil r3, UART_STATUS@lo ldih r3, UART_STATUS@hi ldw r3, 0(r3) andi r3, r3, 1 << UART_RECV_NEW jumpzs+ next; jump if zero branch recv_byte ; we received the enter bootrom sign cmp r0, 0x48 ; 'H' jumpeq- bt_H next: subi r3, r3, 1 jumpnz+ timeout_loop ; branch to default entry point ldil r0, DEFAULT_PROG_START@lo ldih r0, DEFAULT_PROG_START@hi jumpreg r0 ;----- send_byte: ldil r3, UART_STATUS@lo ldih r3, UART_STATUS@hi ldw r3, 0(r3) andi r3, r3, 1 << UART_TRANS_EMPTY jumpzs+ send_byte ; jump if zero ldil r3, UART_TRANS@lo ldih r3, UART_TRANS@hi stb r1, 0(r3) ret ;----- send_word: ; TODO: loop? (less codesize...) lrs r0, r1, 0 branch send_byte lrs r0, r1, 8 branch send_byte lrs r0, r1, 16 branch send_byte lrs r0, r1, 24 branch send_byte ret ;----- recv_byte: ldil r3, UART_STATUS@lo ldih r3, UART_STATUS@hi ldw r3, 0(r3) andi r3, r3, 1 << UART_RECV_NEW jumpzs+ send_byte ; jump if zero ldil r3, UART_RECV@lo ldih r3, UART_RECV@hi lwb r0, 0(r3) ret ;----- recv_word: ldisl r0, 0x0 branch recv_byte or r0, r0, r1 branch recv_byte sll r1, r1, 8 or r0, r0, r1 branch recv_byte sll r1, r1, 16 or r0, r0, r1 branch recv_byte sll r1, r1, 24 or r0, r0, r1 ret ;----- bootrom: branch recv_byte cmpi r0, 0x57 ; 'W' jumpeq- bt_W cmpi r0, 0x52 ; 'R' jumpeq- bt_R cmpi r0, 0x51 ; 'Q' jumpeq- bt_Q cmpi r0, 0x54 ; 'T' jumpeq- bt_T cmpi r0, 0x4a ; 'J' jumpeq- bt_J ; cmpi r0, 0x48 ; 'H' ; jumpeq bt_H ; FALL THROUGH ;) bt_H: ldisl r1, 0x4f ; 'O' branch send_byte jump bootrom bt_W: branch recv_word ; receive addr mov r6, r0 branch recv_word ; receive instr stx r0, 0(r6) ldisl r1, 0x44 ; 'D' branch send_byte jump bootrom bt_R: branch recv_word ; receive addr mov r2, r0 ldisl r1, 0x46 ; 'F' branch send_byte ldx r1, 0(r2) branch send_word jump bootrom bt_Q: branch recv_word ; receive addr mov r6, r0 branch recv_word ; receive data stw r0, 0(r6) ldisl r1, 0x41 ; 'A' branch send_byte jump bootrom bt_T: branch recv_word ; receive addr mov r2, r0 ldisl r1, 0x47 ; 'G' branch send_byte ldw r1, 0(r2) branch send_word jump bootrom bt_J: branch recv_word jumpreg r0 ; 102 instr. please update after modification