Fix crt0 & include missing files
This commit is contained in:
parent
ab14e77b50
commit
ee880802c8
44
loader/source/firm.c
Normal file
44
loader/source/firm.c
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2017 Aurora Wright, TuxSH
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b of GPLv3 applies to this file: Requiring preservation of specified
|
||||||
|
* reasonable legal notices or author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "firm.h"
|
||||||
|
#include "memory.h"
|
||||||
|
#include "cache.h"
|
||||||
|
|
||||||
|
void launchFirm(Firm *firm, int argc, char **argv)
|
||||||
|
{
|
||||||
|
|
||||||
|
//Copy FIRM sections to respective memory locations
|
||||||
|
for(u32 sectionNum = 0; sectionNum < 4 && firm->section[sectionNum].size != 0; sectionNum++)
|
||||||
|
memcpy(firm->section[sectionNum].address, (u8 *)firm + firm->section[sectionNum].offset, firm->section[sectionNum].size);
|
||||||
|
|
||||||
|
//Set ARM11 entrypoint
|
||||||
|
*(vu32 *)0x1FFFFFFC = (u32)firm->arm11Entry;
|
||||||
|
|
||||||
|
//Ensure that all memory transfers have completed and that the caches have been flushed
|
||||||
|
flushCaches();
|
||||||
|
|
||||||
|
//Jump to ARM9 entrypoint. Also give it additional arguments it can dismiss
|
||||||
|
((void (*)(int, char**, u32))firm->arm9Entry)(argc, argv, 0x0000BEEF);
|
||||||
|
|
||||||
|
__builtin_unreachable();
|
||||||
|
}
|
46
loader/source/firm.h
Normal file
46
loader/source/firm.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Luma3DS
|
||||||
|
* Copyright (C) 2017 Aurora Wright, TuxSH
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b of GPLv3 applies to this file: Requiring preservation of specified
|
||||||
|
* reasonable legal notices or author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
typedef struct __attribute__((packed))
|
||||||
|
{
|
||||||
|
u32 offset;
|
||||||
|
u8 *address;
|
||||||
|
u32 size;
|
||||||
|
u32 procType;
|
||||||
|
u8 hash[0x20];
|
||||||
|
} FirmSection;
|
||||||
|
|
||||||
|
typedef struct __attribute__((packed))
|
||||||
|
{
|
||||||
|
char magic[4];
|
||||||
|
u32 reserved1;
|
||||||
|
u8 *arm11Entry;
|
||||||
|
u8 *arm9Entry;
|
||||||
|
u8 reserved2[0x30];
|
||||||
|
FirmSection section[4];
|
||||||
|
} Firm;
|
||||||
|
|
||||||
|
void launchFirm(Firm *firm, int argc, char **argv);
|
@ -33,6 +33,9 @@ _start:
|
|||||||
cmp r2, r4
|
cmp r2, r4
|
||||||
movne r0, #0 @ check magic word
|
movne r0, #0 @ check magic word
|
||||||
|
|
||||||
|
mov r9, r0
|
||||||
|
mov r10, r1
|
||||||
|
|
||||||
@ Change the stack pointer
|
@ Change the stack pointer
|
||||||
mov sp, #0x27000000
|
mov sp, #0x27000000
|
||||||
|
|
||||||
@ -47,8 +50,6 @@ _start:
|
|||||||
bl flushEntireDCache
|
bl flushEntireDCache
|
||||||
bl flushEntireICache
|
bl flushEntireICache
|
||||||
|
|
||||||
push {r0-r3}
|
|
||||||
|
|
||||||
@ Give read/write access to all the memory regions
|
@ Give read/write access to all the memory regions
|
||||||
ldr r0, =0x3333333
|
ldr r0, =0x3333333
|
||||||
mcr p15, 0, r0, c5, c0, 2 @ write data access
|
mcr p15, 0, r0, c5, c0, 2 @ write data access
|
||||||
@ -97,5 +98,6 @@ _start:
|
|||||||
sub r2, r0
|
sub r2, r0
|
||||||
bl memset32
|
bl memset32
|
||||||
|
|
||||||
pop {r0-r3}
|
mov r0, r9
|
||||||
|
mov r1, r10
|
||||||
b main
|
b main
|
||||||
|
Reference in New Issue
Block a user