blob: 535395f3e02c03492363c2cc8ee0f39dc839a0e9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
/*
Copyright (C) 2025 Mikael Hildenborg
SPDX-License-Identifier: BSD-2-Clause
*/
#include <errno.h>
#include <_ansi.h>
extern char *_HeapPtr;
extern char *_heapbase;
char *sbrk(int nbytes)
{
char *newheap = _HeapPtr + nbytes;
/*
The user stack pointer is the top heap.
The behaviour is undefined if we are in supervisor mode.
But memory allocations in supervisor mode feels like a bad idea anyway.
*/
char *heaptop;
__asm__ volatile (
"move.l %%a7, %0\n\t"
: "=g" (heaptop)
:
:);
if (newheap > heaptop)
{
errno = ENOMEM;
return ((char *)-1);
}
char *retptr = _HeapPtr;
_HeapPtr = newheap;
return retptr;
}
|