1: / C register save and restore -- version 7/75 2: / modified by wnj && cbh 6/79 for overlaid text registers 3: / modified by wf jolitz 2/80 to work and use emt syscall 4: / modified for 8-byte thunk, mjk 10/81 5: / 6: 7: .globl csv 8: .globl cret 9: .globl __ovno 10: .globl _etext 11: .data 12: __ovno: 0 13: .text 14: 15: emt= 0104000 / overlays switched by emulator trap. ovno in r0. 16: 17: / ovhndlr1 through ovhndlr7 are called from the thunks after 18: / r1 is set to the location of the first instruction in the subroutine 19: / after the call to csv (~foo+4). They in turn branch to ovhndlr 20: / which sets the overlay and simulates a csv. 21: / Thus, the subroutine's call to csv is bypassed. 22: 23: .globl ovhndlr1, ovhndlr2, ovhndlr3, ovhndlr4, ovhndlr5, ovhndlr6, ovhndlr7 24: 25: ovhndlr1: 26: mov $1,r0 27: br ovhndlr 28: 29: ovhndlr2: 30: mov $2,r0 31: br ovhndlr 32: 33: ovhndlr3: 34: mov $3,r0 35: br ovhndlr 36: 37: ovhndlr4: 38: mov $4,r0 39: br ovhndlr 40: 41: ovhndlr5: 42: mov $5,r0 43: br ovhndlr 44: 45: ovhndlr6: 46: mov $6,r0 47: br ovhndlr 48: 49: ovhndlr7: 50: mov $7,r0 51: br ovhndlr 52: 53: ovhndlr: 54: cmp r0,__ovno 55: beq 1f 56: emt 57: 1: mov sp,r5 58: mov __ovno,-(sp) 59: mov r0,__ovno 60: mov r4,-(sp) 61: mov r3,-(sp) 62: mov r2,-(sp) 63: jsr pc,(r1) / jsr part is sub $2,sp 64: 65: / csv for routines called directly (in base or intra-overlay calls). 66: / no overlays have been changed, so we just save the previous overlay 67: / number on the stack. note that r0 isn't set to the current overlay 68: / because we weren't called through a thunk. 69: csv: 70: mov r5,r1 71: mov sp,r5 72: mov __ovno,-(sp) / overlay is extra (first) word in mark 73: / rest is old code common with csv 74: mov r4,-(sp) 75: mov r3,-(sp) 76: mov r2,-(sp) 77: jsr pc,(r1) / jsr part is sub $2,sp 78: / 79: / at this point, the stack frame looks like this: 80: / 81: / _________________________ 82: / | return addr to callee| 83: / |_______________________| 84: / r5-> | old r5 | 85: / |_______________________| 86: / | previous ovnumber | 87: / |_______________________| 88: / | old r4 | 89: / |_______________________| 90: / | old r3 | 91: / |_______________________| 92: / sp-> | old r2 | 93: / |_______________________| 94: / 95: 96: 97: cret: 98: mov r5,r2 99: / get the overlay out of the mark, and if it is non-zero 100: / make sure it is the currently loaded one 101: mov -(r2),r4 102: bne 1f / zero is easy 103: 2: 104: mov -(r2),r4 105: mov -(r2),r3 106: mov -(r2),r2 107: mov r5,sp 108: mov (sp)+,r5 109: rts pc 110: / not returning to root segment, so check that the right 111: / overlay is loaded, and if not ask UNIX for help 112: 1: 113: cmp r4,__ovno 114: beq 2b / lucked out! 115: / if return address is in root segment, then nothing to do 116: cmp 2(r5),$_etext 117: blos 2b 118: / returning to wrong overlay --- do something! 119: mov r0,r3 120: mov r4,r0 121: emt 122: mov r4,__ovno 123: mov r3,r0 124: / intr. routines may run between these, so should force segment __ovno 125: br 2b