14e98e3e1Schristos /* Hardware memory allocator. 2*88241920Schristos Copyright (C) 1998-2024 Free Software Foundation, Inc. 34e98e3e1Schristos Contributed by Cygnus Support. 44e98e3e1Schristos 54e98e3e1Schristos This file is part of GDB, the GNU debugger. 64e98e3e1Schristos 74e98e3e1Schristos This program is free software; you can redistribute it and/or modify 84e98e3e1Schristos it under the terms of the GNU General Public License as published by 94e98e3e1Schristos the Free Software Foundation; either version 3 of the License, or 104e98e3e1Schristos (at your option) any later version. 114e98e3e1Schristos 124e98e3e1Schristos This program is distributed in the hope that it will be useful, 134e98e3e1Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 144e98e3e1Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 154e98e3e1Schristos GNU General Public License for more details. 164e98e3e1Schristos 174e98e3e1Schristos You should have received a copy of the GNU General Public License 184e98e3e1Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 194e98e3e1Schristos 204b169a6bSchristos /* This must come before any other includes. */ 214b169a6bSchristos #include "defs.h" 224b169a6bSchristos 234b169a6bSchristos #include <stdlib.h> 244e98e3e1Schristos 254e98e3e1Schristos #include "hw-main.h" 264e98e3e1Schristos #include "hw-base.h" 274e98e3e1Schristos 284e98e3e1Schristos struct hw_alloc_data 294e98e3e1Schristos { 304e98e3e1Schristos void *alloc; 314e98e3e1Schristos struct hw_alloc_data *next; 324e98e3e1Schristos }; 334e98e3e1Schristos 344e98e3e1Schristos void 354e98e3e1Schristos create_hw_alloc_data (struct hw *me) 364e98e3e1Schristos { 374e98e3e1Schristos /* NULL */ 384e98e3e1Schristos } 394e98e3e1Schristos 404e98e3e1Schristos void 414e98e3e1Schristos delete_hw_alloc_data (struct hw *me) 424e98e3e1Schristos { 434e98e3e1Schristos while (me->alloc_of_hw != NULL) 444e98e3e1Schristos { 454e98e3e1Schristos hw_free (me, me->alloc_of_hw->alloc); 464e98e3e1Schristos } 474e98e3e1Schristos } 484e98e3e1Schristos 494e98e3e1Schristos 504e98e3e1Schristos 514e98e3e1Schristos void * 524e98e3e1Schristos hw_zalloc (struct hw *me, unsigned long size) 534e98e3e1Schristos { 544e98e3e1Schristos struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data); 554e98e3e1Schristos memory->alloc = zalloc (size); 564e98e3e1Schristos memory->next = me->alloc_of_hw; 574e98e3e1Schristos me->alloc_of_hw = memory; 584e98e3e1Schristos return memory->alloc; 594e98e3e1Schristos } 604e98e3e1Schristos 614e98e3e1Schristos void * 624e98e3e1Schristos hw_malloc (struct hw *me, unsigned long size) 634e98e3e1Schristos { 644e98e3e1Schristos struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data); 654e98e3e1Schristos memory->alloc = zalloc (size); 664e98e3e1Schristos memory->next = me->alloc_of_hw; 674e98e3e1Schristos me->alloc_of_hw = memory; 684e98e3e1Schristos return memory->alloc; 694e98e3e1Schristos } 704e98e3e1Schristos 714e98e3e1Schristos void 724e98e3e1Schristos hw_free (struct hw *me, 734e98e3e1Schristos void *alloc) 744e98e3e1Schristos { 754e98e3e1Schristos struct hw_alloc_data **memory; 764e98e3e1Schristos for (memory = &me->alloc_of_hw; 774e98e3e1Schristos *memory != NULL; 784e98e3e1Schristos memory = &(*memory)->next) 794e98e3e1Schristos { 804e98e3e1Schristos if ((*memory)->alloc == alloc) 814e98e3e1Schristos { 824e98e3e1Schristos struct hw_alloc_data *die = (*memory); 834e98e3e1Schristos (*memory) = die->next; 844e98e3e1Schristos free (die->alloc); 854e98e3e1Schristos free (die); 864e98e3e1Schristos return; 874e98e3e1Schristos } 884e98e3e1Schristos } 894e98e3e1Schristos hw_abort (me, "free of memory not belonging to a device"); 904e98e3e1Schristos } 91