hle.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #include <vector>
  5. #include "core/mem_map.h"
  6. #include "core/hle/hle.h"
  7. #include "core/hle/kernel/thread.h"
  8. #include "core/hle/service/service.h"
  9. #include "core/hle/service/fs/archive.h"
  10. ////////////////////////////////////////////////////////////////////////////////////////////////////
  11. namespace HLE {
  12. static std::vector<ModuleDef> g_module_db;
  13. bool g_reschedule = false; ///< If true, immediately reschedules the CPU to a new thread
  14. const FunctionDef* GetSVCInfo(u32 opcode) {
  15. u32 func_num = opcode & 0xFFFFFF; // 8 bits
  16. if (func_num > 0xFF) {
  17. LOG_ERROR(Kernel_SVC,"unknown svc=0x%02X", func_num);
  18. return nullptr;
  19. }
  20. return &g_module_db[0].func_table[func_num];
  21. }
  22. void CallSVC(u32 opcode) {
  23. const FunctionDef *info = GetSVCInfo(opcode);
  24. if (!info) {
  25. return;
  26. }
  27. if (info->func) {
  28. info->func();
  29. } else {
  30. LOG_ERROR(Kernel_SVC, "unimplemented SVC function %s(..)", info->name.c_str());
  31. }
  32. }
  33. void Reschedule(const char *reason) {
  34. _dbg_assert_msg_(Kernel, reason != 0 && strlen(reason) < 256, "Reschedule: Invalid or too long reason.");
  35. Core::g_app_core->PrepareReschedule();
  36. g_reschedule = true;
  37. }
  38. void RegisterModule(std::string name, int num_functions, const FunctionDef* func_table) {
  39. ModuleDef module = {name, num_functions, func_table};
  40. g_module_db.push_back(module);
  41. }
  42. void RegisterAllModules() {
  43. SVC::Register();
  44. }
  45. void Init() {
  46. Service::Init();
  47. Service::FS::ArchiveInit();
  48. RegisterAllModules();
  49. LOG_DEBUG(Kernel, "initialized OK");
  50. }
  51. void Shutdown() {
  52. Service::FS::ArchiveShutdown();
  53. Service::Shutdown();
  54. g_module_db.clear();
  55. LOG_DEBUG(Kernel, "shutdown OK");
  56. }
  57. } // namespace