mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-10-14 16:57:41 -04:00
Small RISC-V spike demo improvements (#554)
* Put XLEN into .o files. Makes it easier to work on voth RV32 and RV64 binaries side-by-side. * Let the debugger disable HTIF use. * Makefile now links the binary at BASE_ADDRESS I need this so I can easily generate the appropriate binaries for riscv-tests/debug. Unfortunately there doesn't seem to be any good mechanism to externally define values for lds files, so I'm running it through the C preprocessor. Co-authored-by: Joseph Julicher <jjulicher@mac.com>
This commit is contained in:
parent
f87eb7d0d4
commit
c280f26c1b
4 changed files with 31 additions and 17 deletions
|
@ -1,9 +1,11 @@
|
||||||
XLEN ?= 32
|
XLEN ?= 32
|
||||||
CROSS = riscv$(XLEN)-unknown-elf-
|
CROSS = riscv$(XLEN)-unknown-elf-
|
||||||
CC = $(CROSS)gcc
|
CC = $(CROSS)gcc
|
||||||
|
CPP = $(CROSS)cpp
|
||||||
OBJCOPY = $(CROSS)objcopy
|
OBJCOPY = $(CROSS)objcopy
|
||||||
ARCH = $(CROSS)ar
|
ARCH = $(CROSS)ar
|
||||||
DEBUG ?= 0
|
DEBUG ?= 0
|
||||||
|
BASE_ADDRESS ?= 0x80000000
|
||||||
|
|
||||||
ifeq ($(XLEN), 64)
|
ifeq ($(XLEN), 64)
|
||||||
MARCH = rv64ima
|
MARCH = rv64ima
|
||||||
|
@ -33,7 +35,7 @@ CFLAGS = -march=$(MARCH) -mabi=$(MABI) -mcmodel=medany \
|
||||||
-fdata-sections \
|
-fdata-sections \
|
||||||
-fno-builtin-printf
|
-fno-builtin-printf
|
||||||
ASFLAGS = -march=$(MARCH) -mabi=$(MABI) -mcmodel=medany
|
ASFLAGS = -march=$(MARCH) -mabi=$(MABI) -mcmodel=medany
|
||||||
LDFLAGS = -nostartfiles -Tfake_rom.lds \
|
LDFLAGS = -nostartfiles \
|
||||||
-Xlinker --gc-sections \
|
-Xlinker --gc-sections \
|
||||||
-Xlinker --defsym=__stack_size=$(STACK_SIZE)
|
-Xlinker --defsym=__stack_size=$(STACK_SIZE)
|
||||||
|
|
||||||
|
@ -62,20 +64,25 @@ SRCS = main.c main_blinky.c riscv-virt.c htif.c \
|
||||||
ASMS = start.S \
|
ASMS = start.S \
|
||||||
$(RTOS_SOURCE_DIR)/portable/GCC/RISC-V/portASM.S
|
$(RTOS_SOURCE_DIR)/portable/GCC/RISC-V/portASM.S
|
||||||
|
|
||||||
OBJS = $(SRCS:%.c=$(BUILD_DIR)/%.o) $(ASMS:%.S=$(BUILD_DIR)/%.o)
|
OBJS = $(SRCS:%.c=$(BUILD_DIR)/%$(XLEN).o) $(ASMS:%.S=$(BUILD_DIR)/%$(XLEN).o)
|
||||||
DEPS = $(SRCS:%.c=$(BUILD_DIR)/%.d) $(ASMS:%.S=$(BUILD_DIR)/%.d)
|
DEPS = $(SRCS:%.c=$(BUILD_DIR)/%$(XLEN).d) $(ASMS:%.S=$(BUILD_DIR)/%$(XLEN).d)
|
||||||
|
|
||||||
$(BUILD_DIR)/RTOSDemo.axf: $(OBJS) fake_rom.lds Makefile
|
$(BUILD_DIR)/RTOSDemo$(XLEN).axf: $(OBJS) $(BUILD_DIR)/fake_rom$(BASE_ADDRESS).lds Makefile
|
||||||
$(CC) $(LDFLAGS) $(OBJS) -o $@
|
$(CC) $(LDFLAGS) $(OBJS) -T$(BUILD_DIR)/fake_rom$(BASE_ADDRESS).lds -o $@
|
||||||
|
|
||||||
$(BUILD_DIR)/%.o: %.c Makefile
|
$(BUILD_DIR)/%$(XLEN).o: %.c Makefile
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
$(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c $< -o $@
|
$(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
$(BUILD_DIR)/%.o: %.S Makefile
|
$(BUILD_DIR)/%$(XLEN).o: %.S Makefile
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
$(CC) $(CPPFLAGS) $(ASFLAGS) -MMD -MP -c $< -o $@
|
$(CC) $(CPPFLAGS) $(ASFLAGS) -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
|
# Run lds through the C preprocessor, to replace BASE_ADDRESS with the actual
|
||||||
|
# value. It might be simpler to use sed instead.
|
||||||
|
$(BUILD_DIR)/%$(BASE_ADDRESS).lds: fake_rom.lds Makefile
|
||||||
|
$(CPP) $(CPPFLAGS) -DBASE_ADDRESS=$(BASE_ADDRESS) $< | grep -v '^#' > $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(BUILD_DIR)
|
rm -rf $(BUILD_DIR)
|
||||||
|
|
||||||
|
|
|
@ -67,20 +67,20 @@ $ export PATH=~/x-tools/riscv64-unknown-elf/bin:$PATH
|
||||||
To build, simply run `make`. If you want a debug build, pass `DEBUG=1`. If
|
To build, simply run `make`. If you want a debug build, pass `DEBUG=1`. If
|
||||||
you want an RV64 build, pass `XLEN=64`.
|
you want an RV64 build, pass `XLEN=64`.
|
||||||
|
|
||||||
The resulting executable file is ./build/RTOSDemo.axf.
|
The resulting executable file is ./build/RTOSDemo32.axf or ./build/RTOSDemo64.axf.
|
||||||
|
|
||||||
## How to run
|
## How to run
|
||||||
|
|
||||||
RV32:
|
RV32:
|
||||||
```
|
```
|
||||||
$ spike -p1 --isa RV32IMA -m0x80000000:0x10000000 --rbb-port 9824 \
|
$ spike -p1 --isa RV32IMA -m0x80000000:0x10000000 --rbb-port 9824 \
|
||||||
./build/RTOSDemo.axf
|
./build/RTOSDemo32.axf
|
||||||
```
|
```
|
||||||
|
|
||||||
RV64:
|
RV64:
|
||||||
```
|
```
|
||||||
$ spike -p1 --isa RV64IMA -m0x80000000:0x10000000 --rbb-port 9824 \
|
$ spike -p1 --isa RV64IMA -m0x80000000:0x10000000 --rbb-port 9824 \
|
||||||
./build/RTOSDemo.axf
|
./build/RTOSDemo64.axf
|
||||||
```
|
```
|
||||||
|
|
||||||
## How to debug with gdb
|
## How to debug with gdb
|
||||||
|
|
|
@ -4,8 +4,9 @@ ENTRY( _start )
|
||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
/* Fake ROM area */
|
/* Fake ROM area */
|
||||||
rom (rxa) : ORIGIN = 0x80000000, LENGTH = 512K
|
/* BASE_ADDRESS is replaced with the real value by the Makefile. */
|
||||||
ram (wxa) : ORIGIN = 0x80080000, LENGTH = 512K
|
rom (rxa) : ORIGIN = BASE_ADDRESS, LENGTH = 512K
|
||||||
|
ram (wxa) : ORIGIN = BASE_ADDRESS + 512K, LENGTH = 512K
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
|
|
|
@ -40,15 +40,21 @@ int id;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Use a debugger to set this to 0 if this binary was loaded through gdb instead
|
||||||
|
* of spike's ELF loader. HTIF only works if spike's ELF loader was used. */
|
||||||
|
volatile int use_htif = 1;
|
||||||
|
|
||||||
void vSendString( const char *s )
|
void vSendString( const char *s )
|
||||||
{
|
{
|
||||||
portENTER_CRITICAL();
|
portENTER_CRITICAL();
|
||||||
|
|
||||||
|
if (use_htif) {
|
||||||
while (*s) {
|
while (*s) {
|
||||||
htif_putc(*s);
|
htif_putc(*s);
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
htif_putc('\n');
|
htif_putc('\n');
|
||||||
|
}
|
||||||
|
|
||||||
portEXIT_CRITICAL();
|
portEXIT_CRITICAL();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue