~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to Core/HLE/HLEHelperThread.cpp

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2014- PPSSPP Project.
 
2
 
 
3
// This program is free software: you can redistribute it and/or modify
 
4
// it under the terms of the GNU General Public License as published by
 
5
// the Free Software Foundation, version 2.0 or later versions.
 
6
 
 
7
// This program is distributed in the hope that it will be useful,
 
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
// GNU General Public License 2.0 for more details.
 
11
 
 
12
// A copy of the GPL 2.0 should have been included with the program.
 
13
// If not, see http://www.gnu.org/licenses/
 
14
 
 
15
// Official git repository and contact information can be found at
 
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
 
17
 
 
18
#include "Common/ChunkFile.h"
 
19
#include "Core/MemMapHelpers.h"
 
20
#include "Core/HLE/HLE.h"
 
21
#include "Core/HLE/HLEHelperThread.h"
 
22
#include "Core/HLE/sceKernelThread.h"
 
23
#include "Core/HLE/sceKernelMemory.h"
 
24
#include "Core/MIPS/MIPSCodeUtils.h"
 
25
 
 
26
HLEHelperThread::HLEHelperThread() : id_(-1), entry_(0) {
 
27
}
 
28
 
 
29
HLEHelperThread::HLEHelperThread(const char *threadName, u32 instructions[], u32 instrCount, u32 prio, int stacksize) {
 
30
        u32 instrBytes = instrCount * sizeof(u32);
 
31
        u32 totalBytes = instrBytes + sizeof(u32) * 2;
 
32
        AllocEntry(totalBytes);
 
33
        Memory::Memcpy(entry_, instructions, instrBytes);
 
34
 
 
35
        // Just to simplify things, we add the return here.
 
36
        Memory::Write_U32(MIPS_MAKE_JR_RA(), entry_ + instrBytes + 0);
 
37
        Memory::Write_U32(MIPS_MAKE_NOP(), entry_ + instrBytes + 4);
 
38
 
 
39
        Create(threadName, prio, stacksize);
 
40
}
 
41
 
 
42
HLEHelperThread::HLEHelperThread(const char *threadName, const char *module, const char *func, u32 prio, int stacksize) {
 
43
        const u32 bytes = sizeof(u32) * 2;
 
44
        AllocEntry(bytes);
 
45
        Memory::Write_U32(MIPS_MAKE_JR_RA(), entry_ + 0);
 
46
        Memory::Write_U32(MIPS_MAKE_SYSCALL(module, func), entry_ + 4);
 
47
 
 
48
        Create(threadName, prio, stacksize);
 
49
}
 
50
 
 
51
HLEHelperThread::~HLEHelperThread() {
 
52
        __KernelDeleteThread(id_, SCE_KERNEL_ERROR_THREAD_TERMINATED, "helper deleted");
 
53
        kernelMemory.Free(entry_);
 
54
}
 
55
 
 
56
void HLEHelperThread::AllocEntry(u32 size) {
 
57
        entry_ = kernelMemory.Alloc(size);
 
58
        currentMIPS->InvalidateICache(entry_, size);
 
59
}
 
60
 
 
61
void HLEHelperThread::Create(const char *threadName, u32 prio, int stacksize) {
 
62
        id_ = __KernelCreateThreadInternal(threadName, __KernelGetCurThreadModuleId(), entry_, prio, stacksize, 0);
 
63
}
 
64
 
 
65
void HLEHelperThread::DoState(PointerWrap &p) {
 
66
        auto s = p.Section("HLEHelperThread", 1);
 
67
        if (!s) {
 
68
                return;
 
69
        }
 
70
 
 
71
        p.Do(id_);
 
72
        p.Do(entry_);
 
73
}
 
74
 
 
75
void HLEHelperThread::Start(u32 a0, u32 a1) {
 
76
        __KernelStartThread(id_, a0, a1, true);
 
77
}
 
78
 
 
79
void HLEHelperThread::Terminate() {
 
80
        __KernelStopThread(id_, SCE_KERNEL_ERROR_THREAD_TERMINATED, "helper terminated");
 
81
}