summaryrefslogtreecommitdiff
path: root/bootrom/demo/demo.S
blob: c6f26185787f8ba654abe64637cbaefd26ffe882 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#define UART_BASE	0x48000000
#define SPI_BASE	0x48001000
#define GPIO_BASE	0x48002000

#ifndef CFG_STRING
#error Must define CFG_STRING
#endif	
        
	.globl _start
_start:
	j uart_init
	nop
	nop
	.word cfgstr

uart_init:
        // a1 = UART_TX
        // a2 = hello_msg_end
        // for (a0 = hello_msg_start; a0 != a2; ++ a0){
        //   while (a3 = TX_READY == 0);
        //   a3 = *a0
        //   *a1 = a3
        // }

        la a0, hello_msg_start
        la a2, hello_msg_end
        li a1, UART_BASE
                
uart_loop:      
        lw a3, 4(a1) // Wait until non-zero (uart can send data).
        beqz a3, uart_loop

        lb a3, 0(a0) // read the next character in hello_msg
        sw a3, 0(a1) // Write the current character.
        addi a0, a0, 1 // increment the pointer.
        bne  a0, a2, uart_loop

gpio_init:   
	li a0, GPIO_BASE
        li t0, 0xFFFF0000
        sw t0, 4(a0)
        
gpio_loop:
        // For Red LEDs, increment manually.
	li t0, 0x1
	sw t0, (a0)
	li t0, 0x2
	sw t0, (a0)
	li t0, 0x4
	sw t0, (a0)
	li t0, 0x8
	sw t0, (a0)

        // For Blue and Green LEDs, sample the switches & buttons

        lw   t0, (a0)
        srli t0, t0, 16
	andi t0, t0, 0xFF
        slli t0, t0, 4
        sw   t0, (a0)

        j gpio_loop

	.section .rodata

hello_msg_start:
        .incbin "hello_msg.txt"
hello_msg_end:  
                
cfgstr:
	.incbin CFG_STRING