Verified Commit 0e6d0057 authored by Felix Kopp's avatar Felix Kopp
Browse files

arch: call init and preinit array

parent 4359f43b
......@@ -12,6 +12,7 @@ configure_file(
)
target_sources(ardix_arch PRIVATE
arch_init.c
atom_get_put.S
atom.c
atomic.c
......
/* See the end of this file for copyright, license, and warranty information. */
#include <ardix/malloc.h>
#include <toolchain.h>
/* flash.ld */
extern uint32_t _sheap;
extern uint32_t _eheap;
#include <arch/debug.h>
void __preinit_malloc(void)
{
malloc_init(&_sheap, (size_t)&_eheap - (size_t)&_sheap);
}
__preinit_call(__preinit_malloc);
/*
* This file is part of Ardix.
* Copyright (c) 2020, 2021 Felix Kopp <owo@fef.moe>.
*
* Ardix is non-violent software: you may only use, redistribute,
* and/or modify it under the terms of the CNPLv6+ as found in
* the LICENSE file in the source code root directory or at
* <https://git.pixie.town/thufie/CNPL>.
*
* Ardix comes with ABSOLUTELY NO WARRANTY, to the extent
* permitted by applicable law. See the CNPLv6+ for details.
*/
......@@ -2,6 +2,7 @@
#include <arch/hardware.h>
#include <arch/interrupt.h>
#include <arch/linker.h>
#include <arch-generic/hardware.h>
#include <ardix/malloc.h>
......@@ -11,19 +12,6 @@
#include <string.h>
#include <toolchain.h>
/* from flash.ld */
extern uint32_t _sfixed; /* fixed area start */
extern uint32_t _efixed; /* fixed area end */
extern uint32_t _etext; /* program (.text) end */
extern uint32_t _srelocate; /* relocate (.data) start */
extern uint32_t _erelocate; /* relocate end */
extern uint32_t _szero; /* zero area (.bss) start */
extern uint32_t _ezero; /* zero area end */
extern uint32_t _sstack; /* stack start */
extern uint32_t _estack; /* stack end */
extern uint32_t _sheap; /* heap start */
extern uint32_t _eheap; /* heap end */
/* implementation in init/main.c */
extern int main(void);
......@@ -34,8 +22,11 @@ __naked __noreturn void handle_reset(void)
memmove(&_srelocate, &_etext, (size_t)(&_erelocate) - (size_t)(&_srelocate));
memset(&_szero, 0, (size_t)(&_ezero) - (size_t)(&_szero));
/* memory protection isn't implemented yet, heap is shared among all processes */
malloc_init(&_sheap, (size_t)(&_eheap) - (size_t)(&_sheap));
for (uint32_t *fn = &__preinit_array_start; fn != &__preinit_array_end; fn++)
( (void (*)(void))fn )();
for (uint32_t *fn = &__init_array_start; fn != &__init_array_end; fn++)
( (void (*)(void))fn )();
/* start the Kernel */
main();
......
/* See the end of this file for copyright, license, and warranty information. */
#pragma once
#include <stdint.h>
/**
* @file linker.h
* @brief External symbols defined by the linker script (see flash.ld).
* The declarations in this file don't carry an actual value and cannot be
* accessed directly; they are merely there to get the *addresses* of.
*/
/** @brief Start of fixed area */
extern uint32_t _sfixed;
/** @brief End of fixed area */
extern uint32_t _efixed;
/** @brief End of program code (.text) */
extern uint32_t _etext;
/** @brief Start of relocation section (for global and static variables) */
extern uint32_t _srelocate;
/** @brief End of relocation section */
extern uint32_t _erelocate;
/** @brief Start of zero area (.bss) */
extern uint32_t _szero;
/** @brief End of zero area (.bss) */
extern uint32_t _ezero;
/**
* @brief Lowest address of the main (kernel) stack.
* This is technically the end of the stack, because it grows
* from the highest address downwards.
*/
extern uint32_t _sstack;
/** @brief Highest address if the main (kernel) stack. */
extern uint32_t _estack;
/** @brief Start of heap area */
extern uint32_t _sheap;
/** @brief End of heap area */
extern uint32_t _eheap;
/**
* @brief Start of preinit array.
* The preinit array is an array of function pointers that are invoked before
* the ones in the init array and `main()` are called. Only the most critical
* setup routines, like initializing the memory allocator, should go here.
*/
extern uintptr_t __preinit_array_start;
/** @brief End of preinit array. */
extern uintptr_t __preinit_array_end;
/**
* @brief Start of init array.
* The init array is an array of function pointers that are invoked before
* calling `main()` and are there to initialize the various components of the
* standard C library. They are executed after the preinit array, so memory
* allocation is already available.
*/
extern uint32_t __init_array_start;
/** @brief End of init array. */
extern uint32_t __init_array_end;
/*
* This file is part of Ardix.
* Copyright (c) 2020, 2021 Felix Kopp <owo@fef.moe>.
*
* Ardix is non-violent software: you may only use, redistribute,
* and/or modify it under the terms of the CNPLv6+ as found in
* the LICENSE file in the source code root directory or at
* <https://git.pixie.town/thufie/CNPL>.
*
* Ardix comes with ABSOLUTELY NO WARRANTY, to the extent
* permitted by applicable law. See the CNPLv6+ for details.
*/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment