Consolidate license copies
[its.git] / sysdoc / usr.102
1 Copyright (c) 1999 Massachusetts Institute of Technology
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; either version 3 of the License, or (at
6 your option) any later version.
7
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 ------------------------------
17
18 JOBS IN ITS
19
20
21 @. ABSTRACT.
22
23 In ITS, a "job" is an entity that consists mainly of memory to hold
24 a program, registers to run it with, and I/O channels for it to do
25 I/O on through the system.  Whenever a program is
26 running, it must be running "in" some job.  Jobs are structured
27 into trees;  the root of a tree is a "top-level" job, and for any
28 job, the job one step closer to the root is the first job's superior;
29 the first job is one of its inferiors.  Normally, each user has
30 one tree of jobs, but he may also have a few other secondary trees.
31
32 Jobs may read anything associated with any job, but usually may write
33 only their direct inferiors.
34 \f
35 TABLE OF CONTENTS
36
37 A. OVERVIEW OF JOBS.
38
39 B. CREATING AND DELETING INFERIORS, AND OTHER METHODS OF CHANGING THE
40    0. OPENING THE USR: DEVICE - A BASIC TOOL.
41    1. CREATION
42    2. DELETION
43    3. DISOWNING
44    4. REOWNING
45    5. DETACHING
46    6. ATTACHING
47    7. LOGGING IN
48    8. LOGGING OUT AND GUNNING
49
50 C. CONTROL OF INFERIORS.
51    1. READING AND WRITING
52    2. SHARING MEMORY BETWEEN JOBS
53    3. LOADING
54       a. Resetting
55    4. DUMPING
56       a. Pure dumping
57       b. Impure dumping
58    5. STARTING AND STOPPING
59    6. HANDLING INTERRUPTS
60    7. DEBUGGING CONTROLS.
61    8. TTY PASSING
62
63 D. SYSTEM JOBS AND WHAT THEY DO
64    1. THE SYSTEM JOB.
65    2. THE CORE JOB.
66    3. DEMON JOBS.
67 \f
68 A. OVERVIEW OF JOBS.
69
70 Each ITS job has an address space, the slots of which may be filled
71 with various types of memory, perhaps shared with other jobs;  its own
72 set of accumulators (copied temporarily into the real ones when the
73 job is running);  a program counter (PC);  sixteen I/O channels, each of
74 which may be used to handle a device or file;  system "user variables"
75 with which the program in the job may communicate with the system;
76 and other variables used by the system in scheduling
77 or swapping the job, or as temporaries for system call routines.
78
79 The word "user" has two meanings on ITS: one is the human or other being
80 using a terminal;  the other is an individual "user job".  In specific
81 contexts either "job" or "user" sounds better for their common meaning.
82 A "program", however, is a more abstract entity;  the same program may
83 be running in several jobs (but using different files, etc. in each).
84
85 Each job is identified by two names, the UNAME and the JNAME, each of
86 which is up to six SIXBIT characters, left justified in a PDP-10 word.
87 They are available in the .UNAME and .JNAME user variables of the job.
88 These two names uniquely identify the job.
89 All the jobs in a tree must have the same uname.  Two trees may have
90 the same uname;  that usually means that they really correspond to the
91 same user.
92
93 Each job is also uniquely identified by its "job number" (or
94 "user number"), which is a small positive number.  This number
95 is the usual way to specify a job in a system call.  A job may find
96 out its own number by reading its .UIND user variable;  its superior's
97 is in its own .SUPPRO user variable.  The term "user index"
98 may mean, loosely, the job number, but more strictly it means the
99 job number times LUBLK, the length of the system's per-job data block
100 (the "user variable block").  Supported communications paths
101 between the user and the system use the job number, not the user index
102 itself, even if the term "user index" is used.
103
104 A job has several "user variables" which are really variables in the
105 system that pertain to it, and are readable by that job or others
106 using the .USET and .SUSET UUO's (see ITS UUOS).  Each user variable
107 has a name, which starts with ".".  User variables can be opened in
108 DDT just like memory locations, although what DDT does to access them
109 is a .USET.  Some user variables, such as .UIND, .SUPPRO, .UNAME and
110 .JNAME mentioned above, exist solely to be read by programs.  Others
111 also allow the program to tell the system how to treat it;  examples
112 are .OPTION, which contains bits that enable various system features,
113 and .MASK, which is used to enable user interrupts (see ITS INTRUP).
114 A complete list of user variables and what they contain is in the
115 file ITS USETS.
116
117 When a user connects to ITS by typing ^Z or CALL on a terminal, he is
118 supplied with a single top-level job using that terminal, running the
119 program "DDT" (on DM, "MONIT" is used instead).  The jname of that
120 job is always "HACTRN" (pronounced "hack-tran"),
121 and the job is called "a HACTRN".  The uname
122 will be three backarrows followed by three digits, identifying the tree
123 as non-logged-in.  "Logging in" is nothing other than altering the uname
124 of the hactrn to a more meaningful name.  It makes little direct
125 difference.
126 DDT and MONIT both provide facilities for creating other jobs for the
127 user, loading programs into them, and running them.  There are no user
128 commands per se for controlling jobs built into ITS;  instead, the
129 user gives commands to DDT or MONIT telling them to execute the system
130 calls to control his other jobs.
131
132 The two main types of job trees are the console-controlled trees and
133 the non-console-controlled (or "disconsolate") trees.  A console
134 controlled tree has one terminal which is "in use as a console" by
135 the whole tree.  All the jobs in the tree can refer to that terminal as
136 device TTY:.  The number of that terminal can be found in the .CNSL
137 variable of any job of the tree.
138 At any time, only one of the jobs in the tree has
139 permission to do I/O to the console;  that job is said to "own"
140 the console.  Ownership is transferred by means of .ATTY and .DTTY
141 UUO's executed by jobs in the tree (see ITS TTY).  If ^Z (or CALL on
142 TV's) is typed on a console, the job that owns it gets a fatal
143 interrupt.  The jobs may also have other terminals open "as devices",
144 but those can be in use only by a single job, not the whole tree.
145 The console-controlled trees are usually the ones with hactrn's at the
146 top.
147
148 Disconsolate trees do not have any console, but in all other respects
149 bahave just like console-controlled trees.  They may or may not be
150 "disowned".  If they are, they get worse treatment from the scheduler
151 and swapper, and also may be more conveniently "reowned" (made into a
152 subtree of another tree - see below).  Usually only system demons and
153 job-device handlers are disconsolate non-disowned trees.
154 Job-devices will have a .CNSL equal to that of the tree of the
155 job using the job-device.  Other disconsolate jobs will have a .CNSL
156 of -1 if they are scheduled as part of the system, or -2 if scheduled
157 as disowned jobs.
158
159 Jobs often refer to each other using a device, the "USR" device.  A job
160 may be opened on the USR device by specifying its uname and jname as the
161 opened filenames.  It is then possible to examine or deposit the job's
162 memory or user variables, etc.  This is why DDT, when it starts up,
163 mentions its uname and jname by saying "USR:<uname> <jname>".
164 The USR device should not be confused
165 with the JOB device, which is a mechanism for creating software devices
166 which enables the system calls that manipulate the device to be
167 simulated and handled by a user program, the job-device handler program
168 (See ITS JOBDEV).
169
170 The remainder of this file is devoted to desribing the ITS system calls
171 with which jobs may create, delete, sense and control other jobs.
172 \f
173 B. CREATING AND DELETING INFERIORS, AND OTHER METHODS OF CHANGING THE
174   TREE STRUCTURE OF JOBS.
175
176  0. OPENING THE USR: DEVICE - A BASIC TOOL.
177
178 Unfortunately, many different things are done by opening the
179 USR device in different ways in different situations.  They
180 include creation of inferiors, reowning disowned jobs, selection
181 of existing jobs (inferiors or not), and testing for the existence
182 of a job.  Opening USR is the ONLY way to do those things.  What's
183 more, a job's memory cannot be read or written without having a USR
184 channel open in the appropriate direction, and a job's user variables
185 cannot be read or written without at least one USR channel open in
186 either direction.  Thus, opening USR: is very important.  It is intended
187 that this mechanism will be made more rational in the future.
188
189 This section will describe what opening the USR device will do,
190 organised by how it is done.  Later sections will say what
191 to do to achieve a specific goal.
192
193 By convention, "USRI" and "USRO" are the canonical names in MIDAS
194 programs for the I/O channels used for opening the USR device for
195 input and output, respectively.  Their use in an inferior-handling
196 program is a sort of comment.
197
198 A USR: open always specifies two filenames.  Normally they are
199 the uname and jname of the job to be opened.  However, 0 may
200 be used as the first filename to specify your own uname.
201 If the second filename is 0, then the first is not really a
202 name but a job spec;  this crock makes it possible to open a
203 job known only by its number.
204
205 A USR: open must also ask for either block mode or unit mode.
206 Right now SIOT on unit mode USR channels is not as efficient as
207 IOT on block mode channels, so it is usually better to open in
208 block mode.  In any case, this choice is orthogonal to everything
209 else.
210
211 All USR: opens should specify image mode.  Ascii mode doesn't now
212 exist for the USR device, and if you ask for it you will get image
213 mode instead, so for compatibility with the future you should ask
214 for image mode.
215
216 There are four things specified in each USR open that affect the
217 actions taken in important ways.  They are the two filenames,
218 the direction, and the device-dependent bit 1.4 of the open-mode,
219 known here (and inside ITS) as UBPFJ.
220
221 If UBPFJ is set, the open may be for reading only, and will fail with
222 code 4 if the job specified by the uname and jname does not exist.
223 If the job does exist, it will be opened as a "foreign job", which
224 means that the opening job may not modify it at all using the
225 channel opened in this way.  Also, the process of opening the job
226 with UBPFJ is guaranteed not to alter it.  This style of open is
227 good for asking whether a job exists with particular names.
228
229 Without UBPFJ, if the open is for writing, then
230 if a job with the specified uname and jname exists and is the
231   inferior of the job doing the open, it will be opened for
232   writing, with no special side effects.
233 If a job with the specified names exists and can be reowned
234   (it is a top-level disowned job), it will be reowned, and
235   opened for writing.  Reowning may change its uname or jname,
236   so whenever an open might reown a job the program should
237   read back the uname and jname of the opened job just in case.
238 If no job with the specified names exists, then an attempt is
239   made to create an inferior by that name.  If the specified
240   uname isn't the same as yours, that is impossible, and the open
241   fails with code 20.  If you already have the maximum number of
242   inferiors, it fails with code 5.  If there are no job slots available,
243   it fails with code 6.  If the attempt succeeds, the new inferior
244   is opened for writing.
245 Otherwise (a job with the specified names exists, but isn't
246   an inferior of the running job already and can't be made one
247   by reowning it), the open fails with code 12.
248 Note that if an open for writing succeeds, you know the job that
249 is open is your inferior (thought it might not have been so before).
250
251 An open for reading, without UBPFJ, is like an open for writing
252 except that when the job exists but isn't an inferior and can't
253 be reowned, it will be opened as a foreign job (as if UBPFJ were 1).
254
255 To understand these possibilities better, think of the FOO$J command in
256 DDT, which means, essentially, "open the job named FOO".  That command
257 will reselect a job named FOO if there is one;  if not, it will create
258 one.  If there is a job named FOO that isn't a direct inferior of DDT,
259 it will be selected, but will be unwriteable (DDT will type a "#").  If
260 there is a disowned job named FOO, it will be reowned (made into an
261 inferior of DDT), and DDT will type ":$REOWNED$").
262
263 There is no easy way to tell after the fact what has happened when
264 an open without UBPFJ has succeeded.  You know you have an inferior,
265 if an open for writing succeeds,
266 but whether it is new, reowned or old is forgotten.  If you care,
267 you should find out in advance what is going to happen by doing
268 an open with UBPFJ set.  If it fails, you will get a newly created
269 inferior.  If it succeeds, look at the .APRC and .SUPPRO user variables.
270 If both are negative, you have a top-level disowned job which
271 would be reowned.  If .SUPPRO equals your .UIND variable, the
272 job is your inferior already.  Otherwise, an open for writing
273 would fail, and an open for reading would open it as a foreign job.
274
275 Some information is still available after an open.
276 The job's .UPC variable will be nonzero iff the job has ever run
277 (because the user-mode bit, %PCUSR, will be 1).
278 If the job has been run, then it certainly wasn't just created.
279 Also, if the job's uname or jname was changed by the open, then
280 it must have been reowned.
281
282  1. CREATION
283
284 In order to create an inferior, one must choose a jname for it.
285 Its uname will have to be the same as its creator's, and together
286 the uname and jname must be unique among all jobs in existence.
287 An attempt to create an inferior looks just like an attempt to
288 open an existing job, so if the would-be creator is mistaken about
289 the uniqueness of the jname it may get confused (a way out of this
290 problem is described later).
291
292 Given a jname which isn't in use, an inferior of that name may be
293 created by simply opening the USR device with the uname and jname
294 as filenames, as in section 0.  You should open a channel in each
295 direction (call the input channel USRI and the output channel USRO).
296 If you are unwilling to try to live with a foreign job, do the
297 output open first.
298
299 One way to make sure of getting a newly created job is to check
300 in advance that the names are not in use, by opening them with
301 UBPFJ (see section 0) before actually trying to create the job.
302 If the test open succeeds, close the channel again and
303 pick a new jname.
304
305 The new inferior will have 1K of zeroed unshared core,
306 and will not be running (its .USTP will be nonzero).
307
308 Then, if you wish to handle interrupts from the inferior,
309 read the inferior's interrupt bit, which may be found in
310 the inferior's .INTB variable, and remember it somewhere.
311 That is the bit .IFPIR on which YOU will be interrupted,
312 if the inferior gets a fatal interrupt.
313
314  2. DELETION
315
316 Inferiors do not need to remain open to continue to exist.  Simply
317 closing the channels one is open on does not delete it;  it is
318 merely hard to refer to until it is opened again.  This is so
319 that it is possible to have many inferiors without tying up many
320 I/O channels.  When it IS desired to delete an inferior, the
321 .UCLOSE uuo should be used:
322
323         .UCLOSE <channel>,
324
325 This uuo kills the inferior open on <channel>.  All the channels
326 it is open on are closed.  The uuo does not skip.
327 If a foreign job instead of an inferior is open, all the channels
328 in this job that it is open on are closed, but it is not killed.
329 If there isn't a job open on the specified channel, an ILOPR
330 interrupt happens.
331
332  3. DISOWNING
333
334 Disowning an inferior causes it to continue to exist, but no longer
335 as your inferior.  This can be useful for two reasons:
336 1) you wish to log out but want the inferior to remain, or
337 2) you want the job to become someone else's inferior.
338
339 Disowning is done with the DISOWN system call, as follows:
340
341         .CALL [ SETZ ? 'DISOWN
342                 401000,,<job spec>]
343          .VALUE
344
345 It fails if the specified job isn't an inferior of the executing one.
346 If it succeeds, the specified job and its inferiors become
347 a separate disowned tree, of which the specified job is the top.
348 All channels on which the running job had that job open are closed.
349 See the DISOWN symbolic system call for more details and features.
350
351  4. REOWNING
352
353 A top-level disowned job may be "reowned" (made one's inferior)
354 by opening it with bit 1.4 of the mode set to 0.  The uname of
355 every job in the reowned tree will be changed to equal that of
356 the reowning job, if necessary.  If as a result the uname/jname
357 pair of one of the reowned jobs is no longer unique, the jname
358 will be altered until the uname/jname pair is unique.
359
360 Another way to reown a job is to use the REOWN symbolic system
361 call.  The job to be reowned should already be open on an I/O
362 channel as a foreign user;  the REOWN will cause it to be open
363 as an inferior instead on the same channel.  An example is:
364
365         .CALL [ SETZ ? SIXBIT/REOWN/ ? 401000,,USRI]
366          .VALUE
367
368 In DDT, selecting a job that may be reowned will always reown it.
369 DDT will type ":$REOWNED$" when that happens.  If the uname or
370 jname changes, DDT will type the new names.
371
372  5. DETACHING
373
374 An entire tree may be made disowned, have its console taken
375 away from it, or both, with the DETACH system call.  The goal might
376 be to free the console for other use, or to make the tree into
377 a subtree of another tree by reowning it.
378
379  6. ATTACHING
380
381 Attaching is the operation of connecting a terminal to a tree
382 as the tree's console.  The simplest kind of attachment takes
383 a free console and a disowned tree and connects them.  A top-level
384 console-controlled job may also attach one of its inferiors to
385 its console;  this has the same effect as if it were to disown
386 the inferior, detach itself, and then attach the erstwhile inferior
387 to the now free console, except that it happens more smoothly.
388 DDT's :ATTACH command uses the second flavor of ATTACH.  See the
389 ATTACH system call for more details.
390
391  7. LOGGING IN
392
393 When the system creates a top-level job (such as a HACTRN), its uname
394 will be three "_"'s followed by three unique digits.  The job may
395 change its uname to one that gives more information to humans by
396 "logging in", which simply sets the uname.  The job must not have any
397 inferiors at the time;  the new uname must not start with "___" and
398 must not be in use.  A logged-in job may not log in again, but it may
399 change its uname with a .SUSET of .UNAME.
400 Logging in is done with the LOGIN symbolic system call, as follows:
401
402         .CALL [ SETZ ? SIXBIT/LOGIN/
403                 SETZ [<new uname in sixbit>]]
404          .VALUE
405
406 The system call takes an optional third argument which now should be
407 used only by network server telnet jobs.  For them, its hould be the
408 sixbit string "HSTnnn", where nnn is the octal number of the foreign
409 host.
410
411  8. LOGGING OUT AND GUNNING
412
413 A top-level job may delete itself, and all its inferiors, by "loggin
414 out".  This is done with the .LOGOUT UUO, as follows:
415
416         .LOGOUT
417
418 The UUO returns only if it fails (the job isn't top level);  it does not
419 skip.  Programs that do not normally run in top-level jobs might
420 nevertheless be run in disowned jobs sometimes, so they should always
421 try to log out before requesting another command string or trying to ask
422 DDT to kill them.
423
424 A job may force any top-level job to log out by "gunning" it, using the
425 .GUN UUO.  The user index of the job to be gunned must be known.  The
426 way to do it is:
427
428         MOVEI AC,<usr idx>
429         .GUN AC,
430          JRST LOSE      ;FAILED - JOB DIDN'T EXIST OR WASN'T TOP LEVEL.
431         ...             ;SUCCEEDED.
432
433 Gunning should go on only between consenting adults.
434 \f
435 C. CONTROL OF INFERIORS.
436
437 Jobs can control their inferiors by means of several special-purpose
438 system calls.  The more specific of them are documented below under
439 their uses.  One more general one is .USET, which allows the inferior's
440 "user variables" to be read or set.  For example, when section C.5.
441 speaks of "setting the job's .USTP variable", a .USET is meant.  The
442 way to set the .FOO variable with a .USET is this:
443         .USET <channel>,[.SFOO,,[<new value>]]
444 Thus,   .USET <channel>,[.SUSTP,,[0]] will stop the job open on channel
445 <channel>.
446         .USET <channel>,[.RFOO,,TEMP] will read the value of the .FOO
447 variable into TEMP.
448 For a complete description of the available .USET variables, and more
449 features of .USET, see the file ITS .USETS.
450
451  1. READING AND WRITING
452
453 Reading or writing the contents of another job requires having the job
454 open on a USR device channel.  It is done by .IOT'ing on that channel;
455 thus, reading requires an input channel and output requires an output
456 channel.  Selection of the region to read or write is done by setting
457 the channel's access pointer with .ACCESS.  At the moment, SIOT on unit
458 mode USR channels is not very efficient, so it is best to open a job in
459 block mode.  That requires one extra instruction when transferring a
460 single word, which is a slight cost when compared with the ease of
461 transferring several words.
462 Note that ascii mode does not exist for the USR device - all channels
463 should be opened in image mode.
464
465 For example, to read the word at 500 into A, do
466
467         .ACCESS USRI,[500]
468         HRROI B,A
469         .IOT USRI,B
470
471 assuming that USRI is the USR input channel.  This clobbers B.
472 To write A into the word at 500, do
473
474         .ACCESS USRO,[500]
475         HRROI B,A
476         .IOT USRO,B
477
478 assuming that USRO is the USR output channel.  This clobbers B.
479
480 If a non-existent location in another job is read or written
481 with an IOT, an MPV interrupt results.  The .MPVA variable
482 of the job doing the reading will point at the non-existent
483 page of the other job.  (Actually, in ITS before version 1017,
484 when a non-existent page is written, the system may give an MPV,
485 or may do a .CORE on the inferior so that it has enough core
486 to make the IOT succeed.  ITS version 1017 and up will
487 always MPV).
488
489  2. SHARING MEMORY BETWEEN JOBS
490
491 Another way to refer to the core of other jobs is to share
492 memory with them.  The slots of a job's page map should be
493 understood to be pointers to pages;  one page may be pointed
494 to independently by several slots in several jobs' page maps.
495 The CORBLK call can be used to copy other jobs' pointers to pages
496 into one's own job, resulting in shared memory.  Of course,
497 the memory will not have the same address in both slots
498 unless that is specificaly arranged for.
499 Unfortunately, other jobs' accumulators cannot be referred to
500 via memory sharing, since they are not stored anywhere in
501 the job's memory even when the job isn't running.
502
503  3. LOADING
504
505 Loading a binary file into a job is not actually a fundamental
506 operation, since it could be done by a program that understood
507 the format of the binary file and deposited in appropriate
508 locations in the job being loaded.  However, for convenience'
509 sake, the LOAD system call exists for loading a binary file
510 into an inferior, or into the running job itself.  Both types
511 of ITS binary files may be loaded with LOAD;  it is not necessary
512 to know which type of file is being loaded.  Unfortunately, this
513 call works only for disk files.  For other devices, the program
514 must do it the hard way.  Code may be copied from DDT for that
515 purpose.
516
517 The LOAD system call takes two arguments:  the job to be loaded,
518 and the file to load.  The first is expressed by a job spec;  the
519 second, by a channel number.  For example,
520
521         .CALL [ SETZ ? SIXBIT /LOAD/
522                 1000,,-1        ;into myself
523                 401000,,DISKC]  ;the file open on DISKC
524          .VALUE
525
526 The LOAD will leave the disk channel set up to read the file's
527 start instruction, which is a jump to the starting address, or
528 zero if there is no starting address.  After that word in the
529 file should come the symbol table and another copy of the start
530 instruction;  see DDT ORDER for their format.
531
532 Loading a PDUMP file (pure file) inserts pages into the job
533 as specified by the file.  It does not alter the pages of the
534 job that the file has no data for.  It also does not alter the
535 accumulators, even if page 0 is loaded.  Loading an SBLK file
536 (impure file) alters only the words of the job that the file
537 specifies data for.  The other words are NOT cleared.  If data
538 are specified in a nonexistent page, fresh memory will be
539 put there, and also in all nonexistent pages below it in the
540 address space!  Thus, if an impure dump is made of a job containing
541 nonzero data only at address 100000, the resulting file when
542 loaded will create core up through address 101777, even though
543 only the last page of that is actually being loaded.  This
544 unfortunately cannot be changed, but often causes trouble.  For
545 that reason (and many others), it is hoped that there will be
546 a new, more versatile binary format some day.
547
548   a. Resetting
549
550 Loading per se modifies only the locations that the binary file
551 specifies data for.  It does NOT clear the rest of core.  If you
552 want to do that, chances are that you really want to RESET the
553 inferior.  To do that, use the .RESET UUO or the RESET symbolic system
554 call on an I/O channel with the inferior open.
555
556 RESETting a job deletes all of its core, provides it with a single
557 page of unshared writeable core, closes all the job's channels,
558 kills all of its inferiors, and re-initializes most of the job's
559 system variables.  Most notably not cleared out are the job's
560 translation lists for filenames.
561
562  4. DUMPING
563   a. Pure dumping
564   b. Impure dumping
565  5. STARTING AND STOPPING
566
567 An inferior may be started (caused to run) by setting its .USTP
568 variable to zero.  It will continue with whatever PC it has.
569 To set the PC, store the desired new PC in the .UPC variable.
570
571 An inferior may be stopped by setting the .USTP variable to
572 nonzero.  The exact value deposited in .USTP will be forgotten
573 since it corresponds only to a single bit of real storage.
574 This is how the system stops a job which gets a fatal interrupt.
575
576 DDT has another way of stopping a job, which it uses in executing
577 the ^X command: it turns on bit %PIC.Z of the job's .PIRQC, causing
578 a fatal ^Z-typed interrupt in that job.
579 This not only makes the system set the job's .USTP, but causes
580 DDT's interrupt handler to find out about the stoppage of the
581 job and be properly faked out.
582
583  6. HANDLING INTERRUPTS
584
585 Every job has the ability to enable interrupts on several conditions
586 (see ITS INTRUP).  Among those conditions is the occurrence of a fatal
587 error interrupt in an inferior.  This is the mechanism that enables
588 a job to "return to DDT" deliberately - it simply causes a fatal
589 interrupt in itself.  This is also how DDT knows when an illegal
590 instruction is executed by an inferior.
591
592 Whenever a job acquires an inferior (by creation or reowning), one
593 of the job's interrupt bits is assigned to that inferior.  Each
594 inferior has its own interrupt bit.  There are exactly eight
595 interrupt bits which can be used for that purpose, which is why a
596 job can have at most eight inferiors at a time.  Those eight are
597 all located in the left half of the .IFPIR variable.
598
599 The superior should find out which interrupt bit was assigned by reading
600 the inferior's .INTB variable, in which that bit alone will be 1.
601
602 See ITS INTRUP for more details.
603
604 The two system calls .VALUE and .BREAK exist solely so that a job can
605 cause a fatal interrupt to signal its superior.  DDT has standard
606 interpretations for those instructions;  see .INFO.;DDT ORDER.
607
608  7. DEBUGGING CONTROLS.
609
610 These features exist to facilitate debugging.  They work currently on
611 KA-10's only, though they will be extended to KL-10's eventually.
612 They are generally used and controlled only by the superior of the
613 job on which they are acting, to which they are generally transparent.
614
615   a: One-proceed.
616
617 If appropriate bits in a job's PC are set, that job will be
618 able to execute one more instruction and then will get a fatal
619 %PI1PR interrupt.  This feature is used by DDT's "single step"
620 command (^N).  Which bits to use depends on the processor type:
621 for KA's, %PC1PR is the right bit (it is an 18 bit quantity, to
622 be OR'ed into the flags);  for KL's, %PS1PR is right.  On any
623 machine, the symbol OIPBIT will be defined in the ITS symbol
624 table as either %PC1PR,, or %PS1PR,, , whichever is appropriate.
625
626   b: Address-stop (MAR).
627
628 The MAR feature makes it possible to trap all references to a
629 particular address.  When the specified location is referred to
630 ("the MAR is hit"),  the inferior will get a fatal %PIMAR
631 interrupt, which may or may not allow the instruction that
632 tripped the MAR to finish.  The MAR is turned off when it is
633 hit and must be turned on again explicitly or it will stay
634 off forever.
635
636 The MAR is controlled by the .MARA user variable.  Its RH
637 contains the address to be traced.  Its LH contains the control
638 code, which is 0 to turn the MAR off, 1 to trap instruction
639 fetches only, 2 to trap writes only, and 3 to trap all
640 references.  There is also a variable .MARPC which, after
641 the MAR is hit, contains the address of the instruction that
642 hit it.  In addition, the indirect bit will be set on KA's
643 if the instruction that hit the MAR was completed (on KL's,
644 the instruction is always aborted).
645 On KL's, after a MAR, the job's PC (.UPC) will have %PSINH
646 set, which will inhibit MAR hitting for one instruction
647 when the job is continued.
648 The job's PC in .UPC should NOT be used to locate the
649 instruction that hit the MAR, since if the instruction was
650 not aborted and was a jump, the PC will be the address
651 jumped to.  Even if it wasn't a jump, it might have skipped.
652
653   c: .JPC - Last Jump Address.
654
655 The user variable .JPC always contains the address of the last
656 jump instruction executed in the job.  It can be used, for
657 example, to trace a job backward from the point of failure by
658 putting in a breakpoint, examining the .JPC when the breakpoint
659 is hit, and running the program again with the breakpoint now
660 located at the previous jump, etc.  Unfortunately, subroutine
661 calls (including user-trapping UUOs) alter the JPC, even though
662 the information is redundant for them, but returnable UUO's and
663 interrupts do not.  For that reason, after a returnable UUO
664 or interrupt a program should always read .JPC before jumping
665 anywhere, for debugging purposes.  The canonical names UUOJPC
666 and INTJPC exist for the locations .JPC is saved in.  Also,
667 error-handling uuos used by the program should be returnable
668 uuos rather than direct user-trapping uuos, so that the JPC
669 will be meaningful.  The vectored interrupt mechanism has the
670 ability to store .JPC automatically on each interrupt (see
671 ITS INTRUP).
672
673  8. TTY PASSING
674
675 For now, see under .ATTY and .DTTY in ITS TTY.
676 \f
677 D. SYSTEM JOBS AND WHAT THEY DO
678
679 There are two jobs built into the system, that run in exec mode
680 and perform housekeeping tasks;  they are the system job and
681 the core job.  There are also various "demon" jobs that exist
682 at times which, though receiving no special treatment from the
683 system, may be regarded as part of it in that they provide a
684 system-wide service.
685
686  1. THE SYSTEM JOB.
687
688 This job, whose full name is SYS SYS, provides a great many
689 independent services;  it is really a timesharing system for
690 many trusting processes, each of which is controlled by a
691 single bit in the system variable SUPCOR.  Setting the bit for
692 a process causes the process to run, and clear the bit.  The
693 process should never run for very long, or it may tie up the
694 system by making the services of the other processes
695 unobtainable.  If a process wishes to run continually, it does
696 so by setting its bit in SUPCOP.  SUPCOP is or'ed into SUPCOR
697 every second, so a process whose bit in SUPCOP is set will be
698 run again that often.  The process is always started the same
699 way, but it can of course have state variables.
700
701 The reasons why a given activity may involve the system job are
702 1) it may wish to print a message on the system log terminal, or
703 2) it may need to run in a job (eg, do system calls), but not be
704 associated with any one job, or 
705 3) it may need to be able to hang up for short periods of time,
706 but the need to do it may be noticed at a time when that is
707 impossible, or
708 4) it needs to be done once every two minutes or every two hours.
709 The routines for those "very slow" and "super slow" clocks are in
710 the system job.
711
712 Re-initialising the connection to the IMP is an example of reasons 1
713 and 2.  Typing "console free" messages is an example of reason 3 - it
714 involves doing I/O to the terminal, but it isn't done until the last
715 stage of killing a tree, when waiting of any sort would allow PCLSR'ing,
716 which would leave things in a screwed-up state.  An example of reason 4
717 is the detection of core-link files which have not been used for more
718 than 2 minutes.
719
720 A complete list of the system job's functions follows:
721
722   a: Allocating or Deallocating Memory for Job Slots.
723
724 Most of the memory occupied by the system is marked as belonging to
725 the system job.  For that reason, the way more is allocated for user
726 variable blocks is by having the system job do a .CORE UUO.  This is
727 somewhat of a historical crock.  Creating a job does not require such
728 allocation if there are free slots in the memory already allocated. 
729 However, it may need to.  For that reason, if the system job is hung
730 up, often jobs cannot be created.
731
732   b: Printing Various Messages on All Terminals.
733
734 Sometimes, messages such as "ITS GOING DOWN IN ..." or "ITS BEING
735 DEBUGGED" are printed on all the terminals in the world.  It is the
736 system job that prints them on terminals which are free.  Consoles have
737 them printed by DDT, however.
738
739   c: Checksumming the Constant Areas of the System.
740
741 The system job is always checksumming parts of the system and comparing
742 the checksums with those previously calculated.  This mechanism causes
743 the clobberage of a word in the code of the system to be detected.  If
744 only a single word in an area is clobbered, which word it is and the
745 original contents can be detarmined.  In any case, a message is printed
746 on the system log terminal when clobberage is found.
747
748   d: Determining the Date and Time.
749
750   e: Detaching Trees.
751
752 When a top-level job is halted by a fatal interrupt, it is the system
753 job which executes the DETACH system call to detach it.  Similarly, it
754 is the system job which detaches trees controlled by TV terminals when
755 the TV system crashes, and trees controlled by dialup lines whose
756 connections are broken (only when the hardware can detect that).
757
758   f: Depositing  in the System.
759
760 When a job deposits in the system using .SETLOC or .IFSET, the system
761 job is informed so that it can update its checksums and avoid a system
762 clobbered" message.  It also makes the change.
763
764 This used to be a great screw, in that if the system job were hung, it
765 could not be fixed by depositing in the system.  Now, .SETLOC will do
766 the work itself without calling the system job, if the system job
767 appears to be hung.
768
769   g: Printing "Console-free" Messages.
770
771 When a terminal ceases to be in use, the system job is signalled to look
772 at all terminals and print console-free messages on all those which have
773 recently stopped being in use.
774
775   h: Logging Out.
776
777 The final stages of killing a job must be run by some other job.  When a
778 top-level job is being killed, it does some of the work itself (kills
779 its inferiors and closes its channels).  That is to make sure the
780 system job never hangs up trying to do it.  The rest of the work is
781 then done by the system job, which can afford to wait for short peiods
782 of time when the job is almost killed.
783
784   i: Reinitialising the NCP.
785
786 When the connection to the ARPA network goes down, the system job gives
787 interrupts to all the jobs using the network, and also checks every so
788 often whether the network is useable again.
789
790   j: Printing of Various Messages on the System Log Terminal.
791
792 Events which cause messages on the log terminal include logging in,
793 logging out, writing on a directory whose name starts with "SYS",
794 garbage-collecting a disk directory, creating a disk directory,
795 gunning, parity errors, NXM errors.
796
797   l: Spooling the LPT.
798
799 On the AI KA-10 and the ML KA-10, the system job checks periodically for
800 spooled files and prints them.
801
802   m: Starting Other Demons.
803
804 On DM, the system job checks for any domon programs which have been
805 signaled.  If there are any, it loads them into newly created jobs
806 and starts them.
807
808   n: Reinitialising the TV System, or Noticeing that it is Down.
809
810  2. THE CORE JOB.
811
812 This job, whose full name is CORE JOB, allocates core to jobs that
813 request it, and also frees up memory for use as user variable blocks,
814 which have to be allocated consecutively, by relocating the old
815 contents.  Before there was pageing, the core job used to do shuffling.
816
817  3. DEMON JOBS.
818
819   a: The Comsat.
820
821 This demon, always named after some spacecraft or rocket, is responsible
822 for handling mail.  Requests to send mail are placed in the .MAIL.
823 directory, and are eventually processed by the demon.  The demon is
824 necessary because it may not be possible to send mail to other machines
825 right away, and in any case the user should not have to wait the time
826 it takes.  It also provides other services such as forwarding.
827
828   b: NAMDRG.
829
830 This demon maintains the list of logged in users which appears on all
831 free TV consoles.  It also updates a file saying when every user
832 logged out last.  It exists on the AI KA-10 only.
833
834   c: PFTHMG DRAGON.
835
836 This demon updates the logout times file and keeps track of each user's
837 total CPU time.  This demon originated on the ML KA-10, but has run on all
838 ITS machines at one time or another.
839
840 \f