feat: make compatible with openperf

This commit is contained in:
xinyangli 2024-11-09 10:56:27 +08:00
parent a7b830fedd
commit 5fee5aad38
Signed by: xin
SSH key fingerprint: SHA256:UU5pRTl7NiLFJbWJZa+snLylZSXIz5rgHmwjzv8v4oE
79 changed files with 3943 additions and 274 deletions

View file

@ -1,8 +1,8 @@
CROSS_COMPILE := riscv64-linux-gnu-
COMMON_CFLAGS := -fno-pic -march=rv64g -mcmodel=medany -mstrict-align
COMMON_CFLAGS := -fno-pic -march=rv64g -mcmodel=medany -mstrict-align
CFLAGS += $(COMMON_CFLAGS) -static
ASFLAGS += $(COMMON_CFLAGS) -O0
LDFLAGS += -melf64lriscv
LDFLAGS += -melf64lriscv -O2
# overwrite ARCH_H defined in $(AM_HOME)/Makefile
ARCH_H := arch/riscv.h

7
scripts/isa/riscv64.mk Normal file
View file

@ -0,0 +1,7 @@
# This file is from nutshell's am
CROSS_COMPILE := riscv64-unknown-linux-gnu-
COMMON_FLAGS := -fno-pic -march=rv64g -mcmodel=medany
CFLAGS += $(COMMON_FLAGS) -static
ASFLAGS += $(COMMON_FLAGS) -O0
LDFLAGS += -melf64lriscv
ARCH_H := arch/riscv.h

View file

@ -1,6 +1,5 @@
export CROSS_COMPILE := x86_64-linux-gnu-
CFLAGS += -m32 -fno-pic -fno-omit-frame-pointer -march=i386
CFLAGS += -fcf-protection=none # remove endbr32 in Ubuntu 20.04 with a CPU newer than Comet Lake
CFLAGS += --param=min-pagesize=0 # fix warning about "array subscript 0 is outside array bounds"
ASFLAGS += -m32 -fno-pic
LDFLAGS += -melf_i386

View file

@ -1,5 +1,4 @@
export CROSS_COMPILE := x86_64-linux-gnu-
CFLAGS += -m64 -fPIC -mno-sse
CFLAGS += --param=min-pagesize=0 # fix warning about "array subscript 0 is outside array bounds"
ASFLAGS += -m64 -fPIC
LDFLAGS += -melf_x86_64

41
scripts/linker-soc.ld Normal file
View file

@ -0,0 +1,41 @@
ENTRY(_start)
MEMORY {
mrom : ORIGIN = 0x20000000, LENGTH = 4K
sram : ORIGIN = 0x0f000000, LENGTH = 8K
}
SECTIONS {
.text : {
_stext = .;
*(entry);
*(.text*);
_etext = .;
} > mrom AT> mrom
.rodata : {
_srodata = .;
*(.rodata*);
*(.srodata*);
_erodata = .;
} > mrom AT> mrom
.data : {
_sdata = .;
*(.data*);
*(.sdata*);
_edata = .; /* Note that this is VMA */
} > sram AT> mrom
_data_size = SIZEOF(.data);
_data_load_start = LOADADDR(.data);
.bss : {
_sbss = .;
*(.bss*);
*(.sbss*);
*(.scommon);
_ebss = .;
} > sram
_end = .;
_heap_start = ALIGN(0x1000);
_stack_pointer = _sram_start + _sram_limit;
}

View file

@ -25,7 +25,7 @@ SECTIONS {
*(.scommon)
}
_stack_top = ALIGN(0x1000);
. = _stack_top + 0x8000;
. = _stack_top + 0x10000;
_stack_pointer = .;
end = .;
_end = .;

View file

@ -12,13 +12,16 @@ AM_SRCS := native/trm.c \
native/ioe/audio.c \
native/ioe/disk.c \
CFLAGS += -fpie $(shell sdl2-config --cflags)
ASFLAGS += -fpie -pie
CFLAGS += -fpie
comma = ,
LDFLAGS_CXX = $(addprefix -Wl$(comma), $(LDFLAGS)) -pie -ldl $(shell sdl2-config --libs)
LDFLAGS_CXX = $(addprefix -Wl$(comma), $(LDFLAGS))
image:
@echo + LD "->" $(IMAGE_REL)
@g++ -pie -o $(IMAGE) -Wl,--whole-archive $(LINKAGE) -Wl,-no-whole-archive $(LDFLAGS_CXX) -lSDL2 -ldl
run: image
$(IMAGE).elf
$(IMAGE)
gdb: image
gdb -ex "handle SIGUSR1 SIGUSR2 SIGSEGV noprint nostop" $(IMAGE).elf
gdb -ex "handle SIGUSR1 SIGUSR2 SIGSEGV noprint nostop" $(IMAGE)

View file

@ -8,28 +8,23 @@ AM_SRCS := platform/nemu/trm.c \
platform/nemu/mpe.c
CFLAGS += -fdata-sections -ffunction-sections
CFLAGS += -I$(AM_HOME)/am/src/platform/nemu/include
LDSCRIPTS += $(AM_HOME)/scripts/linker.ld
LDFLAGS += --defsym=_pmem_start=0x80000000 --defsym=_entry_offset=0x0
LDFLAGS += -T $(AM_HOME)/scripts/linker.ld \
--defsym=_pmem_start=0x80000000 --defsym=_entry_offset=0x0
LDFLAGS += --gc-sections -e _start
NEMUFLAGS += -l $(shell dirname $(IMAGE).elf)/nemu-log.txt
NEMUFLAGS += -b
#-l $(shell dirname $(IMAGE).elf)/nemu-log.txt
MAINARGS_MAX_LEN = 64
MAINARGS_PLACEHOLDER = The insert-arg rule in Makefile will insert mainargs here.
CFLAGS += -DMAINARGS_MAX_LEN=$(MAINARGS_MAX_LEN) -DMAINARGS_PLACEHOLDER=\""$(MAINARGS_PLACEHOLDER)"\"
CFLAGS += -DMAINARGS=\"$(mainargs)\"
CFLAGS += -I$(AM_HOME)/am/src/platform/nemu/include
.PHONY: $(AM_HOME)/am/src/platform/nemu/trm.c
insert-arg: image
@python $(AM_HOME)/tools/insert-arg.py $(IMAGE).bin $(MAINARGS_MAX_LEN) "$(MAINARGS_PLACEHOLDER)" "$(mainargs)"
image: image-dep
image: $(IMAGE).elf
@$(OBJDUMP) -d $(IMAGE).elf > $(IMAGE).txt
@echo + OBJCOPY "->" $(IMAGE_REL).bin
@$(OBJCOPY) -S --set-section-flags .bss=alloc,contents -O binary $(IMAGE).elf $(IMAGE).bin
run: insert-arg
run: image
$(MAKE) -C $(NEMU_HOME) ISA=$(ISA) run ARGS="$(NEMUFLAGS)" IMG=$(IMAGE).bin
gdb: insert-arg
gdb: image
$(MAKE) -C $(NEMU_HOME) ISA=$(ISA) gdb ARGS="$(NEMUFLAGS)" IMG=$(IMAGE).bin
.PHONY: insert-arg

View file

@ -9,23 +9,22 @@ AM_SRCS := riscv/npc/start.S \
platform/dummy/mpe.c
CFLAGS += -fdata-sections -ffunction-sections
LDSCRIPTS += $(AM_HOME)/scripts/linker.ld
LDFLAGS += --defsym=_pmem_start=0x80000000 --defsym=_entry_offset=0x0
LDFLAGS += -T $(AM_HOME)/scripts/linker.ld \
--defsym=_pmem_start=0x80000000 --defsym=_entry_offset=0x0
LDFLAGS += --gc-sections -e _start
CFLAGS += -DMAINARGS=\"$(mainargs)\"
.PHONY: $(AM_HOME)/am/src/riscv/npc/trm.c
MAINARGS_MAX_LEN = 64
MAINARGS_PLACEHOLDER = The insert-arg rule in Makefile will insert mainargs here.
CFLAGS += -DMAINARGS_MAX_LEN=$(MAINARGS_MAX_LEN) -DMAINARGS_PLACEHOLDER=\""$(MAINARGS_PLACEHOLDER)"\"
insert-arg: image
@python $(AM_HOME)/tools/insert-arg.py $(IMAGE).bin $(MAINARGS_MAX_LEN) "$(MAINARGS_PLACEHOLDER)" "$(mainargs)"
image: image-dep
image: $(IMAGE).elf
@$(OBJDUMP) -d $(IMAGE).elf > $(IMAGE).txt
@echo + OBJCOPY "->" $(IMAGE_REL).bin
@$(OBJCOPY) -S --set-section-flags .bss=alloc,contents -O binary $(IMAGE).elf $(IMAGE).bin
run: insert-arg
echo "TODO: add command here to run simulation"
ref= $(NEMU_HOME)/build/riscv32-nemu-interpreter-so
.PHONY: insert-arg
run: image
make -f $(NPC_HOME)/scripts/sim.mk all
$(NPC_HOME)/build/npc $(IMAGE).bin $(ref)
gdb: image
make -f $(NPC_HOME)/scripts/sim.mk all
gdb --args $(NPC_HOME)/build/npc $(IMAGE).bin

View file

@ -11,7 +11,7 @@ build-arg: image
BOOT_HOME := $(AM_HOME)/am/src/x86/qemu/boot
image: image-dep
image: $(IMAGE).elf
@$(MAKE) -s -C $(BOOT_HOME)
@echo + CREATE "->" $(IMAGE_REL)
@( cat $(BOOT_HOME)/bootblock.o; head -c 1024 /dev/zero; cat $(IMAGE).elf ) > $(IMAGE)

View file

@ -0,0 +1,31 @@
AM_SRCS := riscv/ysyxsoc/start.S \
riscv/ysyxsoc/trm.c \
riscv/ysyxsoc/ioe.c \
riscv/ysyxsoc/timer.c \
riscv/ysyxsoc/input.c \
riscv/ysyxsoc/cte.c \
riscv/ysyxsoc/trap.S \
platform/dummy/vme.c \
platform/dummy/mpe.c
CFLAGS += -fdata-sections -ffunction-sections
LDFLAGS += -T $(AM_HOME)/scripts/linker-soc.ld \
--defsym=_mrom_start=0x20000000 --defsym=_sram_start=0x0f000000 \
--defsym=_entry_offset=0x0 --defsym=_sram_limit=0x2000 #-M
LDFLAGS += --gc-sections -e _start
CFLAGS += -DMAINARGS=\"$(mainargs)\"
.PHONY: $(AM_HOME)/am/src/riscv/ysyxsoc/trm.c
image: $(IMAGE).elf
@$(OBJDUMP) -d $(IMAGE).elf > $(IMAGE).txt
@echo + OBJCOPY "->" $(IMAGE_REL).bin
@$(OBJCOPY) -S --set-section-flags .bss=alloc,contents -O binary $(IMAGE).elf $(IMAGE).bin
ref= $(NEMU_HOME)/riscv32-nemu-interpreter-so
run: image
make -f $(NPC_HOME)/scripts/sim.mk all
$(NPC_HOME)/build/ysyxSoCFull $(IMAGE).bin $(ref)
gdb: image
make -f $(NPC_HOME)/scripts/sim.mk all
gdb --args $(NPC_HOME)/build/npc $(IMAGE).bin

View file

@ -1,8 +1,8 @@
include $(AM_HOME)/scripts/isa/riscv.mk
include $(AM_HOME)/scripts/platform/nemu.mk
CFLAGS += -DISA_H=\"riscv/riscv.h\"
COMMON_CFLAGS += -march=rv32im_zicsr -mabi=ilp32 # overwrite
LDFLAGS += -melf32lriscv # overwrite
COMMON_CFLAGS += -march=rv32im_zicsr -mabi=ilp32 # overwrite
LDFLAGS += -melf32lriscv # overwrite
AM_SRCS += riscv/nemu/start.S \
riscv/nemu/cte.c \

View file

@ -0,0 +1,10 @@
include $(AM_HOME)/scripts/isa/riscv.mk
include $(AM_HOME)/scripts/platform/ysyxsoc.mk
COMMON_CFLAGS += -march=rv32e_zicsr -mabi=ilp32e # overwrite
LDFLAGS += -melf32lriscv # overwrite
AM_SRCS += riscv/ysyxsoc/libgcc/div.S \
riscv/ysyxsoc/libgcc/muldi3.S \
riscv/ysyxsoc/libgcc/multi3.c \
riscv/ysyxsoc/libgcc/ashldi3.c \
riscv/ysyxsoc/libgcc/unused.c

View file

@ -0,0 +1,35 @@
include $(AM_HOME)/scripts/isa/riscv.mk
AM_SRCS := riscv/nutshell/isa/riscv/boot/start.S \
riscv/nutshell/common/mainargs.S \
riscv/nutshell/isa/riscv/trm.c \
riscv/nutshell/common/uartlite.c \
riscv/nutshell/common/ioe.c \
riscv/nutshell/common/timer.c \
platform/dummy/input.c \
platform/dummy/video.c \
platform/dummy/audio.c \
platform/dummy/cte.c \
platform/dummy/vme.c \
platform/dummy/mpe.c \
COMMON_CFLAGS += -march=rv64im_zicsr -mabi=lp64 # overwrite
LDFLAGS += -melf64lriscv # overwrite
CFLAGS += -I$(AM_HOME)/am/src/riscv/nutshell/include -DISA_H=\"riscv.h\"
ASFLAGS += -DMAINARGS=\"$(mainargs)\" # for mainargs.S, modify in the future
CFLAGS += -DMAINARGS=\"$(mainargs)\" # for trm.c
.PHONY: $(AM_HOME)/am/src/riscv/nutshell/common/mainargs.S
LDFLAGS += -L $(AM_HOME)/am/src/riscv/nutshell/ldscript
LDFLAGS += -T $(AM_HOME)/am/src/riscv/nutshell/isa/riscv/boot/loader64.ld
image: $(IMAGE).elf
@$(OBJDUMP) -d $(IMAGE).elf > $(IMAGE).txt
@echo + OBJCOPY "->" $(IMAGE_REL).bin
@$(OBJCOPY) -S --set-section-flags .bss=alloc,contents -O binary $(IMAGE).elf $(IMAGE).bin
run: image
$(NUTSHELL_HOME)/build/emu --no-diff -i $(abspath $(IMAGE).bin)

View file

@ -10,10 +10,10 @@ AM_SRCS := riscv/spike/trm.c \
platform/dummy/mpe.c \
CFLAGS += -fdata-sections -ffunction-sections
LDSCRIPTS += $(AM_HOME)/am/src/riscv/spike/linker.ld
LDFLAGS += -T $(AM_HOME)/am/src/riscv/spike/linker.ld
LDFLAGS += --gc-sections -e _start
CFLAGS += -DMAINARGS=\"$(mainargs)\"
.PHONY: $(AM_HOME)/am/src/riscv/spike/trm.c
image: image-dep
image: $(IMAGE).elf