Port-arm archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Thumb detector

Once again, I've needed to patch a pkg to not explicitly use ARM-Thumb's
"bx" instruction, this time in devel/gmp.

For ROM-starved embedded devices, some ARM cpus have an extension
called THUMB which is a 16bit-opcode-encoded subset of the full
instruction set. I think that newer CPUs just have it all, for
older you have to look for a "T" in its name. StrongARM variants
don't have it.

There's a calling convention to allow ARM library code being called
from and returning to either ARM or Thumb mode; the library has to
replace the usual "mov pc,lr" by "bx lr" for this.

I think it would be useful if people reporting "illegal instruction"
traps on ARM machines to report whether they're running on a non-
Thumb- aware cpu; some code has been detected to explicitly use
the Thumb-compatibility calling/returning convention (e.g. one
year ago in the ocaml native compiler, now gmp), and it would be
useful to look for that. As not everybody has sharp enough eyes 
to read the fineprint on his CPU, here's a test program.

% cat ctest/thumb/Makefile

.include <bsd.prog.mk>

test: $(PROG)
% cat ctest/thumb/thumb.c
#include <signal.h>
#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>

void thumbit(void);
void handler(int);

jmp_buf env;

int main() {

        int rc;

        rc = setjmp(env);

        if (rc==7) {
                printf("Has no Thumb.\n");

        if (SIG_ERR == signal(SIGILL, handler)) {
                err(1, "can't install trap handler");

        printf("Has Thumb.\n");


thumbit() {
        __asm("bx       lr");

handler(int x) {

        longjmp(env, 7);
% (cd ctest/thumb && make test)
rm -f .gdbinit
touch .gdbinit
#   compile  thumb/thumb.o
cc -O2   -Werror      -c    thumb.c
#      link  thumb/thumb
cc           -o thumb  thumb.o          -Wl,-rpath-link,/lib  -L/lib 
-Wl,-rpath-link,/usr/lib  -L/usr/lib
Has no Thumb.

seal your e-mail: http://www.gnupg.org/

Home | Main Index | Thread Index | Old Index