1 /*-------------------------------------------------------------------------
2 malloc.h - dynamic memory allocation header
4 Copyright (C) 2004, Vangelis Rokas <vrokas AT otenet.gr>
6 Modifications for PIC14 by
7 Copyright (C) 2019 Gonzalo Pérez de Olaguer Córdoba <salo@gpoc.es>
9 This library is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by the
11 Free Software Foundation; either version 2, or (at your option) any
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this library; see the file COPYING. If not, write to the
21 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
24 As a special exception, if you link this library with other files,
25 some of which are compiled with SDCC, to produce an executable,
26 this library does not by itself cause the resulting executable to
27 be covered by the GNU General Public License. This exception does
28 not however invalidate any other reasons why the executable file
29 might be covered by the GNU General Public License.
30 -------------------------------------------------------------------------*/
33 * WARNING: This file is only for internal use of the PIC14 C library.
36 #ifndef __PIC14_MALLOC_H__
37 #define __PIC14_MALLOC_H__
41 #define MAX_BLOCK_SIZE 80 /* limited to one bank */
42 #define MAX_HEAP_SIZE 80 /* limited to one bank */
44 #define ALLOC_FLAG 0x80
46 /* memory block header, max size 127 bytes, 126 usable */
50 unsigned count
: 7; /* 0: last block, else block size including this header */
51 unsigned alloc
: 1; /* 0: free, 1: allocated */
55 #define PTR2REC(p) ((_malloc_rec __data *)((unsigned int)(p) - 1))
56 #define REC2PTR(r) ((void __data *)((unsigned int)(r) + 1))
57 #define NEXTREC(r) ((_malloc_rec __data *)((unsigned int)(r) + (r)->bits.count))
59 /* this is an external pointer to HEAP. It should be defined in
60 * the user's program, or it can be a symbol created by linker */
61 extern _malloc_rec __data
*_malloc_heap
;
63 /* initialize heap, should be called before any call to malloc/realloc/calloc */
64 void _initHeap (void __data
*ptr
, size_t size
);
66 /* (re)allocate the specified block with the specified size */
67 void __data
*_allocateHeap (void __data
*ptr
, size_t size
);
69 #endif /* __PIC14_MALLOC_H__ */