2013-10-12 19:42:20 -04:00
|
|
|
#include <stdint.h>
|
|
|
|
#include "std.h"
|
2013-10-21 18:46:04 -04:00
|
|
|
#include "mpyconfig.h"
|
|
|
|
#include "gc.h"
|
2013-10-12 19:42:20 -04:00
|
|
|
|
2013-10-21 18:46:04 -04:00
|
|
|
#if 0
|
2013-10-12 19:42:20 -04:00
|
|
|
static uint32_t mem = 0;
|
|
|
|
|
|
|
|
void *malloc(size_t n) {
|
|
|
|
if (mem == 0) {
|
2013-10-17 17:50:21 -04:00
|
|
|
extern uint32_t _heap_start;
|
2013-10-18 18:44:05 -04:00
|
|
|
mem = (uint32_t)&_heap_start; // need to use big ram block so we can execute code from it (is it true that we can't execute from CCM?)
|
2013-10-12 19:42:20 -04:00
|
|
|
}
|
|
|
|
void *ptr = (void*)mem;
|
|
|
|
mem = (mem + n + 3) & (~3);
|
|
|
|
if (mem > 0x20000000 + 0x18000) {
|
|
|
|
void __fatal_error(const char*);
|
|
|
|
__fatal_error("out of memory");
|
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free(void *ptr) {
|
|
|
|
}
|
|
|
|
|
2013-10-21 18:46:04 -04:00
|
|
|
void *realloc(void *ptr, size_t n) {
|
|
|
|
return malloc(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-10-12 19:42:20 -04:00
|
|
|
void *calloc(size_t sz, size_t n) {
|
|
|
|
char *ptr = malloc(sz * n);
|
|
|
|
for (int i = 0; i < sz * n; i++) {
|
|
|
|
ptr[i] = 0;
|
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2013-10-21 18:46:04 -04:00
|
|
|
void *malloc(size_t n) {
|
|
|
|
return gc_alloc(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void free(void *ptr) {
|
2013-10-22 16:13:36 -04:00
|
|
|
gc_free(ptr);
|
2013-10-21 18:46:04 -04:00
|
|
|
}
|
|
|
|
|
2013-10-12 19:42:20 -04:00
|
|
|
void *realloc(void *ptr, size_t n) {
|
2013-10-21 18:46:04 -04:00
|
|
|
return gc_realloc(ptr, n);
|
2013-10-12 19:42:20 -04:00
|
|
|
}
|
|
|
|
|
2013-10-23 15:39:20 -04:00
|
|
|
void __assert_func(void) {
|
2013-10-12 19:42:20 -04:00
|
|
|
printf("\nASSERT FAIL!");
|
|
|
|
for (;;) {
|
|
|
|
}
|
|
|
|
}
|