diff --git a/seminaries/qtrvsim/qtrvsim-semstart/.gitignore b/seminaries/qtrvsim/qtrvsim-semstart/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..fdad36531fb25eb07eff70445c8e2f70a51e1c17 --- /dev/null +++ b/seminaries/qtrvsim/qtrvsim-semstart/.gitignore @@ -0,0 +1,3 @@ +*.o +depend +simple-lw-sw diff --git a/seminaries/qtrvsim/qtrvsim-semstart/Makefile b/seminaries/qtrvsim/qtrvsim-semstart/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..56719933306285898ab5fbd2395133a5e331c913 --- /dev/null +++ b/seminaries/qtrvsim/qtrvsim-semstart/Makefile @@ -0,0 +1,80 @@ +ARCH=riscv64-unknown-elf + +SOURCES = simple-lw-sw.S +TARGET_EXE = simple-lw-sw + +LDFLAGS += -Wl,-Ttext,0x200 -Wl,-Tdata,0x400 + + +CC=$(ARCH)-gcc +CXX=$(ARCH)-g++ +AS=$(ARCH)-as +LD=$(ARCH)-ld +OBJCOPY=$(ARCH)-objcopy + +ARCHFLAGS += -mabi=ilp32 +ARCHFLAGS += -march=rv32i +ARCHFLAGS += -fno-lto + +CFLAGS += -ggdb -Os -Wall +CXXFLAGS+= -ggdb -Os -Wall +AFLAGS += -ggdb +LDFLAGS += -ggdb +LDFLAGS += -nostartfiles +LDFLAGS += -nostdlib +LDFLAGS += -static +#LDFLAGS += -specs=/opt/musl/riscv64-linux-gnu/lib/musl-gcc.specs + +CFLAGS += $(ARCHFLAGS) +CXXFLAGS+= $(ARCHFLAGS) +AFLAGS += $(ARCHFLAGS) +LDFLAGS += $(ARCHFLAGS) + +OBJECTS += $(filter %.o,$(SOURCES:%.S=%.o)) +OBJECTS += $(filter %.o,$(SOURCES:%.c=%.o)) +OBJECTS += $(filter %.o,$(SOURCES:%.cpp=%.o)) + +all : default + +.PHONY : default clean dep all + +%.o:%.S + $(CC) -D__ASSEMBLY__ $(AFLAGS) -c $< -o $@ + +%.o:%.c + $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ + +%.o:%.cpp + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< + +%.s:%.c + $(CC) $(CFLAGS) $(CPPFLAGS) -S $< -o $@ + +default : $(TARGET_EXE) + +$(TARGET_EXE) : $(OBJECTS) + $(CC) $(LDFLAGS) $^ -o $@ + +dep: depend + +depend: $(SOURCES) $(glob *.h) + echo '# autogenerated dependencies' > depend +ifneq ($(filter %.S,$(SOURCES)),) + $(CC) -D__ASSEMBLY__ $(AFLAGS) -w -E -M $(filter %.S,$(SOURCES)) \ + >> depend +endif +ifneq ($(filter %.c,$(SOURCES)),) + $(CC) $(CFLAGS) $(CPPFLAGS) -w -E -M $(filter %.c,$(SOURCES)) \ + >> depend +endif +ifneq ($(filter %.cpp,$(SOURCES)),) + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -w -E -M $(filter %.cpp,$(SOURCES)) \ + >> depend +endif + +clean: + rm -f *.o *.a $(OBJECTS) $(TARGET_EXE) depend + +#mips-elf-objdump --source -M no-aliases,reg-names=numeric qtmips_binrep + +-include depend diff --git a/seminaries/qtrvsim/qtrvsim-semstart/simple-lw-sw.S b/seminaries/qtrvsim/qtrvsim-semstart/simple-lw-sw.S new file mode 100644 index 0000000000000000000000000000000000000000..1f5d9dfca4714f8e6b32c2e264bbb592da6be2bf --- /dev/null +++ b/seminaries/qtrvsim/qtrvsim-semstart/simple-lw-sw.S @@ -0,0 +1,46 @@ +// Template file with simple memory example +// QtRVSim simulator https://github.com/cvut/qtrvsim/ +// +// template-os.S - example file +// +// (C) 2021 by Pavel Pisa +// e-mail: pisa@cmp.felk.cvut.cz +// homepage: http://cmp.felk.cvut.cz/~pisa +// work: http://www.pikron.com/ +// license: public domain + +// Directives to make interesting windows visible +#pragma qtrvsim show registers +#pragma qtrvsim show memory + +.globl _start +.option norelax + +.text + +_start: +loop: + // load the word from absolute address + lw x2, 0x400(x0) + // store the word to absolute address + sw x2, 0x404(x0) + + // stop execution wait for debugger/user + // ebreak + // ensure that continuation does not + // interpret random data + beq x0, x0, loop + nop + nop + ebreak + +.data +.org 0x400 + +src_val: + .word 0x12345678 +dst_val: + .word 0 + +// Specify location to show in memory window +#pragma qtrvsim focus memory src_val