-
Notifications
You must be signed in to change notification settings - Fork 0
/
relocate.c
262 lines (224 loc) · 7.26 KB
/
relocate.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#include "rom.h"
#include "os_structs.h"
#include "relocate.h"
#include "byte_swap.h"
/**************************************************************************
**************************************************************************
** All Relocate routines assume that the objects are in host order -- all
** they do is make adjustments to the offsets of the pointers. No Relocate
** routines follow pointers.
**************************************************************************
**************************************************************************/
void Relocate_GenericList (void** pList,
UInt16 numEntries,
UInt16 stepSize,
UInt32 oldBase,
UInt32 newBase)
{
UInt16 idex;
UInt32* pVal;
for (idex = 0; idex < numEntries; idex++)
{
pVal = (UInt32*)pList;
if (*pVal)
*pVal = *pVal - oldBase + newBase;
pList = (void**)((UInt8*) pList + stepSize);
}
}
void Relocate_SysNVParams (SysNVParamsPtr pParams,
UInt32 oldBase,
UInt32 newBase)
{
if (! pParams)
return;
if (pParams->splashScreenPtr != 0)
pParams->splashScreenPtr = pParams->splashScreenPtr + newBase - oldBase;
if (pParams->hardResetScreenPtr != 0)
pParams->hardResetScreenPtr = pParams->hardResetScreenPtr + newBase - oldBase;
}
void Relocate_MemMstrPtrTable (MemMstrPtrTablePtr pTable,
UInt32 oldBase,
UInt32 newBase)
{
if (! pTable)
return;
if (pTable->nextTblOffset != 0)
pTable->nextTblOffset = pTable->nextTblOffset + newBase - oldBase;
Relocate_GenericList ((void**)(pTable+1), pTable->numEntries,
sizeof (UInt32), oldBase, newBase);
}
void Relocate_Mem1MstrPtrTable (Mem1MstrPtrTablePtr pTable,
UInt32 oldBase,
UInt32 newBase)
{
if (! pTable)
return;
if (pTable->nextTblOffset != 0)
pTable->nextTblOffset = pTable->nextTblOffset + newBase - oldBase;
Relocate_GenericList ((void**)(pTable+1), pTable->numEntries,
sizeof (UInt32), oldBase, newBase);
}
void Relocate_MemChunkHeader (MemChunkHeaderPtr pChunk,
UInt32 oldBase,
UInt32 newBase)
{
if (! pChunk)
return;
}
void Relocate_Mem1ChunkHeader (Mem1ChunkHeaderPtr pChunk,
UInt32 oldBase,
UInt32 newBase)
{
if (! pChunk)
return;
}
void Relocate_MemChunk (MemChunkHeaderUnionType* pChunk,
UInt16 version,
UInt32 oldBase,
UInt32 newBase)
{
if (version == 0x01)
Relocate_Mem1ChunkHeader (&pChunk->header.ver1, oldBase, newBase);
else
Relocate_MemChunkHeader (&pChunk->header.ver2, oldBase, newBase);
}
void Relocate_CardHeader (CardHeaderPtr pCard,
UInt32 oldBase,
UInt32 newBase)
{
if (! pCard)
return;
if (pCard->resetVector != 0)
pCard->resetVector = pCard->resetVector + newBase - oldBase;
if (pCard->blockListOffset != 0)
pCard->blockListOffset = pCard->blockListOffset + newBase - oldBase;
if (pCard->readWriteParmsOffset != 0)
pCard->readWriteParmsOffset = pCard->readWriteParmsOffset
+ newBase - oldBase;
if (pCard->readOnlyParmsOffset != 0)
pCard->readOnlyParmsOffset = pCard->readOnlyParmsOffset
+ newBase - oldBase;
if (pCard->bigROMOffset != 0)
pCard->bigROMOffset = pCard->bigROMOffset + newBase - oldBase;
if (pCard->readWriteWorkingOffset != 0)
pCard->readWriteWorkingOffset = pCard->readWriteWorkingOffset
+ newBase - oldBase;
}
void Relocate_StorageHeader (StorageHeaderPtr pStore,
UInt32 oldBase,
UInt32 newBase)
{
if (! pStore)
return;
if (pStore->heapListOffset != 0)
pStore->heapListOffset = pStore->heapListOffset + newBase - oldBase;
if (pStore->initCodeOffset1 != 0)
pStore->initCodeOffset1 = pStore->initCodeOffset1 + newBase - oldBase;
if (pStore->initCodeOffset2 != 0)
pStore->initCodeOffset2 = pStore->initCodeOffset2 + newBase - oldBase;
if (pStore->databaseDirID != 0)
pStore->databaseDirID = pStore->databaseDirID + newBase - oldBase;
if (pStore->rsvSpace != 0)
pStore->rsvSpace = pStore->rsvSpace + newBase - oldBase;
if (pStore->dynHeapSpace != 0)
pStore->dynHeapSpace = pStore->dynHeapSpace + newBase - oldBase;
if (pStore->firstRAMBlockSize != 0)
pStore->firstRAMBlockSize = pStore->firstRAMBlockSize
+ newBase - oldBase;
Relocate_SysNVParams(&(pStore->nvParams), oldBase, newBase);
if (pStore->initCodeOffset3 != 0)
pStore->initCodeOffset3 = pStore->initCodeOffset3 + newBase - oldBase;
}
void Relocate_HeapHeader (MemHeapHeaderUnionType* pHeader,
UInt32 oldBase,
UInt32 newBase)
{
UInt16 ver;
if (! pHeader)
return;
ver = memUHeapVer (pHeader);
switch (ver)
{
case 1:
Relocate_Mem1MstrPtrTable(&(pHeader->header.ver1.mstrPtrTbl),
oldBase, newBase);
break;
case 2:
Relocate_MemMstrPtrTable(&(pHeader->header.ver2.mstrPtrTbl),
oldBase, newBase);
break;
case 3:
case 4:
Relocate_MemMstrPtrTable(&(pHeader->header.ver3.mstrPtrTbl),
oldBase, newBase);
}
}
void Relocate_HeapList (HeapListPtr pHeapList,
UInt32 oldBase,
UInt32 newBase)
{
if (! pHeapList)
return;
Relocate_GenericList ((void**)pHeapList->heapOffset, pHeapList->numHeaps,
sizeof(pHeapList->heapOffset[0]), oldBase, newBase);
}
/*
* Relocate a record list. This may be a list of resources, records,
* or database headers depending upon 'lType':
* RL_RESOURCES (0) - Resources
* RL_RECORDS (1) - Records
*/
void Relocate_RecordList (RecordListPtr pRecordList,
UInt32 oldBase,
UInt32 newBase,
UInt16 lType)
{
RsrcEntryPtr pRsrc;
RecordEntryPtr pRec;
if (! pRecordList)
return;
pRsrc = (RsrcEntryPtr) &pRecordList->firstEntry;
pRec = (RecordEntryPtr) &pRecordList->firstEntry;
if (pRecordList->nextRecordListID != 0)
pRecordList->nextRecordListID = pRecordList->nextRecordListID
+ newBase - oldBase;
if (lType == RL_RESOURCES)
Relocate_GenericList ((void**)&(pRsrc->localChunkID),
pRecordList->numRecords,
sizeof(*pRsrc), oldBase, newBase);
else
Relocate_GenericList ((void**)&pRec->localChunkID,
pRecordList->numRecords,
sizeof(*pRec), oldBase, newBase);
}
/*
* Relocate a database list. Doesn't relocate the database headers pointed
* to by the list.
*/
void Relocate_DatabaseList (DatabaseListPtr pList,
UInt32 oldBase,
UInt32 newBase)
{
if (! pList)
return;
if (pList->nextRecordListID != 0)
pList->nextRecordListID = pList->nextRecordListID
+ newBase - oldBase;
Relocate_GenericList ((void**)pList->databaseOffset,pList->numDatabases,
sizeof(pList->databaseOffset[0]),oldBase, newBase);
}
void Relocate_DatabaseHdr (DatabaseHdrPtr pDatabase,
UInt32 oldBase,
UInt32 newBase)
{
if (! pDatabase)
return;
if (pDatabase->appInfoID != 0)
pDatabase->appInfoID = pDatabase->appInfoID + newBase - oldBase;
if (pDatabase->sortInfoID != 0)
pDatabase->sortInfoID = pDatabase->sortInfoID + newBase - oldBase;
//pDatabase->creator = pDatabase->creator + newBase - oldBase;
//pDatabase->uniqueIDSeed = pDatabase->uniqueIDSeed + newBase - oldBase;
Relocate_RecordList(&(pDatabase->recordList), oldBase, newBase,
IsResource(pDatabase) ? RL_RESOURCES : RL_RECORDS);
}