-
Notifications
You must be signed in to change notification settings - Fork 57
/
cfe_psp_memory.c
549 lines (486 loc) · 15.9 KB
/
cfe_psp_memory.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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
/*
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 United States Government as represented by
** the Administrator of the National Aeronautics and Space Administration.
** All Rights Reserved.
**
** Licensed under the Apache License, Version 2.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:https://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
/******************************************************************************
** File: cfe_psp_memory.c
**
** MCP750 vxWorks 6.x Version
**
** Purpose:
** cFE PSP Memory related functions. This is the implementation of the cFE
** memory areas that have to be preserved, and the API that is designed to allow
** acccess to them. It also contains memory related routines to return the
** address of the kernel code used in the cFE checksum.
**
** History:
** 2006/09/29 A. Cudmore | vxWorks 6.2 MCP750 version
** 2016/04/07 M.Grubb | Updated for PSP version 1.3
**
******************************************************************************/
/*
** Include Files
*/
#include <stdio.h>
#include <string.h>
#include <vxWorks.h>
#include <sysLib.h>
#include <moduleLib.h>
/*
** cFE includes
*/
#include "common_types.h"
#include "osapi.h"
/*
** Types and prototypes for this module
*/
#include "cfe_psp.h"
#include "cfe_psp_memory.h"
#include "target_config.h"
/*
** External Declarations
*/
extern unsigned int GetWrsKernelTextStart(void);
extern unsigned int GetWrsKernelTextEnd(void);
/*
** Global variables
*/
/*
** Pointer to the vxWorks USER_RESERVED_MEMORY area
** The sizes of each memory area is defined in os_processor.h for this architecture.
*/
CFE_PSP_ReservedMemoryMap_t CFE_PSP_ReservedMemoryMap;
CFE_PSP_MemoryBlock_t MCP750_ReservedMemBlock;
/*
*********************************************************************************
** CDS related functions
*********************************************************************************
*/
/******************************************************************************
** Function: CFE_PSP_GetCDSSize
**
** Purpose:
** This function fetches the size of the OS Critical Data Store area.
**
** Arguments:
** (none)
**
** Return:
** (none)
*/
int32 CFE_PSP_GetCDSSize(uint32 *SizeOfCDS)
{
int32 return_code;
if (SizeOfCDS == NULL)
{
return_code = CFE_PSP_ERROR;
}
else
{
*SizeOfCDS = CFE_PSP_ReservedMemoryMap.CDSMemory.BlockSize;
return_code = CFE_PSP_SUCCESS;
}
return (return_code);
}
/******************************************************************************
** Function: CFE_PSP_WriteToCDS
**
** Purpose:
** This function writes to the CDS Block.
**
** Arguments:
** (none)
**
** Return:
** (none)
*/
int32 CFE_PSP_WriteToCDS(const void *PtrToDataToWrite, uint32 CDSOffset, uint32 NumBytes)
{
uint8 *CopyPtr;
int32 return_code;
if (PtrToDataToWrite == NULL)
{
return_code = CFE_PSP_ERROR;
}
else
{
if ((CDSOffset < CFE_PSP_ReservedMemoryMap.CDSMemory.BlockSize) &&
((CDSOffset + NumBytes) <= CFE_PSP_ReservedMemoryMap.CDSMemory.BlockSize))
{
CopyPtr = CFE_PSP_ReservedMemoryMap.CDSMemory.BlockPtr;
CopyPtr += CDSOffset;
memcpy(CopyPtr, (char *)PtrToDataToWrite, NumBytes);
return_code = CFE_PSP_SUCCESS;
}
else
{
return_code = CFE_PSP_ERROR;
}
} /* end if PtrToDataToWrite == NULL */
return (return_code);
}
/******************************************************************************
** Function: CFE_PSP_ReadFromCDS
**
** Purpose:
** This function reads from the CDS Block
**
** Arguments:
** (none)
**
** Return:
** (none)
*/
int32 CFE_PSP_ReadFromCDS(void *PtrToDataToRead, uint32 CDSOffset, uint32 NumBytes)
{
uint8 *CopyPtr;
int32 return_code;
if (PtrToDataToRead == NULL)
{
return_code = CFE_PSP_ERROR;
}
else
{
if ((CDSOffset < CFE_PSP_ReservedMemoryMap.CDSMemory.BlockSize) &&
((CDSOffset + NumBytes) <= CFE_PSP_ReservedMemoryMap.CDSMemory.BlockSize))
{
CopyPtr = CFE_PSP_ReservedMemoryMap.CDSMemory.BlockPtr;
CopyPtr += CDSOffset;
memcpy((char *)PtrToDataToRead, CopyPtr, NumBytes);
return_code = CFE_PSP_SUCCESS;
}
else
{
return_code = CFE_PSP_ERROR;
}
} /* end if PtrToDataToWrite == NULL */
return (return_code);
}
/*
*********************************************************************************
** ES Reset Area related functions
*********************************************************************************
*/
/******************************************************************************
** Function: CFE_PSP_GetResetArea
**
** Purpose:
** This function returns the location and size of the ES Reset information area.
** This area is preserved during a processor reset and is used to store the
** ER Log, System Log and reset related variables
**
** Arguments:
** (none)
**
** Return:
** (none)
*/
int32 CFE_PSP_GetResetArea(cpuaddr *PtrToResetArea, uint32 *SizeOfResetArea)
{
int32 return_code;
if ((PtrToResetArea == NULL) || (SizeOfResetArea == NULL))
{
return_code = CFE_PSP_ERROR;
}
else
{
*PtrToResetArea = (cpuaddr)(CFE_PSP_ReservedMemoryMap.ResetMemory.BlockPtr);
*SizeOfResetArea = CFE_PSP_ReservedMemoryMap.ResetMemory.BlockSize;
return_code = CFE_PSP_SUCCESS;
}
return (return_code);
}
/*
*********************************************************************************
** ES User Reserved Area related functions
*********************************************************************************
*/
/******************************************************************************
** Function: CFE_PSP_GetUserReservedArea
**
** Purpose:
** This function returns the location and size of the memory used for the cFE
** User reserved area.
**
** Arguments:
** (none)
**
** Return:
** (none)
*/
int32 CFE_PSP_GetUserReservedArea(cpuaddr *PtrToUserArea, uint32 *SizeOfUserArea)
{
int32 return_code;
if ((PtrToUserArea == NULL) || (SizeOfUserArea == NULL))
{
return_code = CFE_PSP_ERROR;
}
else
{
*PtrToUserArea = (cpuaddr)(CFE_PSP_ReservedMemoryMap.UserReservedMemory.BlockPtr);
*SizeOfUserArea = CFE_PSP_ReservedMemoryMap.UserReservedMemory.BlockSize;
return_code = CFE_PSP_SUCCESS;
}
return (return_code);
}
/*
*********************************************************************************
** ES Volatile disk memory related functions
*********************************************************************************
*/
/******************************************************************************
** Function: CFE_PSP_GetVolatileDiskMem
**
** Purpose:
** This function returns the location and size of the memory used for the cFE
** volatile disk.
**
** Arguments:
** (none)
**
** Return:
** (none)
*/
int32 CFE_PSP_GetVolatileDiskMem(cpuaddr *PtrToVolDisk, uint32 *SizeOfVolDisk)
{
int32 return_code;
if ((PtrToVolDisk == NULL) || (SizeOfVolDisk == NULL))
{
return_code = CFE_PSP_ERROR;
}
else
{
*PtrToVolDisk = (cpuaddr)(CFE_PSP_ReservedMemoryMap.VolatileDiskMemory.BlockPtr);
*SizeOfVolDisk = CFE_PSP_ReservedMemoryMap.VolatileDiskMemory.BlockSize;
return_code = CFE_PSP_SUCCESS;
}
return (return_code);
}
/*
*********************************************************************************
** ES BSP Top Level Reserved memory initialization
*********************************************************************************
*/
/******************************************************************************
** Function: CFE_PSP_InitProcessorReservedMemory
**
** Purpose:
** This function performs the top level reserved memory initialization.
**
** Arguments:
** (none)
**
** Return:
** (none)
*/
int32 CFE_PSP_InitProcessorReservedMemory(uint32 RestartType)
{
int32 return_code;
if (RestartType != CFE_PSP_RST_TYPE_PROCESSOR)
{
OS_printf("CFE_PSP: Clearing Processor Reserved Memory.\n");
memset(MCP750_ReservedMemBlock.BlockPtr, 0, MCP750_ReservedMemBlock.BlockSize);
/*
** Set the default reset type in case a watchdog reset occurs
*/
CFE_PSP_ReservedMemoryMap.BootPtr->bsp_reset_type = CFE_PSP_RST_TYPE_PROCESSOR;
}
return_code = CFE_PSP_SUCCESS;
return (return_code);
}
/******************************************************************************
** Function: CFE_PSP_SetupReservedMemoryMap
**
** Purpose:
** Set up the CFE_PSP_ReservedMemoryMap global data structure
** This only sets the pointers, it does not initialize the data.
**
** Arguments:
** (none)
**
** Return:
** (none)
*/
void CFE_PSP_SetupReservedMemoryMap(void)
{
cpuaddr start_addr;
cpuaddr end_addr;
/*
** Note: this uses a "cpuaddr" (integer address) as an intermediate
** to avoid warnings about alignment. The output of sysMemTop()
** should be aligned to hold any data type, being the very start
** of the memory space.
*/
start_addr = (cpuaddr)sysMemTop();
end_addr = start_addr;
memset(&CFE_PSP_ReservedMemoryMap, 0, sizeof(CFE_PSP_ReservedMemoryMap));
CFE_PSP_ReservedMemoryMap.BootPtr = (CFE_PSP_ReservedMemoryBootRecord_t *)end_addr;
end_addr += sizeof(CFE_PSP_ReservedMemoryBootRecord_t);
end_addr = (end_addr + CFE_PSP_MEMALIGN_MASK) & ~CFE_PSP_MEMALIGN_MASK;
CFE_PSP_ReservedMemoryMap.ExceptionStoragePtr = (CFE_PSP_ExceptionStorage_t *)end_addr;
end_addr += sizeof(CFE_PSP_ExceptionStorage_t);
end_addr = (end_addr + CFE_PSP_MEMALIGN_MASK) & ~CFE_PSP_MEMALIGN_MASK;
CFE_PSP_ReservedMemoryMap.ResetMemory.BlockPtr = (void *)end_addr;
CFE_PSP_ReservedMemoryMap.ResetMemory.BlockSize = GLOBAL_CONFIGDATA.CfeConfig->ResetAreaSize;
end_addr += CFE_PSP_ReservedMemoryMap.ResetMemory.BlockSize;
end_addr = (end_addr + CFE_PSP_MEMALIGN_MASK) & ~CFE_PSP_MEMALIGN_MASK;
CFE_PSP_ReservedMemoryMap.VolatileDiskMemory.BlockPtr = (void *)end_addr;
CFE_PSP_ReservedMemoryMap.VolatileDiskMemory.BlockSize =
GLOBAL_CONFIGDATA.CfeConfig->RamDiskSectorSize * GLOBAL_CONFIGDATA.CfeConfig->RamDiskTotalSectors;
end_addr += CFE_PSP_ReservedMemoryMap.VolatileDiskMemory.BlockSize;
end_addr = (end_addr + CFE_PSP_MEMALIGN_MASK) & ~CFE_PSP_MEMALIGN_MASK;
CFE_PSP_ReservedMemoryMap.CDSMemory.BlockPtr = (void *)end_addr;
CFE_PSP_ReservedMemoryMap.CDSMemory.BlockSize = GLOBAL_CONFIGDATA.CfeConfig->CdsSize;
end_addr += CFE_PSP_ReservedMemoryMap.CDSMemory.BlockSize;
end_addr = (end_addr + CFE_PSP_MEMALIGN_MASK) & ~CFE_PSP_MEMALIGN_MASK;
CFE_PSP_ReservedMemoryMap.UserReservedMemory.BlockPtr = (void *)end_addr;
CFE_PSP_ReservedMemoryMap.UserReservedMemory.BlockSize = GLOBAL_CONFIGDATA.CfeConfig->UserReservedSize;
end_addr += CFE_PSP_ReservedMemoryMap.UserReservedMemory.BlockSize;
end_addr = (end_addr + CFE_PSP_MEMALIGN_MASK) & ~CFE_PSP_MEMALIGN_MASK;
/* The total size of the entire block is the difference in address */
MCP750_ReservedMemBlock.BlockPtr = (void *)start_addr;
MCP750_ReservedMemBlock.BlockSize = end_addr - start_addr;
OS_printf("CFE_PSP: MCP750 Reserved Memory Block at 0x%08lx, Total Size = 0x%lx\n",
(unsigned long)MCP750_ReservedMemBlock.BlockPtr, (unsigned long)MCP750_ReservedMemBlock.BlockSize);
}
/******************************************************************************
* Function: CFE_PSP_DeleteProcessorReservedMemory
*
* No action on MCP750 - reserved block is statically allocated at sysMemTop.
* Implemented for API consistency with other PSPs.
*/
void CFE_PSP_DeleteProcessorReservedMemory(void) {}
/*
*********************************************************************************
** ES BSP kernel memory segment functions
*********************************************************************************
*/
/******************************************************************************
** Function: CFE_PSP_GetKernelTextSegmentInfo
**
** Purpose:
** This function returns the start and end address of the kernel text segment.
** It may not be implemented on all architectures.
**
** Arguments:
** (none)
**
** Return:
** (none)
*/
int32 CFE_PSP_GetKernelTextSegmentInfo(cpuaddr *PtrToKernelSegment, uint32 *SizeOfKernelSegment)
{
int32 return_code;
cpuaddr StartAddress;
cpuaddr EndAddress;
if (SizeOfKernelSegment == NULL)
{
return_code = CFE_PSP_ERROR;
}
else
{
/*
** Get the kernel start and end
** addresses from the BSP, because the
** symbol table does not contain the symbls we need for this
*/
StartAddress = (cpuaddr)GetWrsKernelTextStart();
EndAddress = (cpuaddr)GetWrsKernelTextEnd();
*PtrToKernelSegment = StartAddress;
*SizeOfKernelSegment = (uint32)(EndAddress - StartAddress);
return_code = CFE_PSP_SUCCESS;
}
return (return_code);
}
/******************************************************************************
** Function: CFE_PSP_GetCFETextSegmentInfo
**
** Purpose:
** This function returns the start and end address of the CFE text segment.
** It may not be implemented on all architectures.
**
** Arguments:
** (none)
**
** Return:
** (none)
*/
int32 CFE_PSP_GetCFETextSegmentInfo(cpuaddr *PtrToCFESegment, uint32 *SizeOfCFESegment)
{
int32 return_code;
STATUS status;
MODULE_ID cFEModuleId;
MODULE_INFO cFEModuleInfo;
cpuaddr GetModuleIdAddr;
MODULE_ID (*GetModuldIdFunc)(void);
if (PtrToCFESegment == NULL || SizeOfCFESegment == NULL)
{
return_code = CFE_PSP_ERROR;
}
else
{
/*
* First attempt to call a function called GetCfeCoreModuleID().
*
* If CFE core was started via the "startCfeCore" routine, this
* provides the actual module ID that was loaded by that routine,
* no matter what it is actually named. This is provided by the
* support/integration code compiled directly into the VxWorks kernel
* image.
*
* The prototype should be:
* MODULE_ID GetCfeCoreModuleID(void);
*/
cFEModuleId = NULL;
GetModuleIdAddr = 0;
return_code = OS_SymbolLookup(&GetModuleIdAddr, "GetCfeCoreModuleID");
if (return_code == OS_SUCCESS && GetModuleIdAddr != 0)
{
GetModuldIdFunc = (MODULE_ID(*)(void))GetModuleIdAddr;
cFEModuleId = GetModuldIdFunc();
}
/*
* If the above did not yield a valid module ID,
* then attempt to find the module ID by name.
* This assumes the core executable name as built by CMake
*/
if (cFEModuleId == NULL)
{
cFEModuleId = moduleFindByName((char *)GLOBAL_CONFIGDATA.Default_CoreFilename);
}
if (cFEModuleId == NULL)
{
return_code = CFE_PSP_ERROR;
}
else
{
status = moduleInfoGet(cFEModuleId, &cFEModuleInfo);
if (status != ERROR)
{
*PtrToCFESegment = (cpuaddr)(cFEModuleInfo.segInfo.textAddr);
*SizeOfCFESegment = (uint32)(cFEModuleInfo.segInfo.textSize);
return_code = CFE_PSP_SUCCESS;
}
else
{
return_code = CFE_PSP_SUCCESS;
}
}
}
return (return_code);
}