From 40c061cf4c2055849fbd12395ae61adfc03f9422 Mon Sep 17 00:00:00 2001 From: mpabi Date: Thu, 27 Feb 2025 12:41:11 +0000 Subject: [PATCH] init --- counter.S | 11 +++++-- make/Make.rules | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ make/Makefile | 12 ++++++++ 3 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 make/Make.rules create mode 100644 make/Makefile diff --git a/counter.S b/counter.S index d4b10bd..6a16af9 100644 --- a/counter.S +++ b/counter.S @@ -1,15 +1,20 @@ .data -sentence: .ascii "Become a Prograammer" +// 0x8000102c +sentence: .ascii "Become a Prograammermmmmmrr\0" +// ^ +// ^ .text .align 2 .globl _start _start: + la t2, sentence # Load the address of sentence into t2 - li t0, 0x6d // ascii 'm' - li t1, 0 // licznik wystapien 'm' + li t0, 0x72 // ascii 'm' + + li t1, 0x00 // licznik wystapien 'm' print_loop: lbu t3, 0(t2) # Load the byte (character) from address in t2 diff --git a/make/Make.rules b/make/Make.rules new file mode 100644 index 0000000..68f5574 --- /dev/null +++ b/make/Make.rules @@ -0,0 +1,81 @@ +ARCH=riscv32-unknown-elf +GNU_DIR=$(HOME)/riscv/opt/rv32im_zicsr/ +GNU_BIN=$(GNU_DIR)/bin + + +CC=$(GNU_BIN)/$(ARCH)-gcc +CXX=$(GNU_BIN)/$(ARCH)-g++ +AS=$(GNU_BIN)/$(ARCH)-as +LD=$(GNU_BIN)/$(ARCH)-ld +OBJCOPY=$(GNU_BIN)/$(ARCH)-objcopy +OBJDUMP=$(GNU_BIN)/$(ARCH)-objdump +SIZE=$(GNU_BIN)/$(ARCH)-size +AR=$(GNU_BIN)/$(ARCH)-ar +RANLIB=$(GNU_BIN)/$(ARCH)-ranlib + + +CFLAGS+=-ffreestanding +CFLAGS+=-fno-pic +CFLAGS+=-march=rv32i -mabi=ilp32 +CFLAGS+= -O0 -g + + +LDFLAGS+=-nostdlib +LDFLAGS+=-Wl,-Ttext=0x80000000 +LDFLAGS+= -g + +# see: https://github.com/riscv/riscv-gcc/issues/120 +#LDFLAGS+=-Wl,--no-relax + + + +ASFLAGS+=$(CFLAGS) +CXXFLAGS+=$(CFLAGS) + +CLEAN_DIRS=$(SUBDIRS:%=clean-%) +ALL_DIRS=$(SUBDIRS:%=all-%) + +OBJDUMPFLAGS+=-Mnumeric,no-aliases + +.PHONY: all clean world $(CLEAN_DIRS) $(ALL_DIRS) + + +%.bin : % + $(OBJCOPY) $< -O binary $@ + +%.lst : % + $(OBJDUMP) $(OBJDUMPFLAGS) -dr $< > $<.lst + +% : %.o + $(LINK.c) $(LDFLAGS) -o $@ $^ $(LDLIBS) + $(SIZE) -x -A $@ + +%.s: %.c + $(COMPILE.c) -S -o $@ $< + +%.s: %.cc + $(COMPILE.cc) -S -o $@ $< + +%.o: %.c + $(COMPILE.c) -o $@ $< + +%.o: %.cc + $(COMPILE.cc) -o $@ $< + +%.srec: % + $(OBJCOPY) $< -O srec $@ + + + + +all:: $(ALL_DIRS) + +clean:: $(CLEAN_DIRS) + +$(ALL_DIRS):: + $(MAKE) -C $(@:all-%=%) all + +$(CLEAN_DIRS):: + $(MAKE) -C $(@:clean-%=%) clean + +world:: clean all diff --git a/make/Makefile b/make/Makefile new file mode 100644 index 0000000..a330f3a --- /dev/null +++ b/make/Makefile @@ -0,0 +1,12 @@ + +SUBDIRS=\ + load4regs \ + counter \ + padd \ + link \ + uart \ + sw \ + freestanding + +TOP=. +include $(TOP)/Make.rules