* gcc inline asm unknown mnemonics problems
@ 2022-09-20 4:47 mike
2022-09-20 5:39 ` Xi Ruoyao
0 siblings, 1 reply; 3+ messages in thread
From: mike @ 2022-09-20 4:47 UTC (permalink / raw)
To: gcc-help; +Cc: mike
// gcc_inline_asm_unknown_mnemonics_problems.txt
To: gcc-help@gcc.gnu.org
From: Mike Bennett
gmbgmb@smwireless.net
Before I forget; Thanks for all your good work. I seldom get good info
that has not originated from our efforts.
I am having a problem using ldrexb and strexb using inline assembler. The
code is running on a RPi4 on ubuntu 20.04LTS.
I get an error message "Error: unknown mnemonic `ldrexb' -- `ldrexb
x0,[[sp,8]]'"
I upgraded from gcc 9.4 to gcc 10.3 . It made no difference.
I found a bug report with the following title that may be the cause.
"Bug# 1017961: mozjs102: Fails to build on armel"
The latest versions of gcc are prior to the date on the bug report.
My questions are:
1. Is this bug the cause of my problem?
2. If this is the problem, is there a work around?
3. If the problem is something else please identify the problem?
If you can, please send me an email at the address above.
Thanks Mike.
The test program that illustrates the problem is shown below along with the
make file output.
//***************
// test_ie.h
//***************
#ifndef MACHINE_TYPE_ARM_PI
/* take out WINAPI in "static FORCEINLINE long WINAPI" line below */
static inline long InterlockedExchange( long volatile *dest, long val )
{
long ret;
__asm__ __volatile__( "lock; xchgl %k0,(%1)"
: "=r" (ret) :"r" (dest), "0" (val) : "memory" );
return ret;
}
#else
/* %1 is output = __ret,
%3= *dest is the mutex location,
%2= val the value to put in the mutex
when locked or unlocked,
locked=1, 0=unlocked
*/
static inline volatile long InterlockedExchange( long volatile
*dest, long val )
{
long __ret; /* return value, is the value of lockflag
loaded by ldrex */
/* success/fail result of strex, 0 = success */
if (val != 0)
{
long reg_val;
__asm__ __volatile__
(
"mov %0, %2 \n\t" /* put
lock value in reg */
"ldrexb %1, [%3] \n\t" /* load
mutex lock word */
"cmp %1, #0 \n\t" /* see
if mutex is free, ie lock = 0 */
/****** this cmp is required to set the condition
that
allows strexb to write. ********/
"strexb %1, %0, [%3] \n\t" /* store
lock value in %0 at mem addr %3, */
" \n\t" /* put
result status in r1 */
"cmp %1, #0 \n\t" /* if
strex was successful %1 will be
" \n\t" /* a zero */
"beq ok \n\t" /* if
success, set return value */
:[reg_val] "=r" (reg_val), [__ret] "=r"
(__ret)
:[val] "m" (val), [dest] "m" (dest)
: "cc","memory"
);
__ret = 1; /* failed to get control of mutex */
goto n_ok;
ok: __ret = 0;
}
else
{
*dest = val;
__ret = val;
}
n_ok:
return __ret;
}
#endif
//*******************
// gcc_pi_asm_test.c
//*******************
#include <stdio.h>
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <stdint.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <pthread.h>
#define MACHINE_TYPE_ARM_PI TRUE
#include <test_ie.h>
struct timespec delay_0___1_sec = {0, 1000000 }; //delay 0.001 sec
int nanosleep(const struct timespec *, struct timespec *);
long lock_flag;
//**********************************
// int main()
//**********************************
int main()
{
long ret_val;
while ( (ret_val = InterlockedExchange( &lock_flag, 1) ) != 0)
{
ret_val = nanosleep( &delay_0___1_sec, NULL); // 1 msec
}
return 0;
}
//*********************
// make output
//*********************
mike@pi44:/media/mike/F512_5/Mike/Software/0_Pi4_builds/gcc_pi_asm_test/source$
make
gcc -g -c -std=iso9899:1999 -o obj/gcc_pi_asm_test.o gcc_pi_asm_test.c
-I../include
/tmp/ccVbuJ1z.s: Assembler messages:
/tmp/ccVbuJ1z.s:26: Error: unknown mnemonic `ldrexb' -- `ldrexb x0,[[sp,8]]'
/tmp/ccVbuJ1z.s:28: Error: unknown mnemonic `strexb' -- `strexb
x0,x1,[[sp,8]]'
/tmp/ccVbuJ1z.s:25: Error: undefined symbol sp used as an immediate value
make: *** [makefile:37: obj/gcc_pi_asm_test.o] Error 1
mike@pi44:/media/mike/F512_5/Mike/Software/0_Pi4_builds/gcc_pi_asm_test/source$
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: gcc inline asm unknown mnemonics problems
2022-09-20 4:47 gcc inline asm unknown mnemonics problems mike
@ 2022-09-20 5:39 ` Xi Ruoyao
2022-09-20 10:26 ` Andrew Haley
0 siblings, 1 reply; 3+ messages in thread
From: Xi Ruoyao @ 2022-09-20 5:39 UTC (permalink / raw)
To: mike; +Cc: gcc-help
On Mon, 2022-09-19 at 21:47 -0700, mike wrote:
/* snip */
> I am having a problem using ldrexb and strexb using inline assembler. The
> code is running on a RPi4 on ubuntu 20.04LTS.
>
> I get an error message "Error: unknown mnemonic `ldrexb' -- `ldrexb
> x0,[[sp,8]]'"
ldrexb and strexb are Thumb-2 instructions, but RPi4 uses an AArch64
CPU. AArch64 is an extension of the classic ARM instruction set, not an
extension of Thumb-2. So you can't use them on AArch64.
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: gcc inline asm unknown mnemonics problems
2022-09-20 5:39 ` Xi Ruoyao
@ 2022-09-20 10:26 ` Andrew Haley
0 siblings, 0 replies; 3+ messages in thread
From: Andrew Haley @ 2022-09-20 10:26 UTC (permalink / raw)
To: gcc-help
On 9/20/22 06:39, Xi Ruoyao via Gcc-help wrote:
> On Mon, 2022-09-19 at 21:47 -0700, mike wrote:
>
> /* snip */
>
>> I am having a problem using ldrexb and strexb using inline assembler. The
>> code is running on a RPi4 on ubuntu 20.04LTS.
>>
>> I get an error message "Error: unknown mnemonic `ldrexb' -- `ldrexb
>> x0,[[sp,8]]'"
>
> ldrexb and strexb are Thumb-2 instructions, but RPi4 uses an AArch64
> CPU. AArch64 is an extension of the classic ARM instruction set, not an
> extension of Thumb-2. So you can't use them on AArch64.
The AArch64 name of that instruction is LDAXRB. I'm assuming you're running
a 64-bit kernel: you don't say.
--
Andrew Haley (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-09-20 10:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-20 4:47 gcc inline asm unknown mnemonics problems mike
2022-09-20 5:39 ` Xi Ruoyao
2022-09-20 10:26 ` Andrew Haley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).