-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultilinkrloc.c
103 lines (88 loc) · 2.75 KB
/
multilinkrloc.c
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Multilink.
*
* The Initial Developer of the Original Code is AvantGo, Inc.
* Portions created by AvantGo, Inc. are Copyright (C) 1998-1999
* AvantGo, Inc. All Rights Reserved.
*
* multilinkrloc.c - runtime support for relocating gcc generated data.
*
* created: David Williams, [email protected], July, 1998.
* largely based on code by Kresten Krab Thorup:
*
* Pilot startup code for use with gcc. This code was written
* by Kresten Krab Thorup, and is in the public domain.
* It is *not* under the GPL or the GLPL, you can freely link it
* into your programs.
*/
#include "multilinkrt.h"
#include "multilinkrloc.h"
/*
* This function should be called from
*/
void
MultilinkRelocateDataRsrc(UInt32 rsrcId,
void* text_a, void* data_a, void* bss_a)
{
unsigned long text;
unsigned long bss;
unsigned long data;
MemHandle relocH;
char* relocPtr;
pilot_reloc* relocs;
unsigned count;
unsigned i;
text = (unsigned long)text_a;
bss = (unsigned long)bss_a;
data = (unsigned long)data_a;
relocH = DmGet1Resource('rloc', rsrcId);
if (relocH == 0)
return;
relocPtr = MemHandleLock(relocH);
count = *(unsigned short*)relocPtr;
relocs = (pilot_reloc*)(relocPtr + 2);
for (i = 0; i < count; i++) {
unsigned long* loc;
unsigned offset;
ErrFatalDisplayIf((relocs[i].type != RELOC_ABS_32),
"unknown reloc.type");
offset = relocs[i].offset;
loc = (unsigned long*)((char*)data_a + offset);
switch (relocs[i].section) {
case TEXT_SECTION:
*loc += text;
break;
case DATA_SECTION:
*loc += data;
break;
case BSS_SECTION:
*loc += bss;
break;
default:
ErrDisplay("Unknown reloc.section");
break;
}
}
MemHandleUnlock(relocH);
DmReleaseResource(relocH);
}
#if 0
/* Not used */
void
MultilinkRelocateData(UInt32 rsrcId, void* text_a)
{
extern long data_start, bss_start;
MultilinkRelocateDataRsrc(rsrcId, text_a, &data_start, &bss_start);
}
#endif