Re: RISC OS modules with stock gcc?
- From: Theo Markettos <theom+news@xxxxxxxxxxxxxxxxxxxxxx>
- Date: 15 Oct 2008 21:08:55 +0100 (BST)
David Given <dg@xxxxxxxxxxx> wrote:
That's very interesting --- how does it do it, if you can remember? Does
it actually manage to use ADR to refer to addresses, or does it assemble
the addresses at runtime via several instructions? (gcc appears to only
be able to fix up 32-bit values, so you can't use symbols as immediate
values on individual machine code instructions --- so you can't refer to
them with ADR.)
See below for some examples.
I've done some playing with gcc, and I've *nearly* gotten it all working
using some abbreviated GOT setup code (28 instructions --- not as good
as I'd hoped), gcc actually turns out to take a few shortcuts that
violate one of my assumptions. Basically, I have global variables and
function pointers working, but have lost some const data and string
constants.
Can you point me at something that explains how the GOT works? I had a
Google but didn't really come up with anything coherent.
My three test programs, built with a slightly out of date version of
Norcroft. -zM means 'generate code suitable for building a RISC OS
relocatable module':
foo1.c:
int bar(int a, int *b);
int foo(int a) {
int b=0;
return bar(a,&b);
}
*cc -s foo1.c
; generated by Norcroft RISC OS ARM C vsn 5.54 [04 Apr 2003]
AREA |C$$code|, CODE, READONLY
|x$codeseg|
DCB &66,&6f,&6f,&00
DCD &ff000004
IMPORT __rt_stkovf_split_small
IMPORT bar
EXPORT foo
foo
MOV ip,sp
STMDB sp!,{a1,fp,ip,lr,pc}
SUB fp,ip,#4
CMP sp,sl
BLMI __rt_stkovf_split_small
MOV a2,#0
STR a2,[sp,#-4]!
MOV a2,sp
BL bar
LDMDB fp,{fp,sp,pc}
AREA |C$$data|,DATA
|x$dataseg|
END
*cc -zM -s foo1.c
; generated by Norcroft RISC OS ARM C vsn 5.54 [04 Apr 2003]
AREA |C$$code|, CODE, READONLY
|x$codeseg|
DCB &66,&6f,&6f,&00
DCD &ff000004
IMPORT __rt_stkovf_split_small
IMPORT bar
EXPORT foo
foo
MOV ip,sp
STMDB sp!,{a1,fp,ip,lr,pc}
SUB fp,ip,#4
CMP sp,sl
BLMI __rt_stkovf_split_small
MOV a2,#0
STR a2,[sp,#-4]!
MOV a2,sp
BL bar
LDMDB fp,{fp,sp,pc}
AREA |C$$data|,DATA
|x$dataseg|
END
int bar(int a, int *b);
int foo(int a) {
static int b=0;
return bar(a,&b);
}
*cc -s foo2.c
; generated by Norcroft RISC OS ARM C vsn 5.54 [04 Apr 2003]
AREA |C$$code|, CODE, READONLY
|x$codeseg|
IMPORT bar
EXPORT foo
foo
LDR a2,[pc, #L000008-.-8]
B bar
L000008
DCD |x$dataseg|
AREA |C$$data|,DATA
|x$dataseg|
DCD &00000000
END
*cc -zM -s foo2.c
; generated by Norcroft RISC OS ARM C vsn 5.54 [04 Apr 2003]
AREA |C$$code|, CODE, READONLY
|x$codeseg|
IMPORT bar
EXPORT foo
foo
LDR a3,[pc, #L000010-.-8]
LDR a2,[sl,#-0]
ADD a2,a2,a3
B bar
L000010
DCD |x$dataseg|
AREA |C$$data|,DATA
|x$dataseg|
DCD &00000000
END
foo3.c:
int b=0;
int bar(int a, int *b);
int foo(int a) {
return bar(a,&b);
}
*cc -s foo3.c
; generated by Norcroft RISC OS ARM C vsn 5.54 [04 Apr 2003]
AREA |C$$code|, CODE, READONLY
|x$codeseg|
IMPORT bar
EXPORT foo
foo
LDR a2,[pc, #L000008-.-8]
B bar
L000008
DCD b
AREA |C$$data|,DATA
|x$dataseg|
EXPORT b
b
DCD &00000000
END
*cc -zM -s foo3.c
; generated by Norcroft RISC OS ARM C vsn 5.54 [04 Apr 2003]
AREA |C$$code|, CODE, READONLY
|x$codeseg|
IMPORT bar
EXPORT foo
foo
LDR a3,[pc, #L000010-.-8]
LDR a2,[sl,#-0]
ADD a2,a2,a3
B bar
L000010
DCD b
AREA |C$$data|,DATA
|x$dataseg|
EXPORT b
b
DCD &00000000
END
.
- Follow-Ups:
- Re: RISC OS modules with stock gcc?
- From: David Given
- Re: RISC OS modules with stock gcc?
- References:
- RISC OS modules with stock gcc?
- From: David Given
- Re: RISC OS modules with stock gcc?
- From: Peter Naulls
- Re: RISC OS modules with stock gcc?
- From: David Given
- Re: RISC OS modules with stock gcc?
- From: David Given
- Re: RISC OS modules with stock gcc?
- From: Theo Markettos
- Re: RISC OS modules with stock gcc?
- From: David Given
- Re: RISC OS modules with stock gcc?
- From: Theo Markettos
- Re: RISC OS modules with stock gcc?
- From: David Given
- RISC OS modules with stock gcc?
- Prev by Date: Re: RISC OS modules with stock gcc?
- Next by Date: SuperFPEm
- Previous by thread: Re: RISC OS modules with stock gcc?
- Next by thread: Re: RISC OS modules with stock gcc?
- Index(es):
Relevant Pages
|