Open qianfan-Zhao opened 1 year ago
Not bad... I'm impressed!
It has same issue when testing in ubuntu 20.04 with qemu 4.2.1, but I don't know the reason, however it works after remove "packed" and add "align(4)"
Good idea to use -d guest_errors
. I think unpacking the structs themselves is a bad idea because they are actually aligned in memory per the datasheet. Adding the alignment in the linker works obviously b/c it forces all data to be aligned on a 4-byte boundary, and because the structs are uint32_t
they end up aligned. A bad compiler though would still be free to put padding in between the uint32_t
, or if they weren't uint32_t
padding would get added.
A better solution I think is to use typedef volatile struct __attribute__((packed, aligned(4)))
which should align the stuct itself and leave it packed.
I tested this on my system with qemu 8.0.2 and gcc 12.2 and it started working.
08_scheduler
doesn't work on my WSL2, no uart message anymore afterWelcome to Chapter 8, Scheduling!
.Version:
I had debug the source code and found
ptimer_isr
is never enter, that will make the global variablesystimie
always zero. Appending-d guest_errors
to qemu command line params, I got next error messages:The private timer registers should be accessed with uint32, but qemu report it was accessed by uint8, let's check the disassemble code:
Yes, it is accessed by uint8. Remove the
__attribute__((packed))
from the register declare structure, the gcc will make those register accessed by uint32. Next is a patch:Disassemble code after apply this patch:
qemu work fine and no guest errors now: