sim: bfin: use store buffer for VIT_MAX insns
[deliverable/binutils-gdb.git] / sim / common / hw-alloc.c
CommitLineData
c906108c 1/* Hardware memory allocator.
7b6bb8da
JB
2 Copyright (C) 1998, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
c906108c
SS
4 Contributed by Cygnus Support.
5
6This file is part of GDB, the GNU debugger.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
4744ac1b
JB
10the Free Software Foundation; either version 3 of the License, or
11(at your option) any later version.
c906108c
SS
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
4744ac1b
JB
18You should have received a copy of the GNU General Public License
19along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
20
21
22#include "hw-main.h"
23#include "hw-base.h"
24
25
26#ifdef HAVE_STDLIB_H
27#include <stdlib.h>
28#endif
29
12c4cbd5
MF
30struct hw_alloc_data
31{
c906108c 32 void *alloc;
c906108c
SS
33 struct hw_alloc_data *next;
34};
35
36void
37create_hw_alloc_data (struct hw *me)
38{
39 /* NULL */
40}
41
42void
43delete_hw_alloc_data (struct hw *me)
44{
c906108c
SS
45 while (me->alloc_of_hw != NULL)
46 {
47 hw_free (me, me->alloc_of_hw->alloc);
48 }
49}
50
51
52
53void *
54hw_zalloc (struct hw *me, unsigned long size)
55{
56 struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data);
57 memory->alloc = zalloc (size);
c906108c
SS
58 memory->next = me->alloc_of_hw;
59 me->alloc_of_hw = memory;
60 return memory->alloc;
61}
62
63void *
64hw_malloc (struct hw *me, unsigned long size)
65{
66 struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data);
67 memory->alloc = zalloc (size);
c906108c
SS
68 memory->next = me->alloc_of_hw;
69 me->alloc_of_hw = memory;
70 return memory->alloc;
71}
72
73void
74hw_free (struct hw *me,
75 void *alloc)
76{
77 struct hw_alloc_data **memory;
78 for (memory = &me->alloc_of_hw;
79 *memory != NULL;
80 memory = &(*memory)->next)
81 {
82 if ((*memory)->alloc == alloc)
83 {
84 struct hw_alloc_data *die = (*memory);
85 (*memory) = die->next;
d79fe0d6
MF
86 free (die->alloc);
87 free (die);
c906108c
SS
88 return;
89 }
90 }
91 hw_abort (me, "free of memory not belonging to a device");
92}
This page took 0.596195 seconds and 4 git commands to generate.