From: mike <gmbgmb@smwireless.net>
To: gcc-help@gcc.gnu.org
Cc: mike <gmbgmb@smwireless.net>
Subject: gcc inline asm unknown mnemonics problems
Date: Mon, 19 Sep 2022 21:47:18 -0700 [thread overview]
Message-ID: <17e1dc3f-cca4-1563-fb91-e3ab45d46cc4@smwireless.net> (raw)
// 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$
next reply other threads:[~2022-09-20 4:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-20 4:47 mike [this message]
2022-09-20 5:39 ` Xi Ruoyao
2022-09-20 10:26 ` Andrew Haley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=17e1dc3f-cca4-1563-fb91-e3ab45d46cc4@smwireless.net \
--to=gmbgmb@smwireless.net \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).