2013-01-20 09:13:59 +00:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* Xenia : Xbox 360 Emulator Research Project *
|
|
|
|
******************************************************************************
|
|
|
|
* Copyright 2013 Ben Vanik. All rights reserved. *
|
|
|
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef XENIA_CPU_PROCESSOR_H_
|
|
|
|
#define XENIA_CPU_PROCESSOR_H_
|
|
|
|
|
2015-07-29 07:15:52 +00:00
|
|
|
#include <memory>
|
2015-08-07 03:17:01 +00:00
|
|
|
#include <string>
|
2014-08-16 07:56:50 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2015-05-25 06:16:43 +00:00
|
|
|
#include "xenia/base/mutex.h"
|
2015-05-04 05:28:25 +00:00
|
|
|
#include "xenia/cpu/backend/backend.h"
|
|
|
|
#include "xenia/cpu/entry_table.h"
|
2015-05-02 09:11:11 +00:00
|
|
|
#include "xenia/cpu/export_resolver.h"
|
2015-05-04 05:28:25 +00:00
|
|
|
#include "xenia/cpu/function.h"
|
|
|
|
#include "xenia/cpu/module.h"
|
2015-12-15 05:17:55 +00:00
|
|
|
#include "xenia/cpu/ppc/ppc_frontend.h"
|
2015-05-04 05:28:25 +00:00
|
|
|
#include "xenia/cpu/thread_state.h"
|
2015-02-01 06:49:47 +00:00
|
|
|
#include "xenia/memory.h"
|
2013-06-01 04:22:00 +00:00
|
|
|
|
2015-07-22 07:01:36 +00:00
|
|
|
namespace xe {
|
2015-11-26 03:35:05 +00:00
|
|
|
class Emulator;
|
|
|
|
|
2015-07-22 07:01:36 +00:00
|
|
|
namespace debug {
|
|
|
|
class Debugger;
|
|
|
|
} // namespace debug
|
|
|
|
} // namespace xe
|
|
|
|
|
2013-01-20 09:13:59 +00:00
|
|
|
namespace xe {
|
|
|
|
namespace cpu {
|
|
|
|
|
2015-11-26 03:35:05 +00:00
|
|
|
class Breakpoint;
|
2015-07-29 07:15:52 +00:00
|
|
|
class StackWalker;
|
2015-03-24 15:25:58 +00:00
|
|
|
class ThreadState;
|
2014-08-21 05:50:10 +00:00
|
|
|
class XexModule;
|
2013-01-20 09:13:59 +00:00
|
|
|
|
2014-08-04 22:39:42 +00:00
|
|
|
enum class Irql : uint32_t {
|
|
|
|
PASSIVE = 0,
|
|
|
|
APC = 1,
|
|
|
|
DISPATCH = 2,
|
|
|
|
DPC = 3,
|
|
|
|
};
|
|
|
|
|
2014-07-10 04:21:40 +00:00
|
|
|
class Processor {
|
2014-08-21 05:50:10 +00:00
|
|
|
public:
|
2015-05-24 05:27:43 +00:00
|
|
|
Processor(Memory* memory, ExportResolver* export_resolver,
|
|
|
|
debug::Debugger* debugger);
|
2013-01-20 09:13:59 +00:00
|
|
|
~Processor();
|
|
|
|
|
2013-12-07 06:57:16 +00:00
|
|
|
Memory* memory() const { return memory_; }
|
2015-05-24 05:27:43 +00:00
|
|
|
debug::Debugger* debugger() const { return debugger_; }
|
2015-07-29 07:15:52 +00:00
|
|
|
StackWalker* stack_walker() const { return stack_walker_.get(); }
|
2015-12-15 05:17:55 +00:00
|
|
|
ppc::PPCFrontend* frontend() const { return frontend_.get(); }
|
2015-05-04 05:28:25 +00:00
|
|
|
backend::Backend* backend() const { return backend_.get(); }
|
|
|
|
ExportResolver* export_resolver() const { return export_resolver_; }
|
2013-01-20 09:13:59 +00:00
|
|
|
|
2015-05-06 00:21:08 +00:00
|
|
|
bool Setup();
|
2013-01-20 09:13:59 +00:00
|
|
|
|
2015-06-06 17:59:22 +00:00
|
|
|
void set_debug_info_flags(uint32_t debug_info_flags) {
|
|
|
|
debug_info_flags_ = debug_info_flags;
|
|
|
|
}
|
|
|
|
|
2015-05-06 00:21:08 +00:00
|
|
|
bool AddModule(std::unique_ptr<Module> module);
|
2015-05-04 05:28:25 +00:00
|
|
|
Module* GetModule(const char* name);
|
|
|
|
Module* GetModule(const std::string& name) { return GetModule(name.c_str()); }
|
|
|
|
std::vector<Module*> GetModules();
|
|
|
|
|
|
|
|
Module* builtin_module() const { return builtin_module_; }
|
2015-08-06 04:50:02 +00:00
|
|
|
Function* DefineBuiltin(const std::string& name,
|
|
|
|
BuiltinFunction::Handler handler, void* arg0,
|
|
|
|
void* arg1);
|
2015-05-04 05:28:25 +00:00
|
|
|
|
2015-06-09 06:44:38 +00:00
|
|
|
Function* QueryFunction(uint32_t address);
|
2015-05-04 05:28:25 +00:00
|
|
|
std::vector<Function*> FindFunctionsWithAddress(uint32_t address);
|
|
|
|
|
2015-08-06 04:50:02 +00:00
|
|
|
Function* LookupFunction(uint32_t address);
|
|
|
|
Function* LookupFunction(Module* module, uint32_t address);
|
|
|
|
Function* ResolveFunction(uint32_t address);
|
2015-05-04 05:28:25 +00:00
|
|
|
|
2015-05-06 00:21:08 +00:00
|
|
|
bool Execute(ThreadState* thread_state, uint32_t address);
|
2015-11-28 04:28:21 +00:00
|
|
|
bool ExecuteRaw(ThreadState* thread_state, uint32_t address);
|
2015-03-25 02:41:29 +00:00
|
|
|
uint64_t Execute(ThreadState* thread_state, uint32_t address, uint64_t args[],
|
2015-03-24 15:25:58 +00:00
|
|
|
size_t arg_count);
|
2015-09-01 16:45:14 +00:00
|
|
|
uint64_t ExecuteInterrupt(ThreadState* thread_state, uint32_t address,
|
|
|
|
uint64_t args[], size_t arg_count);
|
2013-09-25 07:46:09 +00:00
|
|
|
|
2014-08-04 22:39:42 +00:00
|
|
|
Irql RaiseIrql(Irql new_value);
|
|
|
|
void LowerIrql(Irql old_value);
|
|
|
|
|
2015-11-26 03:35:05 +00:00
|
|
|
bool InstallBreakpoint(Breakpoint* bp);
|
|
|
|
bool UninstallBreakpoint(Breakpoint* bp);
|
|
|
|
bool BreakpointHit(uint32_t address, uint64_t host_pc);
|
|
|
|
Breakpoint* FindBreakpoint(uint32_t address);
|
|
|
|
std::vector<Breakpoint*> breakpoints() const { return breakpoints_; }
|
|
|
|
|
2014-08-21 05:50:10 +00:00
|
|
|
private:
|
2015-11-26 03:35:05 +00:00
|
|
|
static bool ExceptionCallbackThunk(Exception* ex, void* data);
|
|
|
|
bool ExceptionCallback(Exception* ex);
|
|
|
|
|
2015-08-06 04:50:02 +00:00
|
|
|
bool DemandFunction(Function* function);
|
2013-12-07 06:57:16 +00:00
|
|
|
|
2015-07-16 06:26:58 +00:00
|
|
|
Memory* memory_ = nullptr;
|
|
|
|
debug::Debugger* debugger_ = nullptr;
|
2015-07-29 07:15:52 +00:00
|
|
|
std::unique_ptr<StackWalker> stack_walker_;
|
2013-12-07 06:57:16 +00:00
|
|
|
|
2015-07-16 06:26:58 +00:00
|
|
|
uint32_t debug_info_flags_ = 0;
|
2015-05-04 05:28:25 +00:00
|
|
|
|
2015-12-15 05:17:55 +00:00
|
|
|
std::unique_ptr<ppc::PPCFrontend> frontend_;
|
2015-05-04 05:28:25 +00:00
|
|
|
std::unique_ptr<backend::Backend> backend_;
|
2015-07-16 06:26:58 +00:00
|
|
|
ExportResolver* export_resolver_ = nullptr;
|
2015-05-04 05:28:25 +00:00
|
|
|
|
|
|
|
EntryTable entry_table_;
|
2015-09-06 16:30:54 +00:00
|
|
|
xe::global_critical_region global_critical_region_;
|
2015-05-04 05:28:25 +00:00
|
|
|
std::vector<std::unique_ptr<Module>> modules_;
|
2015-07-16 06:26:58 +00:00
|
|
|
Module* builtin_module_ = nullptr;
|
|
|
|
uint32_t next_builtin_address_ = 0xFFFF0000u;
|
2015-05-04 05:28:25 +00:00
|
|
|
|
2015-11-28 04:28:21 +00:00
|
|
|
std::recursive_mutex breakpoint_lock_;
|
2015-11-26 03:35:05 +00:00
|
|
|
std::vector<Breakpoint*> breakpoints_;
|
|
|
|
|
2014-08-21 05:50:10 +00:00
|
|
|
Irql irql_;
|
2013-01-20 09:13:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace cpu
|
|
|
|
} // namespace xe
|
|
|
|
|
|
|
|
#endif // XENIA_CPU_PROCESSOR_H_
|