em_int.s 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784
  1. /
  2. / (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. / See the copyright notice in the ACK home directory, in the file "Copyright".
  4. /------------------------------------------------------------------------------
  5. /
  6. / This is an interpreter for EM programs with no virtual memory
  7. / which is adapted from an EM1 interpreter by Hans van Staveren
  8. / by Evert Wattel
  9. / Vrije Universiteit
  10. / Amsterdam
  11. /
  12. / Memory layout:
  13. /
  14. / interpreter em-text pd global tables heap unused stack
  15. / __________________________________________________________________
  16. / | | | | | | | | | |
  17. / | | | | | | | | | |
  18. / | 1 | 2 | 3 | 4 | 5 | 6 | | 7 | 8|
  19. / | | | | | | | | | |
  20. / |____________|_______|____|_______|_______|_____|______|______|__|
  21. /
  22. / 1: Interpreter text+data+bss
  23. / 2: EM text
  24. / 3: EM procedure descriptors
  25. / 4: EM global data area
  26. / 5: flow, count and profile tables
  27. / 6: EM heap area
  28. / 7: EM local data and stack
  29. / 8: Arguments to interpreter
  30. /
  31. / Assembly time flags:
  32. / .test : controls checking for undefined variables,nil pointers,
  33. / array indices, etc....
  34. / .prof : controls generation of a runtime profile
  35. / .opfreq: controls runtime frequency count per opcode
  36. / .flow : controls generation of a flow bitmap
  37. / .count : controls generation of a flow count
  38. / .last : controls generation of file with last 16
  39. / consecutive blocks of lines executed
  40. /
  41. / Register layout:
  42. / pcx = EM programcounter
  43. / lb = EM base-address
  44. / nxt = address of start of interpreter loop
  45. /
  46. / The general structure of this interpreter is as follows:
  47. / The opcode byte of the instruction is placed in r0
  48. / with sign-extension and multiplied by 2.
  49. / If .opfreq is nonzero each occurence of each opcode is counted.
  50. / Then, if .prof is nonzero an estimation of the time required
  51. / to execute the instruction is added to a counter associated
  52. / with the source-line number. This estimation is roughly the
  53. / number of memory-cycles needed. At the end of this accounting
  54. / loprof points to the loword of the double precision counter.
  55. / This can be used by individual execution routines to add some
  56. / more to the counter depending on their operand.
  57. /
  58. / NOTE: This interpreter can be loaded in separate I and D space
  59. /
  60. /
  61. /------------------------------------------------------------------------------
  62. / Declaring of some constants
  63. /------------------------------------------------------------------------------
  64. nxt = r4
  65. pcx = r3
  66. lb = r2
  67. statd = -8.
  68. unixextra= 1280. / extra memory asked by heap overflow
  69. und = 100000 / undefined memory pattern
  70. signext = 177400 / high bits for signextension
  71. EINVAL = 22. / UNIX error code for bad signal
  72. / Interpreter options
  73. .float = 1
  74. .opfreq = 0
  75. .last = 1
  76. V7 = 1
  77. V6 = 0
  78. VPLUS = 0
  79. HARDWARE_FP = 1
  80. /------------------------------------------------------------------------------
  81. / EM1 machine errors (in the range 0-63)
  82. /------------------------------------------------------------------------------
  83. EARRAY = 0.
  84. ERANGE = 1.
  85. ESET = 2.
  86. EIOVFL = 3.
  87. EFOVFL = 4.
  88. EFUNFL = 5.
  89. EIDIVZ = 6.
  90. EFDIVZ = 7.
  91. EIUND = 8.
  92. EFUND = 9.
  93. ECONV = 10.
  94. ESTACK = 16.
  95. EHEAP = 17.
  96. EILLINS = 18.
  97. EODDZ = 19.
  98. ECASE = 20.
  99. EMEMFLT = 21.
  100. EBADPTR = 22.
  101. EBADPC = 23.
  102. EBADLAE = 24.
  103. EBADMON = 25.
  104. EBADLIN = 26.
  105. EBADGTO = 27.
  106. /------------------------------------------------------------------------------
  107. / Declaring of some instructions unknown to the assembler
  108. /------------------------------------------------------------------------------
  109. next = 10407 / = mov nxt,pc; jump to decode loop
  110. rti = 2 / return from interrupt
  111. iot = 4 / force core dump
  112. stst = 170300^tst / store floating point status
  113. indir = 0 / for sys indir
  114. exit = 1
  115. fork = 2
  116. read = 3
  117. write = 4
  118. open = 5
  119. close = 6
  120. creat = 8.
  121. break = 17.
  122. alarm = 27.
  123. pause = 29.
  124. sleep = 35.
  125. signal = 48.
  126. /------------------------------------------------------------------------------
  127. / External references
  128. /------------------------------------------------------------------------------
  129. .globl _end
  130. /
  131. /------------------------------------------------------------------------------
  132. / Now the real program starts
  133. /------------------------------------------------------------------------------
  134. startoff:
  135. mov sp,r0
  136. mov sp,ml
  137. mov sp,filb
  138. add $2,filb / pointer to argv in filb for error message
  139. dec (r0)
  140. mov (r0)+,argc / pass to userprogram later
  141. bgt 0f / go for argument
  142. mov $emfile,forward+2 / e.out is load file default
  143. mov $forward+2,argv
  144. br 1f
  145. 0:
  146. tst (r0)+ / skip interpreter name
  147. mov r0,argv / pass to userprogram later
  148. mov (r0),forward+2 / argv filename to open call
  149. 1:
  150. .if V7
  151. tst (r0)+ / increment r0 look for last arg
  152. bne 1b
  153. mov r0,environ
  154. .endif
  155. sys indir;forward
  156. .data
  157. forward: sys open;0;0
  158. emfile: <e.out\0>
  159. .even
  160. .text
  161. jes badarg
  162. mov r0,saver0 / save filedescriptor
  163. mov r0,r5 / duplicate filedescriptor
  164. sys read;header;16. / skip first header
  165. jes badarg / failed
  166. mov r5,r0 / recall fildes
  167. sys read;header;16. / read second header
  168. jes badarg / failed
  169. cmp r0,$16. / long enough ?
  170. jne badarg / no.
  171. mov $_end,r0 / Bottom em-text
  172. mov r0,pb / program base
  173. add txtsiz,r0 / reserve space for text
  174. mov r0,pd / set up proc.descr base
  175. mov nprocs, r3 / number of procs
  176. ash $2,r3 / proc. descr is 4 bytes
  177. .if .count +.prof + .flow
  178. mul $3,r3 / or 12 bytes
  179. .endif
  180. add r3,r0 / reserve space
  181. mov r0,hp / top of pd space, temporarily in hp
  182. mov r0,r3 / base for data fill
  183. mov $retsize,eb / address of value containing 0, temporarily
  184. add szdata,r0 / size of external data
  185. jcs toolarge / too much text and data
  186. mov r0,globmax / maximum global
  187. add $1280.,r0 / bit extra core for setup
  188. mov r0,sybreak+2 / set up for core claim
  189. sys indir;sybreak / ask for the core
  190. jes toolarge / too much, sorry
  191. mov hp,eb / top of pd space
  192. mov txtsiz,leescal+4 / set up for text read
  193. mov pb,leescal+2 / start address text read
  194. mov r5,r0 / file descriptor input
  195. sys indir;leescal / read!!
  196. .data
  197. leescal:
  198. 1: sys read;0;0 / read call
  199. .text
  200. lblread:
  201. / hier is nu dus de tekst ingelezen. De sybreak voor de
  202. / tabellen en de data moet opnieuw gebeuren.
  203. .if .last
  204. mov $47.,r0
  205. mov $lasttab,r5
  206. 3: clr (r5)+
  207. sob r0,3b
  208. mov $-1,(r5)
  209. sub $96.,r5
  210. mov r5,linused
  211. .endif
  212. lblfloat:
  213. .if .float
  214. sys signal;8.;sig8 / catch floating exception
  215. ldfps $7600
  216. movf $50200,fr3 / load 2^32 in fr3 for conversion
  217. / unsigned to float
  218. .endif
  219. sys signal;11.;sig11 / catch segmentation violation
  220. sys signal;12.;sig12 / catch bad system calls
  221. / We make a 1024 buffer for reading in
  222. / data descriptors. When the number of
  223. / bytes in the buffer is less than 512
  224. / we read another block. Descriptors of
  225. / more than 512 bytes are not allowed.
  226. / This is no restriction since they do
  227. / not fit in the descriptor format.
  228. lblbuf:
  229. sub $02000,sp / new buffer bottom
  230. tst (sp) / ask for core
  231. mov sp,r4 / pointer in descriptor
  232. mov saver0,r0 / recall fildes
  233. clr r1 / clear registers for byte
  234. clr r2 / format instruction and data
  235. mov sp,r5 / copy
  236. mov r5,leescal+2 / set up for read
  237. mov $02000,leescal+4 / idem
  238. sys indir;leescal / read
  239. jes badarg / read failed
  240. cmp $02000,r0 / not yet eof?
  241. bgt 0f / eof encountered
  242. add $01000,r5 / buffer middle
  243. mov r5,saver1 / save buffermiddle to compare
  244. br datloop / start data initialization
  245. 0: add r0,r5 / now pointer at top of file
  246. mov r5,saver1 / still set up for compare
  247. datloop:
  248. cmp r4,saver1 / descriptor over middle?
  249. blt 9f / no? go ahead
  250. jsr pc,blshift / yes? shift block down, read next
  251. 9: dec ndatad / still data to initialize?
  252. blt finito / no? go on
  253. movb (r4)+,r1 / opcode descriptor
  254. beq 0f / if 0 then go there
  255. mov r3,r5 / copy data pointer
  256. clr r2 / unsigned integer byte
  257. bisb (r4)+,r2 / "ored" in for data size
  258. asl r1 / make opcode even
  259. mov datswi(r1),pc / main data swich
  260. .data
  261. datswi: 0; dat1; dat2; dat3; dat4; dat5; dat6; dat6; dofloat
  262. .text
  263. dat3: asl r2 / multiply with 2
  264. dat2: 2: movb (r4)+,(r3)+ / copy byte from buffer to data
  265. sob r2,2b / until r2 is 0
  266. br datloop / next datadescriptor
  267. dat4: mov eb,r0 / external base should be added
  268. br 2f / for data pointers
  269. dat5: mov pb,r0 / and program base for procedures
  270. 2: movb (r4)+,(r3) / move in first byte of pointer
  271. movb (r4)+,1(r3) / move in second byte of pointer
  272. add r0,(r3)+ / add pointer base
  273. sob r2,2b / jump back if there is more
  274. br datloop / next data descriptor
  275. dat1: mov $und,(r3)+ / reserve words with undefineds
  276. sob r2,dat1 / jump back if more
  277. br datloop / next data descriptor
  278. 0: mov r3,r1 / copy data pointer (odd register)
  279. sub r5,r1 / subtract previous pointer
  280. movb (r4)+,(r3) / copy first byte of operand
  281. movb (r4)+,1(r3) / copy second byte
  282. mul (r3),r1 / the number of bytes to copy
  283. 1: movb (r5)+,(r3)+ / is the product of the operand
  284. sob r1,1b / and the number of bytes in the
  285. br datloop / previous operation
  286. dat6: add r2,r3 / new data pointer, the old is
  287. mov r3,r0 / still in r5
  288. asr r2 / divide by 2
  289. beq 6f / case 1 byte is special
  290. sub $2,r0 / this is the least significant
  291. / byte in PDP11-standard
  292. 2: movb (r4)+,(r0)+ / copy low byte
  293. movb (r4)+,(r0) / copy high byte
  294. sub $3,r0 / next lowest byte
  295. sob r2,2b / jump if not ready
  296. br datloop / next descriptor
  297. 6: movb (r4)+,(r5) / copy one byte
  298. br datloop / next descriptor
  299. blshift:
  300. mov saver1,r1 / bottom of top half
  301. mov r1,r2 / set up bottom
  302. sub $01000,r2
  303. mov $1000,r0 / number to copy
  304. mov r0,leescal+4 / amount to read
  305. sub r0,r4 / decrease pointer
  306. asr r0 / 512 bytes is 256 words
  307. 3: mov (r1)+,(r2)+ / copy top half in bottom half
  308. sob r0,3b
  309. mov saver1,leescal+2 / set up for read
  310. blockr:
  311. mov saver0,r0 / filedescriptor
  312. sys indir;leescal
  313. jes badarg
  314. clr r1 / clear registers which contain
  315. clr r2 / descriptor bytes later
  316. cmp $01000,r0 / look if eof is encountered
  317. beq 3f / yes? go on
  318. add r0,saver1 / no extra read necessary
  319. 3: rts pc
  320. finito:
  321. cmp globmax,r3 / test if data size ok
  322. jne badarg / load file error
  323. mov eb,filb
  324. add $4,filb
  325. mov nprocs,r5 / set up for procdesc read
  326. mov pd,r3 / proc descriptor base
  327. asl r5 / multiply with 4 because
  328. asl r5 / procdes is 4 bytes
  329. 1: mov saver1,r1 / look what is available
  330. sub r4,r1 / in buffer to be read
  331. add $3,r1 / let it be a multiple
  332. bic $3,r1 / of four
  333. sub r1,r5 / subtract what can be read
  334. asr r1; asr r1; / divide by four
  335. 0:
  336. movb (r4)+,(r3)+ / copy byte
  337. movb (r4)+,(r3)+ / copy byte
  338. movb (r4)+,(r3)+ / copy byte
  339. movb (r4)+,(r3)+ / copy byte
  340. add pb,-2(r3) / change em-address in pdp-address
  341. .if .count + .prof + .flow
  342. clr (r3)+
  343. clr (r3)+
  344. clr (r3)+
  345. clr (r3)+
  346. .endif
  347. sob r1,0b / look if there is more
  348. tst r5 / is there still a descriptor
  349. ble 2f; / no? go on
  350. jsr pc,blshift / yes? read again
  351. br 1b
  352. 2:
  353. cmp eb,r3 / test if procdes is ok
  354. jne badarg / load file error
  355. mov saver0,r0 / fildes in r0
  356. sys close / close input load file
  357. mov ml,sp / fresh stack
  358. mov 2(sp),*filb
  359. .if .flow + .count + .prof
  360. / |==================|
  361. / Here we fill the fields in the procedure | bytes for locals |
  362. / descriptor with table information. The |------------------|
  363. / procedure descriptor has six fields, | start address |
  364. / like described in this picture. We |------------------|
  365. / construct a linked list of the proc. | count pointer |
  366. / descriptors, such that the defined |------------------|
  367. / order of procedures is compatible | first line nr |
  368. / with the text order. Thereafter we |------------------|
  369. / scan the text for line information to | link next proc |
  370. / fill the countpointer and startline |------------------|
  371. / field. The link to the first proc. | current file name|
  372. / is in firstp, links are descriptor |==================|
  373. / start addresses. The last procedure
  374. / links to the external base. All lines in the text get a count
  375. / number, lines of a procedure get consecutive count numbers,
  376. / the procedure count pointer gives the number of the first line.
  377. / Count pointer zero is reserved for the case that no line number
  378. / is yet defined.
  379. makelink:
  380. mov pd,r0 / first descriptor
  381. mov r0,r3 / points to first proc
  382. mov r0,r4 / pd in register
  383. mov eb,r5 / eb in register
  384. 0: mov r0,r1 / copy old descriptor bottom
  385. add $12.,r0 / next descriptor
  386. cmp r0,r5 / top of descriptor space
  387. bhis 4f / ready? continue
  388. 1: cmp 2(r0),2(r1) / compare start addresses
  389. bhis 2f / 2(r0) large? follow link
  390. sub $12.,r1 / 2(r0) small? previous descriptor
  391. cmp r1,r4 / is r1 smaller than pd?
  392. bhis 1b / no? try again
  393. mov r3,8.(r0) / yes? then r0 has small text address
  394. mov r0,r3 / now r3 again points to first proc
  395. br 0b / next descriptor
  396. 2: mov 8.(r1),r2 / follow link to compare with 2(r0)
  397. beq 3f / if 0 then no link defined
  398. cmp 2(r0),2(r2) / compare start addresses
  399. blo 3f / r0 between r1 and r2
  400. mov r2,r1 / r0 above r2,
  401. br 2b / look again.
  402. 3: mov r0,8.(r1) / link of r1 points to r0
  403. mov r2,8.(r0) / link of r0 points to r2
  404. br 0b / next descriptor
  405. 4: mov r3,firstp / firstp links to first procedure
  406. procinf:
  407. mov $1,maxcount / countptr for first proc
  408. mov r3,r4 / points to first proc
  409. 0: mov r3,-(sp) / stack current procedure
  410. mov $-1,r1 / minimal line number 0177777
  411. clr r5 / maximum line number on 0
  412. mov 8.(r3),r4 / bottom address next descriptor
  413. beq 6f / if 0 last procedure
  414. mov 2(r4),r4 / top of current procedure
  415. br 2f / start looking for lines
  416. 6: mov pd,r4 / top of last procedure
  417. 2:
  418. mov 2(r3),r3 / start text address procedure
  419. 8: movb (r3)+,r2 / first opcode for scanning
  420. cmp $-2,r2 / case escape
  421. beq 1f / escape treated at label 1
  422. cmp $-106.,r2 / case lni
  423. blt 7f / ordinary skip at label 7
  424. beq 2f / lni treated at label 2
  425. cmp $-108.,r2 / case lin.l
  426. bgt 7f / ordinary skip at label 7
  427. beq 3f / lin.l at label 3
  428. clr r0 / lin.s0 treated here
  429. bisb (r3)+,r0 / line number in r0
  430. br 4f / compares at label 4
  431. 2: inc r0 / lni increases line number
  432. br 4f / compares at label 4
  433. 3: jsr pc,wrdoff / get 2 byte number
  434. 4:
  435. cmp r1,r0 / look if r0 less than minimum
  436. blo 5f / nothing to declare
  437. mov r0,r1 / r0 new minimum
  438. 5: cmp r0,r5 / look if r0 more than maximum
  439. blo 9f / nothing spectacular
  440. mov r0,r5 / r0 new maximum
  441. br 9f / line processed
  442. 1: clr r2
  443. bisb (r3)+,r2 / escaped instruction opcode
  444. add $128.,r2 / ready for table entry
  445. 7: movb skipdisp(r2),r2 / skip the required number of bytes
  446. add r2,r3
  447. 9: cmp r3,r4 / still more text in this proc?
  448. blt 8b / yes? again
  449. filpd:
  450. mov (sp)+,r3 / get bottom descriptor back
  451. sub r1,r5 / number of lines encountered
  452. bcs 9f / no lines then no file information
  453. mov maxcount,4(r3) / this is the count pointer
  454. mov r1,6(r3) / minimum line in descriptor
  455. inc r5
  456. add r5,maxcount / this is the new maximum
  457. 9: mov 8.(r3),r3 / follow link to next procedure
  458. bne 0b / restart
  459. .data
  460. .byte 2; .byte 2; .byte 0; .byte 0; .byte 1; .byte 1; .byte 1; .byte 0;
  461. .byte 0; .byte 2; .byte 1; .byte 0; .byte 1; .byte 0; .byte 0; .byte 1;
  462. .byte 1; .byte 1; .byte 0; .byte 0; .byte 2; .byte 1; .byte 0; .byte 2;
  463. .byte 0; .byte 1; .byte 1; .byte 2; .byte 1; .byte 1; .byte 1; .byte 1;
  464. .byte 1; .byte 2; .byte 0; .byte 0; .byte 0; .byte 0; .byte 1; .byte 2;
  465. .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 1; .byte 2; .byte 2;
  466. .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
  467. .byte 0; .byte 0; .byte 0; .byte 0; .byte 1; .byte 1; .byte 0; .byte 0;
  468. .byte 0; .byte 1; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 1;
  469. .byte 0; .byte 0; .byte 1; .byte 0; .byte 0; .byte 1; .byte 1; .byte 1;
  470. .byte 1; .byte 0; .byte 2; .byte 1; .byte 1; .byte 1; .byte 2; .byte 0;
  471. .byte 0; .byte 1; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 1;
  472. .byte 2; .byte 2; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
  473. .byte 0; .byte 1; .byte 0; .byte 0; .byte 0; .byte 0; .byte 2; .byte 1;
  474. .byte 1; .byte 1; .byte 1; .byte 1; .byte 1; .byte 1; .byte 1; .byte 1;
  475. .byte 2; .byte 1; .byte 0; .byte 0; .byte 1; .byte 2; .byte 7; .byte 5;
  476. skipdisp:
  477. .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
  478. .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
  479. .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
  480. .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
  481. .byte 0; .byte 0; .byte 0; .byte 1; .byte 0; .byte 0; .byte 2; .byte 0;
  482. .byte 0; .byte 1; .byte 1; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
  483. .byte 0; .byte 0; .byte 1; .byte 2; .byte 1; .byte 1; .byte 1; .byte 1;
  484. .byte 1; .byte 1; .byte 1; .byte 2; .byte 1; .byte 1; .byte 1; .byte 1;
  485. .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
  486. .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
  487. .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0;
  488. .byte 0; .byte 0; .byte 0; .byte 0; .byte 1; .byte 0; .byte 0; .byte 0;
  489. .byte 1; .byte 0; .byte 0; .byte 0; .byte 1; .byte 0; .byte 0; .byte 0;
  490. .byte 1; .byte 1; .byte 0; .byte 1; .byte 0; .byte 2; .byte 0; .byte 2;
  491. .byte 1; .byte 0; .byte 0; .byte 0; .byte 1; .byte 1; .byte 0; .byte 1;
  492. .byte 2; .byte 1; .byte 1; .byte 1; .byte 1; .byte 1; .byte 1; .byte 1;
  493. /escaped opcodes
  494. .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0;
  495. .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 2; .byte 0; .byte 2;
  496. .byte 2; .byte 2; .byte 2; .byte 2; .byte 0; .byte 2; .byte 2; .byte 0;
  497. .byte 2; .byte 0; .byte 0; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0;
  498. .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0;
  499. .byte 2; .byte 0; .byte 0; .byte 0; .byte 0; .byte 2; .byte 2; .byte 2;
  500. .byte 2; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2;
  501. .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 2; .byte 2;
  502. .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 2; .byte 2;
  503. .byte 2; .byte 2; .byte 2; .byte 2; .byte 0; .byte 2; .byte 0; .byte 1;
  504. .byte 2; .byte 2; .byte 2; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2;
  505. .byte 0; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 0; .byte 2;
  506. .byte 0; .byte 2; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0;
  507. .byte 2; .byte 0; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2;
  508. .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 2; .byte 2;
  509. .byte 2; .byte 2; .byte 0; .byte 0; .byte 2; .byte 2; .byte 0; .byte 2;
  510. .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2; .byte 0; .byte 2;
  511. .byte 2; .byte 0; .byte 1; .byte 0; .byte 0; .byte 0; .byte 2; .byte 0;
  512. .byte 2; .byte 0; .byte 2; .byte 2; .byte 2; .byte 2; .byte 2; .byte 2;
  513. .byte 0; .byte 2; .byte 0; .byte 1; .byte 2; .byte 0; .byte 0; .byte 2;
  514. .text
  515. mov globmax,r3 / bottom of table space
  516. mov r3,r5 / copy
  517. .if .prof
  518. mov r3,ltime / set up pointer to base
  519. mov r3,hiprof
  520. mov r3,loprof
  521. add $2,loprof
  522. mov maxcount,r0 / number of lines
  523. inc r0
  524. asl r0 / four byter per prof count
  525. asl r0
  526. add r0,r3
  527. mov r0,profsiz
  528. .endif
  529. .if .flow
  530. mov r3,lflow / set up pointer to base
  531. mov maxcount,r0
  532. ash $-3,r0 / divide by 8
  533. add $2,r0
  534. bic $1,r0 / Rounded up to an integral number of words
  535. add r0,r3
  536. mov r0,flowsiz
  537. .endif
  538. .if .count
  539. mov r3,lcount / set up pointer
  540. mov maxcount,r0
  541. inc r0
  542. ash $2,r0 / multiply by 4
  543. add r0,r3
  544. mov r0,countsiz
  545. .endif
  546. mov r3,tblmax
  547. cmp r3,sybreak+2 / core available for tables?
  548. blos 2f
  549. mov r3,sybreak+2
  550. sys indir;sybreak / ask for core
  551. 2: sub r5,r3 / this amount of space required
  552. asr r3
  553. 2: clr (r5)+ / clear table space
  554. sob r3,2b
  555. .endif
  556. .if [1 - .count] * [1 - .flow] * [1 - .prof]
  557. mov globmax,tblmax
  558. .endif
  559. / start calling sequence here
  560. calseq:
  561. mov tblmax,hp
  562. mov pd,r3 / top of em-text and top of stack
  563. clr r2 / are dummy return values
  564. mov environ,-(sp) / setup environment pointer
  565. mov argv,-(sp) / setup argument pointer
  566. mov *argv,*filb / setup first file message
  567. mov argc,-(sp) / setup argument count
  568. mov entry.,-(sp) / start procedure to call
  569. precal:
  570. mov $loop,r4 / main loop address in r4
  571. jbr cai.z / according to the cai
  572. noarg: mov r0,argv
  573. mov $0f,r0; jbr rude_error
  574. badarg: mov $1f,r0; jbr rude_error
  575. toolarge:mov $2f,r0; jbr rude_error
  576. .data
  577. 0: <no load file\0>
  578. 1: <load file error\0>
  579. 2: <program too large\0>
  580. .even
  581. .text
  582. dofloat:
  583. jsr pc,atof
  584. mov r5,r3 / restore r3
  585. / Assumed that the result is 8
  586. / bytes Recall r2 and move the
  587. / amount of bytes asked for
  588. clr r1 / restore for opcode
  589. sub $8.,r2 / 8 bytes?
  590. beq 1f / yes! later, 4 bytes next
  591. movfo fr0,-(sp) / push result
  592. mov (sp)+,(r3)+ / write result in data
  593. mov (sp)+,(r3)+ / idem
  594. jbr datloop / next loop
  595. 1: movf fr0,-(sp) / push result
  596. mov (sp)+,(r3)+ / write result in data
  597. mov (sp)+,(r3)+ / write result in data
  598. mov (sp)+,(r3)+ / write result in data
  599. mov (sp)+,(r3)+ / write result in data
  600. jbr datloop
  601. atof:
  602. mov r2,-(sp) / save byte count
  603. clr -(sp)
  604. clrf fr0
  605. clr r2
  606. 1:
  607. movb (r4)+,r0 / get byte
  608. cmp $' ,r0
  609. bge 1b
  610. cmpb r0,$'+
  611. beq 1f
  612. cmpb r0,$'-
  613. bne 2f
  614. inc (sp)
  615. 1:
  616. movb (r4)+,r0 / get next byte
  617. 2:
  618. sub $'0,r0
  619. cmp r0,$9.
  620. bhi 2f
  621. jsr pc,digit
  622. br 1b
  623. inc r2
  624. br 1b
  625. 2:
  626. cmpb r0,$'.-'0
  627. bne 2f
  628. 1:
  629. movb (r4)+,r0 / get next byte
  630. sub $'0,r0
  631. cmp r0,$9.
  632. bhi 2f
  633. jsr pc,digit
  634. dec r2
  635. br 1b
  636. 2:
  637. cmpb r0,$'E-'0
  638. beq 3f
  639. cmpb r0,$'e-'0
  640. bne 1f
  641. 3:
  642. clr r3
  643. clr r1
  644. movb (r4)+,r0 / get next byte
  645. cmpb r0,$'+
  646. beq 3f
  647. cmpb r0,$'-
  648. bne 5f
  649. inc r3
  650. 3:
  651. movb (r4)+,r0 / get next byte
  652. 5:
  653. sub $'0,r0
  654. cmp r0,$9.
  655. bhi 3f
  656. mul $10.,r1
  657. add r0,r1
  658. br 3b
  659. 3:
  660. tst r3
  661. bne 3f
  662. neg r1
  663. 3:
  664. sub r1,r2
  665. 1:
  666. movf $one,fr1
  667. movf $one,fr2
  668. mov r2,-(sp)
  669. beq 2f
  670. bgt 1f
  671. neg r2
  672. 1:
  673. mulf $twohalf,fr1
  674. mulf $four,fr2
  675. sob r2,1b
  676. 2:
  677. tst (sp)+
  678. bge 1f
  679. divf fr1,fr0
  680. divf fr2,fr0
  681. br 2f
  682. 1:
  683. mulf fr1,fr0
  684. mulf fr2,fr0
  685. 2:
  686. tst (sp)+
  687. beq 1f
  688. negf fr0
  689. 1: mov (sp)+,r2
  690. rts pc
  691. digit:
  692. cmpf $big,fr0
  693. cfcc
  694. blt 1f
  695. mulf $ten,fr0
  696. movif r0,fr1
  697. addf fr1,fr0
  698. rts pc
  699. 1:
  700. add $2,(sp)
  701. rts pc
  702. /
  703. /
  704. one = 40200
  705. twohalf = 40440
  706. four = 40600
  707. ten = 41040
  708. big = 56200
  709. huge = 77777
  710. /------------------------------------------------------------------------------
  711. /------------------------------------------------------------------------------
  712. / Main loop of interpreter starts here
  713. /------------------------------------------------------------------------------
  714. loop:
  715. movb (pcx)+,r0 / pickup opcode + sign extend
  716. 9: asl r0 / opcode now -256 .. 254 & even
  717. .if .opfreq
  718. mov r0,r1
  719. asl r1 / multiply by two again
  720. add $1,counttab+514.(r1) / cannot be inc
  721. adc counttab+512.(r1) / double precision counters
  722. .endif
  723. .if .prof
  724. add timeinf(r0),*loprof
  725. adc *hiprof / double precision
  726. .endif
  727. mov dispat(r0),pc / fast dispatch
  728. /------------------------------------------------------------------------------
  729. / Two byte opcodes come here for decoding of second byte
  730. /------------------------------------------------------------------------------
  731. escape1:
  732. clr r0
  733. bisb (pcx)+,r0 / fetch second byte no sign extend
  734. asl r0 / 0 to 512 & even
  735. cmp $0500,r0 / look for righ range
  736. jlt e.illins
  737. .if .opfreq
  738. mov r0,r1
  739. asl r1 / multiply by two again
  740. add $1,counttab+1026.(r1) / cannot be inc
  741. adc counttab+1024.(r1) / double precision counters
  742. .endif
  743. .if .prof
  744. add time2inf(r0),*loprof
  745. adc *hiprof / double precision
  746. .endif
  747. mov dispae1(r0),pc / fast dispatch
  748. /----------------------------------------------------------------------------
  749. escape2:
  750. movb (pcx)+,r0 / fetch second byte and sign extend
  751. jne e.illins
  752. .if .opfreq
  753. add $1,counttab+1666. / cannot be inc
  754. adc counttab+1664. / double precision counters
  755. .endif
  756. jbr loc.f / fast dispatch
  757. /------------------------------------------------------------------------------
  758. / dispatch tables, first the unescaped opcodes
  759. /
  760. / name convention is as follows:
  761. / each execution routine has as a name the name of the instruction
  762. / followed by a dot and a suffix.
  763. / suffix can be an integer (sometimes followed by a W),
  764. / an 's'or a 'w', followed by an integer, an 'l' ,a 'p' ,
  765. / a 'n', sometimes followed by a 'w', or a 'z'.
  766. / loc.1 routine to execute loc 1
  767. / zge.s0 routine to execute zge 0 thru 255
  768. / lae.w1 routine to execute lae 1024 thru lae 2046
  769. / lof.2W routine to execute lof 2*the word size
  770. / lol.pw routine to execute positive lol instructions
  771. / loe.l routine to execute all loe instructions
  772. / add.z routine to execute instruction without operand
  773. / or with operand on the stack.
  774. /------------------------------------------------------------------------------
  775. .data
  776. lal.p; lal.n; lal.0; lal._1; lal.w0; lal.w_1; lal.w_2; lar.1W
  777. ldc.0; lde.lw; lde.w0; ldl.0; ldl.w_1; lfr.1W; lfr.2W; lfr.s0
  778. lil.w_1; lil.w0; lil.0; lil.1W; lin.l; lin.s0; lni.z; loc.l
  779. loc._1; loc.s0; loc.s_1; loe.lw; loe.w0; loe.w1; loe.w2; loe.w3
  780. loe.w4; lof.l; lof.1W; lof.2W; lof.3W; lof.4W; lof.s0; loi.l
  781. loi.1; loi.1W; loi.2W; loi.3W; loi.4W; loi.s0; lol.pw; lol.nw
  782. lol.0; lol.1W; lol.2W; lol.3W; lol._1W; lol._2W; lol._3W; lol._4W
  783. lol._5W; lol._6W; lol._7W; lol._8W; lol.w0; lol.w_1; lxa.1; lxl.1
  784. lxl.2; mlf.s0; mli.1W; mli.2W; rck.1W; ret.0; ret.1W; ret.s0
  785. rmi.1W; sar.1W; sbf.s0; sbi.1W; sbi.2W; sdl.w_1; set.s0; sil.w_1
  786. sil.w0; sli.1W; ste.lw; ste.w0; ste.w1; ste.w2; stf.l; stf.1W
  787. stf.2W; stf.s0; sti.1; sti.1W; sti.2W; sti.3W; sti.4W; sti.s0
  788. stl.pw; stl.nw; stl.0; stl.1W; stl._1W; stl._2W; stl._3W; stl._4W
  789. stl._5W; stl.w_1; teq.z; tgt.z; tlt.z; tne.z; zeq.l; zeq.s0
  790. zeq.s1; zer.s0; zge.s0; zgt.s0; zle.s0; zlt.s0; zne.s0; zne.s_1
  791. zre.lw; zre.w0; zrl._1W; zrl._2W; zrl.w_1; zrl.nw; escape1; escape2
  792. dispat: / dispatch table for unescaped opcodes
  793. loc.0; loc.1; loc.2; loc.3; loc.4; loc.5; loc.6; loc.7
  794. loc.8; loc.9; loc.10; loc.11; loc.12; loc.13; loc.14; loc.15
  795. loc.16; loc.17; loc.18; loc.19; loc.20; loc.21; loc.22; loc.23
  796. loc.24; loc.25; loc.26; loc.27; loc.28; loc.29; loc.30; loc.31
  797. loc.32; loc.33; aar.1W; adf.s0; adi.1W; adi.2W; adp.l ; adp.1
  798. adp.2; adp.s0; adp.s_1; ads.1W; and.1W; asp.1W; asp.2W; asp.3W
  799. asp.4W; asp.5W; asp.w0; beq.l; beq.s0; bge.s0; bgt.s0; ble.s0
  800. blm.s0; blt.s0; bne.s0; bra.l; bra.s_1; bra.s_2; bra.s0; bra.s1
  801. cal.1; cal.2; cal.3; cal.4; cal.5; cal.6; cal.7; cal.8
  802. cal.9; cal.10; cal.11; cal.12; cal.13; cal.14; cal.15; cal.16
  803. cal.17; cal.18; cal.19; cal.20; cal.21; cal.22; cal.23; cal.24
  804. cal.25; cal.26; cal.27; cal.28; cal.s0; cff.z; cif.z; cii.z
  805. cmf.s0; cmi.1W; cmi.2W; cmp.z; cms.s0; csa.1W; csb.1W; dec.z
  806. dee.w0; del.w_1; dup.1W; dvf.s0; dvi.1W; fil.l; inc.z; ine.lw
  807. ine.w0; inl._1W; inl._2W; inl._3W; inl.w_1; inn.s0; ior.1W; ior.s0
  808. lae.l; lae.w0; lae.w1; lae.w2; lae.w3; lae.w4; lae.w5; lae.w6
  809. /------------------------------------------------------------------------------
  810. / now dispatch table for escaped opcodes
  811. /------------------------------------------------------------------------------
  812. dispae1: /dispatch escaped opcodes 1
  813. aar.l; aar.z; adf.l; adf.z; adi.l; adi.z; ads.l; ads.z
  814. adu.l; adu.z; and.l; and.z; asp.lw; ass.l; ass.z; bge.l
  815. bgt.l; ble.l; blm.l; bls.l; bls.z; blt.l; bne.l; cai.z
  816. cal.l; cfi.z; cfu.z; ciu.z; cmf.l; cmf.z; cmi.l; cmi.z
  817. cms.l; cms.z; cmu.l; cmu.z; com.l; com.z; csa.l; csa.z
  818. csb.l; csb.z; cuf.z; cui.z; cuu.z; dee.lw; del.pw; del.nw
  819. dup.l; dus.l; dus.z; dvf.l; dvf.z; dvi.l; dvi.z; dvu.l
  820. dvu.z; fef.l; fef.z; fif.l; fif.z; inl.pw; inl.nw; inn.l
  821. inn.z; ior.l; ior.z; lar.l; lar.z; ldc.l; ldf.l; ldl.pw
  822. ldl.nw; lfr.l; lil.pw; lil.nw; lim.z; los.l; los.z; lor.s0
  823. lpi.l; lxa.l; lxl.l; mlf.l; mlf.z; mli.l; mli.z; mlu.l
  824. mlu.z; mon.z; ngf.l; ngf.z; ngi.l; ngi.z; nop.z; rck.l
  825. rck.z; ret.l; rmi.l; rmi.z; rmu.l; rmu.z; rol.l; rol.z
  826. ror.l; ror.z; rtt.z; sar.l; sar.z; sbf.l; sbf.z; sbi.l
  827. sbi.z; sbs.l; sbs.z; sbu.l; sbu.z; sde.l; sdf.l; sdl.pw
  828. sdl.nw; set.l; set.z; sig.z; sil.pw; sil.nw; sim.z; sli.l
  829. sli.z; slu.l; slu.z; sri.l; sri.z; sru.l; sru.z; sti.l
  830. sts.l; sts.z; str.s0; tge.z; tle.z; trp.z; xor.l; xor.z
  831. zer.l; zer.z; zge.l; zgt.l; zle.l; zlt.l; zne.l; zrf.l
  832. zrf.z; zrl.pw; dch.z; exg.s0; exg.l; exg.z; lpb.z; gto.l
  833. /------------------------------------------------------------------------------
  834. / timeinf tables, first the unescaped opcodes
  835. / these tables are parallel to the tables dispat and dispae1
  836. / Each entry contains a reasonable estimate of
  837. / the number of memory-cycles needed to
  838. / execute that instruction. The exact amount cannot be
  839. / supplied, since this can depend rather heavily on the
  840. / size of the object in set, array case instructions etc.
  841. / The table timeinf also contains, added to each entry,
  842. / the number of memory-cycles needed to decode the instruction.
  843. / This number is currently 6. The number is computed for
  844. / the case that all check and runinf options are off.
  845. /------------------------------------------------------------------------------
  846. .if .prof
  847. 23.; 23.; 12.; 12.; 18.; 17.; 19.; 61.
  848. 11.; 31.; 21.; 15.; 20.; 30.; 30.; 31.
  849. 20.; 18.; 18.; 19.; 29.; 18.; 13.; 20.
  850. 10.; 14.; 13.; 27.; 20.; 20.; 20.; 20.
  851. 20.; 23.; 16.; 16.; 16.; 16.; 17.; 38.
  852. 14.; 26.; 26.; 26.; 26.; 28.; 26.; 25.
  853. 11.; 11.; 11.; 11.; 11.; 11.; 11.; 11.
  854. 11.; 11.; 11.; 11.; 16.; 16.; 26.; 24.
  855. 24.; 53.; 25.; 25.; 18.; 27.; 44.; 54.
  856. 30.; 59.; 53.; 21.; 28.; 19.; 51.; 18.
  857. 18.; 21.; 27.; 19.; 20.; 18.; 25.; 16.
  858. 16.; 15.; 12.; 24.; 24.; 24.; 24.; 25.
  859. 26.; 25.; 15.; 13.; 11.; 11.; 11.; 11.
  860. 11.; 16.; 14.; 14.; 14.; 14.; 20.; 16.
  861. 16.; 21.; 16.; 16.; 16.; 16.; 16.; 16.
  862. 26.; 16.; 10.; 10.; 15.; 24.; 10.; 40.
  863. timeinf:
  864. 9.; 10.; 10.; 10.; 10.; 10.; 10.; 10.
  865. 10.; 10.; 10.; 10.; 10.; 10.; 10.; 10.
  866. 10.; 10.; 10.; 10.; 10.; 10.; 10.; 10.
  867. 10.; 10.; 10.; 10.; 10.; 10.; 10.; 10.
  868. 10.; 10.; 48.; 53.; 21.; 28.; 20.; 10.
  869. 10.; 12.; 13.; 11.; 44.; 11.; 11.; 11.
  870. 11.; 11.; 27.; 21.; 17.; 17.; 17.; 17.
  871. 81.; 17.; 17.; 21.; 12.; 12.; 11.; 12.
  872. 54.; 54.; 54.; 54.; 54.; 54.; 54.; 54.
  873. 54.; 54.; 54.; 54.; 54.; 54.; 54.; 54.
  874. 54.; 54.; 54.; 54.; 54.; 54.; 54.; 54.
  875. 54.; 54.; 54.; 54.; 54.; 41.; 49.; 37.
  876. 40.; 53.; 53.; 51.; 60.; 24.; 41.; 11.
  877. 20.; 19.; 10.; 53.; 30.; 29.; 11.; 30.
  878. 20.; 15.; 15.; 15.; 19.; 44.; 37.; 36.
  879. 25.; 19.; 19.; 19.; 19.; 19.; 19.; 19.
  880. /------------------------------------------------------------------------------
  881. / time2inf table for escaped opcodes
  882. / cycles necessary for decoding is already accounted for in timeinf
  883. /------------------------------------------------------------------------------
  884. time2inf:
  885. 57.; 46.; 61.; 50.; 37.; 26.; 30.; 19.
  886. 45.; 34.; 52.; 41.; 37.; 42.; 31.; 21.
  887. 21.; 21.; 91.; 108.; 97.; 21.; 21.; 53.
  888. 60.; 56.; 55.; 26.; 53.; 42.; 62.; 51.
  889. 72.; 61.; 72.; 61.; 38.; 27.; 40.; 29.
  890. 53.; 46.; 54.; 38.; 23.; 30.; 30.; 28.
  891. 36.; 45.; 34.; 61.; 50.; 39.; 28.; 44.
  892. 33.; 68.; 57.; 68.; 57.; 30.; 28.; 54.
  893. 45.; 44.; 33.; 70.; 59.; 22.; 27.; 28.
  894. 29.; 37.; 28.; 27.; 11.; 47.; 40.; 21.
  895. 20.; 35.; 33.; 61.; 50.; 34.; 23.; 39.
  896. 28.; 500.; 47.; 36.; 41.; 30.; 100.; 38.
  897. 27.; 62.; 39.; 28.; 44.; 33.; 88.; 77.
  898. 92.; 81.; 32.; 68.; 57.; 61.; 50.; 37.
  899. 26.; 33.; 22.; 45.; 34.; 29.; 28.; 30.
  900. 28.; 61.; 52.; 16.; 28.; 27.; 11.; 30.
  901. 19.; 36.; 25.; 32.; 21.; 36.; 25.; 31.
  902. 39.; 32.; 32.; 14.; 14.; 117.; 45.; 34.
  903. 31.; 22.; 20.; 20.; 20.; 20.; 20.; 27.
  904. 16.; 26.; 17.; 39.; 47.; 36.; 10.; 29.
  905. .endif
  906. .text
  907. /------------------------------------------------------------------------------
  908. / LOAD CONSTANT, LOAD LOCAL, STORE LOCAL
  909. /------------------------------------------------------------------------------
  910. loc.0: clr -(sp)
  911. next
  912. loc.1: loc.2: loc.3: loc.4: loc.5: loc.6: loc.7: loc.8:
  913. loc.9: loc.10: loc.11: loc.12: loc.13: loc.14: loc.15: loc.16:
  914. loc.17: loc.18: loc.19: loc.20: loc.21: loc.22: loc.23: loc.24:
  915. loc.25: loc.26: loc.27: loc.28: loc.29: loc.30: loc.31: loc.32:
  916. loc.33:
  917. asr r0 / make multiplication undone
  918. mov r0,-(sp)
  919. next
  920. loc._1:
  921. mov $-1,-(sp)
  922. next
  923. loc.s0:
  924. clr r0
  925. br 2f
  926. loc.s_1:
  927. mov $-400,r0
  928. 2: bisb (pcx)+,r0
  929. mov r0,-(sp)
  930. next
  931. lpi.l: / let op, dit is een pointer
  932. / zonder offset op het moment!
  933. loc.l:
  934. jsr pc,wrdoff
  935. mov r0,-(sp)
  936. next
  937. ldc.0:
  938. clr -(sp)
  939. clr -(sp)
  940. next
  941. ldc.l:
  942. jsr pc,wrdoff
  943. mov r0,-(sp)
  944. sxt -(sp)
  945. next
  946. loc.f: jsr pc,wrdoff; mov r0,r1
  947. jsr pc,wrdoff; mov r0,-(sp)
  948. mov r1,-(sp); next
  949. /__________________________________________________________________________
  950. lol.0: mov 010(r2),-(sp); next
  951. lol.1W: mov 012(r2),-(sp); next
  952. lol.2W: mov 014(r2),-(sp); next
  953. lol.3W: mov 016(r2),-(sp); next
  954. lol._1W: mov -02(r2),-(sp); next
  955. lol._2W: mov -04(r2),-(sp); next
  956. lol._3W: mov -06(r2),-(sp); next
  957. lol._4W: mov -010(r2),-(sp); next
  958. lol._5W: mov -012(r2),-(sp); next
  959. lol._6W: mov -014(r2),-(sp); next
  960. lol._7W: mov -016(r2),-(sp); next
  961. lol._8W: mov -020(r2),-(sp); next
  962. lol.w0: clr r0; bisb (pcx)+,r0
  963. 5: asl r0; add r2,r0
  964. mov 010(r0),-(sp); next
  965. lol.w_1: mov $-400,r0; bisb (pcx)+,r0
  966. 2: asl r0; add r2,r0
  967. mov (r0),-(sp); next
  968. lol.pw: jsr pc,wrdoff; br 5b
  969. lol.nw: jsr pc,wrdoff; br 2b
  970. /------------------------------------------------------------------------------
  971. ldl.0: mov 10.(r2),-(sp); mov 8.(r2),-(sp); next
  972. ldl.w_1: mov $-400,r0; bisb (pcx)+,r0
  973. 2: asl r0; add r2,r0
  974. mov 2(r0),-(sp); mov (r0),-(sp); next
  975. ldl.pw: jsr pc,wrdoff; asl r0
  976. add r2,r0; mov 10.(r0),-(sp)
  977. mov 8.(r0),-(sp); next
  978. ldl.nw: jsr pc,wrdoff; br 2b
  979. /------------------------------------------------------------------------------
  980. loe.lw: jsr pc,wrdoff; br 2f
  981. loe.w0: loe.w1: loe.w2: loe.w3: loe.w4:
  982. asr r0; add $0144,r0
  983. swab r0; bisb (pcx)+,r0
  984. 2: asl r0; add eb,r0
  985. mov (r0),-(sp); next
  986. lde.lw: jsr pc,wrdoff; br 2f
  987. lde.w0: clr r0; bisb (pcx)+,r0
  988. 2: asl r0; add eb,r0
  989. mov 2(r0),-(sp); mov (r0),-(sp); next
  990. /------------------------------------------------------------------------------
  991. lil.0: clr r0; br 1f
  992. lil.1W: mov $1,r0; br 1f
  993. lil.pw: jsr pc,wrdoff; br 1f
  994. lil.w0: clr r0; bisb (pcx)+,r0
  995. 1: add $04,r0
  996. 2: asl r0; add r2,r0
  997. mov (r0),-(sp); jsr pc,chckptr
  998. mov *(sp),(sp); next
  999. lil.w_1: mov $-400,r0; bisb (pcx)+,r0; br 2b
  1000. lil.nw: jsr pc,wrdoff; br 2b
  1001. /------------------------------------------------------------------------------
  1002. lof.l: jsr pc,wrdoff
  1003. 1: jsr pc,chckptr; add (sp)+,r0;
  1004. mov (r0),-(sp); next
  1005. lof.1W: lof.2W: lof.3W: lof.4W:
  1006. add $0276,r0;
  1007. br 1b
  1008. lof.s0: clr r0; bisb (pcx)+,r0; br 1b
  1009. ldf.l: jsr pc,wrdoff; add (sp)+,r0
  1010. mov 2(r0),-(sp); mov (r0),-(sp); next
  1011. /------------------------------------------------------------------------------
  1012. lal.p: jsr pc,wrdoff
  1013. 5: add r2,r0; add $8.,r0
  1014. mov r0,-(sp); next
  1015. lal.0: mov r2,-(sp); add $8.,(sp); next
  1016. lal.w0: clr r0; bisb (pcx)+,r0
  1017. asl r0; br 5b
  1018. lal.n: jsr pc,wrdoff; br 2f
  1019. lal._1: mov $-1,r0
  1020. 2: add r2,r0; mov r0,-(sp); next
  1021. lal.w_1: mov $-400,r0
  1022. 3: bisb (pcx)+,r0; asl r0; br 2b
  1023. lal.w_2: mov $-1000,r0; br 3b
  1024. lae.l: jsr pc,wrdoff; br 1f
  1025. lae.w0: lae.w1: lae.w2: lae.w3: lae.w4: lae.w5: lae.w6:
  1026. asr r0
  1027. sub $0171,r0; swab r0
  1028. bisb (pcx)+,r0; asl r0
  1029. 1: add eb,r0;
  1030. .if .test
  1031. cmp globmax,r0;
  1032. bhi 1f; jsr pc,e.badlae;
  1033. .endif
  1034. 1: mov r0,-(sp); next
  1035. /------------------------------------------------------------------------------
  1036. lxl.1: mov $1,r0; br 1f
  1037. lxl.2: mov $2,r0; br 1f
  1038. lxl.l: jsr pc,wrdoff
  1039. bgt 1f; jlt e.oddz
  1040. mov r2,-(sp); next
  1041. 1: mov r2,r1
  1042. 2: mov 8(r1),r1; sob r0,2b
  1043. mov r1,-(sp); next
  1044. lxa.1: mov $1,r0; br 1f
  1045. lxa.l: jsr pc,wrdoff; bgt 1f
  1046. jlt e.oddz; mov r2,-(sp)
  1047. add $10,(sp); next
  1048. 1: mov r2,r1
  1049. 2: mov 8(r1),r1; sob r0,2b
  1050. add $10,r1; mov r1,-(sp); next
  1051. /------------------------------------------------------------------------------
  1052. loi.l: jsr pc,wrdoff; br 2f
  1053. loi.1W: loi.2W: loi.3W: loi.4W:
  1054. add $260,r0; br 1f
  1055. loi.s0: clr r0; bisb (pcx)+,r0
  1056. 2: cmp $1,r0; beq loi.1
  1057. 1: jsr pc,chckptr; mov (sp)+,r1; add r0,r1
  1058. asr r0; jcs e.oddz
  1059. 1: mov -(r1),-(sp); sob r0,1b; next
  1060. loi.1: jsr pc,chckptb; mov (sp),r1; clr r0
  1061. bisb (r1),r0; mov r0,(sp); next
  1062. los.z:
  1063. mov (sp)+,r0
  1064. br 0f
  1065. los.l:
  1066. jsr pc,wrdoff
  1067. 0:
  1068. cmp $04,r0
  1069. beq 4f
  1070. cmp $02,r0; beq 3f
  1071. jbr e.oddz
  1072. 4: mov (sp)+,r0
  1073. 3: mov (sp)+,r0; br 2b
  1074. /------------------------------------------------------------------------------
  1075. /Store group
  1076. /------------------------------------------------------------------------------
  1077. stl.pw: jsr pc,wrdoff; asl r0; br 0f
  1078. stl.0: clr r0; br 0f
  1079. stl.1W: mov $2,r0
  1080. 0: add r2,r0; mov(sp)+,8.(r0); next
  1081. stl.nw: jsr pc,wrdoff; br 0f
  1082. stl.w_1: mov $-400,r0; bisb (pcx)+,r0
  1083. 0: asl r0; add r2,r0
  1084. mov (sp)+,(r0); next
  1085. stl._1W: mov (sp)+,-2(r2); next
  1086. stl._2W: mov (sp)+,-4(r2); next
  1087. stl._3W: mov (sp)+,-6(r2); next
  1088. stl._4W: mov (sp)+,-10(r2); next
  1089. stl._5W: mov (sp)+,-12(r2); next
  1090. sdl.w_1: mov $-400,r0; bisb (pcx)+,r0
  1091. 0: asl r0; add r2,r0
  1092. 2: mov (sp)+,(r0)+; mov (sp)+,(r0); next
  1093. sdl.nw: jsr pc,wrdoff; br 0b
  1094. sdl.pw: jsr pc,wrdoff; asl r0
  1095. add r2,r0; add $8.,r0; br 2b
  1096. /------------------------------------------------------------------------------
  1097. sde.l: jsr pc,wrdoff; add eb,r0
  1098. br 2b
  1099. ste.lw: jsr pc,wrdoff; br 1f
  1100. ste.w0: clr r0; br 0f
  1101. ste.w1: mov $400,r0; br 0f
  1102. ste.w2: mov $1000,r0
  1103. 0: bisb (pcx)+,r0
  1104. 1: asl r0; add eb,r0
  1105. mov (sp)+,(r0); next
  1106. /------------------------------------------------------------------------------
  1107. stf.l: jsr pc,wrdoff; br 6f
  1108. stf.1W: mov $2,r0; br 6f
  1109. stf.2W: mov $4,r0; br 6f
  1110. stf.s0: clr r0; bisb (pcx)+,r0
  1111. 6: add (sp)+,r0; br 7f
  1112. sdf.l: jsr pc,wrdoff; add (sp)+,r0
  1113. jbr 2b
  1114. /------------------------------------------------------------------------------
  1115. sil.w0: clr r0; bisb (pcx)+,r0
  1116. 5: asl r0; add r2,r0
  1117. mov 8.(r0),r0; br 7f
  1118. sil.w_1: mov $-400,r0; bisb (pcx)+,r0
  1119. 2: asl r0; add r2,r0
  1120. mov (r0),r0;
  1121. 7: mov (sp),r1; mov r0,(sp);
  1122. jsr pc,chckptr; mov r1,*(sp)+; next
  1123. sil.pw: jsr pc,wrdoff; br 5b
  1124. sil.nw: jsr pc,wrdoff; br 2b
  1125. /------------------------------------------------------------------------------
  1126. sti.1: jsr pc,chckptb; mov (sp)+,r1;
  1127. movb (sp)+,(r1); next
  1128. sti.1W: sti.2W: sti.3W: sti.4W:
  1129. add $114,r0; br 1f
  1130. sti.s0: clr r0; bisb (pcx)+,r0; br 1f
  1131. sti.l: jsr pc,wrdoff
  1132. 1: asr r0; beq 3f
  1133. jcs e.oddz; jsr pc,chckptr;
  1134. mov (sp)+,r1
  1135. 2: mov (sp)+,(r1)+; sob r0,2b; next
  1136. 3: jcs sti.1; jbr e.oddz
  1137. sts.l: jsr pc,wrdoff
  1138. 0: cmp $2,r0; beq 2f
  1139. cmp $4,r0; beq 4f; jbr e.oddz
  1140. 4: mov (sp)+,r0
  1141. 2: mov (sp)+,r0; br 1b
  1142. sts.z: mov (sp)+,r0; br 0b
  1143. /------------------------------------------------------------------------------
  1144. / POINTER ARITHMETIC
  1145. /------------------------------------------------------------------------------
  1146. adp.l: jsr pc,wrdoff; add r0,(sp); next
  1147. adp.1: add $1,(sp); next
  1148. adp.2: add $2,(sp); next
  1149. adp.s0: clr r0; bisb (pcx)+,r0
  1150. add r0,(sp); next
  1151. adp.s_1: mov $-400,r0; bisb (pcx)+,r0
  1152. add r0,(sp); next
  1153. ads.l: jsr pc,wrdoff; br 0f
  1154. ads.z: mov (sp)+,r0
  1155. 0: cmp $1,r0; beq 1f
  1156. asr r0; jcs e.oddz
  1157. 2: mov (sp)+,r1; sob r0,2b
  1158. add r1,(sp); next
  1159. ads.1W: mov (sp)+,r1; add r1,(sp); next
  1160. 1: movb (sp)+,r1
  1161. add r1,(sp); next
  1162. sbs.l: jsr pc,wrdoff; br 0f
  1163. sbs.z: mov (sp)+,r0
  1164. 0: mov (sp)+,r1; sub r1,(sp)
  1165. beq 0f; mov $-1,r1
  1166. br 1f
  1167. 0: clr r1
  1168. 1: dec r0; beq 3f
  1169. dec r0; beq 2f
  1170. asr r0
  1171. 4: mov r1,-(sp); sob r0,4b
  1172. 2: next
  1173. 3: clrb 1(sp); next
  1174. /------------------------------------------------------------------------------
  1175. /------------------------------------------------------------------------------
  1176. / Clears, increments and decrements
  1177. /------------------------------------------------------------------------------
  1178. inc.z: mov sp,r1;
  1179. 4:
  1180. .if .test
  1181. cmp (r1),$und; jne 3f;
  1182. jsr pc,e.iund; 3:
  1183. .endif
  1184. inc (r1); bvs 9f; next
  1185. inl._1W: mov r2,r1; sub $2,r1; br 4b
  1186. inl._2W: mov r2,r1; sub $4,r1; br 4b
  1187. inl._3W: mov r2,r1; sub $6,r1; br 4b
  1188. inl.w_1: mov $-400,r0; bisb (pcx)+,r0;
  1189. 1: asl r0; mov r2,r1;
  1190. add r0,r1; br 4b
  1191. inl.pw: jsr pc,wrdoff; add $4,r0;
  1192. br 1b; / !! proc frame 4 words
  1193. inl.nw: jsr pc,wrdoff; br 1b
  1194. ine.lw: jsr pc,wrdoff; br 1f
  1195. ine.w0: clr r0; bisb (pcx)+,r0;
  1196. 1: asl r0; add eb,r0;
  1197. mov r0,r1; br 4b
  1198. dec.z: mov sp,r1;
  1199. 4:
  1200. .if .test
  1201. cmp (r1),$und; jne 3f;
  1202. jsr pc,e.iund; 3:
  1203. .endif
  1204. dec (r1); bvs 9f; next
  1205. del.w_1: mov $-400,r0; bisb (pcx)+,r0;
  1206. 1: asl r0; mov r0,r1;
  1207. add r2,r1; br 4b
  1208. del.pw: jsr pc,wrdoff; add $4,r0;
  1209. br 1b; / !proc frame 4 words
  1210. del.nw: jsr pc,wrdoff; br 1b
  1211. dee.w0: clr r0; bisb (pcx)+,r0;
  1212. 1: asl r0; add eb,r0;
  1213. mov r0,r1; br 4b
  1214. dee.lw: jsr pc,wrdoff; br 1b;
  1215. 9: jsr pc,e.iovfl; next
  1216. / jump to an error routine for integer overflow
  1217. zrl._1W: clr -2(r2); next
  1218. zrl._2W: clr -4(r2); next
  1219. zrl.w_1: mov $-400,r0; bisb (pcx)+,r0;
  1220. 1: asl r0; add r2,r0;
  1221. clr (r0); next
  1222. zrl.nw: jsr pc,wrdoff; br 1b
  1223. zrl.pw: jsr pc,wrdoff; add $4,r0;
  1224. br 1b
  1225. zre.lw: jsr pc,wrdoff; br 1f
  1226. zre.w0: clr r0; bisb (pcx)+,r0;
  1227. 1: asl r0; add eb,r0;
  1228. clr (r0); next
  1229. zrf.l: jsr pc,wrdoff; br 1f
  1230. zrf.z: mov (sp)+,r0;
  1231. 1: asr r0;
  1232. 2: clr -(sp); sob r0,2b; next
  1233. zer.s0: clr r0; bisb (pcx)+,r0;
  1234. 3: bit $1,r0; jne e.illins
  1235. / test if number of bytes is even
  1236. br 1b
  1237. zer.l: jsr pc,wrdoff; br 3b
  1238. zer.z: mov (sp)+,r0; br 3b
  1239. /------------------------------------------------------------------------------
  1240. / LOGICAL GROUP
  1241. /------------------------------------------------------------------------------
  1242. and.1W: mov $1,r1; mov $2,r0;
  1243. br lbland;
  1244. and.l: jsr pc,wrdoff; br 0f
  1245. and.z: mov (sp)+,r0;
  1246. 0: ble 9f; mov r0,r1;
  1247. asr r1; bcs 9f;
  1248. lbland: add sp,r0;
  1249. 1: mov (sp)+,r5; com r5;
  1250. bic r5,(r0)+; sob r1,1b;
  1251. next
  1252. ior.1W: mov $1,r1; mov $2,r0;
  1253. br 0f
  1254. ior.s0: clr r0; bisb (pcx)+,r0;
  1255. br 0f
  1256. ior.l: jsr pc,wrdoff; br 0f
  1257. ior.z: mov (sp)+,r0;
  1258. lblior:
  1259. 0: ble 9f; bit $1,r0;
  1260. bne 9f; mov r0,r1;
  1261. mov sp,r5; add r0,r5; asr r1;
  1262. 1: bis (sp)+,(r5)+; sob r1,1b; next
  1263. xor.l: jsr pc,wrdoff; br 0f;
  1264. xor.z: mov (sp)+,r0;
  1265. 0: ble 9f; bit $1,r0;
  1266. bne 9f; mov r0,r1;
  1267. mov sp,r5; add r0,r5; asr r1
  1268. 1: mov (sp)+,r0;
  1269. xor r0,(r5)+; sob r1,1b; next
  1270. com.l: jsr pc,wrdoff; br 1f
  1271. com.z: mov (sp)+,r0;
  1272. 1: bit $1,r0; bne 9f
  1273. mov r0,r1; asr r1
  1274. add sp,r0;
  1275. 2: com -(r0); sob r1,2b
  1276. next
  1277. rol.l: jsr pc,wrdoff; br 3f
  1278. rol.z: mov (sp)+,r0;
  1279. 3: clr r4;
  1280. mov (sp)+,r5; ash $3,r0;
  1281. div r0,r4; mov r5,r4;
  1282. bge 1f; add r0,r4;
  1283. 1: ash $-3,r0; mov sp,r1;
  1284. cmp r0,$1; beq 1f;
  1285. add r0,r1; mov r1,r5;
  1286. asr r0; jcs 9f
  1287. mov r3,saver0; mov r0,r3;
  1288. 4: mov r3,r0; mov r5,r1;
  1289. 2: rol -(r1); sob r0,2b;
  1290. adc -2(r5); sob r4,4b;
  1291. mov saver0,r3; mov $loop,r4; next
  1292. 1: rolb (r1)+; adc (r1);
  1293. sob r4,1b; mov saver1,r4; next
  1294. ror.l: jsr pc,wrdoff; neg (sp); br 3b
  1295. ror.z: mov (sp)+,r0; neg (sp); br 3b
  1296. 9: jsr pc,e.oddz /error codes for odd or
  1297. /negative number of bytes
  1298. /------------------------------------------------------------------------------
  1299. / SET GROUP
  1300. /------------------------------------------------------------------------------
  1301. set.s0: clr r0; bisb (pcx)+,r0
  1302. 1:
  1303. .if .test
  1304. bgt 9f; jsr pc,e.set
  1305. 9:
  1306. .endif
  1307. mov (sp)+,r1
  1308. jsr pc,settest; inc r0
  1309. asr r0; / if r0 odd choose next even
  1310. 2: clr -(sp); sob r0,2b; / empty set
  1311. mov r1,r0; ash $-3,r0;
  1312. add sp,r0; bic $177770,r1;
  1313. bisb bits(r1),(r0); next
  1314. set.l: jsr pc,wrdoff; br 1b
  1315. set.z: mov (sp)+,r0; br 1b
  1316. inn.s0: clr r0; bisb (pcx)+,r0
  1317. 1:
  1318. .if .test
  1319. bgt 9f; jsr pc,e.set
  1320. 9:
  1321. .endif
  1322. mov sp,r5;
  1323. add r0,r5; mov (sp)+,r1;
  1324. jsr pc,settest; mov r1,r0
  1325. ash $-3,r0; add sp,r0;
  1326. clr -(sp);
  1327. bic $177770,r1; bitb bits(r1),(r0)
  1328. beq 2f; mov r5,sp;
  1329. mov $1,(sp); next
  1330. 2: mov r5,sp; clr (sp); next
  1331. inn.l: jsr pc,wrdoff; br 1b
  1332. inn.z: mov (sp)+,r0; br 1b
  1333. .data
  1334. bits: .byte 1
  1335. .byte 2
  1336. .byte 4
  1337. .byte 10
  1338. .byte 20
  1339. .byte 40
  1340. .byte 100
  1341. .byte 200
  1342. .even
  1343. .text
  1344. settest: mov r0,-(sp); clc
  1345. ash $3,r0; sub r1,r0;
  1346. .if .test
  1347. bgt 3f; jsr pc,e.set
  1348. .endif
  1349. 3: mov (sp)+,r0; rts pc
  1350. /------------------------------------------------------------------------------
  1351. / ARRAY GROUP
  1352. /------------------------------------------------------------------------------
  1353. lar.1W: mov $2,r0; br 1f
  1354. lar.l: jsr pc,wrdoff; br 1f
  1355. lar.z: mov (sp)+,r0;
  1356. 1: jsr pc,calcarr; clr -2(sp);
  1357. sub r5,sp; bic $1,sp;
  1358. mov sp,r0;
  1359. 2: movb (r1)+,(r0)+; sob r5,2b; next
  1360. sar.1W: mov $2,r0; br 1f
  1361. sar.l: jsr pc,wrdoff; br 1f
  1362. sar.z: mov (sp)+,r0;
  1363. 1: jsr pc,calcarr; mov sp,r0;
  1364. add r5,sp; inc sp;
  1365. bic $1,sp;
  1366. 2: movb (r0)+,(r1)+; sob r5,2b; next
  1367. aar.1W: mov $2,r0; br 1f
  1368. aar.l: jsr pc,wrdoff; br 1f
  1369. aar.z: mov (sp)+,r0;
  1370. 1: jsr pc,calcarr; mov r1,-(sp); next
  1371. calcarr: sub $02,r0; beq 0f;
  1372. jsr pc,e.oddz;
  1373. 0: tst (sp)+;
  1374. mov (sp)+,r0; mov (sp)+,r1;
  1375. sub (r0)+,r1; bge 9f
  1376. jsr pc,e.array
  1377. 9:
  1378. cmp (r0)+,r1; bge 9f
  1379. jsr pc,e.array
  1380. 9:
  1381. mov (r0),r5;
  1382. mul r5,r1; add (sp)+,r1;
  1383. mov -010(sp),-(sp); rts pc;
  1384. /------------------------------------------------------------------------------
  1385. /--------------------------------------------------------------
  1386. / CONVERT GROUP
  1387. /--------------------------------------------------------------
  1388. cii.z:
  1389. / convert int to int
  1390. / 1 byte -> ? : sign extension
  1391. mov (sp)+,r0
  1392. inc r0 / dest 1 byte = dest 1 word
  1393. bic $1,r0
  1394. .if .test
  1395. cmp (sp),$2 / if size 2 then trap for undefined
  1396. bne 7f
  1397. cmp 2(sp),$und
  1398. bne 7f
  1399. jsr pc,e.iund / this is the trap
  1400. 7:
  1401. .endif
  1402. sub (sp)+,r0
  1403. 0: blt 1f
  1404. asr r0
  1405. bcc 2f
  1406. movb (sp),r1
  1407. mov r1,(sp)
  1408. 2: tst r0
  1409. beq 3f
  1410. tst (sp)
  1411. 4: sxt -(sp)
  1412. sob r0,4b
  1413. 3: next
  1414. 1: sub r0,sp
  1415. .if .test
  1416. mov sp,r1
  1417. neg r0
  1418. asr r0
  1419. tst (sp)
  1420. blt 3f
  1421. 5: tst -(r1)
  1422. bne 9f
  1423. sob r0,5b
  1424. next
  1425. 3: cmp -(r1),$-1
  1426. bne 9f
  1427. sob r0,3b
  1428. .endif
  1429. next
  1430. /-------
  1431. cui.z: mov (sp)+,r0
  1432. sub (sp)+,r0
  1433. clr -(sp)
  1434. add $-2,r0
  1435. br 0b
  1436. cif.z:
  1437. mov (sp)+,r0
  1438. jsr pc,setfloat
  1439. mov (sp)+,r0
  1440. .if .test
  1441. cmp r0,$2 / trap if size 2 undefined integer
  1442. bne 7f
  1443. cmp (sp),$und
  1444. bne 7f
  1445. jsr pc,e.iund / trap for undefined integer
  1446. 7:
  1447. .endif
  1448. jsr pc,setint
  1449. movif (sp)+,fr0
  1450. movf fr0,-(sp)
  1451. next
  1452. cuf.z:
  1453. mov (sp)+,r0
  1454. jsr pc,setfloat
  1455. mov (sp)+,r0
  1456. cmp r0,$02
  1457. bne 1b
  1458. clr -(sp)
  1459. mov $04,r0
  1460. jsr pc,setint
  1461. movif (sp)+,fr0
  1462. cfcc
  1463. bge 1f
  1464. addf fr3,fr0
  1465. 1: movf fr0,-(sp)
  1466. next
  1467. /-------
  1468. cff.z:
  1469. mov (sp)+,r0
  1470. cmp (sp)+,r0
  1471. beq 1f
  1472. jsr pc,setfloat
  1473. movof (sp)+,fr0
  1474. movf fr0,-(sp)
  1475. 1: next
  1476. /-------
  1477. ciu.z: mov (sp)+,r0
  1478. .if .test
  1479. cmp (sp),$2 / trap undefined of size 2
  1480. bne 7f
  1481. cmp 2(sp),$und
  1482. bne 7f
  1483. jsr pc,e.iund / this is the trap
  1484. 7:
  1485. .endif
  1486. sub (sp)+,r0
  1487. asr r0
  1488. bcc 2f
  1489. clrb 1(sp)
  1490. 2:
  1491. 6: tst r0
  1492. beq 3f
  1493. blt 5f
  1494. 4: clr -(sp)
  1495. sob r0,4b
  1496. 3: next
  1497. 9: jsr pc,e.conv; next
  1498. 5: neg r0
  1499. 4: tst (sp)+
  1500. sob r0,4b
  1501. next
  1502. cuu.z:
  1503. mov (sp)+,r0
  1504. sub (sp)+,r0
  1505. asr r0
  1506. jbr 6b
  1507. /-------
  1508. cfu.z:
  1509. mov (sp)+,r1
  1510. mov $4,r0
  1511. jsr pc,setint
  1512. mov (sp)+,r0
  1513. jsr pc,setfloat
  1514. movf (sp)+,fr0
  1515. movfi fr0,-(sp)
  1516. / unfortunately, this does not work for numbers >= 2^31
  1517. .if .test
  1518. jcs 9b
  1519. jlt 9b
  1520. .endif
  1521. mov $4,-(sp)
  1522. mov r1,-(sp)
  1523. jbr cuu.z
  1524. /-------
  1525. cfi.z:
  1526. mov (sp)+,r0
  1527. jsr pc,setint
  1528. mov (sp)+,r0
  1529. jsr pc,setfloat
  1530. movf (sp)+,fr0
  1531. movfi fr0,-(sp)
  1532. jcs e.conv
  1533. next
  1534. /--------------------------------------------------------------
  1535. / INTEGER ARITHMETIC
  1536. /--------------------------------------------------------------
  1537. adi.l: jsr pc,wrdoff; br 0f
  1538. adi.z: mov (sp)+,r0
  1539. 0: cmp r0,$04
  1540. bgt 1f
  1541. cmp r0,$02
  1542. bgt 2f
  1543. bne 1f
  1544. adi.1W:
  1545. .if .test
  1546. cmp (sp),$und / trap undefineds of size 2
  1547. beq 6f
  1548. cmp 2(sp),$und
  1549. bne 7f
  1550. 6: jsr pc,e.iund / this is the trap
  1551. 7:
  1552. .endif
  1553. add (sp)+,(sp)
  1554. .if .test
  1555. bvs 9f
  1556. .endif
  1557. next
  1558. adi.2W: 2: add (sp)+,02(sp)
  1559. .if .test
  1560. bvc 2f
  1561. jsr pc,e.iovfl
  1562. 2:
  1563. .endif
  1564. add (sp)+,02(sp)
  1565. adc (sp)
  1566. .if .test
  1567. bvs 9f
  1568. .endif
  1569. next
  1570. 1:
  1571. jsr pc,e.oddz ; next
  1572. /-------
  1573. sbi.l: jsr pc,wrdoff; br 0f
  1574. sbi.z: mov (sp)+,r0
  1575. 0: cmp r0,$04
  1576. bgt 1b
  1577. cmp r0,$02
  1578. bgt 2f
  1579. bne 1b
  1580. sbi.1W:
  1581. .if .test
  1582. cmp (sp),$und / trap for size 2 undefineds
  1583. beq 6f
  1584. cmp 2(sp),$und
  1585. bne 7f
  1586. 6: jsr pc,e.iund / this is the trap
  1587. 7:
  1588. .endif
  1589. sub (sp)+,(sp)
  1590. .if .test
  1591. bvs 9f
  1592. .endif
  1593. next
  1594. sbi.2W: 2: sub (sp)+,02(sp)
  1595. .if .test
  1596. bvc 2f
  1597. jsr pc,e.iovfl
  1598. 2:
  1599. .endif
  1600. sub (sp)+,02(sp)
  1601. sbc (sp)
  1602. .if .test
  1603. bvs 9f
  1604. next
  1605. 9: jsr pc,e.iovfl
  1606. .endif
  1607. next
  1608. /------
  1609. mli.l: jsr pc,wrdoff; br 0f
  1610. mli.z: mov (sp)+,r0
  1611. 0:
  1612. cmp r0,$04
  1613. bgt 1f
  1614. beq mli4
  1615. cmp r0,$02
  1616. bne 1f
  1617. mli.1W: mov (sp)+,r1
  1618. .if .test
  1619. cmp r1,$und / trap for undefineds of size 2
  1620. beq 6f
  1621. cmp (sp),$und
  1622. bne 7f
  1623. 6: jsr pc,e.iund / this is the trap
  1624. 7:
  1625. .endif
  1626. mul (sp)+,r1
  1627. .if .test
  1628. bcc 9f / overflow
  1629. jsr pc,e.iovfl
  1630. 9:
  1631. .endif
  1632. mov r1,-(sp)
  1633. next
  1634. 1: jmp e.oddz
  1635. /------
  1636. mli.2W: mli4:
  1637. .if .prof
  1638. add $91.,*loprof
  1639. adc *hiprof
  1640. .endif
  1641. jsr pc,regsave
  1642. tst 02(sp)
  1643. sxt r0
  1644. sub (sp),r0
  1645. tst 06(sp)
  1646. sxt r2
  1647. sub 04(sp),r2
  1648. mov r0,r4
  1649. mul r2,r4
  1650. mul 06(sp),r0
  1651. .if .test
  1652. bge 2f
  1653. inc r4
  1654. 2:
  1655. .endif
  1656. mul 02(sp),r2
  1657. .if .test
  1658. bge 2f
  1659. inc r4
  1660. 2: sub r2,r5
  1661. sbc r4
  1662. sub r0,r5
  1663. sbc r4
  1664. add r1,r3
  1665. sbc r5
  1666. sbc r4
  1667. .endif
  1668. mov 02(sp),r0
  1669. mul 06(sp),r0
  1670. .if .test
  1671. bge 2f
  1672. sub $1,r5
  1673. sbc r4
  1674. .endif
  1675. 2: sub r3,r0
  1676. .if .test
  1677. sxt r2
  1678. sbc r5
  1679. sbc r4
  1680. cmp r2,r4
  1681. bne 2f
  1682. cmp r2,r5
  1683. beq 9f
  1684. 2: jsr pc,e.iovfl
  1685. 9:
  1686. .endif
  1687. add $010,sp
  1688. mov r1,-(sp);
  1689. mov r0,-(sp);
  1690. jsr pc,regretu; next
  1691. /-------
  1692. dvi.l: jsr pc,wrdoff; br 0f
  1693. dvi.z: mov (sp)+,r0
  1694. 0: cmp r0,$04
  1695. bgt 1f
  1696. beq dvi4
  1697. cmp r0,$02
  1698. bne 1f
  1699. dvi.1W: mov 02(sp),r1
  1700. sxt r0
  1701. .if .test
  1702. cmp r1,$und / trap for undifined of size 2
  1703. beq 6f
  1704. cmp (sp),$und
  1705. bne 7f
  1706. 6: jsr pc,e.iund / this is the trap
  1707. 7:
  1708. .endif
  1709. div (sp)+,r0
  1710. jcs 9f
  1711. mov r0,(sp)
  1712. next
  1713. 1: jmp e.oddz
  1714. /-------
  1715. dvi4:
  1716. .if .prof
  1717. add $100.,*loprof
  1718. adc *hiprof
  1719. .endif
  1720. jsr pc,regsave
  1721. mov 02(sp),r3
  1722. bne 1f
  1723. tst (sp)
  1724. bne 1f
  1725. 9: jsr pc,e.idivz
  1726. 1: sxt r4
  1727. bpl 1f
  1728. neg r3
  1729. 1: cmp r4,(sp)
  1730. bne hardldiv
  1731. mov 06(sp),r2
  1732. mov 04(sp),r1
  1733. bge 2f
  1734. neg r1
  1735. neg r2
  1736. sbc r1
  1737. com r4
  1738. 2: mov r4,-(sp)
  1739. clr r0
  1740. div r3,r0
  1741. mov r0,-(sp)
  1742. mov r1,r0
  1743. mov r1,r4
  1744. mov r2,r1
  1745. div r3,r0
  1746. bvc 3f
  1747. mov r2,r1
  1748. mov r4,r0
  1749. sub r3,r0
  1750. div r3,r0
  1751. tst r1
  1752. sxt r1
  1753. add r1,r0
  1754. 3: mov r0,r1
  1755. mov (sp)+,r0
  1756. br 4f
  1757. hardldiv:
  1758. .if .prof
  1759. add $75.,*loprof
  1760. adc *hiprof
  1761. .endif
  1762. clr -(sp)
  1763. mov 010(sp),r2
  1764. mov 06(sp),r1
  1765. bpl 5f
  1766. com (sp)
  1767. neg r1
  1768. neg r2
  1769. sbc r1
  1770. 5: clr r0
  1771. mov 02(sp),r3
  1772. bge 6f
  1773. neg r3
  1774. neg 04(sp)
  1775. sbc r3
  1776. com (sp)
  1777. 6: mov $16.,r4
  1778. 9: clc
  1779. rol r2
  1780. rol r1
  1781. rol r0
  1782. cmp r3,r0
  1783. bhi 7f
  1784. bcs 8f
  1785. cmp 04(sp),r1
  1786. blos 8f
  1787. 7: sob r4,9b
  1788. br 1f
  1789. 8: sub 04(sp),r1
  1790. sbc r0
  1791. sub r3,r0
  1792. inc r2
  1793. sob r4,9b
  1794. 1:
  1795. mov r2,r1
  1796. clr r0
  1797. 4: tst (sp)+
  1798. beq 1f
  1799. neg r0
  1800. neg r1
  1801. sbc r0
  1802. 1: add $010,sp
  1803. mov r1,-(sp);
  1804. mov r0,-(sp);
  1805. jsr pc,regretu; next
  1806. /-------
  1807. rmi.l: jsr pc,wrdoff; br 0f
  1808. rmi.z: mov (sp)+,r0
  1809. 0: cmp r0,$04
  1810. bgt 1f
  1811. beq rmi4
  1812. cmp r0,$02
  1813. bne 1f
  1814. rmi.1W: mov 02(sp),r1
  1815. sxt r0
  1816. .if .test
  1817. cmp r1,$und / trap for undefineds of size 2
  1818. beq 6f
  1819. cmp (sp),$und
  1820. bne 7f
  1821. 6: jsr pc,e.iund / this is the trap
  1822. 7:
  1823. .endif
  1824. div (sp)+,r0
  1825. bcs 9f
  1826. mov r1,(sp)
  1827. next
  1828. 1: jmp e.oddz
  1829. /-------
  1830. rmi4:
  1831. .if .prof
  1832. add $100.,*loprof
  1833. adc *hiprof
  1834. .endif
  1835. jsr pc,regsave
  1836. mov 02(sp),r3
  1837. bne 1f
  1838. tst (sp)
  1839. bne 1f
  1840. 9: jsr pc,e.idivz
  1841. 1: tst r3
  1842. sxt r4
  1843. bpl 1f
  1844. neg r3
  1845. 1: cmp r4,(sp)
  1846. bne hardrmi4
  1847. mov 06(sp),r2
  1848. mov 04(sp),r1
  1849. mov r1,r4
  1850. bge 2f
  1851. neg r1
  1852. neg r2
  1853. sbc r1
  1854. 2: mov r4,-(sp)
  1855. clr r0
  1856. div r3,r0
  1857. mov r1,r0
  1858. mov r1,r4
  1859. mov r2,r1
  1860. div r3,r0
  1861. bvc 3f
  1862. mov r2,r1
  1863. mov r4,r0
  1864. sub r3,r0
  1865. div r3,r0
  1866. tst r1
  1867. beq 3f
  1868. add r3,r1
  1869. 3: tst (sp)+
  1870. bpl 4f
  1871. neg r1
  1872. 4: sxt r0
  1873. br 9f
  1874. hardrmi4:
  1875. .if .prof
  1876. add $75.,*loprof
  1877. adc *hiprof
  1878. .endif
  1879. mov 06(sp),r2
  1880. mov 04(sp),r1
  1881. bpl 5f
  1882. neg r1
  1883. neg r2
  1884. sbc r1
  1885. 5: clr r0
  1886. mov (sp),r3
  1887. bge 6f
  1888. neg r3
  1889. neg 02(sp)
  1890. sbc r3
  1891. 6: mov $16.,r4
  1892. 1: clc
  1893. rol r2
  1894. rol r1
  1895. rol r0
  1896. cmp r3,r0
  1897. bhi 7f
  1898. bcs 8f
  1899. cmp 02(sp),r1
  1900. blos 8f
  1901. 7: sob r4,1b
  1902. br 2f
  1903. 8: sub 02(sp),r1
  1904. sbc r0
  1905. sub r3,r0
  1906. sob r4,1b
  1907. 2: tst 04(sp)
  1908. bge 9f
  1909. neg r0
  1910. neg r1
  1911. sbc r0
  1912. 9: add $010,sp
  1913. mov r1,-(sp)
  1914. mov r0,-(sp)
  1915. jsr pc,regretu; next
  1916. /-------
  1917. ngi.l: jsr pc,wrdoff; br 1f
  1918. ngi.z: mov (sp)+,r0
  1919. 1:
  1920. lblngi:
  1921. cmp r0,$02
  1922. bgt 1f
  1923. .if .test
  1924. cmp (sp),$und / trap for undefineds of size 2
  1925. bne 7f
  1926. jsr pc,e.iund
  1927. 7:
  1928. .endif
  1929. neg (sp)
  1930. 3: next
  1931. 1: cmp r0,$04
  1932. bgt 2f
  1933. mov (sp),r0
  1934. neg (sp)
  1935. mov 02(sp),r1
  1936. neg 02(sp)
  1937. sbc (sp)
  1938. cmp r0,(sp)
  1939. .if .test
  1940. bne 3b
  1941. cmp r1,02(sp)
  1942. bne 3b
  1943. 2: jsr pc,e.iovfl
  1944. .endif
  1945. next
  1946. /-------
  1947. sli.l: jsr pc,wrdoff; br 0f
  1948. sli.z: mov (sp)+,r0
  1949. 0: cmp r0,$02
  1950. bgt 1f
  1951. sli.1W: mov (sp)+,r1
  1952. mov (sp)+,r0
  1953. .if .test
  1954. cmp r0,$und / trap for undefined size 2
  1955. bne 7f
  1956. jsr pc,e.iund
  1957. 7:
  1958. .endif
  1959. ash r1,r0
  1960. .if .test
  1961. bvc 7f
  1962. jsr pc,e.iovfl
  1963. 7:
  1964. .endif
  1965. mov r0,-(sp)
  1966. next
  1967. 1: cmp r0,$04
  1968. bgt 2f
  1969. mov 02(sp),r0
  1970. mov 04(sp),r1
  1971. ashc (sp)+,r0
  1972. .if .test
  1973. bvc 7f
  1974. jsr pc,e.iovfl
  1975. 7:
  1976. .endif
  1977. mov r0,(sp)
  1978. mov r1,02(sp)
  1979. next
  1980. 2: jmp e.oddz
  1981. /-------
  1982. sri.l: jsr pc,wrdoff; br 0f
  1983. sri.z: mov (sp)+,r0
  1984. 0: cmp r0,$02
  1985. bgt 1f
  1986. mov (sp)+,r1
  1987. mov (sp)+,r0
  1988. .if .test
  1989. cmp r0,$und / trap for undefined size 2
  1990. bne 7f
  1991. jsr pc,e.iund
  1992. 7:
  1993. .endif
  1994. neg r1
  1995. ash r1,r0
  1996. mov r0,-(sp)
  1997. next
  1998. 1: cmp r0,$04
  1999. bgt 2f
  2000. mov 02(sp),r0
  2001. mov 04(sp),r1
  2002. neg (sp)
  2003. ashc (sp)+,r0
  2004. mov r0,(sp)
  2005. mov r1,02(sp)
  2006. next
  2007. 2: jmp e.oddz
  2008. /--------------------------------------------------------------
  2009. adu.l: jsr pc,wrdoff; br 0f
  2010. adu.z: mov (sp)+,r0
  2011. 0: jsr pc,tstr0; add r0,sp
  2012. mov sp,r1; add r0,sp; asr r0
  2013. 2: adc -(sp); add -(r1),(sp); sob r0,2b
  2014. next
  2015. sbu.l: jsr pc,wrdoff; br 0f
  2016. sbu.z: mov (sp)+,r0
  2017. 0: jsr pc,tstr0; add r0,sp
  2018. mov sp,r1; add r0,sp; asr r0;
  2019. 2: sbc -(sp); sub -(r1),(sp); sob r0,2b
  2020. next
  2021. mlu.l: jsr pc,wrdoff; br 0f
  2022. mlu.z: mov (sp)+,r0
  2023. 0: jsr pc,tstr0
  2024. cmp r0,$04
  2025. bgt 1f
  2026. beq mlu4
  2027. mov (sp)+,r1
  2028. mul (sp)+,r1
  2029. mov r1,-(sp)
  2030. next
  2031. 1: jmp e.oddz
  2032. mlu4:
  2033. .if .prof
  2034. add $90.,*loprof
  2035. adc *hiprof
  2036. .endif
  2037. jsr pc,regsave
  2038. clr r0
  2039. mov 02(sp),r1
  2040. mov 06(sp),r3
  2041. mul r3,r0
  2042. tst r3
  2043. bge 1f
  2044. ashc $15.,r0
  2045. 1: mov 02(sp),r3
  2046. clr r2
  2047. mul 04(sp),r2
  2048. add r3,r0
  2049. mov 06(sp),r3
  2050. clr r2
  2051. mul (sp),r2
  2052. add r3,r0
  2053. add $010,sp
  2054. mov r1,-(sp)
  2055. mov r0,-(sp)
  2056. jsr pc,regretu; next
  2057. 9: jmp e.oddz
  2058. /-------
  2059. dvu.l: jsr pc,wrdoff; br 0f
  2060. dvu.z: mov (sp)+,r0
  2061. 0:
  2062. clr saver0;
  2063. cmp r0,$04
  2064. bgt 9b
  2065. beq dvu4
  2066. clr r0
  2067. mov 02(sp),r1
  2068. tst (sp)
  2069. blt 1f
  2070. div (sp)+,r0
  2071. mov r0,(sp); next
  2072. 1: mov (sp),-(sp);
  2073. clr 02(sp);
  2074. clr -(sp);
  2075. mov $1,saver0;
  2076. dvu4:
  2077. .if .prof
  2078. add $95.,*loprof
  2079. adc *hiprof
  2080. .endif
  2081. jsr pc,regsave
  2082. clr r0
  2083. tst (sp)
  2084. bne harddvu4
  2085. tst 02(sp)
  2086. blt harddvu4
  2087. mov 06(sp),r2
  2088. mov 04(sp),r1
  2089. mov 02(sp),r3
  2090. div r3,r0
  2091. mov r0,-(sp)
  2092. mov r1,r0
  2093. mov r1,r4
  2094. mov r2,r1
  2095. div r3,r0
  2096. bvc 1f
  2097. mov r2,r1
  2098. mov r4,r0
  2099. sub r3,r0
  2100. div r3,r0
  2101. tst r1
  2102. sxt r1
  2103. add r1,r0
  2104. 1: mov r0,r1
  2105. mov (sp)+,r0
  2106. br 2f
  2107. harddvu4:
  2108. .if .prof
  2109. add $75.,*loprof
  2110. adc *hiprof
  2111. .endif
  2112. mov 06(sp),r2
  2113. mov 04(sp),r1
  2114. mov (sp),r3
  2115. mov $17.,r4
  2116. br 3f
  2117. 6: rol r2
  2118. rol r1
  2119. rol r0
  2120. 3: cmp r3,r0
  2121. bhi 4f
  2122. blo 5f
  2123. cmp 02(sp),r1
  2124. blos 5f
  2125. 4: clc
  2126. sob r4,6b
  2127. br 7f
  2128. 5: sub 02(sp),r1
  2129. sbc r0
  2130. sub r3,r0
  2131. sec
  2132. sob r4,6b
  2133. 7: rol r2
  2134. bcc 8f
  2135. mov $01,r0
  2136. br 9f
  2137. 8: clr r0
  2138. 9: mov r2,r1
  2139. 2: add $010,sp
  2140. mov r1,-(sp)
  2141. mov r0,-(sp)
  2142. jsr pc,regretu
  2143. tst saver0;
  2144. beq 2f;
  2145. tst (sp)+
  2146. 2:
  2147. next
  2148. /-------
  2149. 9: jbr e.oddz
  2150. rmu.l: jsr pc,wrdoff; br 0f
  2151. rmu.z: mov (sp)+,r0
  2152. 0: clr saver0;
  2153. cmp r0,$04
  2154. bgt 9b
  2155. beq rmu4
  2156. cmp r0,$02
  2157. bne 9b
  2158. mov $1,saver0;
  2159. mov 02(sp),r1
  2160. tst (sp)
  2161. blt 1f
  2162. clr r0
  2163. div (sp)+,r0
  2164. mov r1,(sp); next
  2165. 1: mov (sp),-(sp)
  2166. clr 02(sp)
  2167. clr -(sp)
  2168. rmu4:
  2169. .if .prof
  2170. add $95.,*loprof
  2171. adc *hiprof
  2172. .endif
  2173. jsr pc,regsave
  2174. clr r0
  2175. tst (sp)
  2176. bne hardrmu4
  2177. tst 02(sp)
  2178. blt hardrmu4
  2179. mov 06(sp),r2
  2180. mov 04(sp),r1
  2181. mov 02(sp),r3
  2182. div r3,r0
  2183. mov r1,r0
  2184. mov r1,r4
  2185. mov r2,r1
  2186. div r3,r0
  2187. bvc 1f
  2188. mov r2,r1
  2189. mov r4,r0
  2190. sub r3,r0
  2191. div r3,r0
  2192. tst r1
  2193. beq 1f
  2194. add r3,r1
  2195. 1: clr r0
  2196. br 2f
  2197. hardrmu4:
  2198. .if .prof
  2199. add $75.,*loprof
  2200. adc *hiprof
  2201. .endif
  2202. mov 06(sp),r2
  2203. mov 04(sp),r1
  2204. mov (sp),r3
  2205. mov $17.,r4
  2206. br 3f
  2207. 6: clc
  2208. rol r2
  2209. rol r1
  2210. rol r0
  2211. 3: cmp r3,r0
  2212. bhi 4f
  2213. bcs 5f
  2214. cmp 02(sp),r1
  2215. blos 5f
  2216. 4: sob r4,6b
  2217. br 2f
  2218. 5: sub 02(sp),r1
  2219. sbc r0
  2220. sub r3,r0
  2221. sob r4,6b
  2222. 2: add $010,sp
  2223. mov r1,-(sp)
  2224. mov r0,-(sp)
  2225. jsr pc,regretu
  2226. tst saver0
  2227. beq 2f;
  2228. tst (sp)+;
  2229. 2: next
  2230. /-------
  2231. slu.l: jsr pc,wrdoff; br 0f
  2232. slu.z: mov (sp)+,r0
  2233. 0:
  2234. cmp r0,$02
  2235. bgt 1f
  2236. mov (sp)+,r1
  2237. mov (sp)+,r0
  2238. ash r1,r0
  2239. mov r0,-(sp)
  2240. next
  2241. 1: cmp r0,$04
  2242. bgt 2f
  2243. mov 02(sp),r0
  2244. mov 04(sp),r1
  2245. ashc (sp)+,r0
  2246. mov r0,(sp)
  2247. mov r1,02(sp)
  2248. next
  2249. 2: jmp e.oddz
  2250. /-------
  2251. sru.l: jsr pc,wrdoff; br 0f
  2252. sru.z: mov (sp)+,r0
  2253. 0:
  2254. cmp r0,$02
  2255. bgt 1f
  2256. mov 2(sp),r1
  2257. neg (sp)
  2258. clr r0
  2259. ashc (sp)+,r0
  2260. 2: mov r1,-(sp)
  2261. next
  2262. 1: cmp r0,$04
  2263. bgt 3f
  2264. mov 02(sp),r0
  2265. mov 04(sp),r1
  2266. neg (sp)
  2267. beq 4f
  2268. ashc $-1,r0
  2269. bic $0100000,r0
  2270. inc (sp)
  2271. beq 4f
  2272. ashc (sp)+,r0
  2273. 4: mov r0,(sp)
  2274. mov r1,02(sp)
  2275. next
  2276. 3: jmp e.oddz
  2277. /-------
  2278. /--------------------------------------------------------------
  2279. / FLOATING POINT INSTRUCTIONS
  2280. /--------------------------------------------------------------
  2281. adf.s0: clr r0; bisb (pcx)+,r0; br 0f
  2282. adf.l: jsr pc,wrdoff; br 0f
  2283. adf.z: mov (sp)+,r0
  2284. 0:
  2285. jsr pc,setfloat
  2286. movf (sp)+,fr0
  2287. addf (sp)+,fr0
  2288. movf fr0,-(sp)
  2289. next
  2290. /-------
  2291. sbf.s0: clr r0; bisb (pcx)+,r0; br 0f
  2292. sbf.l: jsr pc,wrdoff; br 0f
  2293. sbf.z: mov (sp)+,r0
  2294. 0:
  2295. jsr pc,setfloat
  2296. movf (sp)+,fr0
  2297. subf (sp)+,fr0
  2298. negf fr0
  2299. movf fr0,-(sp)
  2300. next
  2301. /-------
  2302. mlf.s0: clr r0; bisb (pcx)+,r0; br 0f
  2303. mlf.l: jsr pc,wrdoff; br 0f
  2304. mlf.z: mov (sp)+,r0
  2305. 0:
  2306. jsr pc,setfloat
  2307. movf (sp)+,fr0
  2308. mulf (sp)+,fr0
  2309. movf fr0,-(sp)
  2310. next
  2311. /-------
  2312. dvf.s0: clr r0; bisb (pcx)+,r0; br 0f
  2313. dvf.l: jsr pc,wrdoff; br 0f
  2314. dvf.z: mov (sp)+,r0
  2315. 0:
  2316. jsr pc,setfloat
  2317. movf (sp)+,fr0
  2318. movf (sp)+,fr1
  2319. divf fr0,r1
  2320. movf fr1,-(sp)
  2321. next
  2322. /-------
  2323. ngf.l: jsr pc,wrdoff; br 0f
  2324. ngf.z: mov (sp)+,r0
  2325. 0:
  2326. jsr pc,setfloat
  2327. negf (sp)
  2328. next
  2329. /-------
  2330. fif.l: jsr pc,wrdoff; br 0f
  2331. fif.z: mov (sp)+,r0
  2332. 0:
  2333. jsr pc,setfloat
  2334. movf (sp)+,fr0
  2335. modf (sp)+,fr0
  2336. movf fr0,-(sp)
  2337. movf fr1,-(sp)
  2338. next
  2339. /-------
  2340. fef.l: jsr pc,wrdoff; br 0f
  2341. fef.z: mov (sp)+,r0
  2342. 0:
  2343. jsr pc,setfloat
  2344. movf (sp),fr0
  2345. movei fr0,-(sp)
  2346. movie $0,fr0
  2347. movf fr0,02(sp)
  2348. next
  2349. /----------------------------------------------------------------------------
  2350. / TEST AND BRANCH GROUP
  2351. /----------------------------------------------------------------------------
  2352. tlt.z: tst (sp)+; blt true; clr -(sp); next
  2353. tle.z: tst (sp)+; ble true; clr -(sp); next
  2354. teq.z: tst (sp)+; beq true; clr -(sp); next
  2355. tne.z: tst (sp)+; bne true; clr -(sp); next
  2356. tge.z: tst (sp)+; bge true; clr -(sp); next
  2357. tgt.z: tst (sp)+; bgt true; clr -(sp); next
  2358. /----------------------------------------------------------------------------
  2359. zlt.s0: tst (sp)+; blt yesbr2; br nobr2
  2360. zlt.l: tst (sp)+; blt yesbr3; br nobr3
  2361. zle.s0: tst (sp)+; ble yesbr2; br nobr2
  2362. zle.l: tst (sp)+; ble yesbr3; br nobr3
  2363. zeq.s0: tst (sp)+; beq yesbr2; br nobr2
  2364. zeq.s1: tst (sp)+; beq yesbr4; br nobr2
  2365. zeq.l: tst (sp)+; beq yesbr3; br nobr3
  2366. zne.s0: tst (sp)+; bne yesbr2; br nobr2
  2367. zne.l: tst (sp)+; bne yesbr3; br nobr3
  2368. zne.s_1: tst (sp)+; bne yesbr5; br nobr2
  2369. zge.s0: tst (sp)+; bge yesbr2; br nobr2
  2370. zge.l: tst (sp)+; bge yesbr3; br nobr3
  2371. zgt.s0: tst (sp)+; bgt yesbr2; br nobr2
  2372. zgt.l: tst (sp)+; bgt yesbr3; br nobr3
  2373. great:
  2374. true: mov $1,-(sp)
  2375. next
  2376. /------------------------------------------------------------------------------
  2377. blt.s0: cmp (sp)+,(sp)+; bgt yesbr2; br nobr2
  2378. blt.l: cmp (sp)+,(sp)+; bgt yesbr3; br nobr3
  2379. ble.s0: cmp (sp)+,(sp)+; bge yesbr2; br nobr2
  2380. ble.l: cmp (sp)+,(sp)+; bge yesbr3; br nobr3
  2381. beq.l: cmp (sp)+,(sp)+; beq yesbr3; br nobr3
  2382. beq.s0: cmp (sp)+,(sp)+; beq yesbr2; br nobr2
  2383. bne.s0: cmp (sp)+,(sp)+; bne yesbr2; br nobr2
  2384. bne.l: cmp (sp)+,(sp)+; bne yesbr3; br nobr3
  2385. bge.s0: cmp (sp)+,(sp)+; ble yesbr2; br nobr2
  2386. bge.l: cmp (sp)+,(sp)+; ble yesbr3; br nobr3
  2387. bgt.s0: cmp (sp)+,(sp)+; blt yesbr2; br nobr2
  2388. bgt.l: cmp (sp)+,(sp)+; blt yesbr3; br nobr3
  2389. bra.s0: yesbr2:
  2390. clr r0;
  2391. 5: bisb (pcx)+,r0
  2392. 1: add r0,pcx
  2393. next
  2394. bra.l: yesbr3:
  2395. jsr pc,wrdoff
  2396. br 1b
  2397. bra.s1: yesbr4: mov $400,r0; br 5b
  2398. bra.s_1: yesbr5: mov $-400,r0; br 5b
  2399. bra.s_2: mov $-800,r0; br 5b
  2400. nobr2: tstb (pcx)+
  2401. next
  2402. nobr3: cmpb (pcx)+,(pcx)+
  2403. next
  2404. /
  2405. /------------------------------------------------------------------------------
  2406. / Compare group
  2407. /------------------------------------------------------------------------------
  2408. calccomp: mov (sp)+,saver1; / old pc
  2409. mov sp,r1;
  2410. add r0,r1; mov r1,r5;
  2411. add r0,r1; mov r1,saver0; / new sp
  2412. mov r0,r1; asr r1;
  2413. 2: cmp (r5)+,(sp)+; blt 3f;
  2414. bgt 4f; dec r1;
  2415. beq 5f
  2416. 2: cmp (r5)+,(sp)+; blo 3f;
  2417. bhi 4f; sob r1,2b;
  2418. 5: mov saver0,sp; clr -(sp);
  2419. br 5f
  2420. 4: mov saver0,sp; mov $1,-(sp);
  2421. br 5f
  2422. 3: mov saver0,sp; mov $-1,-(sp);
  2423. br 5f
  2424. 5: mov saver1,-(sp); rts pc
  2425. cmi.1W: mov $2,r0; br 1f
  2426. cmi.2W: mov $4,r0; br 1f
  2427. cmi.l: jsr pc,wrdoff; br 1f
  2428. cmi.z: mov (sp)+,r0;
  2429. 1: jsr pc,calccomp; next
  2430. cms.s0: clr r0; bisb (pcx)+,r0
  2431. 1: jsr pc,calccomp; tst (sp)+;
  2432. bne great; clr -(sp); next
  2433. cms.l: jsr pc,wrdoff; br 1b
  2434. cms.z: mov (sp)+,r0; br 1b
  2435. cmu.l: jsr pc,wrdoff; br 1f
  2436. cmu.z: mov (sp)+,r0; br 1f
  2437. cmp.z: mov $2,r0;
  2438. 1: jsr pc,calccomp; mov (sp)+,r1;
  2439. jlo less; jhi great;
  2440. clr -(sp); next
  2441. cmf.s0: clr r0; bisb (pcx)+,r0;
  2442. 1: cmp $4,r0; beq 3f
  2443. cmp $8,r0; beq 3f
  2444. jsr pc,e.oddz;
  2445. 3: jsr pc,setfloat
  2446. movf (sp)+,fr0; cmpf (sp)+,fr0;
  2447. 4: cfcc; jlt less; jgt great;
  2448. clr -(sp); next
  2449. cmf.l: jsr pc,wrdoff; br 1b
  2450. cmf.z: mov (sp)+,r0; br 1b
  2451. less: mov $-1,-(sp); next
  2452. /------------------------------------------------------------------------------
  2453. /------------------------------------------------------------------------------
  2454. /------------------------------------------------------------------------------
  2455. / call and return group
  2456. /------------------------------------------------------------------------------
  2457. /
  2458. / Frame format on the stack is:
  2459. /
  2460. / | Parameter 1 |
  2461. / | - - - - - - - - - - - - |
  2462. / | Static link = param 0 | < AB
  2463. / |_________________________| ____
  2464. / |-------------------------| | P
  2465. / | Saved line number | | R
  2466. / |-------------------------| | O
  2467. / | Saved file address | | C
  2468. / |-------------------------| | F
  2469. / | Return address | | R
  2470. / |-------------------------| | A
  2471. / | Dynamic link | < LB | M
  2472. / |_________________________| ____| E
  2473. / |-------------------------|
  2474. / | |
  2475. / | local variable -1 |
  2476. / |-------------------------|
  2477. / | |
  2478. /
  2479. /
  2480. / The static link and the parameters are set by the
  2481. / calling procedure; the frame is set by cal which reserves
  2482. / also the space for local variables.
  2483. /------------------------------------------------------------------------------
  2484. cal.1: cal.2: cal.3: cal.4: cal.5: cal.6: cal.7: cal.8:
  2485. cal.9: cal.10: cal.11: cal.12: cal.13: cal.14: cal.15: cal.16:
  2486. cal.17: cal.18: cal.19: cal.20: cal.21: cal.22: cal.23: cal.24:
  2487. cal.25: cal.26: cal.27: cal.28:
  2488. asr r0; sub $077,r0; br 1f
  2489. cal.s0: clr r0; bisb (pcx)+,r0; br 1f
  2490. cai.z: mov (sp)+,r0; br 1f
  2491. cal.l: jsr pc,wrdoff
  2492. lblcal:
  2493. 1:
  2494. cmp nprocs,r0
  2495. jlos e.badpc
  2496. 1: asl r0; asl r0;
  2497. .if .flow + .count + .prof
  2498. mov r0,r5;
  2499. asl r5
  2500. add r5,r0 / procdes 12 bytes in this case
  2501. .endif
  2502. add pd,r0; / now r0 points to the bottom
  2503. / of the proc descriptor
  2504. mov *eb,-(sp) / save line number
  2505. mov *filb,-(sp) / save file address
  2506. .if .prof + .count + .flow
  2507. tst 10.(r0) / yet a filename defined in this proc?
  2508. bne 4f / yes? continue
  2509. mov (sp),10.(r0) / no? Then take the old filename
  2510. 4: mov curproc,(sp) / save old procdescriptor
  2511. mov r0,curproc / continue with the new one
  2512. mov 4(r0),countfld / count pointer minus line number
  2513. sub 6(r0),countfld / to add at line numbers
  2514. .endif
  2515. mov pcx,-(sp) / return address
  2516. mov r2,-(sp) / old local base
  2517. mov sp,r2 / new local base
  2518. mov (r0)+,r1 / number of bytes for locals
  2519. beq 3f / no locals
  2520. inc r1; asr r1 / make even
  2521. 2: mov $und,-(sp) / make undefined
  2522. sob r1,2b / for r1 words local
  2523. 3: mov (r0),pcx / em start address
  2524. next / ready
  2525. /------------------------------------------------------------------------------
  2526. ret.l: jsr pc,wrdoff; br 1f
  2527. ret.1W: mov $2,r0; br 1f
  2528. ret.s0: clr r0; bisb (pcx)+,r0;
  2529. jlt e.oddz / bad result size
  2530. beq ret.0 / no result
  2531. cmp $32.,r0; bge 1f; jsr pc,e.badlfr
  2532. 1: inc r0; asr r0 / make even
  2533. mov r0,retsize / result size
  2534. mov $retarea,r1 / must point to retarea
  2535. 2: mov (sp)+,(r1)+ / load result
  2536. sob r0,2b / continue when there is more
  2537. br 3f
  2538. retcount:
  2539. ret.0: clr retsize / no function result
  2540. 3: mov r2,sp / set sp to bottom frame
  2541. mov (sp)+,r2 / restore (dynamic) local base
  2542. jeq lblhalt; / if zero then main procedure returns
  2543. mov (sp)+,pcx / return address in program counter
  2544. mov eb,r1 / must point to external base
  2545. mov (sp)+,r0 / file or procdesbase in r0
  2546. .if .count + .flow + .prof
  2547. mov r0,curproc / save procdesbase current proc
  2548. mov 4(r0),countfld / restore pointer to
  2549. beq 5f / countfield 0 non interesting
  2550. sub 6(r0),countfld / table entries
  2551. mov countfld,countptr
  2552. add (sp),countptr
  2553. .if .prof
  2554. tst (sp)
  2555. beq 5f
  2556. mov countptr,r5
  2557. asl r5
  2558. asl r5
  2559. add ltime,r5
  2560. mov r5,hiprof
  2561. add $2,r5
  2562. mov r5,loprof
  2563. .endif
  2564. 5:
  2565. mov 10.(r0),r0 / pointer to file name in r0
  2566. .endif
  2567. retlast:
  2568. .if .last
  2569. tst 4(r1) / file 0 not stacked
  2570. beq 4f
  2571. cmp r0,4(r1) / same file name?
  2572. beq 4f / yes continue
  2573. jsr pc,nexttab / next line table entry in r5
  2574. clr (r5) / 0 indicates file pointer follows
  2575. jsr pc,nexttab / next entry in r5
  2576. mov 4(r1),(r5) / store pointer to file name
  2577. 5: mov (sp),(r1) / restored line number in *eb
  2578. beq 4f / do not put 0 in last table
  2579. jsr pc,nexttab / next entry in r5
  2580. mov (sp),(r5) / line number in table
  2581. 4: cmp (sp),(r1) / line number different?
  2582. bne 5b / yes? put it in table
  2583. .endif
  2584. mov r0,4(r1) / old file address
  2585. mov (sp)+,(r1) / reset line number
  2586. next / main loop again
  2587. lfr.l: jsr pc,wrdoff;
  2588. 8: bit $1,r0; jne e.illins
  2589. cmp r0,retsize; jeq 7f; jsr pc,e.badlfr
  2590. 7: asr r0; / number of words
  2591. tst r0; beq 0f;
  2592. mov $retarea,r1; / must point to retarea
  2593. add r0,r1;
  2594. add r0,r1; / top of result
  2595. 2: mov -(r1),-(sp); / move word of result
  2596. sob r0,2b; / look for more
  2597. 0: next
  2598. lfr.1W: mov $2,r0; br 8b
  2599. lfr.2W: mov $4,r0; br 8b
  2600. lfr.s0: clr r0; bisb (pcx)+,r0; br 8b
  2601. /
  2602. /------------------------------------------------------------------------------
  2603. / miscellaneous
  2604. /------------------------------------------------------------------------------
  2605. exg.s0: clr r0; bisb (pcx)+,r0; br 1f
  2606. exg.l: jsr pc,wrdoff; br 1f
  2607. exg.z: mov (sp)+,r0;
  2608. 1: cmp r0,$1; beq 0f;
  2609. blt 9f; bit $1,r0;
  2610. bne 9f;
  2611. add r0,sp;
  2612. mov r0,r1; asr r1;
  2613. add sp,r0;
  2614. 2: mov -(sp),r5; mov -(r0),(sp);
  2615. mov r5,(r0); sob r1,2b;
  2616. next
  2617. 0: swab (sp); next
  2618. 9: jsr pc,e.oddz; next
  2619. /------------------------------------------------------------------------------
  2620. dup.1W: mov (sp),-(sp); next
  2621. dup.l: jsr pc,wrdoff; br 1f;
  2622. dus.l: jsr pc,wrdoff; br 0f;
  2623. dus.z: mov (sp)+,r0;
  2624. 0: ble 9b; bit $1,r0;
  2625. bne 9b; add r0,sp;
  2626. tst -(sp); mov (sp)+,r0;
  2627. 1: ble 9b; inc r0;
  2628. bic $1,r0; mov r0,r1;
  2629. mov sp,r5; add r0,r5;
  2630. asr r1;
  2631. 2: mov -(r5),-(sp); sob r1,2b; next
  2632. nop.z:
  2633. next
  2634. /------------------------------------------------------------------------------
  2635. fil.l: jsr pc,wrdoff; add eb,r0
  2636. cmp r0,*filb; beq 1f;
  2637. .if .last
  2638. clr *eb / new file asks for new line
  2639. jsr pc,nexttab; clr (r5);
  2640. jsr pc,nexttab; mov *filb,(r5);
  2641. .endif
  2642. .if .flow + .count + .prof
  2643. mov curproc,r1 / current proc descriptor
  2644. mov 4(r1),countfld
  2645. sub 6(r1),countfld / start countptr for this proc
  2646. mov r0,10.(r1) / file pointer in procdes
  2647. .endif
  2648. mov r0,*filb
  2649. 1: next
  2650. lni.z: inc *eb;
  2651. .if .count + .flow + .prof
  2652. inc countptr
  2653. .if .prof
  2654. add $4,hiprof
  2655. add $4,loprof
  2656. .endif
  2657. .endif
  2658. br 8f
  2659. lin.l: jsr pc,wrdoff; br 1f
  2660. lin.s0: clr r0; bisb (pcx)+,r0
  2661. 1: cmp *eb,r0; beq 9f;
  2662. mov r0,*eb
  2663. .if .count + .flow + .prof
  2664. mov countfld,r5
  2665. add r0,r5 / this is the right countptr
  2666. mov r5,countptr
  2667. .if .prof
  2668. asl r5
  2669. asl r5
  2670. add ltime,r5
  2671. mov r5,hiprof
  2672. add $2,r5
  2673. mov r5,loprof
  2674. .endif
  2675. .endif
  2676. 8:
  2677. .if .last
  2678. jsr pc,nexttab / next entry in lasttab
  2679. mov *eb,(r5) / set endline
  2680. .endif
  2681. .if .count
  2682. mov countptr,r1 / line number in r1
  2683. asl r1
  2684. asl r1 / multiply by 4
  2685. add lcount,r1 / r1 is pointer to long integer now
  2686. add $1,2(r1) / cannot be inc
  2687. adc (r1) / that was all
  2688. .endif
  2689. .if .flow
  2690. mov countptr,r1 / line number in r1
  2691. clr r0 / get ready for divide
  2692. div $8.,r0 / r0 = byte offset; r1 = bit offset
  2693. add lflow,r0 / r0 is byte pointer now
  2694. bisb bits(r1),(r0) / set bit
  2695. .endif
  2696. 9: next
  2697. /------------------------------------------------------------------------------
  2698. bls.l: jsr pc,wrdoff; br 0f;
  2699. bls.z: mov (sp)+,r0;
  2700. 0: asr r0
  2701. bhi 1f
  2702. jbr e.oddz
  2703. 1: mov (sp)+,r1; sob r0,1b;
  2704. mov r1,r0; br 1f;
  2705. blm.l: jsr pc,wrdoff
  2706. tst r0
  2707. br 1f
  2708. blm.s0: clr r0; bisb (pcx)+,r0
  2709. 1: jsr pc,regsave; jsr pc,chckptr
  2710. mov (sp)+,r2; jsr pc,chckptr
  2711. mov (sp)+,r3
  2712. mov r0,r1
  2713. asr r0
  2714. beq 2f / Now avoid wrong copy. The pieces may overlap !
  2715. cmp r3,r2
  2716. beq 2f
  2717. blt 3f
  2718. 1: mov (r3)+,(r2)+
  2719. sob r0,1b
  2720. 2: jsr pc,regretu; next
  2721. 3: add r1,r3; add r1,r2;
  2722. 1: mov -(r3),-(r2); sob r0,1b; br 2b
  2723. /------------------------------------------------------------------------------
  2724. / Range check and case instructions
  2725. /------------------------------------------------------------------------------
  2726. csa.l: jsr pc,wrdoff; br 1f;
  2727. csa.z: mov (sp)+,r0;
  2728. 1: sub $2,r0; jne e.illins;
  2729. csa.1W: mov (sp)+,r0;
  2730. mov (sp)+,r1; sub 2(r0),r1;
  2731. blt 6f; cmp 4(r0),r1;
  2732. blo 6f; asl r1;
  2733. add $6,r1; add r0,r1;
  2734. 5: mov (r1),pcx;
  2735. jeq e.case; next
  2736. 6: mov r0,r1; br 5b;
  2737. csb.z: mov (sp)+,r0; br 1f;
  2738. csb.l: jsr pc,wrdoff;
  2739. 1: sub $2,r0; jne e.illins;
  2740. csb.1W: mov (sp)+,r0; mov (sp)+,r1;
  2741. mov r0,pcx; mov 2(r0),r5
  2742. /use pcx as ordinary register
  2743. ble 3f
  2744. 2: add $4,r0; cmp (r0),r1;
  2745. beq 4f; sob r5,2b;
  2746. 3: mov (pcx),pcx; jeq e.case; next
  2747. 4: mov 2(r0),pcx; jeq e.case; next
  2748. rck.l: jsr pc,wrdoff; br 1f;
  2749. rck.z: mov (sp)+,r0;
  2750. 1: sub $2,r0; beq rck.1W;
  2751. sub $2,r0; jne e.oddz;
  2752. mov (sp)+,r1; cmp (sp),(r1);
  2753. blt 9f; cmp (sp),4(r1);
  2754. bgt 9f; next
  2755. rck.1W: mov (sp)+,r1; cmp (sp),(r1);
  2756. blt 9f; cmp (sp),2(r1);
  2757. bgt 9f; next
  2758. 9: mov $ERANGE,-(sp); jmp trp.z;
  2759. /------------------------------------------------------------------------------
  2760. / Load and store register
  2761. /------------------------------------------------------------------------------
  2762. lbllor:
  2763. lor.s0: clr r0; bisb (pcx)+,r0
  2764. cmp r0,$2; jhi e.illins
  2765. asl r0; jmp 1f(r0)
  2766. 1: br 2f; br 3f; br 4f
  2767. 2: mov lb,-(sp); next
  2768. 3: mov sp,r1; mov r1,-(sp); next
  2769. 4: mov hp,-(sp); next
  2770. lblstr:
  2771. str.s0: clr r0; bisb (pcx)+,r0
  2772. cmp r0,$2; jhi e.illins
  2773. asl r0; jmp 1f(r0)
  2774. 1: br 2f; br 3f; br 4f
  2775. 2: mov (sp)+,lb; next
  2776. 3: mov (sp)+,r1; mov r1,sp; next
  2777. 4: mov (sp)+,r1;
  2778. 5: cmp r1,sybreak+2;
  2779. blos 5f; add $unixextra,sybreak+2;
  2780. sys indir;sybreak / ask for more core
  2781. jec 5b;
  2782. 1:
  2783. jsr pc,e.heap; / core claim failed
  2784. next
  2785. 5: cmp r1,globmax; jlo 1b
  2786. mov r1,hp; next
  2787. /------------------------------------------------------------------------------
  2788. ass.l: jsr pc,wrdoff; br 1f
  2789. ass.z: mov (sp)+,r0;
  2790. 1: cmp $2,r0; beq 2f
  2791. cmp $4,r0; jne e.oddz
  2792. mov (sp)+,r0;
  2793. 2: mov (sp)+,r0; br 3f
  2794. asp.lw: jsr pc,wrdoff; br 2f
  2795. asp.w0: clr r0; bisb (pcx)+,r0;
  2796. 2: asl r0; br 3f
  2797. asp.1W: asp.2W: asp.3W: asp.4W: asp.5W:
  2798. sub $88.,r0;
  2799. 3: blt 4f; add r0,sp; next
  2800. 4: neg r0; asr r0;
  2801. 2: mov $und,-(sp); sob r0,2b; next
  2802. /------------------------------------------------------------------------------
  2803. dch.z: mov (sp)+,r1; mov (r1),-(sp);
  2804. cmp (sp),ml; jge e.badptr;
  2805. next / dch adjusts local base to
  2806. / dynamically previous local base
  2807. lpb.z: add $8.,(sp); next / static link 8 bytes from lb
  2808. /------------------------------------------------------------------------------
  2809. gto.l: jsr pc,wrdoff; / get descriptor address
  2810. add eb,r0 / descriptor is in external address space
  2811. mov 4(r0),r2; / new local base after jump
  2812. mov 2(r0),sp; / new stack pointer after jump
  2813. mov (r0),pcx; / new program counter
  2814. .if .prof + .flow + .count
  2815. mov firstp,r0
  2816. 1: mov 8.(r0),r1
  2817. cmp r3,2(r1)
  2818. blos 2f
  2819. mov r1,r0
  2820. br 1b
  2821. 2: mov r0,curproc / procdesbase current proc
  2822. mov 4(r0),countfld / restore pointer to
  2823. sub 6(r0),countfld / table entries
  2824. mov 10.(r0),*filb / file name restored
  2825. .endif
  2826. next
  2827. /------------------------------------------------------------------------------
  2828. / Ignore mask
  2829. /------------------------------------------------------------------------------
  2830. lim.z: mov ignmask,-(sp); next / load ignore mask
  2831. sim.z: mov (sp)+,ignmask; next / store ignore mask
  2832. / for trap routines
  2833. sig.z: mov (sp),r1; / exchange previous
  2834. mov uerrorp,(sp); / and stacked error
  2835. mov r1,uerrorp; / procedure pointer
  2836. next
  2837. /------------------------------------------------------------------------------
  2838. / Signals generated by UNIX
  2839. /------------------------------------------------------------------------------
  2840. sig1:
  2841. mov $sig.trp+0.,-(sp); br 1f
  2842. sig2:
  2843. mov $sig.trp+2.,-(sp); br 1f
  2844. sig3:
  2845. mov $sig.trp+4.,-(sp); br 1f
  2846. sig13:
  2847. mov $sig.trp+24.,-(sp); br 1f
  2848. sig14:
  2849. mov $sig.trp+26.,-(sp); br 1f
  2850. sig15:
  2851. mov $sig.trp+28.,-(sp); br 1f
  2852. sig16:
  2853. mov $sig.trp+30.,-(sp) / push address trap number
  2854. 1: mov *(sp),-2(sp); / save trap number
  2855. mov $-2,*(sp) / set defold trap number
  2856. mov $retutrap,(sp) / set return address to rti
  2857. tst -(sp) / trap number position on stack
  2858. jbr error
  2859. sig12: mov r0,-(sp)
  2860. mov $2,r0; / fildes standard error
  2861. sys 0; 9b / call write message
  2862. sys signal;12.;sig12 / this is a mon-error
  2863. jsr pc,e.badmon
  2864. mov (sp)+,r0
  2865. rti
  2866. sig11: mov r0,saver1 /save r0
  2867. mov sybreak+2,r0
  2868. sub sp,r0
  2869. jgt e.memflt /real trap
  2870. mov $7f,r0
  2871. mov argv,sp /setup a new stack
  2872. jbr rude_error
  2873. .data
  2874. 7: <stack overflow\n\0>
  2875. .even
  2876. sybreak:sys break;_end /For indirect calling of break
  2877. .text
  2878. sig8: mov r0,saver1;
  2879. sys signal;8.;sig8
  2880. mov $ECONV,fpperr+6
  2881. stfps r0
  2882. bit $100,r0
  2883. beq 1f
  2884. mov $ECONV,fpperr+6
  2885. 1: stst r0
  2886. mov $retutrap,-(sp)
  2887. mov fpperr(r0),-(sp)
  2888. mov saver1,r0
  2889. jbr error
  2890. retutrap: rti
  2891. .data
  2892. fpperr: EILLINS; EILLINS; EFDIVZ; ECONV; EFOVFL; EFUNFL; EFUND; EILLINS
  2893. .text
  2894. /------------------------------------------------------------------------------
  2895. / Errors,traps and all their friends
  2896. /------------------------------------------------------------------------------
  2897. savereg: mov r1,-(sp) / stack r1 so r1 scratch register
  2898. mov 2(sp),r1 / now r1 contains return address
  2899. mov r0,2(sp) / save r0
  2900. mov r2,-(sp) / save r2
  2901. mov r3,-(sp) / save r3
  2902. mov r4,-(sp) / save r4
  2903. mov r5,-(sp) / save r5
  2904. mov 12.(sp),r0 / copy error number or param 0
  2905. movf fr0,-(sp) / save float registers
  2906. movf fr1,-(sp) / fr0 and fr1
  2907. stfps -(sp) / and status
  2908. mov $retsize+26.,r5
  2909. mov $13.,r2
  2910. 8: mov -(r5),-(sp); sob r2,8b
  2911. mov r0,-(sp) / extra errno (param 0) on stack
  2912. mov r1,-(sp) / set return address
  2913. rts pc
  2914. restoreg: mov (sp)+,r1 / return address in r1
  2915. add $2,sp / skip error number (param 0)
  2916. mov $13.,r2;
  2917. mov $retsize,r5;
  2918. 8: mov (sp)+,(r5)+; sob r2,8b
  2919. ldfps (sp)+ / restore floating point status
  2920. movf (sp)+,fr1 / restore float registers
  2921. movf (sp)+,fr0 / fr0 and fr1
  2922. mov (sp)+,r5 / restore r5
  2923. mov (sp)+,r4 / restore r4
  2924. mov (sp)+,r3 / restore r3
  2925. mov (sp)+,r2 / restore r2
  2926. mov 2(sp),r0 / restore r0
  2927. mov r1,2(sp) / reset return address
  2928. mov (sp)+,r1 / restore r1
  2929. rts pc
  2930. /------------------------------------------------------------------------------
  2931. / Various error entries
  2932. /------------------------------------------------------------------------------
  2933. e.badlfr: mov r0,r5; mov $2,r0; mov $blfr,9f+2
  2934. sys 0;9f;
  2935. mov r5,r0; rts pc
  2936. .data
  2937. 9: sys write;7;0;
  2938. blfr: <badlfr\n\0>
  2939. .even
  2940. .text
  2941. e.iund: mov $EIUND,-(sp); br error
  2942. e.iovfl: mov $EIOVFL,-(sp); br error
  2943. e.idivz: mov $EIDIVZ,-(sp); br error
  2944. e.range: mov $ERANGE,-(sp); br error
  2945. e.set: mov $ESET,-(sp); br error
  2946. e.badptr: mov $EBADPTR,-(sp); br fatal
  2947. e.fovfl: mov $EFOVFL,-(sp); br error
  2948. e.funfl: mov $EFUNFL,-(sp); br error
  2949. e.fdivz: mov $EFDIVZ,-(sp); br error
  2950. e.fund: mov $EFUND,-(sp); br error
  2951. e.conv: mov $ECONV,-(sp); br error
  2952. e.stack: mov $ESTACK,-(sp); br fatal
  2953. e.badpc: mov $EBADPC,-(sp); br fatal
  2954. e.badlin: mov $EBADLIN,-(sp); br error
  2955. e.badlae: mov $EBADLAE,-(sp); br error
  2956. e.array: mov $EARRAY,-(sp); br error
  2957. e.badmon: mov $EBADMON,-(sp); br error
  2958. e.case: mov $ECASE,-(sp); br fatal
  2959. e.oddz: mov $EODDZ,-(sp); br fatal
  2960. e.illins: mov $EILLINS,-(sp); br fatal
  2961. e.heap: mov $EHEAP,-(sp); br error
  2962. e.memflt: mov $EMEMFLT,-(sp); br fatal
  2963. e.badgto: mov $EBADGTO,-(sp); br error
  2964. /------------------------------------------------------------------------------
  2965. fatal: mov $hlt.z,-(sp) / return from fatal halts
  2966. mov 2(sp),-(sp) / dup error number
  2967. error:
  2968. jsr pc,savereg / save old register contents
  2969. cmp $16.,r0;
  2970. ble 9f;
  2971. mov $1,r1
  2972. ash r0,r1
  2973. bic ignmask,r1
  2974. bne 9f
  2975. jsr pc,restoreg
  2976. add $2,sp / remove error number from stack
  2977. rts pc
  2978. 9:
  2979. cmp uerrorp,$-1 / has the user defined a trapprocedure ?
  2980. beq notrap / if not kill it off fast
  2981. mov uerrorp,-(sp) / go for cal
  2982. mov $-1,uerrorp / user must set trap again
  2983. jbr precal / call trap routine
  2984. /------------------------------------------------------------------------------
  2985. rtt.z: mov r2,sp / sp to bottom frame
  2986. add $8,sp / set to top frame
  2987. jsr pc,restoreg / restore status and registers
  2988. add $2,sp / skip error number
  2989. rts pc
  2990. /------------------------------------------------------------------------------
  2991. trp.z: mov (sp),-(sp); / error number one down
  2992. mov r4,2(sp); / set return address to main loop
  2993. jbr error / call error routine
  2994. /------------------------------------------------------------------------------
  2995. notrap: mov (sp),r1 / error number
  2996. mov $num+9.,r0
  2997. mov r1,retarea / set error number for exit status
  2998. jsr pc,itoa / make string
  2999. mov $num,r0
  3000. rude_error:
  3001. mov r0,8f+4
  3002. mov *filb,8f / pointer to file name
  3003. mov *eb,r1 / line number
  3004. mov $line,8f+6 / line message
  3005. mov $line+21.,r0
  3006. jsr pc,itoa / convert to string
  3007. 1: mov $8f,r4
  3008. 2: mov (r4)+,r0 / next string
  3009. beq 5f
  3010. 3: mov r0,9f+2
  3011. 4: tstb (r0)+ / find zero byte
  3012. bne 4b
  3013. dec r0
  3014. sub 9f+2,r0 / string length
  3015. mov r0,9f+4
  3016. mov $2,r0 / diagnostic output
  3017. sys 0; 9f
  3018. jbr 2b
  3019. 5: / no file
  3020. mov $-1,argc
  3021. jbr hlt.z
  3022. itoa: mov r5,-(sp)
  3023. mov r0,r5
  3024. 1: clr r0
  3025. div $10.,r0
  3026. add $'0,r1
  3027. movb r1,-(r5)
  3028. mov r0,r1
  3029. bne 1b
  3030. mov r5,r0
  3031. mov (sp)+,r5
  3032. rts pc
  3033. .data
  3034. uerrorp: -1 / undefined trap procedure
  3035. sep: <: \0>
  3036. line: < on source line \n\0>
  3037. num: <error \0>
  3038. .even
  3039. 8: 0 / name of text file
  3040. sep / separator
  3041. 0 / error
  3042. line+21. / line number if present
  3043. 0 / end of list
  3044. lblwri:
  3045. 9: sys write;0;0
  3046. .text
  3047. /------------------------------------------------------------------------------
  3048. / Exit instruction, with all it's crud
  3049. /------------------------------------------------------------------------------
  3050. hlt.z:
  3051. mov (sp)+,retarea
  3052. .if .count + .flow + .prof
  3053. br 9f
  3054. .endif
  3055. bne 9f
  3056. clr r0
  3057. sys exit
  3058. 9:
  3059. lblhalt:
  3060. sys creat;1f;666
  3061. .data
  3062. 1: <em_runinf\0>
  3063. 2: <runinf file failed\n\0>
  3064. .even
  3065. .text
  3066. bec 2f
  3067. 3: mov $2b,lblwri+2
  3068. mov $19.,lblwri+4
  3069. mov $2.,r0
  3070. sys indir;lblwri
  3071. br 9f
  3072. 2: mov r0,saver0
  3073. mov $hp,r1
  3074. mov r1,ndatad
  3075. mov $txtsiz,r5
  3076. mov r5,txtsiz
  3077. sub r5,r1
  3078. mov r5,lblwri+2
  3079. mov r1,lblwri+4
  3080. clr r1
  3081. .if .last
  3082. add $1,r1
  3083. .endif
  3084. .if .opfreq
  3085. add $2,r1
  3086. .endif
  3087. .if .count
  3088. add $4,r1
  3089. .endif
  3090. .if .flow
  3091. add $8.,r1
  3092. .endif
  3093. .if .prof
  3094. add $16.,r1
  3095. .endif
  3096. mov r1,entry.
  3097. sys indir;lblwri
  3098. bes 3b
  3099. mov pd,lblwri+2
  3100. mov tblmax,lblwri+4
  3101. sub pd,lblwri+4
  3102. mov saver0,r0
  3103. sys indir;lblwri
  3104. bes 3b
  3105. mov ml,lblwri+2
  3106. mov ml,lblwri+4
  3107. neg lblwri+4
  3108. mov saver0,r0
  3109. sys indir;lblwri
  3110. bes 3b
  3111. 9:
  3112. mov retarea,r0 / set exit status
  3113. 2: sys exit
  3114. /------------------------------------------------------------------------------
  3115. / System call interface routine
  3116. /------------------------------------------------------------------------------
  3117. R0_IN = 0200
  3118. R1_IN = 0100
  3119. R0_OUT = 040
  3120. R1_OUT = 020
  3121. CBIT = 010
  3122. lblmon:
  3123. mon.z:
  3124. mov (sp)+,r0; / call number from stack
  3125. cmp r0,$1 / sys exit ?
  3126. jeq hlt.z / go there
  3127. bit $177700,r0; / range 0-63?
  3128. bne mon.bad; / no? bad call
  3129. movb r0,call; / move call number in system call
  3130. movb tab(r0),r5; / table lookup call conditions
  3131. cmp r5,$-1; / compare for special context
  3132. beq mon.special; / yes? jump to special context
  3133. monmon: mov r5,r4; / save call conditions
  3134. rolb r5 / R0_IN
  3135. bcc 1f / check if bit 7 is on
  3136. mov (sp)+,r0; / call argument in r0
  3137. 1: rolb r5 / R1_IN
  3138. bcc 1f / check if bit 6 is on
  3139. mov (sp)+,r1; / argument in r1
  3140. 1: bic $177770,r4 / clear all exept bits 2,1,0
  3141. beq 2f / if 0 forget about args
  3142. mov r3,saver1 / save r3
  3143. mov $call+2,r3 / base of args for call
  3144. 1: mov (sp)+,(r3)+ / move argument
  3145. sob r4,1b / look for more
  3146. mov saver1,r3 / restore r3
  3147. 2: sys indir;call / this is it folks
  3148. bcc 1f / no error set? forward
  3149. mov r0,r4 / copy error in r4
  3150. 1: rolb r5 / R0_OUT
  3151. bcc 1f / check original bit 5
  3152. mov r0,-(sp) / stack r0 from errno
  3153. 1: rolb r5 / R1_OUT
  3154. bcc 1f / check original bit 4
  3155. mov r1,-(sp) / stack r1
  3156. 1: rolb r5 / CBIT
  3157. bcc mon.end / no c-bit then ready
  3158. mon.cbit:
  3159. mov r4,-(sp) / stack errno
  3160. beq mon.end / only once if no error
  3161. mov r4,-(sp) / stack errno twice when error
  3162. mon.end:
  3163. mov $loop,r4 / restore r4
  3164. next / ready
  3165. mon.special: / special calls decoded here
  3166. cmp r0,$fork / fork?
  3167. beq mon.fork
  3168. cmp r0,$signal / signal?
  3169. beq mon.signal
  3170. mon.bad: / otherwise undecodable
  3171. mov saver0,r4 / restore r4
  3172. jsr pc,e.badmon / mon call error routine
  3173. next
  3174. mon.fork:
  3175. clr r5
  3176. clr r4
  3177. sys fork
  3178. inc r5
  3179. bcc 1f
  3180. mov r0,r4
  3181. 1: mov r0,-(sp)
  3182. mov r5,-(sp)
  3183. br mon.cbit
  3184. mon.signal:
  3185. msign:
  3186. mov (sp)+,r1 / trap number
  3187. mov (sp)+,r0 / signal number
  3188. cmp r0,$16. / only 1 - 16 legal
  3189. bhi sig.bad
  3190. mov r0,call+2 / move signal number into call
  3191. beq sig.bad / 0 illegal
  3192. asl r0 / make 2-32 and even
  3193. mov sig.trp-2(r0),r5 / previous trap number
  3194. cmp r1,$256. / values -1 and -2 special
  3195. bhis 1f
  3196. mov sig.adr-2(r0),r4 / zero label means illegal signal
  3197. bne 2f
  3198. sig.bad:
  3199. mov $EINVAL,r4 / bad signal
  3200. jbr mon.cbit / and continue
  3201. 1: cmp r1,$-3 / -2: reset default, -3: ignore
  3202. blo sig.bad
  3203. mov r1,r4 / trap number in r4
  3204. inc r4
  3205. inc r4 / -2 -> 0, -3 -> -1
  3206. 2: mov r1,sig.trp-2(r0) / new trap number
  3207. / -3 if ignored; -2 if default action
  3208. mov r4,call+4 / translated trap number in call
  3209. clr r4
  3210. sys indir;call
  3211. bcs sig.bad / unlikely to happen
  3212. asr r0 / special if old label odd
  3213. bcc 1f
  3214. mov $-3,r5 / set ignore signal
  3215. 1: mov r5,-(sp) / push trap number
  3216. jbr mon.cbit
  3217. .data
  3218. call: sys 0; 0; 0; 0; 0
  3219. sig.trp:
  3220. -2; -2; -2; -2; -2; -2; -2; -2
  3221. -2; -2; 21.; 25.; -2; -2; -2; -2
  3222. sig.adr:
  3223. sig1; sig2; sig3; 0; 0; 0; 0; sig8
  3224. 0; 0; sig11; sig12; sig13; sig14; sig15; sig16
  3225. tab:
  3226. .if V6
  3227. .byte -1 / 0 = indir
  3228. .byte -1 / 1 = exit
  3229. .byte -1 / 2 = fork
  3230. .byte 2 +R0_IN +R0_OUT +CBIT / 3 = read
  3231. .byte 2 +R0_IN +R0_OUT +CBIT / 4 = write
  3232. .byte 2 +R0_OUT +CBIT / 5 = open
  3233. .byte 0 +R0_IN +CBIT / 6 = close
  3234. .byte 0 +R0_OUT +R1_OUT +CBIT / 7 = wait
  3235. .byte 2 +R0_OUT +CBIT / 8 = creat
  3236. .byte 2 +CBIT / 9 = link
  3237. .byte 1 +CBIT / 10 = unlink
  3238. .byte 2 +CBIT / 11 = exec
  3239. .byte 1 +CBIT / 12 = chdir
  3240. .byte 0 +R0_OUT +R1_OUT / 13 = time
  3241. .byte 3 +CBIT / 14 = mknod
  3242. .byte 2 +CBIT / 15 = chmod
  3243. .byte 2 +CBIT / 16 = chown
  3244. .byte -1 / 17 = break
  3245. .byte 2 +CBIT / 18 = stat
  3246. .byte 2 +R0_IN +CBIT / 19 = seek
  3247. .byte 0 +R0_OUT / 20 = getpid
  3248. .byte 3 +CBIT / 21 = mount
  3249. .byte 1 +CBIT / 22 = umount
  3250. .byte 0 +R0_IN +CBIT / 23 = setuid
  3251. .byte 0 +R0_OUT / 24 = getuid
  3252. .byte 0 +R1_IN +R0_IN +CBIT / 25 = stime
  3253. .byte 3 +R0_IN +R0_OUT +CBIT / 26 = ptrace
  3254. .byte -1 / 27 = x
  3255. .byte 1 +R0_IN +CBIT / 28 = fstat
  3256. .byte -1 / 29 = x
  3257. .byte -1 / 30 = x
  3258. .byte 1 +R0_IN +CBIT / 31 = stty
  3259. .byte 1 +R0_IN +CBIT / 32 = gtty
  3260. .byte -1 / 33 = x
  3261. .byte 0 +R0_IN +CBIT / 34 = nice
  3262. .byte 0 +R0_IN / 35 = sleep
  3263. .byte 0 / 36 = sync
  3264. .byte 1 +R0_IN +CBIT / 37 = kill
  3265. .byte 0 +R0_OUT / 38 = csw
  3266. .byte -1 / 39 = x
  3267. .byte -1 / 40 = x
  3268. .byte 0 +R0_IN +R0_OUT +CBIT / 41 = dup
  3269. .byte 0 +R0_OUT +R1_OUT +CBIT / 42 = pipe
  3270. .byte 1 / 43 = times
  3271. .byte 4 / 44 = prof
  3272. .byte -1 / 45 = x
  3273. .byte 0 +R0_IN +CBIT / 46 = setgid
  3274. .byte 0 +R0_OUT / 47 = getgid
  3275. .byte -1 / 48 = signal
  3276. .byte -1 / 49 = reserved for USG
  3277. .byte -1 / 50 = reserved for USG
  3278. .byte -1 / 51 = x
  3279. .byte -1 / 52 = x
  3280. .byte -1 / 53 = x
  3281. .byte -1 / 54 = x
  3282. .byte -1 / 55 = x
  3283. .byte -1 / 56 = x
  3284. .byte -1 / 57 = x
  3285. .byte -1 / 58 = x
  3286. .byte -1 / 59 = x
  3287. .byte -1 / 60 = x
  3288. .byte -1 / 61 = x
  3289. .byte -1 / 62 = x
  3290. .byte -1 / 63 = x
  3291. .endif
  3292. .if VPLUS
  3293. .byte -1 / 0 = indir
  3294. .byte -1 / 1 = exit
  3295. .byte -1 / 2 = fork
  3296. .byte 2 +R0_IN +R0_OUT +CBIT / 3 = read
  3297. .byte 2 +R0_IN +R0_OUT +CBIT / 4 = write
  3298. .byte 2 +R0_OUT +CBIT / 5 = open
  3299. .byte 0 +R0_IN +CBIT / 6 = close
  3300. .byte 0 +R0_OUT +R1_OUT +CBIT / 7 = wait
  3301. .byte 2 +R0_OUT +CBIT / 8 = creat
  3302. .byte 2 +CBIT / 9 = link
  3303. .byte 1 +CBIT / 10 = unlink
  3304. .byte 2 +CBIT / 11 = exec
  3305. .byte 1 +CBIT / 12 = chdir
  3306. .byte 0 +R0_OUT +R1_OUT / 13 = time
  3307. .byte 3 +CBIT / 14 = mknod
  3308. .byte 2 +CBIT / 15 = chmod
  3309. .byte 2 +CBIT / 16 = chown
  3310. .byte -1 / 17 = break
  3311. .byte 2 +CBIT / 18 = stat
  3312. .byte 2 +R0_IN +CBIT / 19 = seek
  3313. .byte 0 +R0_OUT / 20 = getpid
  3314. .byte 3 +CBIT / 21 = mount
  3315. .byte 1 +CBIT / 22 = umount
  3316. .byte 0 +R0_IN +CBIT / 23 = setuid
  3317. .byte 0 +R0_OUT / 24 = getuid
  3318. .byte 0 +R1_IN +R0_IN +CBIT / 25 = stime
  3319. .byte 3 +R0_IN +R0_OUT +CBIT / 26 = ptrace
  3320. .byte 0 +R0_IN +R0_OUT / 27 = alarm
  3321. .byte 1 +R0_IN +CBIT / 28 = fstat
  3322. .byte 0 / 29 = pause
  3323. .byte -1 / 30 = x
  3324. .byte 1 +R0_IN +CBIT / 31 = stty
  3325. .byte 1 +R0_IN +CBIT / 32 = gtty
  3326. .byte 2 +CBIT / 33 = access
  3327. .byte 0 +R0_IN +CBIT / 34 = nice
  3328. .byte 0 +R0_IN / 35 = sleep
  3329. .byte 0 / 36 = sync
  3330. .byte 1 +R0_IN +CBIT / 37 = kill
  3331. .byte 0 +R0_OUT / 38 = csw
  3332. .byte -1 / 39 = x
  3333. .byte 0 +R0_IN +R0_OUT +R1_OUT +CBIT / 40 = tell
  3334. .byte 0 +R0_IN +R0_OUT +CBIT / 41 = dup
  3335. .byte 0 +R0_OUT +R1_OUT +CBIT / 42 = pipe
  3336. .byte 1 / 43 = times
  3337. .byte 4 / 44 = prof
  3338. .byte -1 / 45 = x
  3339. .byte 0 +R0_IN +CBIT / 46 = setgid
  3340. .byte 0 +R0_OUT / 47 = getgid
  3341. .byte -1 / 48 = signal
  3342. .byte -1 / 49 = reserved for USG
  3343. .byte -1 / 50 = reserved for USG
  3344. .byte 1 +CBIT / 51 = acct
  3345. .byte -1 / 52 = x
  3346. .byte -1 / 53 = x
  3347. .byte -1 / 54 = x
  3348. .byte -1 / 55 = x
  3349. .byte -1 / 56 = x
  3350. .byte -1 / 57 = x
  3351. .byte -1 / 58 = x
  3352. .byte -1 / 59 = x
  3353. .byte -1 / 60 = x
  3354. .byte -1 / 61 = x
  3355. .byte -1 / 62 = x
  3356. .byte -1 / 63 = x
  3357. .endif
  3358. .if V7
  3359. .byte -1 / 0 = indir
  3360. .byte 0 / 1 = exit
  3361. .byte -1 / 2 = fork
  3362. .byte 2 +R0_IN +R0_OUT +CBIT / 3 = read
  3363. .byte 2 +R0_IN +R0_OUT +CBIT / 4 = write
  3364. .byte 2 +R0_OUT +CBIT / 5 = open
  3365. .byte 0 +R0_IN +CBIT / 6 = close
  3366. .byte 0 +R0_OUT +R1_OUT +CBIT / 7 = wait
  3367. .byte 2 +R0_OUT +CBIT / 8 = creat
  3368. .byte 2 +CBIT / 9 = link
  3369. .byte 1 +CBIT / 10 = unlink
  3370. .byte -1 / 11 = x no exec in em code
  3371. .byte 1 +CBIT / 12 = chdir
  3372. .byte -1 / 13 = x time is obsolete
  3373. .byte 3 +CBIT / 14 = mknod
  3374. .byte 2 +CBIT / 15 = chmod
  3375. .byte 3 +CBIT / 16 = chown
  3376. .byte -1 / 17 = break
  3377. .byte 2 +CBIT / 18 = stat
  3378. .byte 3 +R0_IN +R0_OUT +R1_OUT +CBIT / 19 = lseek
  3379. .byte 0 +R0_OUT / 20 = getpid
  3380. .byte 3 +CBIT / 21 = mount
  3381. .byte 1 +CBIT / 22 = umount
  3382. .byte 0 +R0_IN +CBIT / 23 = setuid
  3383. .byte 0 +R0_OUT +R1_OUT / 24 = getuid
  3384. .byte 0 +R1_IN +R0_IN +CBIT / 25 = stime
  3385. .byte 3 +R0_IN +R0_OUT +CBIT / 26 = ptrace
  3386. .byte 0 +R0_IN +R0_OUT / 27 = alarm
  3387. .byte 1 +R0_IN +CBIT / 28 = fstat
  3388. .byte 0 / 29 = pause
  3389. .byte 2 +CBIT / 30 = utime
  3390. .byte -1 / 31 = x
  3391. .byte -1 / 32 = x
  3392. .byte 2 +CBIT / 33 = access
  3393. .byte 0 +R0_IN +CBIT / 34 = nice
  3394. .byte 1 / 35 = ftime
  3395. .byte 0 / 36 = sync
  3396. .byte 1 +R0_IN +CBIT / 37 = kill
  3397. .byte -1 / 38 = x
  3398. .byte -1 / 39 = x
  3399. .byte -1 / 40 = x
  3400. .byte 0 +R1_IN +R0_IN +R0_OUT +CBIT / 41 = dup
  3401. .byte 0 +R0_OUT +R1_OUT +CBIT / 42 = pipe
  3402. .byte 1 / 43 = times
  3403. .byte 4 / 44 = prof
  3404. .byte -1 / 45 = x
  3405. .byte 0 +R0_IN +CBIT / 46 = setgid
  3406. .byte 0 +R0_OUT +R1_OUT / 47 = getgid
  3407. .byte -1 / 48 = signal
  3408. .byte -1 / 49 = reserved for USG
  3409. .byte -1 / 50 = reserved for USG
  3410. .byte 1 +CBIT / 51 = acct
  3411. .byte 3 +CBIT / 52 = phys
  3412. .byte 1 +CBIT / 53 = lock
  3413. .byte 3 +CBIT / 54 = ioctl
  3414. .byte -1 / 55 = x
  3415. .byte 2 +CBIT / 56 = mpxcall
  3416. .byte -1 / 57 = x
  3417. .byte -1 / 58 = x
  3418. .byte 3 +CBIT / 59 = exece
  3419. .byte 1 +CBIT / 60 = umask
  3420. .byte 1 +CBIT / 61 = chroot
  3421. .byte -1 / 62 = x
  3422. .byte -1 / 63 = x
  3423. .endif
  3424. .text
  3425. /------------------------------------------------------------------------------
  3426. / General subroutines
  3427. /------------------------------------------------------------------------------
  3428. wrdoff: movb (pcx)+,r0 /get first byte
  3429. swab r0 /put it in high byte
  3430. clrb r0 /clear low byte of r0
  3431. bisb (pcx)+,r0 /"or" second byte in
  3432. rts pc /done
  3433. /------------------------------------------------------------------------------
  3434. tstr0: cmp r0,$04; jgt e.oddz;
  3435. cmp r0,$02; jne e.oddz; rts pc
  3436. chckptr: / this routine traps a pointer outside
  3437. / the globals, the stack or the heap
  3438. bit $1,2(sp); bne 8f
  3439. chckptb:
  3440. mov 2(sp),r5;
  3441. cmp r5,sp; bhis 9f
  3442. cmp r5,hp; bhis 8f
  3443. .if .count + .prof + .flow
  3444. cmp r5,tblmax; bhis 9f
  3445. cmp r5,globmax; bhis 8f
  3446. .endif
  3447. cmp r5,eb; bhis 9f
  3448. 8: jsr pc,e.badptr
  3449. 9: rts pc
  3450. .if .last
  3451. nexttab: mov linused,r5;
  3452. add $2,r5 / increment lasttab
  3453. cmp r5,$linused / top of table reached?
  3454. blo 1f
  3455. sub $96.,r5
  3456. 1: mov r5,linused
  3457. rts pc
  3458. .endif
  3459. regsave:
  3460. mov r5,savearea
  3461. mov $[savearea+2],r5
  3462. mov r4,(r5)+
  3463. mov r3,(r5)+
  3464. mov r2,(r5)
  3465. rts pc
  3466. regretu:
  3467. mov $[savearea+6],r5
  3468. mov (r5),r2
  3469. mov -(r5),r3
  3470. mov -(r5),r4
  3471. mov -(r5),r5
  3472. rts pc
  3473. setfloat:
  3474. cmp r0,$8.
  3475. bne 1f
  3476. setd
  3477. rts pc
  3478. 1: cmp r0,$04
  3479. bne 3f
  3480. setf
  3481. 2: rts pc
  3482. 3: jmp e.oddz
  3483. setint:
  3484. cmp r0,$04
  3485. bne 4f
  3486. setl
  3487. rts pc
  3488. 4: cmp r0,$02
  3489. bne 3b
  3490. seti
  3491. 5: rts pc
  3492. /------------------------------------------------------------------------------
  3493. / Leftover data
  3494. /------------------------------------------------------------------------------
  3495. .bss
  3496. filb: .=.+2
  3497. curproc:.=.+2
  3498. linmax: .=.+2
  3499. countptr:.=.+2
  3500. countfld:.=.+2
  3501. hiprof: .=.+2
  3502. loprof: .=.+2
  3503. ignmask:.=.+2 / ignore mask for trap
  3504. retsize:.=.+2 / size of return value of function
  3505. retarea:.=.+8 / return area for function value
  3506. savearea: .=.+8 / save register area
  3507. saver0: .=.+2
  3508. saver1: .=.+2
  3509. header:
  3510. txtsiz: .=.+2 / program textsize in bytes
  3511. ndatad: .=.+2 / number of loadfile descriptors
  3512. nprocs: .=.+2 / number of entries in procedure descriptors
  3513. option: entry.: .=.+2 / procedure number to start
  3514. nlines: .=.+2 / maximum sorceline number
  3515. szdata: .=.+2 / address of lowest uninitialized byte
  3516. firstp: .=.+2 / descriptor address first basic block of text
  3517. maxcount: .=.+2 / total number of processable source lines
  3518. argc: .=.+2
  3519. argv: .=.+2
  3520. environ:
  3521. .=.+2
  3522. pb: .=.+2
  3523. pd: .=.+2
  3524. eb: .=.+2
  3525. globmax:
  3526. .=.+2
  3527. tblmax: .=.+2
  3528. ml: .=.+2
  3529. .if .last
  3530. lasttab:.=.+96. / 16 descriptors of integers + index at the end
  3531. linused:.=.+2
  3532. .endif
  3533. .if .opfreq
  3534. counttab:
  3535. .=.+1664.
  3536. .endif
  3537. .if .count
  3538. lcount: .=.+2
  3539. countsiz:.=.+2
  3540. .endif
  3541. .if .flow
  3542. lflow: .=.+2
  3543. flowsiz:.=.+2
  3544. .endif
  3545. .if .prof
  3546. ltime: .=.+2
  3547. profsiz:.=.+2
  3548. .endif
  3549. hp: .=.+2