diff --git a/sw/examples/Makefile b/sw/examples/Makefile index 940fc871..f8de2171 100644 --- a/sw/examples/Makefile +++ b/sw/examples/Makefile @@ -14,22 +14,22 @@ soctarget ?= None ex ?= None # Compile for simulation (may be overridden) -sim ?= false +sim ?= 0 # Compile for use with bootloader (may be overridden) -boot ?= false +boot ?= 0 # Vuart for make run example (may be overridden) vuart ?= None # Save objdump while compiling (may be overridden) -objdump ?= true +objdump ?= 1 # Save binary while compiling (may be overridden) -bin ?= true +bin ?= 1 # Save map file while compiling (may be overridden) -map ?= true +map ?= 1 ######################################################################## # Checks @@ -81,8 +81,8 @@ endif RVPREFIX := riscv64-unknown-elf -CFLAGS := -Wall -CFLAGS += -mabi=ilp32 -march=rv32i -nostartfiles -ffreestanding -Os -g +CFLAGS += -Wall +CFLAGS += -mabi=ilp32 -march=rv32i -nostartfiles -ffreestanding -O0 -g CFLAGS += -I $(RVATOM_LIB)/include -L $(RVATOM_LIB) LINKERSCRIPT := None @@ -114,7 +114,7 @@ ifeq ($(__check_soctarget),true) endif endif - ifeq ($(boot), true) + ifeq ($(boot), 1) LINKERSCRIPT:= ../flashboot/link_app.lds endif @@ -150,18 +150,18 @@ EXAMPLE_DIRS = $(sort $(dir $(wildcard */))) SRC_FILES = $(patsubst %, $(ex)/%, $(src_files)) # atomsim args -ATOMSIM_ARGS = --maxitr=999999999 --enable-uart-dump +ATOMSIM_ARGS = --maxitr=999999999 -uv # VUART setting ifneq ($(vuart), None) ATOMSIM_ARGS += --vuart=$(vuart) endif -ifeq ($(map), true) +ifeq ($(map), 1) LFLAGS += -Xlinker -Map $(executable).map endif -ifeq ($(sim), true) +ifeq ($(sim), 1) CFLAGS += -DSIM endif @@ -190,7 +190,7 @@ help: ## Show help @printf "Note:\n" @printf " - Following TARGETs can be run without overriding \"ex\" & \"soctarget\" variables\n" @printf " help, all, clean-all\n" - @printf " - To save objdump,, set the \"objdump\" variable to \"true\" in the CLI.\n" + @printf " - To save objdump,, set the \"objdump\" variable to \"1\" in the CLI.\n" @printf " - To save run using vuart, set the vuart variable to the path of the simport\n" @@ -203,11 +203,11 @@ $(ex)/$(executable): $(SRC_FILES) @printf "$(COLOR_CYAN)%-15s | Compiling %-35s <- %s$(COLOR_NC)\n" ${ex} $@ $< cd $(ex) && $(RVPREFIX)-gcc $(CFLAGS) $(src_files) -o $(executable) $(LFLAGS) -ifeq ($(objdump), true) +ifeq ($(objdump), 1) $(RVPREFIX)-objdump -Shtd $@ > $@.objdump endif -ifeq ($(bin), true) +ifeq ($(bin), 1) $(RVPREFIX)-objcopy -O binary $@ $@.bin @printf "Binary size: %s bytes\n" $$(stat --format=%s "$@.bin") endif @@ -236,11 +236,11 @@ clean: ## Clean executable all: ## Build all examples - @$(patsubst %/, make -s ex=% compile;,${EXAMPLE_DIRS}) + @$(patsubst %/, make -s ex=% sim=1 compile;,${EXAMPLE_DIRS}) run-all: ## Build & run all examples - @$(patsubst %/, printf "${COLOR_CYAN}----------------------------------------------------${COLOR_NC}\n"; make -s ex=% run;,${EXAMPLE_DIRS}) + @$(patsubst %/, printf "${COLOR_CYAN}----------------------------------------------------${COLOR_NC}\n"; make -s ex=% sim=1 run;,${EXAMPLE_DIRS}) .PHONY: clean-all diff --git a/sw/examples/banner/banner.c b/sw/examples/banner/banner.c index 5960ce72..08461717 100644 --- a/sw/examples/banner/banner.c +++ b/sw/examples/banner/banner.c @@ -34,8 +34,9 @@ int main() puts(banner); printf("CPU : RISC-V Atom @ %d Hz\n", CLK_FREQ); puts("Arch : RV32I - little endian\n"); - printf("CODE RAM : 0x%8x (%d bytes)\n", CODERAM_BASE, CODERAM_SIZE); - printf("DATA RAM : 0x%8x (%d bytes)\n", DATARAM_BASE, DATARAM_SIZE); + printf("CODE RAM : 0x%08x (%d bytes)\n", (unsigned)CODERAM_BASE, (unsigned)CODERAM_SIZE); + printf("DATA RAM : 0x%08x (%d bytes)\n", (unsigned)DATARAM_BASE, (unsigned)DATARAM_SIZE); puts("Exiting...\n"); + asm volatile("ecall"); return 0; } diff --git a/sw/examples/csr/Makefile.include b/sw/examples/csr/Makefile.include deleted file mode 100644 index 42ed5061..00000000 --- a/sw/examples/csr/Makefile.include +++ /dev/null @@ -1,2 +0,0 @@ -src_files = csr.c -executable = csr.elf \ No newline at end of file diff --git a/sw/examples/csr/csr.S b/sw/examples/csr/csr.S deleted file mode 100644 index ee1e28b4..00000000 --- a/sw/examples/csr/csr.S +++ /dev/null @@ -1,23 +0,0 @@ -.global main -.text - -.global _start - -main: - csrrw t0, cycle, x0 // read time - - li t2, 0 - li t3, 10 -loop: - beq t2, t3, exitloop - addi t2, t2, 1 - j loop -exitloop: - - csrrw t1, cycle, x0 // read time - - // get difference - sub t1, t1, t0 - - ebreak - diff --git a/sw/examples/csr/csr.c b/sw/examples/csr/csr.c deleted file mode 100644 index a81197a3..00000000 --- a/sw/examples/csr/csr.c +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -#include -#include - -#define SV \ -__asm__ volatile ("rdcycle t5"); \ -__asm__ volatile ("rdcycleh t6"); - -#define BRK \ -__asm__ volatile ("ebreak"); - -void print_wall_pattern(int height, int width) -{ - for(int j=0; j - -#define n 4 - -int compltedPhilo = 0, i; - -struct fork -{ - int taken; -} ForkAvil[n]; - -struct philosp -{ - int left; - int right; -} Philostatus[n]; - - - -void goForDinner(int philID) -{ - if(Philostatus[philID].left==10 && Philostatus[philID].right == 10) // same like threads concept here cases implemented - { - printf("Philosopher %d completed his dinner\n", philID + 1); - } - else if(Philostatus[philID].left==1 && Philostatus[philID].right == 1) // if already completed dinner - { - printf("Philosopher %d completed his dinner\n", philID + 1); // if just taken two forks - - Philostatus[philID].left = Philostatus[philID].right = 10; // remembering that he completed dinner by assigning value 10 - int otherFork = philID - 1; - - if(otherFork == -1) - otherFork = (n-1); - - ForkAvil[philID].taken = ForkAvil[otherFork].taken = 0; // releasing forks - printf("Philosopher %d released fork %d and fork %d\n", philID+1, philID+1, otherFork+1); - compltedPhilo++; - } - else if(Philostatus[philID].left==1 && Philostatus[philID].right == 0) - { - if(philID==(n-1)) //left already taken, trying for right fork - { - if(ForkAvil[philID].taken==0) // KEY POINT OF THIS PROBLEM, THAT LAST PHILOSOPHER TRYING IN reverse DIRECTION - { - ForkAvil[philID].taken = Philostatus[philID].right = 1; - printf("Fork %d taken by philosopher %d\n",philID+1,philID+1); - } - else - { - printf("Philosopher %d is waiting for fork %d\n",philID+1,philID+1); - } - } - else - { - //except last philosopher case - int dupphilID = philID; - philID-=1; - - if(philID== -1) - philID=(n-1); - - if(ForkAvil[philID].taken == 0) - { - ForkAvil[philID].taken = Philostatus[dupphilID].right = 1; - printf("Fork %d taken by Philosopher %d\n",philID+1,dupphilID+1); - } - else - { - printf("Philosopher %d is waiting for Fork %d\n",dupphilID+1,philID+1); - } - } - } - else if(Philostatus[philID].left==0) - { - //nothing taken yet - if(philID==(n-1)) - { - if(ForkAvil[philID-1].taken==0) - { - //KEY POINT OF THIS PROBLEM, THAT LAST PHILOSOPHER TRYING IN reverse DIRECTION - ForkAvil[philID-1].taken = Philostatus[philID].left = 1; - printf("Fork %d taken by philosopher %d\n",philID,philID+1); - } - else - { - printf("Philosopher %d is waiting for fork %d\n",philID+1,philID); - } - } - else - { - //except last philosopher case - if(ForkAvil[philID].taken == 0) - { - ForkAvil[philID].taken = Philostatus[philID].left = 1; - printf("Fork %d taken by Philosopher %d\n",philID+1,philID+1); - } - else - { - printf("Philosopher %d is waiting for Fork %d\n",philID+1,philID+1); - } - } - } - else - {} -} - - -int main() -{ - serial_init(UART_BAUD_115200); - - for(i=0; i> Till now num of philosophers completed dinner are %d\n\n",compltedPhilo); - } - return 0; -} diff --git a/sw/examples/fibonacci/Makefile.include b/sw/examples/fibonacci/Makefile.include deleted file mode 100644 index 5ee5d92e..00000000 --- a/sw/examples/fibonacci/Makefile.include +++ /dev/null @@ -1,2 +0,0 @@ -src_files = fibonacci.c -executable = fibonacci.elf \ No newline at end of file diff --git a/sw/examples/fibonacci/fibonacci.c b/sw/examples/fibonacci/fibonacci.c deleted file mode 100644 index c933b8fa..00000000 --- a/sw/examples/fibonacci/fibonacci.c +++ /dev/null @@ -1,34 +0,0 @@ -#include - -void printFibonacci(int n){ - static int pprev=0, prev=1, curr; - if(n>0){ - curr = prev + pprev; - pprev = prev; - prev = curr; - printf("%d\n", curr); - printFibonacci(n-1); - } -} - -int main() -{ - int no_of_terms = 32, i; - int pprev = 0; - int prev = 1; - int curr = 0; - - printf("First %d terms of Fibonacci Series (Using Loops):\n", no_of_terms); - - for (i=0; i - - -void towers(int, char, char, char); - -int main() -{ - // Number of disks - int num = 3; - - printf("The sequence of moves involved in the Tower of Hanoi are :\n"); - towers(num, 'A', 'C', 'B'); - return 0; -} - -void towers(int num, char frompeg, char topeg, char auxpeg) -{ - if (num == 1) - { - printf(" Move %c disk 1 from peg %c to peg %c \n", 'd', frompeg, topeg); - return; - } - towers(num - 1, frompeg, auxpeg, topeg); - - printf(" Move disk %d from peg %c to peg %c \n", num, frompeg, topeg); - - towers(num - 1, auxpeg, topeg, frompeg); -} \ No newline at end of file diff --git a/sw/examples/pascal/Makefile.include b/sw/examples/pascal/Makefile.include deleted file mode 100644 index 59331001..00000000 --- a/sw/examples/pascal/Makefile.include +++ /dev/null @@ -1,2 +0,0 @@ -src_files = pascal.c -executable = pascal.elf \ No newline at end of file diff --git a/sw/examples/pascal/pascal.c b/sw/examples/pascal/pascal.c deleted file mode 100644 index 353d03d9..00000000 --- a/sw/examples/pascal/pascal.c +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include - -void myprint(int num, int digits) -{ - int arr[4]; - - int n; - int i; - for(i=0; i=0; i--) - { - if(arr[i]==0 && flag == 0) - putchar(' '); - else - { - putint(arr[i], 0, DEC); - flag = 1; - } - } -} - - -/** - * @briefPrint pascal's triangle - * - */ -int main() { - serial_init(UART_BAUD_115200); - - int rows = 8, coef = 1, space, i, j; - - printf("First %d rows of pascal's triangle...\n", rows); - - for (i = 0; i < rows; i++) { - for (space = 1; space <= rows - i; space++) - printf(" "); - for (j = 0; j <= i; j++) { - if (j == 0 || i == 0) - coef = 1; - else - coef = coef * (i - j + 1) / j; - - myprint(coef, 4); - //print_int(coef, 10); - } - putchar('\n'); - } - return 0; -} \ No newline at end of file diff --git a/sw/examples/systest/Makefile.include b/sw/examples/systest/Makefile.include new file mode 100644 index 00000000..e01958b1 --- /dev/null +++ b/sw/examples/systest/Makefile.include @@ -0,0 +1,2 @@ +src_files = systest.c +executable = systest.elf \ No newline at end of file diff --git a/sw/examples/systest/systest.c b/sw/examples/systest/systest.c new file mode 100644 index 00000000..ea78ddbd --- /dev/null +++ b/sw/examples/systest/systest.c @@ -0,0 +1,78 @@ +#include +#include +#include +#include + +#define CORE "RISC-V Atom" +#define ARCH "RV32I - little endian" + +void print_arr(int arr[], int n){ + putchar('{'); + for(int i=0; iname); + int ret = test->fptr(); + if(ret !=0 ){ + nfailed++; + } + printf("retcode: %d, %s\n\n", ret, res[ret==0]); + } + puts("========================================\n"); + puts(nfailed>0 ? "Some tests failed\n": "All passed!!\n"); + + // calc CPI + uint64_t cycles = cycle(); + uint64_t instret = CSR_read(CSR_INSTRETH); + instret = (instret << 32) | CSR_read(CSR_INSTRET); + + printf("N Cycles: %lld\n", cycles); + printf("N Instr: %lld\n", instret); + printf("CPI: %lld\n", cycles/instret); + return 0; +} diff --git a/sw/examples/systest/tests/crypto.c b/sw/examples/systest/tests/crypto.c new file mode 100644 index 00000000..7ac2e20d --- /dev/null +++ b/sw/examples/systest/tests/crypto.c @@ -0,0 +1,45 @@ +#include +#include + +#define isLower(c) ((c >= 'a') && (c <= 'z')) +#define isUpper(c) ((c >= 'A') && (c <= 'Z')) +#define isDigit(c) ((c >= '0') && (c <= '9')) + +void caesar(char * input, char * output, int n, int key, bool encrypt) { + for (int i = 0; i= 1) + return n * _fact(n-1); + else + return 1; +} + +void recursive_factorial(int arr[], int n) { + for(int i=0; i