riscvarchive / riscv-qemu

QEMU with RISC-V (RV64G, RV32G) Emulation Support
385 stars 154 forks source link

hw/riscv: add missed header files inclusion #130

Closed frantony closed 6 years ago

frantony commented 6 years ago

Typical error messages:

include/hw/riscv/riscv_hart.h:31:5: error: unknown type name ‘SysBusDevice’ SysBusDevice parent_obj; ^~~~ include/hw/riscv/riscv_hart.h:36:5: error: unknown type name ‘RISCVCPU’ RISCVCPU *harts; ^~~~

Signed-off-by: Antony Pavlov antonynpavlov@gmail.com

michaeljclark commented 6 years ago

Can you update your source and try to build again. e.g.

git fetch
git checkout riscv-all
git reset --hard origin/riscv-all

Travis is building this branch okay (except for an unrelated test failure on the clang build):

Not sure what combination of branches you have checked out to cause that failure... any idea how to reproduce?

Note: The riscv-all branch contains merges of branches that gets rebased against upstream so you can't simply do a git pull. That is likely to result in conflicts and/or unusual build failures.

frantony commented 6 years ago

Current branches has no problem with build at all.

The problem is that current header files use some types (e.g. SysBusDevice) but does not include necessary header files.

Please see detailed explanation in this stackoverflow answer: https://stackoverflow.com/a/1804719

There is no problem with current configuration because header files are included in c-files in a "right" order. Please see hw/riscv/sifive_e.c:

#include "target/riscv/cpu.h"
#include "hw/riscv/riscv_hart.h"

If you change header file inclusion order, e.g.

--- a/hw/riscv/sifive_e.c
+++ b/hw/riscv/sifive_e.c
@@ -37,8 +37,8 @@
 #include "hw/loader.h"
 #include "hw/sysbus.h"
 #include "hw/char/serial.h"
-#include "target/riscv/cpu.h"
 #include "hw/riscv/riscv_hart.h"
+#include "target/riscv/cpu.h"
 #include "hw/riscv/sifive_plic.h"
 #include "hw/riscv/sifive_clint.h"
 #include "hw/riscv/sifive_prci.h"

then you will see this error message

In file included from hw/riscv/sifive_e.c:40:0:
include/hw/riscv/riscv_hart.h:36:5: error: unknown type name ‘RISCVCPU’
     RISCVCPU *harts;
     ^~~~~~~~
michaeljclark commented 6 years ago

This patch doesn't seem to apply now and there isn't currently any compile errors so I'm closing this PR.