Commit ba3011f
committed
Fix system emulation reboot
Previously, the SBI RST extension did not distinguish between reboot and
shutdown type. When a userspace reboot command was issued, the hart was
incorrectly halted as if it were a shutdown.
These changes fix the issue by properly detecting and handling two
reboot types: cold and warm. Each type has its own handler:
rv_cold_reboot() and rv_warm_reboot(). Since the initial system
power-on is treated as a cold reboot, the initialization code has been
refactored to share logic with the reboot path, adhering to the DRY
principle. Additionally, device reset helper functions (plic_reset(),
u8250_reset()) are introduced to support peripheral reinitialization
during reboot.
Key changes:
1. Rename rv_reset() to rv_cold_reboot() - Full system reset including
processor, memory, and all peripherals. The initial power-on is treated
as a cold reboot.
2. Introduce rv_warm_reboot() - Faster reboot that only resets processor
and memory, skipping peripheral reinitialization. Can be triggered via
echo "warm" > /sys/kernel/reboot/mode in guestOS.
3. Refactor boot image loading - Extract load_boot_images() helper to
load kernel, DTB, and initrd, reducing code duplication between cold and
warm reboot paths.
4. Introduce rv_reset_hart() - Static helper function to reset only hart
state (GPRs, CSRs, PC), shared by both reboot modes.
5. Add reboot-safe resource management - Add "check for reboot" comments
throughout initialization to reuse already-allocated resources (memory,
fd_map, PLIC, UART, vblk, block_map) instead of re-allocating.
6. Use calloc for vblk/disk arrays - Changed from malloc to calloc so
pointers are initialized to NULL, simplifying reboot checks.
7. Use setjmp/longjmp for clean reboot - Reboot rewrites all registers,
causing call stack values to become stale. setjmp in rv_step()
establishes a return point, longjmp after reboot provides a clean call
stack.
8. Add plic_reset() and u8250_reset() - New device reset functions to
reinitialize state without free/realloc.
9. Add sbi_rst_type_str() and sbi_rst_reason_str() - Helper functions
for human-readable SBI reset type/reason in dmesg.1 parent 40fcbfe commit ba3011f
File tree
10 files changed
+577
-368
lines changed- src
- devices
10 files changed
+577
-368
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
403 | 403 | | |
404 | 404 | | |
405 | 405 | | |
406 | | - | |
407 | | - | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
408 | 412 | | |
409 | 413 | | |
410 | 414 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1098 | 1098 | | |
1099 | 1099 | | |
1100 | 1100 | | |
1101 | | - | |
1102 | 1101 | | |
1103 | 1102 | | |
1104 | 1103 | | |
| |||
1148 | 1147 | | |
1149 | 1148 | | |
1150 | 1149 | | |
1151 | | - | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
1152 | 1168 | | |
1153 | 1169 | | |
1154 | 1170 | | |
| |||
0 commit comments