2020-02-11 21:45:48 -06:00
|
|
|
/*
|
|
|
|
* Copyright 2016 - 2020 gtalent2@gmail.com
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
2019-11-03 23:23:43 -06:00
|
|
|
|
2020-05-29 19:36:00 -05:00
|
|
|
#include <ox/std/bit.hpp>
|
|
|
|
#include <ox/std/heapmgr.hpp>
|
|
|
|
|
2020-01-12 20:45:20 -06:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wpedantic"
|
|
|
|
|
2020-05-29 19:36:00 -05:00
|
|
|
// this warning is too dumb to realize that it can actually confirm the hard
|
|
|
|
// coded address aligns with the requirement of HeapSegment, so it must be
|
|
|
|
// suppressed
|
|
|
|
#pragma GCC diagnostic ignored "-Wcast-align"
|
|
|
|
|
|
|
|
#define MEM_WRAM_BEGIN reinterpret_cast<uint8_t*>(0x02000000)
|
|
|
|
#define MEM_WRAM_END reinterpret_cast<uint8_t*>(0x0203FFFF)
|
|
|
|
|
|
|
|
#define HEAP_BEGIN reinterpret_cast<ox::heapmgr::HeapSegment*>(MEM_WRAM_BEGIN)
|
|
|
|
// set size to half of WRAM
|
|
|
|
#define HEAP_SIZE ((MEM_WRAM_END - MEM_WRAM_BEGIN) / 2)
|
|
|
|
#define HEAP_END reinterpret_cast<ox::heapmgr::HeapSegment*>(MEM_WRAM_BEGIN + HEAP_SIZE)
|
|
|
|
|
2019-11-03 23:23:43 -06:00
|
|
|
extern void (*__preinit_array_start[]) (void);
|
|
|
|
extern void (*__preinit_array_end[]) (void);
|
|
|
|
extern void (*__init_array_start[]) (void);
|
|
|
|
extern void (*__init_array_end[]) (void);
|
|
|
|
|
2020-05-29 19:36:00 -05:00
|
|
|
namespace ox::heapmgr {
|
2020-02-11 21:45:48 -06:00
|
|
|
|
2020-05-29 19:36:00 -05:00
|
|
|
void initHeap(char *heapBegin, char *heapEnd);
|
2020-02-11 21:45:48 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-12 20:45:20 -06:00
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
void __libc_init_array() {
|
2019-11-03 23:23:43 -06:00
|
|
|
auto preInits = __preinit_array_end - __preinit_array_start;
|
|
|
|
for (decltype(preInits) i = 0; i < preInits; i++) {
|
|
|
|
__preinit_array_start[i]();
|
|
|
|
}
|
|
|
|
auto inits = __init_array_end - __init_array_start;
|
|
|
|
for (decltype(inits) i = 0; i < inits; i++) {
|
|
|
|
__preinit_array_start[i]();
|
|
|
|
}
|
|
|
|
}
|
2020-01-12 20:45:20 -06:00
|
|
|
|
|
|
|
int main(int argc, const char **argv);
|
|
|
|
|
2020-01-12 21:18:21 -06:00
|
|
|
int c_start() {
|
2020-01-12 20:45:20 -06:00
|
|
|
const char *args[2] = {"", "rom.oxfs"};
|
2020-05-29 19:36:00 -05:00
|
|
|
ox::heapmgr::initHeap(ox::bit_cast<char*>(HEAP_BEGIN), ox::bit_cast<char*>(HEAP_END));
|
2020-01-12 21:18:21 -06:00
|
|
|
return main(2, args);
|
2020-01-12 20:45:20 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma GCC diagnostic pop
|