Skip to content

Commit

Permalink
Deinit critical hardware before FIRM launch.
Browse files Browse the repository at this point in the history
  • Loading branch information
profi200 committed Jan 6, 2018
1 parent 3de47de commit 2f277db
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 10 deletions.
26 changes: 26 additions & 0 deletions include/system.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

/*
* This file is part of fastboot 3DS
* Copyright (C) 2018 derrek, profi200
*
* 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/>.
*/

#include "types.h"



//void WEAK __systemInit(void);
void WEAK __systemDeinit(void);
2 changes: 2 additions & 0 deletions source/arm11/firm.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "mem_map.h"
#include "arm11/start.h"
#include "hardware/pxi.h"
#include "system.h"
#include "ipc_handler.h"


Expand Down Expand Up @@ -67,6 +68,7 @@ noreturn void firmLaunch(void)
// Relocate ARM11 stub
memcpy((void*)A11_STUB_ENTRY, (const void*)firmLaunchStub, A11_STUB_SIZE);

__systemDeinit();
deinitCpu();

// Change sp to a safe location
Expand Down
2 changes: 2 additions & 0 deletions source/arm11/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "hardware/cache.h"
#include "hardware/gfx.h"
#include "hardware/pxi.h"
#include "system.h"
#include "arm.h"


Expand All @@ -37,6 +38,7 @@ static void power_safe_halt(void)
// give the screens a bit of time to turn off
TIMER_sleepMs(400);

__systemDeinit();
flushDCache();
__cpsid(aif);
}
Expand Down
9 changes: 4 additions & 5 deletions source/arm11/start.s
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@
.extern setupMmu
.extern __libc_init_array
.extern core123Init
.extern systemInit
.extern __systemInit
.extern main
.extern power_off

.section ".crt0", "ax"

Expand Down Expand Up @@ -142,14 +143,12 @@ _start_skip_bss_init_array:
blx setupMmu
bl setupVfp
cpsie a
blx systemInit
blx __systemInit

mov r0, #0 @ argc
mov r1, #0 @ argv
blx main
_start_lp:
wfi
b _start_lp
b power_off


#define MAKE_BRANCH(src, dst) (0xEA000000 | (((((dst) - (src)) >> 2) - 2) & 0xFFFFFF))
Expand Down
9 changes: 7 additions & 2 deletions source/arm11/system.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of fastboot 3DS
* Copyright (C) 2017 derrek, profi200
* Copyright (C) 2018 derrek, profi200
*
* 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
Expand Down Expand Up @@ -34,7 +34,7 @@ static void systemRestoreHwState(void)
MCU_disableLEDs();
}

void WEAK systemInit(void)
void WEAK __systemInit(void)
{
IRQ_init();
TIMER_init();
Expand Down Expand Up @@ -62,3 +62,8 @@ void WEAK systemInit(void)
CPU_poweroffCore23();
#endif
}

void WEAK __systemDeinit(void)
{
IRQ_init();
}
2 changes: 2 additions & 0 deletions source/arm9/firm.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "arm9/dev.h"
#include "fs.h"
#include "hardware/gfx.h"
#include "system.h"


typedef struct
Expand Down Expand Up @@ -329,6 +330,7 @@ noreturn void firmLaunch(void)
{
memcpy((void*)A9_STUB_ENTRY, (const void*)firmLaunchStub, A9_STUB_SIZE);

__systemDeinit();
deinitCpu();

((void (*)(int, const char**))A9_STUB_ENTRY)(firmLaunchArgc, (const char**)(ITCM_KERNEL_MIRROR + 0x7470));
Expand Down
6 changes: 4 additions & 2 deletions source/arm9/start.s
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
.extern fake_heap_start
.extern fake_heap_end
.extern __libc_init_array
.extern systemInit
.extern __systemInit
.extern main
.extern __systemDeinit
.extern irqHandler
.extern undefInstrHandler
.extern prefetchAbortHandler
Expand Down Expand Up @@ -110,11 +111,12 @@ _start:
ldr r1, =fake_heap_end
str r0, [r1]
blx __libc_init_array @ Initialize ctors and dtors
blx systemInit
blx __systemInit

mov r0, #0 @ argc
mov r1, #0 @ argv
blx main
blx __systemDeinit
_start_lp:
mov r0, #0
mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
Expand Down
8 changes: 7 additions & 1 deletion source/arm9/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@



void systemInit(void)
void WEAK __systemInit(void)
{
IRQ_init();
NDMA_init();
Expand All @@ -36,3 +36,9 @@ void systemInit(void)

leaveCriticalSection(0); // Enables interrupts
}

void WEAK __systemDeinit(void)
{
NDMA_init();
IRQ_init();
}

0 comments on commit 2f277db

Please sign in to comment.