Date:2010-10-13 15:49:36 (9 years 1 month 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
44LM32_OBJDUMP=lm32-elf-objdump
55
66SREC2VRAM ?= ../../tools/srec2vram/srec2vram
7
87VRAMFILE=image.ram
98
109CFLAGS=-MMD -O2 -Wall -g -s -fomit-frame-pointer -mbarrel-shift-enabled -mmultiply-enabled -mdivide-enabled -msign-extend-enabled
1110LDFLAGS=-nostdlib -nodefaultlibs -Tlinker.ld
1211SEGMENTS = -j .text -j .rodata -j .data
1312
14all: $(VRAMFILE)
13all: image.srec $(VRAMFILE)
1514
1615crt0ram.o: crt0ram.S
1716    $(LM32_CC) $(CFLAGS) -c crt0ram.S
lm32/logic/sakc/firmware/loader_cain/Makefile
2121soc-hw.o: soc-hw.c
2222    $(LM32_CC) $(CFLAGS) -c soc-hw.c
2323
24
2524xmodem.o: xmodem.c
2625    $(LM32_CC) $(CFLAGS) -c xmodem.c
2726
28
29image: 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
27image: 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
3129
3230image.lst: image
3331    $(LM32_OBJDUMP) -h -S $< > $@
3432
3533image.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
3736
3837image.srec: image image.lst
3938    $(LM32_OBJCOPY) $(SEGMENTS) -O srec image image.srec
4039
40$(VHDLFILE): image.srec
41    $(SREC2VHDL) image.srec > $(VHDLFILE)
42
4143$(VRAMFILE): image.srec
42    $(SREC2VRAM) image.srec 0x0000000 0x1000 > $(VRAMFILE)
44    $(SREC2VRAM) image.srec 0x00000000 0x1000 > $(VRAMFILE)
4345
4446clean:
4547    rm -f image image.lst image.bin image.srec image.map image.ram *.o *.d
lm32/logic/sakc/firmware/loader_cain/crt0ram.S
2424 */
2525
2626/* 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
3330_start:
3431_reset_handler:
3532    xor r0, r0, r0
...... 
4138    nop
4239    nop
4340
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
11441_crt0:
11542    /* Setup stack and global pointer */
11643    mvhi sp, hi(_fstack)
...... 
14067    wcsr IE, r1
14168    ret
14269
70irq_mask:
71    mvi r1, 0x0000000f
72    wcsr IM, r1
73    ret
74
14375irq_disable:
14476    mvi r1, 0
14577    wcsr IE, r1
14678    ret
14779
148irq_set_mask:
149    wcsr IM, r1
150    ret
151
152irq_get_mask:
153    rcsr r1, IM
154    ret
155
15680jump:
15781    b r1
15882
15983halt:
16084    bi halt
16185
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
242get_sp:
243    mv r1, sp
244    ret
245
246get_gp:
247    mv r1, gp
248    ret
249
lm32/logic/sakc/firmware/loader_cain/linker.ld
44__DYNAMIC = 0;
55
66
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;
1010
1111MEMORY {
12  ram : ORIGIN = 0x0000000, LENGTH = 0x1000 /* 4k */
12  bram : ORIGIN = 0x00000000, LENGTH = 0x1000 /* 4k */
1313}
1414
1515SECTIONS
...... 
1919    _ftext = .;
2020    *(.text .stub .text.* .gnu.linkonce.t.*)
2121    _etext = .;
22  } > ram
22  } > bram
2323
2424  .rodata :
2525  {
...... 
2828    *(.rodata .rodata.* .gnu.linkonce.r.*)
2929    *(.rodata1)
3030    _erodata = .;
31  } > ram
31  } > bram
3232
3333  .data :
3434  {
...... 
3939    _gp = ALIGN(16);
4040    *(.sdata .sdata.* .gnu.linkonce.s.*)
4141    _edata = .;
42  } > ram
42  } > bram
4343
4444  .bss :
4545  {
...... 
5353    *(COMMON)
5454    _ebss = .;
5555    _end = .;
56  } > ram
56  } > bram
5757}
5858
59PROVIDE(_fstack = ORIGIN(ram) + LENGTH(ram) - 4);
59PROVIDE(_fstack = ORIGIN(bram) + LENGTH(bram) - 4);
lm32/logic/sakc/firmware/loader_cain/main.c
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
3 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
4
5
61#include "soc-hw.h"
7#define RAM_BASE 0x1000
82
93unsigned int i, j,k; // Loop counter.
104
115
126int main() {
13    int key, len, autoboot = 1, dispmenu = 1;
7  int key, len, autoboot = 1, dispmenu = 1;
148
15   uart_init();
16   uart_putstr("Cain's bootloader!!! \n");
9  uart_putstr("Cain's bootloader!!! \r\n");
1710
1811  while(1){ /* loop forever until u-boot gets booted or the board is reset */
1912    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");
2619      dispmenu = 0;
2720    }
2821      key = uart_getchar();
2922      autoboot = 0;
3023
3124    if(key == '1'){
32      len = rxmodem((char *)0x1000);
25      len = rxmodem((unsigned char *)0x1000);
3326      uart_putstr("Received ");
3427      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);
4030      dispmenu = 1;
4131    }
4232    else{
43      uart_putstr("Invalid input\n");
33      uart_putstr("Invalid input\r\n");
4434      dispmenu = 1;
4535    }
4636  }
4737
38  while(1){ asm("nop;"); }
4839
49    while(1){ asm("nop;"); }
50
51
52   return (0);
53
54
40  return (0);
5541}
lm32/logic/sakc/firmware/loader_cain/soc-hw.c
11#include "soc-hw.h"
22
3uart_t *uart0 = (uart_t *) 0xf0000000;
4timer_t *timer0 = (timer_t *) 0xf0010000;
3uart_t *uart0 = (uart_t *) 0xF0000000;
4timer_t *timer0 = (timer_t *) 0xF0010000;
55gpio_t *gpio0 = (gpio_t *) 0xF0020000;
66
7isr_ptr_t isr_table[32];
7uint32_t msec = 0;
88
9
10void tic_isr();
119/***************************************************************************
12 * IRQ handling
10 * General utility functions
1311 */
14void isr_null()
15{
16}
17
18void 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
28void isr_init()
29{
30    int i;
31    for(i=0; i<32; i++)
32        isr_table[i] = &isr_null;
33}
34
35void isr_register(int irq, isr_ptr_t isr)
36{
37    isr_table[irq] = isr;
38}
39
40void isr_unregister(int irq)
41{
42    isr_table[irq] = &isr_null;
43}
44
45/***************************************************************************
46 * TIMER Functions
47 */
48void msleep(uint32_t msec)
12void sleep(int msec)
4913{
5014    uint32_t tcr;
5115
5216    // Use timer0.1
5317    timer0->compare1 = (FCPU/1000)*msec;
5418    timer0->counter1 = 0;
55    timer0->tcr1 = TIMER_EN;
56
57    do {
58        //halt();
59         tcr = timer0->tcr1;
60     } while ( ! (tcr & TIMER_TRIG) );
61}
62
63void 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;
7120
7221    do {
7322        //halt();
...... 
7524     } while ( ! (tcr & TIMER_TRIG) );
7625}
7726
78
79uint32_t tic_msec;
80
81void tic_isr()
82{
83    tic_msec++;
84    timer0->tcr0 = TIMER_EN | TIMER_AR | TIMER_IRQEN;
85}
86
8727void tic_init()
8828{
89    tic_msec = 0;
90
9129    // Setup timer0.0
92    timer0->compare0 = (FCPU/10000);
30    timer0->compare0 = (FCPU/1000);
9331    timer0->counter0 = 0;
9432    timer0->tcr0 = TIMER_EN | TIMER_AR | TIMER_IRQEN;
95
96    isr_register(1, &tic_isr);
9733}
9834
99
10035/***************************************************************************
10136 * UART Functions
10237 */
...... 
14378  for(pos = 7; pos > -1; pos--)
14479    {
14580      if(digit[pos] < 0xA)
146        uart_putstr(digit[pos] + '0');
81        uart_putstr((char *)digit[pos] + '0');
14782      else
148        uart_putstr(digit[pos] + 'A' - 10);
83        uart_putstr((char *)digit[pos] + 'A' - 10);
14984    }
15085  uart_putchar(' ');
15186}
15287
15388
89
lm32/logic/sakc/firmware/loader_cain/soc-hw.h
9595void uart_putchar(char c);
9696void uart_putstr(char *str);
9797char uart_getchar();
98void hexprint(unsigned int hexval);
9998
10099
101100/***************************************************************************
...... 
106105extern gpio_t *gpio0;
107106extern uint32_t *sram0;
108107
109
110108int rxmodem(unsigned char *dest);
109void hexprint(unsigned int hexval);
111110
112111#endif // SPIKEHW_H
lm32/logic/sakc/firmware/loader_cain/xmodem.c
1818*/
1919
2020#include "soc-hw.h"
21
2122#define SOH 0x01
2223#define EOT 0x04
2324#define ACK 0x06
lm32/logic/sakc/system.v
77module system
88#(
99    parameter bootram_file = "../firmware/loader_cain/image.ram",
10// parameter bootram_file = "../firmware/boot0-serial/image.ram",
1011    parameter clk_freq = 50000000,
1112    parameter uart_baud_rate = 57600
1213) (

Archive Download the corresponding diff file

Branches:
master



interactive