-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bodge:
sbrk
impl stolen from newlib to get minimal libc working w/ …
…microblaze Signed-off-by: Alp Sayin <[email protected]>
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
#include <zephyr/devicetree.h> | ||
#include <zephyr/linker/linker-defs.h> | ||
|
||
#define _DDR_NODE DT_CHOSEN(zephyr_sram) | ||
#define _LAYOUT_DDR_LOC DT_REG_ADDR(_DDR_NODE) | ||
#define _LAYOUT_DDR_SIZE DT_REG_SIZE(_DDR_NODE) | ||
|
||
/* Current offset from HEAP_BASE of unused memory */ | ||
__attribute__((section(".bss"), used)) static size_t heap_sz; | ||
|
||
#define HEAP_BASE ((uintptr_t) (&_end)) | ||
#define MAX_HEAP_SIZE (_LAYOUT_DDR_LOC + _LAYOUT_DDR_SIZE - HEAP_BASE) | ||
|
||
/* Implementation stolen from newlib/libc-hooks.c */ | ||
void *_sbrk(intptr_t count) | ||
{ | ||
void *ret, *ptr; | ||
|
||
ptr = ((char *)HEAP_BASE) + heap_sz; | ||
|
||
if ((heap_sz + count) < MAX_HEAP_SIZE) { | ||
heap_sz += count; | ||
ret = ptr; | ||
|
||
} else { | ||
ret = (void *)-1; | ||
} | ||
|
||
return ret; | ||
} | ||
__weak FUNC_ALIAS(_sbrk, sbrk, void *); |