2014-04-08 19:19:26 -04:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 00:38:14 -05:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-11-19 03:49:13 -05:00
|
|
|
// Refer to the license.txt file included.
|
2014-04-04 22:26:06 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-01-09 16:33:46 -05:00
|
|
|
#include <array>
|
2014-04-08 20:15:08 -04:00
|
|
|
#include "common/common_types.h"
|
2018-09-20 19:28:48 -04:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
enum class VMAPermission : u8;
|
|
|
|
}
|
2014-04-04 22:26:06 -04:00
|
|
|
|
2018-08-24 21:43:32 -04:00
|
|
|
namespace Core {
|
|
|
|
|
2018-09-18 02:49:40 -04:00
|
|
|
/// Generic ARMv8 CPU interface
|
2014-04-27 18:29:51 -04:00
|
|
|
class ARM_Interface : NonCopyable {
|
2014-04-04 22:26:06 -04:00
|
|
|
public:
|
2016-09-18 21:01:46 -04:00
|
|
|
virtual ~ARM_Interface() {}
|
2014-04-04 22:26:06 -04:00
|
|
|
|
2016-12-22 00:08:09 -05:00
|
|
|
struct ThreadContext {
|
2018-01-09 16:33:46 -05:00
|
|
|
std::array<u64, 31> cpu_registers;
|
2017-08-28 21:09:42 -04:00
|
|
|
u64 sp;
|
|
|
|
u64 pc;
|
2018-09-29 17:58:26 -04:00
|
|
|
u32 pstate;
|
|
|
|
std::array<u8, 4> padding;
|
2018-09-18 02:49:40 -04:00
|
|
|
std::array<u128, 32> vector_registers;
|
2018-09-29 17:58:26 -04:00
|
|
|
u32 fpcr;
|
|
|
|
u32 fpsr;
|
|
|
|
u64 tpidr;
|
2016-12-22 00:08:09 -05:00
|
|
|
};
|
2018-09-29 17:58:26 -04:00
|
|
|
// Internally within the kernel, it expects the AArch64 version of the
|
|
|
|
// thread context to be 800 bytes in size.
|
|
|
|
static_assert(sizeof(ThreadContext) == 0x320);
|
2016-12-22 00:08:09 -05:00
|
|
|
|
2018-02-14 12:47:48 -05:00
|
|
|
/// Runs the CPU until an event happens
|
|
|
|
virtual void Run() = 0;
|
2014-05-17 11:59:18 -04:00
|
|
|
|
2014-04-05 15:23:59 -04:00
|
|
|
/// Step CPU by one instruction
|
2018-02-14 12:47:48 -05:00
|
|
|
virtual void Step() = 0;
|
2014-05-17 11:59:18 -04:00
|
|
|
|
2018-03-16 18:22:14 -04:00
|
|
|
/// Maps a backing memory region for the CPU
|
2018-09-15 09:21:06 -04:00
|
|
|
virtual void MapBackingMemory(VAddr address, std::size_t size, u8* memory,
|
2018-03-16 18:22:14 -04:00
|
|
|
Kernel::VMAPermission perms) = 0;
|
|
|
|
|
|
|
|
/// Unmaps a region of memory that was previously mapped using MapBackingMemory
|
2018-09-15 09:21:06 -04:00
|
|
|
virtual void UnmapMemory(VAddr address, std::size_t size) = 0;
|
2017-10-09 23:56:20 -04:00
|
|
|
|
2016-06-27 14:38:49 -04:00
|
|
|
/// Clear all instruction cache
|
|
|
|
virtual void ClearInstructionCache() = 0;
|
|
|
|
|
2017-09-24 17:44:13 -04:00
|
|
|
/// Notify CPU emulation that page tables have changed
|
|
|
|
virtual void PageTableChanged() = 0;
|
|
|
|
|
2014-04-05 15:23:59 -04:00
|
|
|
/**
|
|
|
|
* Set the Program Counter to an address
|
|
|
|
* @param addr Address to set PC to
|
|
|
|
*/
|
2017-08-28 21:09:42 -04:00
|
|
|
virtual void SetPC(u64 addr) = 0;
|
2014-04-05 15:23:59 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the current Program Counter
|
|
|
|
* @return Returns current PC
|
|
|
|
*/
|
2017-08-28 21:09:42 -04:00
|
|
|
virtual u64 GetPC() const = 0;
|
2014-04-05 15:23:59 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an ARM register
|
2017-08-28 21:09:42 -04:00
|
|
|
* @param index Register index
|
2014-04-05 15:23:59 -04:00
|
|
|
* @return Returns the value in the register
|
|
|
|
*/
|
2017-08-28 21:09:42 -04:00
|
|
|
virtual u64 GetReg(int index) const = 0;
|
2014-04-05 15:23:59 -04:00
|
|
|
|
2014-04-10 19:57:56 -04:00
|
|
|
/**
|
|
|
|
* Set an ARM register
|
2017-08-28 21:09:42 -04:00
|
|
|
* @param index Register index
|
2014-04-10 19:57:56 -04:00
|
|
|
* @param value Value to set register to
|
|
|
|
*/
|
2017-08-28 21:09:42 -04:00
|
|
|
virtual void SetReg(int index, u64 value) = 0;
|
2014-04-10 19:57:56 -04:00
|
|
|
|
2015-08-06 21:24:25 -04:00
|
|
|
/**
|
2018-09-18 02:49:40 -04:00
|
|
|
* Gets the value of a specified vector register.
|
|
|
|
*
|
|
|
|
* @param index The index of the vector register.
|
|
|
|
* @return the value within the vector register.
|
2015-08-06 21:24:25 -04:00
|
|
|
*/
|
2018-09-18 02:49:40 -04:00
|
|
|
virtual u128 GetVectorReg(int index) const = 0;
|
2015-08-06 21:24:25 -04:00
|
|
|
|
|
|
|
/**
|
2018-09-18 02:49:40 -04:00
|
|
|
* Sets a given value into a vector register.
|
|
|
|
*
|
|
|
|
* @param index The index of the vector register.
|
|
|
|
* @param value The new value to place in the register.
|
2015-08-06 21:24:25 -04:00
|
|
|
*/
|
2018-09-18 02:49:40 -04:00
|
|
|
virtual void SetVectorReg(int index, u128 value) = 0;
|
2015-08-06 21:24:25 -04:00
|
|
|
|
2014-04-05 15:23:59 -04:00
|
|
|
/**
|
2018-09-18 02:49:40 -04:00
|
|
|
* Get the current PSTATE register
|
|
|
|
* @return Returns the value of the PSTATE register
|
2014-04-05 15:23:59 -04:00
|
|
|
*/
|
2018-09-18 02:49:40 -04:00
|
|
|
virtual u32 GetPSTATE() const = 0;
|
2014-04-05 01:23:28 -04:00
|
|
|
|
2014-05-11 22:14:13 -04:00
|
|
|
/**
|
2018-09-18 02:49:40 -04:00
|
|
|
* Set the current PSTATE register
|
|
|
|
* @param pstate Value to set PSTATE to
|
2014-05-11 22:14:13 -04:00
|
|
|
*/
|
2018-09-18 02:49:40 -04:00
|
|
|
virtual void SetPSTATE(u32 pstate) = 0;
|
2014-05-11 22:14:13 -04:00
|
|
|
|
2017-09-30 14:16:39 -04:00
|
|
|
virtual VAddr GetTlsAddress() const = 0;
|
|
|
|
|
|
|
|
virtual void SetTlsAddress(VAddr address) = 0;
|
|
|
|
|
2018-09-18 02:49:40 -04:00
|
|
|
/**
|
|
|
|
* Gets the value within the TPIDR_EL0 (read/write software thread ID) register.
|
|
|
|
*
|
|
|
|
* @return the value within the register.
|
|
|
|
*/
|
2018-07-20 20:57:45 -04:00
|
|
|
virtual u64 GetTPIDR_EL0() const = 0;
|
|
|
|
|
2018-09-18 02:49:40 -04:00
|
|
|
/**
|
|
|
|
* Sets a new value within the TPIDR_EL0 (read/write software thread ID) register.
|
|
|
|
*
|
|
|
|
* @param value The new value to place in the register.
|
|
|
|
*/
|
2018-07-20 20:57:45 -04:00
|
|
|
virtual void SetTPIDR_EL0(u64 value) = 0;
|
|
|
|
|
2014-05-20 18:50:16 -04:00
|
|
|
/**
|
|
|
|
* Saves the current CPU context
|
|
|
|
* @param ctx Thread context to save
|
|
|
|
*/
|
2016-12-22 00:08:09 -05:00
|
|
|
virtual void SaveContext(ThreadContext& ctx) = 0;
|
2014-05-20 18:50:16 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads a CPU context
|
|
|
|
* @param ctx Thread context to load
|
|
|
|
*/
|
2016-12-22 00:08:09 -05:00
|
|
|
virtual void LoadContext(const ThreadContext& ctx) = 0;
|
2014-05-20 18:50:16 -04:00
|
|
|
|
2018-09-18 02:49:40 -04:00
|
|
|
/// Clears the exclusive monitor's state.
|
2018-07-16 06:24:00 -04:00
|
|
|
virtual void ClearExclusiveState() = 0;
|
|
|
|
|
2014-06-01 21:40:10 -04:00
|
|
|
/// Prepare core for thread reschedule (if needed to correctly handle state)
|
|
|
|
virtual void PrepareReschedule() = 0;
|
2018-12-03 04:13:48 -05:00
|
|
|
|
2018-12-28 20:55:19 -05:00
|
|
|
/// fp (= r29) points to the last frame record.
|
|
|
|
/// Note that this is the frame record for the *previous* frame, not the current one.
|
|
|
|
/// Note we need to subtract 4 from our last read to get the proper address
|
|
|
|
/// Frame records are two words long:
|
|
|
|
/// fp+0 : pointer to previous frame record
|
|
|
|
/// fp+8 : value of lr for frame
|
2018-12-30 20:44:46 -05:00
|
|
|
void LogBacktrace() const;
|
2014-04-04 22:26:06 -04:00
|
|
|
};
|
2018-08-24 21:43:32 -04:00
|
|
|
|
|
|
|
} // namespace Core
|