Working SERV cpu
This commit is contained in:
8
sw/.gitignore
vendored
Normal file
8
sw/.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
*.o
|
||||
*.hex
|
||||
*.bin
|
||||
*.map
|
||||
*.elf.asm
|
||||
*.elf
|
||||
*.coe
|
||||
*.mif
|
||||
@@ -1,14 +1,56 @@
|
||||
TOOLCHAIN_PREFIX?=riscv64-elf-
|
||||
CC=$(TOOLCHAIN_PREFIX)gcc
|
||||
OBJCOPY=$(TOOLCHAIN_PREFIX)objcopy
|
||||
TOOLCHAIN_PREFIX ?= riscv64-elf-
|
||||
|
||||
%.elf: %.S link.ld
|
||||
# $(CC) -nostartfiles -nostdlib -march=rv32i_zicsr -mabi=ilp32 -Tlink.ld -o$@ $<
|
||||
$(CC) -nostartfiles -nostdlib -ffreestanding -march=rv32i_zicsr -mabi=ilp32 -Tlink.ld -o$@ $<
|
||||
%.bin: %.elf
|
||||
CC := $(TOOLCHAIN_PREFIX)gcc
|
||||
OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy
|
||||
OBJDUMP := $(TOOLCHAIN_PREFIX)objdump
|
||||
SIZE := $(TOOLCHAIN_PREFIX)size
|
||||
|
||||
TARGET := blinky
|
||||
SRCS_C := blinky.c
|
||||
SRCS_S := start.s
|
||||
OBJS := $(SRCS_C:.c=.o) $(SRCS_S:.s=.o)
|
||||
|
||||
ARCH_FLAGS := -march=rv32i_zicsr -mabi=ilp32
|
||||
CFLAGS := $(ARCH_FLAGS) -Os -ffreestanding -fno-builtin -Wall -Wextra
|
||||
ASFLAGS := $(ARCH_FLAGS)
|
||||
LDFLAGS := $(ARCH_FLAGS) -nostdlib -nostartfiles -Wl,-Bstatic,-Tlink.ld,--gc-sections,-Map,$(TARGET).map
|
||||
|
||||
HEX_TO_COE := ../../scripts/hex_to_coe.py
|
||||
HEX_TO_MIF := ../../scripts/hex_to_mif.py
|
||||
|
||||
.PHONY: all clean disasm size
|
||||
|
||||
all: $(TARGET).elf $(TARGET).bin $(TARGET).hex $(TARGET).coe $(TARGET).mif $(TARGET).elf.asm
|
||||
|
||||
$(TARGET).elf: $(OBJS) link.ld
|
||||
$(CC) $(LDFLAGS) -o $@ $(OBJS)
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
%.o: %.s
|
||||
$(CC) $(ASFLAGS) -c -o $@ $<
|
||||
|
||||
$(TARGET).bin: $(TARGET).elf
|
||||
$(OBJCOPY) -O binary $< $@
|
||||
%.hex: %.bin
|
||||
|
||||
$(TARGET).hex: $(TARGET).bin
|
||||
hexdump -v -e '1/1 "%02x\n"' $< > $@
|
||||
|
||||
$(TARGET).coe: $(TARGET).hex
|
||||
$(HEX_TO_COE) $< $@
|
||||
|
||||
$(TARGET).mif: $(TARGET).hex
|
||||
$(HEX_TO_MIF) $< $@
|
||||
|
||||
$(TARGET).elf.asm: $(TARGET).elf
|
||||
$(OBJDUMP) -d -S $< > $@
|
||||
|
||||
disasm: $(TARGET).elf.asm
|
||||
|
||||
size: $(TARGET).elf
|
||||
$(SIZE) $<
|
||||
|
||||
clean:
|
||||
rm -f *.elf *.bin *.hex
|
||||
rm -f $(TARGET).elf $(TARGET).bin $(TARGET).hex $(TARGET).coe $(TARGET).mif \
|
||||
$(TARGET).elf.asm $(TARGET).map $(OBJS)
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#define GPIO_BASE 0x80000000
|
||||
#define DELAY 2
|
||||
|
||||
.globl _start
|
||||
_start:
|
||||
lui a0, %hi(GPIO_BASE)
|
||||
addi a0, a0, %lo(GPIO_BASE)
|
||||
addi t0, zero, 0
|
||||
li t1, DELAY
|
||||
.lp1:
|
||||
sb t0, 0(a0)
|
||||
addi t0, t0, 1
|
||||
and t2, zero, zero
|
||||
time1:
|
||||
addi t2, t2, 1
|
||||
bne t1, t2, time1
|
||||
j .lp1
|
||||
22
sw/blinky/blinky.c
Normal file
22
sw/blinky/blinky.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#define GPIO_BASE 0x40000000u
|
||||
|
||||
static volatile uint32_t * const gpio = (volatile uint32_t *)GPIO_BASE;
|
||||
|
||||
static void delay(volatile uint32_t ticks){
|
||||
while (ticks--) {
|
||||
__asm__ volatile ("nop");
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint32_t v = 0;
|
||||
|
||||
for (;;) {
|
||||
*gpio = v;
|
||||
v++;
|
||||
delay(20000u);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,33 @@
|
||||
OUTPUT_ARCH( "riscv" )
|
||||
OUTPUT_ARCH("riscv")
|
||||
ENTRY(_start)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
RAM (rwx) : ORIGIN = 0x00000000, LENGTH = 8K
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x00000000;
|
||||
.text : { *(.text) }
|
||||
.data : { *(.data) }
|
||||
.bss : { *(.bss) }
|
||||
.text :
|
||||
{
|
||||
KEEP(*(.text.init))
|
||||
*(.text .text.*)
|
||||
*(.rodata .rodata.*)
|
||||
} > RAM
|
||||
|
||||
.data :
|
||||
{
|
||||
*(.data .data.*)
|
||||
} > RAM
|
||||
|
||||
.bss (NOLOAD) :
|
||||
{
|
||||
__bss_start = .;
|
||||
*(.bss .bss.*)
|
||||
*(COMMON)
|
||||
__bss_end = .;
|
||||
} > RAM
|
||||
|
||||
. = ALIGN(4);
|
||||
__stack_top = ORIGIN(RAM) + LENGTH(RAM);
|
||||
}
|
||||
|
||||
23
sw/blinky/start.s
Normal file
23
sw/blinky/start.s
Normal file
@@ -0,0 +1,23 @@
|
||||
.section .text.init
|
||||
.globl _start
|
||||
.type _start, @function
|
||||
|
||||
_start:
|
||||
la sp, __stack_top
|
||||
|
||||
# Zero .bss
|
||||
la t0, __bss_start
|
||||
la t1, __bss_end
|
||||
1:
|
||||
bgeu t0, t1, 2f
|
||||
sw zero, 0(t0)
|
||||
addi t0, t0, 4
|
||||
j 1b
|
||||
|
||||
2:
|
||||
call main
|
||||
|
||||
3:
|
||||
j 3b
|
||||
|
||||
.size _start, .-_start
|
||||
Reference in New Issue
Block a user