hle.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. ////////////////////////////////////////////////////////////////////////////////////////////////////
  10. namespace HLE {
  11. static std::vector<ModuleDef> g_module_db;
  12. bool g_reschedule = false; ///< If true, immediately reschedules the CPU to a new thread
  13. const FunctionDef* GetSVCInfo(u32 opcode) {
  14. u32 func_num = opcode & 0xFFFFFF; // 8 bits
  15. if (func_num > 0xFF) {
  16. ERROR_LOG(HLE,"unknown svc=0x%02X", func_num);
  17. return nullptr;
  18. }
  19. return &g_module_db[0].func_table[func_num];
  20. }
  21. void CallSVC(u32 opcode) {
  22. const FunctionDef *info = GetSVCInfo(opcode);
  23. if (!info) {
  24. return;
  25. }
  26. if (info->func) {
  27. info->func();
  28. } else {
  29. ERROR_LOG(HLE, "unimplemented SVC function %s(..)", info->name.c_str());
  30. }
  31. }
  32. void Reschedule(const char *reason) {
  33. #ifdef _DEBUG
  34. _dbg_assert_msg_(HLE, reason != 0 && strlen(reason) < 256, "Reschedule: Invalid or too long reason.");
  35. #endif
  36. Core::g_app_core->PrepareReschedule();
  37. g_reschedule = true;
  38. }
  39. void RegisterModule(std::string name, int num_functions, const FunctionDef* func_table) {
  40. ModuleDef module = {name, num_functions, func_table};
  41. g_module_db.push_back(module);
  42. }
  43. void RegisterAllModules() {
  44. SVC::Register();
  45. }
  46. void Init() {
  47. Service::Init();
  48. RegisterAllModules();
  49. NOTICE_LOG(HLE, "initialized OK");
  50. }
  51. void Shutdown() {
  52. Service::Shutdown();
  53. g_module_db.clear();
  54. NOTICE_LOG(HLE, "shutdown OK");
  55. }
  56. } // namespace