├── .gitignore ├── README.md ├── asm ├── Makefile ├── boot_from_mem.s ├── boot_led.s ├── boot_serial.s ├── boot_sram.s └── serial.s ├── cpp ├── Makefile ├── bootloader.cpp ├── include │ ├── bootstrap.h │ ├── common.h │ ├── elf.h │ ├── exception.h │ ├── machine.h │ ├── memory_test.h │ ├── stdbool.h │ ├── stdint.h │ ├── stdio.h │ ├── stdlib.h │ ├── string.h │ ├── time.h │ └── trivial_mips.h ├── lib │ ├── Makefile │ ├── atob.c │ ├── getchar.c │ ├── machine.cpp │ ├── memory_test.cpp │ ├── newprintf.c │ ├── printbase.c │ ├── printf.c │ ├── printhex.c │ ├── putchar.c │ ├── puts.c │ ├── sprintf.c │ ├── sscanf.c │ ├── stdio.c │ ├── str_fmt.c │ ├── strcat.c │ ├── strcspn.c │ ├── strichr.c │ ├── string.c │ ├── strspn.c │ ├── strtok.c │ ├── strtoul.c │ ├── strtoupp.c │ ├── time.c │ ├── toupper.c │ ├── udelay.c │ └── vsprintf.c ├── mandelbrot.cpp ├── multi.cpp ├── print_1to100.cpp ├── test_memory.cpp ├── test_serial_gpio.cpp └── utility │ ├── linker.ld.S │ ├── main.c │ └── startup.S ├── func_test ├── Makefile ├── bin.lds.S ├── include │ ├── asm │ │ ├── asm.h │ │ ├── context.h │ │ └── regdef.h │ ├── common.h │ ├── cpu.h │ ├── inst_def.h │ ├── inst_delay_slot_def.h │ ├── inst_delay_slot_test.h │ ├── inst_ex_def.h │ ├── inst_ex_test.h │ └── inst_test.h ├── inst │ ├── Makefile │ ├── n10_sltiu.S │ ├── n11_div.S │ ├── n12_divu.S │ ├── n13_mult.S │ ├── n14_multu.S │ ├── n15_and.S │ ├── n16_andi.S │ ├── n17_lui.S │ ├── n18_nor.S │ ├── n19_or.S │ ├── n1_add.S │ ├── n20_ori.S │ ├── n21_xor.S │ ├── n22_xori.S │ ├── n23_sll.S │ ├── n24_sllv.S │ ├── n25_sra.S │ ├── n26_srav.S │ ├── n27_srl.S │ ├── n28_srlv.S │ ├── n29_beq.S │ ├── n2_addi.S │ ├── n30_bne.S │ ├── n31_bgez.S │ ├── n32_bgtz.S │ ├── n33_blez.S │ ├── n34_bltz.S │ ├── n35_bltzal.S │ ├── n36_bgezal.S │ ├── n37_j.S │ ├── n38_jal.S │ ├── n39_jr.S │ ├── n3_addu.S │ ├── n40_jalr.S │ ├── n41_mfhi.S │ ├── n42_mflo.S │ ├── n43_mthi.S │ ├── n44_mtlo.S │ ├── n45_break.S │ ├── n46_syscall.S │ ├── n47_lb.S │ ├── n48_lbu.S │ ├── n49_lh.S │ ├── n4_addiu.S │ ├── n50_lhu.S │ ├── n51_lw.S │ ├── n52_sb.S │ ├── n53_sh.S │ ├── n54_sw.S │ ├── n55_eret.S │ ├── n56_mfc0.S │ ├── n57_mtc0.S │ ├── n58_add_ex.S │ ├── n59_addi_ex.S │ ├── n5_sub.S │ ├── n60_sub_ex.S │ ├── n61_lh_ex.S │ ├── n62_lhu_ex.S │ ├── n63_lw_ex.S │ ├── n64_sh_ex.S │ ├── n65_sw_ex.S │ ├── n66_eret_ex.S │ ├── n67_reserved_instruction_ex.S │ ├── n68_beq_ds.S │ ├── n69_bne_ds.S │ ├── n6_subu.S │ ├── n70_bgez_ds.S │ ├── n71_bgtz_ds.S │ ├── n72_blez_ds.S │ ├── n73_bltz_ds.S │ ├── n74_bltzal_ds.S │ ├── n75_bgezal_ds.S │ ├── n76_j_ds.S │ ├── n77_jal_ds.S │ ├── n78_jr_ds.S │ ├── n79_jalr_ds.S │ ├── n7_slt.S │ ├── n80_beq_ex_ds.S │ ├── n81_bne_ex_ds.S │ ├── n82_bgez_ex_ds.S │ ├── n83_bgtz_ex_ds.S │ ├── n84_blez_ex_ds.S │ ├── n85_bltz_ex_ds.S │ ├── n86_bltzal_ex_ds.S │ ├── n87_bgezal_ex_ds.S │ ├── n88_j_ex_ds.S │ ├── n89_jal_ex_ds.S │ ├── n8_slti.S │ ├── n90_jr_ex_ds.S │ ├── n91_jalr_ex_ds.S │ ├── n92_tlbwi.S │ ├── n93_tlbwr.S │ └── n9_sltu.S ├── readme.md ├── rules.make └── start.S ├── perf_test ├── .gitignore ├── Makefile ├── README.md ├── bench │ ├── Makefile │ ├── bitcount │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── bitarray.c │ │ ├── bitcnt_1.c │ │ ├── bitcnt_2.c │ │ ├── bitcnt_3.c │ │ ├── bitcnt_4.c │ │ ├── bitcnts.c │ │ ├── bitops.h │ │ ├── bitstrng.c │ │ ├── bstr_i.c │ │ ├── conio.h │ │ ├── extkword.h │ │ ├── shell.c │ │ └── sniptype.h │ ├── bubble_sort │ │ ├── Makefile │ │ ├── bubble_sort.c │ │ └── shell.c │ ├── coremark │ │ ├── LICENSE.txt │ │ ├── Makefile │ │ ├── common_coremark.h │ │ ├── core_list_join.c │ │ ├── core_main.c │ │ ├── core_matrix.c │ │ ├── core_portme.c │ │ ├── core_portme.h │ │ ├── core_state.c │ │ ├── core_util.c │ │ ├── coremark.h │ │ └── shell.c │ ├── crc32 │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── crc.h │ │ ├── crc32.c │ │ ├── extra.c │ │ ├── shell.c │ │ └── sniptype.h │ ├── dhrystone │ │ ├── Makefile │ │ ├── dhry.h │ │ ├── dhry_1.c │ │ ├── dhry_2.c │ │ └── shell.c │ ├── quick_sort │ │ ├── Makefile │ │ ├── quick_sort.c │ │ └── shell.c │ ├── select_sort │ │ ├── Makefile │ │ ├── select_sort.c │ │ └── shell.c │ ├── sha │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── input_small.c │ │ ├── sha.c │ │ ├── sha.h │ │ ├── sha_driver.c │ │ └── shell.c │ ├── stream_copy │ │ ├── Makefile │ │ ├── shell.c │ │ └── stream_copy.c │ └── stringsearch │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── bmhasrch.c │ │ ├── bmhisrch.c │ │ ├── bmhsrch.c │ │ ├── pbmsrch_small.c │ │ ├── search.h │ │ └── shell.c ├── bin.lds.S ├── include │ ├── asm │ │ └── regdef.h │ ├── common.h │ ├── const.h │ ├── machine.h │ ├── stdio.h │ ├── stdlib.h │ ├── string.h │ └── time.h ├── lib │ ├── Makefile │ ├── atob.c │ ├── exception.c │ ├── getchar.c │ ├── guess.c │ ├── newprintf.c │ ├── now.c │ ├── printbase.c │ ├── printf.c │ ├── printhex.c │ ├── putchar.c │ ├── puts.c │ ├── rules.make │ ├── sprintf.c │ ├── sscanf.c │ ├── stdio.c │ ├── str_fmt.c │ ├── strcat.c │ ├── strchr.c │ ├── strcspn.c │ ├── strichr.c │ ├── string.c │ ├── strspn.c │ ├── strtok.c │ ├── strtoul.c │ ├── strtoupp.c │ ├── testchar.c │ ├── time.c │ ├── toupper.c │ ├── udelay.c │ └── vsprintf.c └── start.S └── utility ├── convert_bin.c ├── mem_to_coe.sh └── split_bin.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *.bin 2 | *.coe 3 | *.mif 4 | *.o 5 | *.a 6 | *.elf 7 | split_bin 8 | convert_bin 9 | obj/ 10 | func_test/bin.lds 11 | func_test/dump.s 12 | cpp/bootrom 13 | cpp/ram 14 | cpp/linker.*.ld 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Software for TrivialMIPS 2 | 3 | ## Structure 4 | 5 | The project contains source code that runs on board and tools/scripts that can be used to convert the source code to proper format: 6 | 7 | * `bootrom` folder contains programs that will be pre-initialized in bootrom, whose entry point is `0xBFC00000`. The output will be a `filename.coe` file, which can be used in the customization of Block RAM IP. 8 | * `ram` folder contains programs that are intened to be written to SRAM, whose entry point is `0x80000000`. By design, the final output of a program are two files: `filename.base.bin` and `filename.ext.bin`. You should write it to two slies of SRAM respectively by offset 0. The output of `bootrom/boot_from_mem.s` should be used in bootrom in order to jump to the entry point of SRAM. 9 | * `func_test` contains functional tests from Loongson 10 | * `perf_test` contains performance tests from Loongson 11 | 12 | ## Endianness 13 | 14 | > Endianness __MATTERS__! --Harry 15 | 16 | The CPU itself is little-endian, that is, the most significant byte is the one with the highest address. As for initialization files, `coe` and `mem` files put MSB on the leftmost side, so `0x12345678` will still be `12345678` in these files. For little-endian binary memory files, it will be `0x78 0x56 0x34 0x12`, and `xxd` will show it as `78563412`. The compiler and linker should be set in Big Endian mode (`-EL`) when compiling from assembly or C/C++ code. 17 | 18 | The converter from `bin` to `mem` we use does the following work on each line of the given file: 19 | 20 | * read 4 bytes (`0x78 0x56 0x34 0x12`) 21 | * write it out in reverse sequence (`12345678`) -------------------------------------------------------------------------------- /asm/Makefile: -------------------------------------------------------------------------------- 1 | SRCS=$(wildcard *.s) 2 | 3 | export CROSS_COMPILE ?= mipsel-linux-gnu- 4 | AS=${CROSS_COMPILE}as 5 | OBJCOPY=${CROSS_COMPILE}objcopy 6 | 7 | COES=$(SRCS:.s=.coe) 8 | BASES=$(SRCS:.s=.base.bin) 9 | EXTS=$(SRCS:.s=.ext.bin) 10 | 11 | all: bootrom ram 12 | 13 | bootrom: $(COES) 14 | 15 | ram: $(BASES) #$(EXTS) 16 | 17 | %.coe: %.bin convert_bin 18 | mkdir -p bootrom 19 | ./convert_bin $< bootrom/$@ 20 | 21 | %.base.bin: %.bin split_bin 22 | mkdir -p ram 23 | ./split_bin $< ram/$(basename $<).ext.bin ram/$(basename $<).base.bin 24 | 25 | %.ext.bin: %.base.bin 26 | 27 | %.bin: %.o 28 | $(OBJCOPY) -O binary -j .text -j .data -j .bss $< $@ 29 | 30 | %.o: %.s 31 | $(AS) -mips32 -EL $< -o $@ 32 | 33 | convert_bin: ../utility/convert_bin.c 34 | gcc -Wall -O2 -o $@ $< 35 | 36 | split_bin: ../utility/split_bin.cpp 37 | g++ -Wall -Werror -o $@ $< 38 | 39 | clean: 40 | rm -rf bootrom/ ram/ convert_bin split_bin 41 | -------------------------------------------------------------------------------- /asm/boot_from_mem.s: -------------------------------------------------------------------------------- 1 | .org 0x0 2 | .global _start 3 | .set noat 4 | _start: 5 | # enter normal mode 6 | mfc0 $4, $12 7 | la $3, 0x0fbfffff 8 | and $4, $4, $3 9 | mtc0 $4, $12 10 | 11 | lui $4, 0x8000 12 | jr $4 13 | nop 14 | 15 | -------------------------------------------------------------------------------- /asm/boot_led.s: -------------------------------------------------------------------------------- 1 | .org 0x0 2 | .global _start 3 | .set noat 4 | _start: 5 | lui $4, 0xbfc0 6 | lui $3, 0x8000 7 | lui $1, 0xa600 8 | lw $2, 0x0($1) 9 | or $2, $2, $3 10 | sw $2, 0x4($1) 11 | sw $2, 0x8($1) 12 | jr $4 13 | nop 14 | -------------------------------------------------------------------------------- /asm/boot_serial.s: -------------------------------------------------------------------------------- 1 | .org 0x0 2 | .global _start 3 | .set noat 4 | _start: 5 | # enable the hardware interrupt 0 6 | mfc0 $1, $12 7 | ori $1, $1, 0x0401 8 | mtc0 $1, $12 9 | 10 | # use the special interrupt vector 11 | mfc0 $1, $13 12 | lui $2, 0x0080 13 | or $1, $2, $1 14 | mtc0 $1, $13 15 | 16 | _wait_int: 17 | beq $0, $0, _wait_int 18 | nop 19 | 20 | .org 0x400 21 | lui $3, 0x8000 22 | lui $1, 0xa300 23 | lw $2, 0x04($1) 24 | sw $2, 0x00($3) 25 | sw $2, 0x04($1) 26 | ori $2, $0, 0x0000 27 | eret 28 | -------------------------------------------------------------------------------- /asm/boot_sram.s: -------------------------------------------------------------------------------- 1 | .org 0x0 2 | .global _start 3 | .set noat 4 | _start: 5 | lui $4, 0x8000 6 | ori $4, $4, 0x0100 7 | ori $1, 0x0001 8 | sw $1, 0x00($4) 9 | add $1, $1, $1 10 | sw $1, 0x04($4) 11 | add $1, $1, $1 12 | sw $1, 0x08($4) 13 | add $1, $1, $1 14 | sw $1, 0x0c($4) 15 | add $1, $1, $1 16 | sw $1, 0x10($4) 17 | lw $1, 0x00($4) 18 | lw $1, 0x04($4) 19 | lw $1, 0x08($4) 20 | lw $1, 0x0c($4) 21 | lw $1, 0x10($4) 22 | 23 | lui $4, 0x8000 24 | jr $4 25 | nop 26 | 27 | -------------------------------------------------------------------------------- /asm/serial.s: -------------------------------------------------------------------------------- 1 | .org 0x0 2 | .global _start 3 | .set noat 4 | _start: 5 | lui $7, 0xa300 # serial 6 | nop 7 | lui $8, 0x8000 # memory 8 | nop 9 | lui $9, 0xa600 # GPIO 10 | nop 11 | _wait_data: 12 | jr $8 13 | nop 14 | # lw $1, 0x00($7) 15 | # andi $1, 0x0002 16 | # beq $1, $0, _wait_data 17 | # nop 18 | # 19 | # lw $2, 0x04($7) 20 | # sw $2, 0x04($7) 21 | # or $2, $8, $2 22 | # sw $2, 0x04($9) 23 | # 24 | # beq $0, $0, _wait_data 25 | # nop 26 | -------------------------------------------------------------------------------- /cpp/Makefile: -------------------------------------------------------------------------------- 1 | SRCS=$(wildcard *.cpp) 2 | HEADERS=$(wildcard include/*.cpp) 3 | 4 | export CROSS_COMPILE ?= mipsel-linux-gnu- 5 | 6 | CC=${CROSS_COMPILE}gcc 7 | CXX=${CROSS_COMPILE}g++ 8 | LD=${CROSS_COMPILE}ld 9 | AR=${CROSS_COMPILE}ar 10 | OBJCOPY=${CROSS_COMPILE}objcopy 11 | OBJDUMP=${CROSS_COMPILE}objdump 12 | 13 | COES=$(SRCS:.cpp=.coe) 14 | ASM=$(SRCS:.cpp=.s) 15 | BASES=$(SRCS:.cpp=.base.bin) 16 | EXTS=$(SRCS:.cpp=.ext.bin) 17 | EXTS=$(SRCS:.cpp=.s) 18 | 19 | COMP_FLGAS=-msingle-float -nostdinc -nostdlib -ffunction-sections -fdata-sections -ffreestanding -Wall -mxgot -fno-builtin -fno-PIC -fno-PIE -mno-abicalls -g -EL -mhard-float -mips32 -Os -I include -include common.h -include bootstrap.h 20 | CXXFLAGS=$(COMP_FLGAS) -std=c++11 21 | CFLAGS=$(COMP_FLGAS) -Wno-implicit-function-declaration 22 | 23 | LDFLAGS=-static -EL -nostdlib --nmagic --gc-sections 24 | 25 | LINKDER_DEFS= 26 | 27 | export CC CXX AR CFLAGS CXXFLAGS 28 | 29 | all: bootrom sram 30 | 31 | .PHONY: main.o 32 | 33 | bootrom: $(COES) 34 | 35 | sram: $(BASES) #$(EXTS) 36 | 37 | %.coe: %.bootrom.bin convert_bin 38 | mkdir -p bootrom 39 | ./convert_bin $< bootrom/$@ 40 | 41 | %.base.bin: %.ram.bin split_bin 42 | ./split_bin $< ram/$(basename $(basename $<)).ext.bin ram/$(basename $(basename $<)).base.bin 43 | 44 | convert_bin: ../utility/convert_bin.c 45 | gcc -Wall -O2 -o $@ $< 46 | 47 | split_bin: ../utility/split_bin.cpp 48 | g++ -Wall -Werror -o $@ $< 49 | 50 | %.bootrom.bin: %.bootrom.elf 51 | $(OBJCOPY) -O binary -j .text $< $@ 52 | 53 | %.ram.bin: %.ram.elf 54 | $(OBJCOPY) -O binary -j .text -j .data $< $@ 55 | 56 | %.bootrom.elf: linker.bootrom.ld %.o startup.bootrom.o main.o lib/libtinyc.a 57 | mkdir -p bootrom 58 | $(LD) $(LDFLAGS) -T $< -o $@ $(filter-out $<,$^) 59 | $(OBJDUMP) -alDS $@ > bootrom/$(basename $(basename $@)).s 60 | 61 | %.ram.elf: linker.ram.ld %.o startup.ram.o main.o lib/libtinyc.a 62 | mkdir -p ram 63 | $(LD) $(LDFLAGS) -T $< -o $@ $(filter-out $<,$^) 64 | $(OBJDUMP) -alDS $@ > ram/$(basename $(basename $@)).s 65 | 66 | linker.bootrom.ld: utility/linker.ld.S $(HEADERS) 67 | $(CC) -E -P -DCODE_INTO_BOOTROM $(LINKDER_DEFS) $(CFLAGS) $< -o $@ 68 | 69 | linker.ram.ld: utility/linker.ld.S $(HEADERS) 70 | $(CC) -E -P $(LINKDER_DEFS) $(CFLAGS) $< -o $@ 71 | 72 | %.o: %.cpp $(HEADERS) 73 | $(CXX) $(CXXFLAGS) -c -o $@ $< 74 | 75 | main.o: utility/main.c 76 | $(CC) $(CFLAGS) -c -o $@ $< 77 | 78 | startup.ram.o: utility/startup.S 79 | $(CC) $(CFLAGS) -c -o $@ $< 80 | 81 | startup.bootrom.o: utility/startup.S 82 | $(CC) $(CFLAGS) -DCODE_INTO_BOOTROM -c -o $@ $< 83 | 84 | lib/libtinyc.a: 85 | make -C lib libtinyc.a 86 | 87 | clean: 88 | rm -rf ram/ bootrom/ *.ld *.o split_bin convert_bin 89 | make -C lib clean 90 | -------------------------------------------------------------------------------- /cpp/include/bootstrap.h: -------------------------------------------------------------------------------- 1 | #ifndef BOOTSTRAP_H 2 | #define BOOTSTRAP_H 3 | 4 | #ifndef __ASSEMBLER__ 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | int _entry(); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | 18 | #endif -------------------------------------------------------------------------------- /cpp/include/exception.h: -------------------------------------------------------------------------------- 1 | #ifndef __EXCEPTION_H__ 2 | #define __EXCEPTION_H__ 3 | 4 | #include 5 | 6 | __attribute__((section(".rodata"))) 7 | const char* EXCEPTION_MESSAGES[32] = { 8 | "Interrupt", 9 | "TLB modification exception", 10 | "TLB exception (load or instruction fetch)", 11 | "TLB exception (store)", 12 | "Address error exception (load or instruction fetch)", 13 | "Address error exception (store)", 14 | "Bus error exception (instruction fetch)", 15 | "Bus error exception (data reference: load or store)", 16 | "Syscall exception", 17 | "Breakpoint exception", 18 | "Reserved instruction exception", 19 | "Coprocessor Unusable exception", 20 | "Arithmetic Overflow exception", 21 | "Trap exception", 22 | "MSA Floating-Point exception", 23 | "Floating-Point exception", 24 | "", 25 | "", 26 | "", 27 | "TLB Read-Inhibit exception", 28 | "TLB Execution-Inhibit exception", 29 | "", 30 | "", 31 | "WATCH", 32 | "Machine check", 33 | "Thread Allocation, Deallocation, or Scheduling Exceptions", 34 | "", 35 | "", 36 | "", 37 | "", 38 | "Cache error", 39 | "" 40 | }; 41 | 42 | typedef struct { 43 | uint32_t padding[4]; 44 | uint32_t cp0_epc; 45 | uint32_t cp0_cause; 46 | uint32_t cp0_status; 47 | uint32_t cp0_badvaddr; 48 | uint32_t cp0_ebase; 49 | uint32_t gpr[32]; 50 | } trapframe_t; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /cpp/include/machine.h: -------------------------------------------------------------------------------- 1 | #ifndef __MACHINE_H_ 2 | #define __MACHINE_H_ 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | typedef uint8_t byte_t; 12 | typedef uint16_t hword_t; 13 | typedef uint32_t word_t; 14 | typedef uint64_t dword_t; 15 | 16 | #define TLB_COUNT 16 17 | 18 | #define CPU_COUNT_PER_US 1000 // tentative 19 | 20 | #define ADDR(addr) ((void*)addr) 21 | 22 | #define SWITCHES_ADDR ADDR(0xBFF0F020) 23 | #define LED_ADDR ADDR(0xBFF0F000) 24 | #define NUM_ADDR ADDR(0xBFF0F010) 25 | 26 | #define UART_DAT_ADDR ADDR(0xBFD03000) 27 | #define UART_FCR_ADDR ADDR(0xBFD03008) 28 | #define UART_LCR_ADDR ADDR(0xBFD0300C) 29 | #define UART_LSR_ADDR ADDR(0xBFD03014) 30 | #define UART_DLL_ADDR ADDR(0xBFD03000) 31 | #define UART_DLM_ADDR ADDR(0xBFD03004) 32 | #define UART_MCR_ADDR ADDR(0xBFD03010) 33 | #define UART_IER_ADDR ADDR(0xBFD03004) 34 | 35 | #define MEM_START_ADDR ADDR(0x80000000) 36 | #define MEM_END_ADDR ADDR(0x807FFFFF) 37 | #define FLASH_START_ADDR ADDR(0xBA800000) 38 | #define FLASH_END_ADDR ADDR(0xBAFFFFFF) 39 | #define OCM_START_ADDR ADDR(0x88000000) 40 | #define OCM_END_ADDR ADDR(0x8800FFFF) 41 | 42 | #define TIMER_CYCLE_ADDR ADDR(0xBFF0E000) 43 | #define TIMER_MICROSEC_ADDR ADDR(0xBFF0E000) 44 | 45 | #define UART_DATA_READY 2 46 | #define UART_CLEAR_TO_SEND 1 47 | 48 | #define panic() asm volatile("teq $zero, $zero") 49 | 50 | byte_t read_byte(void* addr); 51 | 52 | hword_t read_hword(void* addr); 53 | 54 | word_t read_word(void* addr); 55 | 56 | dword_t read_dword(void* addr); 57 | 58 | void write_byte(void* addr, byte_t data); 59 | 60 | void write_hword(void* addr, hword_t data); 61 | 62 | void write_word(void* addr, word_t data); 63 | 64 | void write_dword(void* addr, dword_t data); 65 | 66 | void init_serial(); 67 | 68 | byte_t read_serial(); 69 | 70 | void write_serial(byte_t data); 71 | 72 | word_t read_serial_word(); 73 | 74 | void write_led(hword_t data); 75 | 76 | void write_segment(word_t data); 77 | 78 | word_t read_switches(); 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /cpp/include/memory_test.h: -------------------------------------------------------------------------------- 1 | #ifndef __MEMORY_TEST_H__ 2 | #define __MEMORY_TEST_H__ 3 | 4 | #include 5 | 6 | word_t rand(word_t &rand_seed); 7 | 8 | bool test_memory(void* start, void* end); 9 | 10 | #endif -------------------------------------------------------------------------------- /cpp/include/stdbool.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. 2 | 3 | This file is part of GCC. 4 | 5 | GCC is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2, or (at your option) 8 | any later version. 9 | 10 | GCC is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with GCC; see the file COPYING. If not, write to 17 | the Free Software Foundation, 51 Franklin Street, Fifth Floor, 18 | Boston, MA 02110-1301, USA. */ 19 | 20 | /* As a special exception, if you include this header file into source 21 | files compiled by GCC, this header file does not by itself cause 22 | the resulting executable to be covered by the GNU General Public 23 | License. This exception does not however invalidate any other 24 | reasons why the executable file might be covered by the GNU General 25 | Public License. */ 26 | 27 | /* 28 | * ISO C Standard: 7.16 Boolean type and values 29 | */ 30 | 31 | #ifndef _STDBOOL_H 32 | #define _STDBOOL_H 33 | 34 | #ifndef __cplusplus 35 | 36 | #define bool _Bool 37 | #define true 1 38 | #define false 0 39 | 40 | #else /* __cplusplus */ 41 | 42 | /* Supporting in C++ is a GCC extension. */ 43 | #define _Bool bool 44 | #define bool bool 45 | #define false false 46 | #define true true 47 | 48 | #endif /* __cplusplus */ 49 | 50 | /* Signal that all the definitions are present. */ 51 | #define __bool_true_false_are_defined 1 52 | 53 | #endif /* stdbool.h */ 54 | -------------------------------------------------------------------------------- /cpp/include/stdint.h: -------------------------------------------------------------------------------- 1 | #ifndef __STDINT_H_ 2 | #define __STDINT_H_ 3 | 4 | typedef signed char int8_t; 5 | typedef short int int16_t; 6 | typedef int int32_t; 7 | typedef long int int64_t; 8 | 9 | typedef unsigned char uint8_t; 10 | typedef unsigned short int uint16_t; 11 | typedef unsigned int uint32_t; 12 | typedef unsigned long uint64_t; 13 | 14 | #endif -------------------------------------------------------------------------------- /cpp/include/stdio.h: -------------------------------------------------------------------------------- 1 | #ifndef STDIO_H 2 | #define STDIO_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | int puts(const char *s); 11 | int putstring(const char *s); // no newline 12 | int printf (const char *fmt, ...); 13 | int sprintf (char *buf, const char *fmt, ...); 14 | 15 | struct FILE{ 16 | char* str; 17 | size_t pos; 18 | }; 19 | 20 | typedef struct FILE FILE; 21 | #define EOF 0xFFFFFFFF 22 | 23 | FILE* fopen(char* str); 24 | size_t fread(void* ptr, size_t size, size_t nmemb, FILE* stream); 25 | void fclose(FILE* stream); 26 | char *fgets(char *s, int size, FILE *stream); 27 | int sscanf(const char *str, const char *fmt, ...); 28 | int getc(FILE* stream); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /cpp/include/stdlib.h: -------------------------------------------------------------------------------- 1 | #define NULL ((void *)0) 2 | -------------------------------------------------------------------------------- /cpp/include/string.h: -------------------------------------------------------------------------------- 1 | #ifndef STRING_H 2 | #define STRING_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | size_t strlen(const char *s); 9 | size_t strnlen(const char *s, size_t len); 10 | 11 | char *strcpy(char *dst, const char *src); 12 | char *strncpy(char *dst, const char *src, size_t len); 13 | 14 | int strcmp(const char *s1, const char *s2); 15 | int strncmp(const char *s1, const char *s2, size_t n); 16 | 17 | char *strchr(const char *s, char c); 18 | char *strfind(const char *s, char c); 19 | //long strtol(const char *s, char **endptr, int base); 20 | 21 | void *memset(void *s, char c, size_t n); 22 | void *memmove(void *dst, const void *src, size_t n); 23 | void *memcpy(void *dst, const void *src, size_t n); 24 | int memcmp(const void *v1, const void *v2, size_t n); 25 | 26 | void bzero(void *s, size_t n); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /cpp/include/time.h: -------------------------------------------------------------------------------- 1 | #ifndef _TIME_H_H 2 | #define _TIME_H_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | typedef unsigned long _clock_t; 9 | typedef unsigned long clock_t; 10 | #define MSEC_PER_SEC 1000L 11 | #define USEC_PER_MSEC 1000L 12 | #define NSEC_PER_USEC 1000L 13 | #define NSEC_PER_MECEC 1000000L 14 | #define USEC_PER_SEC 1000000L 15 | #define NSEC_PER_SEC 1000000000L 16 | #define FSEC_PER_SEC 1000000000000000LL 17 | 18 | struct tms{ 19 | _clock_t tms_utime; 20 | _clock_t tms_stime; 21 | _clock_t tms_cutime; 22 | _clock_t tms_cstime; 23 | }; 24 | 25 | struct tm{ 26 | int tm_sec; 27 | int tm_min; 28 | int tm_hour; 29 | int tm_mday; 30 | int tm_mon; 31 | int tm_year; 32 | int tm_wday; 33 | int tm_yday; 34 | }; 35 | 36 | struct timespec{ 37 | _clock_t tv_sec; 38 | _clock_t tv_nsec; 39 | _clock_t tv_usec; 40 | _clock_t tv_msec; 41 | }; 42 | 43 | struct timeval{ 44 | _clock_t tv_sec; 45 | _clock_t tv_nsec; 46 | _clock_t tv_usec; 47 | _clock_t tv_msec; 48 | }; 49 | 50 | unsigned get_count(); 51 | 52 | unsigned get_us(); 53 | 54 | unsigned long get_ns(); 55 | 56 | #define TIMER_BEGIN unsigned start_count = 0;\ 57 | unsigned stop_count = 0; \ 58 | unsigned total_count = 0; \ 59 | unsigned start_us = 0; \ 60 | unsigned stop_us = 0; \ 61 | unsigned total_us = 0; \ 62 | start_count = get_count(); \ 63 | start_us = get_us(); 64 | 65 | #define TIMER_END stop_count = get_count();\ 66 | stop_us = get_us(); \ 67 | total_count = stop_count - start_count; \ 68 | total_us = stop_us - start_us; \ 69 | 70 | #define TIMER_PRINT printf("Time: %u cycles, %u us", total_count, total_us); 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /cpp/include/trivial_mips.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __TRIVIAL_MIPS_H__ 3 | #define __TRIVIAL_MIPS_H__ 4 | 5 | // kept for compatibility 6 | 7 | #define SERIAL_ADDR 0xa3000000 8 | #define GPIO_ADDR 0xa6000000 9 | #define TIMER_ADDR 0xa4000000 10 | #define MEM_ADDR 0x80000000 11 | #define GRAPHICS_ADDR 0xa2000000 12 | #define LOAD_ENTRY(var, addr) \ 13 | volatile unsigned *const var = reinterpret_cast(addr) 14 | #define LOAD_SERIAL_ENTRY(var) LOAD_ENTRY(var, SERIAL_ADDR) 15 | #define LOAD_GPIO_ENTRY(var) LOAD_ENTRY(var, GPIO_ADDR) 16 | #define LOAD_MEMORY_ENTRY(var) \ 17 | unsigned char *const var = reinterpret_cast(MEM_ADDR) 18 | 19 | inline void send_serial_char(unsigned char c) 20 | { 21 | LOAD_SERIAL_ENTRY(serial_entry); 22 | while(!(serial_entry[0] & 1)); 23 | if(c) serial_entry[1] = c; 24 | } 25 | 26 | inline bool is_serial_ready_to_read() 27 | { 28 | LOAD_SERIAL_ENTRY(serial_entry); 29 | return serial_entry[0] & 2; 30 | } 31 | 32 | inline unsigned read_serial_char() 33 | { 34 | LOAD_SERIAL_ENTRY(serial_entry); 35 | while(!is_serial_ready_to_read()); 36 | return serial_entry[1]; 37 | } 38 | 39 | inline int read_serial_line(char *buf, char terminator='\0') 40 | { 41 | int num = 0; 42 | while((buf[num] = read_serial_char()) != terminator) ++num; 43 | buf[num] = 0; 44 | return num; 45 | } 46 | 47 | inline void send_serial_string(const char *str) 48 | { 49 | for(int i = 0; str[i]; ++i) 50 | send_serial_char(str[i]); 51 | } 52 | 53 | inline void send_serial_hex(unsigned v) 54 | { 55 | send_serial_char('0'); 56 | send_serial_char('x'); 57 | for(int i = 7; i >= 0; --i) 58 | { 59 | unsigned char c = (v >> (i << 2)) & 0xf; 60 | c = (c < 10) ? c + '0' : c + 'a' - 10; 61 | send_serial_char(c); 62 | } 63 | } 64 | 65 | 66 | inline void send_serial_integer_unsigned(unsigned v) 67 | { 68 | if (v != 0){ 69 | send_serial_integer_unsigned(v / 10); 70 | send_serial_char((v % 10) + '0'); 71 | } 72 | } 73 | 74 | 75 | inline void send_serial_integer(int v) 76 | { 77 | if(v < 0) { 78 | send_serial_char('-'); 79 | send_serial_integer_unsigned(-v); 80 | } else if(v > 0) { 81 | send_serial_integer_unsigned(v); 82 | } else { 83 | send_serial_char('0'); 84 | } 85 | } 86 | 87 | 88 | namespace __impl 89 | { 90 | template struct unsigned_sequence { }; 91 | 92 | template 93 | struct maker { 94 | typedef typename maker::type type; 95 | }; 96 | 97 | template 98 | struct maker<0, I...> { 99 | typedef unsigned_sequence type; 100 | }; 101 | 102 | template 103 | inline void send_serial_str_unpack(unsigned char a, Pack... pack) 104 | { 105 | send_serial_char(a); 106 | send_serial_str_unpack(pack...); 107 | } 108 | 109 | template<> 110 | inline void send_serial_str_unpack(unsigned char a) 111 | { 112 | send_serial_char(a); 113 | } 114 | 115 | template 116 | inline void send_serial_str_arr(const char (&str)[N], unsigned_sequence) 117 | { 118 | send_serial_str_unpack(str[I]...); 119 | } 120 | } 121 | 122 | /* send a literal string without using memory to store it */ 123 | template 124 | inline void send_serial_str(const char (&str)[N]) 125 | { 126 | typedef typename __impl::maker::type type; 127 | __impl::send_serial_str_arr(str, type{}); 128 | } 129 | 130 | inline unsigned get_switches() 131 | { 132 | LOAD_GPIO_ENTRY(gpio_entry); 133 | return gpio_entry[0]; 134 | } 135 | 136 | inline void set_segment_displays(unsigned char v) 137 | { 138 | LOAD_GPIO_ENTRY(gpio_entry); 139 | gpio_entry[1] = static_cast(v) | 0x80000000u; 140 | } 141 | 142 | inline void set_leds(unsigned short v) 143 | { 144 | LOAD_GPIO_ENTRY(gpio_entry); 145 | gpio_entry[2] = static_cast(v); 146 | } 147 | 148 | #endif 149 | -------------------------------------------------------------------------------- /cpp/lib/Makefile: -------------------------------------------------------------------------------- 1 | SRCS=$(wildcard *.c) 2 | SRCS_CPP=$(wildcard *.cpp) 3 | OBJS=$(SRCS:.c=.o) 4 | OBJS_CPP=$(SRCS_CPP:.cpp=.o) 5 | 6 | libtinyc.a: $(OBJS) $(OBJS_CPP) 7 | $(AR) -cr $@ $^ 8 | 9 | clean: 10 | rm -f *.o *.a *.s 11 | 12 | %.o: %.c 13 | $(CC) $(CFLAGS) -I ../include -c -o $@ $< 14 | 15 | %.o: %.cpp 16 | $(CXX) $(CXXFLAGS) -I ../include -c -o $@ $< -------------------------------------------------------------------------------- /cpp/lib/getchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int getchar() 4 | { 5 | return read_serial(); 6 | } -------------------------------------------------------------------------------- /cpp/lib/machine.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | template 4 | T read(void *addr){ 5 | auto *ptr = reinterpret_cast(addr); 6 | return *ptr; 7 | } 8 | 9 | template 10 | void write(void *addr, T data){ 11 | auto *ptr = reinterpret_cast(addr); 12 | *ptr = data; 13 | } 14 | 15 | #define GENERATE_READ_FUNC(TYPE) TYPE##_t read_##TYPE(void* addr){ \ 16 | return read(addr); \ 17 | } 18 | 19 | #define GENERATE_WRITE_FUNC(TYPE) void write_##TYPE(void* addr, TYPE##_t data){ \ 20 | write(addr, data); \ 21 | } 22 | 23 | #define RUN_FOR_ALL_TYPE(FUNC) FUNC(byte) \ 24 | FUNC(hword) \ 25 | FUNC(word) \ 26 | FUNC(dword) 27 | 28 | RUN_FOR_ALL_TYPE(GENERATE_READ_FUNC) 29 | RUN_FOR_ALL_TYPE(GENERATE_WRITE_FUNC) 30 | 31 | void init_serial() { 32 | // Enable 8 bytes receive FIFO 33 | write_byte(UART_FCR_ADDR, 0x81); 34 | // enable DLAB latch 35 | write_byte(UART_LCR_ADDR, 0x80); 36 | // set the speed to 115200 37 | write_byte(UART_DLL_ADDR, 0x36); 38 | write_byte(UART_DLM_ADDR, 0x0); 39 | // 8 data bits, 1 stop bit, parity off; turn off DLAB latch 40 | write_byte(UART_LCR_ADDR, ~0x80 & 0x03); 41 | // disable modem controls 42 | write_byte(UART_MCR_ADDR, 0); 43 | // disable interrupts 44 | write_byte(UART_IER_ADDR, 0); 45 | } 46 | 47 | byte_t read_serial(){ 48 | while (!(read_byte(UART_LSR_ADDR) & 0x01)); 49 | return read_byte(UART_DAT_ADDR); 50 | } 51 | 52 | void write_serial(byte_t data){ 53 | while (!(read_byte(UART_LSR_ADDR) & 0x40)); 54 | write_byte(UART_DAT_ADDR, data); 55 | } 56 | 57 | word_t read_serial_word(){ 58 | word_t word = 0; 59 | word |= read_serial(); 60 | word |= read_serial() << 8; 61 | word |= read_serial() << 16; 62 | word |= read_serial() << 24; 63 | return word; 64 | } 65 | 66 | void write_led(hword_t data){ 67 | write_hword(LED_ADDR, data); 68 | } 69 | 70 | void write_segment(word_t data){ 71 | write_word(NUM_ADDR, data); 72 | } 73 | 74 | word_t read_switches(){ 75 | return read_word(SWITCHES_ADDR); 76 | } 77 | -------------------------------------------------------------------------------- /cpp/lib/memory_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | word_t rand(word_t &rand_seed) { 5 | return rand_seed = (rand_seed * 16807L) % ((1u << 31) - 1); 6 | } 7 | 8 | template 9 | bool do_test_memory(void* _start, void* _end) { 10 | word_t rand_seed; 11 | 12 | auto *start = reinterpret_cast(_start); 13 | auto *end = reinterpret_cast(_end); 14 | 15 | auto size = (uint32_t) _end - (uint32_t) _start; 16 | 17 | auto *mem = start; 18 | 19 | rand_seed = 23; 20 | 21 | while(mem < end) { 22 | *mem = rand(rand_seed); 23 | mem++; 24 | } 25 | 26 | mem = start; 27 | 28 | rand_seed = 23; 29 | 30 | while(mem < end) { 31 | // print progress every 1MB 32 | if ((uint32_t) mem % 0x100000 == 0) { 33 | write_segment((uint32_t) mem); 34 | } 35 | auto next = rand(rand_seed); 36 | auto read = *mem; 37 | if (read != static_cast(next)) { 38 | printf("Error at 0x%p: expect 0x%p, got 0x%p\n", mem, next, read); 39 | return false; 40 | } 41 | mem++; 42 | } 43 | 44 | return true; 45 | } 46 | 47 | bool test_memory(void* start, void* end){ 48 | 49 | printf("Starting memory test from 0x%p to 0x%p.\n", start, end); 50 | 51 | putstring("Testing memory by word..."); 52 | if (!do_test_memory(start, end)) return false; 53 | puts("OK!"); 54 | 55 | putstring("Testing memory by half word..."); 56 | if (!do_test_memory(start, end)) return false; 57 | puts("OK!"); 58 | 59 | putstring("Testing memory by byte..."); 60 | if (!do_test_memory(start, end)) return false; 61 | puts("OK!"); 62 | 63 | return true; 64 | } -------------------------------------------------------------------------------- /cpp/lib/newprintf.c: -------------------------------------------------------------------------------- 1 | int newprintf(const char *fmt, ...) 2 | { 3 | int len; 4 | va_list ap; 5 | char buf[1024]; 6 | 7 | va_start(ap, fmt); 8 | len = vsprintf(buf, fmt, ap); 9 | va_end(ap); 10 | putstring(buf); 11 | return (len); 12 | } 13 | -------------------------------------------------------------------------------- /cpp/lib/printbase.c: -------------------------------------------------------------------------------- 1 | int printbase(long v,int w,int base,int sign) 2 | { 3 | int i,j; 4 | int c; 5 | char buf[64]; 6 | unsigned long value; 7 | if(sign && v<0) 8 | { 9 | value = -v; 10 | putchar('-'); 11 | } 12 | else value=v; 13 | 14 | for(i=0;value;i++) 15 | { 16 | buf[i]=value%base; 17 | value=value/base; 18 | } 19 | 20 | #define max(a,b) (((a)>(b))?(a):(b)) 21 | 22 | for(j=max(w,i);j>0;j--) 23 | { 24 | c=j>i?0:buf[j-1]; 25 | putchar((c<=9)?c+'0':c-0xa+'a'); 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /cpp/lib/printf.c: -------------------------------------------------------------------------------- 1 | int printf(const char *fmt, ...) 2 | { 3 | int i; 4 | char c; 5 | void **arg; 6 | void *ap; 7 | int w; 8 | __builtin_va_start(ap, fmt); 9 | arg = ap; 10 | for (i = 0; fmt[i]; i++) 11 | { 12 | c = fmt[i]; 13 | if (c == '%') 14 | { 15 | w = 1; 16 | again: 17 | switch (fmt[i + 1]) 18 | { 19 | case 's': 20 | putstring(*arg); 21 | arg++; 22 | i++; 23 | break; 24 | case 'c': 25 | putchar((long)*arg); 26 | arg++; 27 | i++; 28 | break; 29 | case 'u': 30 | printbase((long)*arg, w, 10, 0); 31 | arg++; 32 | i++; 33 | break; 34 | case 'd': 35 | printbase((long)*arg, w, 10, 1); 36 | arg++; 37 | i++; 38 | break; 39 | case 'l': 40 | printbase((long)*arg, w, 10, 0); 41 | arg++; 42 | i = i + 2; 43 | break; 44 | case 'o': 45 | printbase((long)*arg, w, 8, 0); 46 | arg++; 47 | i++; 48 | break; 49 | case 'b': 50 | printbase((long)*arg, w, 2, 0); 51 | arg++; 52 | i++; 53 | break; 54 | case 'p': 55 | case 'x': 56 | printbase((long)*arg, w, 16, 0); 57 | arg++; 58 | i++; 59 | break; 60 | case '%': 61 | putchar('%'); 62 | i++; 63 | break; 64 | case '0': 65 | i++; 66 | case '1' ... '9': 67 | for (w = 0; fmt[i + 1] > '0' && fmt[i + 1] <= '9'; i++) 68 | w = w * 10 + (fmt[i + 1] - '0'); 69 | goto again; 70 | break; 71 | 72 | default: 73 | putchar('%'); 74 | break; 75 | } 76 | } 77 | else 78 | { 79 | if (c == '\n') 80 | putchar('\r'); 81 | putchar(c); 82 | } 83 | } 84 | return 0; 85 | } 86 | -------------------------------------------------------------------------------- /cpp/lib/printhex.c: -------------------------------------------------------------------------------- 1 | int printhex(long v,int w) 2 | { 3 | int i; 4 | int c; 5 | for(i=4*(w-1);i>=0;i-=4) 6 | { 7 | c=(v>>i)&0xf; 8 | putchar((c<=9)?c+'0':c-0xa+'a'); 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /cpp/lib/putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int putchar(int c) 4 | { 5 | write_serial((byte_t) c); 6 | return c; 7 | } -------------------------------------------------------------------------------- /cpp/lib/puts.c: -------------------------------------------------------------------------------- 1 | int putstring(const char *s) 2 | { 3 | char c; 4 | while ((c = *s)) 5 | { 6 | if (c == '\n') 7 | putchar('\r'); 8 | putchar(c); 9 | s++; 10 | } 11 | return 0; 12 | } 13 | 14 | int puts(const char *s) 15 | { 16 | putstring(s); 17 | putchar('\r'); 18 | putchar('\n'); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /cpp/lib/sprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sprintf(buf,fmt,va_alist) send formatted string to buf 3 | */ 4 | int sprintf(char *buf, const char *fmt, ...) 5 | { 6 | int n; 7 | va_list ap; 8 | 9 | va_start(ap, fmt); 10 | n = vsprintf(buf, fmt, ap); 11 | va_end(ap); 12 | return (n); 13 | } 14 | int snprintf(char *buf, size_t maxlen, const char *fmt, ...) 15 | { 16 | int n; 17 | va_list ap; 18 | 19 | va_start(ap, fmt); 20 | n = vsprintf(buf, fmt, ap); 21 | va_end(ap); 22 | return (n); 23 | } 24 | -------------------------------------------------------------------------------- /cpp/lib/stdio.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define SIZE 10 5 | FILE files[SIZE] = {0}; 6 | /* 7 | 8 | FILE* fopen(char* str){ 9 | FILE* file = &dummy; 10 | while(file->next != NULL){ 11 | file = file->next; 12 | } 13 | file->next = malloc(sizeof(*file)); 14 | file->next->str = str; 15 | file->next->pos = 0; 16 | file->next->next = NULL; 17 | return file->next; 18 | } 19 | */ 20 | FILE* fopen(char* str){ 21 | int i; 22 | for(i=0;istr; 35 | size_t total = strlen(str); 36 | if(stream->pos == total){ 37 | return 0; 38 | } 39 | size_t c = 0; 40 | for(c=0;cpos++]; 42 | if(stream->pos == total){ 43 | break; 44 | } 45 | } 46 | return c; 47 | } 48 | 49 | /* 50 | void fclose(FILE* stream){ 51 | FILE* file = &dummy; 52 | while(file->next != stream){ 53 | file = file->next; 54 | } 55 | FILE* tmp = file->next; 56 | file->next = tmp->next; 57 | free(tmp); 58 | } 59 | */ 60 | 61 | void fclose(FILE* stream){ 62 | int i; 63 | for(i=0;istr = NULL; 69 | stream->pos = 0; 70 | } 71 | 72 | char *fgets(char *s, int size, FILE *stream){ 73 | char* str = stream->str; 74 | size_t total = strlen(str); 75 | size_t c = 0; 76 | char* r = NULL; 77 | while(stream->pos != total){ 78 | if(str[stream->pos] == '\n'){ 79 | s[c++] = str[stream->pos++]; 80 | break; 81 | }else{ 82 | s[c++] = str[stream->pos++]; 83 | } 84 | } 85 | return r; 86 | } 87 | 88 | int getc(FILE* stream){ 89 | char* str = stream->str; 90 | size_t total = strlen(str); 91 | if(stream->pos == total){ 92 | return EOF; 93 | }else{ 94 | return (unsigned char)str[stream->pos++]; 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /cpp/lib/str_fmt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Format string by inserting blanks. 3 | */ 4 | 5 | void str_fmt(char *p, int size, int fmt) 6 | { 7 | int n, m, len; 8 | 9 | len = strlen(p); 10 | switch (fmt) 11 | { 12 | case FMT_RJUST: 13 | for (n = size - len; n > 0; n--) 14 | strichr(p, ' '); 15 | break; 16 | case FMT_LJUST: 17 | for (m = size - len; m > 0; m--) 18 | strcat(p, " "); 19 | break; 20 | case FMT_RJUST0: 21 | for (n = size - len; n > 0; n--) 22 | strichr(p, '0'); 23 | break; 24 | case FMT_CENTER: 25 | m = (size - len) / 2; 26 | n = size - (len + m); 27 | for (; m > 0; m--) 28 | strcat(p, " "); 29 | for (; n > 0; n--) 30 | strichr(p, ' '); 31 | break; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /cpp/lib/strcat.c: -------------------------------------------------------------------------------- 1 | /* $Id: strcat.c,v 1.1.1.1 2006/09/14 01:59:06 root Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2000-2002 Opsycon AB (www.opsycon.se) 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. All advertising materials mentioning features or use of this software 15 | * must display the following acknowledgement: 16 | * This product includes software developed by Opsycon AB. 17 | * 4. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 21 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | * 32 | */ 33 | 34 | char * 35 | strcat(char *dst, const char *src) 36 | { 37 | char *d; 38 | 39 | if (!dst || !src) 40 | return (dst); 41 | 42 | d = dst; 43 | for (; *d; d++); 44 | for (; *src; src++) 45 | *d++ = *src; 46 | *d = 0; 47 | return (dst); 48 | } 49 | -------------------------------------------------------------------------------- /cpp/lib/strcspn.c: -------------------------------------------------------------------------------- 1 | /* $Id: strcspn.c,v 1.1.1.1 2006/09/14 01:59:06 root Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2000-2002 Opsycon AB (www.opsycon.se) 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. All advertising materials mentioning features or use of this software 15 | * must display the following acknowledgement: 16 | * This product includes software developed by Opsycon AB. 17 | * 4. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 21 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | * 32 | */ 33 | 34 | int 35 | strcspn (const char *p, const char *s) 36 | { 37 | int i, j; 38 | 39 | for (i = 0; p[i]; i++) { 40 | for (j = 0; s[j]; j++) { 41 | if (s[j] == p[i]) 42 | break; 43 | } 44 | if (s[j]) 45 | break; 46 | } 47 | return (i); 48 | } 49 | -------------------------------------------------------------------------------- /cpp/lib/strichr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char * 4 | strichr(char *p, int c) 5 | { 6 | char *t; 7 | 8 | if (p != NULL) { 9 | for(t = p; *t; t++); 10 | for (; t >= p; t--) { 11 | *(t + 1) = *t; 12 | } 13 | *p = c; 14 | } 15 | return (p); 16 | } 17 | -------------------------------------------------------------------------------- /cpp/lib/strspn.c: -------------------------------------------------------------------------------- 1 | /* $Id: strspn.c,v 1.1.1.1 2006/09/14 01:59:06 root Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2000-2002 Opsycon AB (www.opsycon.se) 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. All advertising materials mentioning features or use of this software 15 | * must display the following acknowledgement: 16 | * This product includes software developed by Opsycon AB. 17 | * 4. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 21 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | * 32 | */ 33 | 34 | /* return length of initial segment of p that consists entirely of 35 | * characters from s */ 36 | 37 | int 38 | strspn(const char *p, const char *s) 39 | { 40 | int i, j; 41 | 42 | for (i = 0; p[i]; i++) { 43 | for (j = 0; s[j]; j++) { 44 | if (s[j] == p[i]) 45 | break; 46 | } 47 | if (!s[j]) 48 | break; 49 | } 50 | return (i); 51 | } 52 | -------------------------------------------------------------------------------- /cpp/lib/strtok.c: -------------------------------------------------------------------------------- 1 | /* $Id: strtok.c,v 1.1.1.1 2006/09/14 01:59:06 root Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2000-2002 Opsycon AB (www.opsycon.se) 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. All advertising materials mentioning features or use of this software 15 | * must display the following acknowledgement: 16 | * This product includes software developed by Opsycon AB. 17 | * 4. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 21 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | * 32 | */ 33 | 34 | char * 35 | strtok(char *p, const char *tok) 36 | { 37 | static char *t; /* XXX */ 38 | char *r; 39 | int n; 40 | 41 | if (p) 42 | t = p; 43 | 44 | r = t + strspn (t, tok); 45 | if (!(n = strcspn (r, tok))) 46 | return (0); 47 | t = r + n; 48 | if (*t) 49 | *t++ = 0; 50 | return (r); 51 | } 52 | -------------------------------------------------------------------------------- /cpp/lib/strtoul.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ULONG_MAX 4294967295UL 4 | #define LONG_MAX 2147483647L 5 | #define LONG_MIN (-LONG_MAX-1) 6 | #define isspace(c) (c==0x20) 7 | #define isdigit(c) (((c) >= '0') && ((c) <= '9')) 8 | #define isalpha(c) ( (((c) >= 'A') && ((c) <= 'Z')) || \ 9 | (((c) >= 'a') && ((c) <= 'z')) ) 10 | #define isupper(c) (c>='A' && c<='Z') 11 | 12 | unsigned long 13 | strtoul(const char *nptr,char **endptr,int base) 14 | { 15 | int c; 16 | unsigned long result = 0L; 17 | unsigned long limit; 18 | int negative = 0; 19 | int overflow = 0; 20 | int digit; 21 | 22 | while ((c = *nptr) && isspace(c)) /* skip leading white space */ 23 | nptr++; 24 | 25 | if ((c = *nptr) == '+' || c == '-') { /* handle signs */ 26 | negative = (c == '-'); 27 | nptr++; 28 | } 29 | 30 | if (base == 0) { /* determine base if unknown */ 31 | base = 10; 32 | if (*nptr == '0') { 33 | base = 8; 34 | nptr++; 35 | if ((c = *nptr) == 'x' || c == 'X') { 36 | base = 16; 37 | nptr++; 38 | } 39 | } 40 | } else if (base == 16 && *nptr == '0') { 41 | /* discard 0x/0X prefix if hex */ 42 | nptr++; 43 | if ((c = *nptr == 'x') || c == 'X') 44 | nptr++; 45 | } 46 | 47 | limit = ULONG_MAX / base; /* ensure no overflow */ 48 | 49 | nptr--; /* convert the number */ 50 | while ((c = *++nptr) != 0) { 51 | if (isdigit(c)) 52 | digit = c - '0'; 53 | else if(isalpha(c)) 54 | digit = c - (isupper(c) ? 'A' : 'a') + 10; 55 | else 56 | break; 57 | if (digit < 0 || digit >= base) 58 | break; 59 | if (result > limit) 60 | overflow = 1; 61 | if (!overflow) { 62 | result = base * result; 63 | if (digit > ULONG_MAX - result) 64 | overflow = 1; 65 | else 66 | result += digit; 67 | } 68 | } 69 | if (negative && !overflow) /* BIZARRE, but ANSI says we should do this! */ 70 | result = 0L - result; 71 | if (overflow) { 72 | //extern int errno; 73 | //errno = ERANGE; 74 | result = ULONG_MAX; 75 | } 76 | 77 | if (endptr != NULL) /* point at tail */ 78 | *endptr = (char *)nptr; 79 | return result; 80 | } 81 | 82 | -------------------------------------------------------------------------------- /cpp/lib/strtoupp.c: -------------------------------------------------------------------------------- 1 | void 2 | strtoupper(char *p) 3 | { 4 | if(!p) 5 | return; 6 | for (; *p; p++) 7 | *p = toupper (*p); 8 | } 9 | -------------------------------------------------------------------------------- /cpp/lib/time.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | unsigned get_count() 5 | { 6 | return read_word(TIMER_CYCLE_ADDR); 7 | } 8 | 9 | unsigned long clock_gettime(int sel, struct timespec *tmp) 10 | { 11 | unsigned long n = 0; 12 | n = _get_count(); 13 | tmp->tv_nsec = n * (2 * NSEC_PER_USEC / CPU_COUNT_PER_US) % NSEC_PER_USEC; 14 | tmp->tv_usec = (n / CPU_COUNT_PER_US * 2) % USEC_PER_MSEC; 15 | tmp->tv_msec = (n / CPU_COUNT_PER_US * 2 / USEC_PER_MSEC) % MSEC_PER_SEC; 16 | tmp->tv_sec = n / CPU_COUNT_PER_US * 2 / NSEC_PER_SEC; 17 | printf("clock ns=%d,sec=%d\n", tmp->tv_nsec, tmp->tv_sec); 18 | return 0; 19 | } 20 | 21 | unsigned long get_clock() 22 | { 23 | unsigned long n = 0; 24 | n = _get_count(); 25 | return 2 * n; 26 | } 27 | 28 | unsigned get_us() 29 | { 30 | return read_word(TIMER_MICROSEC_ADDR); 31 | } 32 | 33 | unsigned long get_ns() 34 | { 35 | return get_us() * 1000L; 36 | } 37 | -------------------------------------------------------------------------------- /cpp/lib/toupper.c: -------------------------------------------------------------------------------- 1 | int toupper(int c) 2 | { 3 | if (c >= 'a' && c <= 'z') 4 | return c - 'a' + 'A'; 5 | else 6 | return c; 7 | } 8 | -------------------------------------------------------------------------------- /cpp/lib/udelay.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void udelay(int us) 5 | { 6 | unsigned start = get_us(); 7 | unsigned end; 8 | do 9 | { 10 | end = get_us(); 11 | } while (end - start < us); 12 | } 13 | -------------------------------------------------------------------------------- /cpp/mandelbrot.cpp: -------------------------------------------------------------------------------- 1 | #include "trivial_mips.h" 2 | 3 | int _entry() 4 | { 5 | int w = 800, h = 600, x, y; 6 | //each iteration, it calculates: newz = oldz*oldz + p, where p is the current pixel, and oldz stars at the origin 7 | float pr, pi; //real and imaginary part of the pixel p 8 | float newRe, newIm, oldRe, oldIm; //real and imaginary parts of new and old z 9 | float zoom = 1, moveX = -0.5, moveY = 0; //you can change these to zoom and change position 10 | int maxIterations = 255; //after how much iterations the function should stop 11 | 12 | char *gmem = reinterpret_cast(GRAPHICS_ADDR); 13 | 14 | //loop through every pixel 15 | for(y = 0; y < h; y++) 16 | { 17 | for(x = 0; x < w; x++) 18 | { 19 | // calculate the initial real and imaginary part of z, based on the pixel location and zoom and position values 20 | pr = 1.5f * (x - w / 2) / (0.5f * zoom * w) + moveX; 21 | pi = (y - h / 2) / (0.5f * zoom * h) + moveY; 22 | newRe = newIm = oldRe = oldIm = 0; //these should start at 0,0 23 | //"i" will represent the number of iterations 24 | int i; 25 | //start the iteration process 26 | for(i = 0; i < maxIterations; i++) 27 | { 28 | //remember value of previous iteration 29 | oldRe = newRe; 30 | oldIm = newIm; 31 | //the actual iteration, the real and imaginary part are calculated 32 | newRe = oldRe * oldRe - oldIm * oldIm + pr; 33 | newIm = 2.0f * oldRe * oldIm + pi; 34 | //if the point is outside the circle with radius 2: stop 35 | if((newRe * newRe + newIm * newIm) > 4) break; 36 | } 37 | 38 | int color = i * 255 / maxIterations; 39 | 40 | gmem[w * y + x] = (color << 5) | (color << 2) | (color >> 1); 41 | } 42 | } 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /cpp/multi.cpp: -------------------------------------------------------------------------------- 1 | #include "trivial_mips.h" 2 | 3 | int _entry() 4 | { 5 | char A[3000], B[3000]; 6 | int C[6000]; 7 | for(auto &x : C) x = 0; 8 | send_serial_str("Ready to read!\n"); 9 | send_serial_str("Please input two numbers, end with '.'\n"); 10 | int la = read_serial_line(A, '.'); 11 | 12 | send_serial_str("A = "); 13 | send_serial_string(A); 14 | send_serial_char('\n'); 15 | int lb = read_serial_line(B, '.'); 16 | send_serial_str("B = "); 17 | send_serial_string(B); 18 | send_serial_char('\n'); 19 | 20 | LOAD_ENTRY(timer, TIMER_ADDR); 21 | 22 | unsigned start = timer[0]; 23 | 24 | const int TIMES = 100; 25 | 26 | int lc = la + lb; 27 | 28 | for (int n = 0; n < TIMES; ++n) { 29 | for(int k = 0; k < lc; ++k) { 30 | int v = 0; 31 | for(int i = 0; i < la; ++i) { 32 | if(0 <= k - i && k - i < lb) { 33 | v += (A[la - i - 1] - '0') * (B[lb - (k - i) - 1] - '0'); 34 | } 35 | } 36 | C[k] = v; 37 | } 38 | 39 | for(int i = 0; i != lc; ++i) { 40 | if(C[i] > 10){ 41 | C[i + 1] += C[i] / 10; 42 | C[i] %= 10; 43 | } 44 | } 45 | } 46 | 47 | unsigned end = timer[0]; 48 | unsigned total = end - start; 49 | unsigned average = total / TIMES; 50 | 51 | send_serial_str("Start time = "); 52 | send_serial_integer(start); 53 | send_serial_str(" us"); 54 | send_serial_char('\n'); 55 | send_serial_str("End time = "); 56 | send_serial_integer(end); 57 | send_serial_str(" us"); 58 | send_serial_char('\n'); 59 | send_serial_str("Elapsed time = "); 60 | send_serial_integer(total); 61 | send_serial_str(" us"); 62 | send_serial_char('\n'); 63 | send_serial_str("Execution times = "); 64 | send_serial_integer(TIMES); 65 | send_serial_char('\n'); 66 | send_serial_str("Average elapsed time = "); 67 | send_serial_integer(average); 68 | send_serial_str(" us"); 69 | send_serial_char('\n'); 70 | 71 | send_serial_str("A * B = "); 72 | for(int i = lc - 1; i >= 0; --i) 73 | if(i != lc - 1 || C[i]) 74 | send_serial_char(C[i] + '0'); 75 | send_serial_char('\n'); 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /cpp/print_1to100.cpp: -------------------------------------------------------------------------------- 1 | #include "trivial_mips.h" 2 | 3 | int _entry() 4 | { 5 | LOAD_MEMORY_ENTRY(mem); 6 | for(int i = 0; i != 100; ++i) 7 | mem[i + 0x1000] = i; 8 | for(int i = 0; i != 100; ++i) 9 | { 10 | send_serial_integer(mem[i + 0x1000]); 11 | send_serial_char('\n'); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /cpp/test_memory.cpp: -------------------------------------------------------------------------------- 1 | #include "trivial_mips.h" 2 | 3 | inline unsigned rand(unsigned &rand_seed) 4 | { 5 | return rand_seed = (rand_seed * 16807L) % ((1u << 31) - 1); 6 | } 7 | 8 | template 9 | inline void test() 10 | { 11 | unsigned rand_seed; 12 | 13 | volatile Type* mem = reinterpret_cast(MEM_ADDR); 14 | 15 | rand_seed = 23; 16 | for(int i = 0; i != 8 * 1024 * 1024 / sizeof(Type); ++i) 17 | mem[i] = rand(rand_seed); 18 | 19 | rand_seed = 23; 20 | for(int i = 0; i != 8 * 1024 * 1024 / sizeof(Type); ++i) 21 | if(mem[i] != static_cast(rand(rand_seed))) 22 | { 23 | send_serial_str("Error at "); 24 | send_serial_hex(MEM_ADDR + i * sizeof(Type)); 25 | send_serial_str("\n"); 26 | break; 27 | } 28 | } 29 | 30 | int _entry() 31 | { 32 | send_serial_str("Testing memory by word!\n"); 33 | test(); 34 | send_serial_str("OK!\n"); 35 | send_serial_str("Testing memory by short!\n"); 36 | test(); 37 | send_serial_str("OK!\n"); 38 | send_serial_str("Testing memory by byte!\n"); 39 | test(); 40 | send_serial_str("OK!\n"); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /cpp/test_serial_gpio.cpp: -------------------------------------------------------------------------------- 1 | #include "trivial_mips.h" 2 | 3 | int _entry() 4 | { 5 | send_serial_str("Hello MIPS!\n"); 6 | //send_serial_str("This is a message sent by code compiled from C++!\n"); 7 | register unsigned now_val = 0, count = 0; 8 | while(1) 9 | { 10 | if(now_val != get_switches()) 11 | { 12 | set_segment_displays(++count); 13 | send_serial_str("Switch changed: [Hex] "); 14 | send_serial_hex(now_val = get_switches()); 15 | send_serial_str(", [Dec] "); 16 | send_serial_integer(now_val); 17 | send_serial_char('\n'); 18 | } 19 | 20 | if(is_serial_ready_to_read()) 21 | { 22 | send_serial_str("Received: "); 23 | send_serial_hex(read_serial_char()); 24 | send_serial_char('\n'); 25 | } 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /cpp/utility/linker.ld.S: -------------------------------------------------------------------------------- 1 | ENTRY(_start); 2 | 3 | MEMORY 4 | { 5 | BOOTROM (rx) : ORIGIN = 0xBFC00000, LENGTH = 128K 6 | OCM (rwx) : ORIGIN = 0x88000000, LENGTH = 64K 7 | RAM (rwx) : ORIGIN = 0x80000000, LENGTH = 128M 8 | } 9 | 10 | #ifdef CODE_INTO_BOOTROM 11 | #define TEXT_AREA BOOTROM 12 | #define DATA_AREA OCM 13 | #else 14 | #define TEXT_AREA OCM 15 | #define DATA_AREA RAM 16 | #endif 17 | 18 | SECTIONS 19 | { 20 | . = ORIGIN(TEXT_AREA); 21 | 22 | _mem_start = ORIGIN(DATA_AREA); 23 | _mem_end = ORIGIN(DATA_AREA) + LENGTH(DATA_AREA); 24 | 25 | #ifdef CODE_INTO_BOOTROM 26 | _mem_avail_start = ORIGIN(RAM); 27 | _mem_avail_end = ORIGIN(RAM) + LENGTH(RAM); 28 | #else 29 | _mem_avail_start = _stack; 30 | _mem_avail_end = ORIGIN(RAM) + LENGTH(RAM); 31 | #endif 32 | 33 | .text : 34 | { 35 | _text = .; 36 | *(.text.startup) 37 | *(.text*) 38 | *(.rodata*) 39 | *(.reginfo) 40 | *(.init) 41 | *(.stub) 42 | *(.gnu.warning) 43 | *(.MIPS.abiflags) 44 | _text_end = .; 45 | } > TEXT_AREA 46 | 47 | .data : 48 | { 49 | _data = .; 50 | _stack = _data + LENGTH(DATA_AREA) - 32; 51 | *(.data) 52 | *(.data*) 53 | *(.eh_frame) 54 | _gp = ALIGN(16); 55 | *(.got.plt) *(.got) 56 | *(.sdata) 57 | *(.lit8) 58 | *(.lit4) 59 | _data_end = .; 60 | } > DATA_AREA 61 | 62 | .sbss : 63 | { 64 | *(.sbss) 65 | *(.scommon) 66 | } > DATA_AREA 67 | 68 | .bss : 69 | { 70 | _bss = .; 71 | *(.dynbss) 72 | *(.bss*) 73 | *(COMMON) 74 | _bss_end = .; 75 | } > DATA_AREA 76 | 77 | /DISCARD/ : 78 | { 79 | *(.note*); 80 | *(.iplt*); 81 | *(.igot*); 82 | *(.rel*); 83 | *(.comment); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /cpp/utility/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | extern byte_t _bss, _bss_end; 7 | 8 | #define DO_CONCAT(A, B) A#B 9 | #define CONCAT(A, B) DO_CONCAT(A, B) 10 | 11 | void _main() { 12 | 13 | init_serial(); 14 | 15 | write_segment(0x04); 16 | 17 | puts("*****TrivialMIPS Bare Metal System*****"); 18 | 19 | puts("Compilation time: " __TIME__ " " __DATE__); 20 | 21 | write_segment(0x05); 22 | 23 | // clear bss section if needed 24 | auto bss_size = (uint32_t) &_bss_end - (uint32_t) &_bss; 25 | if (bss_size > 0) { 26 | printf("Filling .bss section with 0, offset: 0x%x, size: %d bytes.\n", &_bss, bss_size); 27 | memset(&_bss, 0, bss_size); 28 | } 29 | 30 | write_segment(0x06); 31 | 32 | // call the actual function 33 | int result = _entry(); 34 | if (result == 0) { 35 | puts("Program exited normally."); 36 | } else { 37 | printf("Program exited abnormally with code %d.\n", result); 38 | } 39 | 40 | write_segment(0x07); 41 | 42 | } 43 | 44 | word_t _get_epc() { 45 | word_t n; 46 | asm( 47 | "mfc0 %0, $14\n\t" 48 | :"=r"(n) 49 | ); 50 | return n; 51 | } 52 | 53 | word_t _get_cause() { 54 | word_t n; 55 | asm( 56 | "mfc0 %0, $13\n\t" 57 | :"=r"(n) 58 | ); 59 | return n; 60 | } 61 | 62 | void print_trapframe(trapframe_t *tf) { 63 | for(int i = 1; i < 32; ++i) { 64 | printf("Register $%d: %p\n", i, tf->gpr[i]); 65 | } 66 | printf("EPC: %p, Cause: %p, Status: %p, BadVAddr: %p, EBase: %p\n", tf->cp0_epc, tf->cp0_cause, tf->cp0_status, tf->cp0_badvaddr, tf->cp0_ebase); 67 | } 68 | 69 | void print_tlb() { 70 | for (uint8_t i = 0; i < TLB_COUNT; ++i) { 71 | uint32_t entry_hi, entry_lo_1, entry_lo_2; 72 | asm volatile( 73 | "mtc0 %3, $0, 0\n" 74 | "tlbr\n" 75 | "mfc0 %0, $10, 0\n" 76 | "mfc0 %1, $2, 0\n" 77 | "mfc0 %2, $3, 0\n" 78 | :"=r"(entry_hi), "=r"(entry_lo_1), "=r"(entry_lo_2) 79 | :"r"(i) 80 | ); 81 | printf("TLB item %d: EntryHi %p, EntryLo1: %p, EntryLo2: %p\n", i, entry_hi, entry_lo_1, entry_lo_2); 82 | } 83 | } 84 | 85 | void _exception_handler(trapframe_t *tf, bool assertion) { 86 | puts("*****TrivialMIPS Bare Metal System*****"); 87 | if (assertion) { 88 | puts("CPU internal assertion failed, abort."); 89 | write_segment(0xdeaddead); 90 | } else { 91 | word_t code = (_get_cause() >> 2) & 0xF; 92 | auto epc = _get_epc(); 93 | printf("An exception occurred, with EPC 0x%x and Cause %d (%s).\n", epc, code, EXCEPTION_MESSAGES[code]); 94 | write_led((uint16_t) epc); 95 | } 96 | print_trapframe(tf); 97 | print_tlb(); 98 | puts("*****System HANG*****"); 99 | } 100 | -------------------------------------------------------------------------------- /cpp/utility/startup.S: -------------------------------------------------------------------------------- 1 | .globl _start 2 | .section .text.startup 3 | .set noreorder 4 | 5 | .org 0x0 6 | _start: 7 | # write the segment to indicate boot progress 8 | li $s2, 0xbff0f010 9 | li $t3, 0x00000001 10 | sw $t3, 0($s2) 11 | 12 | #ifndef CODE_INTO_BOOTROM 13 | # setup exception handler 14 | # la $t1, _text 15 | mtc0 $zero, $15, 1 # set c0_ebase to 0 16 | mtc0 $zero, $12 # use ebase and disable interrupts 17 | #endif 18 | 19 | # progress: 2 20 | li $t3, 0x00000002 21 | sw $t3, 0($s2) 22 | 23 | # setup stack pointer 24 | la $sp, _stack 25 | la $gp, _gp 26 | 27 | # progress: 3 28 | li $t3, 0x00000003 29 | sw $t3, 0($s2) 30 | 31 | # jump to our code 32 | jal _main 33 | nop 34 | 35 | _loop: 36 | li $t3, 0x00000000 37 | _loop_body: 38 | li $s1, 0xbff0e000 # $s1 = 0xbfd0e0000 (100 MHz Clock) 39 | lw $t1, 0($s1) # $t1 = time 40 | li $t2, 0x02faf080 # $t2 = 0x02faf080 (50000000) 41 | add $t0, $t1, $t2 # $t0 = $t1 + 0.5s 42 | 43 | _wait: 44 | lw $t1, 0($s1) 45 | beq $t0, $t1, _switch_led_status 46 | nop 47 | b _wait 48 | nop 49 | 50 | _switch_led_status: 51 | li $s2, 0xbff0f010 # write 0xbfd0f010 (numbers) 52 | nor $t3, $t3, $t3 # $t3 = ~$t3 53 | sw $t3, 0($s2) 54 | b _loop_body 55 | nop 56 | 57 | 58 | #ifdef CODE_INTO_BOOTROM 59 | .org 0x180 60 | _cpu_assertion: 61 | li $k0, 0x1 62 | j _exception_entry 63 | #endif 64 | 65 | 66 | #ifdef CODE_INTO_BOOTROM 67 | .org 0x380 68 | #else 69 | .org 0x180 70 | #endif 71 | 72 | _exception: 73 | li $k0, 0x0 74 | _exception_entry: 75 | move $k1, $s0 # save old sp 76 | la $sp, _exception_stack_top # switch to exception stack 77 | addiu $sp, $sp, -200 78 | 79 | # save general registers 80 | sw $ra, 160($sp) 81 | sw $fp, 156($sp) 82 | sw $k1, 152($sp) # k1 = old sp 83 | sw $gp, 148($sp) 84 | sw $k1, 144($sp) # real k1 is damaged 85 | sw $k0, 140($sp) # real k0 is damaged 86 | sw $t9, 136($sp) 87 | sw $t8, 132($sp) 88 | sw $s7, 128($sp) 89 | sw $s6, 124($sp) 90 | sw $s5, 120($sp) 91 | sw $s4, 116($sp) 92 | sw $s3, 112($sp) 93 | sw $s2, 108($sp) 94 | sw $s1, 104($sp) 95 | sw $s0, 100($sp) 96 | sw $t7, 96($sp) 97 | sw $t6, 92($sp) 98 | sw $t5, 88($sp) 99 | sw $t4, 84($sp) 100 | sw $t3, 80($sp) 101 | sw $t2, 76($sp) 102 | sw $t1, 72($sp) 103 | sw $t0, 68($sp) 104 | sw $a3, 64($sp) 105 | sw $a2, 60($sp) 106 | sw $a1, 56($sp) 107 | sw $a0, 52($sp) 108 | sw $v1, 48($sp) 109 | sw $v0, 44($sp) 110 | sw $at, 40($sp) 111 | # save cp0 112 | mfc0 $t1, $15, 1 # EBase 113 | sw $t1, 32($sp) 114 | mfc0 $t1, $8, 0 # BadVAddr 115 | sw $t1, 28($sp) 116 | mfc0 $t1, $12, 0 # Status 117 | sw $t1, 24($sp) 118 | mfc0 $t1, $13, 0 # Cause 119 | sw $t1, 20($sp) 120 | mfc0 $t1, $14, 0 # EPC 121 | sw $t1, 16($sp) 122 | 123 | move $a0, $sp 124 | move $a1, $k0 125 | 126 | jal _exception_handler 127 | nop 128 | j _loop 129 | nop 130 | 131 | 132 | .section .bss.exception 133 | .align 12 134 | _exception_stack: 135 | .space 1024 * 4 # 4KB for exception stack 136 | _exception_stack_top: 137 | -------------------------------------------------------------------------------- /func_test/Makefile: -------------------------------------------------------------------------------- 1 | ver = test_hw 2 | #ver = sim 3 | 4 | TOPDIR=$(shell pwd | sed 's: :\\ :g') 5 | 6 | export LD_PRELOAD = 7 | CFLAGS := -D_KERNEL -DCONFIG_PAGE_SIZE_16KB -fno-builtin -mips32 -DCACHELOCK_MEM -DMEMSTART=0x80000000 -DMEMSIZE=0x0200000 -DCPU_COUNT_PER_US=10 -I $(TOPDIR)/include -include common.h -DAPB_CLK=33333333 8 | CFLAGS += -DLS1FSOC -DCPU_MULT=6 -DDDR_MULT=6 $(ALIGNED) 9 | #CFLAGS += -fno-reorder-blocks -fno-reorder-funcions 10 | 11 | ifeq ($(ver), sim) 12 | CFLAGS += -DSIM 13 | endif 14 | 15 | 16 | export TOPDIR AR CFLAGS 17 | 18 | export CROSS_COMPILE ?= mipsel-linux-gnu- 19 | 20 | all: main.base.bin main.ext.bin dump.s 21 | 22 | main.base.bin: main.bin split_bin 23 | ./split_bin main.bin main.ext.bin main.base.bin 24 | 25 | main.ext.bin: main.bin 26 | 27 | libinst.a: 28 | make -C inst $(TOPDIR)/$@ 29 | 30 | dump.s: main.elf 31 | ${CROSS_COMPILE}objdump -alD $< > $@ 32 | 33 | main.elf: start.o libinst.a bin.lds 34 | ${CROSS_COMPILE}ld -g -T bin.lds -o $@ start.o -L . -linst 35 | 36 | bin.lds: bin.lds.S 37 | ${CROSS_COMPILE}gcc -E -P -Umips -D_LOADER -U_MAIN $(CFLAGS) bin.lds.S -o bin.lds 38 | 39 | main.bin:main.elf 40 | ${CROSS_COMPILE}objcopy -O binary -j .text -j .data $< $@ 41 | 42 | split_bin: ../utility/split_bin.cpp 43 | g++ -std=c++11 -Wall -Werror -O2 -o $@ $< 44 | 45 | clean: 46 | rm -f *.o *.bin *.elf *.a *.s bin.lds split_bin 47 | make -C inst clean 48 | 49 | -include rules.make 50 | -------------------------------------------------------------------------------- /func_test/bin.lds.S: -------------------------------------------------------------------------------- 1 | OUTPUT_ARCH(mips) 2 | ENTRY(_start) 3 | SECTIONS 4 | { 5 | . = MEMSTART; 6 | .text : 7 | { 8 | *(.text) 9 | *(.rodata*) 10 | *(.reginfo) 11 | *(.init) 12 | *(.stub) 13 | *(.gnu.warning) 14 | *(.MIPS.abiflags) 15 | . = ALIGN(0x1000); 16 | *(.text.ebase) 17 | rodata_end = .; 18 | } =0 19 | 20 | .data : AT(rodata_end) 21 | { 22 | *(.got.plt) *(.got) 23 | *(.sdata) 24 | *(.lit8) 25 | *(.lit4) 26 | } 27 | 28 | /DISCARD/ : 29 | { 30 | *(.debug*); 31 | *(.note*); 32 | *(.iplt*); 33 | *(.igot*); 34 | *(.rel*); 35 | *(.comment); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /func_test/include/asm/regdef.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: regdef.h,v 1.3 1999/01/27 04:46:06 imp Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 1992, 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * This code is derived from software contributed to Berkeley by 8 | * Ralph Campbell. This file is derived from the MIPS RISC 9 | * Architecture book by Gerry Kane. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. All advertising materials mentioning features or use of this software 20 | * must display the following acknowledgement: 21 | * This product includes software developed by the University of 22 | * California, Berkeley and its contributors. 23 | * 4. Neither the name of the University nor the names of its contributors 24 | * may be used to endorse or promote products derived from this software 25 | * without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 | * SUCH DAMAGE. 38 | * 39 | * @(#)regdef.h 8.1 (Berkeley) 6/10/93 40 | */ 41 | #ifndef _MIPS_REGDEF_H_ 42 | #define _MIPS_REGDEF_H_ 43 | 44 | #define zero $0 /* always zero */ 45 | #define AT $at /* assembler temp */ 46 | #define v0 $2 /* return value */ 47 | #define v1 $3 48 | #define a0 $4 /* argument registers */ 49 | #define a1 $5 50 | #define a2 $6 51 | #define a3 $7 52 | #define t0 $8 /* temp registers (not saved across subroutine calls) */ 53 | #define t1 $9 54 | #define t2 $10 55 | #define t3 $11 56 | #define t4 $12 57 | #define t5 $13 58 | #define t6 $14 59 | #define t7 $15 60 | #define s0 $16 /* saved across subroutine calls (callee saved) */ 61 | #define s1 $17 62 | #define s2 $18 63 | #define s3 $19 64 | #define s4 $20 65 | #define s5 $21 66 | #define s6 $22 67 | #define s7 $23 68 | #define t8 $24 /* two more temp registers */ 69 | #define t9 $25 70 | #define k0 $26 /* kernel temporary */ 71 | #define k1 $27 72 | #define gp $28 /* global pointer */ 73 | #define sp $29 /* stack pointer */ 74 | #define s8 $30 /* one more callee saved */ 75 | #define ra $31 /* return address */ 76 | #define fp $30 77 | 78 | #define c0_index $0 79 | #define c0_random $1 80 | #define c0_entrylo0 $2 81 | #define c0_entrylo1 $3 82 | #define c0_conf $3 83 | #define c0_context $4 84 | #define c0_pagemask $5 85 | #define c0_wired $6 86 | #define c0_info $7 87 | #define c0_badvaddr $8 88 | #define c0_count $9 89 | #define c0_entryhi $10 90 | #define c0_compare $11 91 | #define c0_status $12 92 | #define c0_cause $13 93 | #define c0_epc $14 94 | #define c0_prid $15 95 | #define c0_ebase $15, 1 96 | #define c0_config $16 97 | #define c0_lladdr $17 98 | #define c0_watchlo $18 99 | #define c0_watchhi $19 100 | #define c0_xcontext $20 101 | #define c0_framemask $21 102 | #define c0_diagnostic $22 103 | #define c0_debug $23 104 | #define c0_depc $24 105 | #define c0_performance $25 106 | #define c0_ecc $26 107 | #define c0_cacheerr $27 108 | #define c0_taglo $28 109 | #define c0_taghi $29 110 | #define c0_errorepc $30 111 | #define c0_desave $31 112 | 113 | 114 | #endif /* !_MIPS_REGDEF_H_ */ 115 | -------------------------------------------------------------------------------- /func_test/include/cpu.h: -------------------------------------------------------------------------------- 1 | #ifndef __CPU_H_ 2 | #define __CPU_H_ 3 | #define SR_BOOT_EXC_VEC 0x00400000 4 | #define PG_SIZE_4K 0x00000000 5 | #endif 6 | -------------------------------------------------------------------------------- /func_test/include/inst_ex_def.h: -------------------------------------------------------------------------------- 1 | // file name: inst_ex_def.h 2 | 3 | /* 58 4 | * ADD_EX(v_s0, v0, v1) 5 | */ 6 | #define ADD_EX(v_s0, v0, v1) \ 7 | li s0, v_s0; \ 8 | li t0, v0; \ 9 | li t1, v1; \ 10 | add s0, t0, t1 11 | 12 | /* 59 13 | * ADDI_EX(v_s0, v0, v1) 14 | */ 15 | #define ADDI_EX(v_s0, v0, v1) \ 16 | li s0, v_s0; \ 17 | li t0, v0; \ 18 | li t1, v1; \ 19 | addi s0, t0, v1 20 | 21 | /* 60 22 | * SUB_EX(v_s0, v0, v1) 23 | */ 24 | #define SUB_EX(v_s0, v0, v1) \ 25 | li s0, v_s0; \ 26 | li t0, v0; \ 27 | li t1, v1; \ 28 | sub s0, t0, t1 29 | 30 | /* 61 31 | * LH_EX(v_s0, data, base_addr, offset, offset_align) 32 | */ 33 | #define LH_EX(v_s0, data, base_addr, offset, offset_align) \ 34 | li s0, v_s0; \ 35 | li t1, data; \ 36 | li t0, base_addr; \ 37 | li t2, offset; \ 38 | li t4, offset_align; \ 39 | sw t1, offset_align(t0); \ 40 | lh s0, offset(t0); \ 41 | mfc0 s5, c0_badvaddr 42 | 43 | /* 62 44 | * LHU_EX(v_s0, data, base_addr, offset, offset_align) 45 | */ 46 | #define LHU_EX(v_s0, data, base_addr, offset, offset_align) \ 47 | li s0, v_s0; \ 48 | li t1, data; \ 49 | li t0, base_addr; \ 50 | li t2, offset; \ 51 | li t4, offset_align; \ 52 | sw t1, offset_align(t0); \ 53 | lhu s0, offset(t0); \ 54 | mfc0 s5, c0_badvaddr 55 | 56 | /* 63 57 | * LW_EX(v_s0, data, base_addr, offset, offset_align) 58 | */ 59 | #define LW_EX(v_s0, data, base_addr, offset, offset_align) \ 60 | li s0, v_s0; \ 61 | li t1, data; \ 62 | li t0, base_addr; \ 63 | li t2, offset; \ 64 | li t4, offset_align; \ 65 | sw t1, offset_align(t0); \ 66 | lw s0, offset(t0); \ 67 | mfc0 s5, c0_badvaddr 68 | 69 | /* 64 70 | * SH_EX(v_s0, data_init, data, base_addr, offset, offset_align) 71 | */ 72 | #define SH_EX(v_s0, data_init, data, base_addr, offset, offset_align) \ 73 | li s0, v_s0; \ 74 | li t1, data; \ 75 | li t0, base_addr; \ 76 | li t2, offset; \ 77 | li t4, offset_align; \ 78 | li t5, data_init; \ 79 | sw t5, offset_align(t0); \ 80 | sh t1, offset(t0); \ 81 | lw s0, offset_align(t0); \ 82 | mfc0 s5, c0_badvaddr 83 | 84 | /* 65 85 | * SW_EX(v_s0, data_init, data, base_addr, offset, offset_align) 86 | */ 87 | #define SW_EX(v_s0, data_init, data, base_addr, offset, offset_align) \ 88 | li s0, v_s0; \ 89 | li t1, data; \ 90 | li t0, base_addr; \ 91 | li t2, offset; \ 92 | li t4, offset_align; \ 93 | li t5, data_init; \ 94 | sw t5, offset_align(t0); \ 95 | sw t1, offset(t0); \ 96 | lw s0, offset_align(t0); \ 97 | mfc0 s5, c0_badvaddr 98 | 99 | /* 66 100 | * ERET_EX(unalign_pc) 101 | */ 102 | #define ERET_EX(unalign_pc) \ 103 | li v0, 0x7; \ 104 | li t0, unalign_pc; \ 105 | la k1, 1234f; \ 106 | mtc0 t0, c0_epc; \ 107 | 1234:; \ 108 | .set mips32; \ 109 | eret; \ 110 | .set mips1; \ 111 | mfc0 s0, c0_badvaddr 112 | 113 | /* 67 114 | * RESERVED_INSTRUCTION_EX(reserved_instruction) 115 | */ 116 | #define RESERVED_INSTRUCTION_EX(reserved_instruction) \ 117 | .word reserved_instruction 118 | -------------------------------------------------------------------------------- /func_test/include/inst_ex_test.h: -------------------------------------------------------------------------------- 1 | // file name: inst_ex_test.h 2 | #include 3 | 4 | /* 58 5 | * TEST_ADD_EX(v_s0, vs, vt, vd) 6 | */ 7 | #define TEST_ADD_EX(v_s0, vs, vt, vd) \ 8 | li v0, 0x04; \ 9 | ADD_EX(v_s0, vs, vt); \ 10 | li s2, vd; \ 11 | bne s0, s2, inst_error; \ 12 | nop; \ 13 | lui s2, 0x1234; \ 14 | bne v0, s2, inst_error; \ 15 | nop 16 | 17 | /* 59 18 | * TEST_ADDI_EX(v_s0, vs, vt, vd) 19 | */ 20 | #define TEST_ADDI_EX(v_s0, vs, vt, vd) \ 21 | li v0, 0x04; \ 22 | ADDI_EX(v_s0, vs, vt); \ 23 | li s2, vd; \ 24 | bne s0, s2, inst_error; \ 25 | nop; \ 26 | lui s2, 0x1234; \ 27 | bne v0, s2, inst_error; \ 28 | nop 29 | 30 | /* 60 31 | * TEST_SUB_EX(v_s0, vs, vt, vd) 32 | */ 33 | #define TEST_SUB_EX(v_s0, vs, vt, vd) \ 34 | li v0, 0x04; \ 35 | SUB_EX(v_s0, vs, vt); \ 36 | li s2, vd; \ 37 | bne s0, s2, inst_error; \ 38 | nop; \ 39 | lui s2, 0x1234; \ 40 | bne v0, s2, inst_error; \ 41 | nop 42 | 43 | /* 61 44 | * TEST_LH_EX(v_s0, data, base_addr, offset, offset_align, vd, badvaddr) 45 | */ 46 | #define TEST_LH_EX(v_s0, data, base_addr, offset, offset_align, vd, badvaddr) \ 47 | li v0, 0x05; \ 48 | LH_EX(v_s0, data, base_addr, offset, offset_align); \ 49 | li s2, vd; \ 50 | bne s0, s2, inst_error; \ 51 | nop; \ 52 | lui s2, 0x5678; \ 53 | bne v0, s2, inst_error; \ 54 | nop; \ 55 | li s6, badvaddr; \ 56 | bne s5, s6, inst_error; \ 57 | nop 58 | 59 | /* 62 60 | * TEST_LHU_EX(v_s0, data, base_addr, offset, offset_align, vd, badvaddr) 61 | */ 62 | #define TEST_LHU_EX(v_s0, data, base_addr, offset, offset_align, vd, badvaddr) \ 63 | li v0, 0x05; \ 64 | LHU_EX(v_s0, data, base_addr, offset, offset_align); \ 65 | li s2, vd; \ 66 | bne s0, s2, inst_error; \ 67 | nop; \ 68 | lui s2, 0x5678; \ 69 | bne v0, s2, inst_error; \ 70 | nop; \ 71 | li s6, badvaddr; \ 72 | bne s5, s6, inst_error; \ 73 | nop 74 | 75 | /* 63 76 | * TEST_LW_EX(v_s0, data, base_addr, offset, offset_align, vd, badvaddr) 77 | */ 78 | #define TEST_LW_EX(v_s0, data, base_addr, offset, offset_align, vd, badvaddr) \ 79 | li v0, 0x05; \ 80 | LW_EX(v_s0, data, base_addr, offset, offset_align); \ 81 | li s2, vd; \ 82 | bne s0, s2, inst_error; \ 83 | nop; \ 84 | lui s2, 0x5678; \ 85 | bne v0, s2, inst_error; \ 86 | nop; \ 87 | li s6, badvaddr; \ 88 | bne s5, s6, inst_error; \ 89 | nop 90 | 91 | /* 64 92 | * TEST_SH_EX(v_s0, data_init, data, base_addr, offset, offset_align, vd, badvaddr) 93 | */ 94 | #define TEST_SH_EX(v_s0, data_init, data, base_addr, offset, offset_align, vd, badvaddr) \ 95 | li v0, 0x06; \ 96 | SH_EX(v_s0, data_init, data, base_addr, offset, offset_align); \ 97 | li s2, vd; \ 98 | bne s0, s2, inst_error; \ 99 | nop; \ 100 | lui s2, 0x1111; \ 101 | bne v0, s2, inst_error; \ 102 | nop; \ 103 | li s6, badvaddr; \ 104 | bne s5, s6, inst_error; \ 105 | nop 106 | 107 | /* 65 108 | * TEST_SW_EX(v_s0, data_init, data, base_addr, offset, offset_align, vd, badvaddr) 109 | */ 110 | #define TEST_SW_EX(v_s0, data_init, data, base_addr, offset, offset_align, vd, badvaddr) \ 111 | li v0, 0x06; \ 112 | SW_EX(v_s0, data_init, data, base_addr, offset, offset_align); \ 113 | li s2, vd; \ 114 | bne s0, s2, inst_error; \ 115 | nop; \ 116 | lui s2, 0x1111; \ 117 | bne v0, s2, inst_error; \ 118 | nop; \ 119 | li s6, badvaddr; \ 120 | bne s5, s6, inst_error; \ 121 | nop 122 | 123 | /* 66 124 | * TEST_ERET_EX(unalign_pc, c0_badvaddr_ref) 125 | */ 126 | #define TEST_ERET_EX(unalign_pc, c0_badvaddr_ref) \ 127 | li v0, 0x07; \ 128 | ERET_EX(unalign_pc); \ 129 | li s2, c0_badvaddr_ref; \ 130 | bne s0, s2, inst_error; \ 131 | nop; \ 132 | lui s2, 0x2222; \ 133 | bne v0, s2, inst_error; \ 134 | nop 135 | 136 | /* 67 137 | * TEST_RESERVED_INSTRUCTION_EX(reserved_instruction) 138 | */ 139 | #define TEST_RESERVED_INSTRUCTION_EX(reserved_instruction) \ 140 | li v0, 0x08; \ 141 | RESERVED_INSTRUCTION_EX(reserved_instruction); \ 142 | lui s2, 0x3333; \ 143 | bne v0, s2, inst_error; \ 144 | nop 145 | -------------------------------------------------------------------------------- /func_test/inst/Makefile: -------------------------------------------------------------------------------- 1 | srcs = $(wildcard *.S) 2 | objs = $(patsubst %.S, %.o, $(srcs)) 3 | 4 | $(TOPDIR)/libinst.a: $(objs) 5 | $(CROSS_COMPILE)$(AR) -cr "$@" $? 6 | 7 | clean: 8 | rm -f *.o *.a *.s 9 | 10 | -include $(TOPDIR)/rules.make 11 | -------------------------------------------------------------------------------- /func_test/inst/n45_break.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | LEAF(n45_break_test) 8 | .set noreorder 9 | li a0, 0x2D 10 | li v0, 0x02 11 | ###test inst 12 | .globl break_pc 13 | break_pc: 14 | break 15 | ###detect exception 16 | li s0, 0xff000000 17 | bne v0, s0, inst_error 18 | nop 19 | ###score ++ 20 | addiu s3, s3, 1 21 | ###output a0|s3 22 | inst_error: 23 | sw s3, 0($23) 24 | sw a0, 0(s1) 25 | jr ra 26 | nop 27 | END(n45_break_test) 28 | -------------------------------------------------------------------------------- /func_test/inst/n46_syscall.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | LEAF(n46_syscall_test) 8 | .set noreorder 9 | li a0, 0x2E 10 | li v0, 0x01 11 | ###test inst 12 | .globl syscall_pc 13 | syscall_pc: 14 | syscall 15 | ###detect exception 16 | li s0, 0x00ff0000 17 | bne v0, s0, inst_error 18 | nop 19 | ###score ++ 20 | addiu s3, s3, 1 21 | ###output a0|s3 22 | inst_error: 23 | sw s3, 0($23) 24 | sw a0, 0(s1) 25 | jr ra 26 | nop 27 | END(n46_syscall_test) 28 | -------------------------------------------------------------------------------- /func_test/inst/n55_eret.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | LEAF(n55_eret_test) 8 | .set noreorder 9 | li a0, 0x37 10 | li v0, 0x03 11 | ###test inst 12 | li t0, 0x7fffffff 13 | addi t0, t0, 0x7fff #overflow ex 14 | lui v0, 0x1234 15 | lui v0, 0x8765 16 | lui v0, 0x5678 17 | .globl eret_ret_pc 18 | eret_ret_pc: 19 | lui v0, 0x4321 20 | ###detect exception 21 | lui s0, 0x0f0f 22 | bne v0, s0, inst_error 23 | nop 24 | ###score ++ 25 | addiu s3, s3, 1 26 | ###output a0|s3 27 | inst_error: 28 | sw s3, 0($23) 29 | sw a0, 0(s1) 30 | jr ra 31 | nop 32 | END(n55_eret_test) 33 | -------------------------------------------------------------------------------- /func_test/inst/n56_mfc0.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | LEAF(n56_mfc0_test) 8 | .set noreorder 9 | li a0, 0x38 10 | li v0, 0x0 11 | ###test inst 12 | li t0, 0xbfc0ffff 13 | #test badvaddr 14 | # can't written by mtc0 15 | mfc0 t1, c0_badvaddr 16 | # mtc0 t0, c0_badvaddr 17 | # mfc0 s0, c0_badvaddr 18 | # mtc0 t1, c0_badvaddr 19 | # bne t0, s0, inst_error 20 | # nop 21 | #test status 22 | mfc0 t1, c0_status 23 | mtc0 t1, c0_status 24 | #test cause 25 | mfc0 t1, c0_cause 26 | mtc0 t1, c0_cause 27 | #test epc 28 | mfc0 t1, c0_epc 29 | mtc0 t0, c0_epc 30 | mfc0 s0, c0_epc 31 | mtc0 t1, c0_epc 32 | bne t0, s0, inst_error 33 | nop 34 | ###detect exception 35 | bne v0, zero, inst_error 36 | nop 37 | ###score ++ 38 | addiu s3, s3, 1 39 | ###output a0|s3 40 | inst_error: 41 | sw s3, 0($23) 42 | sw a0, 0(s1) 43 | jr ra 44 | nop 45 | END(n56_mfc0_test) 46 | -------------------------------------------------------------------------------- /func_test/inst/n57_mtc0.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | LEAF(n57_mtc0_test) 8 | .set noreorder 9 | li a0, 0x39 10 | li v0, 0x0 11 | ###test inst 12 | li t0, 0xbfc0ffff 13 | #test badvaddr 14 | # mfc0 t1, c0_badvaddr 15 | # mtc0 t0, c0_badvaddr 16 | # mfc0 s0, c0_badvaddr 17 | # mtc0 t1, c0_badvaddr 18 | # bne t0, s0, inst_error 19 | # nop 20 | #test status 21 | mfc0 t1, c0_status 22 | mtc0 t1, c0_status 23 | #test cause 24 | mfc0 t1, c0_cause 25 | mtc0 t1, c0_cause 26 | #test epc 27 | mfc0 t1, c0_epc 28 | mtc0 t0, c0_epc 29 | mfc0 s0, c0_epc 30 | mtc0 t1, c0_epc 31 | bne t0, s0, inst_error 32 | nop 33 | ###detect exception 34 | bne v0, zero, inst_error 35 | nop 36 | ###score ++ 37 | addiu s3, s3, 1 38 | ###output a0|s3 39 | inst_error: 40 | sw s3, 0($23) 41 | sw a0, 0(s1) 42 | jr ra 43 | nop 44 | END(n57_mtc0_test) 45 | -------------------------------------------------------------------------------- /func_test/inst/n58_add_ex.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ####LEAF(n58_add_ex_test) 8 | .globl n58_add_ex_test 9 | n58_add_ex_test: 10 | .set noreorder 11 | li a0, 0x3A 12 | ###test inst 13 | TEST_ADD_EX(0x5afb47da, 0x6c8829f0, 0x7f490b93, 0x5afb47da) 14 | TEST_ADD_EX(0x1a376500, 0x2a3ca166, 0x797f30b9, 0x1a376500) 15 | TEST_ADD_EX(0x57b9e040, 0x805413c0, 0xdea0e60a, 0x57b9e040) 16 | TEST_ADD_EX(0x201345c8, 0xcdb7b5d7, 0x96992440, 0x201345c8) 17 | TEST_ADD_EX(0xb7970040, 0x28bad3aa, 0x7efc6380, 0xb7970040) 18 | TEST_ADD_EX(0xb6f7d8ee, 0x9414f228, 0xa93e1e2c, 0xb6f7d8ee) 19 | TEST_ADD_EX(0xcbf98ef6, 0x924af510, 0xeca83800, 0xcbf98ef6) 20 | TEST_ADD_EX(0xb77ba8be, 0xb0e6e640, 0x91ed2798, 0xb77ba8be) 21 | TEST_ADD_EX(0x54b30de8, 0x9e63aee0, 0xb73c06e0, 0x54b30de8) 22 | TEST_ADD_EX(0xf8315a37, 0x4aacef08, 0x358e44d5, 0xf8315a37) 23 | TEST_ADD_EX(0x3fc5f140, 0xa41f9ce8, 0xced3ee78, 0x3fc5f140) 24 | TEST_ADD_EX(0x581761b8, 0x66c5afe0, 0x7aed9464, 0x581761b8) 25 | TEST_ADD_EX(0x4de06530, 0x883c05bd, 0xc0c909c6, 0x4de06530) 26 | TEST_ADD_EX(0x73b2cf92, 0x90a5f39c, 0xd42179e0, 0x73b2cf92) 27 | TEST_ADD_EX(0x0580ff83, 0x6f5f1fbc, 0x2f738fa8, 0x0580ff83) 28 | TEST_ADD_EX(0x89a0a980, 0x474db690, 0x4d4cbef8, 0x89a0a980) 29 | TEST_ADD_EX(0x0f29c5e0, 0x6818e272, 0x6f6d2620, 0x0f29c5e0) 30 | TEST_ADD_EX(0xa417fbd0, 0xf25f8690, 0x8bd5dc00, 0xa417fbd0) 31 | TEST_ADD_EX(0x9ddbf9de, 0x5c71ab68, 0x5ded26b7, 0x9ddbf9de) 32 | TEST_ADD_EX(0x7e5142ea, 0x9207edaf, 0x9ff70ca0, 0x7e5142ea) 33 | TEST_ADD_EX(0xc23fa220, 0x66c13285, 0x62e6a232, 0xc23fa220) 34 | TEST_ADD_EX(0x10c04730, 0x3eb86080, 0x6d13e968, 0x10c04730) 35 | TEST_ADD_EX(0x3d968bd0, 0x715979e0, 0x3c4225a8, 0x3d968bd0) 36 | TEST_ADD_EX(0x2ffed6dc, 0x2b69556c, 0x6126f0bc, 0x2ffed6dc) 37 | TEST_ADD_EX(0x9b902d80, 0x8b470189, 0xad3b3bf0, 0x9b902d80) 38 | TEST_ADD_EX(0x182fd44b, 0x7ec1fd50, 0x17915adc, 0x182fd44b) 39 | TEST_ADD_EX(0x69365359, 0x6f1e0f60, 0x6a965e76, 0x69365359) 40 | TEST_ADD_EX(0x8ff3b27c, 0xb7d9a76f, 0xa7cff5f3, 0x8ff3b27c) 41 | TEST_ADD_EX(0x9f1c5870, 0xa7b7a764, 0xc2d61d9c, 0x9f1c5870) 42 | TEST_ADD_EX(0x28dfb000, 0x92324ebc, 0xa87ab9d0, 0x28dfb000) 43 | TEST_ADD_EX(0x31e6699f, 0x8a78cc40, 0xab7284da, 0x31e6699f) 44 | TEST_ADD_EX(0x2056d57e, 0xda3a9e4d, 0x83c85ffc, 0x2056d57e) 45 | TEST_ADD_EX(0xda5a7118, 0x99cca31f, 0x8984c900, 0xda5a7118) 46 | TEST_ADD_EX(0x14690a6b, 0xc0ff24b0, 0x8d5614c2, 0x14690a6b) 47 | TEST_ADD_EX(0xdf377e47, 0x4e88625a, 0x789fd3c0, 0xdf377e47) 48 | TEST_ADD_EX(0x1dc42f20, 0x45bfade4, 0x7f4b29d1, 0x1dc42f20) 49 | TEST_ADD_EX(0x80b2fd24, 0x971ee968, 0xd15f6fc8, 0x80b2fd24) 50 | TEST_ADD_EX(0xc1d4242e, 0xae64d400, 0xca89c824, 0xc1d4242e) 51 | TEST_ADD_EX(0x70c00360, 0x93eff0e0, 0xe90de540, 0x70c00360) 52 | TEST_ADD_EX(0x445f5ac0, 0xc430fd60, 0x8061c430, 0x445f5ac0) 53 | TEST_ADD_EX(0x08867a70, 0xb4cda0f0, 0xae93e5dc, 0x08867a70) 54 | TEST_ADD_EX(0x6ba62f10, 0xa6c07250, 0xadbb84d2, 0x6ba62f10) 55 | TEST_ADD_EX(0xc8ca9c54, 0x90bc9b00, 0xe827414c, 0xc8ca9c54) 56 | TEST_ADD_EX(0xcf5a69a0, 0x68c44320, 0x5f8324e0, 0xcf5a69a0) 57 | TEST_ADD_EX(0xcc6c38be, 0xb932b6d2, 0x9e42ed6c, 0xcc6c38be) 58 | TEST_ADD_EX(0x5e5952f4, 0xcb2eee91, 0xb4615df0, 0x5e5952f4) 59 | TEST_ADD_EX(0xb59c8b00, 0x85552398, 0x857f364f, 0xb59c8b00) 60 | TEST_ADD_EX(0x4c2e45fe, 0x2fece48f, 0x693adab7, 0x4c2e45fe) 61 | TEST_ADD_EX(0xbc572030, 0x358d0fe4, 0x63930092, 0xbc572030) 62 | TEST_ADD_EX(0xf3750460, 0xdd118380, 0x85ee9fe6, 0xf3750460) 63 | TEST_ADD_EX(0x86f6765c, 0x978c5d9c, 0xd2b76ac8, 0x86f6765c) 64 | TEST_ADD_EX(0x758b3a34, 0x39ef382c, 0x74480400, 0x758b3a34) 65 | TEST_ADD_EX(0xf3709640, 0xba034f60, 0xb615fd67, 0xf3709640) 66 | 67 | ###detect exception 68 | ###score ++ 69 | addiu s3, s3, 1 70 | ###output a0|s3 71 | inst_error: 72 | sw s3, 0($23) 73 | sw a0, 0(s1) 74 | jr ra 75 | nop 76 | ####END(n58_add_ex_test) 77 | -------------------------------------------------------------------------------- /func_test/inst/n59_addi_ex.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ####LEAF(n59_addi_ex_test) 8 | .globl n59_addi_ex_test 9 | n59_addi_ex_test: 10 | .set noreorder 11 | li a0, 0x3B 12 | ###test inst 13 | TEST_ADDI_EX(0x60a71e30, 0x7fff9b21, 0x000071db, 0x60a71e30) 14 | TEST_ADDI_EX(0x6c5392aa, 0x7ffff480, 0x000054b0, 0x6c5392aa) 15 | TEST_ADDI_EX(0xdeb06fd0, 0x7ffff84b, 0x00002c26, 0xdeb06fd0) 16 | TEST_ADDI_EX(0x9993b814, 0x7fffb280, 0x00005589, 0x9993b814) 17 | TEST_ADDI_EX(0x14132028, 0x7ffff860, 0x00001600, 0x14132028) 18 | TEST_ADDI_EX(0xa75f2d54, 0x7fffd84c, 0x00006f02, 0xa75f2d54) 19 | TEST_ADDI_EX(0x9a338000, 0x7fffcf88, 0x00007dc6, 0x9a338000) 20 | TEST_ADDI_EX(0x03a436e0, 0x7fffbf4c, 0x00005f10, 0x03a436e0) 21 | TEST_ADDI_EX(0xca6c3980, 0x7fffd9c4, 0x00003bd6, 0xca6c3980) 22 | TEST_ADDI_EX(0x487fcfe5, 0x7fffdd27, 0x00007208, 0x487fcfe5) 23 | TEST_ADDI_EX(0x22a23618, 0x7fffcf04, 0x00007ca0, 0x22a23618) 24 | TEST_ADDI_EX(0x42aa4389, 0x7ffff347, 0x000033c6, 0x42aa4389) 25 | TEST_ADDI_EX(0xcd908ee8, 0x7fffe660, 0x000025fa, 0xcd908ee8) 26 | TEST_ADDI_EX(0x1bc5574c, 0x7fffb580, 0x00006ce3, 0x1bc5574c) 27 | TEST_ADDI_EX(0xfa1cdcc0, 0x7ffffbdf, 0x00003228, 0xfa1cdcc0) 28 | TEST_ADDI_EX(0xd2169284, 0x7fffc624, 0x00003f46, 0xd2169284) 29 | TEST_ADDI_EX(0xfba95860, 0x7fffa558, 0x00007338, 0xfba95860) 30 | TEST_ADDI_EX(0xda0bca08, 0x7fff9b1f, 0x0000779a, 0xda0bca08) 31 | TEST_ADDI_EX(0x21feb84a, 0x7fffb6c8, 0x000058f3, 0x21feb84a) 32 | TEST_ADDI_EX(0x1d092948, 0x7ffffe85, 0x0000149b, 0x1d092948) 33 | TEST_ADDI_EX(0xce2f8cbc, 0x7ffff7ac, 0x00002ac4, 0xce2f8cbc) 34 | TEST_ADDI_EX(0xb2a90100, 0x7ffff808, 0x00007bb3, 0xb2a90100) 35 | TEST_ADDI_EX(0xdb92e3cc, 0x7fffc19e, 0x00006512, 0xdb92e3cc) 36 | TEST_ADDI_EX(0x51dccfe4, 0x7fffbc60, 0x00006ae7, 0x51dccfe4) 37 | TEST_ADDI_EX(0xda8fec00, 0x7fffccae, 0x00005a83, 0xda8fec00) 38 | TEST_ADDI_EX(0x06152570, 0x80003510, 0x0000baa6, 0x06152570) 39 | TEST_ADDI_EX(0xbd3ea700, 0x80004016, 0x000081f4, 0xbd3ea700) 40 | TEST_ADDI_EX(0x8f7ee6c0, 0x80002c93, 0x0000845d, 0x8f7ee6c0) 41 | TEST_ADDI_EX(0xe6075700, 0x80003a57, 0x0000be07, 0xe6075700) 42 | TEST_ADDI_EX(0x2909db2c, 0x800026f6, 0x0000a61a, 0x2909db2c) 43 | TEST_ADDI_EX(0x5d9751f4, 0x800021b6, 0x0000d072, 0x5d9751f4) 44 | TEST_ADDI_EX(0x7b83cc90, 0x80004287, 0x0000aca4, 0x7b83cc90) 45 | TEST_ADDI_EX(0xe36aedc6, 0x80004ca7, 0x000093c8, 0xe36aedc6) 46 | TEST_ADDI_EX(0x1971cf30, 0x80001c98, 0x0000d760, 0x1971cf30) 47 | TEST_ADDI_EX(0x150533d0, 0x80004d51, 0x00009438, 0x150533d0) 48 | TEST_ADDI_EX(0x9df31000, 0x800020e3, 0x0000ca64, 0x9df31000) 49 | TEST_ADDI_EX(0x9c3b3fa0, 0x80003338, 0x000080b2, 0x9c3b3fa0) 50 | TEST_ADDI_EX(0xeaaba458, 0x80003167, 0x0000a81a, 0xeaaba458) 51 | TEST_ADDI_EX(0x8c7b4880, 0x80001979, 0x0000cb8e, 0x8c7b4880) 52 | TEST_ADDI_EX(0xc94e5d40, 0x800039f2, 0x0000c570, 0xc94e5d40) 53 | TEST_ADDI_EX(0x88416d41, 0x80003e1b, 0x000094c0, 0x88416d41) 54 | TEST_ADDI_EX(0x93a6fc91, 0x800010fc, 0x0000d28c, 0x93a6fc91) 55 | TEST_ADDI_EX(0x5fd3eb1a, 0x8000243e, 0x0000ce06, 0x5fd3eb1a) 56 | TEST_ADDI_EX(0x9892cc38, 0x80001627, 0x0000e6b3, 0x9892cc38) 57 | TEST_ADDI_EX(0x58e7c636, 0x800021ae, 0x00009e80, 0x58e7c636) 58 | TEST_ADDI_EX(0x8704c78c, 0x8000536a, 0x00009617, 0x8704c78c) 59 | TEST_ADDI_EX(0xdf059448, 0x80001d9e, 0x0000a9ed, 0xdf059448) 60 | TEST_ADDI_EX(0xc56f0250, 0x80001228, 0x0000a3a3, 0xc56f0250) 61 | TEST_ADDI_EX(0x1e3cdc70, 0x80001806, 0x0000b09f, 0x1e3cdc70) 62 | TEST_ADDI_EX(0x5c2eb094, 0x800028a4, 0x00008a72, 0x5c2eb094) 63 | 64 | ###detect exception 65 | ###score ++ 66 | addiu s3, s3, 1 67 | ###output a0|s3 68 | inst_error: 69 | sw s3, 0($23) 70 | sw a0, 0(s1) 71 | jr ra 72 | nop 73 | ####END(n59_addi_ex_test) 74 | -------------------------------------------------------------------------------- /func_test/inst/n60_sub_ex.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ####LEAF(n60_sub_ex_test) 8 | .globl n60_sub_ex_test 9 | n60_sub_ex_test: 10 | .set noreorder 11 | li a0, 0x3C 12 | ###test inst 13 | TEST_SUB_EX(0x9f767750, 0x70410c7a, 0x8ddc20c0, 0x9f767750) 14 | TEST_SUB_EX(0x1625bcc8, 0xb53cd464, 0x421d020a, 0x1625bcc8) 15 | TEST_SUB_EX(0xb226ec94, 0xb196dd00, 0x7dfd9ab0, 0xb226ec94) 16 | TEST_SUB_EX(0xdc373c00, 0x21ccbee8, 0x9a01fac4, 0xdc373c00) 17 | TEST_SUB_EX(0xf4e01aa8, 0x734a367f, 0xe17354f8, 0xf4e01aa8) 18 | TEST_SUB_EX(0x8754eb0d, 0x6f8c1169, 0x9eddbba4, 0x8754eb0d) 19 | TEST_SUB_EX(0x3f0637b6, 0x63d3fd1e, 0xd0378bea, 0x3f0637b6) 20 | TEST_SUB_EX(0xb72e3dc0, 0xb467a2f0, 0x43a582b0, 0xb72e3dc0) 21 | TEST_SUB_EX(0xb4cca190, 0xa7c97e00, 0x73ce3080, 0xb4cca190) 22 | TEST_SUB_EX(0x11f4fab1, 0x5bb44744, 0xc4569c6c, 0x11f4fab1) 23 | TEST_SUB_EX(0xa1d47024, 0x4c7be9bb, 0x980db6ec, 0xa1d47024) 24 | TEST_SUB_EX(0xee3b8b21, 0x79450eb0, 0xd3a634f7, 0xee3b8b21) 25 | TEST_SUB_EX(0xb09f8deb, 0x511a4824, 0xc3ae4398, 0xb09f8deb) 26 | TEST_SUB_EX(0x2e700561, 0x5f9d1f40, 0xcf02b6fe, 0x2e700561) 27 | TEST_SUB_EX(0x6f94c2c0, 0xc6dfef00, 0x73d11600, 0x6f94c2c0) 28 | TEST_SUB_EX(0x23f81921, 0x4b546b70, 0x97419254, 0x23f81921) 29 | TEST_SUB_EX(0xedd15164, 0x65eaa24c, 0xe51c2960, 0xedd15164) 30 | TEST_SUB_EX(0x8e970ca6, 0x17f073d4, 0x96249d08, 0x8e970ca6) 31 | TEST_SUB_EX(0xe4305840, 0x71119e61, 0x902a41a0, 0xe4305840) 32 | TEST_SUB_EX(0x2b1bb290, 0x9bdcba50, 0x73610be2, 0x2b1bb290) 33 | TEST_SUB_EX(0x8fa1e167, 0x4364d130, 0xa1395784, 0x8fa1e167) 34 | TEST_SUB_EX(0xc1eea22e, 0x555591ba, 0xc6b80060, 0xc1eea22e) 35 | TEST_SUB_EX(0x5086d0c5, 0x9c695098, 0x633e7b0e, 0x5086d0c5) 36 | TEST_SUB_EX(0xc8c5ad7a, 0x8b1afee8, 0x671bed54, 0xc8c5ad7a) 37 | TEST_SUB_EX(0xde30e340, 0xc76ce200, 0x4d98be80, 0xde30e340) 38 | TEST_SUB_EX(0xba9fa020, 0x3e9fb3b0, 0x8fbebffc, 0xba9fa020) 39 | TEST_SUB_EX(0xf6774e04, 0xb0b68290, 0x424dcfec, 0xf6774e04) 40 | TEST_SUB_EX(0x82ec757d, 0x0a0dc120, 0x872780e0, 0x82ec757d) 41 | TEST_SUB_EX(0xd9449ddc, 0x7f158f40, 0xd649ef60, 0xd9449ddc) 42 | TEST_SUB_EX(0x2b70d50c, 0xadc99f50, 0x58c30364, 0x2b70d50c) 43 | TEST_SUB_EX(0x7e41bd78, 0x9b6a6fec, 0x5a9e9548, 0x7e41bd78) 44 | TEST_SUB_EX(0x73aca300, 0x42691971, 0xa72508a0, 0x73aca300) 45 | TEST_SUB_EX(0x521a0a7e, 0x6796563f, 0xb6fe304d, 0x521a0a7e) 46 | TEST_SUB_EX(0xaa0667b0, 0x77243fcf, 0xbea8215a, 0xaa0667b0) 47 | TEST_SUB_EX(0x356ca2f4, 0x6b3069ae, 0xdd122730, 0x356ca2f4) 48 | TEST_SUB_EX(0x7b3f2760, 0xab29890a, 0x57e6120c, 0x7b3f2760) 49 | TEST_SUB_EX(0x89cff440, 0x8e78bd3e, 0x696bedc0, 0x89cff440) 50 | TEST_SUB_EX(0x685ffa38, 0x8f92dcce, 0x153362d0, 0x685ffa38) 51 | TEST_SUB_EX(0x592d2820, 0xd56cf700, 0x7997dad0, 0x592d2820) 52 | TEST_SUB_EX(0x4c8defdc, 0x8f55ca75, 0x27bb42b4, 0x4c8defdc) 53 | TEST_SUB_EX(0xcf0b6f54, 0x8f139208, 0x453d7a36, 0xcf0b6f54) 54 | TEST_SUB_EX(0xa0d69a38, 0x2ff1a3be, 0x8ae324c0, 0xa0d69a38) 55 | TEST_SUB_EX(0xda3759c0, 0x8ae2d280, 0x3f110408, 0xda3759c0) 56 | TEST_SUB_EX(0x857e42ce, 0x7720685e, 0x8f4affe5, 0x857e42ce) 57 | TEST_SUB_EX(0x3d450948, 0x9981eb30, 0x6d2813e0, 0x3d450948) 58 | TEST_SUB_EX(0xdb52b260, 0x80ef0c00, 0x6518a02c, 0xdb52b260) 59 | TEST_SUB_EX(0x4430d2af, 0x7bed2cdf, 0xb5be3b98, 0x4430d2af) 60 | TEST_SUB_EX(0x07182605, 0xa85e7d00, 0x6b7e8e36, 0x07182605) 61 | 62 | ###detect exception 63 | ###score ++ 64 | addiu s3, s3, 1 65 | ###output a0|s3 66 | inst_error: 67 | sw s3, 0($23) 68 | sw a0, 0(s1) 69 | jr ra 70 | nop 71 | ####END(n60_sub_ex_test) 72 | -------------------------------------------------------------------------------- /func_test/inst/n68_beq_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n68_beq_ds_test) 8 | .globl n68_beq_ds_test 9 | n68_beq_ds_test: 10 | .set noreorder 11 | li a0, 0x44 12 | li v0, 0x00 13 | ###test inst 14 | TEST_BEQ_DS 15 | ###detect exception 16 | bne v0, zero, inst_error 17 | nop 18 | ###score ++ 19 | addiu s3, s3, 1 20 | ###output a0|s3 21 | inst_error: 22 | sw s3, 0($23) 23 | sw a0, 0(s1) 24 | jr ra 25 | nop 26 | ####END(n68_beq_ds_test) 27 | -------------------------------------------------------------------------------- /func_test/inst/n69_bne_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n69_bne_ds_test) 8 | .globl n69_bne_ds_test 9 | n69_bne_ds_test: 10 | .set noreorder 11 | li a0, 0x45 12 | li v0, 0x00 13 | ###test inst 14 | TEST_BNE_DS 15 | ###detect exception 16 | bne v0, zero, inst_error 17 | nop 18 | ###score ++ 19 | addiu s3, s3, 1 20 | ###output a0|s3 21 | inst_error: 22 | sw s3, 0($23) 23 | sw a0, 0(s1) 24 | jr ra 25 | nop 26 | ####END(n69_bne_ds_test) 27 | -------------------------------------------------------------------------------- /func_test/inst/n70_bgez_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n70_bgez_ds_test) 8 | .globl n70_bgez_ds_test 9 | n70_bgez_ds_test: 10 | .set noreorder 11 | li a0, 0x46 12 | li v0, 0x00 13 | ###test inst 14 | TEST_BGEZ_DS 15 | ###detect exception 16 | bne v0, zero, inst_error 17 | nop 18 | ###score ++ 19 | addiu s3, s3, 1 20 | ###output a0|s3 21 | inst_error: 22 | sw s3, 0($23) 23 | sw a0, 0(s1) 24 | jr ra 25 | nop 26 | ####END(n70_bgez_ds_test) 27 | -------------------------------------------------------------------------------- /func_test/inst/n71_bgtz_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n71_bgtz_ds_test) 8 | .globl n71_bgtz_ds_test 9 | n71_bgtz_ds_test: 10 | .set noreorder 11 | li a0, 0x47 12 | li v0, 0x00 13 | ###test inst 14 | TEST_BGTZ_DS 15 | ###detect exception 16 | bne v0, zero, inst_error 17 | nop 18 | ###score ++ 19 | addiu s3, s3, 1 20 | ###output a0|s3 21 | inst_error: 22 | sw s3, 0($23) 23 | sw a0, 0(s1) 24 | jr ra 25 | nop 26 | ####END(n71_bgtz_ds_test) 27 | -------------------------------------------------------------------------------- /func_test/inst/n72_blez_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n72_blez_ds_test) 8 | .globl n72_blez_ds_test 9 | n72_blez_ds_test: 10 | .set noreorder 11 | li a0, 0x48 12 | li v0, 0x00 13 | ###test inst 14 | TEST_BLEZ_DS 15 | ###detect exception 16 | bne v0, zero, inst_error 17 | nop 18 | ###score ++ 19 | addiu s3, s3, 1 20 | ###output a0|s3 21 | inst_error: 22 | sw s3, 0($23) 23 | sw a0, 0(s1) 24 | jr ra 25 | nop 26 | ####END(n72_blez_ds_test) 27 | -------------------------------------------------------------------------------- /func_test/inst/n73_bltz_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n73_bltz_ds_test) 8 | .globl n73_bltz_ds_test 9 | n73_bltz_ds_test: 10 | .set noreorder 11 | li a0, 0x49 12 | li v0, 0x00 13 | ###test inst 14 | TEST_BLTZ_DS 15 | ###detect exception 16 | bne v0, zero, inst_error 17 | nop 18 | ###score ++ 19 | addiu s3, s3, 1 20 | ###output a0|s3 21 | inst_error: 22 | sw s3, 0($23) 23 | sw a0, 0(s1) 24 | jr ra 25 | nop 26 | ####END(n73_bltz_ds_test) 27 | -------------------------------------------------------------------------------- /func_test/inst/n74_bltzal_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n74_bltzal_ds_test) 8 | .globl n74_bltzal_ds_test 9 | n74_bltzal_ds_test: 10 | .set noreorder 11 | li a0, 0x4A 12 | li v0, 0x00 13 | ###test inst 14 | TEST_BLTZAL_DS 15 | ###detect exception 16 | bne v0, zero, inst_error 17 | nop 18 | ###score ++ 19 | addiu s3, s3, 1 20 | ###output a0|s3 21 | inst_error: 22 | sw s3, 0($23) 23 | sw a0, 0(s1) 24 | jr ra 25 | nop 26 | ####END(n74_bltzal_ds_test) 27 | -------------------------------------------------------------------------------- /func_test/inst/n75_bgezal_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n75_bgezal_ds_test) 8 | .globl n75_bgezal_ds_test 9 | n75_bgezal_ds_test: 10 | .set noreorder 11 | li a0, 0x4B 12 | li v0, 0x00 13 | ###test inst 14 | TEST_BGEZAL_DS 15 | ###detect exception 16 | bne v0, zero, inst_error 17 | nop 18 | ###score ++ 19 | addiu s3, s3, 1 20 | ###output a0|s3 21 | inst_error: 22 | sw s3, 0($23) 23 | sw a0, 0(s1) 24 | jr ra 25 | nop 26 | ####END(n75_bgezal_ds_test) 27 | -------------------------------------------------------------------------------- /func_test/inst/n76_j_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n76_j_ds_test) 8 | .globl n76_j_ds_test 9 | n76_j_ds_test: 10 | .set noreorder 11 | li a0, 0x4C 12 | li v0, 0x00 13 | ###test inst 14 | TEST_J_DS 15 | ###detect exception 16 | bne v0, zero, inst_error 17 | nop 18 | ###score ++ 19 | addiu s3, s3, 1 20 | ###output a0|s3 21 | inst_error: 22 | sw s3, 0($23) 23 | sw a0, 0(s1) 24 | jr ra 25 | nop 26 | ####END(n76_j_ds_test) 27 | -------------------------------------------------------------------------------- /func_test/inst/n77_jal_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n77_jal_ds_test) 8 | .globl n77_jal_ds_test 9 | n77_jal_ds_test: 10 | .set noreorder 11 | li a0, 0x4D 12 | li v0, 0x00 13 | ###test inst 14 | TEST_JAL_DS 15 | ###detect exception 16 | bne v0, zero, inst_error 17 | nop 18 | ###score ++ 19 | addiu s3, s3, 1 20 | ###output a0|s3 21 | inst_error: 22 | sw s3, 0($23) 23 | sw a0, 0(s1) 24 | jr ra 25 | nop 26 | ####END(n77_jal_ds_test) 27 | -------------------------------------------------------------------------------- /func_test/inst/n78_jr_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n78_jr_ds_test) 8 | .globl n78_jr_ds_test 9 | n78_jr_ds_test: 10 | .set noreorder 11 | li a0, 0x4E 12 | li v0, 0x00 13 | ###test inst 14 | TEST_JR_DS 15 | ###detect exception 16 | bne v0, zero, inst_error 17 | nop 18 | ###score ++ 19 | addiu s3, s3, 1 20 | ###output a0|s3 21 | inst_error: 22 | sw s3, 0($23) 23 | sw a0, 0(s1) 24 | jr ra 25 | nop 26 | ####END(n78_jr_ds_test) 27 | -------------------------------------------------------------------------------- /func_test/inst/n79_jalr_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n79_jalr_ds_test) 8 | .globl n79_jalr_ds_test 9 | n79_jalr_ds_test: 10 | .set noreorder 11 | li a0, 0x4F 12 | li v0, 0x00 13 | ###test inst 14 | TEST_JALR_DS 15 | ###detect exception 16 | bne v0, zero, inst_error 17 | nop 18 | ###score ++ 19 | addiu s3, s3, 1 20 | ###output a0|s3 21 | inst_error: 22 | sw s3, 0($23) 23 | sw a0, 0(s1) 24 | jr ra 25 | nop 26 | ####END(n79_jalr_ds_test) 27 | -------------------------------------------------------------------------------- /func_test/inst/n80_beq_ex_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n80_beq_ex_ds_test) 8 | .globl n80_beq_ex_ds_test 9 | n80_beq_ex_ds_test: 10 | .set noreorder 11 | li a0, 0x50 12 | # li v0, 0x09 13 | ###test inst 14 | TEST_BEQ_EX_DS_EX_ADDI 15 | TEST_BEQ_EX_DS_EX_ADD 16 | TEST_BEQ_EX_DS_EX_SUB 17 | TEST_BEQ_EX_DS_EX_LH 18 | TEST_BEQ_EX_DS_EX_LHU 19 | TEST_BEQ_EX_DS_EX_LW 20 | TEST_BEQ_EX_DS_EX_SH 21 | TEST_BEQ_EX_DS_EX_SW 22 | TEST_BEQ_EX_DS_EX_RI 23 | TEST_BEQ_EX_DS_EX_SYSCALL 24 | TEST_BEQ_EX_DS_EX_BREAK 25 | ###detect exception 26 | # lui s0, 0x4444 27 | # bne v0, s0, inst_error 28 | # nop 29 | ###score ++ 30 | addiu s3, s3, 1 31 | ###output a0|s3 32 | inst_error: 33 | sw s3, 0($23) 34 | sw a0, 0(s1) 35 | jr ra 36 | nop 37 | ####END(n80_beq_ex_ds_test) 38 | -------------------------------------------------------------------------------- /func_test/inst/n81_bne_ex_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n81_bne_ex_ds_test) 8 | .globl n81_bne_ex_ds_test 9 | n81_bne_ex_ds_test: 10 | .set noreorder 11 | li a0, 0x51 12 | # li v0, 0x09 13 | ###test inst 14 | TEST_BNE_EX_DS_EX_ADDI 15 | TEST_BNE_EX_DS_EX_ADD 16 | TEST_BNE_EX_DS_EX_SUB 17 | TEST_BNE_EX_DS_EX_LH 18 | TEST_BNE_EX_DS_EX_LHU 19 | TEST_BNE_EX_DS_EX_LW 20 | TEST_BNE_EX_DS_EX_SH 21 | TEST_BNE_EX_DS_EX_SW 22 | TEST_BNE_EX_DS_EX_RI 23 | TEST_BNE_EX_DS_EX_SYSCALL 24 | TEST_BNE_EX_DS_EX_BREAK 25 | ###detect exception 26 | # lui s0, 0x4444 27 | # bne v0, s0, inst_error 28 | # nop 29 | ###score ++ 30 | addiu s3, s3, 1 31 | ###output a0|s3 32 | inst_error: 33 | sw s3, 0($23) 34 | sw a0, 0(s1) 35 | jr ra 36 | nop 37 | ####END(n81_bne_ex_ds_test) 38 | -------------------------------------------------------------------------------- /func_test/inst/n82_bgez_ex_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n82_bgez_ex_ds_test) 8 | .globl n82_bgez_ex_ds_test 9 | n82_bgez_ex_ds_test: 10 | .set noreorder 11 | li a0, 0x52 12 | # li v0, 0x09 13 | ###test inst 14 | TEST_BGEZ_EX_DS_EX_ADDI 15 | TEST_BGEZ_EX_DS_EX_ADD 16 | TEST_BGEZ_EX_DS_EX_SUB 17 | TEST_BGEZ_EX_DS_EX_LH 18 | TEST_BGEZ_EX_DS_EX_LHU 19 | TEST_BGEZ_EX_DS_EX_LW 20 | TEST_BGEZ_EX_DS_EX_SH 21 | TEST_BGEZ_EX_DS_EX_SW 22 | TEST_BGEZ_EX_DS_EX_RI 23 | TEST_BGEZ_EX_DS_EX_SYSCALL 24 | TEST_BGEZ_EX_DS_EX_BREAK 25 | ###detect exception 26 | # lui s0, 0x4444 27 | # bne v0, s0, inst_error 28 | # nop 29 | ###score ++ 30 | addiu s3, s3, 1 31 | ###output a0|s3 32 | inst_error: 33 | sw s3, 0($23) 34 | sw a0, 0(s1) 35 | jr ra 36 | nop 37 | ####END(n82_bgez_ex_ds_test) 38 | -------------------------------------------------------------------------------- /func_test/inst/n83_bgtz_ex_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n83_bgtz_ex_ds_test) 8 | .globl n83_bgtz_ex_ds_test 9 | n83_bgtz_ex_ds_test: 10 | .set noreorder 11 | li a0, 0x53 12 | # li v0, 0x09 13 | ###test inst 14 | TEST_BGTZ_EX_DS_EX_ADDI 15 | TEST_BGTZ_EX_DS_EX_ADD 16 | TEST_BGTZ_EX_DS_EX_SUB 17 | TEST_BGTZ_EX_DS_EX_LH 18 | TEST_BGTZ_EX_DS_EX_LHU 19 | TEST_BGTZ_EX_DS_EX_LW 20 | TEST_BGTZ_EX_DS_EX_SH 21 | TEST_BGTZ_EX_DS_EX_SW 22 | TEST_BGTZ_EX_DS_EX_RI 23 | TEST_BGTZ_EX_DS_EX_SYSCALL 24 | TEST_BGTZ_EX_DS_EX_BREAK 25 | ###detect exception 26 | # lui s0, 0x4444 27 | # bne v0, s0, inst_error 28 | # nop 29 | ###score ++ 30 | addiu s3, s3, 1 31 | ###output a0|s3 32 | inst_error: 33 | sw s3, 0($23) 34 | sw a0, 0(s1) 35 | jr ra 36 | nop 37 | ####END(n83_bgtz_ex_ds_test) 38 | -------------------------------------------------------------------------------- /func_test/inst/n84_blez_ex_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n84_blez_ex_ds_test) 8 | .globl n84_blez_ex_ds_test 9 | n84_blez_ex_ds_test: 10 | .set noreorder 11 | li a0, 0x54 12 | # li v0, 0x09 13 | ###test inst 14 | TEST_BLEZ_EX_DS_EX_ADDI 15 | TEST_BLEZ_EX_DS_EX_ADD 16 | TEST_BLEZ_EX_DS_EX_SUB 17 | TEST_BLEZ_EX_DS_EX_LH 18 | TEST_BLEZ_EX_DS_EX_LHU 19 | TEST_BLEZ_EX_DS_EX_LW 20 | TEST_BLEZ_EX_DS_EX_SH 21 | TEST_BLEZ_EX_DS_EX_SW 22 | TEST_BLEZ_EX_DS_EX_RI 23 | TEST_BLEZ_EX_DS_EX_SYSCALL 24 | TEST_BLEZ_EX_DS_EX_BREAK 25 | ###detect exception 26 | # lui s0, 0x4444 27 | # bne v0, s0, inst_error 28 | # nop 29 | ###score ++ 30 | addiu s3, s3, 1 31 | ###output a0|s3 32 | inst_error: 33 | sw s3, 0($23) 34 | sw a0, 0(s1) 35 | jr ra 36 | nop 37 | ####END(n84_blez_ex_ds_test) 38 | -------------------------------------------------------------------------------- /func_test/inst/n85_bltz_ex_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n85_bltz_ex_ds_test) 8 | .globl n85_bltz_ex_ds_test 9 | n85_bltz_ex_ds_test: 10 | .set noreorder 11 | li a0, 0x55 12 | # li v0, 0x09 13 | ###test inst 14 | TEST_BLTZ_EX_DS_EX_ADDI 15 | TEST_BLTZ_EX_DS_EX_ADD 16 | TEST_BLTZ_EX_DS_EX_SUB 17 | TEST_BLTZ_EX_DS_EX_LH 18 | TEST_BLTZ_EX_DS_EX_LHU 19 | TEST_BLTZ_EX_DS_EX_LW 20 | TEST_BLTZ_EX_DS_EX_SH 21 | TEST_BLTZ_EX_DS_EX_SW 22 | TEST_BLTZ_EX_DS_EX_RI 23 | TEST_BLTZ_EX_DS_EX_SYSCALL 24 | TEST_BLTZ_EX_DS_EX_BREAK 25 | ###detect exception 26 | # lui s0, 0x4444 27 | # bne v0, s0, inst_error 28 | # nop 29 | ###score ++ 30 | addiu s3, s3, 1 31 | ###output a0|s3 32 | inst_error: 33 | sw s3, 0($23) 34 | sw a0, 0(s1) 35 | jr ra 36 | nop 37 | ####END(n85_bltz_ex_ds_test) 38 | -------------------------------------------------------------------------------- /func_test/inst/n86_bltzal_ex_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n86_bltzal_ex_ds_test) 8 | .globl n86_bltzal_ex_ds_test 9 | n86_bltzal_ex_ds_test: 10 | .set noreorder 11 | li a0, 0x56 12 | # li v0, 0x09 13 | ###test inst 14 | TEST_BLTZAL_EX_DS_EX_ADDI 15 | TEST_BLTZAL_EX_DS_EX_ADD 16 | TEST_BLTZAL_EX_DS_EX_SUB 17 | TEST_BLTZAL_EX_DS_EX_LH 18 | TEST_BLTZAL_EX_DS_EX_LHU 19 | TEST_BLTZAL_EX_DS_EX_LW 20 | TEST_BLTZAL_EX_DS_EX_SH 21 | TEST_BLTZAL_EX_DS_EX_SW 22 | TEST_BLTZAL_EX_DS_EX_RI 23 | TEST_BLTZAL_EX_DS_EX_SYSCALL 24 | TEST_BLTZAL_EX_DS_EX_BREAK 25 | ###detect exception 26 | # lui s0, 0x4444 27 | # bne v0, s0, inst_error 28 | # nop 29 | ###score ++ 30 | addiu s3, s3, 1 31 | ###output a0|s3 32 | inst_error: 33 | sw s3, 0($23) 34 | sw a0, 0(s1) 35 | jr ra 36 | nop 37 | ####END(n86_bltzal_ex_ds_test) 38 | -------------------------------------------------------------------------------- /func_test/inst/n87_bgezal_ex_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n87_bgezal_ex_ds_test) 8 | .globl n87_bgezal_ex_ds_test 9 | n87_bgezal_ex_ds_test: 10 | .set noreorder 11 | li a0, 0x57 12 | # li v0, 0x09 13 | ###test inst 14 | TEST_BGEZAL_EX_DS_EX_ADDI 15 | TEST_BGEZAL_EX_DS_EX_ADD 16 | TEST_BGEZAL_EX_DS_EX_SUB 17 | TEST_BGEZAL_EX_DS_EX_LH 18 | TEST_BGEZAL_EX_DS_EX_LHU 19 | TEST_BGEZAL_EX_DS_EX_LW 20 | TEST_BGEZAL_EX_DS_EX_SH 21 | TEST_BGEZAL_EX_DS_EX_SW 22 | TEST_BGEZAL_EX_DS_EX_RI 23 | TEST_BGEZAL_EX_DS_EX_SYSCALL 24 | TEST_BGEZAL_EX_DS_EX_BREAK 25 | ###detect exception 26 | # lui s0, 0x4444 27 | # bne v0, s0, inst_error 28 | # nop 29 | ###score ++ 30 | addiu s3, s3, 1 31 | ###output a0|s3 32 | inst_error: 33 | sw s3, 0($23) 34 | sw a0, 0(s1) 35 | jr ra 36 | nop 37 | ####END(n87_bgezal_ex_ds_test) 38 | -------------------------------------------------------------------------------- /func_test/inst/n88_j_ex_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n88_j_ex_ds_test) 8 | .globl n88_j_ex_ds_test 9 | n88_j_ex_ds_test: 10 | .set noreorder 11 | li a0, 0x58 12 | # li v0, 0x09 13 | ###test inst 14 | TEST_J_EX_DS_EX_ADDI 15 | TEST_J_EX_DS_EX_ADD 16 | TEST_J_EX_DS_EX_SUB 17 | TEST_J_EX_DS_EX_LH 18 | TEST_J_EX_DS_EX_LHU 19 | TEST_J_EX_DS_EX_LW 20 | TEST_J_EX_DS_EX_SH 21 | TEST_J_EX_DS_EX_SW 22 | TEST_J_EX_DS_EX_RI 23 | TEST_J_EX_DS_EX_SYSCALL 24 | TEST_J_EX_DS_EX_BREAK 25 | ###detect exception 26 | # lui s0, 0x4444 27 | # bne v0, s0, inst_error 28 | # nop 29 | ###score ++ 30 | addiu s3, s3, 1 31 | ###output a0|s3 32 | inst_error: 33 | sw s3, 0($23) 34 | sw a0, 0(s1) 35 | jr ra 36 | nop 37 | ####END(n88_j_ex_ds_test) 38 | -------------------------------------------------------------------------------- /func_test/inst/n89_jal_ex_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n89_jal_ex_ds_test) 8 | .globl n89_jal_ex_ds_test 9 | n89_jal_ex_ds_test: 10 | .set noreorder 11 | li a0, 0x59 12 | # li v0, 0x09 13 | ###test inst 14 | TEST_JAL_EX_DS_EX_ADDI 15 | TEST_JAL_EX_DS_EX_ADD 16 | TEST_JAL_EX_DS_EX_SUB 17 | TEST_JAL_EX_DS_EX_LH 18 | TEST_JAL_EX_DS_EX_LHU 19 | TEST_JAL_EX_DS_EX_LW 20 | TEST_JAL_EX_DS_EX_SH 21 | TEST_JAL_EX_DS_EX_SW 22 | TEST_JAL_EX_DS_EX_RI 23 | TEST_JAL_EX_DS_EX_SYSCALL 24 | TEST_JAL_EX_DS_EX_BREAK 25 | ###detect exception 26 | # lui s0, 0x4444 27 | # bne v0, s0, inst_error 28 | # nop 29 | ###score ++ 30 | addiu s3, s3, 1 31 | ###output a0|s3 32 | inst_error: 33 | sw s3, 0($23) 34 | sw a0, 0(s1) 35 | jr ra 36 | nop 37 | ####END(n89_jal_ex_ds_test) 38 | -------------------------------------------------------------------------------- /func_test/inst/n90_jr_ex_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n90_jr_ex_ds_test) 8 | .globl n90_jr_ex_ds_test 9 | n90_jr_ex_ds_test: 10 | .set noreorder 11 | li a0, 0x5A 12 | # li v0, 0x09 13 | ###test inst 14 | TEST_JR_EX_DS_EX_ADDI 15 | TEST_JR_EX_DS_EX_ADD 16 | TEST_JR_EX_DS_EX_SUB 17 | TEST_JR_EX_DS_EX_LH 18 | TEST_JR_EX_DS_EX_LHU 19 | TEST_JR_EX_DS_EX_LW 20 | TEST_JR_EX_DS_EX_SH 21 | TEST_JR_EX_DS_EX_SW 22 | TEST_JR_EX_DS_EX_RI 23 | TEST_JR_EX_DS_EX_SYSCALL 24 | TEST_JR_EX_DS_EX_BREAK 25 | ###detect exception 26 | # lui s0, 0x4444 27 | # bne v0, s0, inst_error 28 | # nop 29 | ###score ++ 30 | addiu s3, s3, 1 31 | ###output a0|s3 32 | inst_error: 33 | sw s3, 0($23) 34 | sw a0, 0(s1) 35 | jr ra 36 | nop 37 | ####END(n90_jr_ex_ds_test) 38 | -------------------------------------------------------------------------------- /func_test/inst/n91_jalr_ex_ds.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ###LEAF(n91_jalr_ex_ds_test) 8 | .globl n91_jalr_ex_ds_test 9 | n91_jalr_ex_ds_test: 10 | .set noreorder 11 | li a0, 0x5B 12 | # li v0, 0x09 13 | ###test inst 14 | TEST_JALR_EX_DS_EX_ADDI 15 | TEST_JALR_EX_DS_EX_ADD 16 | TEST_JALR_EX_DS_EX_SUB 17 | TEST_JALR_EX_DS_EX_LH 18 | TEST_JALR_EX_DS_EX_LHU 19 | TEST_JALR_EX_DS_EX_LW 20 | TEST_JALR_EX_DS_EX_SH 21 | TEST_JALR_EX_DS_EX_SW 22 | TEST_JALR_EX_DS_EX_RI 23 | TEST_JALR_EX_DS_EX_SYSCALL 24 | TEST_JALR_EX_DS_EX_BREAK 25 | ###detect exception 26 | # lui s0, 0x4444 27 | # bne v0, s0, inst_error 28 | # nop 29 | ###score ++ 30 | addiu s3, s3, 1 31 | ###output a0|s3 32 | inst_error: 33 | sw s3, 0($23) 34 | sw a0, 0(s1) 35 | jr ra 36 | nop 37 | ####END(n91_jalr_ex_ds_test) 38 | -------------------------------------------------------------------------------- /func_test/inst/n92_tlbwi.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ### refers to testcase No.55 8 | 9 | LEAF(n92_tlbwi_test) 10 | .set noreorder 11 | li a0, 0x5c 12 | ###test inst 13 | li s2, 0x0000 14 | li k0, 0x0010 15 | test_phase1_start: 16 | mtc0 s2, c0_index 17 | lui v0, 0xefe8 18 | ori v0, 0xdc03 19 | sll t1, s2, 0x10 20 | li s0, 0xf124 21 | add s0, t1, s0 22 | lui a3, 0xabcd 23 | ori a3, 0xef81 24 | sw a3, 0(s0) 25 | nop 26 | nop 27 | nop 28 | nop 29 | nop 30 | lui t0, 0xed12 31 | ori t0, 0x5678 32 | bne v1, t0, inst_error 33 | nop 34 | li s0, 0xf124 35 | lw t0, 0(s0) 36 | lui s0, 0xabcd 37 | ori s0, 0xef81 38 | bne s0, t0, inst_error 39 | nop 40 | addiu s2, 0x0001 41 | bne k0, s2, test_phase1_start 42 | nop 43 | li v0, 0x0000 44 | li k0, 0x0010 45 | nop 46 | li v1, 0x0000 47 | test_phase2_start: 48 | li s0, 0xf124 49 | sll t1, v0, 0x10 50 | add s0, t1, s0 51 | lw t1, 0(s0) 52 | lui a3, 0xabcd 53 | ori a3, 0xef81 54 | bne t1, a3, inst_error 55 | nop 56 | addiu v0, 0x0001 57 | li t1, 0x0000 58 | bne t1, v1, inst_error 59 | nop 60 | bne v0, k0, test_phase2_start 61 | nop 62 | ###score ++ 63 | addiu s3, s3, 1 64 | ###output a0|s3 65 | inst_error: 66 | sw s3, 0($23) 67 | sw a0, 0(s1) 68 | jr ra 69 | nop 70 | END(n92_tlbwi_test) 71 | -------------------------------------------------------------------------------- /func_test/inst/n93_tlbwr.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ### refers to testcase No.55 8 | 9 | LEAF(n93_tlbwr_test) 10 | .set noreorder 11 | li a0, 0x5d 12 | ###test inst 13 | test_gbit_start: 14 | lui v0, 0xffe8 15 | ori v0, 0xdc03 16 | lui s2, 0x0011 17 | ori s2, 0xe124 18 | lui s0, 0x0011 19 | ori s0, 0xe000 ##entry hi 20 | lui a3, 0x1234 21 | ori a3, 0x5867 22 | li k0, 0x0001 ##label tlbwr_allbit 23 | li t0, 0x4000 ##entry lo0 24 | li t1, 0x4000 ##entry lo1 25 | sw a3, 0(s2) 26 | nop 27 | nop 28 | nop 29 | nop 30 | nop 31 | lui t0, 0xed08 32 | ori t0, 0xdc16 33 | bne v1, t0, inst_error 34 | nop 35 | lui s2, 0x0011 36 | ori s2, 0xf124 37 | lw t0, 0(s2) 38 | lui a3, 0x1234 39 | ori a3, 0x5867 40 | bne a3, t0, inst_error 41 | nop 42 | li s2, 0x80100124 #bypass TLB 43 | lw t0, 0(s2) 44 | bne a3, t0, inst_error 45 | nop 46 | test_asid_match: 47 | lui v0, 0xffe8 48 | ori v0, 0xdc03 49 | lui s2, 0x0012 50 | ori s2, s2, 0xe124 51 | li k0, 0x0003 #label tlbwr_asid 52 | lui s0, 0x0012 53 | ori s0, 0xe0dc ##entry hi: 0x0012e0dc 54 | lui a3, 0xe235 55 | ori a3, 0xe8f7 56 | li t0, 0x4006 ##entry lo0 57 | li t1, 0x4006 ##entry lo1 58 | sw a3, 0(s2) ##access 0x0012e124 59 | nop 60 | nop 61 | nop 62 | nop 63 | nop 64 | lui t0, 0xed08 65 | ori t0, 0xdc18 66 | bne v1, t0, inst_error 67 | nop 68 | lui s0, 0x0013 69 | ori s0, 0xe0dc ##entry hi: 0x0013e0dc 70 | mtc0 s0, c0_entryhi #set current ASID 71 | lui s2, 0x0013 72 | ori s2, 0xf124 73 | li t0, 0x4006 ##entry lo0 74 | li t1, 0x4006 ##entry lo1 75 | lw t0, 0(s2) ##access 0x0013f124 76 | lui a3, 0xe235 77 | ori a3, 0xe8f7 78 | bne a3, t0, inst_error 79 | nop 80 | test_asid_2: 81 | lui v0, 0xffe8 82 | ori v0, 0xdc03 83 | lui s2, 0x0014 84 | ori s2, s2, 0xe124 85 | li k0, 0x0003 #label tlbwr_asid 86 | lui s0, 0x0014 87 | ori s0, 0xe0dc ##entry hi: 0x0014e0dc 88 | lui a3, 0xbd86 89 | ori a3, 0x13ac 90 | li t0, 0x4006 ##entry lo0 91 | li t1, 0x4000 ##entry lo1 92 | sw a3, 0(s2) 93 | nop 94 | nop 95 | nop 96 | nop 97 | nop 98 | lui t0, 0xed08 99 | ori t0, 0xdc18 100 | bne v1, t0, inst_error 101 | nop 102 | lui s2, 0x0015 103 | ori s2, 0xf124 104 | lui s0, 0x0015 105 | ori s0, 0xe0dc ##entry hi: 0x0015e0dc 106 | li t0, 0x4000 ##entry lo0 107 | li t1, 0x4002 ##entry lo1 108 | li k0, 0x0003 #label tlbwr_asid 109 | lw a3, 0(s2) 110 | lui a3, 0xed08 111 | ori a3, 0xdc18 112 | bne a3, v1, inst_error 113 | nop 114 | ###score ++ 115 | addiu s3, s3, 1 116 | ###output a0|s3 117 | inst_error: 118 | sw s3, 0($23) 119 | sw a0, 0(s1) 120 | jr ra 121 | nop 122 | END(n93_tlbwr_test) 123 | -------------------------------------------------------------------------------- /func_test/rules.make: -------------------------------------------------------------------------------- 1 | .S.o: 2 | ${CROSS_COMPILE}gcc -O2 $(CFLAGS) -fno-pic -mno-abicalls -g -DGUEST -I include -I . -c $< -nostdinc -nostdlib 3 | .c.o: 4 | ${CROSS_COMPILE}gcc -O2 $(CFLAGS) -fno-pic -mno-abicalls -g -DGUEST -I include -I . -c $< -nostdinc -nostdlib 5 | .S.s: 6 | ${CROSS_COMPILE}gcc -O2 $(CFLAGS) -fno-pic -mno-abicalls -g -DGUEST -I include -I . -S -fverbose-asm -o $@ $< -nostdinc -nostdlib 7 | .c.s: 8 | ${CROSS_COMPILE}gcc -O2 $(CFLAGS) -fno-pic -mno-abicalls -g -DGUEST -I include -I . -S -fverbose-asm -o $@ $< -nostdinc -nostdlib 9 | -------------------------------------------------------------------------------- /perf_test/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.bin 3 | *.elf 4 | *.a 5 | testbin 6 | *.o64 7 | *.bin64 8 | *.elf64 9 | *.s 10 | *.vlog 11 | convert 12 | *.coe 13 | *.data 14 | bin.lds 15 | *.mif 16 | -------------------------------------------------------------------------------- /perf_test/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS := -D_KERNEL -DCONFIG_PAGE_SIZE_16KB -fno-builtin -mips1 -DCACHELOCK_MEM -DMEMSTART=0x80000000 -DMEMSIZE=0x00100000 -DCPU_COUNT_PER_US=1000 -I include -include common.h -DAPB_CLK=33333333 2 | CFLAGS += -DLS1FSOC -DCPU_MULT=6 -DDDR_MULT=6 -msoft-float -nostdlib 3 | 4 | export AR CFLAGS 5 | export CROSS_COMPILE ?= mipsel-linux-gnu- 6 | 7 | OBJDIR = obj 8 | 9 | all: bitcount stringsearch coremark dhrystone sha crc32 quick_sort bubble_sort select_sort stream_copy 10 | 11 | bitcount: 12 | $(eval export BENCH = $@) 13 | make target_bench 14 | 15 | stringsearch: 16 | $(eval export BENCH = $@) 17 | make target_bench 18 | 19 | coremark: 20 | $(eval export BENCH = $@) 21 | make target_bench 22 | 23 | dhrystone: 24 | $(eval export BENCH = $@) 25 | make target_bench 26 | 27 | sha: 28 | $(eval export BENCH = $@) 29 | make target_bench 30 | 31 | crc32: 32 | $(eval export BENCH = $@) 33 | make target_bench 34 | 35 | quick_sort: 36 | $(eval export BENCH = $@) 37 | make target_bench 38 | 39 | bubble_sort: 40 | $(eval export BENCH = $@) 41 | make target_bench 42 | 43 | select_sort: 44 | $(eval export BENCH = $@) 45 | make target_bench 46 | 47 | stream_copy: 48 | $(eval export BENCH = $@) 49 | make target_bench 50 | 51 | libtinyc.a libtinyc64.a: 52 | make -C lib $@ 53 | 54 | .SUFFIXES: .o64 .elf64 .bin64 55 | 56 | target_bench: 57 | $(eval export BENCH_DIR = $(BENCH)) 58 | $(eval export BENCH_LIB = $(BENCH).a) 59 | make -C bench/$(BENCH_DIR) 60 | mkdir -p $(OBJDIR)/$(BENCH_DIR) 61 | make generate 62 | 63 | generate: main.base.bin main.ext.bin split_bin 64 | 65 | main.base.bin: main.bin split_bin 66 | ./split_bin $(OBJDIR)/$(BENCH_DIR)/main.bin $(OBJDIR)/$(BENCH_DIR)/main.ext.bin $(OBJDIR)/$(BENCH_DIR)/main.base.bin 67 | 68 | main.ext.bin: main.base.bin 69 | 70 | main.bin: main.elf 71 | ${CROSS_COMPILE}objcopy -O binary -j .text -j .data -j .bss $(OBJDIR)/$(BENCH_DIR)/$< $(OBJDIR)/$(BENCH_DIR)/$@ 72 | 73 | 74 | main.elf: start.o libtinyc.a bin.lds 75 | ${CROSS_COMPILE}ld -g -T bin.lds start.o bench/$(BENCH_DIR)/$(BENCH_LIB) lib/libtinyc.a -o $(OBJDIR)/$(BENCH_DIR)/$@ 76 | ${CROSS_COMPILE}objdump -ald $(OBJDIR)/$(BENCH_DIR)/$@ > $(OBJDIR)/$(BENCH_DIR)/test.s 77 | 78 | bin.lds: bin.lds.S 79 | ${CROSS_COMPILE}gcc -E -P -Umips -D_LOADER -U_MAIN $(CFLAGS) $< -o $@ 80 | 81 | start.o: start.S 82 | ${CROSS_COMPILE}gcc -O2 $(CFLAGS) -fno-pic -mno-abicalls -g -DGUEST -I ../include -c $< -nostdinc -nostdlib 83 | 84 | split_bin: ../utility/split_bin.cpp 85 | g++ -std=c++11 -Wall -Werror -O2 -o $@ $< 86 | 87 | clean: 88 | rm -f *.o *.bin *.elf *.a *.s split_bin bin.lds 89 | rm -rf obj 90 | make -C lib clean 91 | make -C bench clean 92 | 93 | #-include rules.make 94 | -------------------------------------------------------------------------------- /perf_test/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## 目录结构 3 | ``` 4 | 5 | +--./ : 性能测试目录 6 | | 7 | |--bench/ : 测试程序的源代码目录 8 | | 9 | |--include/ : 编译所需的头文件目录 10 | | 11 | |--lib/ : 编译所需的库文件目录 12 | | 13 | |--obj/ : 编译生成的目标文件目录 14 | | 15 | |--bin.lds.S : 链接脚本生成文件 16 | | 17 | |--start.S : 测试程序的启动代码 18 | | 19 | |--Makefile : 编译脚本 20 | ``` 21 | 22 | ## 编译方法 23 | 24 | 1. 编译前,请保证已经配置好交叉编译环境。 25 | 26 | 2. 在当前目录下执行make,即可在obj目录下生成测试所需的所有文件。如果只想编译某一个测试程序,请执行make [程序名],例如:make bitcount。想清除所有编译文件请执行make clean。 27 | 28 | 3. 关于obj目录。 29 | 30 | a. obj下的子目录以测试程序的名字命名 31 | 32 | b. 子目录下,main.elf是中间文件,test.s是程序的反汇编文件,main.bin 是最后生成的内存初始化文件(应放置于内存偏移0x0,即地址0x80000000处) 33 | 34 | ## 使用说明 35 | 36 | 程序需要串口支持,在 `include/machine.h` 中定义了两个地址,其中 `UART_STATUS_ADDR` 的最低位用于判断是否可发送,`UART_DATA_ADDR` 用于发送数据(只有最低8位)。同时也需要一些计时手段,所有测试程序将会读取`TIMER_CYCLE_ADDR` 中存储CPU运行的时钟周期数量,以及 `TIMER_MICROSEC_ADDR` 中存储的每微秒自增的值。 -------------------------------------------------------------------------------- /perf_test/bench/Makefile: -------------------------------------------------------------------------------- 1 | clean: 2 | make -C bitcount clean 3 | make -C stringsearch clean 4 | make -C coremark clean 5 | make -C dhrystone clean 6 | make -C sha clean 7 | make -C crc32 clean 8 | make -C quick_sort clean 9 | make -C bubble_sort clean 10 | make -C select_sort clean 11 | make -C stream_copy clean 12 | -------------------------------------------------------------------------------- /perf_test/bench/bitcount/LICENSE: -------------------------------------------------------------------------------- 1 | From http://www.snippets.org/. 2 | 3 | This code is FREE with no restrictions. 4 | -------------------------------------------------------------------------------- /perf_test/bench/bitcount/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -O3 -mno-abicalls -funroll-all-loops -falign-jumps=16 -falign-functions=16 -fgcse-sm -fgcse-las -finline-functions -finline-limit=1000 -msoft-float -EL -march=mips1 -mips1 2 | CFLAGS += -G8 -DTIME 3 | CFLAGS += -I . -I ../../include -include stdio.h 4 | 5 | all: $(patsubst %.c, %.o, $(wildcard *.c)) 6 | $(CROSS_COMPILE)ar -cr bitcount.a $^ 7 | 8 | %.o: %.c 9 | $(CROSS_COMPILE)gcc $(CFLAGS) -c $< 10 | 11 | clean: 12 | rm -f *.o 13 | rm -f *.a 14 | -------------------------------------------------------------------------------- /perf_test/bench/bitcount/bitarray.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** Functions to maintain an arbitrary length array of bits 5 | */ 6 | 7 | #include "bitops.h" 8 | 9 | char *alloc_bit_array(size_t bits) 10 | { 11 | char *set = malloc((bits + CHAR_BIT - 1) / CHAR_BIT * sizeof(char)); 12 | 13 | return set; 14 | } 15 | 16 | int getbit(char *set, int number) 17 | { 18 | set += number / CHAR_BIT; 19 | return (*set & (1 << (number % CHAR_BIT))) != 0; /* 0 or 1 */ 20 | } 21 | 22 | void setbit(char *set, int number, int value) 23 | { 24 | set += number / CHAR_BIT; 25 | if (value) 26 | *set |= 1 << (number % CHAR_BIT); /* set bit */ 27 | else *set &= ~(1 << (number % CHAR_BIT)); /* clear bit*/ 28 | } 29 | 30 | void flipbit(char *set, int number) 31 | { 32 | set += number / CHAR_BIT; 33 | *set ^= 1 << (number % CHAR_BIT); /* flip bit */ 34 | } 35 | -------------------------------------------------------------------------------- /perf_test/bench/bitcount/bitcnt_1.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** Bit counter by Ratko Tomic 5 | */ 6 | 7 | #include "bitops.h" 8 | 9 | int CDECL bit_count(long x) 10 | { 11 | int n = 0; 12 | /* 13 | ** The loop will execute once for each bit of x set, this is in average 14 | ** twice as fast as the shift/test method. 15 | */ 16 | if (x) do 17 | n++; 18 | while (0 != (x = x&(x-1))) ; 19 | return(n); 20 | } 21 | 22 | #ifdef TEST 23 | 24 | #include 25 | #include "snip_str.h" /* For plural_text() macro */ 26 | 27 | main(int argc, char *argv[]) 28 | { 29 | long n; 30 | 31 | while(--argc) 32 | { 33 | int i; 34 | 35 | n = atol(*++argv); 36 | i = bit_count(n); 37 | printf("%ld contains %d bit%s set\n", 38 | n, i, plural_text(i)); 39 | } 40 | return 0; 41 | } 42 | 43 | #endif /* TEST */ 44 | -------------------------------------------------------------------------------- /perf_test/bench/bitcount/bitcnt_2.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** Bit counter by Ratko Tomic 5 | */ 6 | 7 | #include "bitops.h" 8 | 9 | int CDECL bitcount(long i) 10 | { 11 | i = ((i & 0xAAAAAAAAL) >> 1) + (i & 0x55555555L); 12 | i = ((i & 0xCCCCCCCCL) >> 2) + (i & 0x33333333L); 13 | i = ((i & 0xF0F0F0F0L) >> 4) + (i & 0x0F0F0F0FL); 14 | i = ((i & 0xFF00FF00L) >> 8) + (i & 0x00FF00FFL); 15 | i = ((i & 0xFFFF0000L) >> 16) + (i & 0x0000FFFFL); 16 | return (int)i; 17 | } 18 | 19 | #ifdef TEST 20 | 21 | #include 22 | #include "snip_str.h" /* For plural_text() macro */ 23 | 24 | main(int argc, char *argv[]) 25 | { 26 | long n; 27 | 28 | while(--argc) 29 | { 30 | int i; 31 | 32 | n = atol(*++argv); 33 | i = bitcount(n); 34 | printf("%ld contains %d bit%s set\n", 35 | n, i, plural_text(i)); 36 | } 37 | return 0; 38 | } 39 | 40 | #endif /* TEST */ 41 | -------------------------------------------------------------------------------- /perf_test/bench/bitcount/bitcnt_3.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** BITCNT_3.C - Bit counting functions using table lookup 5 | ** 6 | ** public domain by Auke Reitsma and Bruce Wedding 7 | */ 8 | 9 | #include "bitops.h" /* from Snippets */ 10 | 11 | /* 12 | ** Bits table 13 | */ 14 | 15 | static char bits[256] = 16 | { 17 | 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, /* 0 - 15 */ 18 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, /* 16 - 31 */ 19 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, /* 32 - 47 */ 20 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 48 - 63 */ 21 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, /* 64 - 79 */ 22 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 80 - 95 */ 23 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 96 - 111 */ 24 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, /* 112 - 127 */ 25 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, /* 128 - 143 */ 26 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 144 - 159 */ 27 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 160 - 175 */ 28 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, /* 176 - 191 */ 29 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 192 - 207 */ 30 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, /* 208 - 223 */ 31 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, /* 224 - 239 */ 32 | 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 /* 240 - 255 */ 33 | }; 34 | 35 | /* 36 | ** Count bits in each nybble 37 | ** 38 | ** Note: Only the first 16 table entries are used, the rest could be 39 | ** omitted. 40 | */ 41 | 42 | int CDECL ntbl_bitcount(long int x) 43 | { 44 | return 45 | bits[ (int) (x & 0x0000000FUL) ] + 46 | bits[ (int)((x & 0x000000F0UL) >> 4) ] + 47 | bits[ (int)((x & 0x00000F00UL) >> 8) ] + 48 | bits[ (int)((x & 0x0000F000UL) >> 12)] + 49 | bits[ (int)((x & 0x000F0000UL) >> 16)] + 50 | bits[ (int)((x & 0x00F00000UL) >> 20)] + 51 | bits[ (int)((x & 0x0F000000UL) >> 24)] + 52 | bits[ (int)((x & 0xF0000000UL) >> 28)]; 53 | } 54 | 55 | /* 56 | ** Count bits in each byte 57 | ** 58 | ** by Bruce Wedding, works best on Watcom & Borland 59 | */ 60 | 61 | int CDECL BW_btbl_bitcount(long int x) 62 | { 63 | union 64 | { 65 | unsigned char ch[4]; 66 | long y; 67 | } U; 68 | 69 | U.y = x; 70 | 71 | return bits[ U.ch[0] ] + bits[ U.ch[1] ] + 72 | bits[ U.ch[3] ] + bits[ U.ch[2] ]; 73 | } 74 | 75 | /* 76 | ** Count bits in each byte 77 | ** 78 | ** by Auke Reitsma, works best on Microsoft, Symantec, and others 79 | */ 80 | 81 | int CDECL AR_btbl_bitcount(long int x) 82 | { 83 | unsigned char * Ptr = (unsigned char *) &x ; 84 | int Accu ; 85 | 86 | Accu = bits[ *Ptr++ ]; 87 | Accu += bits[ *Ptr++ ]; 88 | Accu += bits[ *Ptr++ ]; 89 | Accu += bits[ *Ptr ]; 90 | return Accu; 91 | } 92 | 93 | #ifdef TEST 94 | 95 | #include 96 | #include "snip_str.h" /* For plural_text() macro */ 97 | 98 | main(int argc, char *argv[]) 99 | { 100 | long n; 101 | 102 | while(--argc) 103 | { 104 | int i; 105 | 106 | n = atol(*++argv); 107 | i = BW_btbl_bitcount(n); 108 | printf("%ld contains %d bit%s set\n", 109 | n, i, plural_text(i)); 110 | i = AR_btbl_bitcount(n); 111 | printf("%ld contains %d bit%s set\n", 112 | n, i, plural_text(i)); 113 | } 114 | return 0; 115 | } 116 | 117 | #endif /* TEST */ 118 | -------------------------------------------------------------------------------- /perf_test/bench/bitcount/bitcnt_4.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** BITCNT_4.C - Recursive bit counting functions using table lookup 5 | ** 6 | ** public domain by Bob Stout 7 | */ 8 | 9 | #include "bitops.h" /* from Snippets */ 10 | 11 | static char bits[256] = 12 | { 13 | 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, /* 0 - 15 */ 14 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, /* 16 - 31 */ 15 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, /* 32 - 47 */ 16 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 48 - 63 */ 17 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, /* 64 - 79 */ 18 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 80 - 95 */ 19 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 96 - 111 */ 20 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, /* 112 - 127 */ 21 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, /* 128 - 143 */ 22 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 144 - 159 */ 23 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 160 - 175 */ 24 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, /* 176 - 191 */ 25 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 192 - 207 */ 26 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, /* 208 - 223 */ 27 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, /* 224 - 239 */ 28 | 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 /* 240 - 255 */ 29 | }; 30 | 31 | /* 32 | ** Count bits in each nybble 33 | ** 34 | ** Note: Only the first 16 table entries are used, the rest could be 35 | ** omitted. 36 | */ 37 | 38 | int CDECL ntbl_bitcnt(long x) 39 | { 40 | int cnt = bits[(int)(x & 0x0000000FL)]; 41 | 42 | if (0L != (x >>= 4)) 43 | cnt += ntbl_bitcnt(x); 44 | 45 | return cnt; 46 | } 47 | 48 | /* 49 | ** Count bits in each byte 50 | */ 51 | 52 | int CDECL btbl_bitcnt(long x) 53 | { 54 | int cnt = bits[ ((char *)&x)[0] & 0xFF ]; 55 | 56 | if (0L != (x >>= 8)) 57 | cnt += btbl_bitcnt(x); 58 | return cnt; 59 | } 60 | 61 | #ifdef TEST 62 | 63 | #include 64 | #include "snip_str.h" /* For plural_text() macro */ 65 | 66 | main(int argc, char *argv[]) 67 | { 68 | long n; 69 | 70 | while(--argc) 71 | { 72 | int i; 73 | 74 | n = atol(*++argv); 75 | i = btbl_bitcnt(n); 76 | printf("%ld contains %d bit%s set\n", 77 | n, i, plural_text(i)); 78 | } 79 | return 0; 80 | } 81 | 82 | #endif /* TEST */ 83 | -------------------------------------------------------------------------------- /perf_test/bench/bitcount/bitcnts.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** BITCNTS.C - Test program for bit counting functions 5 | ** 6 | ** public domain by Bob Stout & Auke Reitsma 7 | */ 8 | 9 | #include 10 | #include "conio.h" 11 | #include "bitops.h" 12 | #include "time.h" 13 | 14 | #define FUNCS 7 15 | 16 | static int CDECL bit_shifter(long int x); 17 | 18 | unsigned long myrand() 19 | { 20 | unsigned long lfsr = 0xACE1u; 21 | unsigned long bit; 22 | 23 | bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5) ) & 1; 24 | return lfsr = (lfsr >> 1) | (bit << 15); 25 | } 26 | 27 | int bitcnts(int argc, long argv) 28 | { 29 | unsigned long start_ns = 0; 30 | unsigned long stop_ns = 0; 31 | 32 | unsigned long ct, cmin = 0xffffffffffffffff, cmax = 0; 33 | int i, cminix, cmaxix; 34 | long j, n, seed; 35 | int iterations; 36 | 37 | static int (* CDECL pBitCntFunc[FUNCS])(long) = { 38 | bit_count, 39 | bitcount, 40 | ntbl_bitcnt, 41 | ntbl_bitcount, 42 | /* btbl_bitcnt, DOESNT WORK*/ 43 | BW_btbl_bitcount, 44 | AR_btbl_bitcount, 45 | bit_shifter 46 | }; 47 | 48 | static char *text[FUNCS] = { 49 | "Optimized 1 bit/loop counter", 50 | "Ratko's mystery algorithm", 51 | "Recursive bit count by nybbles", 52 | "Non-recursive bit count by nybbles", 53 | /* "Recursive bit count by bytes",*/ 54 | "Non-recursive bit count by bytes (BW)", 55 | "Non-recursive bit count by bytes (AR)", 56 | "Shift and count bits" 57 | }; 58 | 59 | iterations=(int)argv; 60 | puts("Bit counter algorithm benchmark\n"); 61 | start_ns = get_ns(); 62 | 63 | for (i = 0; i < FUNCS; i++) { 64 | for (j = n = 0, seed = myrand(); j < iterations; j++, seed += 13) 65 | { 66 | n += pBitCntFunc[i](seed); 67 | } 68 | } 69 | stop_ns = get_ns(); 70 | ct = (stop_ns - start_ns); 71 | 72 | return n; 73 | } 74 | 75 | static int CDECL bit_shifter(long int x) 76 | { 77 | int i, n; 78 | 79 | for (i = n = 0; x && (i < (sizeof(long) * CHAR_BIT)); ++i, x >>= 1) 80 | n += (int)(x & 1L); 81 | return n; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /perf_test/bench/bitcount/bitops.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** Macros and prototypes for bit operations 5 | ** 6 | ** public domain for SNIPPETS by: 7 | ** Scott Dudley 8 | ** Auke Reitsma 9 | ** Ratko Tomic 10 | ** Aare Tali 11 | ** J. Blauth 12 | ** Bruce Wedding 13 | ** Bob Stout 14 | */ 15 | 16 | #ifndef BITOPS__H 17 | #define BITOPS__H 18 | 19 | #include 20 | //#include /* For size_t */ 21 | //#include /* For CHAR_BIT */ 22 | #include "sniptype.h" /* For TOBOOL() */ 23 | #include "extkword.h" /* For CDECL */ 24 | 25 | /* 26 | ** Macros to manipulate bits in any integral data type. 27 | */ 28 | 29 | #define BitSet(arg,posn) ((arg) | (1L << (posn))) 30 | #define BitClr(arg,posn) ((arg) & ~(1L << (posn))) 31 | #define BitFlp(arg,posn) ((arg) ^ (1L << (posn))) 32 | #define BitTst(arg,posn) TOBOOL((arg) & (1L << (posn))) 33 | 34 | /* 35 | ** Macros to manipulate bits in an array of char. 36 | ** These macros assume CHAR_BIT is one of either 8, 16, or 32. 37 | */ 38 | #define CHAR_BIT 8 39 | 40 | #define MASK CHAR_BIT-1 41 | #define SHIFT ((CHAR_BIT==8)?3:(CHAR_BIT==16)?4:8) 42 | 43 | #define BitOff(a,x) ((void)((a)[(x)>>SHIFT] &= ~(1 << ((x)&MASK)))) 44 | #define BitOn(a,x) ((void)((a)[(x)>>SHIFT] |= (1 << ((x)&MASK)))) 45 | #define BitFlip(a,x) ((void)((a)[(x)>>SHIFT] ^= (1 << ((x)&MASK)))) 46 | #define IsBit(a,x) ((a)[(x)>>SHIFT] & (1 << ((x)&MASK))) 47 | 48 | /* 49 | ** BITARRAY.C 50 | */ 51 | 52 | char *alloc_bit_array(size_t bits); 53 | int getbit(char *set, int number); 54 | void setbit(char *set, int number, int value); 55 | void flipbit(char *set, int number); 56 | 57 | /* 58 | ** BITFILES.C 59 | */ 60 | 61 | ////////typedef struct { 62 | //////// FILE * file; /* for stream I/O */ 63 | //////// char rbuf; /* read bit buffer */ 64 | //////// char rcnt; /* read bit count */ 65 | //////// char wbuf; /* write bit buffer */ 66 | //////// char wcnt; /* write bit count */ 67 | ////////} bfile; 68 | 69 | // bfile * bfopen(char *name, char *mode); // zyw 70 | // int bfread(bfile *bf); 71 | // void bfwrite(int bit, bfile *bf); 72 | // void bfclose(bfile *bf); 73 | 74 | /* 75 | ** BITSTRNG.C 76 | */ 77 | 78 | void bitstring(char *str, long byze, int biz, int strwid); 79 | 80 | /* 81 | ** BSTR_I.C 82 | */ 83 | 84 | unsigned int bstr_i(char *cptr); 85 | 86 | /* 87 | ** BITCNT_1.C 88 | */ 89 | 90 | int CDECL bit_count(long x); 91 | 92 | /* 93 | ** BITCNT_2.C 94 | */ 95 | 96 | int CDECL bitcount(long i); 97 | 98 | /* 99 | ** BITCNT_3.C 100 | */ 101 | 102 | int CDECL ntbl_bitcount(long int x); 103 | int CDECL BW_btbl_bitcount(long int x); 104 | int CDECL AR_btbl_bitcount(long int x); 105 | 106 | /* 107 | ** BITCNT_4.C 108 | */ 109 | 110 | int CDECL ntbl_bitcnt(long x); 111 | int CDECL btbl_bitcnt(long x); 112 | 113 | #endif /* BITOPS__H */ 114 | -------------------------------------------------------------------------------- /perf_test/bench/bitcount/bitstrng.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** bitstring(): print bit pattern of bytes formatted to string. 5 | ** 6 | ** By J. Blauth, Sept. 1992. Hereby placed into the public domain. 7 | ** 8 | ** byze: value to transform to bitstring. 9 | ** biz: count of bits to be shown (counted from lowest bit, can be any 10 | ** even or odd number). 11 | ** strwid: total width the string shall have. Since between every 4 bits a 12 | ** blank (0x20) is inserted (not added after lowest bit), width of 13 | ** bitformat only is (biz+(biz/4-1)). Bits are printed right aligned, 14 | ** positions from highest bit to start of string filled with blanks. 15 | ** If value of strwid smaller than space needed to print all bits, 16 | ** strwid is ignored (e.g.: 17 | ** bitstr(s,b,16,5) results in 19 chars +'\0'). 18 | ** 19 | ** EXAMPLE: 20 | ** for (j = 1; j <= 16; j++) { bitstring(s, j, j, 16); puts(s); } 21 | ** 1: 1 22 | ** 2: 10 23 | ** 3: 011 24 | ** d: 0 0000 0000 1101 25 | ** e: 00 0000 0000 1110 26 | ** f: 000 0000 0000 1111 27 | */ 28 | 29 | #include "bitops.h" 30 | 31 | void bitstring(char *str, long byze, int biz, int strwid) 32 | { 33 | int i, j; 34 | 35 | j = strwid - (biz + (biz >> 2)- (biz % 4 ? 0 : 1)); 36 | for (i = 0; i < j; i++) 37 | *str++ = ' '; 38 | while (--biz >= 0) 39 | { 40 | *str++ = ((byze >> biz) & 1) + '0'; 41 | if (!(biz % 4) && biz) 42 | *str++ = ' '; 43 | } 44 | *str = '\0'; 45 | } 46 | 47 | #ifdef TEST 48 | 49 | #include 50 | 51 | int main(void) 52 | { 53 | char s[80]; long j; 54 | for (j = 1L; j <= 16L; j++) 55 | { 56 | bitstring(s, (long)j, (int)j, 16); 57 | printf("%2ld: %s\n", j, s); 58 | } 59 | return EXIT_SUCCESS; 60 | } 61 | 62 | #endif /* TEST */ 63 | -------------------------------------------------------------------------------- /perf_test/bench/bitcount/bstr_i.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** Make an ascii binary string into an integer. 5 | ** 6 | ** Public domain by Bob Stout 7 | */ 8 | 9 | //#include 10 | #include "bitops.h" 11 | 12 | unsigned int bstr_i(char *cptr) 13 | { 14 | unsigned int i, j = 0; 15 | 16 | while (cptr && *cptr && strchr("01", *cptr)) 17 | { 18 | i = *cptr++ - '0'; 19 | j <<= 1; 20 | j |= (i & 0x01); 21 | } 22 | return(j); 23 | } 24 | 25 | #ifdef TEST 26 | 27 | #include 28 | 29 | int main(int argc, char *argv[]) 30 | { 31 | char *arg; 32 | unsigned int x; 33 | 34 | while (--argc) 35 | { 36 | x = bstr_i(arg = *++argv); 37 | printf("Binary %s = %d = %04Xh\n", arg, x, x); 38 | } 39 | return EXIT_SUCCESS; 40 | } 41 | 42 | #endif /* TEST */ 43 | -------------------------------------------------------------------------------- /perf_test/bench/bitcount/conio.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** UNXCONIO.H - Port crucial DOS|Win|OS/2 non-blocking console I/O 5 | ** functions to Unix/Posix. 6 | ** 7 | ** public domain SNIPPETS header for use with Steve Poole's TERM_OPT.C 8 | */ 9 | 10 | #ifndef UNXCONIO__H 11 | #define UNXCONIO__H 12 | 13 | #include 14 | //#include 15 | 16 | #define echo_on() term_option(0) 17 | #define echo_off() term_option(1) 18 | 19 | int term_option(); 20 | int getch(); 21 | 22 | #endif /* UNXCONIO__H */ 23 | -------------------------------------------------------------------------------- /perf_test/bench/bitcount/extkword.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /*==================================================================== 4 | 5 | _MSC_VER Microsoft C 6.0 and later 6 | _QC Microsoft Quick C 2.51 and later 7 | __TURBOC__ Borland Turbo C, Turbo C++ and BC++ 8 | __BORLANDC__ Borland C++ 9 | __ZTC__ Zortech C and C++ 10 | __SC__ Symantec C++ 11 | __WATCOMC__ WATCOM C 12 | __POWERC Mix Power C 13 | __GNUC__ Gnu C 14 | 15 | Revised: 16 | 17 | 25-Sep-95 Bob Stout Original from PC-PORT.H 18 | 30-Mar-96 Ed Blackman OS/2 mods for OS/2 ver 2.0 and up 19 | 30-May-96 Andrew Clarke Added support for WATCOM C/C++ __NT__ macro. 20 | 17-Jun-96 Bob Stout Added __FLAT__ macros support 21 | 20-Aug-96 Bob Stout Eliminate Win32 conflicts 22 | ======================================================================*/ 23 | 24 | 25 | /* prevent multiple inclusions of this header file */ 26 | 27 | #ifndef EXTKWORD__H 28 | #define EXTKWORD__H 29 | 30 | //#include /* For INT_MAX, LONG_MAX */ 31 | 32 | /* 33 | ** Watcom defines __FLAT__ for 32-bit environments and so will we 34 | */ 35 | 36 | #if !defined(__FLAT__) && !defined(__WATCOMC__) && !defined(_MSC_VER) 37 | #if defined(__GNUC__) 38 | #define __FLAT__ 1 39 | #elif defined (_WIN32) || defined(WIN32) || defined(__NT__) 40 | #define __FLAT__ 1 41 | #elif defined(__INTSIZE) 42 | #if (4 == __INTSIZE) 43 | #define __FLAT__ 1 44 | #endif 45 | #elif (defined(__ZTC__) && !defined(__SC__)) || defined(__TURBOC__) 46 | // #if ((INT_MAX != SHRT_MAX) && (SHRT_MAX == 32767)) 47 | // #define __FLAT__ 1 48 | // #endif 49 | #endif 50 | #endif 51 | 52 | /* 53 | ** Correct extended keywords syntax 54 | */ 55 | 56 | #if defined(__OS2__) /* EBB: not sure this works for OS/2 1.x */ 57 | #include 58 | #define INTERRUPT 59 | #define HUGE 60 | #elif defined(_WIN32) || defined(WIN32) || defined(__NT__) 61 | #define WIN32_LEAN_AND_MEAN 62 | #define NOGDI 63 | #define NOSERVICE 64 | #undef INC_OLE1 65 | #undef INC_OLE2 66 | #include 67 | #define INTERRUPT 68 | #define HUGE 69 | #else /* ! Win 32 or OS/2 */ 70 | /* #if (defined(__POWERC) || (defined(__TURBOC__) && !defined(__BORLANDC__)) \ 71 | || (defined(__ZTC__) && !defined(__SC__))) && !defined(__FLAT__) 72 | #define FAR far 73 | #define NEAR near 74 | #define PASCAL pascal 75 | #define CDECL cdecl 76 | #if (defined(__ZTC__) && !defined(__SC__)) || (defined(__SC__) && \ 77 | (__SC__ < 0x700)) 78 | #define HUGE far 79 | #define INTERRUPT 80 | #else 81 | #define HUGE huge 82 | #define INTERRUPT interrupt 83 | #endif*/ 84 | /* #else 85 | #if (defined(__MSDOS__) || defined(MSDOS)) && !defined(__FLAT__) 86 | #define FAR _far 87 | #define NEAR _near 88 | #define HUGE _huge 89 | #define PASCAL _pascal 90 | #define CDECL _cdecl 91 | #define INTERRUPT _interrupt 92 | #else*/ 93 | #define FAR 94 | #define NEAR 95 | #define HUGE 96 | #define PASCAL 97 | #define CDECL 98 | #endif 99 | /* #endif 100 | #endif*/ 101 | 102 | #endif /* EXTKWORD__H */ 103 | -------------------------------------------------------------------------------- /perf_test/bench/bitcount/shell.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void shell() { 5 | TIMER_BEGIN 6 | 7 | int n = bitcnts(1, 100); 8 | 9 | TIMER_END 10 | 11 | printf("Bits: %ld\n", n); 12 | 13 | TIMER_PRINT 14 | 15 | return; 16 | } 17 | -------------------------------------------------------------------------------- /perf_test/bench/bitcount/sniptype.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** SNIPTYPE.H - Include file for SNIPPETS data types and commonly used macros 5 | */ 6 | 7 | #ifndef SNIPTYPE__H 8 | #define SNIPTYPE__H 9 | 10 | //#include /* For free() */ 11 | //#include /* For NULL & strlen() */ 12 | 13 | typedef enum {Error_ = -1, Success_, False_ = 0, True_} Boolean_T; 14 | 15 | /*#if !defined(WIN32) && !defined(_WIN32) && !defined(__NT__) \ 16 | && !defined(_WINDOWS) 17 | #if !defined(OS2)*/ 18 | typedef unsigned char BYTE; 19 | typedef unsigned long DWORD; 20 | /* #endif*/ 21 | typedef unsigned short WORD; 22 | /*#else 23 | #define WIN32_LEAN_AND_MEAN 24 | #define NOGDI 25 | #define NOSERVICE 26 | #undef INC_OLE1 27 | #undef INC_OLE2 28 | #include 29 | #define HUGE 30 | #endif*/ 31 | 32 | #define NUL '\0' 33 | //#define LAST_CHAR(s) (((char *)s)[strlen(s) - 1]) 34 | #define TOBOOL(x) (!(!(x))) 35 | //#define FREE(p) (free(p),(p)=NULL) 36 | 37 | #endif /* SNIPTYPE__H */ 38 | -------------------------------------------------------------------------------- /perf_test/bench/bubble_sort/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -O3 -mno-abicalls -funroll-all-loops -falign-jumps=16 -falign-functions=16 -fgcse-sm -fgcse-las -finline-functions -finline-limit=1000 -msoft-float -EL -march=mips1 -mips1 2 | CFLAGS += -G8 -DTIME 3 | CFLAGS += -I . -I ../../include -include stdio.h 4 | 5 | all: $(patsubst %.c, %.o, $(wildcard *.c)) 6 | $(CROSS_COMPILE)ar -cr bubble_sort.a $^ 7 | 8 | %.o: %.c 9 | $(CROSS_COMPILE)gcc $(CFLAGS) -c $< 10 | 11 | clean: 12 | rm -f *.o 13 | rm -f *.a 14 | -------------------------------------------------------------------------------- /perf_test/bench/bubble_sort/bubble_sort.c: -------------------------------------------------------------------------------- 1 | int result[1000]; 2 | int *bubble_sort(int *a, int N) { 3 | int m; 4 | for(m = 0; m <= N; m++) { 5 | result[m] = a[m]; 6 | } 7 | 8 | int i, j, t; 9 | for(j = 0; j < N; j ++) { 10 | for(i = 0; i < N - 1 - j; i ++) { 11 | if(result[i] > result[i + 1]) { 12 | t = result[i]; 13 | result[i] = result[i + 1]; 14 | result[i + 1] = t; 15 | } 16 | } 17 | } 18 | return result; 19 | } 20 | -------------------------------------------------------------------------------- /perf_test/bench/coremark/LICENSE.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trivialmips/TrivialMIPS_Software/eccb9fd7a6477f62d1c8c38c8cb76799280263dd/perf_test/bench/coremark/LICENSE.txt -------------------------------------------------------------------------------- /perf_test/bench/coremark/Makefile: -------------------------------------------------------------------------------- 1 | CC = $(CROSS_COMPILE)gcc 2 | LD = $(CROSS_COMPILE)ld 3 | OBJCOPY = $(CROSS_COMPILE)objcopy 4 | OBJDUMP = $(CROSS_COMPILE)objdump 5 | AR = $(CROSS_COMPILE)ar 6 | 7 | AFLAGS= -G 0 -fno-pic -pipe -mno-abicalls -EL -mips1 8 | CFLAGS+= -O3 -mno-abicalls -funroll-all-loops -falign-jumps=16 -falign-functions=16 -fgcse-sm -fgcse-las -finline-functions -finline-limit=1000 -msoft-float -EL -march=mips1 -mips1 9 | CFLAGS+= -I ../../include -include stdio.h -DCOREMARK_LOOP=1 10 | CFLAGS+= -I. -DFLAGS_STR=\"$(FLAGS_STR)\" 11 | CFLAGS+= -G8 12 | 13 | all:link 14 | $(AR) -cr coremark.a $(patsubst %.c, %.o, $(wildcard *.c)) 15 | echo "job done" 16 | 17 | ifndef $(ITERATIONS) 18 | ITERATIONS=0 19 | endif 20 | 21 | CFLAGS+= -DITERATIONS=$(ITERATIONS) -static 22 | 23 | CORE_FILES=core_list_join core_main core_matrix core_state core_util core_portme shell 24 | ORIG_SRCS=$(addsuffix .c,$(CORE_FILES)) 25 | OEXT=.o 26 | SRCS=$(ORIG_SRCS) 27 | OBIS=$(addsuffix $(OEXT), $(CORE_FILES)) 28 | HEADERS=coremark.h 29 | .PHONY:compile link 30 | compile: $(OPATH) $(SRCS) $(HEADERS) 31 | $(CC) $(CFLAGS) -c $(SRCS) 32 | link:compile 33 | @echo "link performed along with compile" 34 | .PHONY:clean 35 | clean: 36 | rm -rf *.o 37 | rm -rf *.a 38 | -------------------------------------------------------------------------------- /perf_test/bench/coremark/common_coremark.h: -------------------------------------------------------------------------------- 1 | #define SERIAL 0xffffffffff2001e0 2 | #include 3 | #ifndef __ASSEMBLER__ 4 | typedef void *va_list; 5 | #define va_start __builtin_va_start 6 | #define va_arg(ap,T) (*(T*)(((ap)+=sizeof(T))-sizeof(T))) 7 | #define va_end(...) 8 | #define __P(x) x 9 | typedef unsigned int u_int; 10 | typedef unsigned long u_long; 11 | typedef unsigned int uint2_t; 12 | typedef unsigned int size_t; 13 | #define isdigit(c) (c>='0' && c<='q') 14 | #define FMT_RJUST 0 15 | #define FMT_LJUST 1 16 | #define FMT_RJUST0 2 17 | #define FMT_CENTER 3 18 | #define NULL ((void *)0) 19 | #endif 20 | -------------------------------------------------------------------------------- /perf_test/bench/coremark/shell.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void shell() { 5 | 6 | TIMER_BEGIN 7 | 8 | int r = core_mark(0,0,0x66,COREMARK_LOOP,7,1,2000); 9 | 10 | TIMER_END 11 | 12 | TIMER_PRINT 13 | 14 | return; 15 | } 16 | -------------------------------------------------------------------------------- /perf_test/bench/crc32/LICENSE: -------------------------------------------------------------------------------- 1 | From http://www.snippets.org/. 2 | 3 | This code is FREE with no restrictions. 4 | -------------------------------------------------------------------------------- /perf_test/bench/crc32/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -O3 -mno-abicalls -funroll-all-loops -falign-jumps=16 -falign-functions=16 -fgcse-sm -fgcse-las -finline-functions -finline-limit=1000 -msoft-float -EL -march=mips1 -mips1 2 | CFLAGS += -G8 -DTIME 3 | CFLAGS += -I . -I ../../include 4 | 5 | all: $(patsubst %.c, %.o, $(wildcard *.c)) 6 | $(CROSS_COMPILE)ar -cr crc32.a $^ 7 | 8 | %.o: %.c 9 | $(CROSS_COMPILE)gcc $(CFLAGS) -c $< 10 | 11 | clean: 12 | rm -f *.o 13 | rm -f *.a 14 | -------------------------------------------------------------------------------- /perf_test/bench/crc32/crc.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** CRC.H - header file for SNIPPETS CRC and checksum functions 5 | */ 6 | 7 | #ifndef CRC__H 8 | #define CRC__H 9 | 10 | #include /* For size_t */ 11 | #include "sniptype.h" /* For BYTE, WORD, DWORD */ 12 | 13 | /* 14 | ** File: ARCCRC16.C 15 | */ 16 | 17 | void init_crc_table(void); 18 | WORD crc_calc(WORD crc, char *buf, unsigned nbytes); 19 | void do_file(char *fn); 20 | 21 | /* 22 | ** File: CRC-16.C 23 | */ 24 | 25 | WORD crc16(char *data_p, WORD length); 26 | 27 | /* 28 | ** File: CRC-16F.C 29 | */ 30 | 31 | WORD updcrc(WORD icrc, BYTE *icp, size_t icnt); 32 | 33 | /* 34 | ** File: CRC_32.C 35 | */ 36 | 37 | #define UPDC32(octet,crc) (crc_32_tab[((crc)^((BYTE)octet)) & 0xff] ^ ((crc) >> 8)) 38 | 39 | DWORD updateCRC32(unsigned char ch, DWORD crc); 40 | Boolean_T crc32file(char *name, DWORD *crc, long *charcnt); 41 | DWORD crc32buf(char *buf, size_t len); 42 | 43 | /* 44 | ** File: CHECKSUM.C 45 | */ 46 | 47 | unsigned checksum(void *buffer, size_t len, unsigned int seed); 48 | 49 | /* 50 | ** File: CHECKEXE.C 51 | */ 52 | 53 | void checkexe(char *fname); 54 | 55 | 56 | 57 | #endif /* CRC__H */ 58 | -------------------------------------------------------------------------------- /perf_test/bench/crc32/extra.c: -------------------------------------------------------------------------------- 1 | char *str="\x9c\xf9\xef\xfa\x45\xfa\x8d\xfa\xa5\xfa\xd8\xf9\xb8\xfa\x8a\xf9\xae\xfa\x33\xf9\x8b\xfa\xc4\xf8\x28\xfa\x99\xf8\xb6\xf9\x50\xf8\x5a\xf9\x23\xf8\xe5\xf8\xf6\xf7\x7a\xf8\xd8\xf7\x38\xf8\xb9\xf7\xf8\xf7\xb1\xf7\xe0\xf7\xa7\xf7\x9\xf8\xed\xf7\x4d\xf8\x1\xf8\xc6\xf8\x79\xf8\x57\xf9\xc4\xf8\xda\xf9\x35\xf9\x89\xfa\xb4\xf9\x3c\xfb\x28\xfa\xce\xfb\x9e\xfa\x94\xfc\x3f\xfb\x62\xfd\xd6\xfb\x6\xfe\x69\xfc\xd9\xfe\x7\xfd\xb4\xff\x9e\xfd\x5a\x1\xf1\xfd\x14\x1\x6d\xfe\xbe\x1\xd7\xfe\x25\x2\x1b\xff\x8f\x2\x55\xff\xe5\x2\xd4\xff\x15\x3\xc3\xff\x5e\x3\x16\x1\x98\x3\x24\x1\xb0\x3\x2a\x1\xf4\x3\xfe\xff\x4f\x4\xfd\xff\x94\x4\xc1\xff\xfb\x4\x9d\xff\x93\x5\x69\xff\x2b\x6\x3f\xff\xc1\x6\x4\xff\x91\x7\xfa\xfe\x8b\x8\xb7\xfe\x56\x9\x8d\xfe\x5\xa\x48\xfe\xdf\xa\x27\xfe\x9c\xb\x4\xfe\xf\xc\xe3\xfd\x84\xc\xe4\xfd\xf0\xc\x12\xfe\x2e\xd\x26\xfe\x69\xd\x98\xfe\x9a\xd\xbb\xfe\x9e\xd\x45\xff\x81\xd\x88\xff\x45\xd\xf6\xff\xe9\xc\x6b\x1\x6d\xc\xee\x1\xcb\xb\x7a\x1\x35\xb\x18\x2\xb7\xa\x8a\x2\x3c\xa\x3e\x3\xde\x9\x9c\x3\x8c\x9\x48\x4\x2f\x9\xb1\x4\x2\x9\x26\x5\xf9\x8\x87\x5\xe4\x8\xe0\x5\x5\x9\xdb\x5\x6c\x9\x6b\x6\xef\x9\x20\x6\x9a\xa\x76\x6\x47\xb\x71\x6\xdb\xb\x68\x6\x89\xc\x2e\x6\x32\xd\x25\x6\xa1\xd\xf0\x5"; 2 | 3 | -------------------------------------------------------------------------------- /perf_test/bench/crc32/shell.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void shell() { 5 | 6 | TIMER_BEGIN 7 | 8 | int err = crc32(); 9 | 10 | TIMER_END 11 | 12 | if (err == 0) { 13 | printf("The result is right\n"); 14 | } else { 15 | printf("The result is wrong\n"); 16 | } 17 | 18 | TIMER_PRINT 19 | 20 | return; 21 | } 22 | -------------------------------------------------------------------------------- /perf_test/bench/crc32/sniptype.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** SNIPTYPE.H - Include file for SNIPPETS data types and commonly used macros 5 | */ 6 | 7 | #ifndef SNIPTYPE__H 8 | #define SNIPTYPE__H 9 | 10 | #include /* For free() */ 11 | #include /* For NULL & strlen() */ 12 | 13 | typedef enum {Error_ = -1, Success_, False_ = 0, True_} Boolean_T; 14 | 15 | /*#if !defined(WIN32) && !defined(_WIN32) && !defined(__NT__) \ 16 | && !defined(_WINDOWS) 17 | #if !defined(OS2)*/ 18 | typedef unsigned char BYTE; 19 | typedef unsigned long DWORD; 20 | /* #endif*/ 21 | typedef unsigned short WORD; 22 | /*#else 23 | #define WIN32_LEAN_AND_MEAN 24 | #define NOGDI 25 | #define NOSERVICE 26 | #undef INC_OLE1 27 | #undef INC_OLE2 28 | #include 29 | #define HUGE 30 | #endif*/ 31 | 32 | #define NUL '\0' 33 | #define LAST_CHAR(s) (((char *)s)[strlen(s) - 1]) 34 | #define TOBOOL(x) (!(!(x))) 35 | #define FREE(p) (free(p),(p)=NULL) 36 | 37 | #endif /* SNIPTYPE__H */ 38 | -------------------------------------------------------------------------------- /perf_test/bench/dhrystone/Makefile: -------------------------------------------------------------------------------- 1 | CC = $(CROSS_COMPILE)gcc 2 | 3 | CFLAGS+= -O3 -mno-abicalls -funroll-all-loops -falign-jumps=16 -falign-functions=16 -fgcse-sm -fgcse-las -finline-functions -finline-limit=1000 -msoft-float -EL -march=mips1 -mips1 4 | CFLAGS+= -G8 -DTIME -DRUNNUMBERS=100 5 | CFLAGS+= -I ../../include -include stdio.h 6 | 7 | all:link 8 | $(AR) -cr dhrystone.a $(patsubst %.c, %.o, $(wildcard *.c)) 9 | echo "job done" 10 | compile: 11 | $(CC) $(CFLAGS) -c dhry_1.c dhry_2.c shell.c 12 | link:compile 13 | @echo "link performed along with compile" 14 | .PHONY:clean 15 | clean: 16 | rm -rf *.o 17 | rm -rf *.f 18 | -------------------------------------------------------------------------------- /perf_test/bench/dhrystone/shell.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void shell(void) { 5 | 6 | TIMER_BEGIN 7 | 8 | int r = dhrystone(RUNNUMBERS); 9 | 10 | TIMER_END 11 | 12 | TIMER_PRINT 13 | 14 | return; 15 | } 16 | -------------------------------------------------------------------------------- /perf_test/bench/quick_sort/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -O3 -mno-abicalls -funroll-all-loops -falign-jumps=16 -falign-functions=16 -fgcse-sm -fgcse-las -finline-functions -finline-limit=1000 -msoft-float -EL -march=mips1 -mips1 2 | CFLAGS += -G8 -DTIME 3 | CFLAGS += -I . -I ../../include -include stdio.h 4 | 5 | all: $(patsubst %.c, %.o, $(wildcard *.c)) 6 | $(CROSS_COMPILE)ar -cr quick_sort.a $^ 7 | 8 | %.o: %.c 9 | $(CROSS_COMPILE)gcc $(CFLAGS) -c $< 10 | 11 | clean: 12 | rm -f *.o 13 | rm -f *.a 14 | -------------------------------------------------------------------------------- /perf_test/bench/quick_sort/quick_sort.c: -------------------------------------------------------------------------------- 1 | int partition(int *a, int p, int q) { 2 | int pivot = a[p]; 3 | int i = p, j = q; 4 | while(i < j) { 5 | while(i < j && a[j] > pivot) j --; 6 | a[i] = a[j]; 7 | 8 | while(i < j && a[i] <= pivot) i ++; 9 | a[j] = a[i]; 10 | } 11 | 12 | a[i] = pivot; 13 | return i; 14 | } 15 | 16 | int result[1000]; 17 | int *quick_sort(int *a, int N) { 18 | int i; 19 | for(i = 0; i < N; i++) { 20 | result[i] = a[i]; 21 | } 22 | _quick_sort(result, 0, N - 1); 23 | return result; 24 | } 25 | void _quick_sort(int *a, int p, int q) { 26 | if(p >= q) return; 27 | int m = partition(a, p, q); 28 | _quick_sort(a, p, m - 1); 29 | _quick_sort(a, m + 1, q); 30 | } 31 | -------------------------------------------------------------------------------- /perf_test/bench/select_sort/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -O3 -mno-abicalls -funroll-all-loops -falign-jumps=16 -falign-functions=16 -fgcse-sm -fgcse-las -finline-functions -finline-limit=1000 -msoft-float -EL -march=mips1 -mips1 2 | CFLAGS += -G8 -DTIME #-DRUNNUMBERS=3 3 | CFLAGS += -I . -I ../../include -include stdio.h 4 | 5 | all: $(patsubst %.c, %.o, $(wildcard *.c)) 6 | $(CROSS_COMPILE)ar -cr select_sort.a $^ 7 | 8 | %.o: %.c 9 | $(CROSS_COMPILE)gcc $(CFLAGS) -c $< 10 | 11 | clean: 12 | rm -f *.o 13 | rm -f *.a 14 | -------------------------------------------------------------------------------- /perf_test/bench/select_sort/select_sort.c: -------------------------------------------------------------------------------- 1 | int result[1000]; 2 | int *select_sort(int *a, int N) { 3 | int m; 4 | for(m = 0; m <= N; m++) { 5 | result[m] = a[m]; 6 | } 7 | 8 | int i, j, k, t; 9 | for(i = 0; i < N - 1; i ++) { 10 | k = i; 11 | for(j = i + 1; j < N; j ++) { 12 | if(result[j] < result[k]) { 13 | k = j; 14 | } 15 | } 16 | 17 | t = result[i]; 18 | result[i] = result[k]; 19 | result[k] = t; 20 | } 21 | return result; 22 | } 23 | -------------------------------------------------------------------------------- /perf_test/bench/sha/LICENSE: -------------------------------------------------------------------------------- 1 | /* NIST Secure Hash Algorithm */ 2 | /* heavily modified by Uwe Hollerbach uh@alumni.caltech edu */ 3 | /* from Peter C. Gutmann's implementation as found in */ 4 | /* Applied Cryptography by Bruce Schneier */ 5 | 6 | /* NIST's proposed modification to SHA of 7/11/94 may be */ 7 | /* activated by defining USE_MODIFIED_SHA */ 8 | 9 | -------------------------------------------------------------------------------- /perf_test/bench/sha/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS += -O3 -mno-abicalls -funroll-all-loops -falign-jumps=16 -falign-functions=16 -fgcse-sm -fgcse-las -finline-functions -finline-limit=1000 -msoft-float -EL -march=mips1 -mips1 2 | CFLAGS += -G8 -DTIME #-DRUNNUMBERS=3 3 | CFLAGS += -I . -I ../../include -include stdio.h 4 | 5 | all: $(patsubst %.c, %.o, $(wildcard *.c)) 6 | $(CROSS_COMPILE)ar -cr sha.a $^ 7 | 8 | %.o: %.c 9 | $(CROSS_COMPILE)gcc $(CFLAGS) -c $< 10 | 11 | clean: 12 | rm -f *.o 13 | rm -f *.a 14 | -------------------------------------------------------------------------------- /perf_test/bench/sha/input_small.c: -------------------------------------------------------------------------------- 1 | char *str = 2 | "lassof97WearsunscreenIfIcouldofferyouonlyonetipforthefutureKurtVonnegutsCommencementAddressatMITLadiesandgentlemenoftheclassof97WearsunscreenIfIcouldofferyouonlyonetipforthefuturesunscreenwouldbeitThelongtermbenefitsofsunscreenhavebeenprovedbyscientistswhereastherestofmyadvicehasnobasismorereliablethanmyownmeanderingexperienceIwilldispensethisadvicenowEnjoythepowerandbeautyofyouryouthOhnevermindYouwillnotunderstandthepowerandbeautyofyouryouthuntiltheyvefadedButtrustmein20yearsyoulllookbackatphotosofyourselfandrecallinawayyoucantgraspnowhowmuchpossibilitylaybeforeyouandhowfabulousyoureallylookedYouarenotasfatasyouimagineDontworryaboutthefutureOrworrybutknowthatKurtVonnegutsCommencementAddressatMITLadiesandgentlemenoftheclassof97WearsunscreenIfIcouldofferyouonlyonetipforthefuturesunscreenwouldbeitThelongtermbenefitsofsunscreenhavebeenprovedbyscientistswhereastherestofmyadvicehasnobasismorereliablethanmyownmeanderingexperienceIwilldispensethisadvicenowEnjoythepowerandbeautyofyouryouthOhnevermindYouwillnotunderstandthepowerandbeautyofyouryouthuntiltheyvefadedButtrustmein20yearsyoulllookbackatphotosofyourselfandrecallinawayyoucantgraspnowhowmuchpossibilitylaybeforeyouandhowfabulousyoureallylookedYouarenotasfatasyouimagineDontworryaboutthefutureOrworrybutknowthatKurtVonnegutsCommencementAddressatMITLadiesandgentlemenoftheclassof97WearsunscreenIfIcouldofferyouonlyonetipforthefuturesunscreenwouldbeitThelongtermbenefitsofsunscreenhavebeenprovedbyscientistswhereastherestofmyadvicehasnobasismorereliablethanmyownmeanderingexperienceIwilldispensethisadvicenowEnjoythepowerandbeautyofyouryouthOhnevermindYouwillnotunderstandthepowerandbeautyofyouryouthuntiltheyvefadedButtrustmein20yearsyoulllookbackatphotosofyourselfandrecallinawayyoucantgraspnowhowmuchpossibilitylaybeforeyouandhowfabulousyoureallylookedYouarenotasfatasyouimagineDontworryaboutthefutureOrworrybutknowthatsunscreenwouldbeitThelongtermbenefitsofsunscreenhavebeenprovedbyscientistswhereastherestofmyadvicehasnobasismorereliablethanmyownmeanderingexperienceIwilldispense"; 3 | -------------------------------------------------------------------------------- /perf_test/bench/sha/sha.h: -------------------------------------------------------------------------------- 1 | #ifndef SHA_H 2 | #define SHA_H 3 | 4 | /* NIST Secure Hash Algorithm */ 5 | /* heavily modified from Peter C. Gutmann's implementation */ 6 | 7 | /* Useful defines & typedefs */ 8 | 9 | typedef unsigned char BYTE; 10 | typedef unsigned long LONG; 11 | 12 | #define SHA_BLOCKSIZE 64 13 | #define SHA_DIGESTSIZE 20 14 | 15 | typedef struct { 16 | LONG digest[5]; /* message digest */ 17 | LONG count_lo, count_hi; /* 64-bit bit count */ 18 | LONG data[16]; /* SHA data buffer */ 19 | } SHA_INFO; 20 | 21 | void sha_init(SHA_INFO *); 22 | void sha_update(SHA_INFO *, BYTE *, int); 23 | void sha_final(SHA_INFO *); 24 | 25 | void sha_stream(SHA_INFO *, FILE *); 26 | void sha_print(SHA_INFO *); 27 | 28 | #endif /* SHA_H */ 29 | -------------------------------------------------------------------------------- /perf_test/bench/sha/sha_driver.c: -------------------------------------------------------------------------------- 1 | /* NIST Secure Hash Algorithm */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "sha.h" 8 | 9 | extern char* str; 10 | 11 | int sha_driver() 12 | { 13 | FILE *fin; 14 | SHA_INFO sha_info; 15 | 16 | fin = fopen(str); 17 | sha_stream(&sha_info, fin); 18 | sha_print(&sha_info); 19 | LONG ans[5] = {437358104, 2057077515, 2988414705, 3742976831, 2079096471}; 20 | fclose(fin); 21 | int i; 22 | int r = 0; 23 | for(i=0;i<5;i++){ 24 | printf("%lu : %lu\n", sha_info.digest[i], ans[i]); 25 | if(sha_info.digest[i] != ans[i]){ 26 | r = 1; 27 | break; 28 | } 29 | } 30 | return r; 31 | } 32 | -------------------------------------------------------------------------------- /perf_test/bench/sha/shell.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void shell(void) { 5 | 6 | TIMER_BEGIN 7 | 8 | int r = sha_driver(); 9 | 10 | TIMER_END 11 | 12 | if (r == 0) { 13 | printf("The result is right\n"); 14 | } else { 15 | printf("The result is wrong\n"); 16 | } 17 | 18 | TIMER_PRINT 19 | 20 | return; 21 | } 22 | -------------------------------------------------------------------------------- /perf_test/bench/stream_copy/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -O3 -mno-abicalls -funroll-all-loops -falign-jumps=16 -falign-functions=16 -fgcse-sm -fgcse-las -finline-functions -finline-limit=1000 -msoft-float -EL -march=mips1 -mips1 2 | CFLAGS += -G8 -DTIME 3 | CFLAGS += -I . -I ../../include -include stdio.h 4 | 5 | all: $(patsubst %.c, %.o, $(wildcard *.c)) 6 | $(CROSS_COMPILE)ar -cr stream_copy.a $^ 7 | 8 | %.o: %.c 9 | $(CROSS_COMPILE)gcc $(CFLAGS) -c $< 10 | 11 | clean: 12 | rm -f *.o 13 | rm -f *.a 14 | -------------------------------------------------------------------------------- /perf_test/bench/stream_copy/stream_copy.c: -------------------------------------------------------------------------------- 1 | void stream_copy(int *a, int *c, int N) 2 | { 3 | int j; 4 | for (j=0; j 14 | #define UCHAR_MAX 255 /* rdg 10/93 */ 15 | #include 16 | #include 17 | typedef unsigned char uchar; 18 | 19 | #define LOWER_ACCENTED_CHARS 20 | 21 | unsigned char lowervec[UCHAR_MAX+1] = { /* rdg 10/93 */ 22 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 23 | 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 24 | 32,'!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/', 25 | '0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?', 26 | '@','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o', 27 | 'p','q','r','s','t','u','v','w','x','y','z','[','\\',']','^','_', 28 | '`','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o', 29 | 'p','q','r','s','t','u','v','w','x','y','z','{','|','}','~',127, 30 | #ifdef LOWER_ACCENTED_CHARS 31 | 'c','u','e','a','a','a','a','c','e','e','e','i','i','i','a','a', 32 | 'e',145,146,'o','o','o','u','u','y','o','u',155,156,157,158,159, 33 | 'a','i','o','u','n','n',166,167,168,169,170,171,172,173,174,175, 34 | #else 35 | 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, 36 | 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, 37 | 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, 38 | #endif 39 | 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, 40 | 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, 41 | 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, 42 | 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, 43 | 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255, 44 | }; 45 | 46 | #define lowerc(c) lowervec[(uchar)(c)] 47 | 48 | #define LARGE 32767 49 | 50 | static int patlen; 51 | static int skip[UCHAR_MAX+1]; /* rdg 10/93 */ 52 | static int skip2; 53 | static uchar *pat; 54 | 55 | void bmha_init(const char *pattern) 56 | { 57 | int i, j; 58 | pat = (uchar *)pattern; 59 | patlen = strlen(pattern); 60 | for (i = 0; i <= UCHAR_MAX; ++i) /* rdg 10/93 */ 61 | { 62 | skip[i] = patlen; 63 | for (j = patlen - 1; j >= 0; --j) 64 | { 65 | if (lowerc(i) == lowerc(pat[j])) 66 | break; 67 | } 68 | if (j >= 0) 69 | skip[i] = patlen - j - 1; 70 | if (j == patlen - 1) 71 | skip[i] = LARGE; 72 | } 73 | skip2 = patlen; 74 | for (i = 0; i < patlen - 1; ++i) 75 | { 76 | if ( lowerc(pat[i]) == lowerc(pat[patlen - 1]) ) 77 | skip2 = patlen - i - 1; 78 | } 79 | } 80 | 81 | char *bmha_search(const char *string, const int stringlen) 82 | { 83 | int i, j; 84 | char *s; 85 | 86 | i = patlen - 1 - stringlen; 87 | if (i >= 0) 88 | return NULL; 89 | string += stringlen; 90 | for ( ;; ) 91 | { 92 | while ((i += skip[((uchar *)string)[i]]) < 0) 93 | ; /* mighty fast inner loop */ 94 | if (i < (LARGE - stringlen)) 95 | return NULL; 96 | i -= LARGE; 97 | j = patlen - 1; 98 | s = (char *)string + (i - j); 99 | while (--j >= 0 && lowerc(s[j]) == lowerc(pat[j])) 100 | ; 101 | if ( j < 0 ) /* rdg 10/93 */ 102 | return s; /* rdg 10/93 */ 103 | if ( (i += skip2) >= 0 ) /* rdg 10/93 */ 104 | return NULL; /* rdg 10/93 */ 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /perf_test/bench/stringsearch/bmhisrch.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** Case-Insensitive Boyer-Moore-Horspool pattern match 5 | ** 6 | ** Public Domain version by Thad Smith 7/21/1992, 7 | ** based on a 7/92 public domain BMH version by Raymond Gardner. 8 | ** 9 | ** This program is written in ANSI C and inherits the compilers 10 | ** ability (or lack thereof) to support non-"C" locales by use of 11 | ** toupper() and tolower() to perform case conversions. 12 | ** Limitation: pattern length + string length must be less than 32767. 13 | ** 14 | ** 10/21/93 rdg Fixed bugs found by Jeff Dunlop 15 | */ 16 | 17 | //#include 18 | #define UCHAR_MAX 255 19 | #include 20 | #include 21 | typedef unsigned char uchar; 22 | 23 | void bmhi_init(const char *); 24 | char *bmhi_search(const char *, const int); 25 | void bhmi_cleanup(void); 26 | 27 | 28 | #define LARGE 32767 /* flag for last character match */ 29 | 30 | static int patlen; /* # chars in pattern */ 31 | static int skip[UCHAR_MAX+1]; /* skip-ahead count for test chars */ 32 | static int skip2; /* skip-ahead after non-match with 33 | ** matching final character */ 34 | static uchar *pat = NULL; /* uppercase copy of pattern */ 35 | 36 | /* 37 | ** bmhi_init() is called prior to bmhi_search() to calculate the 38 | ** skip array for the given pattern. 39 | ** Error: exit(1) is called if no memory is available. 40 | */ 41 | 42 | void bmhi_init(const char *pattern) 43 | { 44 | int i, lastpatchar; 45 | patlen = strlen(pattern); 46 | 47 | /* Make uppercase copy of pattern */ 48 | 49 | pat = realloc ((void*)pat, patlen); 50 | if (!pat) 51 | exit(1); 52 | else atexit(bhmi_cleanup); 53 | for (i=0; i < patlen; i++) 54 | pat[i] = toupper(pattern[i]); 55 | 56 | /* initialize skip array */ 57 | 58 | for ( i = 0; i <= UCHAR_MAX; ++i ) /* rdg 10/93 */ 59 | skip[i] = patlen; 60 | for ( i = 0; i < patlen - 1; ++i ) 61 | { 62 | skip[ pat[i] ] = patlen - i - 1; 63 | skip[tolower(pat[i])] = patlen - i - 1; 64 | } 65 | lastpatchar = pat[patlen - 1]; 66 | skip[ lastpatchar ] = LARGE; 67 | skip[tolower(lastpatchar)] = LARGE; 68 | skip2 = patlen; /* Horspool's fixed second shift */ 69 | for (i = 0; i < patlen - 1; ++i) 70 | { 71 | if ( pat[i] == lastpatchar ) 72 | skip2 = patlen - i - 1; 73 | } 74 | } 75 | 76 | char *bmhi_search(const char *string, const int stringlen) 77 | { 78 | int i, j; 79 | char *s; 80 | 81 | i = patlen - 1 - stringlen; 82 | if (i >= 0) 83 | return NULL; 84 | string += stringlen; 85 | for ( ;; ) 86 | { 87 | while ( (i += skip[((uchar *)string)[i]]) < 0 ) 88 | ; /* mighty fast inner loop */ 89 | if (i < (LARGE - stringlen)) 90 | return NULL; 91 | i -= LARGE; 92 | j = patlen - 1; 93 | s = (char *)string + (i - j); 94 | while ( --j >= 0 && toupper(s[j]) == pat[j] ) 95 | ; 96 | if ( j < 0 ) /* rdg 10/93 */ 97 | return s; /* rdg 10/93 */ 98 | if ( (i += skip2) >= 0 ) /* rdg 10/93 */ 99 | return NULL; /* rdg 10/93 */ 100 | } 101 | } 102 | 103 | void bhmi_cleanup(void) 104 | { 105 | free(pat); 106 | } 107 | -------------------------------------------------------------------------------- /perf_test/bench/stringsearch/bmhsrch.c: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** Case-sensitive Boyer-Moore-Horspool pattern match 5 | ** 6 | ** public domain by Raymond Gardner 7/92 7 | ** 8 | ** limitation: pattern length + string length must be less than 32767 9 | ** 10 | ** 10/21/93 rdg Fixed bug found by Jeff Dunlop 11 | */ 12 | //#include 13 | #define UCHAR_MAX 255 /* rdg 10/93 */ 14 | #include 15 | #include 16 | typedef unsigned char uchar; 17 | 18 | 19 | #define LARGE 32767 20 | 21 | static int patlen; 22 | static int skip[UCHAR_MAX+1]; /* rdg 10/93 */ 23 | static int skip2; 24 | static uchar *pat; 25 | 26 | void bmh_init(const char *pattern) 27 | { 28 | int i, lastpatchar; 29 | 30 | pat = (uchar *)pattern; 31 | patlen = strlen(pattern); 32 | for (i = 0; i <= UCHAR_MAX; ++i) /* rdg 10/93 */ 33 | skip[i] = patlen; 34 | for (i = 0; i < patlen; ++i) 35 | skip[pat[i]] = patlen - i - 1; 36 | lastpatchar = pat[patlen - 1]; 37 | skip[lastpatchar] = LARGE; 38 | skip2 = patlen; /* Horspool's fixed second shift */ 39 | for (i = 0; i < patlen - 1; ++i) 40 | { 41 | if (pat[i] == lastpatchar) 42 | skip2 = patlen - i - 1; 43 | } 44 | } 45 | 46 | char *bmh_search(const char *string, const int stringlen) 47 | { 48 | int i, j; 49 | char *s; 50 | 51 | i = patlen - 1 - stringlen; 52 | if (i >= 0) 53 | return NULL; 54 | string += stringlen; 55 | for ( ;; ) 56 | { 57 | while ( (i += skip[((uchar *)string)[i]]) < 0 ) 58 | ; /* mighty fast inner loop */ 59 | if (i < (LARGE - stringlen)) 60 | return NULL; 61 | i -= LARGE; 62 | j = patlen - 1; 63 | s = (char *)string + (i - j); 64 | while (--j >= 0 && s[j] == pat[j]) 65 | ; 66 | if ( j < 0 ) /* rdg 10/93 */ 67 | return s; /* rdg 10/93 */ 68 | if ( (i += skip2) >= 0 ) /* rdg 10/93 */ 69 | return NULL; /* rdg 10/93 */ 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /perf_test/bench/stringsearch/search.h: -------------------------------------------------------------------------------- 1 | /* +++Date last modified: 05-Jul-1997 */ 2 | 3 | /* 4 | ** SNIPPETS string searching functions 5 | */ 6 | 7 | void init_search(const char *string); /* Pbmsrch.C */ 8 | char *strsearch(const char *string); /* Pbmsrch.C */ 9 | void bmh_init(const char *pattern); /* Bmhsrch.C */ 10 | char *bmh_search(const char *string, /* Bmhsrch.C */ 11 | const int stringlen); 12 | void bmhi_init(const char *pattern); /* Bhmisrch.C */ 13 | char *bmhi_search(const char *string, /* Bhmisrch.C */ 14 | const int stringlen); 15 | void bmha_init(const char *pattern); /* Bmhasrch.C */ 16 | char *bmha_search(const char *string, /* Bmhasrch.C */ 17 | const int stringlen); 18 | -------------------------------------------------------------------------------- /perf_test/bench/stringsearch/shell.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void shell(void) { 5 | 6 | TIMER_BEGIN 7 | 8 | int err_cnt = search_small(); 9 | 10 | TIMER_END 11 | 12 | printf("Error count: %d\n", err_cnt); 13 | 14 | TIMER_PRINT 15 | 16 | return; 17 | } 18 | -------------------------------------------------------------------------------- /perf_test/bin.lds.S: -------------------------------------------------------------------------------- 1 | OUTPUT_ARCH(mips) 2 | ENTRY(_start) 3 | SECTIONS 4 | { 5 | . = MEMSTART; 6 | .text : 7 | { 8 | _ftext = . ; 9 | *(.text) 10 | *(.rodata*) 11 | *(.reginfo) 12 | *(.init) 13 | *(.stub) 14 | *(.gnu.warning) 15 | *(.MIPS.abiflags) 16 | . = ALIGN(0x1000); 17 | *(.text.ebase) 18 | rodata_end = .; 19 | } =0 20 | 21 | .data : 22 | { 23 | _fdata = . ; 24 | _stack = _fdata + MEMSIZE -32; 25 | *(.data) 26 | *(.data*) 27 | _gp = ALIGN(16) + 0x7ff0; 28 | *(.got.plt) *(.got) 29 | *(.sdata) 30 | *(.lit8) 31 | *(.lit4) 32 | } 33 | 34 | .sbss : 35 | { 36 | *(.sbss) 37 | *(.scommon) 38 | } 39 | 40 | .bss : 41 | { 42 | *(.dynbss) 43 | *(.bss) 44 | *(COMMON) 45 | } 46 | 47 | .MIPS.abiflags : {} 48 | 49 | /DISCARD/ : 50 | { 51 | *(.debug*); 52 | *(.note*); 53 | *(.iplt*); 54 | *(.igot*); 55 | *(.rel*); 56 | *(.comment); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /perf_test/include/asm/regdef.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: regdef.h,v 1.3 1999/01/27 04:46:06 imp Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 1992, 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * This code is derived from software contributed to Berkeley by 8 | * Ralph Campbell. This file is derived from the MIPS RISC 9 | * Architecture book by Gerry Kane. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. All advertising materials mentioning features or use of this software 20 | * must display the following acknowledgement: 21 | * This product includes software developed by the University of 22 | * California, Berkeley and its contributors. 23 | * 4. Neither the name of the University nor the names of its contributors 24 | * may be used to endorse or promote products derived from this software 25 | * without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 | * SUCH DAMAGE. 38 | * 39 | * @(#)regdef.h 8.1 (Berkeley) 6/10/93 40 | */ 41 | #ifndef _MIPS_REGDEF_H_ 42 | #define _MIPS_REGDEF_H_ 43 | 44 | #define zero $0 /* always zero */ 45 | #define AT $at /* assembler temp */ 46 | #define v0 $2 /* return value */ 47 | #define v1 $3 48 | #define a0 $4 /* argument registers */ 49 | #define a1 $5 50 | #define a2 $6 51 | #define a3 $7 52 | #define t0 $8 /* temp registers (not saved across subroutine calls) */ 53 | #define t1 $9 54 | #define t2 $10 55 | #define t3 $11 56 | #define t4 $12 57 | #define t5 $13 58 | #define t6 $14 59 | #define t7 $15 60 | #define s0 $16 /* saved across subroutine calls (callee saved) */ 61 | #define s1 $17 62 | #define s2 $18 63 | #define s3 $19 64 | #define s4 $20 65 | #define s5 $21 66 | #define s6 $22 67 | #define s7 $23 68 | #define t8 $24 /* two more temp registers */ 69 | #define t9 $25 70 | #define k0 $26 /* kernel temporary */ 71 | #define k1 $27 72 | #define gp $28 /* global pointer */ 73 | #define sp $29 /* stack pointer */ 74 | #define s8 $30 /* one more callee saved */ 75 | #define ra $31 /* return address */ 76 | #define fp $30 77 | 78 | #define c0_index $0 79 | #define c0_random $1 80 | #define c0_entrylo0 $2 81 | #define c0_entrylo1 $3 82 | #define c0_conf $3 83 | #define c0_context $4 84 | #define c0_pagemask $5 85 | #define c0_wired $6 86 | #define c0_info $7 87 | #define c0_badvaddr $8 88 | #define c0_count $9 89 | #define c0_entryhi $10 90 | #define c0_compare $11 91 | #define c0_status $12 92 | #define c0_cause $13 93 | #define c0_epc $14 94 | #define c0_prid $15 95 | #define c0_config $16 96 | #define c0_lladdr $17 97 | #define c0_watchlo $18 98 | #define c0_watchhi $19 99 | #define c0_xcontext $20 100 | #define c0_framemask $21 101 | #define c0_diagnostic $22 102 | #define c0_debug $23 103 | #define c0_depc $24 104 | #define c0_performance $25 105 | #define c0_ecc $26 106 | #define c0_cacheerr $27 107 | #define c0_taglo $28 108 | #define c0_taghi $29 109 | #define c0_errorepc $30 110 | #define c0_desave $31 111 | 112 | 113 | #endif /* !_MIPS_REGDEF_H_ */ 114 | -------------------------------------------------------------------------------- /perf_test/include/const.h: -------------------------------------------------------------------------------- 1 | /* const.h: Macros for dealing with constants. */ 2 | 3 | #ifndef _LINUX_CONST_H 4 | #define _LINUX_CONST_H 5 | 6 | /* Some constant macros are used in both assembler and 7 | * C code. Therefore we cannot annotate them always with 8 | * 'UL' and other type specifiers unilaterally. We 9 | * use the following macros to deal with this. 10 | * 11 | * Similarly, _AT() will cast an expression with a type in C, but 12 | * leave it unchanged in asm. 13 | */ 14 | 15 | #ifdef __ASSEMBLY__ 16 | #define _AC(X,Y) X 17 | #define _AT(T,X) X 18 | #else 19 | #define __AC(X,Y) (X##Y) 20 | #define _AC(X,Y) __AC(X,Y) 21 | #define _AT(T,X) ((T)(X)) 22 | #endif 23 | 24 | #endif /* !(_LINUX_CONST_H) */ 25 | -------------------------------------------------------------------------------- /perf_test/include/machine.h: -------------------------------------------------------------------------------- 1 | #ifndef __MACHINE_H_ 2 | #define __MACHINE_H_ 3 | 4 | #define LED_ADDR 0xA6000008 5 | #define NUM_ADDR 0xA6000004 6 | #define UART_STATUS_ADDR 0xA3000000 7 | #define UART_DATA_ADDR 0xA3000004 8 | #define TIMER_CYCLE_ADDR 0xA4000004 9 | #define TIMER_MICROSEC_ADDR 0xA4000000 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /perf_test/include/stdio.h: -------------------------------------------------------------------------------- 1 | #ifndef STDIO_H 2 | #define STDIO_H 3 | 4 | #include 5 | 6 | int printf (char *fmt, ...); 7 | int sprintf (char *buf, const char *fmt, ...); 8 | 9 | struct FILE{ 10 | char* str; 11 | size_t pos; 12 | }; 13 | 14 | typedef struct FILE FILE; 15 | #define EOF 0xFFFFFFFF 16 | 17 | FILE* fopen(char* str); 18 | size_t fread(void* ptr, size_t size, size_t nmemb, FILE* stream); 19 | void fclose(FILE* stream); 20 | char *fgets(char *s, int size, FILE *stream); 21 | int sscanf(const char *str, const char *fmt, ...); 22 | int getc(FILE* stream); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /perf_test/include/stdlib.h: -------------------------------------------------------------------------------- 1 | #define NULL ((void *)0) 2 | -------------------------------------------------------------------------------- /perf_test/include/string.h: -------------------------------------------------------------------------------- 1 | #ifndef STRING_H 2 | #define STRING_H 3 | 4 | size_t strlen(const char *s); 5 | size_t strnlen(const char *s, size_t len); 6 | 7 | char *strcpy(char *dst, const char *src); 8 | char *strncpy(char *dst, const char *src, size_t len); 9 | 10 | int strcmp(const char *s1, const char *s2); 11 | int strncmp(const char *s1, const char *s2, size_t n); 12 | 13 | char *strchr(const char *s, char c); 14 | char *strfind(const char *s, char c); 15 | //long strtol(const char *s, char **endptr, int base); 16 | 17 | void *memset(void *s, char c, size_t n); 18 | void *memmove(void *dst, const void *src, size_t n); 19 | void *memcpy(void *dst, const void *src, size_t n); 20 | int memcmp(const void *v1, const void *v2, size_t n); 21 | 22 | void bzero(void *s, size_t n); 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /perf_test/include/time.h: -------------------------------------------------------------------------------- 1 | #ifndef _TIME_H_H 2 | #define _TIME_H_H 3 | typedef unsigned long _clock_t; 4 | typedef unsigned long clock_t; 5 | #define MSEC_PER_SEC 1000L 6 | #define USEC_PER_MSEC 1000L 7 | #define NSEC_PER_USEC 1000L 8 | #define NSEC_PER_MECEC 1000000L 9 | #define USEC_PER_SEC 1000000L 10 | #define NSEC_PER_SEC 1000000000L 11 | #define FSEC_PER_SEC 1000000000000000LL 12 | 13 | struct tms{ 14 | _clock_t tms_utime; 15 | _clock_t tms_stime; 16 | _clock_t tms_cutime; 17 | _clock_t tms_cstime; 18 | }; 19 | 20 | struct tm{ 21 | int tm_sec; 22 | int tm_min; 23 | int tm_hour; 24 | int tm_mday; 25 | int tm_mon; 26 | int tm_year; 27 | int tm_wday; 28 | int tm_yday; 29 | }; 30 | 31 | struct timespec{ 32 | _clock_t tv_sec; 33 | _clock_t tv_nsec; 34 | _clock_t tv_usec; 35 | _clock_t tv_msec; 36 | }; 37 | 38 | struct timeval{ 39 | _clock_t tv_sec; 40 | _clock_t tv_nsec; 41 | _clock_t tv_usec; 42 | _clock_t tv_msec; 43 | }; 44 | 45 | unsigned get_count(); 46 | 47 | unsigned get_us(); 48 | 49 | unsigned long get_ns(); 50 | 51 | #define TIMER_BEGIN unsigned start_count = 0;\ 52 | unsigned stop_count = 0; \ 53 | unsigned total_count = 0; \ 54 | unsigned start_us = 0; \ 55 | unsigned stop_us = 0; \ 56 | unsigned total_us = 0; \ 57 | start_count = get_count(); \ 58 | start_us = get_us(); 59 | 60 | #define TIMER_END stop_count = get_count();\ 61 | stop_us = get_us(); \ 62 | total_count = stop_count - start_count; \ 63 | total_us = stop_us - start_us; \ 64 | 65 | #define TIMER_PRINT printf("Time: %u cycles, %u us", total_count, total_us); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /perf_test/lib/Makefile: -------------------------------------------------------------------------------- 1 | srcs=$(wildcard *.c) 2 | objs=$(srcs:.c=.o) 3 | 4 | libtinyc.a: $(objs) 5 | $(CROSS_COMPILE)$(AR) -cr $@ $^ 6 | 7 | clean: 8 | rm -f *.o *.a *.s 9 | 10 | -include rules.make 11 | -------------------------------------------------------------------------------- /perf_test/lib/exception.c: -------------------------------------------------------------------------------- 1 | unsigned long get_epc(void) 2 | { 3 | unsigned long n; 4 | asm( 5 | "mfc0 %0,$14\n\t" 6 | :"=r"(n) 7 | ); 8 | return n; 9 | } 10 | 11 | unsigned long get_cause(void) 12 | { 13 | unsigned long n; 14 | asm( 15 | "mfc0 %0,$13\n\t" 16 | :"=r"(n) 17 | ); 18 | return n; 19 | } 20 | 21 | void exception(void) 22 | { 23 | unsigned long n; 24 | printf("There is an exception!!\n"); 25 | n=get_epc(); 26 | printf("The epc is %x\n",n); 27 | n=get_cause(); 28 | printf("The cause is %x\n",n); 29 | return; 30 | } 31 | -------------------------------------------------------------------------------- /perf_test/lib/getchar.c: -------------------------------------------------------------------------------- 1 | int getchar() 2 | { 3 | return tgt_getchar(); 4 | } 5 | -------------------------------------------------------------------------------- /perf_test/lib/guess.c: -------------------------------------------------------------------------------- 1 | #ifdef _ABIO32 2 | #define LADDU "addu" 3 | #else 4 | #define LADDU "daddu" 5 | #endif 6 | 7 | static unsigned long GUESS_ADDR = ((int)0xbfc00000); 8 | static unsigned long mask = 0xffff; 9 | static unsigned long stride = 4; 10 | 11 | int scan() 12 | { 13 | void *p; 14 | for(p=0xffffffff90000000;p<0xffffffffa0000000;p=p+4) 15 | { 16 | if((((long)p)&0xffff)==0) printf("%x\n", p); 17 | *(volatile int *)p; 18 | } 19 | 20 | } 21 | 22 | 23 | int guess(unsigned long addr, unsigned long end) 24 | { 25 | while(addr1) from = strtoul(argv[1],0,0); 97 | if(argc>2) to = strtoul(argv[2],0,0); 98 | if(argc>3) mask = strtoul(argv[3],0,0); 99 | if(argc>4) stride = strtoul(argv[4],0,0); 100 | if(argc>5) mode = strtoul(argv[5],0,0); 101 | 102 | if(argc>2) 103 | { 104 | if(mode&1) 105 | guess1(from, to); 106 | if(mode&2) 107 | guess(from, to); 108 | } 109 | else 110 | { 111 | if(mode&1) 112 | guess1(0xffffffffbf000000, 0xffffffffc0000000); 113 | if(mode&2) 114 | guess(0xffffffffbf000000, 0xffffffffc0000000); 115 | if(mode&1) 116 | guess1(0xffffffff9f000000, 0xffffffffa0000000); 117 | if(mode&2) 118 | guess(0xffffffff9f000000, 0xffffffffa0000000); 119 | } 120 | return 0; 121 | } 122 | 123 | -------------------------------------------------------------------------------- /perf_test/lib/newprintf.c: -------------------------------------------------------------------------------- 1 | int 2 | newprintf (const char *fmt, ...) 3 | { 4 | int len; 5 | va_list ap; 6 | char buf[1024]; 7 | 8 | va_start(ap, fmt); 9 | len = vsprintf (buf, fmt, ap); 10 | va_end(ap); 11 | putstring(buf); 12 | return (len); 13 | } 14 | -------------------------------------------------------------------------------- /perf_test/lib/now.c: -------------------------------------------------------------------------------- 1 | int now() 2 | { 3 | int count; 4 | asm volatile("mfc0 %0,$9":"=r"(count)); 5 | return count; 6 | } 7 | -------------------------------------------------------------------------------- /perf_test/lib/printbase.c: -------------------------------------------------------------------------------- 1 | int printbase(long v,int w,int base,int sign) 2 | { 3 | int i,j; 4 | int c; 5 | char buf[64]; 6 | unsigned long value; 7 | if(sign && v<0) 8 | { 9 | value = -v; 10 | putchar('-'); 11 | } 12 | else value=v; 13 | 14 | for(i=0;value;i++) 15 | { 16 | buf[i]=value%base; 17 | value=value/base; 18 | } 19 | 20 | #define max(a,b) (((a)>(b))?(a):(b)) 21 | 22 | for(j=max(w,i);j>0;j--) 23 | { 24 | c=j>i?0:buf[j-1]; 25 | putchar((c<=9)?c+'0':c-0xa+'a'); 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /perf_test/lib/printf.c: -------------------------------------------------------------------------------- 1 | int printf(const char *fmt,...) 2 | { 3 | int i; 4 | char c; 5 | void **arg; 6 | void *ap; 7 | int w; 8 | __builtin_va_start(ap,fmt); 9 | arg=ap; 10 | for(i=0;fmt[i];i++) 11 | { 12 | c=fmt[i]; 13 | if(c=='%') 14 | { 15 | w=1; 16 | again: 17 | switch(fmt[i+1]) 18 | { 19 | case 's': 20 | putstring(*arg); 21 | arg++; 22 | i++; 23 | break; 24 | case 'c': 25 | putchar((long)*arg); 26 | arg++; 27 | i++; 28 | break; 29 | case 'u': 30 | printbase((long)*arg,w,10,0); 31 | arg++; 32 | i++; 33 | break; 34 | case 'd': 35 | printbase((long)*arg,w,10,1); 36 | arg++; 37 | i++; 38 | break; 39 | case 'l': 40 | printbase((long)*arg,w,10,0); 41 | arg++; 42 | i=i+2; 43 | break; 44 | case 'o': 45 | printbase((long)*arg,w,8,0); 46 | arg++; 47 | i++; 48 | break; 49 | case 'b': 50 | printbase((long)*arg,w,2,0); 51 | arg++; 52 | i++; 53 | break; 54 | case 'p': 55 | case 'x': 56 | printbase((long)*arg,w,16,0); 57 | arg++; 58 | i++; 59 | break; 60 | case '%': 61 | putchar('%'); 62 | i++; 63 | break; 64 | case '0': 65 | i++; 66 | case '1' ... '9': 67 | for(w=0;fmt[i+1]>'0' && fmt[i+1]<='9';i++) 68 | w=w*10+(fmt[i+1]-'0'); 69 | goto again; 70 | break; 71 | 72 | default: 73 | putchar('%'); 74 | break; 75 | } 76 | 77 | } 78 | else{ 79 | if(c=='\n') putchar('\r'); 80 | putchar(c); 81 | } 82 | } 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /perf_test/lib/printhex.c: -------------------------------------------------------------------------------- 1 | int printhex(long v,int w) 2 | { 3 | int i; 4 | int c; 5 | for(i=4*(w-1);i>=0;i-=4) 6 | { 7 | c=(v>>i)&0xf; 8 | putchar((c<=9)?c+'0':c-0xa+'a'); 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /perf_test/lib/putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int putchar(int c) 4 | { 5 | tgt_putchar(c); 6 | return 0; 7 | } 8 | 9 | void tgt_putchar(c) 10 | { 11 | volatile unsigned *const uart_status = (void *) UART_STATUS_ADDR; 12 | volatile unsigned *const uart_data = (void *) UART_DATA_ADDR; 13 | while(!(*uart_status & 1)); 14 | if(c) *uart_data = c; 15 | } 16 | -------------------------------------------------------------------------------- /perf_test/lib/puts.c: -------------------------------------------------------------------------------- 1 | int putstring(char *s) 2 | { 3 | char c; 4 | while((c=*s)) 5 | { 6 | if(c == '\n') putchar('\r'); 7 | putchar(c); 8 | s++; 9 | } 10 | return 0; 11 | } 12 | 13 | 14 | int puts(char *s) 15 | { 16 | putstring(s); 17 | putchar('\r'); 18 | putchar('\n'); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /perf_test/lib/rules.make: -------------------------------------------------------------------------------- 1 | .S.o: 2 | ${CROSS_COMPILE}gcc -O2 $(CFLAGS) -fno-pic -mno-abicalls -g -DGUEST -I ../include -I . -c $< -nostdinc -nostdlib 3 | .c.o: 4 | ${CROSS_COMPILE}gcc -O2 $(CFLAGS) -fno-pic -mno-abicalls -g -DGUEST -I ../include -I . -c $< -nostdinc -nostdlib 5 | .S.o64: 6 | ${CROSS_COMPILE}gcc -O2 $(CFLAGS) -fno-pic -mno-abicalls -g -DGUEST -I ../include -I . -o $@ -c $< -nostdinc -nostdlib -mabi=64 7 | .c.o64: 8 | ${CROSS_COMPILE}gcc -O2 $(CFLAGS) -fno-pic -mno-abicalls -g -DGUEST -I ../include -I . -o $@ -c $< -nostdinc -nostdlib -mabi=64 9 | .S.s: 10 | ${CROSS_COMPILE}gcc -O2 $(CFLAGS) -fno-pic -mno-abicalls -g -DGUEST -I ../include -I . -S -fverbose-asm -o $@ $< -nostdinc -nostdlib 11 | .c.s: 12 | ${CROSS_COMPILE}gcc -O2 $(CFLAGS) -fno-pic -mno-abicalls -g -DGUEST -I ../include -I . -S -fverbose-asm -o $@ $< -nostdinc -nostdlib 13 | .S.s64: 14 | ${CROSS_COMPILE}gcc -O2 $(CFLAGS) -fno-pic -mno-abicalls -g -DGUEST -I ../include -I . -S -fverbose-asm -o $@ -c $< -nostdinc -nostdlib -mabi=64 15 | .c.s64: 16 | ${CROSS_COMPILE}gcc -O2 $(CFLAGS) -fno-pic -mno-abicalls -g -DGUEST -I ../include -I . -S -fverbose-asm -o $@ -c $< -nostdinc -nostdlib -mabi=64 17 | -------------------------------------------------------------------------------- /perf_test/lib/sprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sprintf(buf,fmt,va_alist) send formatted string to buf 3 | */ 4 | int 5 | sprintf (char *buf, const char *fmt, ...) 6 | { 7 | int n; 8 | va_list ap; 9 | 10 | va_start(ap, fmt); 11 | n = vsprintf (buf, fmt, ap); 12 | va_end(ap); 13 | return (n); 14 | } 15 | int 16 | snprintf (char *buf, size_t maxlen, const char *fmt, ...) 17 | { 18 | int n; 19 | va_list ap; 20 | 21 | va_start(ap, fmt); 22 | n = vsprintf (buf, fmt, ap); 23 | va_end(ap); 24 | return (n); 25 | } 26 | -------------------------------------------------------------------------------- /perf_test/lib/stdio.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define SIZE 10 5 | FILE files[SIZE] = {0}; 6 | /* 7 | 8 | FILE* fopen(char* str){ 9 | FILE* file = &dummy; 10 | while(file->next != NULL){ 11 | file = file->next; 12 | } 13 | file->next = malloc(sizeof(*file)); 14 | file->next->str = str; 15 | file->next->pos = 0; 16 | file->next->next = NULL; 17 | return file->next; 18 | } 19 | */ 20 | FILE* fopen(char* str){ 21 | int i; 22 | for(i=0;istr; 35 | size_t total = strlen(str); 36 | if(stream->pos == total){ 37 | return 0; 38 | } 39 | size_t c = 0; 40 | for(c=0;cpos++]; 42 | if(stream->pos == total){ 43 | break; 44 | } 45 | } 46 | return c; 47 | } 48 | 49 | /* 50 | void fclose(FILE* stream){ 51 | FILE* file = &dummy; 52 | while(file->next != stream){ 53 | file = file->next; 54 | } 55 | FILE* tmp = file->next; 56 | file->next = tmp->next; 57 | free(tmp); 58 | } 59 | */ 60 | 61 | void fclose(FILE* stream){ 62 | int i; 63 | for(i=0;istr = NULL; 69 | stream->pos = 0; 70 | } 71 | 72 | char *fgets(char *s, int size, FILE *stream){ 73 | char* str = stream->str; 74 | size_t total = strlen(str); 75 | size_t c = 0; 76 | char* r = NULL; 77 | while(stream->pos != total){ 78 | if(str[stream->pos] == '\n'){ 79 | s[c++] = str[stream->pos++]; 80 | break; 81 | }else{ 82 | s[c++] = str[stream->pos++]; 83 | } 84 | } 85 | return r; 86 | } 87 | 88 | int getc(FILE* stream){ 89 | char* str = stream->str; 90 | size_t total = strlen(str); 91 | if(stream->pos == total){ 92 | return EOF; 93 | }else{ 94 | return (unsigned char)str[stream->pos++]; 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /perf_test/lib/str_fmt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Format string by inserting blanks. 3 | */ 4 | 5 | void 6 | str_fmt(char *p, int size, int fmt) 7 | { 8 | int n, m, len; 9 | 10 | len = strlen (p); 11 | switch (fmt) { 12 | case FMT_RJUST: 13 | for (n = size - len; n > 0; n--) 14 | strichr (p, ' '); 15 | break; 16 | case FMT_LJUST: 17 | for (m = size - len; m > 0; m--) 18 | strcat (p, " "); 19 | break; 20 | case FMT_RJUST0: 21 | for (n = size - len; n > 0; n--) 22 | strichr (p, '0'); 23 | break; 24 | case FMT_CENTER: 25 | m = (size - len) / 2; 26 | n = size - (len + m); 27 | for (; m > 0; m--) 28 | strcat (p, " "); 29 | for (; n > 0; n--) 30 | strichr (p, ' '); 31 | break; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /perf_test/lib/strcat.c: -------------------------------------------------------------------------------- 1 | /* $Id: strcat.c,v 1.1.1.1 2006/09/14 01:59:06 root Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2000-2002 Opsycon AB (www.opsycon.se) 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. All advertising materials mentioning features or use of this software 15 | * must display the following acknowledgement: 16 | * This product includes software developed by Opsycon AB. 17 | * 4. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 21 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | * 32 | */ 33 | 34 | char * 35 | strcat(char *dst, const char *src) 36 | { 37 | char *d; 38 | 39 | if (!dst || !src) 40 | return (dst); 41 | 42 | d = dst; 43 | for (; *d; d++); 44 | for (; *src; src++) 45 | *d++ = *src; 46 | *d = 0; 47 | return (dst); 48 | } 49 | -------------------------------------------------------------------------------- /perf_test/lib/strchr.c: -------------------------------------------------------------------------------- 1 | /* $Id: strchr.c,v 1.1.1.1 2006/09/14 01:59:06 root Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2000-2002 Opsycon AB (www.opsycon.se) 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. All advertising materials mentioning features or use of this software 15 | * must display the following acknowledgement: 16 | * This product includes software developed by Opsycon AB. 17 | * 4. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 21 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | * 32 | */ 33 | 34 | char * 35 | strchr(const char *p, int c) 36 | { 37 | if (!p) 38 | return (0); 39 | 40 | for (; *p; p++) 41 | if (*p == c) 42 | return ((char *)p); 43 | return (0); 44 | } 45 | -------------------------------------------------------------------------------- /perf_test/lib/strcspn.c: -------------------------------------------------------------------------------- 1 | /* $Id: strcspn.c,v 1.1.1.1 2006/09/14 01:59:06 root Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2000-2002 Opsycon AB (www.opsycon.se) 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. All advertising materials mentioning features or use of this software 15 | * must display the following acknowledgement: 16 | * This product includes software developed by Opsycon AB. 17 | * 4. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 21 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | * 32 | */ 33 | 34 | int 35 | strcspn (const char *p, const char *s) 36 | { 37 | int i, j; 38 | 39 | for (i = 0; p[i]; i++) { 40 | for (j = 0; s[j]; j++) { 41 | if (s[j] == p[i]) 42 | break; 43 | } 44 | if (s[j]) 45 | break; 46 | } 47 | return (i); 48 | } 49 | -------------------------------------------------------------------------------- /perf_test/lib/strichr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char * 4 | strichr(char *p, int c) 5 | { 6 | char *t; 7 | 8 | if (p != NULL) { 9 | for(t = p; *t; t++); 10 | for (; t >= p; t--) { 11 | *(t + 1) = *t; 12 | } 13 | *p = c; 14 | } 15 | return (p); 16 | } 17 | -------------------------------------------------------------------------------- /perf_test/lib/strspn.c: -------------------------------------------------------------------------------- 1 | /* $Id: strspn.c,v 1.1.1.1 2006/09/14 01:59:06 root Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2000-2002 Opsycon AB (www.opsycon.se) 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. All advertising materials mentioning features or use of this software 15 | * must display the following acknowledgement: 16 | * This product includes software developed by Opsycon AB. 17 | * 4. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 21 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | * 32 | */ 33 | 34 | /* return length of initial segment of p that consists entirely of 35 | * characters from s */ 36 | 37 | int 38 | strspn(const char *p, const char *s) 39 | { 40 | int i, j; 41 | 42 | for (i = 0; p[i]; i++) { 43 | for (j = 0; s[j]; j++) { 44 | if (s[j] == p[i]) 45 | break; 46 | } 47 | if (!s[j]) 48 | break; 49 | } 50 | return (i); 51 | } 52 | -------------------------------------------------------------------------------- /perf_test/lib/strtok.c: -------------------------------------------------------------------------------- 1 | /* $Id: strtok.c,v 1.1.1.1 2006/09/14 01:59:06 root Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2000-2002 Opsycon AB (www.opsycon.se) 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. All advertising materials mentioning features or use of this software 15 | * must display the following acknowledgement: 16 | * This product includes software developed by Opsycon AB. 17 | * 4. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 21 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 24 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | * 32 | */ 33 | 34 | char * 35 | strtok(char *p, const char *tok) 36 | { 37 | static char *t; /* XXX */ 38 | char *r; 39 | int n; 40 | 41 | if (p) 42 | t = p; 43 | 44 | r = t + strspn (t, tok); 45 | if (!(n = strcspn (r, tok))) 46 | return (0); 47 | t = r + n; 48 | if (*t) 49 | *t++ = 0; 50 | return (r); 51 | } 52 | -------------------------------------------------------------------------------- /perf_test/lib/strtoul.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ULONG_MAX 4294967295UL 4 | #define LONG_MAX 2147483647L 5 | #define LONG_MIN (-LONG_MAX-1) 6 | #define isspace(c) (c==0x20) 7 | #define isdigit(c) (((c) >= '0') && ((c) <= '9')) 8 | #define isalpha(c) ( (((c) >= 'A') && ((c) <= 'Z')) || \ 9 | (((c) >= 'a') && ((c) <= 'z')) ) 10 | #define isupper(c) (c>='A' && c<='Z') 11 | 12 | unsigned long 13 | strtoul(const char *nptr,char **endptr,int base) 14 | { 15 | int c; 16 | unsigned long result = 0L; 17 | unsigned long limit; 18 | int negative = 0; 19 | int overflow = 0; 20 | int digit; 21 | 22 | while ((c = *nptr) && isspace(c)) /* skip leading white space */ 23 | nptr++; 24 | 25 | if ((c = *nptr) == '+' || c == '-') { /* handle signs */ 26 | negative = (c == '-'); 27 | nptr++; 28 | } 29 | 30 | if (base == 0) { /* determine base if unknown */ 31 | base = 10; 32 | if (*nptr == '0') { 33 | base = 8; 34 | nptr++; 35 | if ((c = *nptr) == 'x' || c == 'X') { 36 | base = 16; 37 | nptr++; 38 | } 39 | } 40 | } else if (base == 16 && *nptr == '0') { 41 | /* discard 0x/0X prefix if hex */ 42 | nptr++; 43 | if ((c = *nptr == 'x') || c == 'X') 44 | nptr++; 45 | } 46 | 47 | limit = ULONG_MAX / base; /* ensure no overflow */ 48 | 49 | nptr--; /* convert the number */ 50 | while ((c = *++nptr) != 0) { 51 | if (isdigit(c)) 52 | digit = c - '0'; 53 | else if(isalpha(c)) 54 | digit = c - (isupper(c) ? 'A' : 'a') + 10; 55 | else 56 | break; 57 | if (digit < 0 || digit >= base) 58 | break; 59 | if (result > limit) 60 | overflow = 1; 61 | if (!overflow) { 62 | result = base * result; 63 | if (digit > ULONG_MAX - result) 64 | overflow = 1; 65 | else 66 | result += digit; 67 | } 68 | } 69 | if (negative && !overflow) /* BIZARRE, but ANSI says we should do this! */ 70 | result = 0L - result; 71 | if (overflow) { 72 | //extern int errno; 73 | //errno = ERANGE; 74 | result = ULONG_MAX; 75 | } 76 | 77 | if (endptr != NULL) /* point at tail */ 78 | *endptr = (char *)nptr; 79 | return result; 80 | } 81 | 82 | -------------------------------------------------------------------------------- /perf_test/lib/strtoupp.c: -------------------------------------------------------------------------------- 1 | void 2 | strtoupper(char *p) 3 | { 4 | if(!p) 5 | return; 6 | for (; *p; p++) 7 | *p = toupper (*p); 8 | } 9 | -------------------------------------------------------------------------------- /perf_test/lib/testchar.c: -------------------------------------------------------------------------------- 1 | int testchar() 2 | { 3 | return *(volatile char *)(SERIAL+1); 4 | } 5 | -------------------------------------------------------------------------------- /perf_test/lib/time.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | unsigned _get_count() 5 | { 6 | return *((volatile unsigned *)TIMER_CYCLE_ADDR); 7 | } 8 | 9 | unsigned get_count() 10 | { 11 | return _get_count(); 12 | } 13 | 14 | unsigned long clock_gettime(int sel,struct timespec *tmp) 15 | { 16 | unsigned long n = 0; 17 | n = _get_count(); 18 | tmp->tv_nsec = n*(2*NSEC_PER_USEC/CPU_COUNT_PER_US)%NSEC_PER_USEC; 19 | tmp->tv_usec = (n/CPU_COUNT_PER_US*2)%USEC_PER_MSEC; 20 | tmp->tv_msec = (n/CPU_COUNT_PER_US*2/USEC_PER_MSEC)%MSEC_PER_SEC; 21 | tmp->tv_sec = n/CPU_COUNT_PER_US*2/NSEC_PER_SEC; 22 | printf("clock ns=%d,sec=%d\n",tmp->tv_nsec,tmp->tv_sec); 23 | return 0; 24 | } 25 | 26 | unsigned long get_clock() 27 | { 28 | unsigned long n=0; 29 | n=_get_count(); 30 | return 2*n; 31 | } 32 | 33 | unsigned get_us() { 34 | return *((volatile unsigned *)TIMER_MICROSEC_ADDR); 35 | } 36 | 37 | unsigned long get_ns() { 38 | return get_us() * 1000L; 39 | } 40 | -------------------------------------------------------------------------------- /perf_test/lib/toupper.c: -------------------------------------------------------------------------------- 1 | int 2 | toupper(int c) 3 | { 4 | if(c>='a' && c<='z') 5 | return c-'a'+'A'; 6 | else 7 | return c; 8 | } 9 | -------------------------------------------------------------------------------- /perf_test/lib/udelay.c: -------------------------------------------------------------------------------- 1 | void udelay(int us) 2 | { 3 | int count0,count1; 4 | int debug=0; 5 | us *=CPU_COUNT_PER_US; 6 | asm volatile("mfc0 %0,$9":"=r"(count0)); 7 | do{ 8 | asm volatile("mfc0 %0,$9":"=r"(count1)); 9 | }while(count1 -count0 39 | 40 | .set noreorder 41 | .globl _start 42 | .globl start 43 | .globl __main 44 | _start: 45 | start: 46 | lui t2,0x0040 47 | mtc0 t2, c0_status 48 | mtc0 zero, c0_cause 49 | la sp, _stack 50 | la gp, _gp 51 | 52 | bal shell /* Get current execute address */ 53 | nop 54 | loop: 55 | j loop 56 | 57 | exit: 58 | ori t1,zero,0x00ff 59 | lui AT, 0x8000 60 | sb t1,0x7ffc(AT) 61 | 62 | .org 0x380 63 | jal exception 64 | nop 65 | j exit 66 | nop 67 | -------------------------------------------------------------------------------- /utility/convert_bin.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char **argv) 6 | { 7 | FILE *in; 8 | FILE *out; 9 | 10 | if (argc < 3) 11 | { 12 | fprintf(stderr, "Usage: ./convert_bin binary.in coe.out\n"); 13 | return 1; 14 | } 15 | 16 | char str_bin[256]; 17 | char str_coe[256]; 18 | strncpy(str_bin, argv[1], 256); 19 | strncpy(str_coe, argv[2], 256); 20 | 21 | unsigned char mem[32]; 22 | 23 | in = fopen(str_bin, "rb"); 24 | out = fopen(str_coe, "w"); 25 | 26 | fprintf(out, "memory_initialization_radix = 16;\n"); 27 | fprintf(out, "memory_initialization_vector =\n"); 28 | while (!feof(in)) 29 | { 30 | if (fread(mem, 1, 4, in) != 4) 31 | { 32 | fprintf(out, "%02x%02x%02x%02x\n", mem[3], mem[2], mem[1], mem[0]); 33 | break; 34 | } 35 | fprintf(out, "%02x%02x%02x%02x\n", mem[3], mem[2], mem[1], mem[0]); 36 | } 37 | fclose(in); 38 | fclose(out); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /utility/mem_to_coe.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | LINENUM0=$(wc -l $1 | cut -f 1 -d ' ') 4 | LINENUM=$(echo "1+$LINENUM0" | bc) 5 | 6 | echo ";DEPTH = $LINENUM;" 7 | echo ";WIDTH = 32;" 8 | echo "memory_initialization_radix=16;" 9 | echo "memory_initialization_vector=" 10 | sed 's/$/,/' $1 11 | echo "00000000;" 12 | echo "" 13 | -------------------------------------------------------------------------------- /utility/split_bin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | std::ifstream ifs(argv[1], std::ofstream::binary); 7 | std::ofstream ofs_odd(argv[2], std::ofstream::binary); 8 | std::ofstream ofs_even(argv[3], std::ofstream::binary); 9 | unsigned data; 10 | int cnt = 0; 11 | while(ifs.read(reinterpret_cast(&data), 4)) 12 | { 13 | if(cnt & 1) 14 | ofs_odd.write(reinterpret_cast(&data), 4); 15 | else ofs_even.write(reinterpret_cast(&data), 4); 16 | cnt++; 17 | } 18 | return 0; 19 | } 20 | --------------------------------------------------------------------------------