mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-02-16 21:45:37 +00:00
meso: miscellaneous cleanup and build fixes
This commit is contained in:
parent
af352e4f7f
commit
623b5f4eb9
7 changed files with 73 additions and 153 deletions
|
@ -52,7 +52,7 @@ ATMOSPHERE_DEFINES += -DATMOSPHERE_GIT_BRANCH=\"$(ATMOSPHERE_GIT_BRANCH)\" -DATM
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# Ensure top directory is set.
|
# Ensure top directory is set.
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
export TOPDIR ?= $(CURDIR)
|
TOPDIR ?= $(CURDIR)
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# TARGET is the name of the output
|
# TARGET is the name of the output
|
||||||
|
@ -60,13 +60,13 @@ export TOPDIR ?= $(CURDIR)
|
||||||
# DATA is a list of directories containing data files
|
# DATA is a list of directories containing data files
|
||||||
# INCLUDES is a list of directories containing header files
|
# INCLUDES is a list of directories containing header files
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
export TARGET ?= $(notdir $(CURDIR))
|
TARGET := $(notdir $(CURDIR))
|
||||||
export BUILD := build
|
BUILD := build
|
||||||
export DATA := data
|
DATA := data
|
||||||
export INCLUDES := include
|
INCLUDES := include
|
||||||
export SOURCES ?= $(shell find source -type d \
|
SOURCES ?= $(shell find source -type d \
|
||||||
-not \( -path source/arch -prune \) \
|
-not \( -path source/arch -prune \) \
|
||||||
-not \( -path source/board -prune \) \)
|
-not \( -path source/board -prune \) \)
|
||||||
|
|
||||||
ifneq ($(strip $(wildcard source/$(ATMOSPHERE_ARCH_DIR)/.*)),)
|
ifneq ($(strip $(wildcard source/$(ATMOSPHERE_ARCH_DIR)/.*)),)
|
||||||
SOURCES += $(shell find source/$(ATMOSPHERE_ARCH_DIR) -type d)
|
SOURCES += $(shell find source/$(ATMOSPHERE_ARCH_DIR) -type d)
|
||||||
|
|
|
@ -18,5 +18,5 @@
|
||||||
#ifdef ATMOSPHERE_ARCH_ARM64
|
#ifdef ATMOSPHERE_ARCH_ARM64
|
||||||
#include "../arch/arm64/init/kern_k_init_page_table.hpp"
|
#include "../arch/arm64/init/kern_k_init_page_table.hpp"
|
||||||
#else
|
#else
|
||||||
#error "Unknown architecutre for KInitialPageTable"
|
#error "Unknown architecture for KInitialPageTable"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,66 +17,68 @@
|
||||||
|
|
||||||
namespace ams::kern::init::Elf::Elf64 {
|
namespace ams::kern::init::Elf::Elf64 {
|
||||||
|
|
||||||
/* API to apply relocations or call init array. */
|
/* API to apply relocations or call init array. */
|
||||||
void ApplyRelocations(uintptr_t base_address, const Dyn *dynamic) {
|
void ApplyRelocations(uintptr_t base_address, const Dyn *dynamic) {
|
||||||
uintptr_t dyn_rel = 0;
|
uintptr_t dyn_rel = 0;
|
||||||
uintptr_t dyn_rela = 0;
|
uintptr_t dyn_rela = 0;
|
||||||
uintptr_t rel_count = 0;
|
uintptr_t rel_count = 0;
|
||||||
uintptr_t rela_count = 0;
|
uintptr_t rela_count = 0;
|
||||||
uintptr_t rel_ent = 0;
|
uintptr_t rel_ent = 0;
|
||||||
uintptr_t rela_ent = 0;
|
uintptr_t rela_ent = 0;
|
||||||
|
|
||||||
/* Iterate over all tags, identifying important extents. */
|
/* Iterate over all tags, identifying important extents. */
|
||||||
for (const Dyn *cur_entry = dynamic; cur_entry->GetTag() != DT_NULL; cur_entry++) {
|
for (const Dyn *cur_entry = dynamic; cur_entry->GetTag() != DT_NULL; cur_entry++) {
|
||||||
switch (cur_entry->GetTag()) {
|
switch (cur_entry->GetTag()) {
|
||||||
case DT_REL:
|
case DT_REL:
|
||||||
dyn_rel = base_address + cur_entry->GetPtr();
|
dyn_rel = base_address + cur_entry->GetPtr();
|
||||||
break;
|
break;
|
||||||
case DT_RELA:
|
case DT_RELA:
|
||||||
dyn_rela = base_address + cur_entry->GetPtr();
|
dyn_rela = base_address + cur_entry->GetPtr();
|
||||||
break;
|
break;
|
||||||
case DT_RELENT:
|
case DT_RELENT:
|
||||||
rel_ent = cur_entry->GetValue();
|
rel_ent = cur_entry->GetValue();
|
||||||
break;
|
break;
|
||||||
case DT_RELAENT:
|
case DT_RELAENT:
|
||||||
rela_ent = cur_entry->GetValue();
|
rela_ent = cur_entry->GetValue();
|
||||||
break;
|
break;
|
||||||
case DT_RELCOUNT:
|
case DT_RELCOUNT:
|
||||||
rel_count = cur_entry->GetValue();
|
rel_count = cur_entry->GetValue();
|
||||||
break;
|
break;
|
||||||
case DT_RELACOUNT:
|
case DT_RELACOUNT:
|
||||||
rela_count = cur_entry->GetValue();
|
rela_count = cur_entry->GetValue();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply all Rel relocations */
|
/* Apply all Rel relocations */
|
||||||
for (size_t i = 0; i < rel_count; i++) {
|
for (size_t i = 0; i < rel_count; i++) {
|
||||||
const auto &rel = *reinterpret_cast<const Elf64::Rel *>(dyn_rel + rel_ent * i);
|
const auto &rel = *reinterpret_cast<const Elf64::Rel *>(dyn_rel + rel_ent * i);
|
||||||
|
|
||||||
/* Only allow R_AARCH64_RELATIVE relocations. */
|
/* Only allow R_AARCH64_RELATIVE relocations. */
|
||||||
while (rel.GetType() != R_AARCH64_RELATIVE) { /* ... */ }
|
while (rel.GetType() != R_AARCH64_RELATIVE) { /* ... */ }
|
||||||
|
|
||||||
/* Apply the relocation. */
|
/* Apply the relocation. */
|
||||||
Elf64::Addr *target_address = reinterpret_cast<Elf64::Addr *>(base_address + rel.GetOffset());
|
Elf64::Addr *target_address = reinterpret_cast<Elf64::Addr *>(base_address + rel.GetOffset());
|
||||||
*target_address += base_address;
|
*target_address += base_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply all Rela relocations. */
|
/* Apply all Rela relocations. */
|
||||||
for (size_t i = 0; i < rela_count; i++) {
|
for (size_t i = 0; i < rela_count; i++) {
|
||||||
const auto &rela = *reinterpret_cast<const Elf64::Rela *>(dyn_rela + rela_ent * i);
|
const auto &rela = *reinterpret_cast<const Elf64::Rela *>(dyn_rela + rela_ent * i);
|
||||||
|
|
||||||
/* Only allow R_AARCH64_RELATIVE relocations. */
|
/* Only allow R_AARCH64_RELATIVE relocations. */
|
||||||
while (rela.GetType() != R_AARCH64_RELATIVE) { /* ... */ }
|
while (rela.GetType() != R_AARCH64_RELATIVE) { /* ... */ }
|
||||||
|
|
||||||
/* Apply the relocation. */
|
/* Apply the relocation. */
|
||||||
Elf64::Addr *target_address = reinterpret_cast<Elf64::Addr *>(base_address + rela.GetOffset());
|
Elf64::Addr *target_address = reinterpret_cast<Elf64::Addr *>(base_address + rela.GetOffset());
|
||||||
*target_address = base_address + rela.GetAddend();
|
*target_address = base_address + rela.GetAddend();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallInitArrayFuncs(uintptr_t init_array_start, uintptr_t init_array_end) {
|
void CallInitArrayFuncs(uintptr_t init_array_start, uintptr_t init_array_end) {
|
||||||
|
for (uintptr_t cur_entry = init_array_start; cur_entry < init_array_end; cur_entry += sizeof(void *)) {
|
||||||
}
|
(*(void (**)())(cur_entry))();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,84 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2018-2019 Atmosphère-NX
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms and conditions of the GNU General Public License,
|
|
||||||
* version 2, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope 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 <mesosphere.hpp>
|
|
||||||
|
|
||||||
namespace ams::kern::init::Elf::Elf64 {
|
|
||||||
|
|
||||||
/* API to apply relocations or call init array. */
|
|
||||||
void ApplyRelocations(uintptr_t base_address, const Dyn *dynamic) {
|
|
||||||
uintptr_t dyn_rel = 0;
|
|
||||||
uintptr_t dyn_rela = 0;
|
|
||||||
uintptr_t rel_count = 0;
|
|
||||||
uintptr_t rela_count = 0;
|
|
||||||
uintptr_t rel_ent = 0;
|
|
||||||
uintptr_t rela_ent = 0;
|
|
||||||
|
|
||||||
/* Iterate over all tags, identifying important extents. */
|
|
||||||
for (const Dyn *cur_entry = dynamic; cur_entry->GetTag() != DT_NULL; cur_entry++) {
|
|
||||||
switch (cur_entry->GetTag()) {
|
|
||||||
case DT_REL:
|
|
||||||
dyn_rel = base_address + cur_entry->GetPtr();
|
|
||||||
break;
|
|
||||||
case DT_RELA:
|
|
||||||
dyn_rela = base_address + cur_entry->GetPtr();
|
|
||||||
break;
|
|
||||||
case DT_RELENT:
|
|
||||||
rel_ent = cur_entry->GetValue();
|
|
||||||
break;
|
|
||||||
case DT_RELAENT:
|
|
||||||
rela_ent = cur_entry->GetValue();
|
|
||||||
break;
|
|
||||||
case DT_RELCOUNT:
|
|
||||||
rel_count = cur_entry->GetValue();
|
|
||||||
break;
|
|
||||||
case DT_RELACOUNT:
|
|
||||||
rela_count = cur_entry->GetValue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Apply all Rel relocations */
|
|
||||||
for (size_t i = 0; i < rel_count; i++) {
|
|
||||||
const auto &rel = *reinterpret_cast<const Elf64::Rel *>(dyn_rel + rel_ent * i);
|
|
||||||
|
|
||||||
/* Only allow R_AARCH64_RELATIVE relocations. */
|
|
||||||
while (rel.GetType() != R_AARCH64_RELATIVE) { /* ... */ }
|
|
||||||
|
|
||||||
/* Apply the relocation. */
|
|
||||||
Elf64::Addr *target_address = reinterpret_cast<Elf64::Addr *>(base_address + rel.GetOffset());
|
|
||||||
*target_address += base_address;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Apply all Rela relocations. */
|
|
||||||
for (size_t i = 0; i < rela_count; i++) {
|
|
||||||
const auto &rela = *reinterpret_cast<const Elf64::Rela *>(dyn_rela + rela_ent * i);
|
|
||||||
|
|
||||||
/* Only allow R_AARCH64_RELATIVE relocations. */
|
|
||||||
while (rela.GetType() != R_AARCH64_RELATIVE) { /* ... */ }
|
|
||||||
|
|
||||||
/* Apply the relocation. */
|
|
||||||
Elf64::Addr *target_address = reinterpret_cast<Elf64::Addr *>(base_address + rela.GetOffset());
|
|
||||||
*target_address = base_address + rela.GetAddend();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CallInitArrayFuncs(uintptr_t init_array_start, uintptr_t init_array_end) {
|
|
||||||
for (uintptr_t cur_entry = init_array_start; cur_entry < init_array_end; cur_entry += sizeof(void *)) {
|
|
||||||
(*(void (**)())(cur_entry))();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -11,6 +11,7 @@ ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
|
|
||||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||||
|
export TOPDIR := $(CURDIR)
|
||||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||||
|
|
||||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||||
|
@ -59,21 +60,23 @@ 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: clean all
|
.PHONY: $(BUILD) clean all
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
all: $(BUILD)
|
all: $(BUILD) check_libmeso
|
||||||
|
|
||||||
$(BUILD):
|
$(BUILD): check_libmeso
|
||||||
@[ -d $@ ] || mkdir -p $@
|
@[ -d $@ ] || mkdir -p $@
|
||||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||||
|
|
||||||
|
check_libmeso:
|
||||||
|
@$(MAKE) --no-print-directory -C ../../libraries/libmesosphere
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
clean:
|
clean:
|
||||||
@echo clean ...
|
@echo clean ...
|
||||||
@rm -fr $(BUILD) $(OUTPUT).bin $(OUTPUT).elf
|
@rm -fr $(BUILD) $(OUTPUT).bin $(OUTPUT).elf
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
else
|
else
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
|
@ -89,7 +92,7 @@ $(OUTPUT).bin : $(OUTPUT).elf
|
||||||
$(OBJCOPY) -S -O binary $< $@
|
$(OBJCOPY) -S -O binary $< $@
|
||||||
@echo built ... $(notdir $@)
|
@echo built ... $(notdir $@)
|
||||||
|
|
||||||
$(OUTPUT).elf : $(OFILES)
|
$(OUTPUT).elf : $(OFILES) ../../../libraries/libmesosphere/lib/libmesosphere.a
|
||||||
|
|
||||||
%.elf:
|
%.elf:
|
||||||
@echo linking $(notdir $@)
|
@echo linking $(notdir $@)
|
||||||
|
|
|
@ -73,7 +73,6 @@ SECTIONS
|
||||||
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } :krnlldr
|
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } :krnlldr
|
||||||
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) } : rodata
|
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) } : rodata
|
||||||
|
|
||||||
__dynamic__start__ = . ;
|
|
||||||
.dynamic : { *(.dynamic) } :krnlldr :dyn
|
.dynamic : { *(.dynamic) } :krnlldr :dyn
|
||||||
.dynsym : { *(.dynsym) } :krnlldr
|
.dynsym : { *(.dynsym) } :krnlldr
|
||||||
.dynstr : { *(.dynstr) } :krnlldr
|
.dynstr : { *(.dynstr) } :krnlldr
|
||||||
|
|
|
@ -89,7 +89,7 @@ __external_references:
|
||||||
.quad __bss_start__ - _start
|
.quad __bss_start__ - _start
|
||||||
.quad __bss_end__ - _start
|
.quad __bss_end__ - _start
|
||||||
.quad __stack_end - _start
|
.quad __stack_end - _start
|
||||||
.quad __dynamic__start__ - _start
|
.quad _DYNAMIC - _start
|
||||||
.quad __init_array_start - _start
|
.quad __init_array_start - _start
|
||||||
.quad __init_array_end - _start
|
.quad __init_array_end - _start
|
||||||
.quad __vectors_start__ - _start
|
.quad __vectors_start__ - _start
|
Loading…
Add table
Reference in a new issue