home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / mint / mint_doc / mint.doc
Encoding:
Text File  |  1990-09-17  |  33.8 KB  |  680 lines

  1. MiNT is Not TOS: A Multitasking Operating System Extension for the Atari ST
  2.  
  3. Copyright 1990 Eric R. Smith. All rights reserved. See the file COPYING
  4. for conditions of redistribution.
  5.  
  6. WARNING: This program does some very low level things to your computer.
  7. MiNT works well on my machine, and I trust my data to it. But
  8. then, I make regular backups, so even if a horrible bug in MiNT that
  9. I haven't found yet trashes my hard drive, I won't lose much. You'll
  10. have to decide for yourself about trusting your data to MiNT. I would
  11. certainly recommend regular backups in any event.
  12.  
  13. MiNT COMES WITH ABSOLUTELY NO WARRANTY, NOR WILL I BE LIABLE FOR ANY
  14. DAMAGES INCURRED FROM THE USE OF IT. USE ENTIRELY AT YOUR OWN RISK!!!
  15.  
  16. Introduction
  17.  
  18. MiNT is an extension of (and eventually, I hope, a replacement for) TOS.
  19. It provides extra services such as multitasking and pipes. If you don't
  20. know what those terms mean, MiNT is probably not for you -- at this stage,
  21. MiNT is still very incomplete and should be regarded as "experimental".
  22.  
  23. MiNT will run a great number of ("most", I hope) TOS programs, including
  24. GEM. As the name says, though, MiNT is not TOS, so it can't be expected to
  25. run all TOS programs, or even all well-behaved TOS programs. There are two
  26. classes of incompatibilities with TOS: bugs and features. Bugs are undoubtedly
  27. present; if you find any please report them to me. There are also some
  28. features of MiNT that may cause incompatibilites. Most of these are listed
  29. in the accompanying "features" file. 
  30.  
  31. MiNT tries to emulate TOS 1.4 very closely. If you have TOS 1.0 or 1.2,
  32. you may think you can use MiNT instead of buying TOS 1.4. This isn't really
  33. a very good idea, because MiNT calls TOS, and so having the newer version
  34. of TOS will really speed things up. Besides, the GEM that comes with TOS 1.4
  35. is a lot better than the old GEM.
  36.  
  37.  
  38. Using MiNT
  39.  
  40. MiNT can be started from an AUTO folder, by setting it as an AUTO boot program
  41. on the desktop (TOS 1.4 or higher only) or by running it. I prefer the AUTO
  42. folder way myself.
  43.  
  44. If you put it in an AUTO folder, it should be the last thing in the folder
  45. (since any later programs in the folder will run only after MiNT is finished,
  46. and MiNT should never finish). You'll have to start GEM up seperately; a
  47. program ("gem.prg") is provided for this purpose.
  48.  
  49. MiNT always tries to run a program named "init.prg" in the current directory
  50. (which is the root directory if MiNT was started from an AUTO folder).
  51. This can be your favorite shell, or (if GEM is not yet active when MiNT runs)
  52. gem.prg.
  53.  
  54. Once MiNT is running, the computer should behave just as it does under TOS,
  55. except that some new drives (Q, V, and X) will be available, background
  56. processes can be started, and programs can use the new features of MiNT.
  57.  
  58. MiNT can be asked to provide a trace of the currently executing programs.
  59. Hitting CTRL-ALT-F1 increases the debugging level; hitting CTRL-ALT-F2
  60. decreases it, and hitting CTRL-ALT-F3 sends the output to the printer
  61. instead of the screen. This feature was designed to aid in debugging MiNT
  62. itself, but can also be useful in finding problems with user programs.
  63. Debugging level 0 (the normal) prints messages only when something goes
  64. seriously wrong inside of MiNT itself. Debugging level 1 prints a message
  65. when any system call fails. Debugging level 2 provides a (sickeningly)
  66. exhaustive trace of what's going on in the system.
  67. CTRL-ALT-DEL provides a (warm) boot, as in TOS >= 1.4, and
  68. CTRL-ALT-SHIFT-DEL provides a cold boot.
  69.  
  70. Some other keys are recognized by MiNT if the process is doing I/O in
  71. "cooked" mode:
  72. ^C (CTRL-C): interrupt running program with signal SIGINT. This (usually)
  73.     will kill the process, unless it has made arrangements to catch it.
  74.     Note that ^C takes effect immediately under MiNT, whereas under TOS
  75.     it only takes effect when the process reads or writes.
  76. ^\: send a QUIT signal to a process; usually the same end result as ^C, but
  77.     it is guaranteed to kill a TOS program (only MiNT specific programs
  78.     know how to catch it). Use with caution.
  79. ^Z: suspend the current process
  80.  
  81. These keys do *not* have any effect on processes operating in "raw" mode,
  82. such as editors.
  83.  
  84.  
  85. Pseudo Drives
  86.  
  87. MiNT provides some fake "disk drives"; if the contents of these drives
  88. are listed, various "files" are shown. These "files" are not necessarily
  89. real files, but may represent other objects such as executing programs or
  90. regions of memory.
  91.  
  92. The following drives are available:
  93.  
  94. Drive Q:: contains files which are FIFO queues (e.g. pipes). All files
  95. created on drive Q are temporary; when the last program using a FIFO
  96. closes it, it is erased. Normally, drive Q will be empty, but it will
  97. have items on it when you're running a window manager, print spooler,
  98. or similar program that uses FIFOs or pseudo-ttys for communication.
  99.  
  100. Drive V:: contains files which correspond to the BIOS devices; this allows
  101. you to access these devices from within programs. For example, saving an
  102. ASCII text file to "V:\PRN" should cause it to be printed on your printer.
  103. Of course, this will work *only* with ASCII data, so don't expect to get
  104. anything meaningful printed if you try to save your spreadsheet to "V:\PRN"!
  105. The following devices are available:
  106.    PRN: printer
  107.    AUX: auxiliary (RS232) port
  108.    MDI: midi port
  109.    KBD: intelligent keyboard controller
  110.    CON: current control terminal (NOT necessarily the keyboard/screen!)
  111.    TTY: same as above
  112.    FD0: current file handle 0 (standard input)
  113.    FD1: current file handle 1 (standard output)
  114.    FD2: current file handle 2 (standard error)
  115.    PHY: (physical console) the keyboard/screen
  116.    MOUSE: the mouse
  117.    NULL: a null device (like Unix's /dev/null)
  118.  
  119. The "FDx" file handles are useful for providing I/O redirection to programs
  120. that normally require file names on the command line; for example, if you
  121. want to run such a program in a pipeline.
  122.  
  123. Drive X:: listing this drive gives information about currently executing
  124. processes, such as whether they're running, ready, or waiting, their process
  125. i.d. numbers, and the amount of memory they've taken. Deleting one of the
  126. "files" kills the corresponding process. (Killing MiNT is impossible;
  127. killing GEM is a very bad idea). The "files" will have names like "INIT.001";
  128. this means that the process name is "INIT" (presumably because it was started
  129. from a file like "INIT.PRG"), and its process i.d. is 1. You can rename
  130. processes just as if they were files, except that any extension you give is
  131. always replaced with the process i.d. (e.g. if you rename INIT.001 to FOO.BAR,
  132. it will really become FOO.001). The size of a process is the amount of memory
  133. that is allocated to it. Its date/time stamp reflects how much processor
  134. time it has consumed; for example, a process that has consumed 27 hours,
  135. 13 minutes, and 6 seconds of computer time will have a date of Jan.2, 1980
  136. and a time of 03:13:06 (because of the way GEMDOS stores dates, the "0"
  137. point is midnight, Jan. 1, 1980). A process' current state is reflected
  138. by its attribute bits; most of these are not visible from the desktop, alas,
  139. but here are the combinations and their meanings:
  140.     attribute      process state
  141.       0x00        currently running
  142.       0x01        ready to run
  143.       0x20        waiting for an event (e.g. for a child to finish)
  144.       0x21        waiting for I/O
  145.       0x22        zombie (exited, but parent doesn't know yet)
  146.       0x02        terminated and resident
  147.       0x24        stopped by a signal
  148. Deleting a "file" on drive X: will send a SIGTERM signal to the corresponding
  149. process, which will usually result in that process being terminated. It
  150. is not possible to delete processes which are terminated and resident,
  151. or zombie processes.
  152.  
  153. Note that pseudo-drives are not yet very well integrated with GEM. In
  154. particular, the TOS 1.0 desktop won't recognize drives above P. TOS 1.4 will;
  155. I haven't tried TOS 1.2. File selectors may not present these drives as
  156. an option, either, but typing the full path and name of a file (e.g. V:\PRN)
  157. should work OK.
  158.  
  159.  
  160. Background Processes
  161.  
  162. Programs may be started in the background. A sample program ("bg.ttp")
  163. is provided that will do this for you. It works best from a shell;
  164. for example, to make foo.ttp in the background from gulam, type:
  165.     cd \foo\src
  166.     bg.ttp -o make.out make foo.ttp
  167. The "-o make.out" tells "bg" to redirect the command's standard tty,
  168. output, and error output (handles -1, 1, and 2) to "make.out".
  169. You might also want to redirect the standard input from an empty
  170. file, or from a file that will never have input waiting (like V:\NUL)
  171. so that "make" won't try to read anything from your console.
  172.  
  173. Shells designed to work with MiNT (for example, the "init.prg" that is
  174. provided) may use the Unix "&" notation for running processes in the
  175. background; with this notation, the job above would be:
  176.     cd \foo\src
  177.     make foo.ttp >make.out &
  178. (here the ">make.out" is the notation for redirecting the standard output
  179. of a process). Note that the sample shell does not provide a way of
  180. redirecting the standard error output; however, it does provide job
  181. control (see below), and processes that try to write on the terminal
  182. will be stopped automatically.
  183.  
  184. Only one GEM program can be active ("ready") at a time. This essentially
  185. means that GEM programs cannot be run in the background. It wouldn't
  186. make much sense, anyways, since GEM programs take over the whole screen.
  187.  
  188.  
  189. Pipes
  190.  
  191. Pipes are special files that are used to communicate between processes. The
  192. data in a pipe is always in memory, so using a pipe instead of a temporary
  193. file is usually faster; it also doesn't consume disk space. Only 2048 bytes
  194. can be held in a pipe at once; when a process tries to write more data,
  195. it is suspended until another process reads some data, thus "emptying"
  196. the pipe. If there are no more readers, a process writing on a pipe is
  197. terminated.
  198.  
  199. A simple "pipe" program is provided to run two programs concurrently,
  200. passing data between them in a pipe. The syntax is
  201.     pipe.ttp cmd1 cmd2
  202. which is equivalent to the Unix "cmd1 | cmd2". Note that if cmd1 or cmd2
  203. contain arguments, then you must run the "pipe" program from a shell that
  204. supports the Atari standard extended argument convention, and that you
  205. must enclose the commands in quotes, e.g. in gulam:
  206.     set env_style mw    # extended arguments
  207.     pipe 'ls.ttp -l foo' 'fgrep.ttp myfile'
  208. does the same as the Unix command
  209.     ls -l foo | fgrep myfile
  210. or using a temporary file
  211.     ls -l foo >junk; fgrep myfile <junk; rm junk
  212.  
  213. Shells designed to work explicitly with MiNT will probably not need the
  214. external "pipe" command, and instead will use the Unix notation for
  215. pipelines. (The sample shell that comes with MiNT as init.prg does
  216. this). This second method is preferable, as it provides a way of
  217. joining more than two programs in a pipeline.
  218.  
  219.  
  220. Job Control
  221.  
  222. MiNT currently (as of version 0.6) supports job control. The ^Z
  223. (control-Z) key can be used to suspend a process. The process can
  224. be restarted again if it is sent the appropriate signal. A sample
  225. program (fg.ttp) is provided that will do this; the syntax is 
  226.     fg.ttp process-name
  227. where "process-name" is either the process id of the process, or its
  228. name as displayed in the drive X: listing (e.g. gem.003). If the process
  229. was not stopped, an error will occur.
  230. There is also a "delayed" suspend key, ^Y, that takes effect only when
  231. a process attempts to read it.
  232.  
  233. More sophisticated job control facilites can be provided by shells that
  234. are specifically written with MiNT in mind. The sample "init.prg"
  235. demonstrates this. Jobs run in the background from such shells are auto-
  236. matically stopped when they attempt to read from the terminal or write to it.
  237. Thus, you can run a long compile in the background, and if an error
  238. occurs and the compiler attempts to write on the screen, it will be stopped.
  239.  
  240.  
  241. Programming with MiNT
  242.  
  243. A file (mintbind.h) is provided that gives a C interface to the new
  244. MiNT system calls. Users of other programming languages will have to write
  245. the interfaces themselves; it should be relatively straightforward, as long
  246. as your compiler provides a way to call GEMDOS directly.
  247.  
  248. Testing for the presence of MiNT:
  249.  
  250. There are several ways to check to see if MiNT is active. Probably the best
  251. way is to check the cookie jar; MiNT installs a cookie of
  252. 0x4d694e54 (in ASCII, 'MiNT'), with a value consisting of the major/
  253. minor version numbers in the high/low bytes of the low word. Thus, MiNT
  254. version 1.2 will have a cookie value of 0x00000102L. (This isn't
  255. the place to explain the cookie jar, but basically it's a list of
  256. (cookie, value) pairs of longwords, terminated by cookie 0; a pointer
  257. to the jar is found at 0x5a0. MiNT always installs a cookie jar; versions
  258. of TOS prior to 1.6 don't always, in which case 0x5a0 will contain 0).
  259.  
  260. A "quick and dirty" way to see if MiNT is active is to make a system
  261. call that only exists under MiNT (preferably one with no side effects!).
  262. Pgetpid() or Syield() are good choices. If MiNT is not active, these
  263. calls will fail, returning -32 (invalid function). This method has the
  264. disadvantage that future versions of TOS, or other multitasking programs,
  265. may use the same trap numbers as MiNT, but have different meanings.
  266. For this reason, the "cookie jar" method is preferred.
  267.  
  268. Interprocess Communication:
  269.  
  270. MiNT provides 3 forms of interprocess communication (IPC): signals, fifos,
  271. and shared memory.
  272.  
  273. Signals:
  274.  
  275. Signals are a way of notifying a process of an event. The Pkill(pid, sig)
  276. system call is used to send signal number "sig" to the process with process
  277. id "pid". It is called "Pkill" because the default action of most signals is
  278. to terminate the process. If a process wishes to catch a signal and do
  279. processing, it can use the Psignal(sig, func) system call to arrange to have
  280. function "func" called when signal "sig" is received. If func is 0, then
  281. the default action is restored. If func is 1, then the signal will be ignored.
  282.  
  283. Processes can temporarily block receipt of signals via the Psigblock() and
  284. Psigsetmask() system calls.
  285.  
  286. Fifos:
  287.  
  288. Fifos are "first in first out" message queues. Pipes are a special kind of
  289. (unidirectional) fifo. Fifos are represented by files on drive Q:. They are
  290. created with the Fcreate(name, flags) system call. "name" will be the name
  291. under which the fifo is known (maximum 14 characters); "flags" is explained
  292. below. The returned file handle is treated just like an ordinary file, and
  293. may be written to and read from (unless the fifo is unidirectional, in
  294. which case it may only be written to). The program that creates the fifo
  295. is normally called the "server". Other programs ("clients") may use the
  296. Fopen(name, mode) system call to open the other end of the fifo and read
  297. the data that the server writes, or write data for the server to read.
  298. When the last program (either client or server) using a fifo closes it, the
  299. fifo is deleted automatically. Note that one program can be both client and
  300. server, if it creates a fifo with Fcreate and then opens it again with Fopen.
  301. Also, children of the server can inherit the Fcreate'd file handle.
  302.  
  303. The bits in the "flags" argument to Fcreate have the following meanings:
  304. 0x01: make fifo unidirectional (server can write, clients can read)
  305. 0x02: cause reads to return EOF if no other processes are writing, and writes
  306.       to raise the SIGPIPE signal if no other processes are reading. The
  307.       default action (if this flag is not specify) is to block waiting for
  308.       reads and writes
  309. 0x04: make the fifo a pseudo-tty; to client processes, the fifo will act
  310.       just like a terminal with the server "typing" the characters; for
  311.       example, if the server writes a ^C, SIGINT will be sent to clients
  312.  
  313. Attempting to Fcreate() a fifo with the same name as an already existing
  314. one will result in an access error.
  315.  
  316. Pipes may be created through the Fpipe() system call as well as through
  317. the Fcreate/Fopen pair; the former method is easier, since the kernel
  318. takes care of name conflicts, etc.
  319.  
  320. Fifos may be locked by processes via the Fcntl system call, as follows:
  321.  
  322. struct flock {
  323.     short l_type;        /* type of lock */
  324. #define F_RDLCK        0
  325. #define F_WRLCK        1
  326. #define F_UNLCK        3
  327.     long l_start;        /* start of locked region */
  328.     long l_len;        /* 0 for rest of file */
  329.     short l_pid;        /* set by F_GETLK */
  330. };
  331.  
  332. Fcntl(fd, &lock, F_SETLK): set a lock as specified by the lock structure.
  333. The current version of MiNT only understands locks on the whole FIFO,
  334. so lock.l_start and lock.l_len should both be 0. If lock.l_type is F_UNLCK,
  335. then the lock is released. Otherwise, the file whole file is locked
  336. (future versions of MiNT may distinguish between read and write locks,
  337. but for now all locks are treated as write locks (F_WRLCK) and block both
  338. reads and writes). If another process has locked the fifo, returns -36
  339. (access denied). If a process holding a lock terminates, the fifo is
  340. automatically unlocked.
  341.  
  342. Fcntl(fd, &lock, F_GETLK): if a lock exists on the fifo, set lock to
  343. indicate what kind of lock it is; otherwise, set lock.l_type to F_UNLCK.
  344.  
  345. Locks are only "advisory"; that is, programs may ignore locks if they
  346. choose to do so. However, they are a good way to insure that two clients'
  347. data are not mixed together in a fifo.
  348.  
  349. See the sample LPR and LPD utilites, and the MIWM window manager for
  350. demonstrations of how to use fifos.
  351.  
  352. Shared memory:
  353.  
  354. Children created with the Pexec(4,...) share all of their parents memory,
  355. as do children created with the Pvfork() system call. Hence, they may
  356. communicate with their parent (or with each other) via global variables.
  357.  
  358.  
  359. MiNT extensions to GEMDOS calls:
  360.  
  361. Pexec(100, name, cmdline, environment):
  362.     Similar to Pexec(0, ...), except the calling program does not wait for
  363. the child to finish. Returns a negative error code, or the (positive)
  364. process I.D. of the child.
  365.  
  366. Pexec(104, 0L, basepage, 0L):
  367.     Similar to Pexec(4, ...); starts executing a basepage previously
  368. set up by Pexec(5, ...). The caller does not wait for the child to
  369. finish. Returns a negative error code, or the process I.D. of the child.
  370.  
  371. Pexec(200, name, cmdline, environment):
  372.     As with Pexec(0,...) and Pexec(100,...) this runs a program. However,
  373. with this variant the caller is completely replaced with the executing
  374. program. The process retains its process i.d. and most other attributes,
  375. but all of its memory is freed and a new address space is set up for it
  376. containing the code from the indicated program. Whereas Pexec(0,...)
  377. is like a subroutine call, Pexec(200,...) is like a "goto". It returns
  378. only if an error occurs.
  379.  
  380.  
  381. New MiNT calls:
  382.  
  383.  
  384. int Syield():                    [ GEMDOS 0xff ]
  385.     Temporarily yields control of the processor so that other processes
  386. may execute. Programs that are looping, waiting for some condition, should
  387. make this call to avoid using more CPU time than necessary. (MiNT will
  388. pre-empt the process eventually; Syield() is just a way of notifying
  389. MiNT that it's OK to switch processes right now). Syield() always returns
  390. 0.
  391.  
  392. int Fpipe( int *ptr ):                [ GEMDOS 0x100 ]
  393.     Creates a pipe. On success, Fpipe() returns 0 and sets the two (16 bit)
  394. integers pointed to by "ptr" as follows: ptr[0] is the file handle of the
  395. read-only end of the pipe, and ptr[1] the file handle of the write-only end.
  396. If an error occurs during pipe creation, the (negative) error code is
  397. returned and the memory pointed to by "ptr" is left unchanged.
  398.  
  399. int Fcntl( int f, long arg, int cmd):        [ GEMDOS 0x104 ]
  400.     Does various file control commands. "f" is the file handle of an open
  401. file; "cmd" is an integer specifying the file control option desired; and
  402. "arg" depends on "cmd" (quite often it's a pointer to a structure of some
  403. sort). The exact commands available vary depending on the type of file "f"
  404. is.
  405.  
  406. long Finstat( int f ):                [ GEMDOS 0x105 ]
  407.     Returns the number of characters that may be read from the file whose
  408. handle is "f"; "0" means that there are no characters waiting. If the
  409. integer "f" is not a valid file handle, a negative error code is returned.
  410. BUGS: disk files always return "1", so this call is useful only for pipes
  411. and terminals.
  412.  
  413. long Foutstat( int f )                [ GEMDOS 0x106 ]
  414.     Returns the number of bytes that may be written to a file before the
  415. writing process will have to go to sleep. Useful mainly for pipes or
  416. slow terminal devices.
  417. BUGS: always returns "1" for files on disk, even if the disk is full.
  418.  
  419. long Fgetchar(int f, int mode):            [ GEMDOS 0x107 ]
  420.     Reads a character from the file whose handle is "f". "mode" controls
  421. how the reading is done; if (mode & 0x1) == 0x1 then the data is
  422. "cooked", i.e. ^C and other control characters are interpreted; if
  423. (mode & 0x2) == 0x2 then the character is echoed to the device it was
  424. read from. If no more data is available from the file, Fgetchar will
  425. return 0x0000ff1a. If an error occurs, a (long) negative error code will
  426. be returned. Otherwise, the character read is returned. Note that when
  427. reading from the console, the scan code is put in the second byte
  428. of the longword returned, just as the BIOS does. The GEMDOS console input
  429. calls (Cconin(), Crawcin(), Cauxin(), etc.) are translated by MiNT into
  430. this call.
  431.  
  432. long Fputchar( int f, long c, int mode ):    [ GEMDOS 0x108 ]
  433.     Writes a character to the file whose handle is "f". "mode" is as for
  434. Fgetchar. "c" is long so that BIOS scan codes can be passed to pseudo-tty's
  435. and other terminal-like devices; for ordinary files, only the low byte of
  436. "c" is used.
  437.  
  438. long Pwait():                    [ GEMDOS 0x109 ]
  439.     Returns the exit status of children run asynchronously (e.g. with
  440. Pexec(100,...)). If necessary, it will wait until one of the children
  441. exits. The returned value consists of the child's process id in the high
  442. word, and the child's exit code (the value the child passed to Pterm())
  443. in the low word. If the caller has no un-waited for children left
  444. running, Pwait() will return -33 (file not found; think of it as searching
  445. drive X:).
  446.  
  447. int Snice( int delta ):                [ GEMDOS 0x10a ]
  448.     Set the current processes "niceness". A nice process has a lower
  449. priority. Negative niceness means increase the priority. The priority
  450. is inherited by children, so shells can use this to set their children's
  451. priority. The new priority (which will be -delta if, as is the default,
  452. the process had 0 priority) is returned, so processes can use Snice(0)
  453. to determine their current priority.
  454. BUGS:
  455.     Scheduling is done more-or-less round-robin, by priority. A smarter
  456. algorithm would be nice.
  457.  
  458. int Pgetpid():                    [ GEMDOS 0x10b ]
  459. int Pgetppid():                    [ GEMDOS 0x10c ]
  460. int Pgetpgrp():                    [ GEMDOS 0x10d ]
  461.     Get the current process' process id, its parent's process id, or
  462. its process group, respectively.
  463.  
  464. int Psetpgrp(pid, newgrp):            [ GEMDOS 0x10e ]
  465.     Sets the process group of the process with the given pid to
  466. "newgrp". The process must have the same user id, or it must be
  467. a child of the current process. If pid == 0, the process group
  468. of the current process is changed.
  469.  
  470. int Pgetuid():                    [ GEMDOS 0x10f ]
  471.     Returns the user id under which the current process is running.
  472.  
  473. int Psetuid( int id ):                [ GEMDOS 0x110 ]
  474.     Sets the current process' user id to "id". Valid only if the
  475. user id is currently 0, otherwise it returns EACCDN (access denied).
  476.  
  477. int Pkill( int pid, int sig ):            [ GEMDOS 0x111 ]
  478.     Sends the indicated signal to the process with the given pid. If
  479. pid is negative, it is sent to all processes whose process group is
  480. equal to pid. If pid == 0, it is sent to all processes with the same
  481. process group as the calling process (this includes the calling process,
  482. which must therefore make provisions to catch the signal).
  483. Returns 0 on success, EFILNF if process "pid" is not found, and EACCDN
  484. if the user id of process "pid" does not match the calling process'
  485. user id.
  486.  
  487. long Psignal(int sig, long handler):        [ GEMDOS 0x112 ]
  488.     Installs a signal handler for the indicated signal. "handler" is the
  489. address of a function that will be called when the signal occurs; it
  490. should have prototype
  491.     void handler(long sig)
  492. The parameter passed to it is a 32 bit number indicating which signal
  493. happened, so that the same handler can deal with multiple signals.
  494. MiNT saves the process' context before calling the handler, so it does
  495. not have to worry about saving/restoring registers. The signal handling
  496. mechanism is based upon BSD; that is, the signal being dealt with is
  497. masked until the handler returns, so there is no danger of race
  498. conditions. The handler always runs in the same mode (user or supervisor)
  499. that the process was in at the time of the signal. System calls may
  500. be performed by the handler (the Pvfork() and Pfork() system calls, while
  501. legal, may not produce the desired results).
  502.     Normally, signal handlers will either return or terminate the program.
  503. In these cases, no special processing needs to be done. If, however,
  504. the handler exits via a longjmp() back to some other point in the program,
  505. the Psigreturn() system call must be invoked before the longjmp()
  506. This call fixes up the kernel's stack and unmasks the signal currently under
  507. consideration. Thus, a handler for ^C may look like this:
  508.  
  509.     void catch_ctrlc(sig)
  510.         long sig;
  511.     {
  512.         Cconws("\r\nInterrupt ignored\r\n");
  513.         Psigreturn();
  514.         longjmp(top_of_program, 1);
  515.     }
  516.  
  517. int Pvfork():                    [ GEMDOS 0x113 ]
  518.     Creates a copy of the current process. As with the BSD "vfork()"
  519. system call (and unlike Unix's "fork()") both child and parent share the
  520. same address space. To avoid conflicts, the parent is put to sleep
  521. and is not awoken until the child exits or calls Pexec with mode 200
  522. (overlay); in the latter case, the child is given a new address space.
  523. The return value is 0 in the child, and the child's pid in the parent.
  524. On an error, a negative error value is returned and no child is started.
  525. BUGS:
  526.     This function should only be called from user mode; if called from
  527. supervisor mode, the child will be started in user mode anyways, and will
  528. have to call Super(0L) to reset to supervisor mode.
  529.  
  530. int Pgetgid():                    [ GEMDOS 0x114 ]
  531.     Gets the group id of the current process.
  532.  
  533. int Psetgid(id):                [ GEMDOS 0x115 ]
  534.     Sets the group id of the current process to "id". Valid only if the process
  535. currently has group id 0 or user id 0.
  536.  
  537. long Psigblock(mask):                [ GEMDOS 0x116 ]
  538.     Blocks the signals given in the 32 bit mask. For example, to block the
  539. SIGINT signal, do Psigblock(1L << SIGINT). This call adds to the set of
  540. blocked signals, so previously blocked signals remain blocked. The return
  541. value is the set of previously blocked signals, which can be restored by
  542. the Psigsetmask() call (see below). Note that some signals (e.g. SIGKILL)
  543. are not blockable, and requests to block them have no effect.
  544.  
  545. long Psigsetmask(mask):                [ GEMDOS 0x117 ]
  546.     Replaces the set of blocked signals with the set in "mask". The 32
  547. bit mask is the same as the one for Psigblock (q.v.). The old set of
  548. blocked signals is returned.
  549.  
  550. long Pusrval(arg):                [ GEMDOS 0x118 ]
  551.     Returns the process specific user value for this process. This is
  552. a long word that is part of the process structure, and may be used by
  553. window managers, etc. to provide extensions to MiNT. If arg is not -1,
  554. then the user value is set to arg. It is recommended that "arg" should
  555. be a pointer to a structure whose first member is the old user value;
  556. thus, a chain of structures may be established, terminated by a value
  557. of 0 (the value set by MiNT itself). Children inherit their parents
  558. user value.
  559.  
  560. int Pdomain(newdom):                [ GEMDOS 0x119 ]
  561.     If newdom is not -1, sets the process domain of the current process
  562. to "newdom"; in any event, returns the previous domain of the process.
  563. Currently 2 process domains are supported. Domain 0 is the TOS domain,
  564. and is the default for all new processes; domain 1 is the MiNT domain.
  565. Certain system calls may behave differently in different domains. In the
  566. TOS domain, of course, all system calls are TOS compatible. If a process
  567. is running in the MiNT domain, the Fread() and Fwrite() system on terminals
  568. act more like the Unix read() and write() system calls, and terminal
  569. modes may be changed with the Fcntl() system call. Also, processes running
  570. under the MiNT domain may use the forward slash '/' as a directory
  571. separator, as well as the backward slash '\'.
  572.  
  573. long Psigreturn():                [ GEMDOS 0x11a ]
  574.     Prepare to exit from a signal handler. This is done automatically by
  575. the kernel when a signal handler returns, so it is needed only before
  576. longjmp() calls. It will fail (harmlessly) and return a negative error
  577. code if no signal is being processed.
  578.  
  579. long Pfork():                    [ GEMDOS 0x11b ]
  580.     Create a new process that is a duplicate of the current one, but
  581. which has its own copy of the address space. This is a more expensive
  582. operation than Pvfork(), but may be necessary if the child wishes to
  583. manipulate global variables without changing their values in the parent.
  584. BUGS:
  585.     The child and parent do not operate asynchronously in the current
  586. version of MiNT; the parent is blocked until the child either exits
  587. or overlays itself with Pexec(200,...). This will be corrected in a
  588. future version of MiNT, so don't count on this behaviour!
  589.     As with Pvfork(), the child always starts in user mode.
  590.  
  591. long Pwait3(int flag, long *rusage):        [ GEMDOS 0x11c ]
  592.     Wait for a child, and return its exit status. If "flag" is nonzero and
  593. no unwaited for children exist, Pwait3 will return 0, otherwise it will
  594. wait for a child to exit. If no children exist at all, Pwait3 will return
  595. -33 (file not found). If "rusage" is nonzero, information about the
  596. child's resource usage is placed into the memory pointed by rusage, as
  597. follows:
  598.      rusage[0]: milliseconds spent by child in user space
  599.      rusage[1]: milliseconds spent by child in kernel space
  600.  
  601. int Fselect(unsigned timeout, long *rfds, long *wfds, long *xfds):
  602.                         [ GEMDOS 0x11d ]
  603.     See which open files are ready for reading, writing, or have error
  604. conditions on them (the last is not yet implemented). "rfds" and "wfds"
  605. are pointers to 32 bit bitmaps, which indicate which files we are interested
  606. in reading and writing, respectively; if a bit is on, the corresponding
  607. file descriptor is tested as to whether it is ready for reads or writes.
  608. If a bit is set for an invalid file descriptor, an error is returned.
  609. "timeout" is an unsigned integer giving the number of milliseconds to wait
  610. before returning; if it is 0, Fselect will block indefinitely.
  611. On return, the bitmaps pointed to by rfds and wfds are set to indicate which
  612. file descriptors (of those originally specified) are ready for reading/writing.
  613. Passing a null pointer for "rfds" or "wfds" is equivalent to passing a
  614. pointer to (long)0. Fselect(0, 0, 0, 0) will therefore go to sleep forever.
  615. Fselect returns the number of file descriptors of interest that are ready
  616. for reading and/or writing, or 0 if the timeout elapses without any of
  617. those descriptors becoming ready.
  618.  
  619. void Prusage( long r[8] ):            [ GEMDOS 0x11e ]
  620.    Get various resource usage information from the operating system. The
  621. values are placed in the array "r" as follows:
  622.    r[0]: time spent by process in MiNT kernel (milliseconds)
  623.    r[1]: time spent by process in its own code (milliseconds)
  624.    r[2]: total kernel time spent by children of this process (milliseconds)
  625.    r[3]: total user code time spent by children (milliseconds)
  626.    r[4]: memory allocated to this process (bytes)
  627.    r[5]-r[7]: reserved
  628.  
  629. long Psetlimit(int lim, long value):        [ GEMDOS 0x11f ]
  630.    Get/set a resource limit for a process. Which limit is affected is governed
  631. by the value of "lim", as follows:
  632.     1: get/set maximum CPU time for process (in milliseconds)
  633.     2: get/set total maximum memory allowed for process
  634.     3: get/set limit on Malloc'd memory for process
  635. If "value" is negative, the limit is unchanged; if "value" is 0, the
  636. corresponding resource is unlimited; otherwise, the resource limit is
  637. set to "value". The old limit is returned (0 if there was no limit).
  638.  
  639. long Talarm( long secs ):            [ GEMDOS 0x120 ]
  640.     Set an alarm to go off "secs" seconds from now, and returns the amount
  641. previously on the timer. If "secs" == 0, cancels any pending alarm; if 
  642. "secs" is negative, returns the amount of time remaining before an alarm
  643. is to go off, without changing the alarm.
  644.  
  645. long *Dos_tab():                [ GEMDOS 0xffff ]
  646. long *Bios_tab():                [ BIOS 0xffff ]
  647. long *Xbios_tab():                [ XBIOS 0xffff ]
  648.     These calls return a pointer to the GEMDOS, BIOS, and XBIOS function
  649. tables, respectively. They correspond to function #-1 for each of the
  650. respective calls. The pointers returned may be manipulated by user
  651. programs, allowing for easy replacement of system routines by user supplied
  652. routines. For example, to change the Sversion() system call to return
  653. 2*the GEMDOS version instead of the GEMDOS version, a program could do the
  654. following:
  655.     long (*old_sversion)();
  656.     long new_sversion() {
  657.         long old;
  658.         old = (old_sversion == NULL) ? Sversion() : (*old_sversion)();
  659.         return 2*old;
  660.     }
  661.     void install() {
  662.        long *dtab = Dos_tab();
  663.        old_sversion = (long (*)()) dtab[0x30];
  664.        dtab[0x30] = (long)new_sversion;  /* Sversion is GEMDOS call 0x30 */
  665.     }
  666. The installed routines are called with the parameters on the stack just
  667. as passed to GEMDOS (i.e. with 16 bit integers). The return value should
  668. be passed in D0 (most C compilers do this automatically). Registers need
  669. not be saved; MiNT does that automatically. Note that MiNT resets
  670. all the system vectors to point to TOS while executing system calls, so
  671. if you make a system call inside your routine, you'll be calling TOS,
  672. not MiNT. If you want to call MiNT, use the function tables to find
  673. the address of the MiNT routine you want. (WARNING: some function table
  674. entries will be 0; this indicates to MiNT that it should call through to
  675. TOS. See the example above.)
  676.     Caution is STRONGLY advised in the use of this feature; a miscue will
  677. crash the system. Make sure that the routines are de-installed when the
  678. program exits (or make the program stay in memory with the Ptermres() call).
  679.  
  680.