mach.nr 12 KB

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