Skip to content

Commit 192517f

Browse files
authored
arm64: fix 32 bit memory operations (#63)
Ensure to use unsigned memory move instructions when moving 32 bit data in a 64 bit register. If the MSb of a 32 bit word in the memory is 1 the value is interpreted as signed and stored as such in the 64 bit register. E.g. moving the 0xe8000020 value from memory to register would result such register being set to 0xffffffffe8000020. A successive access to the memory based on such value will most probably trigger a memory exception.
1 parent 1b7ab88 commit 192517f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

internal/reg/reg_arm64.s

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@
77

88
// func Move(dst uint32, src uint32)
99
TEXT ·Move(SB),$0-8
10-
MOVW dst+0(FP), R0
11-
MOVW src+4(FP), R1
10+
MOVWU dst+0(FP), R0
11+
MOVWU src+4(FP), R1
1212

1313
// copy src to dst
14-
MOVW (R1), R3
15-
MOVW R3, (R0)
14+
MOVWU (R1), R3
15+
MOVWU R3, (R0)
1616

1717
// zero out src
18-
MOVW $0, R3
19-
MOVW R3, (R1)
18+
MOVWU $0, R3
19+
MOVWU R3, (R1)
2020

2121
RET
2222

2323
// func Write(addr uint32, val uint32)
2424
TEXT ·Write(SB),$0-8
25-
MOVW addr+0(FP), R0
26-
MOVW val+4(FP), R1
25+
MOVWU addr+0(FP), R0
26+
MOVWU val+4(FP), R1
2727

28-
MOVW R1, (R0)
28+
MOVWU R1, (R0)
2929

3030
RET
3131

0 commit comments

Comments
 (0)