mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #10943 from gschorcht/cpu/mps430_common_heap
cpu/msp430_common: set top of heap for sbrk
This commit is contained in:
commit
c391ed4109
@ -126,6 +126,8 @@ void msp430_cpu_init(void)
|
||||
|
||||
#define STACK_EXTRA 32
|
||||
|
||||
extern char __stack; /* provided by linker script */
|
||||
char *__heap_end = NULL; /* top of heap */
|
||||
|
||||
/*
|
||||
* Allocate memory from the heap. Check that we don't collide with the
|
||||
@ -135,12 +137,15 @@ void msp430_cpu_init(void)
|
||||
*/
|
||||
void *sbrk(int incr)
|
||||
{
|
||||
char *stack_pointer;
|
||||
char *__heap_top = __heap_end;
|
||||
|
||||
asmv("mov r1, %0" : "=r"(stack_pointer));
|
||||
stack_pointer -= STACK_EXTRA;
|
||||
if (!__heap_top) {
|
||||
/* set __heap_top to stack pointer if we are not in thread mode */
|
||||
asmv("mov r1, %0" : "=r"(__heap_top));
|
||||
__heap_top -= STACK_EXTRA;
|
||||
}
|
||||
|
||||
if (incr > (stack_pointer - cur_break)) {
|
||||
if (incr > (__heap_top - cur_break)) {
|
||||
return (void *) - 1; /* ENOMEM */
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,13 @@
|
||||
|
||||
extern void board_init(void);
|
||||
|
||||
/**
|
||||
* Leave some extra space in the stack to allows us to finish the kernel
|
||||
* initialization procedure. __heap_end is set the current stack, minus
|
||||
* STACK_EXTRA since there is still code to execute.
|
||||
*/
|
||||
#define STACK_EXTRA 32
|
||||
|
||||
__attribute__((constructor)) static void startup(void)
|
||||
{
|
||||
/* use putchar so the linker links it in: */
|
||||
@ -35,5 +42,10 @@ __attribute__((constructor)) static void startup(void)
|
||||
|
||||
LOG_INFO("RIOT MSP430 hardware initialization complete.\n");
|
||||
|
||||
/* save current stack pointer as top of heap before enter the thread mode */
|
||||
extern char *__heap_end;
|
||||
__asm__ __volatile__("mov r1, %0" : "=r"(__heap_end));
|
||||
__heap_end -= STACK_EXTRA;
|
||||
|
||||
kernel_init();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user