mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-23 04:12:02 +00:00
sept: fix undefined behavior with emummc
This commit is contained in:
parent
a4daa0761a
commit
c8f2d17d02
6 changed files with 13 additions and 38 deletions
|
@ -39,7 +39,7 @@ DEFINES := -D__BPMP__ -DFUSEE_STAGE1_SRC -DATMOSPHERE_GIT_BRANCH=\"$(AMSBRANCH)\
|
||||||
|
|
||||||
CFLAGS := \
|
CFLAGS := \
|
||||||
-g \
|
-g \
|
||||||
-O2 \
|
-Os \
|
||||||
-fomit-frame-pointer \
|
-fomit-frame-pointer \
|
||||||
-ffunction-sections \
|
-ffunction-sections \
|
||||||
-fdata-sections \
|
-fdata-sections \
|
||||||
|
@ -76,15 +76,14 @@ export OUTPUT := $(CURDIR)/$(TARGET)
|
||||||
export TOPDIR := $(CURDIR)
|
export TOPDIR := $(CURDIR)
|
||||||
|
|
||||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir)) \
|
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||||
$(AMS)/exosphere/rebootstub
|
|
||||||
|
|
||||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||||
|
|
||||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) rebootstub.bin
|
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# use CXX for linking C++ projects, CC for standard C
|
# use CXX for linking C++ projects, CC for standard C
|
||||||
|
@ -111,13 +110,10 @@ export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||||
|
|
||||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||||
|
|
||||||
.PHONY: $(BUILD) clean all check_rebootstub
|
.PHONY: $(BUILD) clean all
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
all: check_rebootstub $(BUILD)
|
all: $(BUILD)
|
||||||
|
|
||||||
check_rebootstub:
|
|
||||||
@$(MAKE) -C $(AMS)/exosphere/rebootstub all
|
|
||||||
|
|
||||||
$(BUILD):
|
$(BUILD):
|
||||||
@[ -d $@ ] || mkdir -p $@
|
@[ -d $@ ] || mkdir -p $@
|
||||||
|
@ -126,7 +122,6 @@ $(BUILD):
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
clean:
|
clean:
|
||||||
@echo clean ...
|
@echo clean ...
|
||||||
@$(MAKE) -C $(AMS)/exosphere/rebootstub clean
|
|
||||||
@rm -fr $(BUILD) $(TARGET).bin $(TARGET).elf
|
@rm -fr $(BUILD) $(TARGET).bin $(TARGET).elf
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ PHDRS
|
||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
NULL : ORIGIN = 0x00000000, LENGTH = 0x1000
|
NULL : ORIGIN = 0x00000000, LENGTH = 0x1000
|
||||||
main : ORIGIN = 0x40010040, LENGTH = 0x1000
|
main : ORIGIN = 0x40010000, LENGTH = 0x1000
|
||||||
high_iram : ORIGIN = 0x4003F000, LENGTH = 0x1000
|
high_iram : ORIGIN = 0x4003F000, LENGTH = 0x1000
|
||||||
low_iram : ORIGIN = 0x40003000, LENGTH = 0x8000
|
low_iram : ORIGIN = 0x40003000, LENGTH = 0x8000
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ MEMORY
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
PROVIDE(__crt0_start__ = 0x4003F000);
|
PROVIDE(__crt0_start__ = 0x4003F000);
|
||||||
PROVIDE(__main_start__ = 0x40010040);
|
PROVIDE(__main_start__ = 0x40010000);
|
||||||
PROVIDE(__stack_top__ = 0x40010000);
|
PROVIDE(__stack_top__ = 0x40010000);
|
||||||
PROVIDE(__stack_bottom__ = 0x4000C000);
|
PROVIDE(__stack_bottom__ = 0x4000C000);
|
||||||
PROVIDE(__heap_start__ = 0);
|
PROVIDE(__heap_start__ = 0);
|
||||||
|
|
|
@ -93,6 +93,10 @@ ipatch_word:
|
||||||
.global jump_to_main
|
.global jump_to_main
|
||||||
.type jump_to_main, %function
|
.type jump_to_main, %function
|
||||||
jump_to_main:
|
jump_to_main:
|
||||||
|
/* Insert 0x40 of NOPs, for version compatibility. */
|
||||||
|
.rept 16
|
||||||
|
nop
|
||||||
|
.endr
|
||||||
/* Just jump to main */
|
/* Just jump to main */
|
||||||
ldr sp, =__stack_top__
|
ldr sp, =__stack_top__
|
||||||
b main
|
b main
|
||||||
|
|
|
@ -27,12 +27,6 @@
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
#define u8 uint8_t
|
|
||||||
#define u32 uint32_t
|
|
||||||
#include "rebootstub_bin.h"
|
|
||||||
#undef u8
|
|
||||||
#undef u32
|
|
||||||
|
|
||||||
void wait(uint32_t microseconds) {
|
void wait(uint32_t microseconds) {
|
||||||
uint32_t old_time = TIMERUS_CNTR_1US_0;
|
uint32_t old_time = TIMERUS_CNTR_1US_0;
|
||||||
while (TIMERUS_CNTR_1US_0 - old_time <= microseconds) {
|
while (TIMERUS_CNTR_1US_0 - old_time <= microseconds) {
|
||||||
|
@ -63,29 +57,12 @@ __attribute__((noreturn)) void pmc_reboot(uint32_t scratch0) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((noreturn)) void reboot_to_self(void) {
|
|
||||||
/* Patch SDRAM init to perform an SVC immediately after second write */
|
|
||||||
APBDEV_PMC_SCRATCH45_0 = 0x2E38DFFF;
|
|
||||||
APBDEV_PMC_SCRATCH46_0 = 0x6001DC28;
|
|
||||||
/* Set SVC handler to jump to reboot stub in IRAM. */
|
|
||||||
APBDEV_PMC_SCRATCH33_0 = 0x4003F000;
|
|
||||||
APBDEV_PMC_SCRATCH40_0 = 0x6000F208;
|
|
||||||
|
|
||||||
/* Copy reboot stub into IRAM high. */
|
|
||||||
for (size_t i = 0; i < rebootstub_bin_size; i += sizeof(uint32_t)) {
|
|
||||||
write32le((void *)0x4003F000, i, read32le(rebootstub_bin, i));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Trigger warm reboot. */
|
|
||||||
pmc_reboot(1 << 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__((noreturn)) void wait_for_button_and_reboot(void) {
|
__attribute__((noreturn)) void wait_for_button_and_reboot(void) {
|
||||||
uint32_t button;
|
uint32_t button;
|
||||||
while (true) {
|
while (true) {
|
||||||
button = btn_read();
|
button = btn_read();
|
||||||
if (button & BTN_POWER) {
|
if (button & BTN_POWER) {
|
||||||
reboot_to_self();
|
pmc_reboot(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,7 +121,6 @@ void hexdump(const void* data, size_t size, uintptr_t addrbase);
|
||||||
|
|
||||||
__attribute__((noreturn)) void watchdog_reboot(void);
|
__attribute__((noreturn)) void watchdog_reboot(void);
|
||||||
__attribute__((noreturn)) void pmc_reboot(uint32_t scratch0);
|
__attribute__((noreturn)) void pmc_reboot(uint32_t scratch0);
|
||||||
__attribute__((noreturn)) void reboot_to_self(void);
|
|
||||||
__attribute__((noreturn)) void wait_for_button_and_reboot(void);
|
__attribute__((noreturn)) void wait_for_button_and_reboot(void);
|
||||||
|
|
||||||
__attribute__((noreturn)) void generic_panic(void);
|
__attribute__((noreturn)) void generic_panic(void);
|
||||||
|
|
Loading…
Reference in a new issue