Adding includes to baremetal c code

165 views
Skip to first unread message

Damien Towning

unread,
Jul 19, 2022, 9:13:24 PM7/19/22
to Chipyard
I am just wondering what the situation is when adding includes to baremetal c code for consumption by Spike. I took a look under the chipyard/tests directory at the Makefile but could not see anything in it about includes in it. I'd like to include  <sys/mman.h> header in a bit of c code I am working on.

Philipp Schmitz

unread,
Jul 20, 2022, 3:29:25 AM7/20/22
to Chipyard
Hi,

running  riscv64-unknown-elf-gcc -xc -E -v - (assuming you use riscv64-unknown-elf-gcc) shows you the standard include paths of your riscv cross compiler.

Including non standard files can be done by defining INC=-I/path/to/include/file and adding $(INC) to the makefile

%.o: %.c mmio.h spiflash.h
    $(GCC) $(CFLAGS) $(INC) -c $< -o $@

However, <sys/mman.h> assumes an OS and thus does not exist for embedded compilers (see: https://github.com/riscv-collab/riscv-gnu-toolchain/issues/565#issuecomment-876518787)

I hope this helps.

Regards
Philipp

Damien Towning

unread,
Jul 20, 2022, 4:15:05 AM7/20/22
to Chipyard
Thank you. That helps a lot. Now of course I wonder how to tell which libraries I can use and not use? Libraries available somewhere under riscv-tools-install/riscv64-unknown-elf?

Philipp Schmitz

unread,
Jul 20, 2022, 4:43:52 AM7/20/22
to Chipyard
Yes, you should be able to use all libraries that can be found under the paths that running  'riscv64-unknown-elf-gcc -xc -E -v -' returns , i.e riscv-tools-install/lib/gcc/riscv64-unknown-elf/9.2.0/include; riscv-tools-install/lib/gcc/riscv64-unknown-elf/9.2.0/include-fixed; riscv-tools-install/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/include
Reply all
Reply to author
Forward
0 new messages