2 * Simple malloc implementation
4 * Copyright (c) 2014 Google, Inc
6 * SPDX-License-Identifier: GPL-2.0+
14 DECLARE_GLOBAL_DATA_PTR;
16 void *malloc_simple(size_t bytes)
21 new_ptr = gd->malloc_ptr + bytes;
22 debug("%s: size=%zx, ptr=%lx, limit=%lx: ", __func__, bytes, new_ptr,
24 if (new_ptr > gd->malloc_limit) {
25 debug("space exhausted\n");
28 ptr = map_sysmem(gd->malloc_base + gd->malloc_ptr, bytes);
29 gd->malloc_ptr = ALIGN(new_ptr, sizeof(new_ptr));
30 debug("%lx\n", (ulong)ptr);
35 void *memalign_simple(size_t align, size_t bytes)
40 addr = ALIGN(gd->malloc_base + gd->malloc_ptr, align);
41 new_ptr = addr + bytes - gd->malloc_base;
42 if (new_ptr > gd->malloc_limit)
44 ptr = map_sysmem(addr, bytes);
45 gd->malloc_ptr = ALIGN(new_ptr, sizeof(new_ptr));
50 #if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE)
51 void *calloc(size_t nmemb, size_t elem_size)
53 size_t size = nmemb * elem_size;
57 memset(ptr, '\0', size);