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_
|
|
|
|
|
2014-08-16 07:56:50 +00:00
|
|
|
#include <mutex>
|
|
|
|
#include <vector>
|
|
|
|
|
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/frontend/ppc_frontend.h"
|
|
|
|
#include "xenia/cpu/function.h"
|
|
|
|
#include "xenia/cpu/module.h"
|
|
|
|
#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-05-05 03:57:46 +00:00
|
|
|
namespace xe {
|
|
|
|
namespace debug {
|
|
|
|
class Debugger;
|
|
|
|
} // namespace debug
|
|
|
|
} // namespace xe
|
|
|
|
|
2013-01-20 09:13:59 +00:00
|
|
|
namespace xe {
|
|
|
|
namespace cpu {
|
|
|
|
|
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:
|
2014-09-10 03:25:38 +00:00
|
|
|
Processor(Memory* memory, ExportResolver* export_resolver);
|
2013-01-20 09:13:59 +00:00
|
|
|
~Processor();
|
|
|
|
|
2013-12-07 06:57:16 +00:00
|
|
|
Memory* memory() const { return memory_; }
|
2015-05-05 03:57:46 +00:00
|
|
|
debug::Debugger* debugger() const { return debugger_.get(); }
|
2015-05-04 05:28:25 +00:00
|
|
|
frontend::PPCFrontend* frontend() const { return frontend_.get(); }
|
|
|
|
backend::Backend* backend() const { return backend_.get(); }
|
|
|
|
ExportResolver* export_resolver() const { return export_resolver_; }
|
2013-01-20 09:13:59 +00:00
|
|
|
|
|
|
|
int Setup();
|
|
|
|
|
2015-05-04 05:28:25 +00:00
|
|
|
int AddModule(std::unique_ptr<Module> module);
|
|
|
|
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_; }
|
|
|
|
FunctionInfo* DefineBuiltin(const std::string& name,
|
|
|
|
FunctionInfo::ExternHandler handler, void* arg0,
|
|
|
|
void* arg1);
|
|
|
|
|
|
|
|
std::vector<Function*> FindFunctionsWithAddress(uint32_t address);
|
|
|
|
|
|
|
|
int LookupFunctionInfo(uint32_t address, FunctionInfo** out_symbol_info);
|
|
|
|
int LookupFunctionInfo(Module* module, uint32_t address,
|
|
|
|
FunctionInfo** out_symbol_info);
|
|
|
|
int ResolveFunction(uint32_t address, Function** out_function);
|
|
|
|
|
2015-03-25 02:41:29 +00:00
|
|
|
int Execute(ThreadState* thread_state, uint32_t address);
|
|
|
|
uint64_t Execute(ThreadState* thread_state, uint32_t address, uint64_t args[],
|
2015-03-24 15:25:58 +00:00
|
|
|
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-03-25 02:41:29 +00:00
|
|
|
uint64_t ExecuteInterrupt(uint32_t cpu, uint32_t address, uint64_t args[],
|
2014-08-21 05:50:10 +00:00
|
|
|
size_t arg_count);
|
2013-01-28 01:49:32 +00:00
|
|
|
|
2014-08-21 05:50:10 +00:00
|
|
|
private:
|
2015-05-04 05:28:25 +00:00
|
|
|
int DemandFunction(FunctionInfo* symbol_info, Function** out_function);
|
2013-12-07 06:57:16 +00:00
|
|
|
|
2014-08-21 05:50:10 +00:00
|
|
|
Memory* memory_;
|
2013-12-07 06:57:16 +00:00
|
|
|
|
2015-05-04 05:28:25 +00:00
|
|
|
uint32_t debug_info_flags_;
|
|
|
|
uint32_t trace_flags_;
|
|
|
|
|
2015-05-05 03:57:46 +00:00
|
|
|
std::unique_ptr<debug::Debugger> debugger_;
|
2015-05-04 05:28:25 +00:00
|
|
|
|
|
|
|
std::unique_ptr<frontend::PPCFrontend> frontend_;
|
|
|
|
std::unique_ptr<backend::Backend> backend_;
|
|
|
|
ExportResolver* export_resolver_;
|
|
|
|
|
|
|
|
EntryTable entry_table_;
|
|
|
|
std::mutex modules_lock_;
|
|
|
|
std::vector<std::unique_ptr<Module>> modules_;
|
|
|
|
Module* builtin_module_;
|
|
|
|
uint32_t next_builtin_address_;
|
|
|
|
|
2014-08-21 05:50:10 +00:00
|
|
|
Irql irql_;
|
|
|
|
std::mutex interrupt_thread_lock_;
|
2015-03-24 15:25:58 +00:00
|
|
|
ThreadState* interrupt_thread_state_;
|
2015-03-25 02:41:29 +00:00
|
|
|
uint32_t interrupt_thread_block_;
|
2013-01-20 09:13:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace cpu
|
|
|
|
} // namespace xe
|
|
|
|
|
|
|
|
#endif // XENIA_CPU_PROCESSOR_H_
|