FemtoRVのメモリマップを調べる
FemtoRVのメモリマップを調べたい
このへんがあやしい?
FemtoRV/RTL/femtosoc.v
メモリマップ
0xFFFFFFFF (アドレス空間の上限)
0x400000 (IOアドレス開始位置、スタックポインタの初期値)
0x0 (baremetal のプログラム配置場所)
IOアドレスとRAMアドレス
code:FemtoRV/RTL/femtosoc.v
wire mem_address_is_io = mem_address22; wire mem_address_is_ram = !mem_address22; RAMアドレス
0x0から0x3FFFFF (524Kバイト)
IOアドレス
メモリマップトIOのベースアドレス
0x400000
IO_LEDS
0x400004 (0x400000 + 4)
IO_UART_DAT
0x400008 (0x400000 + 8)
IO_UART_CNTL
0x400016 (0x400000 + 16)
code:FIRMWARE/LIBFEMTORV32/femtorv32.inc
# Mapped IO constants
.equ IO_BASE, 0x400000 # Base address of memory-mapped IO
code: FIRMWARE/LIBFEMTORV32/HardwareConfig_bits.inc
.equ IO_LEDS, 4
.equ IO_UART_DAT, 8
.equ IO_UART_CNTL, 16
...
.equ IO_BUTTONS, 2048
code:FemtoRV/RTL/DEVICES/HardwareConfig_bits.v
// We got a total of 20 bits for 1-hot addressing of IO registers.
localparam IO_LEDS_bit = 0; // RW four leds
localparam IO_UART_DAT_bit = 1; // RW write: data to send (8 bits) read: received data (8 bits)
localparam IO_UART_CNTL_bit = 2; // R status. bit 8: valid read data. bit 9: busy sending
...
localparam IO_BUTTONS_bit = 9; // R buttons state
...
// The three constant hardware config registers, using the three last bits of IO address space
localparam IO_HW_CONFIG_RAM_bit = 17; // R total quantity of RAM, in bytes
localparam IO_HW_CONFIG_DEVICES_bit = 18; // R configured devices
localparam IO_HW_CONFIG_CPUINFO_bit = 19; // R CPU information CPL(6) FREQ(10) RESERVED(16)
実際に確保されるRAM
code:FemtoRV/RTL/CONFIGS/ulx3s_config.v
`define NRV_RAM 262144 // default for ULX3S
262144バイト → 262Kバイト(0x40000)
プログラムの開始アドレス
baremetal: 0x0
femtOS elf executable: 0x10000
spi elf: 0x810000
code:FemtoRV/FIRMWARE/makefile.inc
# Generate a "bare metal elf", to be loaded from address 0 (rule for conversion to .hex file in makefile.inc)
# The generated ".hex" file is directly included in the Verilog files, for memory initialization
%.baremetal.elf: %.o $(RV_BINARIES)
$(RVLD) $(RVLDFLAGS) -T$(FIRMWARE_DIR)/CRT/baremetal.ld $< -o $@ $(FEMTORV32_LIBS_SMALL) $(RVGCC_LIB)
# Generate a "femtOS elf executable", to be loaded from address 0x10000 (rule for conversion to .bin file in makefile.inc)
%.elf: %.o $(RV_BINARIES)
$(RVGPP) $(RVCFLAGS) $(RVCPPFLAGS) -nostdlib $< -o $@ -Wl,-gc-sections $(FEMTORV32_LIBS) -lsupc++ $(RVGCC_LIB) $(FIRMWARE_DIR)/CRT/crt0_baremetal.o
# Generate a "spi elf", to be loaded from address 0x810000
%.spiflash.elf: %.o $(RV_BINARIES)
$(RVLD) $(RVLDFLAGS) -T$(FIRMWARE_DIR)/CRT/spiflash_$(BOARD).ld $< -o $@ $(FEMTORV32_LIBS) -lsupc++ $(RVGCC_LIB)
スタックポインタ(sp)の初期値
sp = 0x400000 (IOアドレスの0番地目と同じアドレス)
LEDドライバ
FemtoRV/RTL/DEVICES/LEDs.v
テキスト領域と静的データ領域と動的データ領域とスタック
調べた場所
FemtoRV/FIRMWARE/EXAMPLES/Makefile
FemtoRV/FIRMWARE/makefile.inc
FemtoRV/FIRMWARE/CRT/baremetal.ld (ベアメタルの場合)
FemtoRV/FIRMWARE/TOOLCHAIN/xpack-riscv-none-embed-gcc-10.1.0-1.1-darwin-x64/riscv-none-embed/lib/ldscripts/elf32lriscv.x (femtOS elf executableの場合・デフォルトのリンカスクリプトがこれ)
テキスト領域
開始位置
baremetal: 0x0
femtOS elf executable: 0x10000 (0x0 〜 0xFFFF まではfemtOS本体とファームウェアが入りそう)
静的データ領域