Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 8 files changed
  • 0 comments
  • 1 contributor
6  .gitignore
... ...
@@ -1,2 +1,8 @@
1 1
 __pycache__
2 2
 build/*
  3
+*.o
  4
+*.d
  5
+*.a
  6
+tools/bin2hex
  7
+tools/flterm
  8
+tools/mkmmimg
30  software/bios/Makefile
... ...
@@ -0,0 +1,30 @@
  1
+M2DIR=../..
  2
+include $(M2DIR)/software/include.mak
  3
+
  4
+OBJECTS=crt0.o isr.o main.o
  5
+
  6
+all: bios.bin
  7
+
  8
+# pull in dependency info for *existing* .o files
  9
+-include $(OBJECTS:.o=.d)
  10
+
  11
+%.bin: %.elf
  12
+	$(MAKE) -C $(M2DIR)/tools
  13
+	$(OBJCOPY) -O binary $< $@
  14
+	chmod -x $@
  15
+	$(M2DIR)/tools/mkmmimg $@ write
  16
+
  17
+bios.elf: linker.ld $(OBJECTS) libs
  18
+bios-rescue.elf: linker-rescue.ld $(OBJECTS) libs
  19
+
  20
+%.elf:
  21
+	$(LD) $(LDFLAGS) -T $< -N -o $@ $(OBJECTS) -L$(M2DIR)/software/libbase -lbase
  22
+	chmod -x $@
  23
+
  24
+libs:
  25
+	make -C $(M2DIR)/software/libbase
  26
+
  27
+.PHONY: clean libs
  28
+
  29
+clean:
  30
+	rm -f $(OBJECTS) $(OBJECTS:.o=.d) bios.elf bios.bin bios-rescue.elf bios-rescue.bin .*~ *~
167  software/bios/crt0.S
... ...
@@ -0,0 +1,167 @@
  1
+/*
  2
+ * LatticeMico32 C startup code.
  3
+ *
  4
+ * Redistribution and use in source and binary forms, with or without
  5
+ * modification, are permitted provided that the following conditions
  6
+ * are met:
  7
+ * 1. Redistributions of source code must retain the above copyright
  8
+ * notice, this list of conditions and the following disclaimer.
  9
+ * 2. Redistributions in binary form must reproduce the above copyright
  10
+ * notice, this list of conditions and the following disclaimer in the
  11
+ * documentation and/or other materials provided with the distribution.
  12
+ *
  13
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  14
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  16
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  17
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  19
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  20
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  22
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  23
+ * SUCH DAMAGE.
  24
+ */
  25
+
  26
+/* Exception handlers - Must be 32 bytes long. */
  27
+.section    .text, "ax", @progbits
  28
+.global     _start
  29
+_start:
  30
+_reset_handler:
  31
+	xor	r0, r0, r0
  32
+	wcsr	IE, r0
  33
+	mvhi	r1, hi(_reset_handler)
  34
+	ori	r1, r1, lo(_reset_handler)
  35
+	wcsr	EBA, r1
  36
+	bi	_crt0
  37
+	nop
  38
+	nop
  39
+
  40
+_breakpoint_handler:
  41
+	bi _breakpoint_handler
  42
+	nop
  43
+	nop
  44
+	nop
  45
+	nop
  46
+	nop
  47
+	nop
  48
+	nop
  49
+
  50
+_instruction_bus_error_handler:
  51
+	bi _instruction_bus_error_handler
  52
+	nop
  53
+	nop
  54
+	nop
  55
+	nop
  56
+	nop
  57
+	nop
  58
+	nop
  59
+
  60
+_watchpoint_hander:
  61
+	bi _watchpoint_hander
  62
+	nop
  63
+	nop
  64
+	nop
  65
+	nop
  66
+	nop
  67
+	nop
  68
+	nop
  69
+
  70
+_data_bus_error_handler:
  71
+	bi _data_bus_error_handler
  72
+	nop
  73
+	nop
  74
+	nop
  75
+	nop
  76
+	nop
  77
+	nop
  78
+	nop
  79
+
  80
+_divide_by_zero_handler:
  81
+	bi _divide_by_zero_handler
  82
+	nop
  83
+	nop
  84
+	nop
  85
+	nop
  86
+	nop
  87
+	nop
  88
+	nop
  89
+
  90
+_interrupt_handler:
  91
+	sw      (sp+0), ra
  92
+	calli   .save_all
  93
+	calli   isr
  94
+	bi      .restore_all_and_eret
  95
+	nop
  96
+	nop
  97
+	nop
  98
+	nop
  99
+
  100
+macaddress:
  101
+	.byte 0x10
  102
+	.byte 0xe2
  103
+	.byte 0xd5
  104
+	.byte 0x00
  105
+	.byte 0x00
  106
+	.byte 0x00
  107
+
  108
+	/* padding to align to a 32-bit boundary */
  109
+	.byte 0x00
  110
+	.byte 0x00
  111
+
  112
+_crt0:
  113
+	/* Setup stack and global pointer */
  114
+	mvhi    sp, hi(_fstack)
  115
+	ori     sp, sp, lo(_fstack)
  116
+	mvhi    gp, hi(_gp)
  117
+	ori     gp, gp, lo(_gp)
  118
+
  119
+	/* Clear BSS */
  120
+	mvhi    r1, hi(_fbss)
  121
+	ori     r1, r1, lo(_fbss)
  122
+	mvhi    r3, hi(_ebss)
  123
+	ori     r3, r3, lo(_ebss)
  124
+.clearBSS:
  125
+	be      r1, r3, .callMain
  126
+	sw      (r1+0), r0
  127
+	addi    r1, r1, 4
  128
+	bi      .clearBSS
  129
+
  130
+.callMain:
  131
+	bi      main
  132
+
  133
+.save_all:
  134
+	addi    sp, sp, -56
  135
+	sw      (sp+4), r1
  136
+	sw      (sp+8), r2
  137
+	sw      (sp+12), r3
  138
+	sw      (sp+16), r4
  139
+	sw      (sp+20), r5
  140
+	sw      (sp+24), r6
  141
+	sw      (sp+28), r7
  142
+	sw      (sp+32), r8
  143
+	sw      (sp+36), r9
  144
+	sw      (sp+40), r10
  145
+	sw      (sp+48), ea
  146
+	sw      (sp+52), ba
  147
+	/* ra needs to be moved from initial stack location */
  148
+	lw      r1, (sp+56)
  149
+	sw      (sp+44), r1
  150
+	ret
  151
+
  152
+.restore_all_and_eret:
  153
+	lw      r1, (sp+4)
  154
+	lw      r2, (sp+8)
  155
+	lw      r3, (sp+12)
  156
+	lw      r4, (sp+16)
  157
+	lw      r5, (sp+20)
  158
+	lw      r6, (sp+24)
  159
+	lw      r7, (sp+28)
  160
+	lw      r8, (sp+32)
  161
+	lw      r9, (sp+36)
  162
+	lw      r10, (sp+40)
  163
+	lw      ra, (sp+44)
  164
+	lw      ea, (sp+48)
  165
+	lw      ba, (sp+52)
  166
+	addi    sp, sp, 56
  167
+	eret
25  software/bios/isr.c
... ...
@@ -0,0 +1,25 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#include <hw/interrupts.h>
  19
+#include <irq.h>
  20
+
  21
+void isr(void)
  22
+{
  23
+	unsigned int irqs;
  24
+	irqs = irq_pending() & irq_getmask();
  25
+}
57  software/bios/linker.ld
... ...
@@ -0,0 +1,57 @@
  1
+OUTPUT_FORMAT("elf32-lm32")
  2
+ENTRY(_start)
  3
+
  4
+__DYNAMIC = 0;
  5
+
  6
+MEMORY {
  7
+	flash : ORIGIN = 0x00860000, LENGTH = 0x20000 /* 128K */
  8
+	sram  : ORIGIN = 0x10000000, LENGTH = 0x01000 /* 4K */
  9
+}
  10
+
  11
+SECTIONS
  12
+{
  13
+	.text :
  14
+	{
  15
+		_ftext = .;
  16
+		*(.text .stub .text.* .gnu.linkonce.t.*)
  17
+		_etext = .;
  18
+	} > flash
  19
+
  20
+	.rodata :
  21
+	{
  22
+		. = ALIGN(4);
  23
+		_frodata = .;
  24
+		*(.rodata .rodata.* .gnu.linkonce.r.*)
  25
+		*(.rodata1)
  26
+		_erodata = .;
  27
+	} > flash
  28
+
  29
+	/* We shouldn't have a .data section, but the GNU crapchain whines if we don't */
  30
+	.data :
  31
+	{
  32
+		. = ALIGN(4);
  33
+		_fdata = .;
  34
+		*(.data .data.* .gnu.linkonce.d.*)
  35
+		*(.data1)
  36
+		_gp = ALIGN(16);
  37
+		*(.sdata .sdata.* .gnu.linkonce.s.*)
  38
+		_edata = .;
  39
+	} > flash
  40
+
  41
+	.bss :
  42
+	{
  43
+		. = ALIGN(4);
  44
+		_fbss = .;
  45
+		*(.dynsbss)
  46
+		*(.sbss .sbss.* .gnu.linkonce.sb.*)
  47
+		*(.scommon)
  48
+		*(.dynbss)
  49
+		*(.bss .bss.* .gnu.linkonce.b.*)
  50
+		*(COMMON)
  51
+		. = ALIGN(4);
  52
+		_ebss = .;
  53
+		_end = .;
  54
+	} > sram
  55
+}
  56
+
  57
+PROVIDE(_fstack = ORIGIN(sram) + LENGTH(sram) - 4);
16  software/bios/main.c
... ...
@@ -0,0 +1,16 @@
  1
+#include <hw/uart.h>
  2
+
  3
+static void print(const char *s)
  4
+{
  5
+	while(*s) {
  6
+		while(!(CSR_UART_STAT & UART_STAT_THRE));
  7
+		CSR_UART_RXTX = *s;
  8
+		s++;
  9
+	}
  10
+}
  11
+
  12
+int main(void)
  13
+{
  14
+	print("Hello World\n");
  15
+	while(1);
  16
+}
4  software/include.mak
@@ -34,8 +34,8 @@ endif
34 34
 
35 35
 # Toolchain options
36 36
 #
37  
-INCLUDES_NOLIBC ?= -nostdinc -I$(MMDIR)/software/include/base
38  
-INCLUDES = $(INCLUDES_NOLIBC) -I$(MMDIR)/software/include -I$(MMDIR)/tools
  37
+INCLUDES_NOLIBC ?= -nostdinc -I$(M2DIR)/software/include/base
  38
+INCLUDES = $(INCLUDES_NOLIBC) -I$(M2DIR)/software/include -I$(M2DIR)/tools
39 39
 ASFLAGS = $(INCLUDES) -nostdinc
40 40
 # later: -Wmissing-prototypes
41 41
 CFLAGS = -O9 -Wall -Wstrict-prototypes -Wold-style-definition -Wshadow \
10  software/libbase/Makefile
... ...
@@ -1,13 +1,13 @@
1  
-MMDIR=../..
2  
-include $(MMDIR)/software/include.mak
  1
+M2DIR=../..
  2
+include $(M2DIR)/software/include.mak
3 3
 
4 4
 OBJECTS=divsi3.o libc.o console.o system.o board.o uart.o softfloat.o softfloat-glue.o vsnprintf.o atof.o
5 5
 
  6
+all: libbase.a
  7
+
6 8
 # pull in dependency info for *existing* .o files
7 9
 -include $(OBJECTS:.o=.d)
8 10
 
9  
-all: libbase.a
10  
-
11 11
 libbase.a: $(OBJECTS)
12 12
 	$(AR) clr libbase.a $(OBJECTS)
13 13
 	$(RANLIB) libbase.a
@@ -15,4 +15,4 @@ libbase.a: $(OBJECTS)
15 15
 .PHONY: clean
16 16
 
17 17
 clean:
18  
-	rm -f $(OBJECTS) $(OBJECTS:.o=.d) libbase.a .*~ *~ Makefile.bak
  18
+	rm -f $(OBJECTS) $(OBJECTS:.o=.d) libbase.a .*~ *~

No commit comments for this range

Something went wrong with that request. Please try again.