ARM:r0 is also corrupted after calling __do_div64.
PATCH 1/1 ARM:r0 is also corrupted after calling __do_div64.
R0 is corrupted after calling __do_div64 and compiler is not informed about this in macro __do_div_asm. If n is to be used again after this macro, r0 is not reloaded and n will contain incorrect value
--- arch/arm/include/asm/div64.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arm/include/asm/div64.h +3 -3
@@ -34,13 +34,13 @@ register unsigned long long __n asm("r0") = n; \ registerunsigned long long __res asm("r2" ); \ register unsigned int __rem asm(__xh); \ - asm( __asmeq("%0", __xh) \ + asm( __asmeq("%R0", __xh) \ __asmeq("%1", "r2") \ __asmeq("%2", "r0") \ __asmeq("%3", "r4") \ "bl __do_div64" \ - : "=r" (__rem), "=r" (__res) \ -: " r" (__n), " r" (__base) \ + : "=r" (__n), "=r" (__res) \ + : "0"(__n), "r" (__base) \: " ip", " lr", " cc"); \ n = __res; \ __rem; \
Signature · 1 line
1.9.1
PATCH 1/1 ARM:r0 is also corrupted after calling __do_div64.
Quoted 3 lines · Chen Gang
R0 is corrupted after calling
__do_div64and compiler is not informed about this in macro__do_div_asm. If n is to be used again after this macro, r0 is not reloaded and n will contain incorrect value
This isn't going to work if we're building for big endian (__ARMEB__ set) because then we end up telling the compiler that __rem and __n are both in r0, which is impossible.
arch/arm/include/asm/div64.h line 36
Quoted 8 lines
arch/arm/include/asm/div64.h +0
-0@@ -34,13 +34,13 @@ register unsigned long long __n asm("r0") = n; \ registerunsigned long long __res asm("r2" ); \ register unsigned int __rem asm(__xh); \
register unsigned int __rem_xh asm(__xh); \ register unsigned int __rem_xl asm(__xl); \
arch/arm/include/asm/div64.h line 37
Quoted 2 lines
arch/arm/include/asm/div64.h +1
-1- asm( __asmeq("%0", __xh) \ + asm( __asmeq("%R0", __xh) \
asm( __asmeq("%0", __xh) \
__asmeq("%1", __xl) \... and increment each following register %-spec by one...
arch/arm/include/asm/div64.h line 43
Quoted 8 lines
arch/arm/include/asm/div64.h +2
-2__asmeq("%1", "r2") \ __asmeq("%2", "r0") \ __asmeq("%3", "r4") \ "bl __do_div64" \ - : "=r" (__rem), "=r" (__res) \ -: " r" (__n), " r" (__base) \ + : "=r" (__n), "=r" (__res) \ + : "0"(__n), "r" (__base) \
This is obviously wrong because __rem is left unset, and that's one of the two values this macro returns.
: "=r" (__rem_xh), "=r" (__rem_xl), "=r" (__res) \ : "r" (__n), "r" (__base) \
arch/arm/include/asm/div64.h line 46
Quoted 3 lines
arch/arm/include/asm/div64.h +0
-0: "ip", "lr", "cc"); \ n = __res; \ __rem; \
__rem_xh;
Basically this renames __rem to __rem_xh, and introduces a new __rem_xl to take the other half of the remainder which we don't use.
Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up according to speedtest.net.
PATCH 1/1 ARM:r0 is also corrupted after calling __do_div64.
R0 is corrupted after calling __do_div64 and compiler is not informed about this in macro __do_div_asm. If n is to be used again after this macro, r0 is not reloaded and n will contain incorrect value
--- arch/arm/include/asm/div64.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
arch/arm/include/asm/div64.h +7 -5
@@ -34,13 +34,15 @@ register unsigned long long __n asm("r0") = n; \ registerunsigned long long __res asm("r2" ); \ register unsigned int __rem asm(__xh); \ + register unsigned int __clobber asm(__xl); \ asm( __asmeq("%0", __xh) \ - __asmeq("%1", "r2") \ - __asmeq("%2", "r0") \ - __asmeq("%3", "r4") \ + __asmeq("%1", __xl) \ + __asmeq("%2", "r2") \ + __asmeq("%3", "r0") \ + __asmeq("%4", "r4") \ "bl __do_div64" \ - : "=r" (__rem), "=r" (__res) \ -: " r" (__n), " r" (__base) \ + : "=r"(__rem), "=r"(__clobber), "=r"(__res) \ +: " r"(__n), " r"(__base) \ : " ip", " lr", " cc"); \ n = __res; \ __rem; \
Signature · 1 line
1.9.1
PATCH 1/1 ARM:r0 is also corrupted after calling __do_div64.
Hi, Russell
The following patch is made according to your suggestion. Could you review or merge it before your context is cleaned? Thanks!
Br, Chen Gang
Quoted 34 lines · Chen Gang
R0 is corrupted after calling
__do_div64and compiler is not informed about this in macro__do_div_asm. If n is to be used again after this macro, r0 is not reloaded and n will contain incorrect valueSigned-off-by Chen Gang <[email protected]>--- arch/arm/include/asm/div64.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)arch/arm/include/asm/div64.h +7
-5@@ -34,13 +34,15 @@ register unsigned long long __n asm("r0") = n; \ registerunsigned long long __res asm("r2" ); \ register unsigned int __rem asm(__xh); \ + register unsigned int __clobber asm(__xl); \ asm( __asmeq("%0", __xh) \ - __asmeq("%1", "r2") \ - __asmeq("%2", "r0") \ - __asmeq("%3", "r4") \ + __asmeq("%1", __xl) \ + __asmeq("%2", "r2") \ + __asmeq("%3", "r0") \ + __asmeq("%4", "r4") \ "bl __do_div64" \ - : "=r" (__rem), "=r" (__res) \ -: " r" (__n), " r" (__base) \ + : "=r"(__rem), "=r"(__clobber), "=r"(__res) \ +: " r"(__n), " r"(__base) \ : " ip", " lr", " cc"); \ n = __res; \ __rem; \
PATCH 1/1 ARM:r0 is also corrupted after calling __do_div64.
In reply to Russell King - ARM LinuxQuoted 7 lines · Russell King - ARM Linux
Quoted 3 lines · Chen Gang
R0 is corrupted after calling
__do_div64and compiler is not informed about this in macro__do_div_asm. If n is to be used again after this macro, r0 is not reloaded and n will contain incorrect valueThis isn't going to work if we're building for big endian (
__ARMEB__set) because then we end up telling the compiler that__remand__nare both in r0, which is impossible.
We tested your suggestion , it works and it feels better. I have sent another patch based on your suggestions.
Quoted 41 lines
arch/arm/include/asm/div64.h line 36
Quoted 9 lines
arch/arm/include/asm/div64.h +0
-0@@ -34,13 +34,13 @@ register unsigned long long __n asm("r0") = n; \ registerunsigned long long __res asm("r2" ); \ register unsigned int __rem asm(__xh); \register unsigned int __rem_xh asm(__xh); \ register unsigned int __rem_xl asm(__xl); \arch/arm/include/asm/div64.h line 37
Quoted 2 lines
arch/arm/include/asm/div64.h +1
-1- asm( __asmeq("%0", __xh) \ + asm( __asmeq("%R0", __xh) \asm( __asmeq("%0", __xh) \ __asmeq("%1", __xl) \... and increment each following register %-spec by one...
arch/arm/include/asm/div64.h line 43
Quoted 8 lines
arch/arm/include/asm/div64.h +2
-2__asmeq("%1", "r2") \ __asmeq("%2", "r0") \ __asmeq("%3", "r4") \ "bl __do_div64" \ - : "=r" (__rem), "=r" (__res) \ -: " r" (__n), " r" (__base) \ + : "=r" (__n), "=r" (__res) \ + : "0"(__n), "r" (__base) \This is obviously wrong because
__remis left unset, and that's one of the two values this macro returns.: "=r" (__rem_xh), "=r" (__rem_xl), "=r" (__res) \ : "r" (__n), "r" (__base) \arch/arm/include/asm/div64.h line 46
Quoted 3 lines
arch/arm/include/asm/div64.h +0
-0: "ip", "lr", "cc"); \ n = __res; \ __rem; \__rem_xh;Basically this renames
__remto__rem_xh, and introduces a new__rem_xlto take the other half of the remainder which we don't use.