MCPcopy Create free account
hub / github.com/RPCSX/rpcsx / sys_initialize_tls

Function sys_initialize_tls

ps3fw/sys_ppu_thread_.cpp:70–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70void sys_initialize_tls(ppu_thread& ppu, u64 main_thread_id, u32 tls_seg_addr, u32 tls_seg_size, u32 tls_mem_size)
71{
72 sysPrxForUser.notice("sys_initialize_tls(thread_id=0x%llx, addr=*0x%x, size=0x%x, mem_size=0x%x)", main_thread_id, tls_seg_addr, tls_seg_size, tls_mem_size);
73
74 // Uninitialized TLS expected.
75 if (ppu.gpr[13] != 0)
76 return;
77
78 // Initialize TLS memory
79 s_tls_addr = tls_seg_addr;
80 s_tls_file = tls_seg_size;
81 s_tls_zero = tls_mem_size - tls_seg_size;
82 s_tls_size = tls_mem_size + 0x30; // 0x30 is system area size
83 s_tls_area = vm::alloc(0x40000, vm::main) + 0x30;
84 s_tls_max = (0x40000 - 0x30) / s_tls_size;
85 s_tls_map = std::make_unique<atomic_t<bool>[]>(s_tls_max);
86
87 // Allocate TLS for main thread
88 ppu.gpr[13] = ppu_alloc_tls() + 0x7000 + 0x30;
89
90 sysPrxForUser.notice("TLS initialized (addr=0x%x, size=0x%x, max=0x%x)", s_tls_area - 0x30, s_tls_size, s_tls_max);
91
92 // TODO
93 g_spu_printf_agcb = vm::null;
94 g_spu_printf_dgcb = vm::null;
95 g_spu_printf_atcb = vm::null;
96 g_spu_printf_dtcb = vm::null;
97
98 vm::var<sys_lwmutex_attribute_t> lwa;
99 lwa->protocol = SYS_SYNC_PRIORITY;
100 lwa->recursive = SYS_SYNC_RECURSIVE;
101 lwa->name_u64 = "atexit!\0"_u64;
102 sys_lwmutex_create(ppu, g_ppu_atexit_lwm, lwa);
103
104 vm::var<sys_mutex_attribute_t> attr;
105 attr->protocol = SYS_SYNC_PRIORITY;
106 attr->recursive = SYS_SYNC_NOT_RECURSIVE;
107 attr->pshared = SYS_SYNC_NOT_PROCESS_SHARED;
108 attr->adaptive = SYS_SYNC_NOT_ADAPTIVE;
109 attr->ipc_key = 0;
110 attr->flags = 0;
111 attr->name_u64 = "_lv2ppu\0"_u64;
112 sys_mutex_create(ppu, g_ppu_once_mutex, attr);
113
114 attr->recursive = SYS_SYNC_RECURSIVE;
115 attr->name_u64 = "_lv2tls\0"_u64;
116 sys_mutex_create(ppu, g_ppu_exit_mutex, attr);
117
118 lwa->protocol = SYS_SYNC_PRIORITY;
119 lwa->recursive = SYS_SYNC_RECURSIVE;
120 lwa->name_u64 = "_lv2prx\0"_u64;
121 sys_lwmutex_create(ppu, g_ppu_prx_lwm, lwa);
122 // TODO: missing prx initialization
123}
124
125error_code sys_ppu_thread_create(ppu_thread& ppu, vm::ptr<u64> thread_id, u32 entry, u64 arg, s32 prio, u32 stacksize, u64 flags, vm::cptr<char> threadname)
126{

Callers

nothing calls this directly

Calls 4

allocFunction · 0.85
ppu_alloc_tlsFunction · 0.85
sys_lwmutex_createFunction · 0.85
sys_mutex_createFunction · 0.85

Tested by

no test coverage detected