Hardware Design: SIE
Sign in or create your account | Project List | Help
Hardware Design: SIE Commit Details
Date: | 2010-10-13 15:49:36 (12 years 11 months ago) |
---|---|
Author: | Carlos Camargo |
Commit: | 7b666c041a17337c4cf022200ff91c6e02081184 |
Message: | lm32 loader |
Files: |
lm32/logic/sakc/firmware/boot0-serial/Makefile (1 diff) lm32/logic/sakc/firmware/loader_cain/Makefile (1 diff) lm32/logic/sakc/firmware/loader_cain/crt0ram.S (3 diffs) lm32/logic/sakc/firmware/loader_cain/linker.ld (5 diffs) lm32/logic/sakc/firmware/loader_cain/main.c (1 diff) lm32/logic/sakc/firmware/loader_cain/soc-hw.c (3 diffs) lm32/logic/sakc/firmware/loader_cain/soc-hw.h (2 diffs) lm32/logic/sakc/firmware/loader_cain/xmodem.c (1 diff) lm32/logic/sakc/system.v (1 diff) |
Change Details
lm32/logic/sakc/firmware/boot0-serial/Makefile | ||
---|---|---|
4 | 4 | LM32_OBJDUMP=lm32-elf-objdump |
5 | 5 | |
6 | 6 | SREC2VRAM ?= ../../tools/srec2vram/srec2vram |
7 | ||
8 | 7 | VRAMFILE=image.ram |
9 | 8 | |
10 | 9 | CFLAGS=-MMD -O2 -Wall -g -s -fomit-frame-pointer -mbarrel-shift-enabled -mmultiply-enabled -mdivide-enabled -msign-extend-enabled |
11 | 10 | LDFLAGS=-nostdlib -nodefaultlibs -Tlinker.ld |
12 | 11 | SEGMENTS = -j .text -j .rodata -j .data |
13 | 12 | |
14 | all: $(VRAMFILE) | |
13 | all: image.srec $(VRAMFILE) | |
15 | 14 | |
16 | 15 | crt0ram.o: crt0ram.S |
17 | 16 | $(LM32_CC) $(CFLAGS) -c crt0ram.S |
lm32/logic/sakc/firmware/loader_cain/Makefile | ||
---|---|---|
21 | 21 | soc-hw.o: soc-hw.c |
22 | 22 | $(LM32_CC) $(CFLAGS) -c soc-hw.c |
23 | 23 | |
24 | ||
25 | 24 | xmodem.o: xmodem.c |
26 | 25 | $(LM32_CC) $(CFLAGS) -c xmodem.c |
27 | 26 | |
28 | ||
29 | image: crt0ram.o main.o soc-hw.o xmodem.o linker.ld Makefile | |
30 | $(LM32_LD) $(LDFLAGS) -Map image.map -N -o image crt0ram.o main.o soc-hw.o xmodem.o | |
27 | image: crt0ram.o main.o soc-hw.o xmodem.o | |
28 | $(LM32_LD) $(LDFLAGS) -Map image.map -N -o image crt0ram.o main.o soc-hw.o xmodem.o | |
31 | 29 | |
32 | 30 | image.lst: image |
33 | 31 | $(LM32_OBJDUMP) -h -S $< > $@ |
34 | 32 | |
35 | 33 | image.bin: image |
36 | $(LM32_OBJCOPY) $(SEGMENTS) -O binary image image.bin | |
34 | $(LM32_OBJCOPY) $(SEGMENTS) -O srec image image.bin | |
35 | $(LM32_OBJCOPY) $(SEGMENTS) -O binary image image_bin.bin | |
37 | 36 | |
38 | 37 | image.srec: image image.lst |
39 | 38 | $(LM32_OBJCOPY) $(SEGMENTS) -O srec image image.srec |
40 | 39 | |
40 | $(VHDLFILE): image.srec | |
41 | $(SREC2VHDL) image.srec > $(VHDLFILE) | |
42 | ||
41 | 43 | $(VRAMFILE): image.srec |
42 | $(SREC2VRAM) image.srec 0x0000000 0x1000 > $(VRAMFILE) | |
44 | $(SREC2VRAM) image.srec 0x00000000 0x1000 > $(VRAMFILE) | |
43 | 45 | |
44 | 46 | clean: |
45 | 47 | rm -f image image.lst image.bin image.srec image.map image.ram *.o *.d |
lm32/logic/sakc/firmware/loader_cain/crt0ram.S | ||
---|---|---|
24 | 24 | */ |
25 | 25 | |
26 | 26 | /* Exception handlers - Must be 32 bytes long. */ |
27 | .section .text, "ax", @progbits | |
28 | .global _start | |
29 | .global irq_enable, irq_disable, irq_set_mask, irq_get_mask | |
30 | .global jump, halt | |
31 | .global get_sp, get_gp | |
32 | ||
27 | .section .text, "ax", @progbits | |
28 | .global _start | |
29 | .global irq_enable, irq_disable, irq_mask, jump, halt | |
33 | 30 | _start: |
34 | 31 | _reset_handler: |
35 | 32 | xor r0, r0, r0 |
... | ... | |
41 | 38 | nop |
42 | 39 | nop |
43 | 40 | |
44 | _breakpoint_handler: | |
45 | nop | |
46 | nop | |
47 | nop | |
48 | nop | |
49 | nop | |
50 | nop | |
51 | nop | |
52 | nop | |
53 | ||
54 | _ibuserror_handler: | |
55 | nop | |
56 | nop | |
57 | nop | |
58 | nop | |
59 | nop | |
60 | nop | |
61 | nop | |
62 | nop | |
63 | ||
64 | _watchpoint_handler: | |
65 | nop | |
66 | nop | |
67 | nop | |
68 | nop | |
69 | nop | |
70 | nop | |
71 | nop | |
72 | nop | |
73 | ||
74 | _dbuserror_handler: | |
75 | nop | |
76 | nop | |
77 | nop | |
78 | nop | |
79 | nop | |
80 | nop | |
81 | nop | |
82 | nop | |
83 | ||
84 | _divzero_handler: | |
85 | nop | |
86 | nop | |
87 | nop | |
88 | nop | |
89 | nop | |
90 | nop | |
91 | nop | |
92 | nop | |
93 | ||
94 | _interrupt_handler: | |
95 | sw (sp+0), ra | |
96 | calli _save_all | |
97 | rcsr r1, IP | |
98 | calli irq_handler | |
99 | mvhi r1, 0xffff | |
100 | ori r1, r1, 0xffff | |
101 | wcsr IP, r1 | |
102 | bi _restore_all_and_eret | |
103 | ||
104 | _scall_handler: | |
105 | nop | |
106 | nop | |
107 | nop | |
108 | nop | |
109 | nop | |
110 | nop | |
111 | nop | |
112 | nop | |
113 | ||
114 | 41 | _crt0: |
115 | 42 | /* Setup stack and global pointer */ |
116 | 43 | mvhi sp, hi(_fstack) |
... | ... | |
140 | 67 | wcsr IE, r1 |
141 | 68 | ret |
142 | 69 | |
70 | irq_mask: | |
71 | mvi r1, 0x0000000f | |
72 | wcsr IM, r1 | |
73 | ret | |
74 | ||
143 | 75 | irq_disable: |
144 | 76 | mvi r1, 0 |
145 | 77 | wcsr IE, r1 |
146 | 78 | ret |
147 | 79 | |
148 | irq_set_mask: | |
149 | wcsr IM, r1 | |
150 | ret | |
151 | ||
152 | irq_get_mask: | |
153 | rcsr r1, IM | |
154 | ret | |
155 | ||
156 | 80 | jump: |
157 | 81 | b r1 |
158 | 82 | |
159 | 83 | halt: |
160 | 84 | bi halt |
161 | 85 | |
162 | /* Save all registers onto the stack */ | |
163 | _save_all: | |
164 | addi sp, sp, -128 | |
165 | sw (sp+4), r1 | |
166 | sw (sp+8), r2 | |
167 | sw (sp+12), r3 | |
168 | sw (sp+16), r4 | |
169 | sw (sp+20), r5 | |
170 | sw (sp+24), r6 | |
171 | sw (sp+28), r7 | |
172 | sw (sp+32), r8 | |
173 | sw (sp+36), r9 | |
174 | sw (sp+40), r10 | |
175 | #ifdef MICO32_FULL_CONTEXT_SAVE_RESTORE | |
176 | sw (sp+44), r11 | |
177 | sw (sp+48), r12 | |
178 | sw (sp+52), r13 | |
179 | sw (sp+56), r14 | |
180 | sw (sp+60), r15 | |
181 | sw (sp+64), r16 | |
182 | sw (sp+68), r17 | |
183 | sw (sp+72), r18 | |
184 | sw (sp+76), r19 | |
185 | sw (sp+80), r20 | |
186 | sw (sp+84), r21 | |
187 | sw (sp+88), r22 | |
188 | sw (sp+92), r23 | |
189 | sw (sp+96), r24 | |
190 | sw (sp+100), r25 | |
191 | sw (sp+104), r26 | |
192 | sw (sp+108), r27 | |
193 | #endif | |
194 | sw (sp+120), ea | |
195 | sw (sp+124), ba | |
196 | /* ra and sp need special handling, as they have been modified */ | |
197 | lw r1, (sp+128) | |
198 | sw (sp+116), r1 | |
199 | mv r1, sp | |
200 | addi r1, r1, 128 | |
201 | sw (sp+112), r1 | |
202 | ret | |
203 | ||
204 | /* Restore all registers and return from exception */ | |
205 | _restore_all_and_eret: | |
206 | lw r1, (sp+4) | |
207 | lw r2, (sp+8) | |
208 | lw r3, (sp+12) | |
209 | lw r4, (sp+16) | |
210 | lw r5, (sp+20) | |
211 | lw r6, (sp+24) | |
212 | lw r7, (sp+28) | |
213 | lw r8, (sp+32) | |
214 | lw r9, (sp+36) | |
215 | lw r10, (sp+40) | |
216 | #ifdef MICO32_FULL_CONTEXT_SAVE_RESTORE | |
217 | lw r11, (sp+44) | |
218 | lw r12, (sp+48) | |
219 | lw r13, (sp+52) | |
220 | lw r14, (sp+56) | |
221 | lw r15, (sp+60) | |
222 | lw r16, (sp+64) | |
223 | lw r17, (sp+68) | |
224 | lw r18, (sp+72) | |
225 | lw r19, (sp+76) | |
226 | lw r20, (sp+80) | |
227 | lw r21, (sp+84) | |
228 | lw r22, (sp+88) | |
229 | lw r23, (sp+92) | |
230 | lw r24, (sp+96) | |
231 | lw r25, (sp+100) | |
232 | lw r26, (sp+104) | |
233 | lw r27, (sp+108) | |
234 | #endif | |
235 | lw ra, (sp+116) | |
236 | lw ea, (sp+120) | |
237 | lw ba, (sp+124) | |
238 | /* Stack pointer must be restored last, in case it has been updated */ | |
239 | lw sp, (sp+112) | |
240 | eret | |
241 | ||
242 | get_sp: | |
243 | mv r1, sp | |
244 | ret | |
245 | ||
246 | get_gp: | |
247 | mv r1, gp | |
248 | ret | |
249 |
lm32/logic/sakc/firmware/loader_cain/linker.ld | ||
---|---|---|
4 | 4 | __DYNAMIC = 0; |
5 | 5 | |
6 | 6 | |
7 | _RAM_START = 0x0000000; | |
8 | _RAM_SIZE = 0x1000; | |
9 | _RAM_END = _RAM_START + _RAM_SIZE; | |
7 | _BRAM_START = 0x00000000; | |
8 | _BRAM_SIZE = 0x1000; | |
9 | _BRAM_END = _BRAM_START + _BRAM_SIZE; | |
10 | 10 | |
11 | 11 | MEMORY { |
12 | ram : ORIGIN = 0x0000000, LENGTH = 0x1000 /* 4k */ | |
12 | bram : ORIGIN = 0x00000000, LENGTH = 0x1000 /* 4k */ | |
13 | 13 | } |
14 | 14 | |
15 | 15 | SECTIONS |
... | ... | |
19 | 19 | _ftext = .; |
20 | 20 | *(.text .stub .text.* .gnu.linkonce.t.*) |
21 | 21 | _etext = .; |
22 | } > ram | |
22 | } > bram | |
23 | 23 | |
24 | 24 | .rodata : |
25 | 25 | { |
... | ... | |
28 | 28 | *(.rodata .rodata.* .gnu.linkonce.r.*) |
29 | 29 | *(.rodata1) |
30 | 30 | _erodata = .; |
31 | } > ram | |
31 | } > bram | |
32 | 32 | |
33 | 33 | .data : |
34 | 34 | { |
... | ... | |
39 | 39 | _gp = ALIGN(16); |
40 | 40 | *(.sdata .sdata.* .gnu.linkonce.s.*) |
41 | 41 | _edata = .; |
42 | } > ram | |
42 | } > bram | |
43 | 43 | |
44 | 44 | .bss : |
45 | 45 | { |
... | ... | |
53 | 53 | *(COMMON) |
54 | 54 | _ebss = .; |
55 | 55 | _end = .; |
56 | } > ram | |
56 | } > bram | |
57 | 57 | } |
58 | 58 | |
59 | PROVIDE(_fstack = ORIGIN(ram) + LENGTH(ram) - 4); | |
59 | PROVIDE(_fstack = ORIGIN(bram) + LENGTH(bram) - 4); |
lm32/logic/sakc/firmware/loader_cain/main.c | ||
---|---|---|
1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
2 | ||
3 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
4 | ||
5 | ||
6 | 1 | #include "soc-hw.h" |
7 | #define RAM_BASE 0x1000 | |
8 | 2 | |
9 | 3 | unsigned int i, j,k; // Loop counter. |
10 | 4 | |
11 | 5 | |
12 | 6 | int main() { |
13 | int key, len, autoboot = 1, dispmenu = 1; | |
7 | int key, len, autoboot = 1, dispmenu = 1; | |
14 | 8 | |
15 | uart_init(); | |
16 | uart_putstr("Cain's bootloader!!! \n"); | |
9 | uart_putstr("Cain's bootloader!!! \r\n"); | |
17 | 10 | |
18 | 11 | while(1){ /* loop forever until u-boot gets booted or the board is reset */ |
19 | 12 | if(dispmenu){ |
20 | uart_putstr("\n1: Upload program to RAM\n"); | |
21 | // uart_putstr("2: Upload u-boot to Dataflash\n"); | |
22 | // uart_putstr("3: Upload Kernel to Dataflash\n"); | |
23 | // uart_putstr("4: Start u-boot\n"); | |
24 | // uart_putstr("5: Upload Filesystem image\n"); | |
25 | // uart_putstr("6: Memory test\n"); | |
13 | uart_putstr("\n1: Upload program to RAM\r\n"); | |
14 | // uart_putstr("2: Upload u-boot to Dataflash\r\n"); | |
15 | // uart_putstr("3: Upload Kernel to Dataflash\r\n"); | |
16 | // uart_putstr("4: Start u-boot\r\n"); | |
17 | // uart_putstr("5: Upload Filesystem image\r\n"); | |
18 | // uart_putstr("6: Memory test\r\n"); | |
26 | 19 | dispmenu = 0; |
27 | 20 | } |
28 | 21 | key = uart_getchar(); |
29 | 22 | autoboot = 0; |
30 | 23 | |
31 | 24 | if(key == '1'){ |
32 | len = rxmodem((char *)0x1000); | |
25 | len = rxmodem((unsigned char *)0x1000); | |
33 | 26 | uart_putstr("Received "); |
34 | 27 | hexprint(len); |
35 | uart_putstr(" bytes\n"); | |
36 | jump(RAM_BASE); | |
37 | // dispmenu = 1; | |
38 | } | |
39 | else if(key == '2'){ | |
28 | uart_putstr(" bytes\r\n"); | |
29 | // jump(RAM_BASE); | |
40 | 30 | dispmenu = 1; |
41 | 31 | } |
42 | 32 | else{ |
43 | uart_putstr("Invalid input\n"); | |
33 | uart_putstr("Invalid input\r\n"); | |
44 | 34 | dispmenu = 1; |
45 | 35 | } |
46 | 36 | } |
47 | 37 | |
38 | while(1){ asm("nop;"); } | |
48 | 39 | |
49 | while(1){ asm("nop;"); } | |
50 | ||
51 | ||
52 | return (0); | |
53 | ||
54 | ||
40 | return (0); | |
55 | 41 | } |
lm32/logic/sakc/firmware/loader_cain/soc-hw.c | ||
---|---|---|
1 | 1 | #include "soc-hw.h" |
2 | 2 | |
3 | uart_t *uart0 = (uart_t *) 0xf0000000; | |
4 | timer_t *timer0 = (timer_t *) 0xf0010000; | |
3 | uart_t *uart0 = (uart_t *) 0xF0000000; | |
4 | timer_t *timer0 = (timer_t *) 0xF0010000; | |
5 | 5 | gpio_t *gpio0 = (gpio_t *) 0xF0020000; |
6 | 6 | |
7 | isr_ptr_t isr_table[32]; | |
7 | uint32_t msec = 0; | |
8 | 8 | |
9 | ||
10 | void tic_isr(); | |
11 | 9 | /*************************************************************************** |
12 | * IRQ handling | |
10 | * General utility functions | |
13 | 11 | */ |
14 | void isr_null() | |
15 | { | |
16 | } | |
17 | ||
18 | void irq_handler(uint32_t pending) | |
19 | { | |
20 | int i; | |
21 | ||
22 | for(i=0; i<32; i++) { | |
23 | if (pending & 0x01) (*isr_table[i])(); | |
24 | pending >>= 1; | |
25 | } | |
26 | } | |
27 | ||
28 | void isr_init() | |
29 | { | |
30 | int i; | |
31 | for(i=0; i<32; i++) | |
32 | isr_table[i] = &isr_null; | |
33 | } | |
34 | ||
35 | void isr_register(int irq, isr_ptr_t isr) | |
36 | { | |
37 | isr_table[irq] = isr; | |
38 | } | |
39 | ||
40 | void isr_unregister(int irq) | |
41 | { | |
42 | isr_table[irq] = &isr_null; | |
43 | } | |
44 | ||
45 | /*************************************************************************** | |
46 | * TIMER Functions | |
47 | */ | |
48 | void msleep(uint32_t msec) | |
12 | void sleep(int msec) | |
49 | 13 | { |
50 | 14 | uint32_t tcr; |
51 | 15 | |
52 | 16 | // Use timer0.1 |
53 | 17 | timer0->compare1 = (FCPU/1000)*msec; |
54 | 18 | timer0->counter1 = 0; |
55 | timer0->tcr1 = TIMER_EN; | |
56 | ||
57 | do { | |
58 | //halt(); | |
59 | tcr = timer0->tcr1; | |
60 | } while ( ! (tcr & TIMER_TRIG) ); | |
61 | } | |
62 | ||
63 | void nsleep(uint32_t nsec) | |
64 | { | |
65 | uint32_t tcr; | |
66 | ||
67 | // Use timer0.1 | |
68 | timer0->compare1 = (FCPU/1000000)*nsec; | |
69 | timer0->counter1 = 0; | |
70 | timer0->tcr1 = TIMER_EN; | |
19 | timer0->tcr1 = TIMER_EN | TIMER_IRQEN; | |
71 | 20 | |
72 | 21 | do { |
73 | 22 | //halt(); |
... | ... | |
75 | 24 | } while ( ! (tcr & TIMER_TRIG) ); |
76 | 25 | } |
77 | 26 | |
78 | ||
79 | uint32_t tic_msec; | |
80 | ||
81 | void tic_isr() | |
82 | { | |
83 | tic_msec++; | |
84 | timer0->tcr0 = TIMER_EN | TIMER_AR | TIMER_IRQEN; | |
85 | } | |
86 | ||
87 | 27 | void tic_init() |
88 | 28 | { |
89 | tic_msec = 0; | |
90 | ||
91 | 29 | // Setup timer0.0 |
92 | timer0->compare0 = (FCPU/10000); | |
30 | timer0->compare0 = (FCPU/1000); | |
93 | 31 | timer0->counter0 = 0; |
94 | 32 | timer0->tcr0 = TIMER_EN | TIMER_AR | TIMER_IRQEN; |
95 | ||
96 | isr_register(1, &tic_isr); | |
97 | 33 | } |
98 | 34 | |
99 | ||
100 | 35 | /*************************************************************************** |
101 | 36 | * UART Functions |
102 | 37 | */ |
... | ... | |
143 | 78 | for(pos = 7; pos > -1; pos--) |
144 | 79 | { |
145 | 80 | if(digit[pos] < 0xA) |
146 | uart_putstr(digit[pos] + '0'); | |
81 | uart_putstr((char *)digit[pos] + '0'); | |
147 | 82 | else |
148 | uart_putstr(digit[pos] + 'A' - 10); | |
83 | uart_putstr((char *)digit[pos] + 'A' - 10); | |
149 | 84 | } |
150 | 85 | uart_putchar(' '); |
151 | 86 | } |
152 | 87 | |
153 | 88 | |
89 |
lm32/logic/sakc/firmware/loader_cain/soc-hw.h | ||
---|---|---|
95 | 95 | void uart_putchar(char c); |
96 | 96 | void uart_putstr(char *str); |
97 | 97 | char uart_getchar(); |
98 | void hexprint(unsigned int hexval); | |
99 | 98 | |
100 | 99 | |
101 | 100 | /*************************************************************************** |
... | ... | |
106 | 105 | extern gpio_t *gpio0; |
107 | 106 | extern uint32_t *sram0; |
108 | 107 | |
109 | ||
110 | 108 | int rxmodem(unsigned char *dest); |
109 | void hexprint(unsigned int hexval); | |
111 | 110 | |
112 | 111 | #endif // SPIKEHW_H |
lm32/logic/sakc/firmware/loader_cain/xmodem.c | ||
---|---|---|
18 | 18 | */ |
19 | 19 | |
20 | 20 | #include "soc-hw.h" |
21 | ||
21 | 22 | #define SOH 0x01 |
22 | 23 | #define EOT 0x04 |
23 | 24 | #define ACK 0x06 |
lm32/logic/sakc/system.v | ||
---|---|---|
7 | 7 | module system |
8 | 8 | #( |
9 | 9 | parameter bootram_file = "../firmware/loader_cain/image.ram", |
10 | // parameter bootram_file = "../firmware/boot0-serial/image.ram", | |
10 | 11 | parameter clk_freq = 50000000, |
11 | 12 | parameter uart_baud_rate = 57600 |
12 | 13 | ) ( |
Branches:
master