diff --git a/dhrystone/Makefile b/dhrystone/Makefile new file mode 100644 index 0000000..85e5a76 --- /dev/null +++ b/dhrystone/Makefile @@ -0,0 +1,66 @@ +include /f-of-e-tools/tools/sunflower/conf/setup.conf + +TREEROOT = $(SUNFLOWERROOT) +GB3_ROOT = /gb3-resources + +TARGET-ARCH = riscv32-elf +TARGET = riscv + +PROGRAM = dhrystone +PROGRAM-SF = dhrystone-sf +INIT = init +INIT-SF = init-sf + +INCLUDE_DIR = ../include + +OPTFLAGS = -O0 +CFLAGS = -march=rv32i -mabi=ilp32 $(TARGET-ARCH-FLAGS) -Wall +ASFLAGS = --march=rv32i --mabi=ilp32 +INCLUDES = -I$(INCLUDE_DIR) +LDFLAGS = -L$(TOOLSLIB)/$(TARGET) -Map $(PROGRAM).map -Tsail.ld +LDFLAGS-SF = -Ttext $(LOADADDR-SF) -L$(TOOLSLIB)/$(TARGET) -Map $(PROGRAM).map +SREC2HEX = srec2hex +LOADADDR-SF = 0x08004000 + +OBJS =\ + $(INIT).o\ + $(PROGRAM).o\ + +OBJS-SF =\ + $(INIT-SF).o\ + $(PROGRAM).o\ + +all: $(PROGRAM) $(PROGRAM).sr $(PROGRAM-SF) $(PROGRAM-SF).sr Makefile + +$(INIT).o: $(INIT).S + $(AS) $(ASFLAGS) $(INIT).S -o $(INIT).o + +$(PROGRAM): $(OBJS) + $(LD) $(LDFLAGS) $(OBJS) -o $@ -lc -lm -lgcc + +$(PROGRAM).sr:$(PROGRAM) + $(OBJCOPY) -O srec $(PROGRAM) $@ + +$(PROGRAM).o: $(PROGRAM).c Makefile + $(CC) $(CFLAGS) $(OPTFLAGS) $(INCLUDES) -c $(PROGRAM).c + + +$(INIT-SF).o: $(INIT-SF).S + $(CPP) $(INIT-SF).S > $(INIT-SF).i; $(AS) $(ASFLAGS) $(INIT-SF).i -o $(INIT-SF).o + +$(PROGRAM-SF): $(OBJS-SF) + $(LD) $(LDFLAGS-SF) $(OBJS-SF) -o $@ -lc -lgcc -lgloss + +$(PROGRAM-SF).sr:$(PROGRAM-SF) + $(OBJCOPY) -O srec $(PROGRAM-SF) $@ + +install: all + mkdir -p $(GB3_ROOT)/processor/programs/ + $(SREC2HEX) -b 4096 $(PROGRAM).sr + cp program.hex $(GB3_ROOT)/processor/programs/ + cp data.hex $(GB3_ROOT)/processor/programs/ + +clean: + $(RM) init.i *.o $(PROGRAM) $(PROGRAM).sr $(PROGRAM).map + $(RM) init-sf.i *.o $(PROGRAM-SF) $(PROGRAM-SF).sr $(PROGRAM-SF).map + $(RM) program.hex data.hex diff --git a/dhrystone/dhrystone.c b/dhrystone/dhrystone.c new file mode 100644 index 0000000..8481556 --- /dev/null +++ b/dhrystone/dhrystone.c @@ -0,0 +1,287 @@ +#include // Enables dynamic stack allocation +#include /* for strcpy, strcmp */ + +/* General definitions: */ +#ifdef NOSTRUCTASSIGN +#define structassign(d, s) memcpy(&(d), &(s), sizeof(d)) +#else +#define structassign(d, s) d = s +#endif + +#ifdef NOENUM +#define Ident_1 0 +#define Ident_2 1 +#define Ident_3 2 +#define Ident_4 3 +#define Ident_5 4 +typedef int Enumeration; +#else +typedef enum {Ident_1, Ident_2, Ident_3, Ident_4, Ident_5} Enumeration; +#endif + +#define Null 0 +#define true 1 +#define false 0 + +typedef int One_Thirty; +typedef int One_Fifty; +typedef char Capital_Letter; +typedef int Boolean; +typedef char Str_30 [31]; +typedef int Arr_1_Dim [50]; +typedef int Arr_2_Dim [50] [50]; + +typedef struct record { + struct record *Ptr_Comp; + Enumeration Discr; + union { + struct { + Enumeration Enum_Comp; + int Int_Comp; + char Str_Comp[31]; + } var_1; + struct { + Enumeration E_Comp_2; + char Str_2_Comp[31]; + } var_2; + struct { + char Ch_1_Comp; + char Ch_2_Comp; + } var_3; + } variant; +} Rec_Type, *Rec_Pointer; + +// #define NUMBER_OF_RUNS 500 /* Default number of runs */ +#define NUMBER_OF_RUNS 50000 + +/* Global Variables: */ +Rec_Pointer Ptr_Glob, Next_Ptr_Glob; +int Int_Glob; +Boolean Bool_Glob; +char Ch_1_Glob, Ch_2_Glob; +int Arr_1_Glob[50]; +int Arr_2_Glob[50][50]; + +/* Function Declarations */ +void Proc_1(Rec_Pointer Ptr_Val_Par); +void Proc_2(One_Fifty *Int_Par_Ref); +void Proc_3(Rec_Pointer *Ptr_Ref_Par); +void Proc_4(); +void Proc_5(); +void Proc_6(Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par); +void Proc_7(One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val, One_Fifty *Int_Par_Ref); +void Proc_8(Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, int Int_2_Par_Val); +Enumeration Func_1(Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val); +Boolean Func_2(Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref); +Boolean Func_3(Enumeration Enum_Par_Val); + +/* Main Program */ +int main(int argc, char **argv) { + One_Fifty Int_1_Loc; + One_Fifty Int_2_Loc; + One_Fifty Int_3_Loc; + char Ch_Index; + Enumeration Enum_Loc; + Str_30 Str_1_Loc; + Str_30 Str_2_Loc; + int Run_Index; + int Number_Of_Runs = NUMBER_OF_RUNS; + + /* Initializations */ + Next_Ptr_Glob = (Rec_Pointer) alloca(sizeof(Rec_Type)); + Ptr_Glob = (Rec_Pointer) alloca(sizeof(Rec_Type)); + + Ptr_Glob->Ptr_Comp = Next_Ptr_Glob; + Ptr_Glob->Discr = Ident_1; + Ptr_Glob->variant.var_1.Enum_Comp = Ident_3; + Ptr_Glob->variant.var_1.Int_Comp = 40; + strcpy(Ptr_Glob->variant.var_1.Str_Comp, "DHRYSTONE PROGRAM, SOME STRING"); + strcpy(Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING"); + + Arr_2_Glob[8][7] = 10; + + for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index) { + Proc_5(); + Proc_4(); + Int_1_Loc = 2; + Int_2_Loc = 3; + strcpy(Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING"); + Enum_Loc = Ident_2; + Bool_Glob = !Func_2(Str_1_Loc, Str_2_Loc); + while (Int_1_Loc < Int_2_Loc) { + Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc; + Proc_7(Int_1_Loc, Int_2_Loc, &Int_3_Loc); + Int_1_Loc += 1; + } + Proc_8(Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc); + Proc_1(Ptr_Glob); + for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index) { + if (Enum_Loc == Func_1(Ch_Index, 'C')) { + Proc_6(Ident_1, &Enum_Loc); + strcpy(Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING"); + Int_2_Loc = Run_Index; + Int_Glob = Run_Index; + } + } + Int_2_Loc = Int_2_Loc * Int_1_Loc; + Int_1_Loc = Int_2_Loc / Int_3_Loc; + Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc; + Proc_2(&Int_1_Loc); + } + + return 0; +} + +/* Define missing functions here */ +void Proc_1(Rec_Pointer Ptr_Val_Par) { + Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp; + structassign(*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob); + Ptr_Val_Par->variant.var_1.Int_Comp = 5; + Next_Record->variant.var_1.Int_Comp = Ptr_Val_Par->variant.var_1.Int_Comp; + Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp; + Proc_3(&Next_Record->Ptr_Comp); + if (Next_Record->Discr == Ident_1) { + Next_Record->variant.var_1.Int_Comp = 6; + Proc_6(Ptr_Val_Par->variant.var_1.Enum_Comp, &Next_Record->variant.var_1.Enum_Comp); + Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp; + Proc_7(Next_Record->variant.var_1.Int_Comp, 10, &Next_Record->variant.var_1.Int_Comp); + } else { + structassign(*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp); + } +} + +void Proc_2(One_Fifty *Int_Par_Ref) { + One_Fifty Int_Loc; + Enumeration Enum_Loc = Ident_2; + + Int_Loc = *Int_Par_Ref + 10; + do { + if (Ch_1_Glob == 'A') { + Int_Loc -= 1; + *Int_Par_Ref = Int_Loc - Int_Glob; + Enum_Loc = Ident_1; + } + } while (Enum_Loc != Ident_1); +} + +void Proc_3(Rec_Pointer *Ptr_Ref_Par) { + if (Ptr_Glob != Null) { + *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp; + } + Proc_7(10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp); +} + +void Proc_4() { + Boolean Bool_Loc; + + Bool_Loc = Ch_1_Glob == 'A'; + Bool_Glob = Bool_Loc | Bool_Glob; + Ch_2_Glob = 'B'; +} + +void Proc_5() { + Ch_1_Glob = 'A'; + Bool_Glob = false; +} + +void Proc_6(Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par) { + *Enum_Ref_Par = Enum_Val_Par; + if (!Func_3(Enum_Val_Par)) { + *Enum_Ref_Par = Ident_4; + } + switch (Enum_Val_Par) { + case Ident_1: + *Enum_Ref_Par = Ident_1; + break; + case Ident_2: + if (Int_Glob > 100) { + *Enum_Ref_Par = Ident_1; + } else { + *Enum_Ref_Par = Ident_4; + } + break; + case Ident_3: + *Enum_Ref_Par = Ident_2; + break; + case Ident_4: + break; + case Ident_5: + *Enum_Ref_Par = Ident_3; + break; + } +} + +void Proc_7(One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val, One_Fifty *Int_Par_Ref) { + One_Fifty Int_Loc; + + Int_Loc = Int_1_Par_Val + 2; + *Int_Par_Ref = Int_2_Par_Val + Int_Loc; +} + +void Proc_8(Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, int Int_2_Par_Val) { + One_Fifty Int_Index; + One_Fifty Int_Loc; + + Int_Loc = Int_1_Par_Val + 5; + Arr_1_Par_Ref[Int_Loc] = Int_2_Par_Val; + Arr_1_Par_Ref[Int_Loc + 1] = Arr_1_Par_Ref[Int_Loc]; + Arr_1_Par_Ref[Int_Loc + 30] = Int_Loc; + for (Int_Index = Int_Loc; Int_Index <= Int_Loc + 1; ++Int_Index) { + Arr_2_Par_Ref[Int_Loc][Int_Index] = Int_Loc; + } + Arr_2_Par_Ref[Int_Loc][Int_Loc - 1] += 1; + Arr_2_Par_Ref[Int_Loc + 20][Int_Loc] = Arr_1_Par_Ref[Int_Loc]; + Int_Glob = 5; +} + +Enumeration Func_1(Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val) { + Capital_Letter Ch_1_Loc; + Capital_Letter Ch_2_Loc; + + Ch_1_Loc = Ch_1_Par_Val; + Ch_2_Loc = Ch_1_Loc; + if (Ch_2_Loc != Ch_2_Par_Val) { + return (Ident_1); + } else { + Ch_1_Glob = Ch_1_Loc; + return (Ident_2); + } +} + +Boolean Func_2(Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref) { + One_Thirty Int_Loc; + Capital_Letter Ch_Loc; + + Int_Loc = 2; + while (Int_Loc <= 2) { + if (Func_1(Str_1_Par_Ref[Int_Loc], Str_2_Par_Ref[Int_Loc + 1]) == Ident_1) { + Ch_Loc = 'A'; + Int_Loc += 1; + } + } + if (Ch_Loc >= 'W' && Ch_Loc < 'Z') { + Int_Loc = 7; + } + if (Ch_Loc == 'R') { + return (true); + } else { + if (strcmp(Str_1_Par_Ref, Str_2_Par_Ref) > 0) { + Int_Loc += 7; + Int_Glob = Int_Loc; + return (true); + } else { + return (false); + } + } +} + +Boolean Func_3(Enumeration Enum_Par_Val) { + Enumeration Enum_Loc; + + Enum_Loc = Enum_Par_Val; + if (Enum_Loc == Ident_3) { + return (true); + } else { + return (false); + } +} diff --git a/dhrystone/init-sf.S b/dhrystone/init-sf.S new file mode 100644 index 0000000..428957a --- /dev/null +++ b/dhrystone/init-sf.S @@ -0,0 +1,17 @@ +.globl _start +.globl __errno +.align 4 + + +_start: +init: +.option push +.option norelax + la gp, __global_pointer$ +.option pop + call main; + call exit; + + +__errno: + .long 0 diff --git a/dhrystone/init.S b/dhrystone/init.S new file mode 100644 index 0000000..3ea5171 --- /dev/null +++ b/dhrystone/init.S @@ -0,0 +1,9 @@ +.globl _start +.align 2 + +_start: + +init: + nop + li sp, 5120 # 4096 (== 0x1000) for the code section plus another 1k for the data section + j main diff --git a/dhrystone/run.m b/dhrystone/run.m new file mode 100644 index 0000000..bd40b43 --- /dev/null +++ b/dhrystone/run.m @@ -0,0 +1,5 @@ +newnode riscv +sizemem 65536 +srecl "dhrystone-sf.sr" +run +on diff --git a/dhrystone/sail.ld b/dhrystone/sail.ld new file mode 100644 index 0000000..32b4d49 --- /dev/null +++ b/dhrystone/sail.ld @@ -0,0 +1,27 @@ +OUTPUT_FORMAT("elf32-littleriscv") +OUTPUT_ARCH(riscv) + +ENTRY(_start) + +SECTIONS +{ + . = 0x00; + .text . : + { + _text = . ; + *(.text) + . = 0x1000; + *(.strings) + _etext = . ; + } + + .data . : + { + *(.data) + } + + .bss . : + { + *(.bss) + } +}