env.nr 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. .SN 8
  2. .VS 1 0
  3. .BP
  4. .S1 "ENVIRONMENT INTERACTIONS"
  5. EM programs can interact with their environment in three ways.
  6. Two, starting/stopping and monitor calls, are dealt with in this chapter.
  7. The remaining way to interact, interrupts, will be treated
  8. together with traps in chapter 9.
  9. .S2 "Program starting and stopping"
  10. EM user programs start with a call to a procedure called
  11. _m_a_i_n.
  12. The assembler and backends look for the definition of a procedure
  13. with this name in their input.
  14. The call passes three parameters to the procedure.
  15. The parameters are similar to the parameters supplied by the
  16. UNIX
  17. .FS
  18. UNIX is a Trademark of Bell Laboratories.
  19. .FE
  20. operating system to C programs.
  21. These parameters are often called
  22. .BW argc ,
  23. .B argv
  24. and
  25. .BW envp .
  26. Argc is the parameter nearest to LB and is a wordsized integer.
  27. The other two are pointers to the first element of an array of
  28. string pointers.
  29. .N
  30. The
  31. .B argv
  32. array contains
  33. .B argc
  34. strings, the first of which contains the program call name.
  35. The other strings in the
  36. .B argv
  37. array are the program parameters.
  38. .P
  39. The
  40. .B envp
  41. array contains strings in the form "name=string", where 'name'
  42. is the name of an environment variable and string its value.
  43. The
  44. .B envp
  45. is terminated by a zero pointer.
  46. .P
  47. An EM user program stops if the program returns from the first
  48. invocation of _m_a_i_n.
  49. The contents of the function return area are used to procure a
  50. wordsized program return code.
  51. EM programs also stop when traps and interrupts occur that are
  52. not caught and when the exit monitor call is executed.
  53. .S2 "Input/Output and other monitor calls"
  54. EM differs from most conventional machines in that it has high level i/o
  55. instructions.
  56. Typical instructions are OPEN FILE and READ FROM FILE instead
  57. of low level instructions such as setting and clearing
  58. bits in device registers.
  59. By providing such high level i/o primitives, the task of implementing
  60. EM on various non EM machines is made considerably easier.
  61. .P
  62. I/O is initiated by the MON instruction, which expects an iocode on top
  63. of the stack.
  64. Often there are also parameters which are pushed on the
  65. stack in reverse order, that is: last
  66. parameter first.
  67. Some i/o functions also provide results, which are returned on the stack.
  68. In the list of monitor calls we use several types of parameters and results,
  69. these types consist of integers and unsigneds of varying sizes, but never
  70. smaller than the wordsize, and the two pointer types.
  71. .N 1
  72. The names of the types used are:
  73. .IS 4
  74. .PS - 10
  75. .PT int
  76. an integer of wordsize
  77. .PT int2
  78. an integer whose size is the maximum of the wordsize and 2
  79. bytes
  80. .PT int4
  81. an integer whose size is the maximum of the wordsize and 4
  82. bytes
  83. .PT intp
  84. an integer with the size of a pointer
  85. .PT uns2
  86. an unsigned integer whose size is the maximum of the wordsize and 2
  87. .PT unsp
  88. an unsigned integer with the size of a pointer
  89. .PT ptr
  90. a pointer into data space
  91. .PE 1
  92. .IE 0
  93. The table below lists the i/o codes with their results and
  94. parameters.
  95. This list is similar to the system calls of the UNIX Version 7
  96. operating system.
  97. .A
  98. To execute a monitor call, proceed as follows:
  99. .IS 2
  100. .N 1
  101. .PS a 4 "" )
  102. .PT
  103. Stack the parameters, in reverse order, last parameter first.
  104. .PT
  105. Push the monitor call number (iocode) onto the stack.
  106. .PT
  107. Execute the MON instruction.
  108. .PE 1
  109. .IE
  110. An error code is present on the top of the stack after
  111. execution of most monitor calls.
  112. If this error code is zero, the call performed the action
  113. requested and the results are available on top of the stack.
  114. Non-zero error codes indicate a failure, in this case no
  115. results are available and the error code has been pushed twice.
  116. This construction enables programs to test for failure with a
  117. single instruction (~TEQ or TNE~) and still find out the cause of
  118. the failure.
  119. The result name 'e' is reserved for the error code.
  120. .N 1
  121. List of monitor calls.
  122. .DS B
  123. .ta 4n 13n 29n 52n
  124. nr name parameters results function
  125. 1 Exit status:int Terminate this process
  126. 2 Fork e,flag,pid:int Spawn new process
  127. 3 Read fildes:int;buf:ptr;nbytes:unsp
  128. e:int;rbytes:unsp Read from file
  129. 4 Write fildes:int;buf:ptr;nbytes:unsp
  130. e:int;wbytes:unsp Write on a file
  131. 5 Open string:ptr;flag:int
  132. e,fildes:int Open file for read and/or write
  133. 6 Close fildes:int e:int Close a file
  134. 7 Wait e:int;status,pid:int2
  135. Wait for child
  136. 8 Creat string:ptr;mode:int
  137. e,fildes:int Create a new file
  138. 9 Link string1,string2:ptr
  139. e:int Link to a file
  140. 10 Unlink string:ptr e:int Remove directory entry
  141. 12 Chdir string:ptr e:int Change default directory
  142. 14 Mknod string:ptr;mode,addr:int2
  143. e:int Make a special file
  144. 15 Chmod string:ptr;mode:int2
  145. e:int Change mode of file
  146. 16 Chown string:ptr;owner,group:int2
  147. e:int Change owner/group of a file
  148. 18 Stat string,statbuf:ptr
  149. e:int Get file status
  150. 19 Lseek fildes:int;off:int4;whence:int
  151. e:int;oldoff:int4 Move read/write pointer
  152. 20 Getpid pid:int2 Get process identification
  153. 21 Mount special,string:ptr;rwflag:int
  154. e:int Mount file system
  155. 22 Umount special:ptr e:int Unmount file system
  156. 23 Setuid userid:int2 e:int Set user ID
  157. 24 Getuid e_uid,r_uid:int2 Get user ID
  158. 25 Stime time:int4 e:int Set time and date
  159. 26 Ptrace request:int;pid:int2;addr:ptr;data:int
  160. e,value:int Process trace
  161. 27 Alarm seconds:uns2 previous:uns2 Schedule signal
  162. 28 Fstat fildes:int;statbuf:ptr
  163. e:int Get file status
  164. 29 Pause Stop until signal
  165. 30 Utime string,timep:ptr
  166. e:int Set file times
  167. 33 Access string:ptr;mode:int
  168. e:int Determine file accessibility
  169. 34 Nice incr:int Set program priority
  170. 35 Ftime bufp:ptr e:int Get date and time
  171. 36 Sync Update filesystem
  172. 37 Kill pid:int2;sig:int
  173. e:int Send signal to a process
  174. 41 Dup fildes,newfildes:int
  175. e,fildes:int Duplicate a file descriptor
  176. 42 Pipe e,w_des,r_des:int Create a pipe
  177. 43 Times buffer:ptr Get process times
  178. 44 Profil buff:ptr;bufsiz,offset,scale:intp
  179. Execution time profile
  180. 46 Setgid gid:int2 e:int Set group ID
  181. 47 Getgid e_gid,r_gid:int Get group ID
  182. 48 Sigtrp trapno,signo:int
  183. e,prevtrap:int See below
  184. 51 Acct file:ptr e:int Turn accounting on or off
  185. 53 Lock flag:int e:int Lock a process
  186. 54 Ioctl fildes,request:int;argp:ptr
  187. e:int Control device
  188. 56 Mpxcall cmd:int;vec:ptr e:int Multiplexed file handling
  189. 59 Exece name,argv,envp:ptr
  190. e:int Execute a file
  191. 60 Umask mask:int2 oldmask:int2 Set file creation mode mask
  192. 61 Chroot string:ptr e:int Change root directory
  193. .DE 1
  194. Codes 0, 11, 13, 17, 31, 32, 38, 39, 40, 45, 49, 50, 52,
  195. 55, 57, 58, 62, and 63 are
  196. not used.
  197. .P
  198. All monitor calls, except fork and sigtrp
  199. are the same as the UNIX version 7 system calls.
  200. .P
  201. The sigtrp entry maps UNIX signals onto EM interrupts.
  202. Normally, trapno is in the range 0 to 252.
  203. In that case it requests that signal signo
  204. will cause trap trapno to occur.
  205. When given trap number \-2, default signal handling is reset, and when given
  206. trap number \-3, the signal is ignored.
  207. .P
  208. The flag returned by fork is 1 in the child process and 0 in
  209. the parent.
  210. The pid returned is the process-id of the other process.
  211. .VS