2013-10-24 03:42:24 +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. *
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2014-01-05 01:12:46 +00:00
|
|
|
#ifndef XENIA_KERNEL_KERNEL_STATE_H_
|
|
|
|
#define XENIA_KERNEL_KERNEL_STATE_H_
|
2013-10-24 03:42:24 +00:00
|
|
|
|
2015-05-14 23:20:49 +00:00
|
|
|
#include <gflags/gflags.h>
|
|
|
|
|
2014-08-03 21:38:04 +00:00
|
|
|
#include <memory>
|
2014-08-16 07:56:50 +00:00
|
|
|
#include <mutex>
|
2014-08-03 21:38:04 +00:00
|
|
|
|
2015-05-24 21:11:44 +00:00
|
|
|
#include "xenia/base/mutex.h"
|
2015-05-02 09:11:11 +00:00
|
|
|
#include "xenia/cpu/export_resolver.h"
|
2015-02-01 06:49:47 +00:00
|
|
|
#include "xenia/kernel/app.h"
|
2015-02-12 22:16:43 +00:00
|
|
|
#include "xenia/kernel/content_manager.h"
|
2015-02-01 06:49:47 +00:00
|
|
|
#include "xenia/kernel/fs/filesystem.h"
|
|
|
|
#include "xenia/kernel/object_table.h"
|
|
|
|
#include "xenia/kernel/user_profile.h"
|
|
|
|
#include "xenia/memory.h"
|
|
|
|
#include "xenia/xbox.h"
|
2013-10-24 03:42:24 +00:00
|
|
|
|
2014-08-17 02:07:21 +00:00
|
|
|
namespace xe {
|
|
|
|
class Emulator;
|
|
|
|
namespace cpu {
|
|
|
|
class Processor;
|
|
|
|
} // namespace cpu
|
|
|
|
} // namespace xe
|
2013-10-24 03:42:24 +00:00
|
|
|
|
2015-05-14 23:20:49 +00:00
|
|
|
DECLARE_bool(headless);
|
|
|
|
|
2013-10-24 03:42:24 +00:00
|
|
|
namespace xe {
|
|
|
|
namespace kernel {
|
|
|
|
|
2014-08-17 02:07:21 +00:00
|
|
|
class Dispatcher;
|
2015-05-20 05:20:49 +00:00
|
|
|
class XKernelModule;
|
2014-08-17 02:07:21 +00:00
|
|
|
class XModule;
|
|
|
|
class XNotifyListener;
|
|
|
|
class XThread;
|
|
|
|
class XUserModule;
|
2013-10-24 03:42:24 +00:00
|
|
|
|
2015-06-27 18:44:40 +00:00
|
|
|
// (?), used by KeGetCurrentProcessType
|
|
|
|
constexpr uint32_t X_PROCTYPE_IDLE = 0;
|
|
|
|
constexpr uint32_t X_PROCTYPE_USER = 1;
|
|
|
|
constexpr uint32_t X_PROCTYPE_SYSTEM = 2;
|
|
|
|
|
2015-06-05 00:46:00 +00:00
|
|
|
struct ProcessInfoBlock {
|
|
|
|
xe::be<uint32_t> unk_00;
|
|
|
|
xe::be<uint32_t> unk_04; // blink
|
|
|
|
xe::be<uint32_t> unk_08; // flink
|
|
|
|
xe::be<uint32_t> unk_0C;
|
|
|
|
xe::be<uint32_t> unk_10;
|
|
|
|
xe::be<uint32_t> thread_count;
|
|
|
|
xe::be<uint8_t> unk_18;
|
|
|
|
xe::be<uint8_t> unk_19;
|
|
|
|
xe::be<uint8_t> unk_1A;
|
|
|
|
xe::be<uint8_t> unk_1B;
|
|
|
|
xe::be<uint32_t> kernel_stack_size;
|
|
|
|
xe::be<uint32_t> unk_20;
|
|
|
|
xe::be<uint32_t> tls_data_size;
|
|
|
|
xe::be<uint32_t> tls_raw_data_size;
|
|
|
|
xe::be<uint16_t> tls_slot_size;
|
|
|
|
xe::be<uint8_t> unk_2E;
|
|
|
|
xe::be<uint8_t> process_type;
|
|
|
|
xe::be<uint32_t> bitmap[0x20 / 4];
|
|
|
|
xe::be<uint32_t> unk_50;
|
|
|
|
xe::be<uint32_t> unk_54; // blink
|
|
|
|
xe::be<uint32_t> unk_58; // flink
|
|
|
|
xe::be<uint32_t> unk_5C;
|
|
|
|
};
|
|
|
|
|
2013-10-24 03:42:24 +00:00
|
|
|
class KernelState {
|
2014-08-17 02:07:21 +00:00
|
|
|
public:
|
2013-10-24 03:42:24 +00:00
|
|
|
KernelState(Emulator* emulator);
|
|
|
|
~KernelState();
|
|
|
|
|
|
|
|
static KernelState* shared();
|
|
|
|
|
|
|
|
Emulator* emulator() const { return emulator_; }
|
2013-12-07 06:57:16 +00:00
|
|
|
Memory* memory() const { return memory_; }
|
2013-10-24 03:42:24 +00:00
|
|
|
cpu::Processor* processor() const { return processor_; }
|
|
|
|
fs::FileSystem* file_system() const { return file_system_; }
|
2015-05-02 09:11:11 +00:00
|
|
|
|
2015-02-12 22:16:43 +00:00
|
|
|
uint32_t title_id() const;
|
2013-10-24 03:42:24 +00:00
|
|
|
|
2014-01-12 05:40:23 +00:00
|
|
|
Dispatcher* dispatcher() const { return dispatcher_; }
|
|
|
|
|
2014-08-03 21:38:04 +00:00
|
|
|
XAppManager* app_manager() const { return app_manager_.get(); }
|
2014-08-04 04:26:10 +00:00
|
|
|
UserProfile* user_profile() const { return user_profile_.get(); }
|
2015-02-12 22:16:43 +00:00
|
|
|
ContentManager* content_manager() const { return content_manager_.get(); }
|
2014-08-03 21:38:04 +00:00
|
|
|
|
2013-10-24 03:42:24 +00:00
|
|
|
ObjectTable* object_table() const { return object_table_; }
|
2015-05-24 21:11:44 +00:00
|
|
|
xe::recursive_mutex& object_mutex() { return object_mutex_; }
|
2013-10-24 03:42:24 +00:00
|
|
|
|
2015-06-05 00:46:00 +00:00
|
|
|
uint32_t process_type() const;
|
|
|
|
void set_process_type(uint32_t value);
|
|
|
|
uint32_t process_info_block_address() const {
|
|
|
|
return process_info_block_address_;
|
|
|
|
}
|
2014-11-01 18:42:44 +00:00
|
|
|
|
2014-08-15 03:28:44 +00:00
|
|
|
void RegisterModule(XModule* module);
|
|
|
|
void UnregisterModule(XModule* module);
|
2015-05-18 05:40:43 +00:00
|
|
|
bool IsKernelModule(const char* name);
|
2015-05-25 03:44:27 +00:00
|
|
|
object_ref<XModule> GetModule(const char* name);
|
|
|
|
object_ref<XUserModule> GetExecutableModule();
|
|
|
|
void SetExecutableModule(object_ref<XUserModule> module);
|
2015-05-20 05:20:49 +00:00
|
|
|
template <typename T>
|
2015-05-25 03:44:27 +00:00
|
|
|
object_ref<XKernelModule> LoadKernelModule() {
|
|
|
|
auto kernel_module = object_ref<XKernelModule>(new T(emulator_, this));
|
|
|
|
LoadKernelModule(kernel_module);
|
|
|
|
return kernel_module;
|
2015-05-20 05:20:49 +00:00
|
|
|
}
|
2015-05-25 03:44:27 +00:00
|
|
|
object_ref<XUserModule> LoadUserModule(const char* name);
|
2013-10-24 03:42:24 +00:00
|
|
|
|
2014-01-08 04:54:47 +00:00
|
|
|
void RegisterThread(XThread* thread);
|
|
|
|
void UnregisterThread(XThread* thread);
|
2015-05-09 07:56:42 +00:00
|
|
|
void OnThreadExecute(XThread* thread);
|
|
|
|
void OnThreadExit(XThread* thread);
|
2015-05-25 03:50:52 +00:00
|
|
|
object_ref<XThread> GetThreadByID(uint32_t thread_id);
|
2014-01-08 04:54:47 +00:00
|
|
|
|
2014-06-23 02:41:26 +00:00
|
|
|
void RegisterNotifyListener(XNotifyListener* listener);
|
|
|
|
void UnregisterNotifyListener(XNotifyListener* listener);
|
|
|
|
void BroadcastNotification(XNotificationID id, uint32_t data);
|
|
|
|
|
2015-05-14 23:35:29 +00:00
|
|
|
void CompleteOverlapped(uint32_t overlapped_ptr, X_RESULT result);
|
|
|
|
void CompleteOverlappedEx(uint32_t overlapped_ptr, X_RESULT result,
|
|
|
|
uint32_t extended_error, uint32_t length);
|
|
|
|
void CompleteOverlappedImmediate(uint32_t overlapped_ptr, X_RESULT result);
|
|
|
|
void CompleteOverlappedImmediateEx(uint32_t overlapped_ptr, X_RESULT result,
|
|
|
|
uint32_t extended_error, uint32_t length);
|
2014-08-04 04:26:10 +00:00
|
|
|
|
2014-08-17 02:07:21 +00:00
|
|
|
private:
|
2015-05-25 03:44:27 +00:00
|
|
|
void LoadKernelModule(object_ref<XKernelModule> kernel_module);
|
2015-05-20 05:20:49 +00:00
|
|
|
|
2014-08-17 02:07:21 +00:00
|
|
|
Emulator* emulator_;
|
|
|
|
Memory* memory_;
|
2013-10-24 03:42:24 +00:00
|
|
|
cpu::Processor* processor_;
|
|
|
|
fs::FileSystem* file_system_;
|
|
|
|
|
2014-08-17 02:07:21 +00:00
|
|
|
Dispatcher* dispatcher_;
|
2014-01-12 05:40:23 +00:00
|
|
|
|
2014-08-03 21:38:04 +00:00
|
|
|
std::unique_ptr<XAppManager> app_manager_;
|
2014-08-04 04:26:10 +00:00
|
|
|
std::unique_ptr<UserProfile> user_profile_;
|
2015-02-12 22:16:43 +00:00
|
|
|
std::unique_ptr<ContentManager> content_manager_;
|
2014-08-03 21:38:04 +00:00
|
|
|
|
2014-08-17 02:07:21 +00:00
|
|
|
ObjectTable* object_table_;
|
2015-05-24 21:11:44 +00:00
|
|
|
xe::recursive_mutex object_mutex_;
|
2014-01-08 04:54:47 +00:00
|
|
|
std::unordered_map<uint32_t, XThread*> threads_by_id_;
|
2015-05-25 03:50:52 +00:00
|
|
|
std::vector<object_ref<XNotifyListener>> notify_listeners_;
|
2014-10-30 04:09:54 +00:00
|
|
|
bool has_notified_startup_;
|
2013-10-24 03:42:24 +00:00
|
|
|
|
2014-11-01 18:42:44 +00:00
|
|
|
uint32_t process_type_;
|
2015-05-25 03:44:27 +00:00
|
|
|
object_ref<XUserModule> executable_module_;
|
|
|
|
std::vector<object_ref<XKernelModule>> kernel_modules_;
|
|
|
|
std::vector<object_ref<XUserModule>> user_modules_;
|
2015-05-03 22:17:22 +00:00
|
|
|
|
2015-06-05 00:46:00 +00:00
|
|
|
uint32_t process_info_block_address_;
|
|
|
|
|
2013-10-24 03:42:24 +00:00
|
|
|
friend class XObject;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace kernel
|
|
|
|
} // namespace xe
|
|
|
|
|
2014-01-05 01:12:46 +00:00
|
|
|
#endif // XENIA_KERNEL_KERNEL_STATE_H_
|