以下程序计算核心数并打印它。如果我编译程序
riscv64-unknown-elf-gcc -static -mcmodel=medany -Ttext 0x80000000
minimal.S -nostdlib -nostartfiles -o minimal.riscv.elf
并使用spike
运行它spike -p2 minimal.riscv.elf
输出
# of Cores: 2
如果我使用火箭芯片生成器(使用4234cff)构建的火箭芯片做同样的事情
make CONFIG=DualCoreConfig
并在其上运行程序
./emulator-rocketchip-DualCoreConfig minimal.riscv.elf
输出
# of Cores: 1
虽然它应该是2.我是否必须以不同方式构建火箭芯片,还是需要在某处激活另一个核心?
.data
.align 4
num_harts: .dword 0
message: .ascii "# of Cores: "
number_of_cores: .ascii "0"
end: .ascii "\n"
.align 4
syscall_data: .space 64
.text
.globl _start
_start:
csrr a0, mhartid # get core id
la t1, num_harts # load address of num_harts
li t2, 1 # set register t2=1
amoadd.w zero, t2, (t1) # use atomar instruction to count and write # of cores
rdcycle t0 # read cycles
li t1, 50000 # set t1=50000
add t1, t0, t1 # add 50000 to read cycles and store in t1
3: rdcycle t0 # read cycles
blt t0, t1, 3b # until t0 == t1
while: bne a0, zero, while # let all cores exept core 0 run infinitely
la t0, num_harts # load address of num_harts
lw a0, 0(t0) # set a0=num_harts
add a0, a0, 48 # convert # of cores to ascii
la t0, number_of_cores # get address of reserved string
sb a0, 0(t0) # write # of cores to number_of_cores
add a7, zero, 64 # set syscall for write
add a0, zero, 1 # set a0 to 1
la a1, message # set a1 to address of message
add a2, zero, 17 # set length of address
la t4, syscall_data # end of string
sd a7, 0(t4) # write values to memory
sd a0, 8(t4)
sd a1, 16(t4)
sd a2, 24(t4)
la t0, tohost # execute syscall
sd t4, (t0)
1: ld t5, 64(t0)
beq t5, zero, 1b
sd zero, 64(t0)
add a0, zero, 1 # end program
sd a0, (t0)
3: j 3b
.section ".tohost","aw",@progbits
.align 6
.globl tohost
tohost: .dword 0
.align 6
.globl fromhost
fromhost: .dword 0