Skip to content

Commit 62c9acf

Browse files
committed
Fix linux poweroff syscon
1 parent 07fd36c commit 62c9acf

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The CPU is implemented using a variable-size build-order-independent subframe ar
3333
| `0xf0000030` | `0x20` | R/W | UART1 |
3434
| `0xf0000050` | `0x20` | R/W | UART2 |
3535
| `0xf0000070` | `0x20` | R/W | UART3 |
36-
| `0xfffffff0` | `0x4` | W | Syscon |
36+
| `0xfffffff0` | `0x4` | R/W | Syscon |
3737

3838
\* Atomic instructions are only supported in RAM.
3939

@@ -88,14 +88,15 @@ Note that the processor itself does not set the TX overflow flag or prevent code
8888

8989
### Syscon
9090

91-
Address `0xfffffff0` contains a simple write-only peripheral which can be used to control the system by writing values from the following table. Unsupported values will have no effect if written.
91+
Address `0xfffffff0` contains a simple memory-mapped peripheral which can be used to control the system by writing values from the following table. Unsupported values will have no effect if written. Reads will always return `0`.
9292

9393
| Value | Effect |
9494
| ------------ | --------- |
9595
| `0x00000000` | Power off |
9696
| `0x00000001` | Reboot |
97+
| `0x00000002` | Power off |
9798

98-
Additionally, the machine trap vector CSR `mtvec` is initialized to `0xfffffff0` at reset. To help catch issues with uninitialized `mtvec`, the processor will halt and output an error message if code jumps to this address.
99+
Additionally, the trap vector CSRs `mtvec` and `stvec` are initialized to `0xfffffff0` at reset. To help catch issues with uninitialized trap vectors, the processor will halt and output an error message if a trap jumps to this address.
99100

100101
## ISA
101102

0 Bytes
Binary file not shown.

linux/buildroot/board/mlogv32/dts/mlogv32.dts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
compatible = "syscon-poweroff";
9797
regmap = <&syscon>;
9898
offset = <0x0>;
99-
value = <0x0>;
99+
value = <0x2>;
100100
};
101101

102102
reboot {

src/cpu/worker.mlog.jinja

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,10 @@ load_rom_word_unchecked:
961961
# address, mcause, mtval -> result
962962
load_mmio_word:
963963
#% do declare_locals(access_uart_locals)
964+
# linux syscon driver does a read-modify-write, so the syscon needs to be readable
965+
set result 0
966+
jump load_mmio_word__ret equal address {{SYSCON}}
967+
964968
# the extra 3 at the start is in case we jump here from address translation
965969
# in that case, address may be up to 34 bits
966970
op sub $$offset address {{MMIO_START}}
@@ -977,9 +981,9 @@ load_mmio_word:
977981
#directive end_assert_length
978982

979983
# MCR, MSR, and SPR are all hardwired to zero
980-
set result 0
981984
jump load_mmio_word__uart_lsr equal $$offset 0x24
982985
jump load_mmio_word__not_zero lessThan $$offset 0x20
986+
load_mmio_word__ret:
983987
set @counter ret
984988
load_mmio_word__not_zero:
985989

@@ -1772,9 +1776,9 @@ store_mmio_word_unchecked__uart_fcr__no_reset_tx:
17721776
jump end_instruction always
17731777

17741778
store_value__syscon:
1775-
jump state->halt equal rs2 0
1779+
jump end_instruction greaterThan rs2 2
17761780
jump state->reset equal rs2 1
1777-
jump end_instruction always
1781+
jump state->halt always # 0 or 2 (for linux syscon)
17781782

17791783
LR.W:
17801784
# R-type: rs1, rs2=0, rd_id

0 commit comments

Comments
 (0)