@ This program dumps the contents of the Flash memory to the serial port at
@ 9600 8N1
@ It prints a '>' character, then three '.' characters, then the Flash contents

.arm
.text
.org 0

	.set HwUartControl,		0x000004C0
	.set HwUartData,		0x00000480
	.set HwPDDR,			0x00000003
	.set HwControl,			0x00000100
	.set HwControlUartEnable,	0x00000100
	.set HwControlExCkEn,		0x00040000
	.set HwSysFlg1,			0x00000140
	.set HwSysFlg1UBusy1,		1<<11
	.set HwSysFlg1UTxFF1,		1<<23
	.set HwSysFlg1URxFE1,		1<<22
	.set _start,			0
	.set FlashMem1Start,		0x70000000
	.set FlashMem1End,		0x70100000
	.set FlashMem2Start,		0x60000000
	.set FlashMem2End,		0x60100000

	.macro serialTx reg
	LDR r9,[r12,#HwSysFlg1]
	TST r9,#HwSysFlg1UTxFF1
	BNE .-8

	STRB \reg,[r12,#HwUartData]
	.endm

	.macro serialRx reg
	LDR r9,[r12,#HwSysFlg1]
	TST r9,#HwSysFlg1URxFE1
	BEQ .-8

	LDRB \reg,[r12,#HwUartData]
	.endm


	@LDR r0, =0x00070001
	@STR r0,[r12,#HwUartControl]
	LDR r10, =FlashMem1Start

	@serialRx r0
	
	LDR r0,='.'
	serialTx r0
	serialTx r0
	serialTx r0

Loop1:	LDR r0,[r10]
	serialTx r0
	mov r0,r0,lsr #8
	serialTx r0
	mov r0,r0,lsr #8
	serialTx r0
	mov r0,r0,lsr #8
	serialTx r0

	ADD r10,r10,#4	
	LDR r0,=FlashMem1End
	TEQ r10,r0
	BEQ SetMem2
	LDR r0,=FlashMem2End
	TEQ r10,r0
	BEQ Done
	B Loop1
	
SetMem2:
	LDR r10,=FlashMem2Start
	B Loop1

Done:	B Done

	.ltorg
	
.org 0x800, 0
