11-26-2019, 02:59 PM
Thank you for your quick reply! I tried adding a linker file which I had to modify a little
The lines annotated with /* This is modified */ indicate modifications from fpga/src/bootrom/linker.lds. GCC seems to require these sections (Otherwise compilation fails with undefined reference to _end / _edata / __global_pointer$). The compilation works with the linker file as posted above. Loading the binary in GDB unfortunately still doesn't work.
It seems like the memory is still not writable in that area. Thus, I tried larger ROM_BASE offsets e.g. 800000000 which results in an error at compile time:
Do you have any idea what I am doing wrong?
Code:
ENTRY(main)
SECTIONS
{
ROM_BASE = 0x8000000; /* ... but actually position independent */
. = ROM_BASE;
.text.init : { *(.text.init) }
.text : ALIGN(0x100) {
_TEXT_START_ = .;
*(.text)
_TEXT_END_ = .;
}
PROVIDE( __global_pointer$ = . + (4K / 2) ); /* This is modified */
.data : ALIGN(0x100) {
_DATA_START_ = .;
*(.data)
_DATA_END_ = .;
}
PROVIDE(_data = ADDR(.data));
PROVIDE(_data_lma = LOADADDR(.data));
_edata = .; /* This is modified */
PROVIDE (edata = .);
.bss : ALIGN(0x100) {
_BSS_START_ = .;
*(.bss)
_BSS_END_ = .;
}
.rodata : ALIGN(0x100) {
_RODATA_START_ = .;
*(.rodata)
*(.dtb*)
*(.rodata*)
_RODATA_END_ = .;
}
PROVIDE(_end = .); /* This is modified */
}
The lines annotated with /* This is modified */ indicate modifications from fpga/src/bootrom/linker.lds. GCC seems to require these sections (Otherwise compilation fails with undefined reference to _end / _edata / __global_pointer$). The compilation works with the linker file as posted above. Loading the binary in GDB unfortunately still doesn't work.
Code:
(gdb) load
Loading section .text, size 0xbea6 lma 0x8000000
Loading section .text.startup, size 0x18 lma 0x800bea6
Loading section .data, size 0x1100 lma 0x800bf00
Loading section .eh_frame, size 0x4 lma 0x800d000
Loading section .sdata, size 0x20 lma 0x800d008
Loading section .fini_array, size 0x8 lma 0x800d028
Loading section .init_array, size 0x8 lma 0x800d030
Loading section .init_array.00000, size 0x8 lma 0x800d038
Loading section .rodata, size 0xd10 lma 0x800d200
Loading section .srodata, size 0x8 lma 0x800df10
Loading section .srodata.cst8, size 0x30 lma 0x800df18
Start address 0x80000a6, load size 56642
Transfer rate: 40 KB/sec, 4045 bytes/write.
(gdb) disassemble main
Dump of assembler code for function main:
=> 0x00000000080000a6 <+0>: beqz a3,0x8000020 <_start+32>
0x00000000080000a8 <+2>: jal t4,0x7fdb692
0x00000000080000ac <+6>: jal t4,0x7fdb696
0x00000000080000b0 <+10>: jal t4,0x7fdb69a
0x00000000080000b4 <+14>: jal t4,0x7fdb69e
0x00000000080000b8 <+18>: jal t4,0x7fdb6a2
0x00000000080000bc <+22>: jal t4,0x7fdb6a6
0x00000000080000c0 <+26>: jal t4,0x7fdb6aa
0x00000000080000c4 <+30>: jal t4,0x7fdb6ae
0x00000000080000c8 <+34>: jal t4,0x7fdb6b2
0x00000000080000cc <+38>: jal t4,0x7fdb6b6
End of assembler dump.
It seems like the memory is still not writable in that area. Thus, I tried larger ROM_BASE offsets e.g. 800000000 which results in an error at compile time:
Code:
~/Desktop/jan/helloworld $ riscv64-unknown-elf-gcc -Tlinker.lds -ffreestanding test.c -o out
/home/pi/Desktop/compiler/lib/gcc/riscv64-unknown-elf/9.2.0/crtbegin.o: in function `__do_global_dtors_aux':
crtstuff.c:(.text+0x0): relocation truncated to fit: R_RISCV_HI20 against `completed.5527'
/tmp/ccgwp6EG.o: in function `main':
test.c:(.text+0x12): relocation truncated to fit: R_RISCV_HI20 against `.LC0'
/home/pi/Desktop/compiler/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/lib/libc.a(lib_a-exit.o): in function `exit':
exit.c:(.text+0xe): relocation truncated to fit: R_RISCV_HI20 against symbol `_global_impure_ptr' defined in .srodata section in /home/pi/Desktop/compiler/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/lib/libc.a(lib_a-impure.o)
/home/pi/Desktop/compiler/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/lib/libc.a(lib_a-printf.o): in function `_printf_r':
printf.c:(.text+0x22): relocation truncated to fit: R_RISCV_HI20 against symbol `_impure_ptr' defined in .sdata section in /home/pi/Desktop/compiler/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/lib/libc.a(lib_a-impure.o)
/home/pi/Desktop/compiler/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/lib/libc.a(lib_a-vfprintf.o): in function `.L3':
vfprintf.c:(.text+0xac): relocation truncated to fit: R_RISCV_HI20 against `.LC10'
/home/pi/Desktop/compiler/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/lib/libc.a(lib_a-wsetup.o): in function `__swsetup_r':
wsetup.c:(.text+0x0): relocation truncated to fit: R_RISCV_HI20 against symbol `_impure_ptr' defined in .sdata section in /home/pi/Desktop/compiler/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/lib/libc.a(lib_a-impure.o)
/home/pi/Desktop/compiler/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/lib/libc.a(lib_a-__call_atexit.o): in function `__call_exitprocs':
__call_atexit.c:(.text+0x2): relocation truncated to fit: R_RISCV_HI20 against symbol `_global_impure_ptr' defined in .srodata section in /home/pi/Desktop/compiler/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/lib/libc.a(lib_a-impure.o)
/home/pi/Desktop/compiler/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/lib/libc.a(lib_a-__call_atexit.o): in function `register_fini':
__call_atexit.c:(.text.startup+0xa): relocation truncated to fit: R_RISCV_HI20 against symbol `__libc_fini_array' defined in .text section in /home/pi/Desktop/compiler/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/lib/libc.a(lib_a-fini.o)
/home/pi/Desktop/compiler/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/lib/libc.a(lib_a-fflush.o): in function `.L60':
fflush.c:(.text+0x1d4): relocation truncated to fit: R_RISCV_HI20 against symbol `_impure_ptr' defined in .sdata section in /home/pi/Desktop/compiler/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/lib/libc.a(lib_a-impure.o)
/home/pi/Desktop/compiler/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/lib/libc.a(lib_a-findfp.o): in function `_cleanup_r':
findfp.c:(.text+0x4): relocation truncated to fit: R_RISCV_HI20 against symbol `_fclose_r' defined in .text section in /home/pi/Desktop/compiler/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/lib/libc.a(lib_a-fclose.o)
/home/pi/Desktop/compiler/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/lib/libc.a(lib_a-freer.o): in function `_malloc_trim_r':
mallocr.c:(.text+0x4): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
Do you have any idea what I am doing wrong?