dis.ms 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824
  1. .so /sys/lib/tmac/tmac.uni
  2. .TL
  3. Dis Virtual Machine Specification
  4. .AU
  5. .I "Lucent Technologies Inc"
  6. .I "30 September 1999"
  7. .I "Extensively revised by Vita Nuova Limited"
  8. .I "5 June 2000, 9 January 2003"
  9. .NH 1
  10. Introduction
  11. .LP
  12. The Dis virtual machine provides the execution environment for programs running under the Inferno operating system. The virtual machine models a CISC-like, three operand, memory-to-memory architecture. Code can either be interpreted by a C library or compiled on-the-fly into machine code for the target architecture.
  13. .LP
  14. This paper defines the virtual machine informally.
  15. A separate paper by Winterbottom and Pike[2] discusses its design.
  16. The Dis object file format is also defined here.
  17. Literals and keywords are in
  18. .CW typewriter
  19. typeface.
  20. .NH 1
  21. Addressing Modes
  22. .SH
  23. Operand Size
  24. .LP
  25. Operand sizes are defined as follows: a byte is 8 bits, a word or pointer is 32 bits, a float is 64 bits, a big integer is 64 bits. The operand size of each instruction is encoded explicitly by the operand code. The operand size and type are specified by the last character of the instruction mnemonic:
  26. .IP
  27. .TS
  28. lf(CW) lfR .
  29. W word, 32-bit two's complement
  30. B byte, 8-bit unsigned
  31. F float, 64-bit IEEE format
  32. L big, 64-bit two's complement
  33. P pointer
  34. C Unicode string encoded in UTF-8
  35. M memory
  36. MP memory containing pointers
  37. .TE
  38. .LP
  39. Two more operand types are defined to provide `short'
  40. types for use by languages other than Limbo:
  41. signed 16-bit integers, called `short word'
  42. here, and 32-bit IEEE format floating-point numbers, called `short float' or `short real' here.
  43. Support for them is limited to conversion to and from words or floats respectively;
  44. the instructions are marked below with a dagger (†).
  45. .SH
  46. Memory Organization
  47. .LP
  48. Memory for a thread is divided into several separate regions. The code segment stores either a decoded virtual machine instruction stream suitable for execution by the interpreter or flash compiled native machine code for the host CPU. Neither type of code segment is addressable from the instruction set. At the object code level, PC values are offsets, counted in instructions, from the beginning of the code space.
  49. .LP
  50. Data memory is a linear array of bytes, addressed using 32-bit pointers. Words are stored in the native representation of the host CPU. Data types larger than a byte must be stored at addresses aligned to
  51. a multiple of the data size. A thread executing a module has access to two regions of addressable data memory. A module pointer
  52. .CW "mp" \& (
  53. register) defines a region of global storage for a particular module, a frame pointer
  54. .CW "fp" \& (
  55. register) defines the current activation record or frame for the thread. Frames are allocated dynamically from a stack by function call and return instructions. The stack is extended automatically from the heap.
  56. .LP
  57. The
  58. .CW mp
  59. and
  60. .CW fp
  61. registers cannot be addressed directly, and therefore, can be modified only by call and return instructions.
  62. .SH
  63. Effective Addresses
  64. .LP
  65. Each instruction can potentially address three operands. The source and destination operands are general, but the middle operand can use any address mode except double indirect. If the middle operand of a three address instruction is omitted, it is assumed to be the same as the destination operand.
  66. .LP
  67. The general operands generate an effective address from three basic modes: immediate, indirect and double indirect. The assembler syntax for each mode is:
  68. .IP
  69. .TS
  70. lf(CW) lfR .
  71. 10(fp) 30-bit signed indirect from fp
  72. 20(mp) 30-bit signed indirect from mp
  73. $0x123 30-bit signed immediate value
  74. 10(20(fp)) two 16-bit unsigned offsets double indirect from fp
  75. 10(20(mp)) two 16-bit unsigned offsets double indirect from mp
  76. .TE
  77. .SH
  78. Garbage Collection
  79. .LP
  80. The Dis machine performs both reference counted and real time mark and sweep garbage collection. This hyrbrid approach allows code to be generated in several styles: pure reference counted, mark and sweep, or a hybrid of the two approaches. Compiler writers have the freedom to choose how specific types are handled by the machine to optimize code for performance or language implementation. Instruction selection determines which algorithm will be applied to specific types.
  81. .LP
  82. When using reference counting, pointers are a special operand type and should only be manipulated using the pointer instructions in order to ensure the correct functioning of the garbage collector. Every memory location that stores a pointer must be known to the interpreter so that it can be initialized and deallocated correctly. The information is transmitted in the form of type descriptors in the object module. Each type descriptor contains a bit vector for a particular type where each bit corresponds to a word in memory. Type descriptors are generated automatically by the Limbo compiler. The assembler syntax for a type descriptor is:
  83. .P1
  84. desc $10, 132, "001F"
  85. .P2
  86. The first parameter is the descriptor number, the second is the size in bytes, and the third a pointer map. The map contains a list of hex bytes where each byte maps eight 32 bit words. The most significant bit represents the lowest memory address.
  87. A one bit indicates a pointer in memory. The map need not have an entry for every byte and unspecified bytes are assumed zero.
  88. .LP
  89. Throughout this description, the symbolic constant
  90. .CW H
  91. refers to a nil pointer.
  92. .NH 1
  93. Instruction Set
  94. .SH
  95. add\fIx\fP \- Add
  96. .P1
  97. Syntax: addb src1, src2, dst
  98. addf src1, src2, dst
  99. addw src1, src2, dst
  100. addl src1, src2, dst
  101. Function: dst = src1 + src2
  102. .P2
  103. .LP
  104. The
  105. .CW "add"
  106. instructions compute the sum of the operands addressed by
  107. .CW "src1"
  108. and
  109. .CW "src2"
  110. and stores the result in the
  111. .CW " dst"
  112. operand. For
  113. .CW "addb"
  114. the result is truncated to eight bits.
  115. .SH
  116. addc \- Add strings
  117. .P1
  118. Syntax: addc src1, src2, dst
  119. Function: dst = src1 + src2
  120. .P2
  121. .LP
  122. The
  123. .CW "addc"
  124. instruction concatenates the two UTF strings pointed to by
  125. .CW " src1"
  126. and
  127. .CW "src2" ;
  128. the result is placed in the pointer addressed by
  129. .CW "dst" .
  130. If both pointers are
  131. .CW "H"
  132. the result will be a zero length string rather than
  133. .CW "H" .
  134. .SH
  135. alt \- Alternate between communications
  136. .P1
  137. Syntax: alt src, dst
  138. .P2
  139. The
  140. .CW "alt"
  141. instruction selects between a set of channels ready to communicate. The
  142. .CW src
  143. argument is the address of a structure of the following form:
  144. .P1
  145. struct Alt {
  146. int nsend; /* Number of senders */
  147. int nrecv; /* Number of receivers */
  148. struct {
  149. Channel* c; /* Channel */
  150. void* val; /* Address of lval/rval */
  151. } entry[];
  152. };
  153. .P2
  154. The vector is divided into two sections; the first lists the channels ready to send values, the second lists channels either ready to receive or an array of channels each of which may be ready to receive. The counts of the sender and receiver channels are stored as the first and second words addressed by
  155. .CW src .
  156. An
  157. .CW "alt"
  158. instruction proceeds by testing each channel for readiness to communicate. A ready channel is added to a list. If the list is empty after each channel has been considered, the thread blocks at the
  159. .CW "alt"
  160. instruction waiting for a channel to become ready; otherwise, a channel is picked at random from the ready set.
  161. .LP
  162. The
  163. .CW "alt"
  164. instruction then uses the selected channel to perform the communication using the
  165. .CW "val"
  166. address as either a source for send or a destination for receive. The numeric index of the selected vector element is placed in
  167. .CW "dst" .
  168. .SH
  169. and\fIx\fP \- Logical AND
  170. .P1
  171. Syntax: andb src1, src2, dst
  172. andw src1, src2, dst
  173. andl src1, src2, dst
  174. Function: dst = src1 & src2
  175. .P2
  176. The instructions compute the bitwise AND of the two operands addressed by
  177. .CW "src1"
  178. and
  179. .CW "src2"
  180. and stores the result in the
  181. .CW "dst"
  182. operand.
  183. .SH
  184. beq\fIx\fP \- Branch equal
  185. .P1
  186. Syntax: beqb src1, src2, dst
  187. beqc src1, src2, dst
  188. beqf src1, src2, dst
  189. beqw src1, src2, dst
  190. beql src1, src2, dst
  191. Function: if src1 == src2 then pc = dst
  192. .P2
  193. If the
  194. .CW "src1"
  195. operand is equal to the
  196. .CW "src2"
  197. operand, then control is transferred to the program counter specified by the
  198. .CW "dst"
  199. operand.
  200. .SH
  201. bge\fIx\fP \- Branch greater or equal
  202. .P1
  203. Syntax: bgeb src1, src2, dst
  204. bgec src1, src2, dst
  205. bgef src1, src2, dst
  206. bgew src1, src2, dst
  207. bgel src1, src2, dst
  208. Function: if src1 >= src2 then pc = dst
  209. .P2
  210. If the
  211. .CW "src1"
  212. operand is greater than or equal to the
  213. .CW "src2"
  214. operand, then control is transferred to program counter specified by the
  215. .CW "dst"
  216. operand. This instruction performs a signed comparison.
  217. .SH
  218. bgt\fIx\fP \- Branch greater
  219. .P1
  220. Syntax: bgtb src1, src2, dst
  221. bgtc src1, src2, dst
  222. bgtf src1, src2, dst
  223. bgtw src1, src2, dst
  224. bgtl src1, src2, dst
  225. Function: if src1 > src2 then pc = dst
  226. .P2
  227. If the
  228. .CW "src1"
  229. operand is greater than the
  230. .CW "src2"
  231. operand, then control is transferred to the program counter specified by the
  232. .CW "dst"
  233. operand. This instruction performs a signed comparison.
  234. .SH
  235. ble\fIx\fP \- Branch less than or equal
  236. .P1
  237. Syntax: bleb src1, src2, dst
  238. blec src1, src2, dst
  239. blef src1, src2, dst
  240. blew src1, src2, dst
  241. blel src1, src2, dst
  242. Function: if src1 <= src2 then pc = dst
  243. .P2
  244. If the
  245. .CW "src1"
  246. operand is less than or equal to the
  247. .CW "src2"
  248. operand, then control is transferred to the program counter specified by the
  249. .CW "dst"
  250. operand. This instruction performs a signed comparison.
  251. .SH
  252. blt\fIx\fP \- Branch less than
  253. .P1
  254. Syntax: bltb src1, src2, dst
  255. bltc src1, src2, dst
  256. bltf src1, src2, dst
  257. bltw src1, src2, dst
  258. bltl src1, src2, dst
  259. Function: if src1 < src2 then pc = dst
  260. .P2
  261. If the
  262. .CW "src1"
  263. operand is less than the
  264. .CW "src2"
  265. operand, then control is transferred to the program counter specified by the
  266. .CW "dst"
  267. operand.
  268. .SH
  269. bne\fIx\fP \- Branch not equal
  270. .P1
  271. Syntax: bneb src1, src2, dst
  272. bnec src1, src2, dst
  273. bnef src1, src2, dst
  274. bnew src1, src2, dst
  275. bnel src1, src2, dst
  276. Function: if src1 != src2 then pc = dst
  277. .P2
  278. If the
  279. .CW "src1"
  280. operand is not equal to the
  281. .CW "src2"
  282. operand, then control is transferred to the program counter specified by the
  283. .CW "dst"
  284. operand.
  285. .SH
  286. call \- Call local function
  287. .P1
  288. Syntax: call src, dst
  289. Function: link(src) = pc
  290. frame(src) = fp
  291. mod(src) = 0
  292. fp = src
  293. pc = dst
  294. .P2
  295. The
  296. .CW "call"
  297. instruction performs a function call to a routine in the same module. The
  298. .CW "src"
  299. argument specifies a frame created by
  300. .CW "new" .
  301. The current value of
  302. .CW "pc"
  303. is stored in link(src), the current value of
  304. .CW "fp"
  305. is stored in frame(src) and the module link register is set to 0. The value of
  306. .CW "fp"
  307. is then set to
  308. .CW "src"
  309. and control is transferred to the program counter specified by
  310. .CW dst .
  311. .SH
  312. case \- Case compare integer and branch
  313. .P1
  314. Syntax: case src, dst
  315. Function: pc = 0..i: dst[i].pc where
  316. dst[i].lo >= src && dst[i].hi < src
  317. .P2
  318. The
  319. .CW "case"
  320. instruction jumps to a new location specified by a range of values. The
  321. .CW "dst"
  322. operand points to a table in memory containing a table of
  323. .CW "i"
  324. values. Each value is three words long: the first word specifies a low value, the second word specifies a high value, and the third word specifies a program counter. The first word of the table gives the number of entries. The
  325. .CW "case"
  326. instruction searches the table for the first matching value where the
  327. .CW "src"
  328. operand is greater than or equal to the low word and less than the high word. Control is transferred to the program counter stored in the first word of the matching entry.
  329. .SH
  330. casec \- Case compare string and branch
  331. .P1
  332. Syntax: casec src, dst
  333. Function: pc = 0..i: dst[i].pc where
  334. dst[i].lo >= src && dst[i].hi < src
  335. .P2
  336. The
  337. .CW "casec"
  338. instruction jumps to a new location specified by a range of string constants. The table is the same as described for the
  339. .CW case
  340. instruction.
  341. .SH
  342. cons\fIx\fP \- Allocate new list element
  343. .P1
  344. Syntax: consb src, dst
  345. consc src, dst
  346. consf src, dst
  347. consl src, dst
  348. consm src, dst
  349. consmp src, dst
  350. consp src, dst
  351. consw src, dst
  352. Function: p = new(src, dst)
  353. dst = p
  354. .P2
  355. The
  356. .CW "cons"
  357. instructions add a new element to the head of a list. A new list element is composed from the
  358. .CW "src"
  359. operand and a pointer to the head of an extant list specified by
  360. .CW "dst" .
  361. The resulting element is stored back into
  362. .CW "dst" .
  363. .SH
  364. cvtac \- Convert byte array to string
  365. .P1
  366. Syntax: cvtac src, dst
  367. Function: dst = string(src)
  368. .P2
  369. The
  370. .CW "src"
  371. operand must be an array of bytes, which is converted into a character string and stored in
  372. .CW "dst" .
  373. The new string is a copy of the bytes in
  374. .CW "src" .
  375. .SH
  376. cvtbw \- Convert byte to word
  377. .P1
  378. Syntax: cvtbw src, dst
  379. Function: dst = src & 0xff
  380. .P2
  381. A byte is fetched from the
  382. .CW "src"
  383. operand extended to the size of a word and then stored into
  384. .CW "dst" .
  385. .SH
  386. cvtca \- Convert string to byte array
  387. .P1
  388. Syntax: cvtca src, dst
  389. Function: dst = array(src)
  390. .P2
  391. The
  392. .CW "src"
  393. operand must be a string which is converted into an array of bytes and stored in
  394. .CW "dst" .
  395. The new array is a copy of the characters in src.
  396. .SH
  397. cvtcf \- Convert string to real
  398. .P1
  399. Syntax: cvtcf src, dst
  400. Function: dst = (float)src
  401. .P2
  402. The string addressed by the
  403. .CW "src"
  404. operand is converted to a floating point value and stored in the
  405. .CW "dst"
  406. operand. Initial white space is ignored; conversion ceases at the first character in the string that is not part of the representation of the floating point value.
  407. .SH
  408. cvtcl \- Convert string to big
  409. .P1
  410. Syntax: cvtcl src, dst
  411. Function: dst = (big)src
  412. .P2
  413. The string addressed by the
  414. .CW "src"
  415. operand is converted to a big integer and stored in the
  416. .CW "dst"
  417. operand. Initial white space is ignored; conversion ceases at the first non-digit in the string.
  418. .SH
  419. cvtcw \- Convert string to word
  420. .P1
  421. Syntax: cvtcw src, dst
  422. Function: dst = (int)src
  423. .P2
  424. The string addressed by the
  425. .CW "src"
  426. operand is converted to a word and stored in the
  427. .CW "dst"
  428. operand. Initial white space is ignored; after a possible sign, conversion ceases at the first non-digit in the string.
  429. .SH
  430. cvtfc \- Convert real to string
  431. .P1
  432. Syntax: cvtfc src, dst
  433. Function: dst = string(src)
  434. .P2
  435. The floating point value addressed by the
  436. .CW "src"
  437. operand is converted to a string and stored in the
  438. .CW "dst"
  439. operand. The string is a floating point representation of the value.
  440. .SH
  441. cvtfw \- Convert real to word
  442. .P1
  443. Syntax: cvtfw src, dst
  444. Function: dst = (int)src
  445. .P2
  446. The floating point value addressed by
  447. .CW "src"
  448. is converted into a word and stored into
  449. .CW "dst" .
  450. The floating point value is rounded to the nearest integer.
  451. .SH
  452. cvtfl \- Convert real to big
  453. .P1
  454. Syntax: cvtfl src, dst
  455. Function: dst = (big)src
  456. .P2
  457. The floating point value addressed by
  458. .CW "src"
  459. is converted into a big integer and stored into
  460. .CW "dst" .
  461. The floating point value is rounded to the nearest integer.
  462. .SH
  463. cvtfr \- Convert real to short real†
  464. .P1
  465. Syntax: cvtfr src, dst
  466. Function: dst = (short float)src
  467. .P2
  468. The floating point value addressed by
  469. .CW "src"
  470. is converted to a short (32-bit) floating point value and stored into
  471. .CW "dst" .
  472. The floating point value is rounded to the nearest integer.
  473. .SH
  474. cvtlc \- Convert big to string
  475. .P1
  476. Syntax: cvtlc src, dst
  477. Function: dst = string(src)
  478. .P2
  479. The big integer addressed by the
  480. .CW "src"
  481. operand is converted to a string and stored in the
  482. .CW "dst"
  483. operand. The string is the decimal representation of the big integer.
  484. .SH
  485. cvtlw \- Convert big to word
  486. .P1
  487. Syntax: cvtlw src, dst
  488. Function: dst = (int)src
  489. .P2
  490. The big integer addressed by the
  491. .CW "src"
  492. operand is converted to a word and stored in the
  493. .CW "dst"
  494. operand.
  495. .SH
  496. cvtsw \- Convert short word to word†
  497. .P1
  498. Syntax: cvtsw src, dst
  499. Function: dst = (int)src
  500. .P2
  501. The short word addressed by the
  502. .CW "src"
  503. operand is converted to a word and stored in the
  504. .CW "dst"
  505. operand.
  506. .SH
  507. cvtwb \- Convert word to byte
  508. .P1
  509. Syntax: cvtwb src, dst
  510. Function: dst = (byte)src;
  511. .P2
  512. The
  513. .CW "src"
  514. operand is converted to a byte and stored in the
  515. .CW "dst"
  516. operand.
  517. .SH
  518. cvtwc \- Convert word to string
  519. .P1
  520. Syntax: cvtwc src, dst
  521. Function: dst = string(src)
  522. .P2
  523. The word addressed by the
  524. .CW "src"
  525. operand is converted to a string and stored in the
  526. .CW "dst"
  527. operand. The string is the decimal representation of the word.
  528. .SH
  529. cvtwl \- Convert word to big
  530. .P1
  531. Syntax: cvtwl src, dst
  532. Function: dst = (big)src;
  533. .P2
  534. The word addressed by the
  535. .CW "src"
  536. operand is converted to a big integer and stored in the
  537. .CW "dst"
  538. operand.
  539. .SH
  540. cvtwf \- Convert word to real
  541. .P1
  542. Syntax: cvtwf src, dst
  543. Function: dst = (float)src;
  544. .P2
  545. The word addressed by the
  546. .CW "src"
  547. operand is converted to a floating point value and stored in the
  548. .CW "dst"
  549. operand.
  550. .SH
  551. cvtws \- Convert word to short word†
  552. .P1
  553. Syntax: cvtws src, dst
  554. Function: dst = (short)src;
  555. .P2
  556. The word addressed by the
  557. .CW "src"
  558. operand is converted to a short word and stored in the
  559. .CW "dst"
  560. operand.
  561. .SH
  562. cvtlf \- Convert big to real
  563. .P1
  564. Syntax: cvtlf src, dst
  565. Function: dst = (float)src;
  566. .P2
  567. The big integer addressed by the
  568. .CW "src"
  569. operand is converted to a floating point value and stored in the
  570. .CW "dst"
  571. operand.
  572. .SH
  573. cvtrf \- Convert short real to real†
  574. .P1
  575. Syntax: cvtrf src, dst
  576. Function: dst = (float)src;
  577. .P2
  578. The short (32 bit) floating point value addressed by the
  579. .CW "src"
  580. operand is converted to a 64-bit floating point value and stored in the
  581. .CW "dst"
  582. operand.
  583. .SH
  584. div\fIx\fP \- Divide
  585. .P1
  586. Syntax: divb src1, src2, dst
  587. divf src1, src2, dst
  588. divw src1, src2, dst
  589. divl src1, src2, dst
  590. Function: dst = src2/src1
  591. .P2
  592. The
  593. .CW "src2"
  594. operand is divided by the
  595. .CW "src1"
  596. operand and the quotient is stored in the
  597. .CW "dst"
  598. operand. Division by zero causes the thread to terminate.
  599. .SH
  600. exit \- Terminate thread
  601. .P1
  602. Syntax: exit
  603. Function: exit()
  604. .P2
  605. The executing thread terminates. All resources held in the stack are deallocated.
  606. .SH
  607. frame \- Allocate frame for local call
  608. .P1
  609. Syntax: frame src1, src2
  610. Function: src2 = fp + src1->size
  611. initmem(src2, src1);
  612. .P2
  613. The frame instruction creates a new stack frame
  614. for a call to a function in the same module. The frame is initialized according to the type descriptor supplied as the
  615. .CW src1
  616. operand. A pointer to the newly created frame is stored in the
  617. .CW src2
  618. operand.
  619. .SH
  620. goto \- Computed goto
  621. .P1
  622. Syntax: goto src, dst
  623. Function: pc = dst[src]
  624. .P2
  625. The
  626. .CW "goto"
  627. instruction performs a computed goto. The
  628. .CW "src"
  629. operand must be an integer index into a table of PC values specified by the
  630. .CW "dst"
  631. operand.
  632. .SH
  633. head\fIx\fP \- Head of list
  634. .P1
  635. Syntax: headb src, dst
  636. headf src, dst
  637. headm src, dst
  638. headmp src, dst
  639. headp src, dst
  640. headw src, dst
  641. headl src, dst
  642. Function: dst = hd src
  643. .P2
  644. The
  645. .CW "head"
  646. instructions make a copy of the first data item stored in a list. The
  647. .CW "src"
  648. operand must be a list of the correct type. The first item is copied into the
  649. .CW "dst"
  650. operand. The list is not modified.
  651. .SH
  652. indc \- Index by character
  653. .P1
  654. Syntax: indc src1, src2, dst
  655. Function: dst = src1[src2]
  656. .P2
  657. The
  658. .CW "indc"
  659. instruction indexes Unicode strings. The
  660. .CW "src1"
  661. instruction must be a string. The
  662. .CW "src2"
  663. operand must be an integer specifying the origin-0 index in
  664. .CW src1
  665. of the (Unicode) character to store in the
  666. .CW "dst"
  667. operand.
  668. .SH
  669. indx \- Array index
  670. .P1
  671. Syntax: indx src1, dst, src2
  672. Function: dst = &src1[src2]
  673. .P2
  674. The
  675. .CW "indx"
  676. instruction computes the effective address of an array element. The
  677. .CW "src1"
  678. operand must be an array created by the
  679. .CW "newa"
  680. instruction. The
  681. .CW "src2"
  682. operand must be an integer. The effective address of the
  683. .CW "src2"
  684. element of the array is stored in the
  685. .CW "dst"
  686. operand.
  687. .SH
  688. ind\fIx\fP \- Index by type
  689. .P1
  690. Syntax: indb src1, dst, src2
  691. indw src1, dst, src2
  692. indf src1, dst, src2
  693. indl src1, dst, src2
  694. Function: dst = &src1[src2]
  695. .P2
  696. The
  697. .CW "indb" ,
  698. .CW "indw" ,
  699. .CW "indf"
  700. and
  701. .CW "indl"
  702. instructions index arrays of the basic types. The
  703. .CW "src1"
  704. operand must be an array created by the
  705. .CW "newa"
  706. instruction. The
  707. .CW "src2"
  708. operand must be a non-negative integer index less than the array size. The effective address of the element at the index is stored in the
  709. .CW "dst"
  710. operand.
  711. .SH
  712. insc \- Insert character into string
  713. .P1
  714. Syntax: insc src1, src2, dst
  715. Function: src1[src2] = dst
  716. .P2
  717. The
  718. .CW "insc"
  719. instruction inserts a character into an existing string.
  720. The index in
  721. .CW "src2"
  722. must be a non-negative integer less than the length of the string plus one.
  723. (The character will be appended to the string if the index is equal to
  724. the string's length.)
  725. The
  726. .CW "src1"
  727. operand must be a string (or nil).
  728. The character to insert must be a valid 21-bit unicode value represented as a word.
  729. .SH
  730. jmp \- Branch always
  731. .P1
  732. Syntax: jmp dst
  733. Function: pc = dst
  734. .P2
  735. Control is transferred to the location specified by the
  736. .CW "dst"
  737. operand.
  738. .SH
  739. lea \- Load effective address
  740. .P1
  741. Syntax: lea src, dst
  742. Function: dst = &src
  743. .P2
  744. The
  745. .CW "lea"
  746. instruction computes the effective address of the
  747. .CW "src"
  748. operand and stores it in the
  749. .CW "dst"
  750. operand.
  751. .SH
  752. lena \- Length of array
  753. .P1
  754. Syntax: lena src, dst
  755. Function: dst = nelem(src)
  756. .P2
  757. The
  758. .CW "lena"
  759. instruction computes the length of the array specified by the
  760. .CW "src"
  761. operand and stores it in the
  762. .CW "dst"
  763. operand.
  764. .SH
  765. lenc \- Length of string
  766. .P1
  767. Syntax: lenc src, dst
  768. Function: dst = utflen(src)
  769. .P2
  770. The
  771. .CW "lenc"
  772. instruction computes the number of characters in the UTF string addressed by the
  773. .CW "src"
  774. operand and stores it in the
  775. .CW "dst"
  776. operand.
  777. .SH
  778. lenl \- Length of list
  779. .P1
  780. Syntax: lenl src, dst
  781. Function: dst = 0;
  782. for(l = src; l; l = tl l)
  783. dst++;
  784. .P2
  785. The
  786. .CW "lenl"
  787. instruction computes the number of elements in the list addressed by the
  788. .CW "src"
  789. operand and stores the result in the
  790. .CW "dst"
  791. operand.
  792. .SH
  793. load \- Load module
  794. .P1
  795. Syntax: load src1, src2, dst
  796. Function: dst = load src2 src1
  797. .P2
  798. The
  799. .CW "load"
  800. instruction loads a new module into the heap. The module might optionally be compiled into machine code depending on the module header. The
  801. .CW "src1"
  802. operand is a pathname to the file containing the object code for the module. The
  803. .CW "src2"
  804. operand specifies the address
  805. of a linkage descriptor for the module (see below).
  806. A reference to the newly loaded module is stored in the
  807. .CW "dst"
  808. operand.
  809. If the module could not be loaded for any reason, then
  810. .CW "dst"
  811. will be set to
  812. .CW H .
  813. .LP
  814. The linkage descriptor referenced by the
  815. .CW src2
  816. operand is a table in data space that lists the functions
  817. imported by the current module from the module to be loaded.
  818. It has the following layout:
  819. .P1
  820. int nentries;
  821. struct { /* word aligned */
  822. int sig;
  823. byte name[]; /* UTF encoded name, 0-terminated */
  824. } entry[];
  825. .P2
  826. The
  827. .CW nentries
  828. value gives the number of entries in the table and can be zero.
  829. It is followed by that many linkage entries.
  830. Each entry is aligned on a word boundary; there can therefore
  831. be padding before each structure.
  832. The entry names the imported function in the UTF-encoded string in
  833. .CW name ,
  834. which is terminated by a byte containing zero.
  835. The MD5 hash of the function's type signature is given in the value
  836. .CW sig .
  837. For each entry,
  838. .CW load
  839. instruction checks that a function with the same name in the newly loaded
  840. exists, with the same signature.
  841. Otherwise the load will fail and
  842. .CW dst
  843. will be set to
  844. .CW H .
  845. .LP
  846. The entries in the linkage descriptor form an array of linkage records
  847. (internal to the virtual machine) associated with the
  848. module pointer returned in
  849. .CW dst ,
  850. that is indexed by operators
  851. .CW mframe ,
  852. .CW mcall
  853. and
  854. .CW mspawn
  855. to refer to functions in that module.
  856. The linkage scheme provides a level of indirection that allows
  857. a module to be loaded using any module declaration that is a valid
  858. subset of the implementation module's declaration,
  859. and allows entry points to be added to modules without invalidating
  860. calling modules.
  861. .SH
  862. lsr\fIx\fP \- Logical shift right
  863. .P1
  864. Syntax: lsrw src1, src2, dst
  865. lsrl src1, src2, dst
  866. Function: dst = (unsigned)src2 >> src1
  867. .P2
  868. The
  869. .CW "lsr"
  870. instructions shift the
  871. .CW "src2"
  872. operand right by the number of bits specified by the
  873. .CW "src1"
  874. operand, replacing the vacated bits by 0, and store the result in the
  875. .CW "dst"
  876. operand. Shift counts less than 0 or greater than the number of bits in the object have undefined results.
  877. This instruction is included for support of languages other than Limbo,
  878. and is not used by the Limbo compiler.
  879. .SH
  880. mcall \- Inter-module call
  881. .P1
  882. Syntax: mcall src1, src2, src3
  883. Function: link(src1) = pc
  884. frame(src1) = fp
  885. mod(src1) = current_moduleptr
  886. current_moduleptr = src3->moduleptr
  887. fp = src1
  888. pc = src3->links[src2]->pc
  889. .P2
  890. The
  891. .CW "mcall"
  892. instruction calls a function in another module. The first argument specifies a new frame for the called procedure and must have been built using the
  893. .CW "mframe"
  894. instruction.
  895. The
  896. .CW "src3"
  897. operand is a module reference generated by a successful
  898. .CW "load"
  899. instruction.
  900. The
  901. .CW "src2"
  902. operand specifies the index for the called
  903. function in the array of linkage records associated with that module reference
  904. (see the
  905. .CW load
  906. instruction).
  907. .SH
  908. mframe \- Allocate inter-module frame
  909. .P1
  910. Syntax: mframe src1, src2, dst
  911. Function: dst = fp + src1->links[src2]->t->size
  912. initmem(dst, src1->links[src2])
  913. .P2
  914. The
  915. .CW mframe
  916. instruction allocates a new frame for a procedure call into another module. The
  917. .CW src1
  918. operand specifies the location of a module pointer created as the result of a successful load instruction. The
  919. .CW src2
  920. operand specifies the index for the called function in
  921. the array of linkage records associated
  922. with that module pointer (see the
  923. .CW load
  924. instruction).
  925. A pointer to the initialized frame is stored in
  926. .CW dst .
  927. The
  928. .CW src2
  929. operand specifies the linkage number of the function to be called in the module specified by
  930. .CW src1 .
  931. .SH
  932. mnewz \- Allocate object given type from another module
  933. .P1
  934. Syntax: mnewz src1, src2, dst
  935. Function: dst = malloc(src1->types[src2]->size)
  936. initmem(dst, src1->types[src2]->map)
  937. .P2
  938. The
  939. .CW mnewz
  940. instruction allocates and initializes storage to a new
  941. area of memory.
  942. The
  943. .CW src1
  944. operand specifies the location of a module pointer created as the result of a successful load instruction.
  945. The size of the new memory area and the location of
  946. pointers within it are specified by the
  947. .CW src2
  948. operand, which gives a
  949. type descriptor number within that module.
  950. Space not occupied by pointers is initialized to zero.
  951. A pointer to the initialized object is stored in
  952. .CW dst .
  953. This instruction is not used by Limbo; it was added to implement other languages.
  954. .SH
  955. mod\fIx\fP \- Modulus
  956. .P1
  957. Syntax: modb src1, src2, dst
  958. modw src1, src2, dst
  959. modl src1, src2, dst
  960. Function: dst = src2 % src1
  961. .P2
  962. The modulus instructions compute the remainder of the
  963. .CW "src2"
  964. operand divided by the
  965. .CW "src1"
  966. operand and store the result in
  967. .CW "dst" .
  968. The operator preserves the condition that the absolute value of a%b is less than the absolute value of
  969. .CW "b" ;
  970. .CW "(a/b)*b + a%b"
  971. is always equal to
  972. .CW a .
  973. .SH
  974. mov\fIx\fP \- Move scalar
  975. .P1
  976. Syntax: movb src, dst
  977. movw src, dst
  978. movf src, dst
  979. movl src, dst
  980. Function: dst = src
  981. .P2
  982. The move operators perform assignment. The value specified by the
  983. .CW "src"
  984. operand is copied to the
  985. .CW "dst"
  986. operand.
  987. .SH
  988. movm \- Move memory
  989. .P1
  990. Syntax: movm src1, src2, dst
  991. Function: memmove(&dst, &src1, src2)
  992. .P2
  993. The
  994. .CW "movm"
  995. instruction copies memory from the
  996. .CW "src1"
  997. operand to the
  998. .CW "dst"
  999. operand for
  1000. .CW "src2"
  1001. bytes. The
  1002. .CW "src1"
  1003. and
  1004. .CW "dst"
  1005. operands specify the effective address of the memory rather than a pointer to the memory.
  1006. .SH
  1007. movmp \- Move memory and update reference counts
  1008. .P1
  1009. Syntax: movmp src1, src2, dst
  1010. Function: decmem(&dst, src2)
  1011. memmove(&dst, &src1, src2->size)
  1012. incmem(&src, src2)
  1013. .P2
  1014. The
  1015. .CW "movmp"
  1016. instructions performs the same function as the
  1017. .CW "movm"
  1018. instruction but increments the reference count of pointers contained in the data type. For each pointer specified by the
  1019. .CW "src2"
  1020. type descriptor, the corresponding pointer reference count in the destination is decremented. The
  1021. .CW "movmp"
  1022. instruction then copies memory from the
  1023. .CW "src1"
  1024. operand to the
  1025. .CW "dst"
  1026. operand for the number of bytes described by the type descriptor. For each pointer specified by the type descriptor the corresponding pointer reference count in the source is incremented.
  1027. .SH
  1028. movp \- Move pointer
  1029. .P1
  1030. Syntax: movp src, dst
  1031. Function: destroy(dst)
  1032. dst = src
  1033. incref(src)
  1034. .P2
  1035. The
  1036. .CW "movp"
  1037. instruction copies a pointer adjusting the reference counts to reflect the new pointers.
  1038. .SH
  1039. movpc \- Move program counter
  1040. .P1
  1041. Syntax: movpc src, dst
  1042. Function: dst = PC(src);
  1043. .P2
  1044. The
  1045. .CW "movpc"
  1046. instruction computes the actual address of an immediate PC value. The
  1047. .CW "dst"
  1048. operand is set to the actual machine address of the instruction addressed by the
  1049. .CW "src"
  1050. operand. This instruction must be used to calculate PC values for computed branches.
  1051. .SH
  1052. mspawn \- Module spawn function
  1053. .P1
  1054. Syntax: mspawn src1, src2, src3
  1055. Function: fork();
  1056. if(child){
  1057. link(src1) = 0
  1058. frame(src1) = 0
  1059. mod(src1) = src3->moduleptr
  1060. current_moduleptr = src3->moduleptr
  1061. fp = src1
  1062. pc = src3->links[src2]->pc
  1063. }
  1064. .P2
  1065. The
  1066. .CW "mspawn"
  1067. instruction creates a new thread, which starts executing a function in another module.
  1068. The first argument specifies a new frame for the called procedure and must have been built using the
  1069. .CW "mframe"
  1070. instruction.
  1071. The
  1072. .CW "src3"
  1073. operand is a module reference generated by a successful
  1074. .CW "load"
  1075. instruction.
  1076. The
  1077. .CW "src2"
  1078. operand specifies the index for the called function in
  1079. the array of linkage records associated with that module reference (see the
  1080. .CW load
  1081. instruction above).
  1082. .SH
  1083. mul\fIx\fP - Multiply
  1084. .P1
  1085. Syntax: mulb src1, src2, dst
  1086. mulw src1, src2, dst
  1087. mulf src1, src2, dst
  1088. mull src1, src2, dst
  1089. Function: dst = src1 * src2
  1090. .P2
  1091. The
  1092. .CW src1
  1093. operand is multiplied by the
  1094. .CW src2
  1095. operand and the product is stored in the
  1096. .CW dst
  1097. operand.
  1098. .SH
  1099. nbalt \- Non blocking alternate
  1100. .P1
  1101. Syntax: nbalt src, dst
  1102. .P2
  1103. The
  1104. .CW "nbalt"
  1105. instruction has the same operands and function as
  1106. .CW "alt"
  1107. , except that if no channel is ready to communicate, the instruction does not block. When no channels are ready, control is transferred to the PC in the last element of the table addressed by
  1108. .CW dst .
  1109. .SH
  1110. negf \- Negate real
  1111. .P1
  1112. Syntax: negf src, dst
  1113. Function: dst = -src
  1114. .P2
  1115. The floating point value addressed by the
  1116. .CW "src"
  1117. operand is negated and stored in the
  1118. .CW "dst"
  1119. operand.
  1120. .SH
  1121. new, newz \- Allocate object
  1122. .P1
  1123. Syntax: new src, dst
  1124. newz src, dst
  1125. Function: dst = malloc(src->size);
  1126. initmem(dst, src->map);
  1127. .P2
  1128. The
  1129. .CW "new"
  1130. instruction allocates and initializes storage to a new area of memory. The size and locations of pointers are specified by the type descriptor number given as the
  1131. .CW "src"
  1132. operand. A pointer to the newly allocated object is placed in
  1133. .CW "dst" .
  1134. Any space not occupied by pointers has undefined value.
  1135. .LP
  1136. The
  1137. .CW "newz"
  1138. instruction additionally guarantees that all non-pointer values are set to zero.
  1139. It is not used by Limbo.
  1140. .SH
  1141. newa, newaz \- Allocate array
  1142. .P1
  1143. Syntax: newa src1, src2, dst
  1144. newaz src1, src2, dst
  1145. Function: dst = malloc(src2->size * src1);
  1146. for(i = 0; i < src1; i++)
  1147. initmem(dst + i*src2->size, src2->map);
  1148. .P2
  1149. The
  1150. .CW "newa"
  1151. instruction allocates and initializes an array. The number of elements is specified by the
  1152. .CW "src1"
  1153. operand. The type of each element is specified by the type descriptor number given as the
  1154. .CW "src2"
  1155. operand.
  1156. Space not occupied by pointers has undefined value.
  1157. The
  1158. .CW newaz
  1159. instruction additionally guarantees that all non-pointer values are set to zero;
  1160. it is not used by Limbo.
  1161. .SH
  1162. newc\fIx\fP \- Allocate channel
  1163. .P1
  1164. Syntax: newcw dst
  1165. newcb dst
  1166. newcl dst
  1167. newcf dst
  1168. newcp dst
  1169. newcm src, dst
  1170. newcmp src, dst
  1171. Function: dst = new(Channel)
  1172. .P2
  1173. The
  1174. .CW "newc"
  1175. instruction allocates a new channel of the specified type and stores a reference to the channel in
  1176. .CW "dst" .
  1177. For the
  1178. .CW "newcm"
  1179. instruction the source specifies the number of bytes of memory used by values sent on the channel (see the
  1180. .CW movm
  1181. instruction above).
  1182. For the
  1183. .CW "newcmp"
  1184. instruction the first operand specifies a type descriptor giving the length of the structure and the location of pointers within the structure (see the
  1185. .CW movmp
  1186. instruction above).
  1187. .SH
  1188. or\fIx\fP \- Logical OR
  1189. .P1
  1190. Syntax: orb src1, src2, dst
  1191. orw src1, src2, dst
  1192. orl src1, src2, dst
  1193. Function: dst = src1 | src
  1194. .P2
  1195. These instructions compute the bitwise OR of the two operands addressed by
  1196. .CW "src1"
  1197. and
  1198. .CW "src2"
  1199. and store the result in the
  1200. .CW "dst"
  1201. operand.
  1202. .SH
  1203. recv \- Receive from channel
  1204. .P1
  1205. Syntax: recv src, dst
  1206. Function: dst = <-src
  1207. .P2
  1208. The
  1209. .CW "recv"
  1210. instruction receives a value from some other thread on the channel specified by the
  1211. .CW "src"
  1212. operand. Communication is synchronous, so the calling thread will block until a corresponding
  1213. .CW "send"
  1214. or
  1215. .CW "alt"
  1216. is performed on the channel. The type of the received value is determined by the channel type and the
  1217. .CW "dst"
  1218. operand specifies where to place the received value.
  1219. .SH
  1220. ret \- Return from function
  1221. .P1
  1222. Syntax: ret
  1223. Function: npc = link(fp)
  1224. mod = mod(fp)
  1225. fp = frame(fp)
  1226. pc = npc
  1227. .P2
  1228. The
  1229. .CW "ret"
  1230. instruction returns control to the instruction after the call of the current function.
  1231. .SH
  1232. send \- Send to channel
  1233. .P1
  1234. Syntax: send src, dst
  1235. Function: dst <-= src
  1236. .P2
  1237. The
  1238. .CW "send"
  1239. instruction sends a value from this thread to some other thread on the channel specified by the
  1240. .CW "dst"
  1241. operand. Communication is synchronous so the calling thread will block until a corresponding
  1242. .CW "recv"
  1243. or
  1244. .CW "alt"
  1245. is performed on the channel. The type of the sent value is determined by the channel type and the
  1246. .CW "dst"
  1247. operand specifies where to retrieve the sent value.
  1248. .SH
  1249. shl\fIx\fP \- Shift left arithmetic
  1250. .P1
  1251. Syntax: shlb src1, src2, dst
  1252. shlw src1, src2, dst
  1253. shll src1, src2, dst
  1254. Function: dst = src2 << src1
  1255. .P2
  1256. The
  1257. .CW "shl"
  1258. instructions shift the
  1259. .CW "src2"
  1260. operand left by the number of bits specified by the
  1261. .CW "src1"
  1262. operand and store the result in the
  1263. .CW "dst"
  1264. operand. Shift counts less than 0 or greater than the number of bits in the object have undefined results.
  1265. .SH
  1266. shr\fIx\fP \- Shift right arithmetic
  1267. .P1
  1268. Syntax: shrb src1, src2, dst
  1269. shrw src1, src2, dst
  1270. shrl src1, src2, dst
  1271. Function: dst = src2 >> src1
  1272. .P2
  1273. The
  1274. .CW "shr"
  1275. instructions shift the
  1276. .CW "src2"
  1277. operand right by the number of bits specified by the
  1278. .CW "src1"
  1279. operand and store the result in the
  1280. .CW "dst"
  1281. operand. Shift counts less than 0 or greater than the number of bits in the object have undefined results.
  1282. .SH
  1283. slicea \- Slice array
  1284. .P1
  1285. Syntax: slicea src1, src2, dst
  1286. Function: dst = dst[src1:src2]
  1287. .P2
  1288. The
  1289. .CW "slicea"
  1290. instruction creates a new array, which contains the elements from the index at
  1291. .CW "src1"
  1292. to the index
  1293. .CW "src2-1" .
  1294. The new array is a reference array which points at the elements in the initial array. The initial array will remain allocated until both arrays are no longer referenced.
  1295. .SH
  1296. slicec \- Slice string
  1297. .P1
  1298. Syntax: slicec src1, src2, dst
  1299. Function: dst = dst[src1:src2]
  1300. .P2
  1301. The
  1302. .CW "slicec"
  1303. instruction creates a new string, which contains characters from the index at
  1304. .CW "src1"
  1305. to the index
  1306. .CW "src2-1" .
  1307. Unlike
  1308. .CW "slicea"
  1309. , the new string is a copy of the elements from the initial string.
  1310. .SH
  1311. slicela \- Assign to array slice
  1312. .P1
  1313. Syntax: slicela src1, src2, dst
  1314. Function: dst[src2:] = src1
  1315. .P2
  1316. The
  1317. .CW "src1"
  1318. and
  1319. .CW "dst"
  1320. operands must be arrays of equal types. The
  1321. .CW "src2"
  1322. operand is a non-negative integer index. The
  1323. .CW "src1"
  1324. array is assigned to the array slice
  1325. .CW "dst[src2:]" ;
  1326. .CW "src2 + nelem(src1)"
  1327. must not exceed
  1328. .CW "nelem(dst)" .
  1329. .SH
  1330. spawn \- Spawn function
  1331. .P1
  1332. Syntax: spawn src, dst
  1333. Function: fork();
  1334. if(child)
  1335. dst(src);
  1336. .P2
  1337. The
  1338. .CW "spawn"
  1339. instruction creates a new thread and calls the function specified by the
  1340. .CW "dst"
  1341. operand. The argument frame passed to the thread function is specified by the
  1342. .CW "src"
  1343. operand and should have been created by the
  1344. .CW "frame"
  1345. instruction.
  1346. .SH
  1347. sub\fIx\fP \- Subtract
  1348. .P1
  1349. Syntax: subb src1, src2, dst
  1350. subf src1, src2, dst
  1351. subw src1, src2, dst
  1352. subl src1, src2, dst
  1353. Function: dst = src2 - src1
  1354. .P2
  1355. The
  1356. .CW "sub"
  1357. instructions subtract the operands addressed by
  1358. .CW "src1"
  1359. and
  1360. .CW "src2"
  1361. and stores the result in the
  1362. .CW "dst"
  1363. operand. For
  1364. .CW "subb" ,
  1365. the result is truncated to eight bits.
  1366. .SH
  1367. tail \- Tail of list
  1368. .P1
  1369. Syntax: tail src, dst
  1370. Function: dst = src->next
  1371. .P2
  1372. The
  1373. .CW "tail"
  1374. instruction takes the list specified by the
  1375. .CW "src"
  1376. operand and creates a reference to a new list with the head removed, which is stored in the
  1377. .CW "dst"
  1378. operand.
  1379. .SH
  1380. tcmp \- Compare types
  1381. .P1
  1382. Syntax: tcmp src, dst
  1383. Function: if(typeof(src) != typeof(dst))
  1384. error("typecheck");
  1385. .P2
  1386. The
  1387. .CW "tcmp"
  1388. instruction compares the types of the two pointers supplied by the
  1389. .CW "src"
  1390. and
  1391. .CW "dst"
  1392. operands. The comparison will succeed if the two pointers were created from the same type descriptor or the
  1393. .CW "src"
  1394. operand is
  1395. .CW "nil" ;
  1396. otherwise, the program will error. The
  1397. .CW "dst"
  1398. operand must be a valid pointer.
  1399. .SH
  1400. xor\fIx\fP \- Exclusive OR
  1401. .P1
  1402. Syntax: xorb src1, src2, dst
  1403. xorw src1, src2, dst
  1404. xorl src1, src2, dst
  1405. Function: dst = src1 ^ src2
  1406. .P2
  1407. These instructions compute the bitwise exclusive-OR of the two operands addressed by
  1408. .CW "src1"
  1409. and
  1410. .CW "src2"
  1411. and store the result in the
  1412. .CW "dst"
  1413. operand.
  1414. .NH 1
  1415. Object File Format
  1416. .LP
  1417. An object file defines a single module. The file has the following structure:
  1418. .P1
  1419. Objfile
  1420. {
  1421. Header;
  1422. Code_section;
  1423. Type_section;
  1424. Data_section;
  1425. Module_name;
  1426. Link_section;
  1427. };
  1428. .P2
  1429. The following data types are used in the description of the file encoding:
  1430. .IP
  1431. .TS
  1432. lf(CW) lw(4i)fR .
  1433. OP T{
  1434. encoded integer operand, encoding selected by the two most significant bits as follows:
  1435. .nf
  1436. 00 signed 7 bits, 1 byte
  1437. .br
  1438. 10 signed 14 bits, 2 bytes
  1439. .br
  1440. 11 signed 30 bits, 4 bytes
  1441. T}
  1442. B unsigned byte
  1443. W 32 bit signed integer
  1444. F canonicalized 64-bit IEEE754 floating point value
  1445. SO 16 bit unsigned small offset from register
  1446. SI 16 bit signed immediate value
  1447. LO 30 bit signed large offset from register
  1448. .TE
  1449. .LP
  1450. All binary values are encoded in two's complement format, most significant byte first.
  1451. .SH
  1452. The Header Section
  1453. .P1
  1454. Header
  1455. {
  1456. OP: magic_number;
  1457. Signature;
  1458. OP: runtime_flag;
  1459. OP: stack_extent;
  1460. OP: code_size;
  1461. OP: data_size;
  1462. OP: type_size;
  1463. OP: link_size;
  1464. OP: entry_pc;
  1465. OP: entry_type;
  1466. };
  1467. .P2
  1468. The magic number is defined as 819248
  1469. (symbolically
  1470. .CW XMAGIC ),
  1471. for modules that have not been signed cryptographically, and 923426
  1472. (symbolically
  1473. .CW "SMAGIC" ),
  1474. for modules that contain a signature.
  1475. On the Inferno system, the symbolic names
  1476. .CW "XMAGIC"
  1477. and
  1478. .CW SMAGIC
  1479. are defined by the C include file
  1480. .CW "/include/isa.h"
  1481. and the Limbo module
  1482. .CW /module/dis.m .
  1483. .LP
  1484. The signature field is only present if the magic number is
  1485. .CW "SMAGIC" .
  1486. It has the form:
  1487. .P1
  1488. Signature
  1489. {
  1490. OP: length;
  1491. array[length] of byte: signature;
  1492. };
  1493. .P2
  1494. A digital signature is defined by a length, followed by an array of untyped bytes.
  1495. Data within the signature should identify the signing authority, algorithm, and data to be signed.
  1496. .LP
  1497. The
  1498. .CW runtime_flag
  1499. is a bit mask that defines various execution options for a Dis module. The flags currently defined are:
  1500. .P1
  1501. MUSTCOMPILE = 1<<0
  1502. DONTCOMPILE = 1<<1
  1503. SHAREMP = 1<<2
  1504. .P2
  1505. The
  1506. .CW "MUSTCOMPILE"
  1507. flag indicates that a
  1508. .CW "load"
  1509. instruction should draw an error if the implementation is unable to compile the module into native instructions using a just-in-time compiler.
  1510. .LP
  1511. The
  1512. .CW "DONTCOMPILE"
  1513. flag indicates that the module should not be compiled into native instructions, even though it is the default for the runtime environment. This flag may be set to allow debugging or to save memory.
  1514. .LP
  1515. The
  1516. .CW "SHAREMP"
  1517. flag indicates that each instance of the module should use the same module data for all instances of the module. There is no implicit synchronization between threads using the shared data.
  1518. .LP
  1519. The
  1520. .CW stack_extent
  1521. value indicates the number of bytes by which the thread stack of this module should be extended in the event that procedure calls exhaust the allocated stack. While stack extension is transparent to programs, increasing this value may improve the efficiency of execution at the expense of using more memory.
  1522. .LP
  1523. The
  1524. .CW code_size
  1525. is a count of the number of instructions stored in the Code_section.
  1526. .LP
  1527. The
  1528. .CW data_size
  1529. gives the size in bytes of the module's global data, which is initialized
  1530. by evaluating the contents of the data section.
  1531. .LP
  1532. The
  1533. .CW type_size
  1534. is a count of the number of type descriptors stored in the Type_section.
  1535. .LP
  1536. The
  1537. .CW link_size
  1538. is a count of the number of external linkage directives stored in the Link_section.
  1539. .LP
  1540. The
  1541. .CW entry_pc
  1542. is an integer index into the instruction stream that is the default entry point for this module. The
  1543. .CW entry_pc
  1544. should point to the first instruction of a function. Instructions are numbered from a program counter value of zero.
  1545. .LP
  1546. The
  1547. .CW entry_type
  1548. is the index of the type descriptor that corresponds to the function entry point set by
  1549. .CW entry_pc .
  1550. .SH
  1551. The Code Section
  1552. .LP
  1553. The code section describes a sequence of instructions for the virtual machine. An instruction is encoded as follows:
  1554. .P1
  1555. Instruction
  1556. {
  1557. B: opcode;
  1558. B: address_mode;
  1559. Middle_data;
  1560. Source_data;
  1561. Dest_data;
  1562. };
  1563. .P2
  1564. .LP
  1565. The
  1566. .CW opcode
  1567. specifies the instruction to execute, encoded as follows:
  1568. .IP
  1569. .TS
  1570. tab(:);
  1571. l l l l l .
  1572. 00 nop:20 headb:40 mulw:60 blew:80 shrl
  1573. 01 alt:21 headw:41 mulf:61 bgtw:81 bnel
  1574. 02 nbalt:22 headp:42 divb:62 bgew:82 bltl
  1575. 03 goto:23 headf:43 divw:63 beqf:83 blel
  1576. 04 call:24 headm:44 divf:64 bnef:84 bgtl
  1577. 05 frame:25 headmp:45 modw:65 bltf:85 bgel
  1578. 06 spawn:26 tail:46 modb:66 blef:86 beql
  1579. 07 runt:27 lea:47 andb:67 bgtf:87 cvtlf
  1580. 08 load:28 indx:48 andw:68 bgef:88 cvtfl
  1581. 09 mcall:29 movp:49 orb:69 beqc:89 cvtlw
  1582. 0A mspawn:2A movm:4A orw:6A bnec:8A cvtwl
  1583. 0B mframe:2B movmp:4B xorb:6B bltc:8B cvtlc
  1584. 0C ret:2C movb:4C xorw:6C blec:8C cvtcl
  1585. 0D jmp:2D movw:4D shlb:6D bgtc:8D headl
  1586. 0E case:2E movf:4E shlw:6E bgec:8E consl
  1587. 0F exit:2F cvtbw:4F shrb:6F slicea:8F newcl
  1588. 10 new:30 cvtwb:50 shrw:70 slicela:90 casec
  1589. 11 newa:31 cvtfw:51 insc:71 slicec:91 indl
  1590. 12 newcb:32 cvtwf:52 indc:72 indw:92 movpc
  1591. 13 newcw:33 cvtca:53 addc:73 indf:93 tcmp
  1592. 14 newcf:34 cvtac:54 lenc:74 indb:94 mnewz
  1593. 15 newcp:35 cvtwc:55 lena:75 negf:95 cvtrf
  1594. 16 newcm:36 cvtcw:56 lenl:76 movl:96 cvtfr
  1595. 17 newcmp:37 cvtfc:57 beqb:77 addl:97 cvtws
  1596. 18 send:38 cvtcf:58 bneb:78 subl:98 cvtsw
  1597. 19 recv:39 addb:59 bltb:79 divl:99 lsrw
  1598. 1A consb:3A addw:5A bleb:7A modl:9A lsrl
  1599. 1B consw:3B addf:5B bgtb:7B mull:9B eclr
  1600. 1C consp:3C subb:5C bgeb:7C andl:9C newz
  1601. 1D consf:3D subw:5D beqw:7D orl:9D newaz
  1602. 1E consm:3E subf:5E bnew:7E xorl
  1603. 1F consmp:3F mulb:5F bltw:7F shll
  1604. .TE
  1605. .LP
  1606. The
  1607. .CW address_mode
  1608. byte specifies the addressing mode of each of the three operands: middle, source and destination. The source and destination operands are encoded by three bits and the middle operand by two bits. The bits are packed as follows:
  1609. .P1
  1610. bit 7 6 5 4 3 2 1 0
  1611. m1 m0 s2 s1 s0 d2 d1 d0
  1612. .P2
  1613. The middle operand is encoded as follows:
  1614. .IP
  1615. .TS
  1616. lf(CW) lf(CW) lw(3i)fR .
  1617. 00 \fInone\fP no middle operand
  1618. 01 $SI small immediate
  1619. 10 SO(FP) small offset indirect from FP
  1620. 11 SO(MP) small offset indirect from MP
  1621. .TE
  1622. .LP
  1623. The source and destination operands are encoded as follows:
  1624. .IP
  1625. .TS
  1626. lf(CW) lf(CW) lw(3i)fR .
  1627. 000 LO(MP) offset indirect from MP
  1628. 001 LO(FP) offset indirect from FP
  1629. 010 $OP 30 bit immediate
  1630. 011 \fInone\fP no operand
  1631. 100 SO(SO(MP)) double indirect from MP
  1632. 101 SO(SO(FP)) double indirect from FP
  1633. 110 \fIreserved\fP
  1634. 111 \fIreserved\fP
  1635. .TE
  1636. .LP
  1637. The
  1638. .CW middle_data
  1639. field is only present if the middle operand specifier of the address_mode is not `none'.
  1640. If the field is present it is encoded as an
  1641. .CW "OP" .
  1642. .LP
  1643. The
  1644. .CW source_data
  1645. and
  1646. .CW dest_data
  1647. fields are present only if the corresponding
  1648. .CW address_mode
  1649. field is not `none'.
  1650. For offset indirect and immediate modes the field contains a single
  1651. .CW "OP" .
  1652. For double indirect modes the values are encoded as two
  1653. .CW "OP"
  1654. values: the first value is the register indirect offset, and the second value is the final indirect offset. The offsets for double indirect addressing cannot be larger than 16 bits.
  1655. .SH
  1656. The Type Section
  1657. .LP
  1658. The type section contains type descriptors describing the layout of pointers within data types. The format of each descriptor is:
  1659. .P1
  1660. Type_descriptor
  1661. {
  1662. OP: desc_number;
  1663. OP: size;
  1664. OP: number_ptrs;
  1665. array[number_ptrs] of B: map;
  1666. };
  1667. .P2
  1668. .LP
  1669. The
  1670. .CW desc_number
  1671. is a small integer index used to identify the descriptor to instructions such as
  1672. .CW "new" .
  1673. .LP
  1674. The
  1675. .CW "size"
  1676. field is the size in bytes of the memory described by this type.
  1677. .LP
  1678. The
  1679. .CW number_ptrs
  1680. field gives the size in bytes of the
  1681. .CW "map"
  1682. array.
  1683. .LP
  1684. The
  1685. .CW "map"
  1686. array is a bit vector where each bit corresponds to a word in memory.
  1687. The most significant bit corresponds to the lowest address.
  1688. For each bit in the map,
  1689. the word at the corresponding offset in the type is a pointer iff the bit is set to 1.
  1690. .SH
  1691. The Data Section
  1692. .LP
  1693. The data section encodes the contents of the
  1694. .CW "MP"
  1695. data for the module. The section contains a sequence of items; each item contains
  1696. a control byte and an offset into the section,
  1697. followed by one or more data items.
  1698. A control byte of zero marks the end of the data section.
  1699. Otherwise, it gives the type of data to be loaded and selects between
  1700. two representations of an item:
  1701. .P1
  1702. Short_item
  1703. {
  1704. B: code;
  1705. OP: offset;
  1706. array[code & 16rF] of type[code>>4]: data;
  1707. };
  1708. .P3
  1709. Long_item
  1710. {
  1711. B: code;
  1712. OP: count;
  1713. OP: offset;
  1714. array[ndata] of type[code>>4]: data;
  1715. };
  1716. .P2
  1717. A
  1718. .CW Short_item
  1719. is generated for 15 or fewer items, otherwise a
  1720. .CW "Long_item"
  1721. is generated. In a
  1722. .CW "Long_item"
  1723. the count field (bottom 4 bits of code) is set to zero and the count follows as an
  1724. .CW "OP" .
  1725. The top 4 bits of code determine the type of the datum.
  1726. The defined values are:
  1727. .IP
  1728. .TS
  1729. lf(CW) lw(3i)f(R) .
  1730. 0001 8 bit bytes
  1731. 0010 32 bit words
  1732. 0011 utf encoded string
  1733. 0100 real value IEEE754 canonical representation
  1734. 0101 Array
  1735. 0110 Set array address
  1736. 0111 Restore load address
  1737. 1000 64 bit big
  1738. .TE
  1739. .LP
  1740. The byte, word, real and big operands are encoded as sequences
  1741. of bytes (of appropriate length) in big-endian form, converted to native
  1742. format before being stored in the data space.
  1743. The `string' code takes a UTF-encoded sequence of
  1744. .CW count
  1745. bytes, which is converted to an array of 21-bit Unicode values stored in an
  1746. implementation-dependent structure on
  1747. the heap; a 4-byte pointer to the string descriptor is stored in the data space.
  1748. The `array' code takes two 4-byte operands: the first is the index of the array's type
  1749. descriptor in the type section; the second is the length of the array to be created.
  1750. The result in memory is a 4-byte pointer to an implementation-dependent
  1751. array descriptor in the heap.
  1752. .LP
  1753. Each item's data is stored at the address formed by adding the
  1754. .CW offset
  1755. in that item to a base address maintained by the loader.
  1756. Initially that address is the base of the data space of the module instance.
  1757. A new base for loading subsequent items can be set or restored by
  1758. the following operations, used to initialize arrays.
  1759. The `set array index' item must appear immediately following an `array'
  1760. item.
  1761. Its operand is a 4-byte big-endian integer that gives an index into that
  1762. array, at which address subsequent data should be loaded; the
  1763. previous load address is stacked internally.
  1764. Subsequent data will be loaded at offsets from the new base address.
  1765. The `restore load address' item has no operands; it pops a load address
  1766. from the internal address stack and makes that the new
  1767. base address.
  1768. .SH
  1769. The Module Name
  1770. .LP
  1771. The module name immediately follows the data section.
  1772. It contains the name of the implementation module, in UTF encoding,
  1773. terminated by a zero byte.
  1774. .SH
  1775. The Link Section
  1776. .LP
  1777. The link section contains an array of external linkage items:
  1778. the list of functions exported by this module.
  1779. Each item describes one exported function in the following form:
  1780. .P1
  1781. Linkage_item
  1782. {
  1783. OP: pc;
  1784. OP: desc_number;
  1785. W: sig;
  1786. array[] of byte: name;
  1787. };
  1788. .P2
  1789. The
  1790. .CW pc
  1791. is the instruction number of the function's entry point.
  1792. The
  1793. .CW desc_number
  1794. is the index, in the type section, of the type descriptor for the function's stack frame.
  1795. The
  1796. .CW sig
  1797. word is a 32-bit hash of the function's type signature.
  1798. Finally,
  1799. the name of the function is stored as a variable length array of bytes
  1800. in UTF-8 encoding,
  1801. with the end of the array marked by a zero byte.
  1802. The names of member functions of an exported adt are qualified
  1803. by the name of the adt.
  1804. The next linkage item, if any, follows immediately.
  1805. .NH 1
  1806. Symbol Table File Format
  1807. .LP
  1808. The object file format does not include type information for debuggers.
  1809. The Limbo compiler can optionally produce a separate symbol table file.
  1810. Its format is defined in the entry
  1811. .I sbl (6)
  1812. of [1].
  1813. .NH 1
  1814. References
  1815. .IP 1.
  1816. .I "Inferno Programmer's Manual"
  1817. (Third Edition),
  1818. Volume 1 (`the manual'),
  1819. Vita Nuova Holdings Limited, June 2000.
  1820. .IP 2.
  1821. P Winterbottom and R Pike,
  1822. ``The Design of the Inferno Virtual Machine'',
  1823. reprinted in this volume.