heap position is now dynamically determined

This commit is contained in:
Lauchmelder 2022-01-21 12:23:42 +01:00
parent dbe4a2a84e
commit aedba6e52b
5 changed files with 7 additions and 12 deletions

View file

@ -12,6 +12,7 @@ SECTIONS
*(COMMON)
__bss_end = .;
}
__heap_base = .;
_end = .;
/DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) }

View file

@ -24,8 +24,5 @@ _start:
cbnz w2, 3b
4: # Jump to main() in C
ldr x0, =_start
ldr x1, =0x50000
str x0, [x1]
bl main
b 1b

View file

@ -47,7 +47,7 @@ char* ultoa(unsigned long number, char* string, int base)
if(digit < 10)
temp[i++] = '0' + digit;
else
temp[i++] = 'A' + digit;
temp[i++] = 'A' + digit - 10;
}
}

View file

@ -8,8 +8,7 @@ char* get_user_input(char* buffer);
void main()
{
const char* hex_chars = "0123456789ABCDEF";
long int start = *(volatile long int*)0x50000;
extern long _start;
char buffer[1024];
uart_init();
@ -18,7 +17,7 @@ void main()
print_clippy();
uart_puts("Boot successful! \n");
uart_puts("Started execution at 0x");
uart_puts(ultoa(start, buffer, 16));
uart_puts(ultoa((long)&_start, buffer, 16));
for(;;)
{

View file

@ -15,14 +15,12 @@ struct Block
void* data;
};
#define HEAP_BASE ((void*)0x40000000)
#define BLOCK_SIZE 4096
#define MAGIC_NUMBER 0xDEADBEEF
static struct FreeBlock* head = (struct FreeBlock*)HEAP_BASE;
extern const void* __heap_base;
static struct FreeBlock* head = NULL;
void heap_init()
{
head = (struct FreeBlock*)__heap_base;
head->next = head + sizeof(struct FreeBlock);
head->size = 0;