This commit is contained in:
Pavel 2024-01-17 12:48:52 +03:00
parent 08024178e3
commit b00a02d171
11 changed files with 191 additions and 66 deletions

View File

@ -405,6 +405,8 @@ type
procedure vmovdqa (reg0:TRegValue;reg1:TRegValue);
procedure sahf;
procedure lahf;
procedure cli;
procedure sti;
procedure seto(reg:TRegValue);
procedure int3;
procedure testq(reg0:TRegValue;reg1:TRegValue);
@ -4662,6 +4664,16 @@ begin
_O($9F);
end;
procedure t_jit_builder.cli;
begin
_O($FA);
end;
procedure t_jit_builder.sti;
begin
_O($FB);
end;
procedure t_jit_builder.seto(reg:TRegValue);
const
desc:t_op_type=(op:$0F90;opt:[not_prefix]);

View File

@ -9,7 +9,8 @@ uses
vm,
vmparam,
kern_conf,
sys_event;
sys_event,
time;
procedure dce_initialize();
@ -29,7 +30,47 @@ uses
kern_event,
kern_mtx,
md_time,
kern_proc;
kern_proc,
kern_timeout;
const
EVENTID_FLIP =$0006;
EVENTID_VBLANK=$0007;
procedure knote_eventid(event_id:WORD;flipArg:QWORD;lockflags:Integer);
begin
knote(@g_video_out_event_flip, event_id or (flipArg shl 16), lockflags);
end;
var
callout_vblank:t_callout;
callout_refs :Int64=0;
procedure vblank_expire(arg:Pointer);
begin
if (callout_refs<>0) then
begin
knote_eventid(EVENTID_VBLANK, 0, 1); //SCE_VIDEO_OUT_EVENT_VBLANK
//
callout_reset(@callout_vblank, callout_vblank.c_time, @vblank_expire, nil);
end;
end;
procedure open_vblank;
var
time:Int64;
begin
if (System.InterlockedIncrement64(callout_refs)=1) then
begin
time:=round(hz/59.94);
callout_reset(@callout_vblank, time, @vblank_expire, nil);
end;
end;
procedure close_vblank;
begin
System.InterlockedDecrement64(callout_refs);
end;
type
p_flip_control_args=^t_flip_control_args;
@ -268,6 +309,8 @@ begin
len:=111; //canary
copyout(@len,ptr,SizeOf(QWORD));
open_vblank;
Exit(0);
end;
Exit(EINVAL);
@ -282,6 +325,8 @@ begin
Writeln('dce_video_close:',data^.arg2);
close_vblank;
Exit(0);
end;
Exit(EINVAL);
@ -367,7 +412,7 @@ begin
Exit(EINVAL);
end;
12: //scaler?
12: //sceVideoOutSysUpdateScalerParameters
begin
if (data^.arg5=0) and (data^.arg6=0) then
begin
@ -382,7 +427,7 @@ begin
len:=0;
Writeln('dce_flip_control(',data^.id,'):get_data?');
//print_backtrace_td(stderr);
print_backtrace_td(stderr);
Result:=copyout(@len,ptr,8);
@ -534,9 +579,7 @@ begin
'0x',HexStr(data^.flipArg,16),' ',
data^.eop_val);
knote(@g_video_out_event_flip, $0006 or (data^.flipArg shl 16), 0); //SCE_VIDEO_OUT_EVENT_FLIP
knote(@g_video_out_event_flip, $0007 or (data^.flipArg shl 16), 0); //SCE_VIDEO_OUT_EVENT_VBLANK
knote_eventid(EVENTID_FLIP, data^.flipArg, 0); //SCE_VIDEO_OUT_EVENT_FLIP
flipArg:=data^.flipArg;
@ -690,11 +733,11 @@ begin
event_id:=kn^.kn_kevent.ident shr 48;
case event_id of
$0006: //SCE_VIDEO_OUT_EVENT_FLIP
EVENTID_FLIP: //SCE_VIDEO_OUT_EVENT_FLIP
begin
knlist_add(@g_video_out_event_flip,kn,0)
end;
$0007: //SCE_VIDEO_OUT_EVENT_VBLANK
EVENTID_VBLANK: //SCE_VIDEO_OUT_EVENT_VBLANK
begin
knlist_add(@g_video_out_event_flip,kn,0)
end;
@ -718,11 +761,11 @@ begin
event_id:=kn^.kn_kevent.ident shr 48;
case event_id of
$0006: //SCE_VIDEO_OUT_EVENT_FLIP
EVENTID_FLIP: //SCE_VIDEO_OUT_EVENT_FLIP
begin
knlist_remove(@g_video_out_event_flip,kn,0)
end;
$0007: //SCE_VIDEO_OUT_EVENT_VBLANK
EVENTID_VBLANK: //SCE_VIDEO_OUT_EVENT_VBLANK
begin
knlist_remove(@g_video_out_event_flip,kn,0)
end;
@ -793,6 +836,8 @@ begin
knlist_init_mtx(@g_video_out_event_flip,@knlist_lock_flip);
callout_init_mtx(@callout_vblank,knlist_lock_flip,0);
kqueue_add_filteropts(EVFILT_DISPLAY,@filterops_display);
make_dev(@dce_cdevsw,0,0,0,0666,'dce',[]);

View File

@ -12,7 +12,8 @@ uses
kern_jit_ctx;
var
print_asm:Boolean=False;
print_asm :Boolean=False;
debug_info:Boolean=False;
procedure pick(var ctx:t_jit_context2;preload:Pointer);
procedure pick_locked(var ctx:t_jit_context2);
@ -872,17 +873,20 @@ var
link_jmp:t_jit_i_link;
begin
//debug
if debug_info then
begin
link_jmp:=ctx.builder.jmp(nil_link,os8);
//
ctx.builder._O($FA); //cli
ctx.builder.cli;
//op_set_r14_imm(ctx,$FACEADD7);
op_set_r14_imm(ctx,Int64(ctx.ptr_curr));
add_orig(ctx);
op_set_r14_imm(ctx,Int64(ctx.ptr_next));
//op_set_r14_imm(ctx,$FACEADDE);
ctx.builder._O($FB); //sti
ctx.builder.sti;
//
link_jmp._label:=ctx.builder.get_curr_label.after;
end;
//debug
end;

View File

@ -118,7 +118,6 @@ uses
subr_hash,
vsys_generic,
kern_proc,
kern_callout,
kern_timeout,
kern_namedobj;

View File

@ -50,6 +50,7 @@ uses
vfcntl,
vfs_vnops,
vfs_subr,
kern_thread,
kern_budget,
kern_descrip,
vfs_cache,
@ -1411,6 +1412,7 @@ begin
end;
Move(p_proc.p_comm, td^.td_name, sizeof(td^.td_name));
KernSetThreadDebugName(td,'ps4:');
{
* mark as execed, wakeup the process that vforked (if any) and tell

View File

@ -314,6 +314,7 @@ procedure TD_SET_CAN_RUN(td:p_kthread);
procedure THREAD_NO_SLEEPING();
procedure THREAD_SLEEPING_OK();
function THREAD_IS_NOSLEEPING:Boolean;
function curthread_pflags_set(flags:Integer):Integer;
procedure curthread_pflags_restore(save:Integer);
@ -522,6 +523,14 @@ begin
td^.td_pflags:=td^.td_pflags and (not TDP_NOSLEEPING);
end;
function THREAD_IS_NOSLEEPING:Boolean;
var
td:p_kthread;
begin
td:=curkthread;
Result:=(td^.td_pflags and TDP_NOSLEEPING)<>0;
end;
//
function curthread_pflags_set(flags:Integer):Integer;

View File

@ -53,6 +53,8 @@ procedure FOREACH_THREAD_FINISH();
function THREAD_NEXT(i:p_kthread_iterator):Boolean;
function THREAD_GET (i:p_kthread_iterator):p_kthread;
procedure KernSetThreadDebugName(newtd:p_kthread;prefix:PChar);
function SIGPENDING(td:p_kthread):Boolean;
procedure threadinit; //SYSINIT

View File

@ -14,6 +14,21 @@ uses
kern_rwlock,
kern_callout;
type
t_callout_func=kern_callout.t_callout_func;
p_callout=kern_callout.p_callout;
t_callout=kern_callout.t_callout;
const
CALLOUT_LOCAL_ALLOC =kern_callout.CALLOUT_LOCAL_ALLOC ;
CALLOUT_ACTIVE =kern_callout.CALLOUT_ACTIVE ;
CALLOUT_PENDING =kern_callout.CALLOUT_PENDING ;
CALLOUT_MPSAFE =kern_callout.CALLOUT_MPSAFE ;
CALLOUT_RETURNUNLOCKED=kern_callout.CALLOUT_RETURNUNLOCKED;
CALLOUT_SHAREDLOCK =kern_callout.CALLOUT_SHAREDLOCK ;
CALLOUT_RWLOCK =kern_callout.CALLOUT_RWLOCK ;
procedure kern_timeout_init();
procedure CC_LOCK(cc:p_callout_cpu);
@ -65,6 +80,7 @@ begin
c^:=Default(t_callout);
if (mpsafe<>0) then
begin
c^.c_lock :=nil; //no locking
c^.c_flags:=CALLOUT_RETURNUNLOCKED;
end else
begin
@ -79,7 +95,7 @@ begin
c^.c_lock:=lock;
Assert((flags and (not (CALLOUT_RETURNUNLOCKED or CALLOUT_SHAREDLOCK)))=0,'callout_init_lock: bad flags');
Assert((lock<>nil) or ((flags and CALLOUT_RETURNUNLOCKED)=0),'callout_init_lock: CALLOUT_RETURNUNLOCKED with no lock');
Assert(lock=nil,'invalid lock');
Assert(lock<>nil,'invalid lock');
c^.c_flags:=flags and (CALLOUT_RETURNUNLOCKED or CALLOUT_SHAREDLOCK);
end;
@ -350,7 +366,7 @@ begin
Exit(0);
end;
if (safe<>0) then
if (safe<>0) and (not THREAD_IS_NOSLEEPING) then
begin
while (cc^.cc_curr=c) do
begin

View File

@ -24,6 +24,9 @@ procedure md_init_tty;
implementation
uses
kern_thr;
function ttydisc_read_poll(tp:p_tty):QWORD;
var
N:DWORD;
@ -78,92 +81,124 @@ begin
Result:=uiomove(@BUF, BLK.Information, uio);
end;
type
TWRITE_BUF=object
MAX,LEN:QWORD;
PTR:Pointer;
BUF:array[0..1023] of AnsiChar;
Procedure INIT ();
function WRITE(N:Pointer;L:QWORD):QWORD;
function UP (L:QWORD):QWORD;
end;
Procedure TWRITE_BUF.INIT();
begin
PTR:=@BUF[0];
MAX:=Length(BUF);
LEN:=0;
end;
function TWRITE_BUF.WRITE(N:Pointer;L:QWORD):QWORD;
begin
if (L>MAX) then L:=MAX;
Move(N^,PTR^,L);
Inc(PTR,L);
Dec(MAX,L);
Inc(LEN,L);
Result:=L;
end;
function TWRITE_BUF.UP(L:QWORD):QWORD;
begin
if (L>MAX) then L:=MAX;
Inc(PTR,L);
Dec(MAX,L);
Inc(LEN,L);
Result:=L;
end;
function ttydisc_write(tp:p_tty;uio:p_uio;ioflag:Integer):Integer;
var
MAX,LEN,OFS:QWORD;
BLK:IO_STATUS_BLOCK;
OFFSET:Int64;
PTR:Pointer;
BUF:array[0..1023] of AnsiChar;
BUF:TWRITE_BUF;
i:QWORD;
td:p_kthread;
begin
//init
BLK:=Default(IO_STATUS_BLOCK);
OFFSET:=Int64(FILE_WRITE_TO_END_OF_FILE_L);
//
BUF.INIT();
//tty name
if ((tp^.t_flags and TF_NOWRITEPREFIX)=0) then
begin
OFS:=tp^.t_nlen;
Move(tp^.t_name^,BUF,OFS);
PTR:=@BUF[OFS];
MAX:=Length(BUF)-OFS;
LEN:=uio^.uio_resid+OFS;
end else
BUF.WRITE(tp^.t_name,tp^.t_nlen);
end;
//thread
td:=curkthread;
if (td<>nil) then
begin
PTR:=@BUF[0];
MAX:=Length(BUF);
LEN:=uio^.uio_resid;
OFS:=0;
BUF.WRITE(pchar('('),1);
BUF.WRITE(@td^.td_name,strlen(@td^.td_name));
BUF.WRITE(pchar('):'),2);
end;
//text
while (LEN<>0) do
while (uio^.uio_resid<>0) do
begin
if (LEN>MAX) then LEN:=MAX;
//
Result:=uiomove(PTR, LEN-OFS, uio);
i:=uio^.uio_resid;
Result:=uiomove(BUF.PTR, BUF.MAX, uio);
if (Result<>0) then Break;
i:=i-uio^.uio_resid;
BUF.UP(i);
//
NtWriteFile(tp^.t_wr_handle,0,nil,nil,@BLK,@BUF,LEN,@OFFSET,nil);
NtWriteFile(tp^.t_wr_handle,0,nil,nil,@BLK,@BUF.BUF,BUF.LEN,@OFFSET,nil);
//
PTR:=@BUF[0];
MAX:=Length(BUF);
LEN:=uio^.uio_resid;
OFS:=0;
BUF.INIT();
end;
end;
function ttycrt_write(tp:p_tty;iov_base:Pointer;iov_len:qword):Integer;
var
MAX,LEN,OFS:QWORD;
BLK:IO_STATUS_BLOCK;
OFFSET:Int64;
PTR:Pointer;
BUF:array[0..1023] of AnsiChar;
BUF:TWRITE_BUF;
i:QWORD;
td:p_kthread;
begin
Result:=0;
//init
BLK:=Default(IO_STATUS_BLOCK);
OFFSET:=Int64(FILE_WRITE_TO_END_OF_FILE_L);
//
BUF.INIT();
//tty name
if ((tp^.t_flags and TF_NOWRITEPREFIX)=0) then
begin
OFS:=tp^.t_nlen;
Move(tp^.t_name^,BUF,OFS);
PTR:=@BUF[OFS];
MAX:=Length(BUF)-OFS;
LEN:=iov_len+OFS;
end else
BUF.WRITE(tp^.t_name,tp^.t_nlen);
end;
//thread
td:=curkthread;
if (td<>nil) then
begin
PTR:=@BUF[0];
MAX:=Length(BUF);
LEN:=iov_len;
OFS:=0;
if (td^.td_name='SceVideoOutServiceThread') then
begin
Exit(0);
end;
BUF.WRITE(pchar('('),1);
BUF.WRITE(@td^.td_name,strlen(@td^.td_name));
BUF.WRITE(pchar('):'),2);
end;
//text
while (LEN<>0) do
while (iov_len<>0) do
begin
if (LEN>MAX) then LEN:=MAX;
i:=BUF.WRITE(iov_base,iov_len);
Inc(iov_base,i);
Dec(iov_len ,i);
//
MAX:=LEN-OFS;
Move(iov_base^,PTR^,MAX);
Inc(iov_base,MAX);
Dec(iov_len ,MAX);
NtWriteFile(tp^.t_wr_handle,0,nil,nil,@BLK,@BUF.BUF,BUF.LEN,@OFFSET,nil);
//
NtWriteFile(tp^.t_wr_handle,0,nil,nil,@BLK,@BUF,LEN,@OFFSET,nil);
//
PTR:=@BUF[0];
MAX:=Length(BUF);
LEN:=iov_len;
OFS:=0;
BUF.INIT();
end;
end;

View File

@ -87,7 +87,6 @@ uses
sys_event,
sys_eventvar,
kern_event,
kern_callout,
kern_timeout,
kern_exec,
kern_dynlib,
@ -386,7 +385,7 @@ begin
//argv0:='/app0/scene2.bin';
//argv0:='/app0/basic_quad_debug.elf';
argv0:='/app0/hello_world8.bin';
//argv0:='/app0/hello_world9.bin';
err:=_execve(argv0,@argv0,nil);
end;

View File

@ -42,6 +42,8 @@ var
cnt:QWORD;
error, newflags, save:Integer;
begin
if (n<=0) then Exit(0);
td:=curkthread;
error:=0;