From 25506c1ab5194dcbe8048ccda6f7c1f29118a65f Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 11 Jul 2013 18:36:26 +0200 Subject: [PATCH] software: share crt0 --- software/bios/Makefile | 6 +- software/libbase/Makefile | 2 +- software/{bios => libbase}/crt0.S | 0 software/videomixer/Makefile | 6 +- software/videomixer/crt0.S | 167 ------------------------------ 5 files changed, 9 insertions(+), 172 deletions(-) rename software/{bios => libbase}/crt0.S (100%) delete mode 100644 software/videomixer/crt0.S diff --git a/software/bios/Makefile b/software/bios/Makefile index 973fb3ab..9a7ef979 100644 --- a/software/bios/Makefile +++ b/software/bios/Makefile @@ -1,7 +1,7 @@ M2DIR=../.. include $(M2DIR)/software/common.mak -OBJECTS=crt0.o isr.o sdram.o main.o boot-helper.o boot.o dataflow.o +OBJECTS=isr.o sdram.o main.o boot-helper.o boot.o dataflow.o all: bios.bin @@ -17,7 +17,9 @@ all: bios.bin bios.elf: linker.ld $(OBJECTS) libs %.elf: - $(LD) $(LDFLAGS) -T $< -N -o $@ $(OBJECTS) \ + $(LD) $(LDFLAGS) -T $< -N -o $@ \ + $(M2DIR)/software/libbase/crt0.o \ + $(OBJECTS) \ -L$(M2DIR)/software/libnet \ -L$(M2DIR)/software/libbase \ -L$(M2DIR)/software/libcompiler-rt \ diff --git a/software/libbase/Makefile b/software/libbase/Makefile index 11e944d0..e58da5ce 100644 --- a/software/libbase/Makefile +++ b/software/libbase/Makefile @@ -3,7 +3,7 @@ include $(M2DIR)/software/common.mak OBJECTS=setjmp.o libc.o errno.o crc16.o crc32.o console.o system.o id.o uart.o qsort.o strtod.o -all: libbase.a libbase-nofloat.a +all: crt0.o libbase.a libbase-nofloat.a # pull in dependency info for *existing* .o files -include $(OBJECTS:.o=.d) diff --git a/software/bios/crt0.S b/software/libbase/crt0.S similarity index 100% rename from software/bios/crt0.S rename to software/libbase/crt0.S diff --git a/software/videomixer/Makefile b/software/videomixer/Makefile index 4e97ceb6..b4e6c183 100644 --- a/software/videomixer/Makefile +++ b/software/videomixer/Makefile @@ -1,7 +1,7 @@ M2DIR=../.. include $(M2DIR)/software/common.mak -OBJECTS=crt0.o isr.o time.o fb.o dvisampler0.o dvisampler1.o main.o +OBJECTS=isr.o time.o fb.o dvisampler0.o dvisampler1.o main.o all: videomixer.bin videomixer.fbi @@ -18,7 +18,9 @@ all: videomixer.bin videomixer.fbi videomixer.elf: linker.ld $(OBJECTS) libs %.elf: - $(LD) $(LDFLAGS) -T $< -N -o $@ $(OBJECTS) \ + $(LD) $(LDFLAGS) -T $< -N -o $@ \ + $(M2DIR)/software/libbase/crt0.o \ + $(OBJECTS) \ -L$(M2DIR)/software/libbase \ -L$(M2DIR)/software/libcompiler-rt \ -lbase -lcompiler-rt diff --git a/software/videomixer/crt0.S b/software/videomixer/crt0.S deleted file mode 100644 index 62797209..00000000 --- a/software/videomixer/crt0.S +++ /dev/null @@ -1,167 +0,0 @@ -/* - * LatticeMico32 C startup code. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* Exception handlers - Must be 32 bytes long. */ -.section .text, "ax", @progbits -.global _start -_start: -_reset_handler: - xor r0, r0, r0 - wcsr IE, r0 - mvhi r1, hi(_reset_handler) - ori r1, r1, lo(_reset_handler) - wcsr EBA, r1 - bi _crt0 - nop - nop - -_breakpoint_handler: - bi _breakpoint_handler - nop - nop - nop - nop - nop - nop - nop - -_instruction_bus_error_handler: - bi _instruction_bus_error_handler - nop - nop - nop - nop - nop - nop - nop - -_watchpoint_hander: - bi _watchpoint_hander - nop - nop - nop - nop - nop - nop - nop - -_data_bus_error_handler: - bi _data_bus_error_handler - nop - nop - nop - nop - nop - nop - nop - -_divide_by_zero_handler: - bi _divide_by_zero_handler - nop - nop - nop - nop - nop - nop - nop - -_interrupt_handler: - sw (sp+0), ra - calli .save_all - calli isr - bi .restore_all_and_eret - nop - nop - nop - nop - -macaddress: - .byte 0x10 - .byte 0xe2 - .byte 0xd5 - .byte 0x00 - .byte 0x00 - .byte 0x00 - - /* padding to align to a 32-bit boundary */ - .byte 0x00 - .byte 0x00 - -_crt0: - /* Setup stack and global pointer */ - mvhi sp, hi(_fstack) - ori sp, sp, lo(_fstack) - mvhi gp, hi(_gp) - ori gp, gp, lo(_gp) - - /* Clear BSS */ - mvhi r1, hi(_fbss) - ori r1, r1, lo(_fbss) - mvhi r3, hi(_ebss) - ori r3, r3, lo(_ebss) -.clearBSS: - be r1, r3, .callMain - sw (r1+0), r0 - addi r1, r1, 4 - bi .clearBSS - -.callMain: - bi main - -.save_all: - addi sp, sp, -56 - sw (sp+4), r1 - sw (sp+8), r2 - sw (sp+12), r3 - sw (sp+16), r4 - sw (sp+20), r5 - sw (sp+24), r6 - sw (sp+28), r7 - sw (sp+32), r8 - sw (sp+36), r9 - sw (sp+40), r10 - sw (sp+48), ea - sw (sp+52), ba - /* ra needs to be moved from initial stack location */ - lw r1, (sp+56) - sw (sp+44), r1 - ret - -.restore_all_and_eret: - lw r1, (sp+4) - lw r2, (sp+8) - lw r3, (sp+12) - lw r4, (sp+16) - lw r5, (sp+20) - lw r6, (sp+24) - lw r7, (sp+28) - lw r8, (sp+32) - lw r9, (sp+36) - lw r10, (sp+40) - lw ra, (sp+44) - lw ea, (sp+48) - lw ba, (sp+52) - addi sp, sp, 56 - eret -- 2.30.2