test
This commit is contained in:
parent
b820b3995e
commit
71a99c4add
Binary file not shown.
|
@ -0,0 +1,81 @@
|
|||
|
||||
ARCH=riscv64-unknown-elf
|
||||
GNU_DIR=$(HOME)/riscv/riscv/
|
||||
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+= -g
|
||||
|
||||
|
||||
LDFLAGS+=-nostdlib
|
||||
LDFLAGS+=-Wl,-Ttext=0x00000000
|
||||
|
||||
# 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 --disassemble-all $< > $<.lst
|
||||
|
||||
% : %.o
|
||||
$(LINK.cc) $(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
|
|
@ -0,0 +1,27 @@
|
|||
TOP=./
|
||||
include $(TOP)/Make.rules
|
||||
|
||||
LDLIBS=
|
||||
#CFLAGS+=-O0 -g
|
||||
# CFLAGS+=-Og -ggdb3
|
||||
CFLAGS+=-O0 -ggdb3
|
||||
|
||||
LDFLAGS+=-Wl,--no-relax
|
||||
LDFLAGS+=-Wl,-Ttext=0x80000000,-Tdata=0x80010000
|
||||
# LDFLAGS+=-T murax_128k_ram.ld
|
||||
|
||||
PROGS=prog prog.bin prog.lst
|
||||
|
||||
all:: $(PROGS)
|
||||
|
||||
prog: _crt0.o _rvmain.o myfunc.o
|
||||
$(LINK.cc) -o $@ $^ $(LDLIBS)
|
||||
$(SIZE) -A -x $@
|
||||
|
||||
clean::
|
||||
rm -f $(PROGS) *.o *.s *.lst *.bin *.srec *.dis
|
||||
|
||||
.PHONY: run
|
||||
run: prog.bin
|
||||
../../../src/rvddt -l0x3000 -f prog.bin
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
.text
|
||||
.global _start
|
||||
.type _start, @function
|
||||
|
||||
_start:
|
||||
# Initialize global pointer
|
||||
.option push
|
||||
.option norelax
|
||||
la gp, __global_pointer$
|
||||
.option pop
|
||||
|
||||
li sp, 0x800ffff0
|
||||
|
||||
# Clear the bss segment
|
||||
la a0, __bss_start
|
||||
la a1, __BSS_END__
|
||||
|
||||
clear_bss:
|
||||
bgeu a0, a1, finish_bss
|
||||
sb x0, 0(a0)
|
||||
addi a0, a0, 1
|
||||
beq x0, x0, clear_bss
|
||||
finish_bss:
|
||||
|
||||
nop //!
|
||||
|
||||
call main
|
||||
|
||||
nop //!
|
||||
|
||||
# abort execution here
|
||||
ebreak
|
||||
|
||||
.section .rodata
|
||||
alfabet:
|
||||
.string "abcdefghijklmnopqrstuwxyz"
|
||||
slowo:
|
||||
|
||||
.section .data
|
||||
wynik:
|
||||
.string "mpabi"
|
||||
.space 26 # rezerwuje 26 bajtów dla wyniku, zainicjowane na 0
|
Binary file not shown.
|
@ -0,0 +1,23 @@
|
|||
#include <stdint.h>
|
||||
|
||||
int strlen(char *s)
|
||||
{
|
||||
char *p = s;
|
||||
while (*p != '\0')
|
||||
p++;
|
||||
return p - s;
|
||||
}
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
char *p1 = "Bogon12313";
|
||||
char *p2 = "Maks12122";
|
||||
|
||||
int8_t name = strlen(p2);
|
||||
int8_t surname = strlen(p1);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
Binary file not shown.
|
@ -0,0 +1,35 @@
|
|||
#include "myfunc.h"
|
||||
|
||||
// Lokalna deklaracja funkcji my_strlen
|
||||
static int my_strlen(const char *str) {
|
||||
int length = 0;
|
||||
while (str[length] != '\0') {
|
||||
length++;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
void count_characters(const char* alfabet, const char* slowo, uint8_t* wynik) {
|
||||
// Użycie my_strlen do obliczenia długości alfabetu
|
||||
int alfabet_length = my_strlen(alfabet);
|
||||
|
||||
for (int i = 0; i < alfabet_length; ++i) {
|
||||
wynik[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < alfabet_length; ++i) {
|
||||
for (int j = 0; slowo[j] != '\0'; ++j) {
|
||||
if (alfabet[i] == slowo[j]) {
|
||||
wynik[i]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #include "myfunc.h"
|
||||
|
||||
// const char* alfabet = "abcdefghijklmnopqrstuwxyz";
|
||||
// const char* slowo = "mpabi";
|
||||
// int wynik[26] = {0}; // Inicjalizacja tablicy wyników na 0
|
||||
|
||||
// count_characters(alfabet, slowo, wynik);
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef myfunc_H
|
||||
#define myfunc_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
void count_characters(const char* alfabet, const char* slowo, uint8_t* wynik);
|
||||
|
||||
#endif
|
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue