mach.nr 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. .BP
  2. .SN 10
  3. .S1 "EM MACHINE LANGUAGE"
  4. The EM machine language is designed to make program text compact
  5. and to make decoding easy.
  6. Compact program text has many advantages: programs execute faster,
  7. programs occupy less primary and secondary storage and loading
  8. programs into satellite processors is faster.
  9. The decoding of EM machine language is so simple,
  10. that it is feasible to use interpreters as long as EM hardware
  11. machines are not available.
  12. This chapter is irrelevant when back ends are used to
  13. produce executable target machine code.
  14. .S2 "Instruction encoding"
  15. A design goal of EM is to make the
  16. program text as compact as possible.
  17. Decoding must be easy, however.
  18. The encoding is fully byte oriented, without any small bit fields.
  19. There are 256 primary opcodes, two of which are an escape to
  20. two groups of 256 secondary opcodes each.
  21. .A
  22. EM instructions without arguments have a single opcode assigned,
  23. possibly escaped:
  24. .Dr 14
  25. |--------------|
  26. | opcode |
  27. |--------------|
  28. or
  29. |--------------|--------------|
  30. | escape | opcode |
  31. |--------------|--------------|
  32. .De
  33. The encoding for instructions with an argument is more complex.
  34. Several instructions have an address from the global data area
  35. as argument.
  36. Other instructions have different opcodes for positive
  37. and negative arguments.
  38. .N 1
  39. There is always an opcode that takes the next two bytes as argument,
  40. high byte first:
  41. .Dr 14
  42. |--------------|--------------|--------------|
  43. | opcode | hibyte | lobyte |
  44. |--------------|--------------|--------------|
  45. or
  46. |--------------|--------------|--------------|--------------|
  47. | escape | opcode | hibyte | lobyte |
  48. |--------------|--------------|--------------|--------------|
  49. .De
  50. An extra escape is provided for instructions with four or eight byte arguments.
  51. .Dr 6
  52. |--------------|--------------|--------------| |--------------|
  53. | ESCAPE | opcode | hibyte |...| lobyte |
  54. |--------------|--------------|--------------| |--------------|
  55. .De
  56. For most instructions some argument values predominate.
  57. The most frequent combinations of instruction and argument
  58. will be encoded in a single byte, called a mini:
  59. .Dr 6
  60. |---------------|
  61. |opcode+argument| (mini)
  62. |---------------|
  63. .De
  64. The number of minis is restricted, because only
  65. 254 primary opcodes are available.
  66. Many instructions have the bulk of their arguments
  67. fall in the range 0 to 255.
  68. Instructions that address global data have their arguments
  69. distributed over a wider range,
  70. but small values of the high byte are common.
  71. For all these cases there is another encoding
  72. that combines the instruction and the high byte of the argument
  73. into a single opcode.
  74. These opcodes are called shorties.
  75. Shorties may be escaped.
  76. .Dr 14
  77. |--------------|--------------|
  78. | opcode+high | lobyte | (shortie)
  79. |--------------|--------------|
  80. or
  81. |--------------|--------------|--------------|
  82. | escape | opcode+high | lobyte |
  83. |--------------|--------------|--------------|
  84. .De
  85. Escaped shorties are useless if the normal encoding has a primary opcode.
  86. Note that for some instruction-argument combinations
  87. several different encodings are available.
  88. It is the task of the assembler to select the shortest of these.
  89. The savings by these mini and shortie
  90. opcodes are considerable, about 55%.
  91. .P
  92. Further improvements are possible:
  93. the arguments of
  94. many instructions are a multiple of the wordsize.
  95. Some do also not allow zero as an argument.
  96. If these arguments are divided by the wordsize and,
  97. when zero is not allowed, then decremented by 1, more of them can
  98. be encoded as shortie or mini.
  99. The arguments of some other instructions
  100. rarely or never assume the value 0, but start at 1.
  101. The value 1 is then encoded as 0,
  102. 2 as 1 and so on.
  103. .P
  104. Assigning opcodes to instructions by the assembler is completely
  105. table driven.
  106. For details see appendix B.
  107. .S2 "Procedure descriptors"
  108. The procedure identifiers used in the interpreter are indices
  109. into a table of procedure descriptors.
  110. Each descriptor contains:
  111. .IS 6
  112. .PS - 4
  113. .PT 1.
  114. the number of bytes to be reserved for locals at each
  115. invocation.
  116. .N
  117. This is a pointer-szied integer.
  118. .PT 2.
  119. the start address of the procedure
  120. .PE
  121. .IE
  122. .S2 "Load format"
  123. The EM machine language load format defines the interface between
  124. the EM assembler/loader and the EM machine itself.
  125. A load file consists of a header, the program text to be executed,
  126. a description of the global data area and the procedure descriptor table,
  127. in this order.
  128. All integers in the load file are presented with the
  129. least significant byte first.
  130. .P
  131. The header has two parts: the first half (eight 16-bit integers)
  132. aids in selecting
  133. the correct EM machine or interpreter.
  134. Some EM machines, for instance, may have hardware floating point
  135. instructions.
  136. .N
  137. The header entries are as follows (bit 0 is rightmost):
  138. .IS 2
  139. .VS 1 0
  140. .PS 1 4 "" :
  141. .PT
  142. magic number (07255)
  143. .PT
  144. flag bits with the following meaning:
  145. .PS - 7 "" :
  146. .PT bit 0
  147. TEST; test for integer overflow etc.
  148. .PT bit 1
  149. PROFILE; for each source line: count the number of memory
  150. cycles executed.
  151. .PT bit 2
  152. FLOW; for each source line: set a bit in a bit map table if
  153. instructions on that line are executed.
  154. .PT bit 3
  155. COUNT; for each source line: increment a counter if that line
  156. is entered.
  157. .PT bit 4
  158. REALS; set if a program uses floating point instructions.
  159. .PT bit 5
  160. EXTRA; more tests during compiler debugging.
  161. .PE
  162. .PT
  163. number of unresolved references.
  164. .PT
  165. version number; used to detect obsolete EM load files.
  166. .PT
  167. wordsize ; the number of bytes in each machine word.
  168. .PT
  169. pointer size ; the number of bytes available for addressing.
  170. .PT
  171. unused
  172. .PT
  173. unused
  174. .PE
  175. .IE
  176. The second part of the header (eight entries, of pointer size bytes each)
  177. describes the load file itself:
  178. .IS 2
  179. .PS 1 4 "" :
  180. .PT
  181. NTEXT; the program text size in bytes.
  182. .PT
  183. NDATA; the number of load-file descriptors (see below).
  184. .PT
  185. NPROC; the number of entries in the procedure descriptor table.
  186. .PT
  187. ENTRY; procedure number of the procedure to start with.
  188. .PT
  189. NLINE; the maximum source line number.
  190. .PT
  191. SZDATA; the address of the lowest uninitialized data byte.
  192. .PT
  193. unused
  194. .PT
  195. unused
  196. .PE
  197. .IE
  198. .P
  199. The program text consists of NTEXT bytes.
  200. NTEXT is always a multiple of the wordsize.
  201. The first byte of the program text is the
  202. first byte of the instruction address
  203. space, i.e. it has address 0.
  204. Pointers into the program text are found in the procedure descriptor
  205. table where relocation is simple and in the global data area.
  206. The initialization of the global data area allows easy
  207. relocation of pointers into both address spaces.
  208. .P
  209. The global data area is described by the NDATA descriptors.
  210. Each descriptor describes a number of consecutive words (of~wordsize)
  211. and consists of a sequence of bytes.
  212. While reading the descriptors from the load file, one can
  213. initialize the global data area from low to high addresses.
  214. The size of the initialized data area is given by SZDATA,
  215. this number can be used to check the initialization.
  216. .N
  217. The header of each descriptor consists of a byte, describing the type,
  218. and a count.
  219. The number of bytes used for this (unsigned) count depends on the
  220. type of the descriptor and
  221. is either a pointer-sized integer
  222. or one byte.
  223. The meaning of the count depends on the descriptor type.
  224. At load time an interpreter can
  225. perform any conversion deemed necessary, such as
  226. reordering bytes in integers
  227. and pointers and adding base addresses to pointers.
  228. .BP
  229. .A
  230. In the following pictures we show a graphical notation of the
  231. initializers.
  232. The leftmost rectangle represents the leading byte.
  233. .N 1
  234. .DS
  235. .PS - 4 " "
  236. Fields marked with
  237. .N 1
  238. .PT n
  239. contain a pointer-sized integer used as a count
  240. .PT m
  241. contain a one-byte integer used as a count
  242. .PT b
  243. contain a one-byte integer
  244. .PT w
  245. contain a wordsized integer
  246. .PT p
  247. contain a data or instruction pointer
  248. .PT s
  249. contain a null terminated ASCII string
  250. .PE 1
  251. .DE 0
  252. .VS 1 1
  253. .Dr 6
  254. -------------------
  255. | 0 | n | repeat last initialization n times
  256. -------------------
  257. .De
  258. .Dr 4
  259. ---------
  260. | 1 | m | m uninitialized words
  261. ---------
  262. .De
  263. .Dr 6
  264. ____________
  265. / bytes \e
  266. ----------------- -----
  267. | 2 | m | b | b |...| b | m initialized bytes
  268. ----------------- -----
  269. .De
  270. .Dr 6
  271. _________
  272. / word \e
  273. -----------------------
  274. | 3 | m | w |... m initialized wordsized integers
  275. -----------------------
  276. .De
  277. .Dr 6
  278. _________
  279. / pointer \e
  280. -----------------------
  281. | 4 | m | p |... m initialized data pointers
  282. -----------------------
  283. .De
  284. .Dr 6
  285. _________
  286. / pointer \e
  287. -----------------------
  288. | 5 | m | p |... m initialized instruction pointers
  289. -----------------------
  290. .De
  291. .Dr 6
  292. ____________
  293. / bytes \e
  294. -------------------------
  295. | 6 | m | b | b |...| b | initialized integer of size m
  296. -------------------------
  297. .De
  298. .Dr 6
  299. ____________
  300. / bytes \e
  301. -------------------------
  302. | 7 | m | b | b |...| b | initialized unsigned of size m
  303. -------------------------
  304. .De
  305. .Dr 6
  306. ____________
  307. / string \e
  308. -------------------------
  309. | 8 | m | s | initialized float of size m
  310. -------------------------
  311. .De 3
  312. .PS - 8
  313. .PT type~0:
  314. If the last initialization initialized k bytes starting
  315. at address \fIa\fP, do the same initialization again n times,
  316. starting at \fIa\fP+k, \fIa\fP+2*k, .... \fIa\fP+n*k.
  317. This is the only descriptor whose starting byte
  318. is followed by an integer with the
  319. size of a
  320. pointer,
  321. in all other descriptors the first byte is followed by a one-byte count.
  322. This descriptor must be preceded by a descriptor of
  323. another type.
  324. .PT type~1:
  325. Reserve m words, not explicitly initialized (BSS and HOL).
  326. .PT type~2:
  327. The m bytes following the descriptor header are
  328. initializers for the next m bytes of the
  329. global data area.
  330. m is divisible by the wordsize.
  331. .PT type~3:
  332. The m words following the header are initializers for the next m words of the
  333. global data area.
  334. .PT type~4:
  335. The m data address space pointers following the header are
  336. initializers for the next
  337. m data pointers in the global data area.
  338. Interpreters that represent EM pointers by
  339. target machine addresses must relocate all data pointers.
  340. .PT type~5:
  341. The m instruction address space pointers following the header are
  342. initializers for the next
  343. m instruction pointers in the global data area.
  344. Interpreters that represent EM instruction pointers by
  345. target machine addresses must relocate these pointers.
  346. .PT type~6:
  347. The m bytes following the header form
  348. a signed integer number with a size of m bytes,
  349. which is an initializer for the next m bytes
  350. of the global data area.
  351. m is governed by the same restrictions as for
  352. transfer of objects to/from memory.
  353. .PT type~7:
  354. The m bytes following the header form
  355. an unsigned integer number with a size of m bytes,
  356. which is an initializer for the next m bytes
  357. of the global data area.
  358. m is governed by the same restrictions as for
  359. transfer of objects to/from memory.
  360. .PT type~8:
  361. The header is followed by an ASCII string, null terminated, to
  362. initialize, in global data,
  363. a floating point number with a size of m bytes.
  364. m is governed by the same restrictions as for
  365. transfer of objects to/from memory.
  366. The ASCII string contains the notation of a real as used in the
  367. Pascal language.
  368. .PE
  369. .P
  370. The NPROC procedure descriptors on the load file consist of
  371. an instruction space address (of~pointer~size) and
  372. an integer (of~pointer~size) specifying the number of bytes for
  373. locals.