1 | /* |
---|
2 | * Workspace Handler |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2009. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.com/license/LICENSE. |
---|
10 | */ |
---|
11 | |
---|
12 | #if HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <rtems/system.h> |
---|
17 | #include <rtems/config.h> |
---|
18 | #include <rtems/score/wkspace.h> |
---|
19 | #include <rtems/score/interr.h> |
---|
20 | |
---|
21 | #include <string.h> /* for memset */ |
---|
22 | |
---|
23 | /* #define DEBUG_WORKSPACE */ |
---|
24 | #if defined(DEBUG_WORKSPACE) |
---|
25 | #include <rtems/bspIo.h> |
---|
26 | #endif |
---|
27 | |
---|
28 | /* |
---|
29 | * _Workspace_Handler_initialization |
---|
30 | */ |
---|
31 | void _Workspace_Handler_initialization(void) |
---|
32 | { |
---|
33 | uintptr_t memory_available = 0; |
---|
34 | void *starting_address = rtems_configuration_get_work_space_start(); |
---|
35 | uintptr_t size = rtems_configuration_get_work_space_size(); |
---|
36 | |
---|
37 | if ( rtems_configuration_get_do_zero_of_workspace() ) |
---|
38 | memset( starting_address, 0, size ); |
---|
39 | |
---|
40 | memory_available = _Heap_Initialize( |
---|
41 | &_Workspace_Area, |
---|
42 | starting_address, |
---|
43 | size, |
---|
44 | CPU_HEAP_ALIGNMENT |
---|
45 | ); |
---|
46 | |
---|
47 | if ( memory_available == 0 ) |
---|
48 | _Internal_error_Occurred( |
---|
49 | INTERNAL_ERROR_CORE, |
---|
50 | true, |
---|
51 | INTERNAL_ERROR_TOO_LITTLE_WORKSPACE |
---|
52 | ); |
---|
53 | } |
---|
54 | |
---|
55 | /* |
---|
56 | * _Workspace_Allocate |
---|
57 | */ |
---|
58 | void *_Workspace_Allocate( |
---|
59 | size_t size |
---|
60 | ) |
---|
61 | { |
---|
62 | void *memory; |
---|
63 | |
---|
64 | memory = _Heap_Allocate( &_Workspace_Area, size ); |
---|
65 | #if defined(DEBUG_WORKSPACE) |
---|
66 | printk( |
---|
67 | "Workspace_Allocate(%d) from %p/%p -> %p\n", |
---|
68 | size, |
---|
69 | __builtin_return_address( 0 ), |
---|
70 | __builtin_return_address( 1 ), |
---|
71 | memory |
---|
72 | ); |
---|
73 | #endif |
---|
74 | return memory; |
---|
75 | } |
---|
76 | |
---|
77 | /* |
---|
78 | * _Workspace_Free |
---|
79 | */ |
---|
80 | void _Workspace_Free( |
---|
81 | void *block |
---|
82 | ) |
---|
83 | { |
---|
84 | #if defined(DEBUG_WORKSPACE) |
---|
85 | printk( |
---|
86 | "Workspace_Free(%p) from %p/%p\n", |
---|
87 | block, |
---|
88 | __builtin_return_address( 0 ), |
---|
89 | __builtin_return_address( 1 ) |
---|
90 | ); |
---|
91 | #endif |
---|
92 | _Heap_Free( &_Workspace_Area, block ); |
---|
93 | } |
---|
94 | |
---|
95 | /* |
---|
96 | * _Workspace_Allocate_or_fatal_error |
---|
97 | */ |
---|
98 | void *_Workspace_Allocate_or_fatal_error( |
---|
99 | size_t size |
---|
100 | ) |
---|
101 | { |
---|
102 | void *memory; |
---|
103 | |
---|
104 | memory = _Heap_Allocate( &_Workspace_Area, size ); |
---|
105 | #if defined(DEBUG_WORKSPACE) |
---|
106 | printk( |
---|
107 | "Workspace_Allocate_or_fatal_error(%d) from %p/%p -> %p\n", |
---|
108 | size, |
---|
109 | __builtin_return_address( 0 ), |
---|
110 | __builtin_return_address( 1 ), |
---|
111 | memory |
---|
112 | ); |
---|
113 | #endif |
---|
114 | |
---|
115 | if ( memory == NULL ) |
---|
116 | _Internal_error_Occurred( |
---|
117 | INTERNAL_ERROR_CORE, |
---|
118 | true, |
---|
119 | INTERNAL_ERROR_WORKSPACE_ALLOCATION |
---|
120 | ); |
---|
121 | |
---|
122 | return memory; |
---|
123 | } |
---|