meso: skeleton libmesosphere in prep for kernelldr dev

This commit is contained in:
Michael Scire 2019-12-12 06:29:37 -08:00 committed by SciresM
parent 0b0fdc5c58
commit 36c47a0014
22 changed files with 732 additions and 13 deletions

View file

@ -33,8 +33,10 @@
#define ALIGNED(algn) __attribute__((aligned(algn)))
#define NORETURN __attribute__((noreturn))
#define WEAK __attribute__((weak))
#define WEAK_SYMBOL __attribute__((weak))
#define ALWAYS_INLINE inline __attribute__((always_inline))
#define CONST_FOLD(x) (__builtin_constant_p(x) ? (x) : (x))
#define CONCATENATE_IMPL(S1, s2) s1##s2
#define CONCATENATE(s1, s2) CONCATENATE_IMPL(s1, s2)
@ -44,3 +46,16 @@
#else
#define ANONYMOUS_VARIABLE(pref) CONCATENATE(pref, __LINE__)
#endif
#define AMS_PREDICT(expr, value, _probability) __builtin_expect_with_probability(expr, value, ({ \
constexpr double probability = _probability; \
static_assert(0.0 <= probability); \
static_assert(probability <= 1.0); \
probability; \
}))
#define AMS_PREDICT_TRUE(expr, probability) AMS_PREDICT(!!expr, 1, probability)
#define AMS_PREDICT_FALSE(expr, probability) AMS_PREDICT(!!expr, 0, probability)
#define AMS_LIKELY(expr) AMS_PREDICT_TRUE(expr, 1.0)
#define AMS_UNLIKELY(expr) AMS_PREDICT_FALSE(expr, 1.0)

View file

@ -54,11 +54,20 @@
#ifdef ATMOSPHERE_BOARD_NINTENDO_SWITCH
#ifdef ATMOSPHERE_IS_STRATOSPHERE
/* Libnx. */
#include <switch.h>
#else
/* Non-EL0 code can't include libnx. */
#include "types.hpp"
#endif
#else
#error "Unsupported board"
#endif /* ATMOSPHERE_BOARD_NINTENDO_SWITCH */

View file

@ -0,0 +1,73 @@
/*
* 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 <cstdint>
#include <cstddef>
#include <cstdbool>
#include <cstdalign>
/* NOTE: This file serves as a substitute for libnx <switch/types.h>. */
typedef uint8_t u8; ///< 8-bit unsigned integer.
typedef uint16_t u16; ///< 16-bit unsigned integer.
typedef uint32_t u32; ///< 32-bit unsigned integer.
typedef uint64_t u64; ///< 64-bit unsigned integer.
typedef __uint128_t u128; ///< 128-bit unsigned integer.
typedef int8_t s8; ///< 8-bit signed integer.
typedef int16_t s16; ///< 16-bit signed integer.
typedef int32_t s32; ///< 32-bit signed integer.
typedef int64_t s64; ///< 64-bit signed integer.
typedef __int128_t s128; ///< 128-bit unsigned integer.
typedef volatile u8 vu8; ///< 8-bit volatile unsigned integer.
typedef volatile u16 vu16; ///< 16-bit volatile unsigned integer.
typedef volatile u32 vu32; ///< 32-bit volatile unsigned integer.
typedef volatile u64 vu64; ///< 64-bit volatile unsigned integer.
typedef volatile u128 vu128; ///< 128-bit volatile unsigned integer.
typedef volatile s8 vs8; ///< 8-bit volatile signed integer.
typedef volatile s16 vs16; ///< 16-bit volatile signed integer.
typedef volatile s32 vs32; ///< 32-bit volatile signed integer.
typedef volatile s64 vs64; ///< 64-bit volatile signed integer.
typedef volatile s128 vs128; ///< 128-bit volatile signed integer.
typedef u32 Result; ///< Function error code result type.
/// Creates a bitmask from a bit number.
#ifndef BIT
#define BIT(n) (1U<<(n))
#endif
/// Marks a function as not returning, for the purposes of compiler optimization.
#ifndef NORETURN
#define NORETURN __attribute__((noreturn))
#endif
/// This will get un-defined by <vapours/results/results_common.hpp>
#define R_SUCCEEDED(res) (res == 0)
#define R_FAILED(res) (res != 0)
/// Flags a function as (always) inline.
#define NX_INLINE __attribute__((always_inline)) static inline
/// Flags a function as constexpr in C++14 and above; or as (always) inline otherwise.
#if __cplusplus >= 201402L
#define NX_CONSTEXPR NX_INLINE constexpr
#else
#define NX_CONSTEXPR NX_INLINE
#endif