Browse Source

fw: build and link a file that can go into the fast memory

Build and link a file to be loaded into the CPU fast memory for boot.
H. Peter Anvin 3 years ago
parent
commit
345f6b4fb6
5 changed files with 97 additions and 0 deletions
  1. 5 0
      fw/.gitignore
  2. 53 0
      fw/Makefile
  3. 7 0
      fw/boot.hex
  4. 11 0
      fw/head.S
  5. 21 0
      fw/hello.c

+ 5 - 0
fw/.gitignore

@@ -0,0 +1,5 @@
+*.o
+*.i
+*.s
+*.elf
+*.bin

+ 53 - 0
fw/Makefile

@@ -0,0 +1,53 @@
+MAKEFLAGS += -R -r
+
+CROSS	  = riscv32-unknown-elf-
+CC	  = $(CROSS)gcc
+LD	  = $(CROSS)ld
+OBJCOPY   = $(CROSS)objcopy
+BIN2MEM   = hexdump -v -e '1/4 "%08x" 7/4 " %08x" "\n"'
+CFLAGS	  =  -march=rv32imc -O2 -ggdb3 -mabi=ilp32 \
+	     -mshorten-memrefs -mno-strict-align
+LDFLAGS   = --section-start=.init=0 -z common-page-size=16 -z max-page-size=16
+
+# Delete output files on error
+.DELETE_ON_ERROR:
+
+# Don't delete intermediate files
+.SECONDARY:
+
+all: boot.hex
+
+boot.elf: head.o hello.o
+
+%.hex: %.elf
+	$(OBJCOPY) -O ihex $< $@
+
+%.mem: %.bin
+	$(BIN2MEM) $< > $@
+
+%.bin: %.elf
+	$(OBJCOPY) -O binary $< $@
+
+%.elf:
+	$(LD) $(LDFLAGS) -o $@ $^
+
+%.o: %.c
+	$(CC) $(CFLAGS) -c -o $@ $<
+
+%.s: %.c
+	$(CC) $(CFLAGS) -S -o $@ $<
+
+%.i: %.c
+	$(CC) $(CFLAGS) -E -o $@ $<
+
+%.o: %.S
+	$(CC) $(CFLAGS) -c -o $@ $<
+
+%.s: %.S
+	$(CC) $(CFLAGS) -E -o $@ $<
+
+clean:
+	rm -f *.o *.i *.s *.elf *.bin
+
+spotless: clean
+	rm -f *.mem *.hex

+ 7 - 0
fw/boot.hex

@@ -0,0 +1,7 @@
+:100000006F00600100000000000000000000000020
+:040010006F0040003D
+:1000140001A09307000313078004B70600C02380E0
+:0C002400E60003C7170085077DFB01A064
+:1000300048656C6C6F2C20576F726C64210D0A0040
+:0400000300000016E3
+:00000001FF

+ 11 - 0
fw/head.S

@@ -0,0 +1,11 @@
+	// The linker ensures that section .init is first
+	.section ".init","ax"
+	.org 0
+	.globl _reset
+_reset:
+	j _start
+
+	.org 0x10
+	.globl _irq
+_irq:
+	j die		// Nothing for now

+ 21 - 0
fw/hello.c

@@ -0,0 +1,21 @@
+#define CONSOLE (*(volatile unsigned char *)0xc0000000)
+
+void die(void)
+{
+    while (1)
+	;
+}
+
+void _start(int y)
+{
+    static const char hello[] = "Hello, World!\r\n";
+    const char *p;
+    int x = 1;
+
+    for (p = hello; *p; p++) {
+	CONSOLE = *p;
+	x *= *p;
+    }
+
+    die();
+}