1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
[fun@kru ~/test]% for i in *;do echo ----- $i -----;cat $i;done
----- f.i -----
void f(void)
{
    g(); /* calling thumb code, while in ARM mode */
}
----- g.i -----
void g(void) __attribute__((section(".custom")));
void g(void)
{
}
----- Makefile -----
CROSS=arm-elf-eabi-
OPTS=-mthumb-interwork -g

a.out: start.o f.o g.o
	$(CROSS)ld -T test.lds start.o f.o g.o

f.o: f.i
	$(CROSS)gcc $(OPTS) -c f.i

g.o: g.i
	$(CROSS)gcc $(OPTS) -c g.i

start.o: start.i
	$(CROSS)gcc $(OPTS) -mthumb -c start.i

test: a.out
	$(CROSS)objdump -d -S a.out

clean:
	rm -f g.o f.o start.o a.out
----- start.i -----
void _start(void)
{
    f();
    g();
}

----- test.lds -----
ENTRY(_start)
OUTPUT_FORMAT(elf32-littlearm)
OUTPUT_ARCH(arm)

MEMORY
{
    RAM1 : ORIGIN = 0x0,        LENGTH = 0x100
    RAM2 : ORIGIN = 0x10000000,     LENGTH = 0x100
}

SECTIONS
{
    .text :
    {
        *(.text)
    } > RAM1

    .custom :
    {
        *(.custom)
    } > RAM2
}