Commit 8f9fd34
committed
Fix system emulation reboot
At 7d13e82, 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 for both modes (interpreter and JIT) 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.
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, etc) instead of re-allocating. For
JIT state resources, might free and re-allocate (e.g., calling
jit_state_exit()) to reuse the existing APIs.
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 dccb5a8 commit 8f9fd34
File tree
10 files changed
+641
-370
lines changed- src
- devices
10 files changed
+641
-370
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 | |
|---|---|---|---|
| |||
1093 | 1093 | | |
1094 | 1094 | | |
1095 | 1095 | | |
1096 | | - | |
1097 | 1096 | | |
1098 | 1097 | | |
1099 | 1098 | | |
| |||
1143 | 1142 | | |
1144 | 1143 | | |
1145 | 1144 | | |
1146 | | - | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
1147 | 1163 | | |
1148 | 1164 | | |
1149 | 1165 | | |
| |||
0 commit comments