source: rtems/cpukit/score/src/wkspace.c @ da42259

4.104.115
Last change on this file since da42259 was a2fa532d, checked in by Joel Sherrill <joel.sherrill@…>, on 08/05/09 at 15:35:02

2009-08-05 Joel Sherrill <joel.sherrill@…>

  • score/src/wkspace.c: Improve debug output.
  • Property mode set to 100644
File size: 2.6 KB
Line 
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 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <rtems/system.h>
19#include <rtems/config.h>
20#include <rtems/score/wkspace.h>
21#include <rtems/score/interr.h>
22#include <rtems/config.h>
23
24#include <string.h>  /* for memset */
25
26/* #define DEBUG_WORKSPACE */
27#if defined(DEBUG_WORKSPACE)
28  #include <rtems/bspIo.h>
29#endif
30
31/*
32 *  _Workspace_Handler_initialization
33 */
34void _Workspace_Handler_initialization(void)
35{
36  uint32_t    memory_available;
37  void       *starting_address;
38  size_t      size;
39
40  starting_address = Configuration.work_space_start;
41  size             = Configuration.work_space_size;
42
43  if ( !starting_address || !_Addresses_Is_aligned( starting_address ) )
44    _Internal_error_Occurred(
45      INTERNAL_ERROR_CORE,
46      true,
47      INTERNAL_ERROR_INVALID_WORKSPACE_ADDRESS
48    );
49
50  if ( Configuration.do_zero_of_workspace )
51   memset( starting_address, 0, size );
52
53  memory_available = _Heap_Initialize(
54    &_Workspace_Area,
55    starting_address,
56    size,
57    CPU_HEAP_ALIGNMENT
58  );
59
60  if ( memory_available == 0 )
61    _Internal_error_Occurred(
62      INTERNAL_ERROR_CORE,
63      true,
64      INTERNAL_ERROR_TOO_LITTLE_WORKSPACE
65    );
66}
67
68/*
69 *  _Workspace_Allocate
70 */
71void *_Workspace_Allocate(
72  size_t   size
73)
74{
75  void *memory;
76
77  memory = _Heap_Allocate( &_Workspace_Area, size );
78  #if defined(DEBUG_WORKSPACE)
79    printk(
80      "Workspace_Allocate(%d) from %p/%p -> %p\n",
81      size,
82      __builtin_return_address( 0 ),
83      __builtin_return_address( 1 ),
84      memory
85    );
86  #endif
87  return memory;
88}
89
90/*
91 *  _Workspace_Free
92 */
93bool _Workspace_Free(
94  void *block
95)
96{
97  #if defined(DEBUG_WORKSPACE)
98    printk(
99      "Workspace_Free(%p) from %p/%p\n",
100      block,
101      __builtin_return_address( 0 ),
102      __builtin_return_address( 1 )
103    );
104  #endif
105   return _Heap_Free( &_Workspace_Area, block );
106}
107
108/*
109 *  _Workspace_Allocate_or_fatal_error
110 */
111void *_Workspace_Allocate_or_fatal_error(
112  size_t      size
113)
114{
115  void *memory;
116
117  memory = _Heap_Allocate( &_Workspace_Area, size );
118  #if defined(DEBUG_WORKSPACE)
119    printk(
120      "Workspace_Allocate_or_fatal_error(%d) from %p/%p -> %p\n",
121      size,
122      __builtin_return_address( 0 ),
123      __builtin_return_address( 1 ),
124      memory
125    );
126  #endif
127
128  if ( memory == NULL )
129    _Internal_error_Occurred(
130      INTERNAL_ERROR_CORE,
131      true,
132      INTERNAL_ERROR_WORKSPACE_ALLOCATION
133    );
134
135  return memory;
136}
Note: See TracBrowser for help on using the repository browser.