mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-30 14:35:17 -04:00
meso: skeleton libmesosphere in prep for kernelldr dev
This commit is contained in:
parent
0b0fdc5c58
commit
36c47a0014
22 changed files with 732 additions and 13 deletions
129
libraries/libmesosphere/Makefile
Normal file
129
libraries/libmesosphere/Makefile
Normal file
|
@ -0,0 +1,129 @@
|
|||
#---------------------------------------------------------------------------------
|
||||
# pull in common atmosphere configuration
|
||||
#---------------------------------------------------------------------------------
|
||||
include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/../config/common.mk
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
DEFINES := $(ATMOSPHERE_DEFINES) -DATMOSPHERE_IS_MESOSPHERE
|
||||
SETTINGS := $(ATMOSPHERE_SETTINGS) -O2 -mgeneral-regs-only -Werror
|
||||
CFLAGS := $(ATMOSPHERE_CFLAGS) $(SETTINGS) $(DEFINES) $(INCLUDE)
|
||||
CXXFLAGS := $(CFLAGS) $(ATMOSPHERE_CXXFLAGS) -flto
|
||||
ASFLAGS := $(ATMOSPHERE_ASFLAGS) $(SETTINGS)
|
||||
|
||||
LIBS :=
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(ATMOSPHERE_LIBRARIES_DIR)/libvapours
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
CFILES := $(foreach dir,$(SOURCES),$(filter-out $(notdir $(wildcard $(dir)/*.arch.*.c)) $(notdir $(wildcard $(dir)/*.board.*.c)) $(notdir $(wildcard $(dir)/*.os.*.c)), \
|
||||
$(notdir $(wildcard $(dir)/*.c))))
|
||||
CFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.arch.$(ATMOSPHERE_ARCH_NAME).c)))
|
||||
CFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.board.$(ATMOSPHERE_BOARD_NAME).c)))
|
||||
CFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.os.$(ATMOSPHERE_OS_NAME).c)))
|
||||
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(filter-out $(notdir $(wildcard $(dir)/*.arch.*.cpp)) $(notdir $(wildcard $(dir)/*.board.*.cpp)) $(notdir $(wildcard $(dir)/*.os.*.cpp)), \
|
||||
$(notdir $(wildcard $(dir)/*.cpp))))
|
||||
CPPFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.arch.$(ATMOSPHERE_ARCH_NAME).cpp)))
|
||||
CPPFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.board.$(ATMOSPHERE_BOARD_NAME).cpp)))
|
||||
CPPFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.os.$(ATMOSPHERE_OS_NAME).cpp)))
|
||||
|
||||
SFILES := $(foreach dir,$(SOURCES),$(filter-out $(notdir $(wildcard $(dir)/*.arch.*.s)) $(notdir $(wildcard $(dir)/*.board.*.s)) $(notdir $(wildcard $(dir)/*.os.*.s)), \
|
||||
$(notdir $(wildcard $(dir)/*.s))))
|
||||
SFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.arch.$(ATMOSPHERE_ARCH_NAME).s)))
|
||||
SFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.board.$(ATMOSPHERE_BOARD_NAME).s)))
|
||||
SFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.os.$(ATMOSPHERE_OS_NAME).s)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
||||
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
|
||||
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I.
|
||||
|
||||
.PHONY: clean all
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
all: lib/$(TARGET).a
|
||||
|
||||
lib:
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
|
||||
release:
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
|
||||
lib/$(TARGET).a : lib release $(SOURCES) $(INCLUDES)
|
||||
@$(MAKE) BUILD=release OUTPUT=$(CURDIR)/$@ \
|
||||
BUILD_CFLAGS="-DNDEBUG=1 -O2" \
|
||||
DEPSDIR=$(CURDIR)/release \
|
||||
--no-print-directory -C release \
|
||||
-f $(CURDIR)/Makefile
|
||||
|
||||
dist-bin: all
|
||||
@tar --exclude=*~ -cjf $(TARGET).tar.bz2 include lib
|
||||
|
||||
dist-src:
|
||||
@tar --exclude=*~ -cjf $(TARGET)-src.tar.bz2 include source Makefile
|
||||
|
||||
dist: dist-src dist-bin
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr release lib *.bz2
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
$(OUTPUT) : $(OFILES)
|
||||
|
||||
$(OFILES_SRC) : $(HFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%_bin.h %.bin.o : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
||||
|
28
libraries/libmesosphere/README.md
Normal file
28
libraries/libmesosphere/README.md
Normal file
|
@ -0,0 +1,28 @@
|
|||

|
||||
|
||||
libmesosphere is a work-in-progress C++ library implementing functionality for the Horizon Kernel.
|
||||
|
||||
Licensing
|
||||
=====
|
||||
|
||||
This software is licensed under the terms of the GPLv2, with exemptions for specific projects noted below.
|
||||
|
||||
You can find a copy of the license in the [LICENSE file](LICENSE).
|
||||
|
||||
Exemptions:
|
||||
* The [yuzu emulator project](https://github.com/yuzu-emu/yuzu) is exempt from GPLv2 licensing and may (at its option) instead license any source code authored for the libmesosphere project as GPLv2 or later.
|
||||
|
||||
Credits
|
||||
=====
|
||||
|
||||
libmesosphere is currently being developed and maintained by __SciresM__.<br>
|
||||
|
||||
In addition to those credited in [Atmosphère's credits](https://github.com/Atmosphere-NX/Atmosphere/blob/master/README.md#Credits), we would like to thank for contributing to libmesosphere in some significant way:
|
||||
|
||||
* @[devkitPro](https://github.com/devkitPro)
|
||||
* @[yellows8](https://github.com/yellows8)
|
||||
* @[qlutoo](https://github.com/plutooo)
|
||||
* @[hedgeberg](https://github.com/hedgeberg)
|
||||
* @[Nintendo](https://github.com/Nintendo)
|
||||
* @[NVidia](https://github.com/NVidia)
|
||||
* @[Kaphotics](https://github.com/kwsch)
|
28
libraries/libmesosphere/include/mesosphere.hpp
Normal file
28
libraries/libmesosphere/include/mesosphere.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/* All kernel code should have access to libvapours. */
|
||||
#include <vapours.hpp>
|
||||
|
||||
/* First, pull in core macros (panic, etc). */
|
||||
#include "mesosphere/kern_panic.hpp"
|
||||
|
||||
/* Primitive types. */
|
||||
#include "mesosphere/kern_k_typed_address.hpp"
|
||||
|
||||
/* Core functionality. */
|
||||
#include "mesosphere/kern_select_k_system_control.hpp"
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::kern {
|
||||
|
||||
class KSystemControl {
|
||||
public:
|
||||
|
||||
/* Panic. */
|
||||
static NORETURN void StopSystem();
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,240 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::kern {
|
||||
|
||||
#ifndef MESOSPHERE_DISABLE_TYPED_ADDRESSES
|
||||
|
||||
template<bool Virtual, typename T>
|
||||
class KTypedAddress {
|
||||
private:
|
||||
uintptr_t address;
|
||||
public:
|
||||
/* Constructors. */
|
||||
constexpr ALWAYS_INLINE KTypedAddress() : address(0) { /* ... */ }
|
||||
constexpr ALWAYS_INLINE KTypedAddress(uintptr_t a) : address(a) { /* ... */ }
|
||||
template<typename U>
|
||||
constexpr ALWAYS_INLINE explicit KTypedAddress(U *ptr) : address(reinterpret_cast<uintptr_t>(ptr)) { /* ... */ }
|
||||
|
||||
/* Assignment operator. */
|
||||
constexpr ALWAYS_INLINE KTypedAddress operator=(KTypedAddress rhs) {
|
||||
this->address = rhs.address;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* Arithmetic operators. */
|
||||
template<typename I>
|
||||
constexpr ALWAYS_INLINE KTypedAddress operator+(I rhs) const {
|
||||
static_assert(std::is_integral<I>::value);
|
||||
return this->address + rhs;
|
||||
}
|
||||
|
||||
template<typename I>
|
||||
constexpr ALWAYS_INLINE KTypedAddress operator-(I rhs) const {
|
||||
static_assert(std::is_integral<I>::value);
|
||||
return this->address - rhs;
|
||||
}
|
||||
|
||||
template<typename I>
|
||||
constexpr ALWAYS_INLINE KTypedAddress operator+=(I rhs) {
|
||||
static_assert(std::is_integral<I>::value);
|
||||
this->address += rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename I>
|
||||
constexpr ALWAYS_INLINE KTypedAddress operator-=(I rhs) {
|
||||
static_assert(std::is_integral<I>::value);
|
||||
this->address -= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* Logical operators. */
|
||||
constexpr ALWAYS_INLINE uintptr_t operator&(uintptr_t mask) const {
|
||||
return this->address & mask;
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE uintptr_t operator|(uintptr_t mask) const {
|
||||
return this->address | mask;
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE uintptr_t operator<<(int shift) const {
|
||||
return this->address << shift;
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE uintptr_t operator>>(int shift) const {
|
||||
return this->address >> shift;
|
||||
}
|
||||
|
||||
/* Comparison operators. */
|
||||
constexpr ALWAYS_INLINE bool operator==(KTypedAddress rhs) const {
|
||||
return this->address == rhs.address;
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE bool operator!=(KTypedAddress rhs) const {
|
||||
return this->address != rhs.address;
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE bool operator<(KTypedAddress rhs) const {
|
||||
return this->address < rhs.address;
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE bool operator<=(KTypedAddress rhs) const {
|
||||
return this->address <= rhs.address;
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE bool operator>(KTypedAddress rhs) const {
|
||||
return this->address > rhs.address;
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE bool operator>=(KTypedAddress rhs) const {
|
||||
return this->address >= rhs.address;
|
||||
}
|
||||
|
||||
/* For convenience, also define comparison operators versus uintptr_t. */
|
||||
constexpr ALWAYS_INLINE bool operator==(uintptr_t rhs) const {
|
||||
return this->address == rhs;
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE bool operator!=(uintptr_t rhs) const {
|
||||
return this->address != rhs;
|
||||
}
|
||||
|
||||
/* TODO: <, <=, >, >= against uintptr_t? would need to be declared outside of class. Maybe worth it. */
|
||||
|
||||
/* Allow getting the address explicitly, for use in accessors. */
|
||||
constexpr ALWAYS_INLINE uintptr_t GetValue() const {
|
||||
return this->address;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct KPhysicalAddressTag{};
|
||||
struct KVirtualAddressTag{};
|
||||
struct KProcessAddressTag{};
|
||||
|
||||
using KPhysicalAddress = KTypedAddress<false, KPhysicalAddressTag>;
|
||||
using KVirtualAddress = KTypedAddress<true, KVirtualAddressTag>;
|
||||
using KProcessAddress = KTypedAddress<true, KProcessAddressTag>;
|
||||
|
||||
/* Define accessors. */
|
||||
template<bool Virtual, typename T>
|
||||
constexpr ALWAYS_INLINE uintptr_t GetInteger(KTypedAddress<Virtual, T> address) {
|
||||
return address.GetValue();
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
constexpr ALWAYS_INLINE T *GetPointer(KTypedAddress<true, U> address) {
|
||||
return CONST_FOLD(reinterpret_cast<T *>(address.GetValue()));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr ALWAYS_INLINE void *GetVoidPointer(KTypedAddress<true, T> address) {
|
||||
return CONST_FOLD(reinterpret_cast<void *>(address.GetValue()));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* Plausibly, we may not want compiler overhead from using strongly typed addresses. */
|
||||
/* In this case, we should just use uintptr_t. */
|
||||
using KPhysicalAddress = uintptr_t;
|
||||
using KVirtualAddress = uintptr_t;
|
||||
using KProcessAddress = uintptr_t;
|
||||
|
||||
/* Define accessors. */
|
||||
constexpr ALWAYS_INLINE uintptr_t GetInteger(uintptr_t address) {
|
||||
return address;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr ALWAYS_INLINE T *GetPointer(uintptr_t address) {
|
||||
return CONST_FOLD(reinterpret_cast<T *>(address));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr ALWAYS_INLINE void *GetVoidPointer(uintptr_t address) {
|
||||
return CONST_FOLD(reinterpret_cast<void *>(address));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
constexpr inline T Null = [] {
|
||||
if constexpr (std::is_same<T, uintptr_t>::value) {
|
||||
return 0;
|
||||
} else {
|
||||
static_assert(std::is_same<T, KPhysicalAddress>::value ||
|
||||
std::is_same<T, KVirtualAddress>::value ||
|
||||
std::is_same<T, KProcessAddress>::value);
|
||||
return T(0);
|
||||
}
|
||||
}();
|
||||
|
||||
/* Basic type validations. */
|
||||
static_assert(sizeof(KPhysicalAddress) == sizeof(uintptr_t));
|
||||
static_assert(sizeof(KVirtualAddress) == sizeof(uintptr_t));
|
||||
static_assert(sizeof(KProcessAddress) == sizeof(uintptr_t));
|
||||
|
||||
static_assert(std::is_trivially_destructible<KPhysicalAddress>::value);
|
||||
static_assert(std::is_trivially_destructible<KVirtualAddress>::value);
|
||||
static_assert(std::is_trivially_destructible<KProcessAddress>::value);
|
||||
|
||||
static_assert(Null<uintptr_t> == 0);
|
||||
static_assert(Null<KPhysicalAddress> == Null<uintptr_t>);
|
||||
static_assert(Null<KVirtualAddress> == Null<uintptr_t>);
|
||||
static_assert(Null<KProcessAddress> == Null<uintptr_t>);
|
||||
|
||||
/* Arithmetic validations. */
|
||||
static_assert(KPhysicalAddress(10) + 5 == KPhysicalAddress(15));
|
||||
static_assert(KPhysicalAddress(10) - 5 == KPhysicalAddress(5));
|
||||
static_assert([]{ KPhysicalAddress v(10); v += 5; return v; }() == KPhysicalAddress(15));
|
||||
static_assert([]{ KPhysicalAddress v(10); v -= 5; return v; }() == KPhysicalAddress(5));
|
||||
|
||||
/* Logical validations. */
|
||||
static_assert((KPhysicalAddress(0b11111111) >> 1) == 0b01111111);
|
||||
static_assert((KPhysicalAddress(0b10101010) >> 1) == 0b01010101);
|
||||
static_assert((KPhysicalAddress(0b11111111) << 1) == 0b111111110);
|
||||
static_assert((KPhysicalAddress(0b01010101) << 1) == 0b10101010);
|
||||
static_assert((KPhysicalAddress(0b11111111) & 0b01010101) == 0b01010101);
|
||||
static_assert((KPhysicalAddress(0b11111111) & 0b10101010) == 0b10101010);
|
||||
static_assert((KPhysicalAddress(0b01010101) & 0b10101010) == 0b00000000);
|
||||
static_assert((KPhysicalAddress(0b00000000) | 0b01010101) == 0b01010101);
|
||||
static_assert((KPhysicalAddress(0b11111111) | 0b01010101) == 0b11111111);
|
||||
static_assert((KPhysicalAddress(0b10101010) | 0b01010101) == 0b11111111);
|
||||
|
||||
/* Comparisons. */
|
||||
static_assert(KPhysicalAddress(0) == KPhysicalAddress(0));
|
||||
static_assert(KPhysicalAddress(0) != KPhysicalAddress(1));
|
||||
static_assert(KPhysicalAddress(0) < KPhysicalAddress(1));
|
||||
static_assert(KPhysicalAddress(0) <= KPhysicalAddress(1));
|
||||
static_assert(KPhysicalAddress(1) > KPhysicalAddress(0));
|
||||
static_assert(KPhysicalAddress(1) >= KPhysicalAddress(0));
|
||||
|
||||
static_assert(!(KPhysicalAddress(0) == KPhysicalAddress(1)));
|
||||
static_assert(!(KPhysicalAddress(0) != KPhysicalAddress(0)));
|
||||
static_assert(!(KPhysicalAddress(1) < KPhysicalAddress(0)));
|
||||
static_assert(!(KPhysicalAddress(1) <= KPhysicalAddress(0)));
|
||||
static_assert(!(KPhysicalAddress(0) > KPhysicalAddress(1)));
|
||||
static_assert(!(KPhysicalAddress(0) >= KPhysicalAddress(1)));
|
||||
|
||||
/* Accessors. */
|
||||
static_assert(15 == GetInteger(KPhysicalAddress(15)));
|
||||
static_assert(0 == GetInteger(Null<KPhysicalAddress>));
|
||||
/* TODO: reinterpret_cast<> not valid in a constant expression, can't test get pointers. */
|
||||
|
||||
}
|
53
libraries/libmesosphere/include/mesosphere/kern_panic.hpp
Normal file
53
libraries/libmesosphere/include/mesosphere/kern_panic.hpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::kern {
|
||||
|
||||
NORETURN void Panic(const char *file, int line, const char *format, ...);
|
||||
NORETURN void Panic();
|
||||
|
||||
}
|
||||
|
||||
#ifdef MESOSPHERE_ENABLE_DEBUG_PRINT
|
||||
#define MESOSPHERE_PANIC(...) ams::kern::Panic(__FILE__, __LINE__, __VA_ARGS__)
|
||||
#else
|
||||
#define MESOSPHERE_PANIC(...) ams::kern::Panic()
|
||||
#endif
|
||||
|
||||
#ifdef MESOSPHERE_ENABLE_ASSERTIONS
|
||||
#define MESOSPHERE_ASSERT_IMPL(expr, ...) \
|
||||
({ \
|
||||
if (AMS_UNLIKELY(!expr)) { \
|
||||
MESOSPHERE_PANIC(__VA_ARGS__); \
|
||||
} \
|
||||
})
|
||||
#else
|
||||
#define MESOSPHERE_ASSERT_IMPL(expr, ...) do { } while (0)
|
||||
#endif
|
||||
|
||||
#define MESOSPHERE_ASSERT(expr) MESOSPHERE_ASSERT_IMPL(expr, "Assertion failed: %s", #expr)
|
||||
#define MESOSPHERE_R_ASSERT(expr) MESOSPHERE_ASSERT_IMPL(R_SUCCEEDED(expr), "Result assertion failed: %s", #expr)
|
||||
|
||||
#define MESOSPHERE_ABORT() MESOSPHERE_PANIC("Abort()");
|
||||
|
||||
#define MESOSPHERE_ABORT_UNLESS(expr) \
|
||||
({ \
|
||||
if (AMS_UNLIKELY(!expr)) { \
|
||||
MESOSPHERE_PANIC("Abort(): %s", #expr); \
|
||||
} \
|
||||
})
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#ifdef ATMOSPHERE_BOARD_NINTENDO_SWITCH
|
||||
#include "board/nintendo/switch/kern_k_system_control.hpp"
|
||||
#else
|
||||
#error "Unknown board for KSystemControl"
|
||||
#endif
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* 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>
|
||||
#include "kern_secure_monitor.hpp"
|
||||
|
||||
namespace ams::kern {
|
||||
|
||||
void KSystemControl::StopSystem() {
|
||||
/* TODO: smc::Panic(0xF00); */
|
||||
while (true) { /* ... */ }
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <mesosphere.hpp>
|
||||
|
||||
namespace ams::kern::smc {
|
||||
|
||||
/* TODO: Secure Monitor API. */
|
||||
|
||||
}
|
45
libraries/libmesosphere/source/kern_panic.cpp
Normal file
45
libraries/libmesosphere/source/kern_panic.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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::result::impl {
|
||||
|
||||
NORETURN void OnResultAssertion(Result result) {
|
||||
MESOSPHERE_PANIC("OnResultAssertion(2%03d-%04d)", result.GetModule(), result.GetDescription());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace ams::kern {
|
||||
|
||||
namespace {
|
||||
|
||||
NORETURN void StopSystem() {
|
||||
KSystemControl::StopSystem();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
NORETURN WEAK_SYMBOL void Panic(const char *file, int line, const char *format, ...) {
|
||||
/* TODO: Implement printing, log this information. */
|
||||
StopSystem();
|
||||
}
|
||||
|
||||
NORETURN WEAK_SYMBOL void Panic() {
|
||||
StopSystem();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue