From 3a38fe4130922e9900af3aa7f056e3ba2232fa61 Mon Sep 17 00:00:00 2001 From: Dolu1990 Date: Wed, 20 Mar 2019 01:13:05 +0100 Subject: [PATCH] Add mmu regresion blank project --- src/test/cpp/raw/common/asm.mk | 73 ++++++++++++++++++++++++++++++ src/test/cpp/raw/mmu/build/mmu.asm | 43 ++++++++++++++++++ src/test/cpp/raw/mmu/build/mmu.hex | 10 ++++ src/test/cpp/raw/mmu/makefile | 3 ++ src/test/cpp/raw/mmu/src/crt.S | 46 +++++++++++++++++++ src/test/cpp/raw/mmu/src/ld | 16 +++++++ 6 files changed, 191 insertions(+) create mode 100644 src/test/cpp/raw/common/asm.mk create mode 100644 src/test/cpp/raw/mmu/build/mmu.asm create mode 100644 src/test/cpp/raw/mmu/build/mmu.hex create mode 100644 src/test/cpp/raw/mmu/makefile create mode 100644 src/test/cpp/raw/mmu/src/crt.S create mode 100644 src/test/cpp/raw/mmu/src/ld diff --git a/src/test/cpp/raw/common/asm.mk b/src/test/cpp/raw/common/asm.mk new file mode 100644 index 0000000..8459b7b --- /dev/null +++ b/src/test/cpp/raw/common/asm.mk @@ -0,0 +1,73 @@ +PROJ_NAME=mmu + + +RISCV_PATH?=/opt/riscv/ +CFLAGS += -march=rv32i -mabi=ilp32 +RISCV_NAME = riscv64-unknown-elf +RISCV_OBJCOPY = $(RISCV_PATH)/bin/$(RISCV_NAME)-objcopy +RISCV_OBJDUMP = $(RISCV_PATH)/bin/$(RISCV_NAME)-objdump +RISCV_CLIB=$(RISCV_PATH)$(RISCV_NAME)/lib/ +RISCV_CC=$(RISCV_PATH)/bin/$(RISCV_NAME)-gcc +LDSCRIPT=src/ld + + +SRCS = $(wildcard src/*.c) \ + $(wildcard src/*.cpp) \ + $(wildcard src/*.S) + + +CFLAGS += -static +LDFLAGS += -e_start -T $(LDSCRIPT) -nostartfiles -Wl,-Map,$(OBJDIR)/$(PROJ_NAME).map -Wl,--print-memory-usage +OBJDIR = build +OBJS := $(SRCS) +OBJS := $(OBJS:.c=.o) +OBJS := $(OBJS:.cpp=.o) +OBJS := $(OBJS:.S=.o) +OBJS := $(addprefix $(OBJDIR)/,$(OBJS)) + + + +all: $(OBJDIR)/$(PROJ_NAME).elf $(OBJDIR)/$(PROJ_NAME).hex $(OBJDIR)/$(PROJ_NAME).asm $(OBJDIR)/$(PROJ_NAME).v + @echo "done" + +$(OBJDIR)/%.elf: $(OBJS) | $(OBJDIR) + $(RISCV_CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) + +%.hex: %.elf + $(RISCV_OBJCOPY) -O ihex $^ $@ + +%.bin: %.elf + $(RISCV_OBJCOPY) -O binary $^ $@ + +%.v: %.elf + $(RISCV_OBJCOPY) -O verilog $^ $@ + +%.asm: %.elf + $(RISCV_OBJDUMP) -S -d $^ > $@ + +$(OBJDIR)/%.o: %.c + mkdir -p $(dir $@) + $(RISCV_CC) -c $(CFLAGS) $(INC) -o $@ $^ + +$(OBJDIR)/%.o: %.cpp + mkdir -p $(dir $@) + $(RISCV_CC) -c $(CFLAGS) $(INC) -o $@ $^ + +$(OBJDIR)/%.o: %.S + mkdir -p $(dir $@) + $(RISCV_CC) -c $(CFLAGS) -o $@ $^ -D__ASSEMBLY__=1 + +$(OBJDIR): + mkdir -p $@ + +clean: + rm -f $(OBJDIR)/$(PROJ_NAME).elf + rm -f $(OBJDIR)/$(PROJ_NAME).hex + rm -f $(OBJDIR)/$(PROJ_NAME).map + rm -f $(OBJDIR)/$(PROJ_NAME).v + rm -f $(OBJDIR)/$(PROJ_NAME).asm + find $(OBJDIR) -type f -name '*.o' -print0 | xargs -0 -r rm + +.SECONDARY: $(OBJS) + + diff --git a/src/test/cpp/raw/mmu/build/mmu.asm b/src/test/cpp/raw/mmu/build/mmu.asm new file mode 100644 index 0000000..243b786 --- /dev/null +++ b/src/test/cpp/raw/mmu/build/mmu.asm @@ -0,0 +1,43 @@ + +build/mmu.elf: file format elf32-littleriscv + + +Disassembly of section .crt_section: + +80000000 : +80000000: 0280006f j 80000028 <_start> +80000004: 00000013 nop +80000008: 00000013 nop +8000000c: 00000013 nop +80000010: 00000013 nop +80000014: 00000013 nop +80000018: 00000013 nop +8000001c: 00000013 nop + +80000020 : +80000020: 0200006f j 80000040 +80000024: 30200073 mret + +80000028 <_start>: +80000028: 00000097 auipc ra,0x0 +8000002c: 01808093 addi ra,ra,24 # 80000040 +80000030: 30509073 csrw mtvec,ra +80000034: 10509073 csrw stvec,ra +80000038: 00100e13 li t3,1 +8000003c: 0100006f j 8000004c + +80000040 : +80000040: f0100137 lui sp,0xf0100 +80000044: f2410113 addi sp,sp,-220 # f00fff24 +80000048: 01c12023 sw t3,0(sp) + +8000004c : +8000004c: f0100137 lui sp,0xf0100 +80000050: f2010113 addi sp,sp,-224 # f00fff20 +80000054: 00012023 sw zero,0(sp) +80000058: 00000013 nop +8000005c: 00000013 nop +80000060: 00000013 nop +80000064: 00000013 nop +80000068: 00000013 nop +8000006c: 00000013 nop diff --git a/src/test/cpp/raw/mmu/build/mmu.hex b/src/test/cpp/raw/mmu/build/mmu.hex new file mode 100644 index 0000000..096ccfc --- /dev/null +++ b/src/test/cpp/raw/mmu/build/mmu.hex @@ -0,0 +1,10 @@ +:0200000480007A +:100000006F008002130000001300000013000000C6 +:100010001300000013000000130000001300000094 +:100020006F00000273002030970000009380800171 +:100030007390503073905010130E10006F00000139 +:10004000370110F0130141F22320C101370110F0F4 +:10005000130101F22320010013000000130000002F +:100060001300000013000000130000001300000044 +:04000005800000284F +:00000001FF diff --git a/src/test/cpp/raw/mmu/makefile b/src/test/cpp/raw/mmu/makefile new file mode 100644 index 0000000..961e3bc --- /dev/null +++ b/src/test/cpp/raw/mmu/makefile @@ -0,0 +1,3 @@ +PROJ_NAME=mmu + +include ../common/asm.mk \ No newline at end of file diff --git a/src/test/cpp/raw/mmu/src/crt.S b/src/test/cpp/raw/mmu/src/crt.S new file mode 100644 index 0000000..533939b --- /dev/null +++ b/src/test/cpp/raw/mmu/src/crt.S @@ -0,0 +1,46 @@ +.globl _start + + + j _start + nop + nop + nop + nop + nop + nop + nop + +.global trap_entry +trap_entry: + j fail + mret + +_start: + la x1, fail + csrw mtvec, x1 + csrw stvec, x1 + +//Test 1 SC on unreserved area should fail and not write memory + li x28, 1 + + + + j pass + + +fail: //x28 => error code + li x2, 0xF00FFF24 + sw x28, 0(x2) + +pass: + li x2, 0xF00FFF20 + sw x0, 0(x2) + + + + nop + nop + nop + nop + nop + nop diff --git a/src/test/cpp/raw/mmu/src/ld b/src/test/cpp/raw/mmu/src/ld new file mode 100644 index 0000000..cd04151 --- /dev/null +++ b/src/test/cpp/raw/mmu/src/ld @@ -0,0 +1,16 @@ +OUTPUT_ARCH( "riscv" ) + +MEMORY { + onChipRam (W!RX)/*(RX)*/ : ORIGIN = 0x80000000, LENGTH = 8K +} + +SECTIONS +{ + + .crt_section : + { + . = ALIGN(4); + *crt.o(.text) + } > onChipRam + +}