OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [score/] [src/] [heapextend.c] - Blame information for rev 609

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *  Heap Handler
3
 *
4
 *  COPYRIGHT (c) 1989-1999.
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.OARcorp.com/rtems/license.html.
10
 *
11
 *  $Id: heapextend.c,v 1.2 2001-09-27 11:59:34 chris Exp $
12
 */
13
 
14
 
15
#include <rtems/system.h>
16
#include <rtems/score/sysstate.h>
17
#include <rtems/score/heap.h>
18
 
19
/*PAGE
20
 *
21
 *  _Heap_Extend
22
 *
23
 *  This routine grows the_heap memory area using the size bytes which
24
 *  begin at starting_address.
25
 *
26
 *  Input parameters:
27
 *    the_heap          - pointer to heap header.
28
 *    starting_address  - pointer to the memory area.
29
 *    size              - size in bytes of the memory block to allocate.
30
 *
31
 *  Output parameters:
32
 *    *amount_extended  - amount of memory added to the_heap
33
 */
34
 
35
Heap_Extend_status _Heap_Extend(
36
  Heap_Control        *the_heap,
37
  void                *starting_address,
38
  unsigned32           size,
39
  unsigned32          *amount_extended
40
)
41
{
42
  Heap_Block        *the_block;
43
  unsigned32        *p;
44
 
45
  /*
46
   *  The overhead was taken from the original heap memory.
47
   */
48
 
49
  Heap_Block  *old_final;
50
  Heap_Block  *new_final;
51
 
52
  /*
53
   *  There are five possibilities for the location of starting
54
   *  address:
55
   *
56
   *    1. non-contiguous lower address     (NOT SUPPORTED)
57
   *    2. contiguous lower address         (NOT SUPPORTED)
58
   *    3. in the heap                      (ERROR)
59
   *    4. contiguous higher address        (SUPPORTED)
60
   *    5. non-contiguous higher address    (NOT SUPPORTED)
61
   *
62
   *  As noted, this code only supports (4).
63
   */
64
 
65
  if ( starting_address >= (void *) the_heap->start &&        /* case 3 */
66
       starting_address <= (void *) the_heap->final
67
     )
68
    return HEAP_EXTEND_ERROR;
69
 
70
  if ( starting_address < (void *) the_heap->start ) {  /* cases 1 and 2 */
71
 
72
      return HEAP_EXTEND_NOT_IMPLEMENTED;               /* cases 1 and 2 */
73
 
74
  } else {                                              /* cases 4 and 5 */
75
 
76
    the_block = (Heap_Block *)
77
       _Addresses_Subtract_offset( starting_address, HEAP_OVERHEAD );
78
    if ( the_block != the_heap->final )
79
      return HEAP_EXTEND_NOT_IMPLEMENTED;                   /* case 5 */
80
  }
81
 
82
  /*
83
   *  Currently only case 4 should make it to this point.
84
   *  The basic trick is to make the extend area look like a used
85
   *  block and free it.
86
   */
87
 
88
  *amount_extended = size;
89
 
90
  old_final = the_heap->final;
91
  new_final = _Addresses_Add_offset( old_final, size );
92
  /* SAME AS: _Addresses_Add_offset( starting_address, size-HEAP_OVERHEAD ); */
93
 
94
  the_heap->final = new_final;
95
 
96
  old_final->front_flag =
97
  new_final->back_flag  = _Heap_Build_flag( size, HEAP_BLOCK_USED );
98
  new_final->front_flag = HEAP_DUMMY_FLAG;
99
 
100
  /*
101
   *  Must pass in address of "user" area
102
   *  So add in the offset field.
103
   */
104
 
105
  p = (unsigned32 *) &old_final->next;
106
  *p = sizeof(unsigned32);
107
  p++;
108
  _Heap_Free( the_heap, p );
109
 
110
  return HEAP_EXTEND_SUCCESSFUL;
111
}
112
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.