diff --git a/fpPS4.lpr b/fpPS4.lpr index af0cacf1..6e3f253d 100644 --- a/fpPS4.lpr +++ b/fpPS4.lpr @@ -339,7 +339,7 @@ begin //RTYPE = 7, //R_X86_64_JUMP_SLOT //SBIND = 2, //STB_WEAK //STYPE = 0} //STT_NOTYPE - Writeln('Warn^:',Info^.lib^.strName,':',ps4libdoc.GetFunctName(Info^.Nid),':',HexStr(Info^.Nid,16)); + Writeln(StdErr,'Warn^:',Info^.lib^.strName,':',ps4libdoc.GetFunctName(Info^.Nid),':',HexStr(Info^.Nid,16)); end; end; @@ -541,6 +541,9 @@ begin //ps4_app.app_path:='C:\Users\User\Desktop\Games\JETPACKJOYRIDE\CUSA03633\'; //ps4_app.app_file:='C:\Users\User\Desktop\Games\JETPACKJOYRIDE\CUSA03633\eboot.bin'; + //ps4_app.app_path:='G:\Games\JETPACKJOYRIDE\CUSA03633\'; + //ps4_app.app_file:='G:\Games\JETPACKJOYRIDE\CUSA03633\eboot.bin'; + //elf:=Telf_file(LoadPs4ElfFromFile('libSceLibcInternal.sprx')); //elf.Prepare; //elf.SavePs4ElfToFile('libSceLibcInternal.prx'); diff --git a/ps4_libsceaudioout.pas b/ps4_libsceaudioout.pas index a7423a07..f8a04dcb 100644 --- a/ps4_libsceaudioout.pas +++ b/ps4_libsceaudioout.pas @@ -289,7 +289,7 @@ begin pstream:=nil; err:=0; - if (_type=SCE_AUDIO_OUT_PORT_TYPE_MAIN) then //so far only main + if (_type=SCE_AUDIO_OUT_PORT_TYPE_MAIN) or (_type=SCE_AUDIO_OUT_PORT_TYPE_BGM) then //so far only MAIN/BGM begin _sig_lock; err:=Pa_OpenDefaultStream(@pstream, diff --git a/ps4_libscepad.pas b/ps4_libscepad.pas index 831c9c01..b377574d 100644 --- a/ps4_libscepad.pas +++ b/ps4_libscepad.pas @@ -254,8 +254,6 @@ begin end; function ps4_scePadRead(handle:Integer;data:PScePadData;num:Integer):Integer; SysV_ABI_CDecl; -var - i:Integer; begin Result:=0; if (num<>0) then @@ -263,11 +261,6 @@ begin ps4_scePadReadState(handle,data); Result:=1; end; - if (num>1) then - For i:=1 to num-1 do - begin - data[i]:=Default(ScePadData); - end; end; function ps4_scePadSetVibration(handle:Integer;pParam:PScePadVibrationParam):Integer; SysV_ABI_CDecl; diff --git a/ps4_libscevideoout.pas b/ps4_libscevideoout.pas index 7f3aa718..d7724ccb 100644 --- a/ps4_libscevideoout.pas +++ b/ps4_libscevideoout.pas @@ -1114,7 +1114,10 @@ begin //SwSaveTime(t1); - ps4_usleep(time); + if (time<>0) then + begin + ps4_usleep(time); + end; //Sleep(_usec2msec(time)); //t2:=SwTimePassedUnits(t1); @@ -1134,6 +1137,7 @@ begin if (bufferIndex=SCE_VIDEO_OUT_BUFFER_INDEX_BLANK) then begin + post_event_flip(flipArg); post_event_vblank(flipArg); end else begin diff --git a/seh64.pas b/seh64.pas index ba7eaa0e..319dce69 100644 --- a/seh64.pas +++ b/seh64.pas @@ -367,58 +367,157 @@ const FPC_EXCEPTION_CODE=$E0465043; { -INSERTQ xmm1, xmm2, imm8, +psllq = _m128i _mm_slli_epi64(_m128i a, int cnt) +psrlq = _m128i _mm_srli_epi64(_m128i a, int cnt) -imm8 F2 0F 78 /r ib ib -Insert field starting at bit 0 of xmm2 with the length -specified by [5:0] of the first immediate byte. This -field is inserted into xmm1 starting at the bit position -specified by [5:0] of the second immediate byte. +SSP_FORCEINLINE __m128i ssp_logical_bitwise_select_SSE2 (__m128i a,b,mask) -INSERTQ xmm1, xmm2 F2 0F 79 /r -Insert field starting at bit 0 of xmm2 with the length -specified by xmm2[69:64]. This field is inserted into -xmm1 starting at the bit position specified by -xmm2[77:72]. +{ + a = _mm_and_si128 ( a, mask ); // clear a where mask = 0 + b = _mm_andnot_si128( mask, b ); // clear b where mask = 1 + a = _mm_or_si128 ( a, b ); // a = a OR b + return a; } +SSP_FORCEINLINE __m128i ssp_inserti_si64_SSE2( __m128i a, __m128i b, int len, int ndx ) + + const static __m128i MASK = SSP_CONST_SET_32I( 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF ); + + int left = ndx + len; + __m128i m; + m = _mm_slli_epi64( MASK, 64-left ); // clear the mask to the left + m = _mm_srli_epi64( m, 64-len ); // clear the mask to the right + m = _mm_slli_epi64( m, ndx ); // put the mask into the proper position + b = _mm_slli_epi64( b, ndx ); // put the insert bits into the proper position + + a = ssp_logical_bitwise_select_SSE2( b, a, m ); + return a; +} + +//f2 0f 78 [c1] [30] [00] insertq $0x0,$0x30,%xmm1 ,%xmm0 c1 = [11] %xmm[000] %xmm[001] +//f2 [44] 0f 78 [c7] [30] [00] insertq $0x0,$0x30,%xmm7 ,%xmm8 c7 = [11] %xmm[000]+8 %xmm[111] +//f2 [41] 0f 78 [f8] [30] [00] insertq $0x0,$0x30,%xmm8 ,%xmm7 f8 = [11] %xmm[111] %xmm[000]+8 +//f2 [45] 0f 78 [c7] [30] [00] insertq $0x0,$0x30,%xmm15,%xmm8 c7 = [11] %xmm[000]+8 %xmm[111]+8 + +const + IQ_MASK:array[0..3] of DWORD=($FFFFFFFF,$FFFFFFFF,$FFFFFFFF,$FFFFFFFF); + +procedure ssp_logical_bitwise_select_SSE2; assembler; nostackframe; +asm + andps %xmm2, %xmm0 //( a, mask ) r = %xmm0 + andnps %xmm1, %xmm2 //( mask, b ) r = %xmm2 + orps %xmm2, %xmm0 //( a, b ) r = %xmm0 +end; + +procedure insertq_xmm5_xmm8_30_00; assembler; +const + len=$30; + ndx=$00; + left=ndx+len; + m64_left=64-left; + m64_len =64-len; +var + xmm0,xmm1,xmm2:array[0..3] of DWORD; +asm + Movq %xmm0,xmm0 + Movq %xmm1,xmm1 + Movq %xmm2,xmm2 + + Movq IQ_MASK,%xmm2 + + //a = xmm5 + //b = xmm8 + + Movq %xmm8,%xmm0 + Movq %xmm5,%xmm1 + + psllq m64_left,%xmm2 //m = ( MASK, 64-left ) clear the mask to the left + psrlq m64_len ,%xmm2 //m = ( m, 64-len ) clear the mask to the right + psllq ndx ,%xmm2 //m = ( m, ndx ) put the mask into the proper position + psllq ndx ,%xmm0 //b = ( b, ndx ) put the insert bits into the proper position + + call ssp_logical_bitwise_select_SSE2 + + Movq %xmm0,%xmm5 + + Movq xmm0,%xmm0 + Movq xmm1,%xmm1 + Movq xmm2,%xmm2 +end; + +procedure patch_insertq(p:Pbyte); +var + i:int64; +begin + Case p[1] of + $0f: + begin + p[0]:=$90; + p[1]:=$90; + p[2]:=$90; + p[3]:=$90; + p[4]:=$90; + p[5]:=$90; + end; + $41: + begin + //e8 [00 00 00 00] ,(90) callq rel32, nop + p[0]:=$90; + p[1]:=$90; + p[2]:=$90; + p[3]:=$90; + p[4]:=$90; + p[5]:=$90; + p[6]:=$90; + end; + $44: + begin + p[0]:=$90; + p[1]:=$90; + p[2]:=$90; + p[3]:=$90; + p[4]:=$90; + p[5]:=$90; + p[6]:=$90; + end; + $45: + begin + p[0]:=$90; + p[1]:=$90; + p[2]:=$90; + p[3]:=$90; + p[4]:=$90; + p[5]:=$90; + p[6]:=$90; + end; + else; + end; +end; + function Test_SIGILL(const rec:TExceptionRecord;ctx:PCONTEXT):longint; begin case rec.ExceptionCode of STATUS_ILLEGAL_INSTRUCTION: begin Case PDWORD(rec.ExceptionAddress)[0] of //4 byte - //00 11 22 33 44 55 66 - $780f41f2: //f2 41 0f 78 e8 30 00 insertq $0x0,$0x30,%xmm8,%xmm5 + //00 11 22 33 44 55 66 + $780f41f2, //f2 41 0f 78 e8 [30] [00] insertq $0x0,$0x30,%xmm8,%xmm5 + $780f44f2, + $780f45f2: + if ((PBYTE(rec.ExceptionAddress)[4] and $C0)=$C0) then begin - PBYTE(rec.ExceptionAddress)[0]:=$90; - PBYTE(rec.ExceptionAddress)[1]:=$90; - PBYTE(rec.ExceptionAddress)[2]:=$90; - PBYTE(rec.ExceptionAddress)[3]:=$90; - PBYTE(rec.ExceptionAddress)[4]:=$90; - PBYTE(rec.ExceptionAddress)[5]:=$90; - PBYTE(rec.ExceptionAddress)[6]:=$90; - - ctx^.Rip:=ctx^.Rip+7; - + patch_insertq(rec.ExceptionAddress); NtContinue(ctx,False); end; else; end; Case (PDWORD(rec.ExceptionAddress)[0] and $FFFFFF) of //3 byte - //00 11 22 33 44 55 - $780FF2: //f2 0f 78 c1 30 00 insertq $0x0,$0x30,%xmm1,%xmm0 + // 00 11 22 33 44 55 c1 = [11] %xmm[000] %xmm[001] + $780FF2: //[f2 0f 78] [c1] [30] [00] insertq $0x0,$0x30,%xmm1,%xmm0 + if ((PBYTE(rec.ExceptionAddress)[3] and $C0)=$C0) then begin - PBYTE(rec.ExceptionAddress)[0]:=$90; - PBYTE(rec.ExceptionAddress)[1]:=$90; - PBYTE(rec.ExceptionAddress)[2]:=$90; - PBYTE(rec.ExceptionAddress)[3]:=$90; - PBYTE(rec.ExceptionAddress)[4]:=$90; - PBYTE(rec.ExceptionAddress)[5]:=$90; - - ctx^.Rip:=ctx^.Rip+6; - + patch_insertq(rec.ExceptionAddress); NtContinue(ctx,False); end; else; diff --git a/sys/sys_crt.pas b/sys/sys_crt.pas index 48cfb569..9340fa9c 100644 --- a/sys/sys_crt.pas +++ b/sys/sys_crt.pas @@ -36,7 +36,7 @@ Begin if (t.BufPos=0) then exit; n:=0; - _sig_lock; + _sig_lock(SL_NOINTRRUP); spin_lock(StdOutLock); WriteConsole(t.Handle,t.Bufptr,t.BufPos,@n,nil); @@ -45,7 +45,7 @@ Begin t.BufPos:=0; spin_unlock(StdOutLock); - _sig_unlock; + _sig_unlock(SL_NOINTRRUP); end; Procedure CrtErrWrite(var t:TextRec); @@ -58,7 +58,7 @@ Begin if (t.BufPos=0) then exit; n:=0; - _sig_lock; + _sig_lock(SL_NOINTRRUP); spin_lock(StdOutLock); old:=7; @@ -73,7 +73,7 @@ Begin t.BufPos:=0; spin_unlock(StdOutLock); - _sig_unlock; + _sig_unlock(SL_NOINTRRUP); end; Procedure CrtClose(Var F:TextRec); diff --git a/sys/sys_kernel.pas b/sys/sys_kernel.pas index a5c424fe..aa6e5f42 100644 --- a/sys/sys_kernel.pas +++ b/sys/sys_kernel.pas @@ -115,7 +115,7 @@ end; function SwDelayExecution(Alertable:Boolean;DelayInterval:PQWORD):DWORD; begin - _sig_lock(Alertable); + _sig_lock(ord(Alertable)); Result:=NtDelayExecution(Alertable,Pointer(DelayInterval)); _sig_unlock; end; @@ -126,7 +126,7 @@ function SwWaitForSingleObject( TimeOut:PQWORD; Alertable:LONGBOOL):DWORD; begin - _sig_lock(Alertable); + _sig_lock(ord(Alertable)); Result:=NtWaitForSingleObject(ObjectHandle,Alertable,Pointer(TimeOut)); _sig_unlock; end; @@ -164,7 +164,7 @@ begin SwSaveTime(QTIME); timeout:=-timeout; - _sig_lock(True); + _sig_lock(SL_ALERTABLE); res:=NtWaitForSingleObject(Handle,True,@timeout); _sig_unlock; timeout:=-timeout; @@ -181,7 +181,7 @@ begin end else begin - _sig_lock(True); + _sig_lock(SL_ALERTABLE); res:=NtWaitForSingleObject(Handle,True,@timeout); _sig_unlock; end; diff --git a/sys/sys_signal.pas b/sys/sys_signal.pas index 237433a8..db32935b 100644 --- a/sys/sys_signal.pas +++ b/sys/sys_signal.pas @@ -52,6 +52,10 @@ type _rsp:QWORD; end; +Const + SL_ALERTABLE=1; + SL_NOINTRRUP=2; + function _SIG_IDX(sig:Integer):DWORD; inline; function _SIG_VALID(sig:Integer):Boolean; inline; function _SIG_VALID_32(sig:Integer):Boolean; inline; @@ -68,8 +72,8 @@ function __sigprocmask(how:Integer;_set,oldset:p_sigset_t):Integer; function __sigaction(signum:Integer;act,oldact:p_sigaction_t):Integer; -procedure _sig_lock(Alertable:Boolean=False); -procedure _sig_unlock; +procedure _sig_lock(flags:integer=0); +procedure _sig_unlock(flags:integer=0); function _pthread_kill(t:Pointer;sig:Integer):Integer; @@ -421,7 +425,7 @@ const function __sig_self_interrupt(t:pthread):Integer; forward; -procedure _sig_lock(Alertable:Boolean=False); +procedure _sig_lock(flags:integer=0); label tryagain; var @@ -432,7 +436,7 @@ begin t:=_get_curthread; if (t=nil) then Exit; - if Alertable then + if ((flags and SL_ALERTABLE)<>0) then begin fetch_or(t^.sig._flag,ALERTABLE_FLAG); end; @@ -440,7 +444,7 @@ begin i:=fetch_add(t^.sig._lock,1); //need to interrupt - if (i=0) or Alertable then + if ((flags and SL_NOINTRRUP)=0) and ((i=0) or ((flags and SL_ALERTABLE)<>0)) then begin tryagain: @@ -466,7 +470,7 @@ begin end; -procedure _sig_unlock; +procedure _sig_unlock(flags:integer=0); label tryagain; var @@ -484,7 +488,7 @@ begin i:=fetch_sub(t^.sig._lock,1); //need to interrupt - if (i=1) or Alertable then + if ((flags and SL_NOINTRRUP)=0) and ((i=1) or Alertable) then begin tryagain: @@ -508,7 +512,10 @@ begin end; - fetch_and(t^.sig._flag,DWORD(not ALERTABLE_FLAG)); + if ((flags and SL_NOINTRRUP)=0) then + begin + fetch_and(t^.sig._flag,DWORD(not ALERTABLE_FLAG)); + end; end; //var @@ -545,7 +552,7 @@ begin While (sigqueue_get(@t^.sig,signo,@info)<>0) do begin - Writeln('>__sig_test:'{,system.InterlockedIncrement(_test_counter)},':',t^.ThreadId); + //Writeln('>__sig_test:'{,system.InterlockedIncrement(_test_counter)},':',t^.ThreadId); sact:=ps_sigact[_SIG_IDX(signo)]; @@ -609,7 +616,7 @@ begin end; end; - Writeln('<__sig_test:'{,_test_counter,':'},t^.ThreadId); + //Writeln('<__sig_test:'{,_test_counter,':'},t^.ThreadId); end; @@ -649,7 +656,7 @@ begin end; end; - Writeln('>__sig_interrupt:',t^.ThreadId,' ',t^.sig._lock); + //Writeln('>__sig_interrupt:',t^.ThreadId,' ',t^.sig._lock); repeat __sig_test_align(t,@ctx); @@ -685,7 +692,7 @@ begin event_try_enable(t^.sig._event); //mark change - Writeln('__sig_self_interrupt'); + //Writeln('__sig_self_interrupt'); if not InitializeContextExtended(@ctx) then Exit(ESRCH); if (NtGetContextThread(t^.handle,ctx.CONTEXT)<>STATUS_SUCCESS) then Exit(ESRCH); @@ -702,14 +709,14 @@ begin ctx.CONTEXT^.Rcx:=qword(t); ctx.CONTEXT^.Rsp:=rsp; - Writeln('beg Sptr=',HexStr(Sptr)); + //Writeln('beg Sptr=',HexStr(Sptr)); - Writeln('>NtContinue:',HexStr(ctx.CONTEXT^.Rip,16)); + //Writeln('>NtContinue:',HexStr(ctx.CONTEXT^.Rip,16)); NtContinue(ctx.CONTEXT,False); eoi: - Writeln('end Sptr=',HexStr(Sptr)); + //Writeln('end Sptr=',HexStr(Sptr)); Result:=0; end; @@ -769,7 +776,7 @@ begin if IS_SYSCALL(ctx.CONTEXT^.Rip) then //system call in code without blocking begin //skip - Writeln('Warn syscall:0x',HexStr(ctx.CONTEXT^.Rax,4)); + //Writeln('Warn syscall:0x',HexStr(ctx.CONTEXT^.Rax,4)); //store_release(t^.sig._wait,1); @@ -870,6 +877,8 @@ var begin if (t=nil) then Exit(EINVAL); + Writeln('_pthread_kill:',sig,':',pthread(t)^.ThreadId); + if (sig=0) then Exit(0); //check pthread if not _SIG_VALID_32(sig) then Exit(EINVAL);