Skip to content

Commit

Permalink
Merge pull request #104 from stellar-aria/feature/proper-init
Browse files Browse the repository at this point in the history
Linkerscript rework and proper initialization
  • Loading branch information
jamiefaye committed Jun 27, 2023
2 parents e7689b8 + 47c8abd commit 884da39
Show file tree
Hide file tree
Showing 17 changed files with 175 additions and 225 deletions.
244 changes: 140 additions & 104 deletions linker_script_rz_a1l.ld
Original file line number Diff line number Diff line change
Expand Up @@ -87,158 +87,194 @@ SVC_STACK_SIZE = 0x2000; /* SVC mode stack */
ABT_STACK_SIZE = 0x2000; /* ABT mode stack */
TTB_SIZE = 0x8000; /* Level-1 Translation Table for MMU */


/* INTERNAL_RAM_START may *NOT* be lower than 0x20000000!!!!! */
INTERNAL_RAM_START = 0x20020000;
INTERNAL_RAM_END = 0x20300000;

SECTIONS
{
/* L1 translation table must be aligned to 16KB Boundary! */
/* Please refer to Cortex-A Series Version: 4.0 Programmer’s Guide, */
/* section 9.4 First level address translation */
.ttb_mmu1 INTERNAL_RAM_START :
.reset :
{
ttb_mmu1_base = .;
. += TTB_SIZE;
. = ALIGN(0x4);
ttb_mmu1_end = .;
} >RAM012L

.irq_stack :
{
irq_stack_start = .;
. += IRQ_STACK_SIZE;
. = ALIGN(0x4);
irq_stack_end = .;
} >RAM012L
execute = .;
*start.o (.text)
*start.o (.rodata)
*start.o (.data)

*access.o (.text)
*access.o (.rodata)
*access.o (.data)

.fiq_stack :
{
fiq_stack_start = .;
. += FIQ_STACK_SIZE;
. = ALIGN(0x4);
fiq_stack_end = .;
} >RAM012L
*initsct.o (.text)
*initsct.o (.rodata)
*initsct.o (.data)

.svc_stack :
{
PROVIDE(svc_stack_start = .);
. += SVC_STACK_SIZE;
. = ALIGN(0x4);
svc_stack_end = .;
} >RAM012L
*reset_handler.o (.text)
*reset_handler.o (.rodata)
*reset_handler.o (.data)

.abt_stack :
{
abt_stack_start = .;
. += ABT_STACK_SIZE;
. = ALIGN(0x4);
abt_stack_end = .;
} >RAM012L

.bss :
{
_bss = .;
PROVIDE(__bss_start__ = .);
*(.bss)
*(.bss.**)
*(COMMON)
. = ALIGN(0x4);
PROVIDE(__bss_end__ = .);
_ebss = .;
_end = .;
} >RAM012L

.reset : ALIGN(0x20) /* 0x10 isn't enough. Not sure why any of this is necessary though. */
{
EXEC_BASE = .;
execute = .;
*start.o (.text)
*ttb_init.o (.text)
*ttb_init.o (.rodata)
*ttb_init.o (.data)

. = ALIGN(0x4);
*(.text)
*(.text.startup)
address_end_reset = .;
} > RAM012L

.text :
.rodata :
{
text_start = .;
. = ALIGN(0x4);
_stext = .;

*(.text)
address_end_text = .;
} > RAM012L


*(.text*)
*(.rodata)
*(.rodata*)
*(.glue_7) /* stubs generated by gcc to glue ARM7 code calling Thumb code */
*(.glue_7t) /* stubs generated by gcc to glue Thumb code calling ARM7 code */

KEEP(*(.init))
KEEP(*(.fini))

. = ALIGN(0x4);
_etext = .;
} > RAM012L

.preinit_array :
{
PROVIDE_HIDDEN(__preinit_array_start = .);
KEEP(*(.preinit_array*))
PROVIDE_HIDDEN(__preinit_array_end = .);
} > RAM012L

.init_array :
{
PROVIDE_HIDDEN(__init_array_start = .);
KEEP(*(SORT(.init_array*)))
KEEP(*(.init_array*))
PROVIDE_HIDDEN(__init_array_end = .);
} > RAM012L

.fini_array :
{
PROVIDE_HIDDEN(__fini_array_start = .);
KEEP(*(.fini_array*))
KEEP(*(SORT(.fini_array*)))
PROVIDE_HIDDEN(__fini_array_end = .);
} > RAM012L

/* See http://embdev.net/topic/282936 */
.ARM.exidx : {
__exidx_start = .;
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
__exidx_end = .;
PROVIDE_HIDDEN(__exidx_start = .);
*(.ARM.exidx*)
*(.gnu.linkonce.armexidx.*)
PROVIDE_HIDDEN(__exidx_end = .);
} > RAM012L
_etext = .;

.rodata :

.data :
{
*(.rodata)
*(.rodata.*)
. = ALIGN(0x8);
address_start_data_ROM = .;
_data = .;
*(.data)
*(.data.*)
_sdata = .;
*(.data)
*(.data*)
*(.igot.plt)
*(.got.plt)
*(.got)
. = ALIGN(0x8);
address_end_data_ROM = .;
_edata = .;
} > RAM012L


/* Uncommenting this section back in allows the section at the top of the main C++ file to be uncommented...
But I'm not sure if this is really the right place for this. */

/*
.tors :
{
__CTOR_LIST__ = .;
. = ALIGN(2);
__ctors = .;
*(.ctors)
__ctors_end = .;
__CTOR_END__ = .;

__DTOR_LIST__ = .;
___dtors = .;
*(.dtors)
___dtors_end = .;
__DTOR_END__ = .;
. = ALIGN(2);
_mdata = .;
*/

*(.got.plt)
*(.got)
. = ALIGN(0x8);
address_end_data_ROM = .;
} > RAM012L

.irq_stack :
{
irq_stack_start = .;
. += IRQ_STACK_SIZE;
. = ALIGN(0x4);
irq_stack_end = .;
fiq_stack_start = .;
. += FIQ_STACK_SIZE;
. = ALIGN(0x4);
fiq_stack_end = .;
svc_stack_start = .;
. += SVC_STACK_SIZE;
. = ALIGN(0x4);
svc_stack_end = .;
abt_stack_start = .;
. += ABT_STACK_SIZE;
. = ALIGN(0x4);
abt_stack_end = .;
} >RAM012L

/* L1 translation table must be aligned to 16KB Boundary! */
/* Please refer to Cortex-A Series Version: 4.0 Programmer’s Guide, */
/* section 9.4 First level address translation */
.ttb_mmu1 (NOLOAD) : ALIGN(0x4000)
{
ttb_mmu1_base = .;
. += TTB_SIZE;
. = ALIGN(0x4);
ttb_mmu1_end = .;
} >RAM012L


/* The heap-start needs its own section because for some reason, extra stuff is injected after the previous section. */
.heap_start : ALIGN(4)

.bss (NOLOAD) :
{
__heap_start = .;
PROVIDE(end = .); /* THIS LINE instructs that the heap start here! */
} > RAM012L
_bss = .;
PROVIDE(__bss_start__ = .);
*(.bss)
*(.bss.**)
*(COMMON)
. = ALIGN(0x4);
PROVIDE(__bss_end__ = .);
_ebss = .;
} >RAM012L

. = ALIGN(4);
/* End of user data. Heap starts from here */
end = .;
_end = .;

/* This causes some kind of "copy"ing to happen in initsct.S. I'm not sure what it does, but if I remove the middle line, then stuff goes wrong sometimes when I dynamically allocate
memory - depending on the exact length of the program I think. */
/* For more information see: rdimon's libgloss/arm/syscall.c @ _sbrk */
/* See also: https://ww1.microchip.com/downloads/en/DeviceDoc/Frequently-Asked-Questions-4.9.3.26.txt point 12 */

/*
.data :
.heap (NOLOAD) :
{
address_start_data_RAM = .;
. += (address_end_data_ROM - address_start_data_ROM);
address_end_data_RAM = .;
} > RAM012L
*/

. = ALIGN(4);
PROVIDE(__heap_start__ = .);
PROVIDE(__heap_start = .);
PROVIDE(_nl_heap_start = .);
KEEP(*(.heap))
. = ALIGN(0x4);
PROVIDE(__heap_end__ = .);
PROVIDE(__heap_end = .);
PROVIDE(_nl_heap_end = .);
} > RAM012L

/* Program Stack _must_ be at end of memory due to GeneralMemoryAllocator (see checkStack) */
.program_stack (INTERNAL_RAM_END - PROGRAM_STACK_SIZE) :
{
program_stack_start = .;
. += PROGRAM_STACK_SIZE;
. = ALIGN(0x4);
program_stack_end = .;
} >RAM012L

}
2 changes: 1 addition & 1 deletion src/ActionLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#include "playbackhandler.h"
#include "oled.h"

ActionLogger actionLogger;
ActionLogger actionLogger{};

ActionLogger::ActionLogger() {
firstAction[BEFORE] = NULL;
Expand Down
17 changes: 4 additions & 13 deletions src/AudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,24 +158,18 @@ int monitoringAction;

uint32_t saddr;

VoiceSample voiceSamples[NUM_VOICE_SAMPLES_STATIC];
VoiceSample voiceSamples[NUM_VOICE_SAMPLES_STATIC] = {};
VoiceSample* firstUnassignedVoiceSample = voiceSamples;

TimeStretcher timeStretchers[NUM_TIME_STRETCHERS_STATIC];
TimeStretcher timeStretchers[NUM_TIME_STRETCHERS_STATIC] = {};
TimeStretcher* firstUnassignedTimeStretcher = timeStretchers;

Voice staticVoices
[NUM_VOICES_STATIC]; // Hmm, I forgot this was still being used. It's not a great way of doing things... wait does this still actually get used? No?
// Hmm, I forgot this was still being used. It's not a great way of doing things... wait does this still actually get used? No?
Voice staticVoices[NUM_VOICES_STATIC] = {};
Voice* firstUnassignedVoice;

// You must set up dynamic memory allocation before calling this, because of its call to setupWithPatching()
void init() {

new (&reverb) revmodel;
new (&reverbCompressor) Compressor;
new (&metronome) Metronome;
new (&activeVoices) VoiceVector;

paramManagerForSamplePreview = new ((void*)paramManagerForSamplePreviewMemory) ParamManagerForTimeline();
paramManagerForSamplePreview->setupWithPatching(); // Shouldn't be an error at init time...
Sound::initParams(paramManagerForSamplePreview);
Expand All @@ -195,17 +189,14 @@ void init() {
sampleForPreview->sideChainSendLevel = 2147483647;

for (int i = 0; i < NUM_VOICE_SAMPLES_STATIC; i++) {
new (&voiceSamples[i]) VoiceSample();
voiceSamples[i].nextUnassigned = (i == NUM_VOICE_SAMPLES_STATIC - 1) ? NULL : &voiceSamples[i + 1];
}

for (int i = 0; i < NUM_TIME_STRETCHERS_STATIC; i++) {
new (&timeStretchers[i]) TimeStretcher();
timeStretchers[i].nextUnassigned = (i == NUM_TIME_STRETCHERS_STATIC - 1) ? NULL : &timeStretchers[i + 1];
}

for (int i = 0; i < NUM_VOICES_STATIC; i++) {
new (&staticVoices[i]) Voice();
staticVoices[i].nextUnassigned = (i == NUM_VOICES_STATIC - 1) ? NULL : &staticVoices[i + 1];
}

Expand Down
2 changes: 1 addition & 1 deletion src/AudioFileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ extern uint8_t currentlyAccessingCard;

char const* const audioRecordingFolderNames[] = {"SAMPLES/CLIPS", "SAMPLES/RECORD", "SAMPLES/RESAMPLE"};

AudioFileManager audioFileManager;
AudioFileManager audioFileManager{};

AudioFileManager::AudioFileManager() {
cardDisabled = false;
Expand Down
3 changes: 0 additions & 3 deletions src/AutomatedTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ uint32_t timeLastCall;
TestState* currentState = &instrumentClipViewTestState;

void init() {
new (&changePresetTestAction) ChangePresetTestAction;
new (&playButtonTestAction) PlayButtonTestAction;
new (&instrumentClipViewTestState) InstrumentClipViewTestState;
}

void turnSelectEncoder(int offset) {
Expand Down
1 change: 0 additions & 1 deletion src/AutomatedTester.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#define AUTOMATEDTESTER_H_

namespace AutomatedTester {
void init();
void turnSelectEncoder(int offset);
void doMomentaryButtonPress(int x, int y);
void possiblyDoSomething();
Expand Down
2 changes: 1 addition & 1 deletion src/Browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extern "C" {
String Browser::currentDir;
bool Browser::qwertyVisible;

CStringArray Browser::fileItems(sizeof(FileItem));
CStringArray Browser::fileItems{sizeof(FileItem)};
int Browser::scrollPosVertical;
int Browser::fileIndexSelected;
int Browser::numCharsInPrefix;
Expand Down
Loading

0 comments on commit 884da39

Please sign in to comment.