RTEMS: cpukit/include/rtems/score/memory.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
memory.h
Go to the documentation of this file.
1
9/*
10 * SPDX-License-Identifier: BSD-2-Clause
11 *
12 * Copyright (C) 2019 embedded brains GmbH
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef _RTEMS_SCORE_MEMORY_H
37#define _RTEMS_SCORE_MEMORY_H
38
39#include <rtems/score/basedefs.h>
40#include <rtems/score/assert.h>
41
42#ifdef __cplusplus
43extern "C" {
44#endif /* __cplusplus */
45
60 typedef struct {
64 const void *begin;
65
69 void *free;
70
74 const void *end;
75} Memory_Area;
76
80 typedef struct {
84 size_t count;
85
89 Memory_Area *areas;
90} Memory_Information;
91
97#define MEMORY_INFORMATION_INITIALIZER( areas ) \
98 { RTEMS_ARRAY_SIZE( areas ), ( areas ) }
99
106#define MEMORY_INITIALIZER( begin, end ) { ( begin ), ( begin ), ( end ) }
107
115 RTEMS_INLINE_ROUTINE size_t _Memory_Get_count(
116 const Memory_Information *information
117)
118{
119 return information->count;
120}
121
130 RTEMS_INLINE_ROUTINE Memory_Area *_Memory_Get_area(
131 const Memory_Information *information,
132 size_t index
133)
134{
135 _Assert( index < _Memory_Get_count( information ) );
136 return &information->areas[ index ];
137}
138
146 RTEMS_INLINE_ROUTINE void _Memory_Initialize(
147 Memory_Area *area,
148 void *begin,
149 void *end
150)
151{
152 area->begin = begin;
153 area->free = begin;
154 area->end = end;
155}
156
164 RTEMS_INLINE_ROUTINE void _Memory_Initialize_by_size(
165 Memory_Area *area,
166 void *begin,
167 uintptr_t size
168)
169{
170 area->begin = begin;
171 area->free = begin;
172 area->end = (char *) begin + size;
173}
174
182 RTEMS_INLINE_ROUTINE const void *_Memory_Get_begin( const Memory_Area *area )
183{
184 return area->begin;
185}
186
193 RTEMS_INLINE_ROUTINE void _Memory_Set_begin(
194 Memory_Area *area,
195 const void *begin
196)
197{
198 area->begin = begin;
199}
200
208 RTEMS_INLINE_ROUTINE const void *_Memory_Get_end( const Memory_Area *area )
209{
210 return area->end;
211}
212
219 RTEMS_INLINE_ROUTINE void _Memory_Set_end(
220 Memory_Area *area,
221 const void *end
222)
223{
224 area->end = end;
225}
226
234 RTEMS_INLINE_ROUTINE uintptr_t _Memory_Get_size( const Memory_Area *area )
235{
236 return (uintptr_t) area->end - (uintptr_t) area->begin;
237}
238
246 RTEMS_INLINE_ROUTINE void *_Memory_Get_free_begin( const Memory_Area *area )
247{
248 return area->free;
249}
250
257 RTEMS_INLINE_ROUTINE void _Memory_Set_free_begin(
258 Memory_Area *area,
259 void *begin
260)
261{
262 area->free = begin;
263}
264
272 RTEMS_INLINE_ROUTINE uintptr_t _Memory_Get_free_size( const Memory_Area *area )
273{
274 return (uintptr_t) area->end - (uintptr_t) area->free;
275}
276
285 RTEMS_INLINE_ROUTINE void _Memory_Consume(
286 Memory_Area *area,
287 uintptr_t consume
288)
289{
290 area->free = (char *) area->free + consume;
291}
292
304const Memory_Information *_Memory_Get( void );
305
319void *_Memory_Allocate(
320 const Memory_Information *information,
321 uintptr_t size,
322 uintptr_t alignment
323);
324
332void _Memory_Fill( const Memory_Information *information, int c );
333
340extern const bool _Memory_Zero_before_use;
341
345void _Memory_Zero_free_areas( void );
346
350void _Memory_Dirty_free_areas( void );
351
354#ifdef __cplusplus
355}
356#endif /* __cplusplus */
357
358#endif /* _RTEMS_SCORE_MEMORY_H */
assert.h
Information for the Assert Handler.
basedefs.h
Basic Definitions.
_Assert
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100
RTEMS_INLINE_ROUTINE
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:66
_Memory_Initialize
RTEMS_INLINE_ROUTINE void _Memory_Initialize(Memory_Area *area, void *begin, void *end)
Initialize the memory area.
Definition: memory.h:146
_Memory_Get_area
RTEMS_INLINE_ROUTINE Memory_Area * _Memory_Get_area(const Memory_Information *information, size_t index)
Get a memory area by index.
Definition: memory.h:130
_Memory_Get_end
RTEMS_INLINE_ROUTINE const void * _Memory_Get_end(const Memory_Area *area)
Get the memory area end.
Definition: memory.h:208
_Memory_Initialize_by_size
RTEMS_INLINE_ROUTINE void _Memory_Initialize_by_size(Memory_Area *area, void *begin, uintptr_t size)
Initialize the memory area by size.
Definition: memory.h:164
_Memory_Get_count
RTEMS_INLINE_ROUTINE size_t _Memory_Get_count(const Memory_Information *information)
Get the memory area count.
Definition: memory.h:115
_Memory_Get_free_begin
RTEMS_INLINE_ROUTINE void * _Memory_Get_free_begin(const Memory_Area *area)
Get the begin of the free area of the memory area.
Definition: memory.h:246
_Memory_Get
const Memory_Information * _Memory_Get(void)
Return the memory information of this platform.
Definition: bspgetworkarea.c:203
_Memory_Set_begin
RTEMS_INLINE_ROUTINE void _Memory_Set_begin(Memory_Area *area, const void *begin)
Set the memory area begin.
Definition: memory.h:193
_Memory_Get_free_size
RTEMS_INLINE_ROUTINE uintptr_t _Memory_Get_free_size(const Memory_Area *area)
Get the size of the free memory area of the memory area.
Definition: memory.h:272
_Memory_Zero_before_use
const bool _Memory_Zero_before_use
Indicates if the memory is zeroed during system initialization.
Definition: memoryzerobeforeuse.c:34
_Memory_Consume
RTEMS_INLINE_ROUTINE void _Memory_Consume(Memory_Area *area, uintptr_t consume)
Consume the specified size from the free memory area of the memory area.
Definition: memory.h:285
_Memory_Get_size
RTEMS_INLINE_ROUTINE uintptr_t _Memory_Get_size(const Memory_Area *area)
Get the memory area size.
Definition: memory.h:234
_Memory_Dirty_free_areas
void _Memory_Dirty_free_areas(void)
Dirty all free memory areas of the system.
Definition: memorydirtyfreeareas.c:34
_Memory_Allocate
void * _Memory_Allocate(const Memory_Information *information, uintptr_t size, uintptr_t alignment)
Allocate a memory area from the memory information.
Definition: memoryallocate.c:34
_Memory_Set_end
RTEMS_INLINE_ROUTINE void _Memory_Set_end(Memory_Area *area, const void *end)
Set the memory area end.
Definition: memory.h:219
_Memory_Set_free_begin
RTEMS_INLINE_ROUTINE void _Memory_Set_free_begin(Memory_Area *area, void *begin)
Set the begin of the free area of the memory area.
Definition: memory.h:257
_Memory_Zero_free_areas
void _Memory_Zero_free_areas(void)
Zeros all free memory areas of the system.
Definition: memoryzerofreeareas.c:34
_Memory_Get_begin
RTEMS_INLINE_ROUTINE const void * _Memory_Get_begin(const Memory_Area *area)
Get the memory area begin.
Definition: memory.h:182
_Memory_Fill
void _Memory_Fill(const Memory_Information *information, int c)
Fill all free memory areas of the memory information with a constant byte.
Definition: memoryfill.c:36
Memory_Area
The memory area description.
Definition: memory.h:60
Memory_Area::end
const void * end
A pointer to the end of the memory area.
Definition: memory.h:74
Memory_Area::begin
const void * begin
A pointer to the begin of the memory area.
Definition: memory.h:64
Memory_Area::free
void * free
A pointer to the begin of the free area of the memory area.
Definition: memory.h:69
Memory_Information
The memory information.
Definition: memory.h:80
Memory_Information::areas
Memory_Area * areas
The memory area table.
Definition: memory.h:89
Memory_Information::count
size_t count
The count of memory areas.
Definition: memory.h:84