mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-11-03 23:28:48 +00:00 
			
		
		
		
	Added CPU, mutex, process, thread, timer
This commit is contained in:
		
							parent
							
								
									06891d9454
								
							
						
					
					
						commit
						f557d26b40
					
				
					 20 changed files with 299 additions and 41 deletions
				
			
		| 
						 | 
				
			
			@ -9,6 +9,7 @@
 | 
			
		|||
// bootrom. Because we're not emulating this, and essentially just "stubbing" the functionality, I'm
 | 
			
		||||
// putting this as a subset of HLE for now.
 | 
			
		||||
 | 
			
		||||
#include <boost/serialization/binary_object.hpp>
 | 
			
		||||
#include "common/common_funcs.h"
 | 
			
		||||
#include "common/common_types.h"
 | 
			
		||||
#include "common/swap.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -56,6 +57,14 @@ public:
 | 
			
		|||
 | 
			
		||||
private:
 | 
			
		||||
    ConfigMemDef config_mem;
 | 
			
		||||
 | 
			
		||||
    friend class boost::serialization::access;
 | 
			
		||||
    template <class Archive>
 | 
			
		||||
    void serialize(Archive& ar, const unsigned int file_version)
 | 
			
		||||
    {
 | 
			
		||||
        auto o_config_mem = boost::serialization::binary_object(&config_mem, sizeof(config_mem));
 | 
			
		||||
        ar & o_config_mem;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} // namespace ConfigMem
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -109,17 +109,17 @@ template <class Archive>
 | 
			
		|||
void KernelSystem::serialize(Archive& ar, const unsigned int file_version)
 | 
			
		||||
{
 | 
			
		||||
    ar & named_ports;
 | 
			
		||||
    // TODO: CPU
 | 
			
		||||
    ar & *current_cpu.get();
 | 
			
		||||
    // NB: subsystem references and prepare_reschedule_callback are constant
 | 
			
		||||
    ar & *resource_limits.get();
 | 
			
		||||
    ar & next_object_id;
 | 
			
		||||
    //ar & *timer_manager.get();
 | 
			
		||||
    ar & *timer_manager.get();
 | 
			
		||||
    ar & next_process_id;
 | 
			
		||||
    ar & process_list;
 | 
			
		||||
    ar & current_process;
 | 
			
		||||
    // ar & *thread_manager.get();
 | 
			
		||||
    //ar & *config_mem_handler.get();
 | 
			
		||||
    //ar & *shared_page_handler.get();
 | 
			
		||||
    ar & *thread_manager.get();
 | 
			
		||||
    ar & *config_mem_handler.get();
 | 
			
		||||
    ar & *shared_page_handler.get();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SERIALIZE_IMPL(KernelSystem)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,11 +23,12 @@ void ReleaseThreadMutexes(Thread* thread) {
 | 
			
		|||
    thread->held_mutexes.clear();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Mutex::Mutex(KernelSystem& kernel) : WaitObject(kernel), kernel(kernel) {}
 | 
			
		||||
Mutex::Mutex() : kernel(*g_kernel) {}
 | 
			
		||||
Mutex::~Mutex() {}
 | 
			
		||||
 | 
			
		||||
std::shared_ptr<Mutex> KernelSystem::CreateMutex(bool initial_locked, std::string name) {
 | 
			
		||||
    auto mutex{std::make_shared<Mutex>(*this)};
 | 
			
		||||
    auto mutex{std::make_shared<Mutex>()};
 | 
			
		||||
    mutex->Init(*this);
 | 
			
		||||
 | 
			
		||||
    mutex->lock_count = 0;
 | 
			
		||||
    mutex->name = std::move(name);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,7 +17,7 @@ class Thread;
 | 
			
		|||
 | 
			
		||||
class Mutex final : public WaitObject {
 | 
			
		||||
public:
 | 
			
		||||
    explicit Mutex(KernelSystem& kernel);
 | 
			
		||||
    explicit Mutex();
 | 
			
		||||
    ~Mutex() override;
 | 
			
		||||
 | 
			
		||||
    std::string GetTypeName() const override {
 | 
			
		||||
| 
						 | 
				
			
			@ -68,7 +68,6 @@ private:
 | 
			
		|||
        ar & priority;
 | 
			
		||||
        ar & name;
 | 
			
		||||
        ar & holding_thread;
 | 
			
		||||
        ar & kernel; // TODO: Check that this works!
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,9 +4,13 @@
 | 
			
		|||
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <boost/serialization/array.hpp>
 | 
			
		||||
#include <boost/serialization/bitset.hpp>
 | 
			
		||||
#include "common/archives.h"
 | 
			
		||||
#include "common/assert.h"
 | 
			
		||||
#include "common/common_funcs.h"
 | 
			
		||||
#include "common/logging/log.h"
 | 
			
		||||
#include "common/serialization/boost_vector.hpp"
 | 
			
		||||
#include "core/hle/kernel/errors.h"
 | 
			
		||||
#include "core/hle/kernel/memory.h"
 | 
			
		||||
#include "core/hle/kernel/process.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -17,6 +21,28 @@
 | 
			
		|||
 | 
			
		||||
namespace Kernel {
 | 
			
		||||
 | 
			
		||||
template <class Archive>
 | 
			
		||||
void Process::serialize(Archive& ar, const unsigned int file_version)
 | 
			
		||||
{
 | 
			
		||||
    ar & boost::serialization::base_object<Object>(*this);
 | 
			
		||||
    ar & handle_table;
 | 
			
		||||
    ar & codeset;
 | 
			
		||||
    ar & resource_limit;
 | 
			
		||||
    ar & svc_access_mask;
 | 
			
		||||
    ar & handle_table_size;
 | 
			
		||||
    ar & (boost::container::vector<AddressMapping, boost::container::dtl::static_storage_allocator<AddressMapping, 8> >&)address_mappings;
 | 
			
		||||
    ar & flags.raw;
 | 
			
		||||
    ar & kernel_version;
 | 
			
		||||
    ar & ideal_processor;
 | 
			
		||||
    ar & process_id;
 | 
			
		||||
    ar & vm_manager;
 | 
			
		||||
    ar & memory_used;
 | 
			
		||||
    ar & memory_region;
 | 
			
		||||
    ar & tls_slots;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SERIALIZE_IMPL(Process)
 | 
			
		||||
 | 
			
		||||
std::shared_ptr<CodeSet> KernelSystem::CreateCodeSet(std::string name, u64 program_id) {
 | 
			
		||||
    auto codeset{std::make_shared<CodeSet>()};
 | 
			
		||||
    codeset->Init(*this);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,13 +11,10 @@
 | 
			
		|||
#include <string>
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <boost/container/static_vector.hpp>
 | 
			
		||||
#include <boost/serialization/array.hpp>
 | 
			
		||||
#include <boost/serialization/bitset.hpp>
 | 
			
		||||
#include <boost/serialization/base_object.hpp>
 | 
			
		||||
#include <boost/serialization/vector.hpp>
 | 
			
		||||
#include <boost/serialization/base_object.hpp>
 | 
			
		||||
#include "common/bit_field.h"
 | 
			
		||||
#include "common/common_types.h"
 | 
			
		||||
#include "common/serialization/boost_vector.hpp"
 | 
			
		||||
#include "core/hle/kernel/handle_table.h"
 | 
			
		||||
#include "core/hle/kernel/object.h"
 | 
			
		||||
#include "core/hle/kernel/vm_manager.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -234,23 +231,6 @@ private:
 | 
			
		|||
 | 
			
		||||
    friend class boost::serialization::access;
 | 
			
		||||
    template <class Archive>
 | 
			
		||||
    void serialize(Archive& ar, const unsigned int file_version)
 | 
			
		||||
    {
 | 
			
		||||
        ar & boost::serialization::base_object<Object>(*this);
 | 
			
		||||
        ar & handle_table;
 | 
			
		||||
        ar & codeset;
 | 
			
		||||
        ar & resource_limit;
 | 
			
		||||
        ar & svc_access_mask;
 | 
			
		||||
        ar & handle_table_size;
 | 
			
		||||
        ar & (boost::container::vector<AddressMapping, boost::container::dtl::static_storage_allocator<AddressMapping, 8> >&)address_mappings;
 | 
			
		||||
        ar & flags.raw;
 | 
			
		||||
        ar & kernel_version;
 | 
			
		||||
        ar & ideal_processor;
 | 
			
		||||
        ar & process_id;
 | 
			
		||||
        ar & vm_manager;
 | 
			
		||||
        ar & memory_used;
 | 
			
		||||
        ar & memory_region;
 | 
			
		||||
        ar & tls_slots;
 | 
			
		||||
    }
 | 
			
		||||
    void serialize(Archive& ar, const unsigned int file_version);
 | 
			
		||||
};
 | 
			
		||||
} // namespace Kernel
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,6 +13,7 @@
 | 
			
		|||
#include <chrono>
 | 
			
		||||
#include <ctime>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <boost/serialization/binary_object.hpp>
 | 
			
		||||
#include "common/bit_field.h"
 | 
			
		||||
#include "common/common_funcs.h"
 | 
			
		||||
#include "common/common_types.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -104,6 +105,14 @@ private:
 | 
			
		|||
    std::chrono::seconds init_time;
 | 
			
		||||
 | 
			
		||||
    SharedPageDef shared_page;
 | 
			
		||||
 | 
			
		||||
    friend class boost::serialization::access;
 | 
			
		||||
    template <class Archive>
 | 
			
		||||
    void serialize(Archive& ar, const unsigned int file_version)
 | 
			
		||||
    {
 | 
			
		||||
        auto o_shared_page = boost::serialization::binary_object(&shared_page, sizeof(shared_page));
 | 
			
		||||
        ar & o_shared_page;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} // namespace SharedPage
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,10 +6,12 @@
 | 
			
		|||
#include <list>
 | 
			
		||||
#include <unordered_map>
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include "common/archives.h"
 | 
			
		||||
#include "common/assert.h"
 | 
			
		||||
#include "common/common_types.h"
 | 
			
		||||
#include "common/logging/log.h"
 | 
			
		||||
#include "common/math_util.h"
 | 
			
		||||
#include "common/serialization/boost_flat_set.h"
 | 
			
		||||
#include "core/arm/arm_interface.h"
 | 
			
		||||
#include "core/arm/skyeye_common/armstate.h"
 | 
			
		||||
#include "core/core.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -25,6 +27,30 @@
 | 
			
		|||
 | 
			
		||||
namespace Kernel {
 | 
			
		||||
 | 
			
		||||
template <class Archive>
 | 
			
		||||
void Thread::serialize(Archive& ar, const unsigned int file_version)
 | 
			
		||||
{
 | 
			
		||||
    ar & *context.get();
 | 
			
		||||
    ar & thread_id;
 | 
			
		||||
    ar & status;
 | 
			
		||||
    ar & entry_point;
 | 
			
		||||
    ar & stack_top;
 | 
			
		||||
    ar & nominal_priority;
 | 
			
		||||
    ar & current_priority;
 | 
			
		||||
    ar & last_running_ticks;
 | 
			
		||||
    ar & processor_id;
 | 
			
		||||
    ar & tls_address;
 | 
			
		||||
    ar & held_mutexes;
 | 
			
		||||
    ar & pending_mutexes;
 | 
			
		||||
    ar & owner_process;
 | 
			
		||||
    ar & wait_objects;
 | 
			
		||||
    ar & wait_address;
 | 
			
		||||
    ar & name;
 | 
			
		||||
    // TODO: How the hell to do wakeup_callback
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SERIALIZE_IMPL(Thread)
 | 
			
		||||
 | 
			
		||||
bool Thread::ShouldWait(const Thread* thread) const {
 | 
			
		||||
    return status != ThreadStatus::Dead;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,6 +9,9 @@
 | 
			
		|||
#include <unordered_map>
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <boost/container/flat_set.hpp>
 | 
			
		||||
#include <boost/serialization/shared_ptr.hpp>
 | 
			
		||||
#include <boost/serialization/unordered_map.hpp>
 | 
			
		||||
#include <boost/serialization/vector.hpp>
 | 
			
		||||
#include "common/common_types.h"
 | 
			
		||||
#include "common/thread_queue_list.h"
 | 
			
		||||
#include "core/arm/arm_interface.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -145,6 +148,17 @@ private:
 | 
			
		|||
 | 
			
		||||
    friend class Thread;
 | 
			
		||||
    friend class KernelSystem;
 | 
			
		||||
 | 
			
		||||
    friend class boost::serialization::access;
 | 
			
		||||
    template <class Archive>
 | 
			
		||||
    void serialize(Archive& ar, const unsigned int file_version)
 | 
			
		||||
    {
 | 
			
		||||
        ar & next_thread_id;
 | 
			
		||||
        ar & current_thread;
 | 
			
		||||
        ar & ready_queue;
 | 
			
		||||
        ar & wakeup_callback_table;
 | 
			
		||||
        ar & thread_list;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Thread final : public WaitObject {
 | 
			
		||||
| 
						 | 
				
			
			@ -305,6 +319,10 @@ public:
 | 
			
		|||
 | 
			
		||||
private:
 | 
			
		||||
    ThreadManager& thread_manager;
 | 
			
		||||
 | 
			
		||||
    friend class boost::serialization::access;
 | 
			
		||||
    template <class Archive>
 | 
			
		||||
    void serialize(Archive& ar, const unsigned int file_version);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,15 +14,15 @@
 | 
			
		|||
 | 
			
		||||
namespace Kernel {
 | 
			
		||||
 | 
			
		||||
Timer::Timer(KernelSystem& kernel)
 | 
			
		||||
    : WaitObject(kernel), kernel(kernel), timer_manager(kernel.GetTimerManager()) {}
 | 
			
		||||
Timer::Timer() : kernel(*g_kernel), timer_manager(g_kernel->GetTimerManager()) {}
 | 
			
		||||
Timer::~Timer() {
 | 
			
		||||
    Cancel();
 | 
			
		||||
    timer_manager.timer_callback_table.erase(callback_id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::shared_ptr<Timer> KernelSystem::CreateTimer(ResetType reset_type, std::string name) {
 | 
			
		||||
    auto timer{std::make_shared<Timer>(*this)};
 | 
			
		||||
    auto timer{std::make_shared<Timer>()};
 | 
			
		||||
    timer->Init(*this);
 | 
			
		||||
 | 
			
		||||
    timer->reset_type = reset_type;
 | 
			
		||||
    timer->signaled = false;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,7 @@
 | 
			
		|||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <boost/serialization/unordered_map.hpp>
 | 
			
		||||
#include "common/common_types.h"
 | 
			
		||||
#include "core/core_timing.h"
 | 
			
		||||
#include "core/hle/kernel/object.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -33,11 +34,19 @@ private:
 | 
			
		|||
 | 
			
		||||
    friend class Timer;
 | 
			
		||||
    friend class KernelSystem;
 | 
			
		||||
 | 
			
		||||
    friend class boost::serialization::access;
 | 
			
		||||
    template <class Archive>
 | 
			
		||||
    void serialize(Archive& ar, const unsigned int file_version)
 | 
			
		||||
    {
 | 
			
		||||
        ar & next_timer_callback_id;
 | 
			
		||||
        ar & timer_callback_table;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class Timer final : public WaitObject {
 | 
			
		||||
public:
 | 
			
		||||
    explicit Timer(KernelSystem& kernel);
 | 
			
		||||
    explicit Timer();
 | 
			
		||||
    ~Timer() override;
 | 
			
		||||
 | 
			
		||||
    std::string GetTypeName() const override {
 | 
			
		||||
| 
						 | 
				
			
			@ -103,6 +112,18 @@ private:
 | 
			
		|||
    TimerManager& timer_manager;
 | 
			
		||||
 | 
			
		||||
    friend class KernelSystem;
 | 
			
		||||
 | 
			
		||||
    friend class boost::serialization::access;
 | 
			
		||||
    template <class Archive>
 | 
			
		||||
    void serialize(Archive& ar, const unsigned int file_version)
 | 
			
		||||
    {
 | 
			
		||||
        ar & reset_type;
 | 
			
		||||
        ar & initial_delay;
 | 
			
		||||
        ar & interval_delay;
 | 
			
		||||
        ar & signaled;
 | 
			
		||||
        ar & name;
 | 
			
		||||
        ar & callback_id;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} // namespace Kernel
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue