From:	SMTP%"neill@macro.demon.co.uk"  5-JAN-1994 19:46:51.56
To:	EVERHART
CC:	
Subj:	DDB.4-OF-5  Detached debugger

Date: Wed, 05 Jan 1994 23:27:09 +0000
From: Neill Clift <neill@macro.demon.co.uk>
To: EVERHART@arisia.gce.com
Message-ID: <009781AA.DA49C480.5391@macro.demon.co.uk>
Subject: DDB.4-OF-5  Detached debugger

-+-+-+-+-+-+-+-+ START OF PART 4 -+-+-+-+-+-+-+-+
X`09$def`09pib_t_terminal`09.blkb`09acb_k_devlen+1`09;`20Input/Output`20buffer
V
X`09$def`09pib_q_lksb`09.blkq`091`09`09;`20lock`20status`20block
X`09$def`09pib_t_lockname`09.blkb`09pib_k_lockname`09;`20Place`20to`20put`20loc
Vkname
X`09$def`09pib_l_epid`09.blkl`091`09`09;`20external`20PID`20of`20target
X`09$equ`09pib_r_code`09.`09`09`09;`20code`20starts`20here
X`09$equ`09pib_k_length`09.`09`09`09;`20set`20length`20of`20block
X`09$defend`09pid
X;
X`09.psect`09ddb_rdata`20nowrt`20rd`20noexe`20shr
Xvta0:`09.ascid`09/_VTA0:/`09`09`09`09;`20Virtual`20terminal`20name
X;!!!!`09.psect`09ddb_code`20nowrt`20rd`20exe`20pic`20shr
X`09.psect`09zddb_code`20wrt`20rd`20exe`20pic`20shr
X`09.entry`09ddb_priv`20`5Em<>
Xefn`20`20`20`20`20`20=`204`09`09`09`09`09`09;`20Event`20flag`20to`20set
Xpidadr`20`20`20=`20efn+4`09`09`09`09`09;`20PID`20of`20process
Xiosb`20`20`20`20`20=`20pidadr+4`09`09`09`09`09;`20I/O`20status`20block
Xterminal`20=`20iosb+4`09`09`09`09`09;`20Terminal`20to`20debug`20on
Xnargs`20`20`20`20=`204`09`09`09`09`09`09;`20Total`20arguments
X`09$cmkrnl_s`20-
X`09`09routin`20=`20b`5Eddb_priv_k,`20-
X`09`09arglst`20=`20(ap)
X99$:`09ret
X`09.entry`09ddb_privw`20`5Em<>
X`09$cmkrnl_s`20-
X`09`09routin`20=`20b`5Eddb_priv_k,`20-
X`09`09arglst`20=`20(ap)
X`09blbc`09r0,`2099$
X`09$synch_s`20-
X`09`09efn`20`20=`20efn(ap),`20-
X`09`09iosb`20=`20iosb(ap)
X99$:`09ret
X;
X`09.entry`09ddb_priv_k`20`5Em<r2,r3,r4,r5,r6,r7,r8,r9,r10,r11>
X;
X;`20At`20this`20point`20R4`20contains`20address
X;
X;`09jsb`09g`5Eini$brk
X`09bsbw`09alloc_buf_r5`09`09`09;`20allocate`20ACB
X`09blbc`09r0,`2099$`09`09`09`09;`20failed`20to`20allocate
X`09bsbw`09copy_args_r4`09`09`09;`20copy`20arguments`20into`20ACB
X`09blbc`09r0,`2099$`09`09`09`09;`20quit`20on`20error
X`09bsbb`09copy_code_r4`09`09`09;`20copy`20code`20into`20pool
X`09bsbb`09qast_r5`09`09`09`09;`20queue`20the`20ast
X99$:`09bsbw`09tidy_r2`09`09`09`09;`20tidy`20up
X`09ret`09`09`09`09`09;`20return`20status
X;
X;`20Copies`20the`20code`20into`20pool`20and`20sets`20addresses`20of`20code`20t
Vo`20execute.
X;`20Inputs:
X;`20`20`20`20R5:`20ACB`20address
X;`20Outputs:
X;`20Trashes:
X;`20`20`20`20R0,R1,R2,R3,R4
X;
Xcopy_code_r4:
X`09pushl`09r5`09`09`09`09;`20Save`20ACB
X`09movab`09acb_r_code(r5),`20acb$l_kast(r5)`09;`20set`20code`20to`20execute`20
Vat`20IPL`202
X`09movc3`09#code_length,`20w`5Ecode_start,`20-
X`09`09acb_r_code(r5)`09`09`09;`20Copy`20the`20code`20into`20pool
X`09movl`09#ss$_normal,`20r0`09`09`09;`20all`20is`20ok
X`09popl`09r5`09`09`09`09;`20restore`20ACB
X`09rsb
X;
X;`20Tests`20the`20status`20of`20the`20target`20process`20and`20queues`20the`20
VAST`20to`20it`20if`20all`20is`20ok
X;
X;`20Inputs:
X;`20`20`20`20R5:`20ACB`20address
X;`20Outputs:
X;`20`20`20`20R0:`20Status
X;`20`20`20`20R5:`20Cleared`20if`20AST`20queued`20ok.
X;`20Trashes:
X;`20`20`20`20R1,R3,R4
Xqast_r5:
X`09setipl`09ipl`20`20`20`20`20=`20w`5Esched,`20-`09`09;`20up`20to`20sched`20fo
Vr`20database
X`09`09environ`20=`20UNIPROCESSOR`09`09;`20just`20want`20to`20raise`20IPL
X`09lock`09lockname`20`20=`20sched,`20-`09`09;`20lock`20the`20database
X`09`09condition`20=`20NOSETIPL,`20-`09`09;`20poor`20mans`20lockdown
X`09`09preserve`20`20=`20NO`09`09`09;`20dont`20save`20R0
X`09movl`09acb$l_pid(r5),`20r0`09`09;`20get`20PID`20back
X`09jsb`09g`5Eexe$ipid_to_pcb`09`09;`20convert`20to`20PCB
X`09beql`09100$`09`09`09`09;`20process`20has`20gone`20now
X`09bbs`09#pcb$v_delpen,`20pcb$l_sts(r0),`20-
X`09`09100$`09`09`09`09;`20dont`20queue`20to`20delpen`20proc
X`09bbs`09#pcb$v_suspen,`20pcb$l_sts(r0),`20-
X`09`09110$`09`09`09`09;`20dont`20queue`20to`20suspened
X`09bbs`09#pcb$v_softsusp,`20pcb$l_sts(r0),`20-
X`09`09110$`09`09`09`09;`20dont`20queue`20to`20soft`20susp
X`09cmpw`09#sch$c_suspo,`20pcb$w_state(r0)`09;`20dont`20queue`20to`20suspended
V
X`09beql`09110$
X`09cmpw`09#sch$c_susp,`20pcb$w_state(r0)`09;`20`20..
X`09beql`09110$
X`09cmpw`09#sch$c_mwait,`20pcb$w_state(r0)`09;`20`20or`20resource`20wait`20proc
Vesses
X`09beql`09110$
X`09tstb`09pcb$b_astact(r0)`09`09;`20Any`20ASTs`20active?
X`09bneq`09120$
X`09cmpb`09#`5EB1111,`20pcb$b_asten(r0)`09;`20All`20ASTs`20enabled?
X`09bneq`09130$
X`09movl`09#pri$_ticom,`20r2`09`09`09;`20set`20large`20priority`20inc
X`09jsb`09g`5Esch$qast`09`09`09;`20queue`20the`20AST`09
X`09blbc`09r0,`20100$`09`09`09;`20quit`20with`20error
X`09clrl`09r5`09`09`09`09;`20dont`20deallocate`20ACB
X99$:`09unlock`09lockname`20=`20sched,`20-`09`09;`20unlock`20database
X`09`09newipl`20`20`20=`20#ipl$_astdel,`20-`09;`20can't`20affort`20to`20loose
V`20memory
X`09`09preserve`20=`20YES`09`09`09;`20save`20status
X`09rsb
X100$:`09movzwl`09#ss$_nonexpr,`20r0`09`09;`20Say`20no`20process`20there
X`09brb`0999$`09`09`09`09;`20get`20back`20in`20line
X110$:`09movzwl`09#ss$_suspended,`20r0`09`09;`20say`20suspended
X`09brb`0999$
X120$:`09movl`09#ddb__astact,`20r0`09`09;`20say`20thread`20active
X`09brb`0999$
X130$:`09movl`09#ddb__astdis,`20r0`09`09;`20say`20ASTs`20disabled
X`09brb`0999$
Xsched:`09.long`09ipl$_sched`09`09`09;`20must`20be`20in`20next`20or`20same`20pa
Vge
X`09assume`09<.-qast_r5>`20le`20512
X;
X;`20Probes,`20copies`20(to`20ACB)`20and`20validates`20arguments.
X;
X;`20Inputs:
X;`20`20`20`20R5:`20Pointer`20to`20ACB
X;`20`20`20`20AP:`20Argument`20list`20pointer
X;`20Outputs:
X;`20`20`20`20R0:`20Status
X;`20Trashes:
X;`20`20`20`20R1,R2,R3,R4
X;
Xcopy_args_r4:
X`09movl`09g`5Ectl$gl_pcb,`20r4`09`09;`20get`20address`20of`20PCB
X`09movl`09pcb$l_pid(r4),`20acb_l_rpid(r5)`09;`20save`20our`20PID`20for`20retur
Vn
X`09movl`09g`5Ectl$gl_phd,`20r0`09`09;`20get`20process`20header
X`09movl`09phd$l_imgcnt(r0),`20-
X`09`09acb_l_imgcnt(r5)`09`09;`20Save`20image`20count`20for`20later
X`09movpsl`09r0`09`09`09`09;`20get`20our`20psl
X`09extzv`09#psl$v_prvmod,`20#psl$s_prvmod,`20-
X`09`09r0,`20acb_l_acmode(r5)`09`09;`20get`20previous`20mode
X`09movb`09#psl$c_kernel!acb$m_kast!acb$m_nodelete,`20-
X`09`09acb$b_rmod(r5)`09`09`09;`20set`20AST`20mode`20to`20kernel
X`09prober`09#0,`20#nargs*4+4,`20(ap)`09`09;`20can`20we`20read`20the`20arg`20li
Vst
X`09beql`09accvio`09`09`09`09;`20can't`20read`20it
X`09movzwl`09#ss$_insfarg,`20r0`09`09;`20assume`20too`20few`20arguments
X`09cmpb`09(ap),`20#nargs`09`09`09;`20enough`20arguments?
X`09blssu`0999$`09`09`09`09;`20not`20enough
X`09movl`09iosb(ap),`20r1`09`09`09;`20get`20iosb`20address
X`09probew`09#0,`20#8,`20(r1)`09`09`09;`20can`20we`20write`20it?
X`09beql`09accvio`09`09`09`09;`20nope!
X`09clrq`09(r1)`09`09`09`09;`20zero`20it`20for`20starters
X`09movl`09r1,`20acb_l_iosb(r5)`09`09;`20save`20away`20iosb`20address
X`09movl`09efn(ap),`20r3`09`09`09;`20get`20event`20flag`20number
X`09jsb`09g`5Esch$clrefr`09`09`09;`20clear`20the`20event`20flag
X`09blbc`09r0,`2099$`09`09`09`09;`20quit`20on`20error
X`09movl`09r3,`20acb_l_efn(r5)`09`09;`20save`20event`20flag`20number
X`09bsbb`09get_terminal_r4`09`09`09;`20get`20the`20terminal`20name
X`09blbc`09r0,`2099$`09`09`09`09;`20quit`20if`20error
X`09movl`09pidadr(ap),`20r1`09`09`09;`20get`20address`20of`20PID
X`09prober`09#0,`20#4,`20(r1)`09`09`09;`20can`20we`20read`20the`20longword?
X`09beql`09accvio`09`09`09`09;`20failed`20to`20read`20it
X`09movl`09(r1),`20r0`09`09`09;`20get`20pid
X`09movl`09r0,`20acb_l_epid(r5)`09`09;`20save`20external`20PID
X`09jsb`09g`5Eexe$epid_to_ipid`09`09;`20convert`20to`20internal`20format
X`09beql`09noprc`09`09`09`09;`20zero`20means`20not`20converted
X`09movl`09r0,`20acb$l_pid(r5)`09`09;`20save`20the`20remote`20pid
X`09movl`09#ss$_normal,`20r0`09`09`09;`20all`20is`20ok
X99$:`09rsb
Xaccvio:`09movzwl`09#ss$_accvio,`20r0`09`09`09;`20say`20access`20violation
X`09rsb
Xnoprc:`09movzwl`09#ss$_nonexpr,`20r0`09`09;`20say`20process`20not`20found
X`09rsb
X;
X;`20Creates`20a`20logical`20UCB`20(Virtual`20terminal)`20for`20the`20physical
V`20terminal.
X;`20Inputs:
X;`20`20`20`20R4:`20PCB`20address
X;`20`20`20`20R5:`20ACB`20address
X;`20Outputs:
X;`20Trashes:
X;
Xget_terminal_r4:
X`09movq`09r4,`20-(sp)`09`09`09;`20save`20ACB/PCB`20address
X`09jsb`09g`5Esch$iolockw`09`09`09;`20Lock`20IO`20database`20fow`20write
X`09movaq`09vta0,`20r1`09`09`09;`20get`20vta0:`20address
X`09jsb`09g`5Eioc$searchdev`09`09`09;`20search`20for`20device
X`09clrl`09r5`09`09`09`09;`20Assume`20no`20cloned`20UCB
X`09blbc`09r0,`201$`09`09`09`09;`20skip`20logical`20UCB`20bit
X`09bsbb`09clone_ucb_r5`09`09`09;`20Clone`20the`20UCB
X1$:`09movl`09#ss$_accvio,`20r0`09`09`09;`20assume`20access`20violation
X`09movl`09terminal(ap),`20r1`09`09;`20get`20device`20name
X`09prober`09#0,`20#8,`20(r1)`09`09`09;`20read`20descriptor?
X`09beql`0999$`09`09`09`09;`20exit`20with`20error
X`09jsb`09g`5Eioc$searchdev`09`09`09;`20search`20for`20device
X`09blbc`09r0,`2099$`09`09`09`09;`20quit`20with`20error
X`09cmpb`09#dc$_term,`20ucb$b_devclass(r1)`09;`20this`20a`20terminal?
X`09bneq`09110$`09`09`09`09;`20say`20its`20not`20right!
X;
X;`20R1`20Contains`20original`20terminal`20UCB
X;`20R5`20Contains`20cloned`20UCB`20address`20(VTAnnn:)`20or`20zero
X;
X`09tstl`09r5`09`09`09`09;`20cloned`20device`20there?
X`09beql`0997$`09`09`09`09;`20just`20copy`20device`20name
X`09bsbb`09setup_plucb_r3`09`09`09;`20setup`20UCBs
X`09brb`0998$`09`09`09`09;`20use`20LUCB
X97$:`09movl`09r1,`20r5`09`09`09`09;`20use`20PUCB`20for`20name
X98$:`09movl`094(sp),`20r2`09`09`09;`20get`20ACB`20address`20back
X`09movl`09#acb_k_devlen,`20r0`09`09;`20set`20length`20of`20output
X`09movab`09acb_t_terminal+1(r2),`20r1`09;`20set`20buffer`20address
X`09mnegl`09#1,`20r4`09`09`09`09;`20we`20want`20a`20full`20device`20name
X`09jsb`09g`5Eioc$cvt_devnam`09`09;`20convert`20UCB`20to`20device`20name
X`09movb`09r1,`20acb_t_terminal(r2)`09`09;`20set`20length`20of`20terminal
X99$:`09movq`09(sp)+,`20r4`09`09`09;`20get`20ACB/PCB`20address`20back
X`09pushl`09r0`09`09`09`09;`20save`20status
X`09jsb`09g`5Esch$iounlock`09`09`09;`20unlock`20and`20return
X`09popl`09r0`09`09`09`09;`20restore`20status
X`09rsb`09`09`09`09`09;`20return`20status
X110$:`09movzwl`09#ss$_ivdevnam,`20r0`09`09;`20say`20bad`20device`20name
X`09brb`0999$`09`09`09`09;`20release`20mutex
X;
X;`20Clones`20the`20UCB`20pointed`20to`20by`20R1
X;
X;`20Inputs:
X;`20`20`20`20R1:`20UCB`20to`20clone
X;`20Outputs:
X;`20`20`20`20R0:`20Status
X;`20`20`20`20R5:`20Cloned`20UCB`20address`20or`20zero`20if`20failed
X;
Xclone_ucb_r5:
X`09movl`09r1,`20r5`09`09`09`09;`20get`20UCB`20into`20input`20reg
X`09jsb`09g`5Eioc$clone_ucb`09`09`09;`20clone`20the`20device
X`09movl`09r2,`20r5`09`09`09`09;`20get`20UCB`20into`20correct`20reg
X`09blbc`09r0,`201$`09`09`09`09;`20do`20the`20rest
X`09clrw`09ucb$w_refc(r5)`09`09`09;`20say`20no`20accessors
X`09assume`09ucb$v_deleteucb`20gt`2015`09`09;`20Can`20we`20shrink`20instruction
V?
X`09bisw`09#ucb$m_deleteucb@-16,`20-
X`09`09ucb$l_sts+2(r5)`09`09`09;`20say`20to`20delete`20on`20deaccess
X`09rsb
X1$:`09clrl`09r5`09`09`09`09;`20say`20no`20ucb`20there
X`09rsb
X;
X;`20Set`20up`20information`20in`20the`20Logical`20UCB`20and`20cross`20link`20t
Vhis`20with`20the`20PUCB.
X;`20Inputs:
X;`20`20`20`20R1:`20PUCB
X;`20`20`20`20R5:`20LUCB
X;`20Outputs:
X;`20`20`20`20R1:`20PUCB
X;`20`20`20`20R5:`20LUCB
X;`20Trashes:
X;`20`20`20`20R2,R3
X;
Xsetup_plucb_r3:
X;`09bisw`09#ucb$m_job,`20ucb$w_devsts(r1)`09;`20Say`20we`20have`20told`20job
V`20control
X;`09assume`09dev$v_avl`20gt`2015`09`09`09;`20Can`20we`20shrink`20instruction?
V
X;`09bicw`09#dev$m_avl@-16,`20-
X;`09`09ucb$l_devchar+2(r1)`09`09;`20say`20unavailable
X;`09assume`09dev$v_red`20gt`207`09`09`09;`20Can`20we`20shrink`20instruction?
X;`09assume`09dev$v_red`20lt`2016`09`09`09;`20in`20a`20byte?
X;`09bisb`09#dev$m_red@-8,`20-
X;`09`09ucb$l_devchar2+1(r1)`09`09;`20say`20redirected`20UCB
X`09movb`09ucb$b_devtype(r1),`20-
X`09`09ucb$b_devtype(r5)`09`09;`20copy`20device`20type`09
X`09movb`09ucb$b_flck(r1),`20-
X`09`09ucb$b_flck(r5)`09`09`09;`20copy`20fork`20lock`20index
X`09assume`09<ucb$b_dipl+1>`20eq`20ucb$b_amod`09;`20copy`20both`20fields?
X`09movw`09ucb$b_dipl(r1),`20-
X`09`09ucb$b_dipl(r5)`09`09`09;`20copy`20ipl`20and`20access`20mode
X`09movl`09ucb$l_dlck(r1),`20-
X`09`09ucb$l_dlck(r5)`09`09`09;`20copy`20device`20lock
X`09movl`09ucb$l_affinity(r1),`20-
X`09`09ucb$l_affinity(r5)`09`09;`20copy`20device`20affinity
X`09movw`09ucb$w_devbufsiz(r1),`20-
X`09`09ucb$w_devbufsiz(r5)`09`09;`20copy`20device`20size
X`09assume`09<ucb$l_devdepend+4>`20eq`20ucb$l_devdepnd2
X`09movq`09ucb$l_devdepend(r1),`20-
X`09`09ucb$l_devdepend(r5)`09`09;`20copy`20device`20dependent`20flags
X;`09movl`09r1,`20ucb$l_tl_phyucb(r5)`09`09;`20link`20LUCB`20to`20PUCB
X;`09movl`09r5,`20ucb$l_tt_logucb(r1)`09`09;`20link`20PUCB`20to`20LUCB
X`09movl`09ucb$l_orb(r1),`20r2`09`09;`20get`20PUCB`20object`20rights`20block
X`09movl`09ucb$l_orb(r5),`20r3`09`09;`20get`20LUCB`20object`20rights`20block
X`09movw`09orb$w_prot(r2),`20orb$w_prot(r3)`09;`20copy`20protection
X`09movl`09orb$l_owner(r2),`20orb$l_owner(r3);`20copy`20owner
X99$:`09rsb
X;
X;`20Tidy`20up`20any`20memory`20allocated`20and`20drop`20IPL`20etc.
X;
X;`20Inputs:
X;`20`20`20`20R5:`20ACB`20address
X;`20Outputs:
X;`20`20`20`20R0:`20Status
X;`20Trashes:
X;`20`20`20`20R1,R2
X;
Xtidy_r2:
X`09tstl`09r5`09`09`09`09;`20copy`20ACB`20address
X`09beql`092$`09`09`09`09;`20ACB`20non`20allocated?
X`09pushl`09r0`09`09`09`09;`20save`20status
X`09movl`09acb_l_acb(r5),`20r0`09`09;`20get`20chained`20ACB
X`09beql`091$`09`09`09`09;`20skip`20chain`20drop
X`09jsb`09g`5Eexe$deanonpaged`09`09;`20deallocate`20it
X1$:`09movl`09r5,`20r0`09`09`09`09;`20get`20the`20main`20ones`20address
X`09jsb`09g`5Eexe$deanonpaged`09`09;`20deallocate`20it
X`09popl`09r0`09`09`09`09;`20retore`20status
X2$:`09setipl`09#0`09`09`09`09;`20set`20IPL`20back`20to`20zero
X`09rsb
X;
X;`20Allocates`20an`20AST`20Control`20Block`20(ACB)`20from`20nonpaged`20pool.
X;
X;`20Inputs:
X;`20Outputs:
X;`20`20`20`20R0:`20Status
X;`20`20`20`20R5:`20Address`20of`20ACB
X;`20Trashes:
X;`20`20`20`20R2,R3,R4
X;
Xalloc_buf_r5:
X`09movzwl`09#acb_k_length+code_length,`20r1`09;`20set`20size`20of`20ACB`20and
V`20extension
X`09jsb`09g`5Eexe$allocbuf`09`09`09;`20Allocate`20the`20buffer
X`09blbc`09r0,`20insfmem`09`09`09;`20No`20memory?
X`09movl`09r2,`20r5`09`09`09`09;`20copy`20address`20of`20ACB
X`09clrl`09acb_l_acb(r5)`09`09`09;`20say`20no`20chained`20ACB
X`09movb`09#dyn$c_acb,`20acb$b_type(r5)`09;`20set`20type`20to`20ACB
X`09movzbl`09#acb$k_length,`20r1`09`09;`20set`20size`20of`20ACB
X`09jsb`09g`5Eexe$allocbuf`09`09`09;`20Allocate`20the`20buffer
X`09blbc`09r0,`20insfmem1`09`09`09;`20No`20memory?
X`09movb`09#dyn$c_acb,`20acb$b_type(r2)`09;`20set`20type`20to`20ACB
X`09movl`09r2,`20acb_l_acb(r5)`09`09;`20copy`20address`20of`20ACB
X`09rsb
Xinsfmem:
X`09clrl`09r5`09`09`09`09;`20mark`20buffer`20as`20missing
Xinsfmem1:
X`09movzwl`09#ss$_insfmem,`20r0`09`09;`20say`20no`20memory`20available
X`09rsb
X;
X;`20The`20block`20of`20code`20between`20code_start`20and`20code_end`20is`20cop
Vied`20into`20nonpaged
X;`20pool`20to`20be`20executed`20by`20the`20remote`20process.`20Since`20to`20ex
Vecute`20the`20AST`20the
X;`20target`20process`20must`20execute`20an`20REI`20we`20dont`20have`20to`20do
V`20one`20ourselves.
X;
X;
X;`20Well`20here`20we`20are`20in`20remote`20process`20context.`20Special`20kern
Val`20ASTs`20must`20only`20use
X;`20R0-R5.`20R5`20must`20be`20preserved.
X;
X;`20Inputs:
X;`20`20`20`20R4:`20PCB`20address
X;`20`20`20`20R5:`20ACB`20address
X;`20Outputs:
X;`20`20`20`20R5:`20ACB`20address
X;`20Trashes:
X;
X;
+-+-+-+-+-+-+-+-  END  OF PART 4 +-+-+-+-+-+-+-+-
--
Neill Clift  neill@macro.demon.co.uk
