1: / fp1 -- floating point simulator 2: 3: rti = 2 4: bpt = 3 5: iot = 4 6: emt = 104000 7: 8: m.ext = 200 / long mode bit 9: m.lngi = 100 / long integer mode 10: 11: 12: .globl fptrap 13: .globl ac0, ac1, ac2, ac3 14: 15: fptrap: 16: dec reenter 17: bge 1f 18: iot / reentered! 19: 1: 20: mov (sp)+,spc 21: mov (sp)+,sps 22: mov r0,sr0 23: mov $sr1,r0 24: mov r1,(r0)+ 25: mov r2,(r0)+ 26: mov r3,(r0)+ 27: mov r4,(r0)+ 28: mov r5,(r0)+ 29: mov sp,(r0)+ 30: mov (r0),r5 / pc 31: 32: 33: mov r1, tr1 / save r1 34: mov r5,r1 / put pc in r1 35: dec r1 36: dec r1 37: mov $-1, r0 / -1 in r0 38: emt / instruction at (r1) is magically 39: mov r0,r5 / returned in r0 40: mov tr1, r1 / restore r1 41: 42: again: 43: sub $8,sp / room for double push 44: clr trapins 45: mov r5,r4 46: bic $7777,r4 47: cmp r4,$170000 48: beq 1f 49: jmp badins 50: 1: 51: bic $100000,fpsr / clear fp error 52: bic $170000,r5 53: mov r5,r4 54: bit $7000,r4 55: bne class3 56: bit $700,r4 57: bne class2 58: cmp r4,$12 59: blos 1f 60: jmp badins 61: 1: 62: asl r4 63: jmp *1f(r4) 64: 65: .data 66: 1: 67: i.cfcc / 170000 68: i.setf / 170001 69: i.seti / 170002 70: badins 71: badins 72: badins 73: badins 74: badins 75: badins 76: i.setd / 170011 77: i.setl / 170012 78: .text 79: 80: class2: 81: cmp r5,$400 82: bge 1f 83: mov $9f,r1 84: jsr pc,fsrc 85: br 2f 86: 87: .data 88: 9: mod0rx; mod242 89: .text 90: 91: 1: 92: mov $9f,r1 93: jsr pc,fsrc 94: 95: .data 96: 9: mod0f; mod24f 97: .text 98: 99: 2: 100: mov r3,r5 101: asl r4 102: asl r4 103: clrb r4 104: swab r4 105: asl r4 106: jsr pc,*1f(r4) 107: jmp sret 108: 109: .data 110: 1: 111: badins / 1700xx 112: i.ldfps / 1701xx 113: i.stfps / 1702xx 114: badins / 1703xx - stst 115: i.clrx / 1704xx 116: i.tstx / 1705xx 117: i.absx / 1706xx 118: i.negx / 1707xx 119: .text 120: 121: class3: 122: cmp r5,$5000 123: blt 1f 124: mov r5,r2 125: clrb r2 126: cmp r2,$6400 127: blt 2f 128: sub $1400,r2 129: 2: 130: cmp r2,$5000 131: bne 2f 132: mov $9f,r1 133: jsr pc,fsrc 134: 135: .data 136: 9: mod0rx; mod242 137: .text 138: 139: br 3f 140: 2: 141: cmp r2,$5400 142: bne 2f 143: mov $9f,r1 144: jsr pc,fsrc 145: br 3f 146: 147: .data 148: 9: mod0ra; mod24i 149: .text 150: 151: 2: 152: mov $9f,r1 153: jsr pc,fsrc 154: br 3f 155: 156: .data 157: 9: mod0f; mod24d 158: .text 159: 160: 1: 161: mov $9f,r1 162: jsr pc,fsrc 163: 164: .data 165: 9: mod0f; mod24f 166: .text 167: 168: 3: 169: jsr pc,freg 170: mov r2,r5 171: clrb r4 172: swab r4 173: asl r4 174: jsr pc,*1f(r4) 175: br sret 176: 177: .data 178: 1: 179: badins / 1700xx 180: badins / 1704xx 181: i.mulx / 1710xx 182: i.modx / 1714xx 183: i.addx / 1720xx 184: i.ldx / 1724xx 185: i.subx / 1730xx 186: i.cmpx / 1734xx 187: i.stx / 1740xx 188: i.divx / 1744xx 189: i.stexp / 1750xx 190: i.stcxj / 1754xx 191: i.stcxy / 1760xx 192: i.ldexp / 1764xx 193: i.ldcjx / 1770xx 194: i.ldcyx / 1774xx 195: .text 196: 197: i.cfcc: 198: mov fpsr,r0 199: bic $!17,r0 200: mov r0,sps 201: br ret 202: 203: i.setf: 204: bic $m.ext,fpsr 205: br ret 206: 207: i.setd: 208: bis $m.ext,fpsr 209: br ret 210: 211: i.seti: 212: bic $m.lngi,fpsr 213: br ret 214: 215: i.setl: 216: bis $m.lngi,fpsr 217: br ret 218: 219: badins: 220: inc trapins 221: br ret1 222: 223: sret: 224: mov $fpsr,r0 225: bic $17,(r0) 226: tstb 1(r5) 227: bpl 1f 228: bis $10,(r0) 229: br ret 230: 1: 231: bne ret 232: bis $4,(r0) 233: 234: ret: 235: mov ssp,sp 236: 237: mov r1, tr1 / save r1 238: mov spc,r1 / put pc in r1 239: mov $-1, r0 / -1 in r0 240: emt / instruction at (r1) is magically 241: mov r0,r5 / returned in r0 242: mov tr1, r1 / restore r1 243: 244: cmp r5,$170000 245: blo ret1 246: add $2,spc 247: jbr again / if another fp, save trap 248: 249: ret1: 250: mov $sr1,r0 251: mov (r0)+,r1 252: mov (r0)+,r2 253: mov (r0)+,r3 254: mov (r0)+,r4 255: mov (r0)+,r5 256: mov (r0)+,sp 257: mov sr0,r0 258: mov sps,-(sp) 259: mov spc,-(sp) 260: tst trapins 261: bne 1f 262: inc reenter 263: rti 264: 1: 265: bpt 266: 267: freg: 268: mov r5,r2 269: bic $!300,r2 270: asr r2 271: asr r2 272: asr r2 273: add $ac0,r2 274: rts pc 275: 276: fsrc: 277: mov r5,r3 278: bic $!7,r3 / register 279: asl r3 280: add $sr0,r3 281: mov r5,r0 282: bic $!70,r0 / mode 283: asr r0 284: asr r0 285: jmp *1f(r0) 286: 287: .data 288: 1: 289: mod0 290: mod1 291: mod2 292: mod3 293: mod4 294: mod5 295: mod6 296: mod7 297: .text 298: 299: mod24f: 300: mov $4,r0 301: bit $m.ext,fpsr 302: beq 1f 303: add $4,r0 304: 1: 305: rts pc 306: 307: mod24d: 308: mov $8,r0 309: bit $m.ext,fpsr 310: beq 1f 311: sub $4,r0 312: 1: 313: rts pc 314: 315: mod242: 316: mov $2,r0 317: rts pc 318: 319: mod24i: 320: mov $2,r0 321: bit $m.lngi,fpsr 322: beq 1f 323: add $2,r0 324: 1: 325: rts pc 326: 327: mod0: 328: jmp *(r1)+ 329: 330: mod0f: 331: sub $sr0,r3 / get fp ac 332: cmp r3,$6*2 333: bhis badi1 334: asl r3 335: asl r3 336: add $ac0,r3 337: rts pc 338: 339: mod0ra: 340: bit $m.lngi,fpsr 341: bne badi1 342: 343: mod0r: 344: cmp r3,$ssp 345: bhis badi1 346: mod0rx: 347: rts pc 348: 349: mod1: 350: cmp r3,$spc 351: beq badi1 352: mov (r3),r3 353: br check 354: 355: mod2: 356: mov (r3),-(sp) 357: jsr pc,*2(r1) 358: 359: cmp r3,$spc 360: bne 1f 361: mov $2,r0 362: 363: 364: mov r0,tr0 365: mov r1, tr1 / save r1 366: mov (r3),r1 / put pc in r1 367: mov $-1, r0 / -1 in r0 368: emt / instruction at (r1) is magically 369: mov r0,pctmp / returned in r0 370: mov tr1, r1 / restore r1 371: mov tr0,r0 372: 373: mov $pctmp,(sp) 374: 1: 375: add r0,(r3) 376: mov (sp)+,r3 377: br check 378: 379: mod3: 380: / doesn't handle PC absolute mode 381: mov *(r3),-(sp) 382: add $2,(r3) 383: mov (sp)+,r3 384: br check 385: 386: mod4: 387: cmp r3,$spc / test pc 388: beq badi1 389: jsr pc,*2(r1) 390: 391: sub r0,(r3) 392: mov (r3),r3 393: br check 394: 395: mod5: 396: cmp r3,$spc 397: beq badi1 398: sub $2,(r3) 399: mov *(r3),r3 400: br check 401: 402: mod6: 403: 404: mov r1, tr1 / save r1 405: mov spc,r1 / put pc in r1 406: mov $-1, r0 / -1 in r0 407: emt / instruction at (r1) is magically 408: mov r0,-(sp) / returned in r0 409: mov tr1, r1 / restore r1 410: 411: add $2,spc 412: add (r3),(sp) 413: mov (sp)+,r3 414: br check 415: 416: mod7: 417: jsr pc,mod6 418: mov (r3),r3 419: br check 420: 421: badi1: 422: jmp badins 423: 424: check: 425: bit $1,r3 426: bne badi1 427: rts pc 428: 429: setab: 430: mov $asign,r0 431: jsr pc,seta 432: mov r3,r2 433: mov $bsign,r0 434: 435: seta: 436: clr (r0) 437: mov (r2)+,r1 438: mov r1,-(sp) 439: beq 1f 440: blt 2f 441: inc (r0)+ 442: br 3f 443: 2: 444: dec (r0)+ 445: 3: 446: bic $!177,r1 447: bis $200,r1 448: br 2f 449: 1: 450: clr (r0)+ 451: 2: 452: mov r1,(r0)+ 453: mov (r2)+,(r0)+ 454: bit $m.ext,fpsr 455: beq 2f 456: mov (r2)+,(r0)+ 457: mov (r2)+,(r0)+ 458: br 3f 459: 2: 460: clr (r0)+ 461: clr (r0)+ 462: 3: 463: mov (sp)+,r1 464: asl r1 465: clrb r1 466: swab r1 467: sub $200,r1 468: mov r1,(r0)+ / exp 469: rts pc 470: 471: norm: 472: mov $areg,r0 473: mov (r0)+,r1 474: mov r1,-(sp) 475: mov (r0)+,r2 476: bis r2,(sp) 477: mov (r0)+,r3 478: bis r3,(sp) 479: mov (r0)+,r4 480: bis r4,(sp)+ 481: bne 1f 482: clr asign 483: rts pc 484: 1: 485: bit $!377,r1 486: beq 1f 487: clc 488: ror r1 489: ror r2 490: ror r3 491: ror r4 492: inc (r0) 493: br 1b 494: 1: 495: bit $200,r1 496: bne 1f 497: asl r4 498: rol r3 499: rol r2 500: rol r1 501: dec (r0) 502: br 1b 503: 1: 504: mov r4,-(r0) 505: mov r3,-(r0) 506: mov r2,-(r0) 507: mov r1,-(r0) 508: rts pc