1: /* `alloca' standard 4.2 subroutine for 68000's and 16000's and pyramids. 2: Also has _setjmp and _longjmp for pyramids. 3: Also has hack_sky for sun 2. 4: Copyright (C) 1985 Richard M. Stallman. 5: 6: This file is part of GNU Emacs. 7: 8: GNU Emacs is distributed in the hope that it will be useful, 9: but WITHOUT ANY WARRANTY. No author or distributor 10: accepts responsibility to anyone for the consequences of using it 11: or for whether it serves any particular purpose or works at all, 12: unless he says so in writing. Refer to the GNU Emacs General Public 13: License for full details. 14: 15: Everyone is granted permission to copy, modify and redistribute 16: GNU Emacs, but only under the conditions described in the 17: GNU Emacs General Public License. A copy of this license is 18: supposed to have been given to you along with GNU Emacs so you 19: can know your rights and responsibilities. It should be in a 20: file named COPYING. Among other things, the copyright notice 21: and this notice must be preserved on all copies. */ 22: 23: 24: /* Both 68000 systems I have run this on have had broken versions of alloca. 25: Also, I am told that non-berkeley systems do not have it at all. 26: So replace whatever system-provided alloca there may be 27: on all 68000 systems. */ 28: 29: #include "config.h" 30: 31: #ifndef HAVE_ALLOCA /* define this to use system's alloca */ 32: 33: #ifdef hp9000s200 34: data 35: text 36: globl _alloca 37: _alloca 38: move.l (sp)+,a0 ; pop return addr from top of stack 39: move.l (sp)+,d0 ; pop size in bytes from top of stack 40: add.l #ROUND,d0 ; round size up to long word 41: and.l #MASK,d0 ; mask out lower two bits of size 42: sub.l d0,sp ; allocate by moving stack pointer 43: tst.b PROBE(sp) ; stack probe to allocate pages 44: move.l sp,d0 ; return pointer 45: add.l #-4,sp ; new top of stack 46: jmp (a0) ; not a normal return 47: MASK equ -4 ; Longword alignment 48: ROUND equ 3 ; ditto 49: PROBE equ -128 ; safety buffer for C compiler scratch 50: data 51: 52: #else 53: #ifdef m68k /* SGS assembler totally different */ 54: file "alloca.s" 55: global alloca 56: alloca: 57: mov.l (%sp)+,%a1 # pop return addr from top of stack 58: mov.l (%sp)+,%d0 # pop size in bytes from top of stack 59: add.l &R%1,%d0 # round size up to long word 60: and.l &-4,%d0 # mask out lower two bits of size 61: sub.l %d0,%sp # allocate by moving stack pointer 62: tst.b P%1(%sp) # stack probe to allocate pages 63: mov.l %sp,%a0 # return pointer as pointer 64: mov.l %sp,%d0 # return pointer as int to avoid disaster 65: add.l &-4,%sp # new top of stack 66: jmp (%a1) # not a normal return 67: set S%1,64 # safety factor for C compiler scratch 68: set R%1,3+S%1 # add to size for rounding 69: set P%1,-132 # probe this far below current top of stack 70: 71: #else /* not m68k */ 72: 73: #ifdef m68000 74: 75: /* Some systems want the _, some do not. Win with both kinds. */ 76: .globl _alloca 77: _alloca: 78: .globl alloca 79: alloca: 80: movl sp@+,a0 81: movl a7,d0 82: subl sp@,d0 83: andl #~3,d0 84: movl d0,sp 85: tstb sp@(0) /* Make stack pages exist */ 86: /* Needed on certain systems 87: that lack true demand paging */ 88: addql #4,d0 89: jmp a0@ 90: 91: #endif /* m68000 */ 92: #endif /* not m68k */ 93: #endif /* not hp9000s200 */ 94: 95: #ifdef ns16000 96: 97: .text 98: .align 2 99: /* Some systems want the _, some do not. Win with both kinds. */ 100: .globl _alloca 101: _alloca: 102: .globl alloca 103: alloca: 104: 105: /* Two different assembler syntaxes are used for the same code 106: on different systems. */ 107: 108: #ifdef sequent 109: #define IM 110: #define REGISTER(x) x 111: #else 112: #define IM $ 113: #define REGISTER(x) 0(x) 114: #endif 115: 116: /* 117: * The ns16000 is a little more difficult, need to copy regs. 118: * Also the code assumes direct linkage call sequence (no mod table crap). 119: * We have to copy registers, and therefore waste 32 bytes. 120: * 121: * Stack layout: 122: * new sp -> junk 123: * registers (copy) 124: * r0 -> new data 125: * | (orig retval) 126: * | (orig arg) 127: * old sp -> regs (orig) 128: * local data 129: * fp -> old fp 130: */ 131: 132: movd tos,r1 /* pop return addr */ 133: negd tos,r0 /* pop amount to allocate */ 134: sprd sp,r2 135: addd r2,r0 136: bicb IM/**/3,r0 /* 4-byte align */ 137: lprd sp,r0 138: adjspb IM/**/36 /* space for regs, +4 for caller to pop */ 139: movmd 0(r2),4(sp),IM/**/4 /* copy regs */ 140: movmd 0x10(r2),0x14(sp),IM/**/4 141: jump REGISTER(r1) /* funky return */ 142: #endif /* ns16000 */ 143: 144: #ifdef pyramid 145: 146: .globl _alloca 147: 148: _alloca: addw $3,pr0 # add 3 (dec) to first argument 149: bicw $3,pr0 # then clear its last 2 bits 150: subw pr0,sp # subtract from SP the val in PR0 151: movw sp,pr0 # ret. current SP 152: ret 153: 154: .globl __longjmp 155: .globl _longjmp 156: .globl __setjmp 157: .globl _setjmp 158: 159: __longjmp: jump _longjmp 160: __setjmp: jump _setjmp 161: 162: #endif /* pyramid */ 163: 164: #ifdef ATT3B5 165: 166: .align 4 167: .globl alloca 168: 169: alloca: 170: movw %ap, %r8 171: subw2 $9*4, %r8 172: movw 0(%r8), %r1 /* pc */ 173: movw 4(%r8), %fp 174: movw 8(%r8), %sp 175: addw2 %r0, %sp /* make room */ 176: movw %sp, %r0 /* return value */ 177: jmp (%r1) /* continue... */ 178: 179: #endif /* ATT3B5 */ 180: 181: /* 182: A Hack to reinitialize the floating point table in C or Fortran 183: code. 184: There are no arguments to the call 185: 186: David Robinson 187: Jet Propulsion Laboratory 188: ia-sun2!david@cit-vax.arpa 189: 190: WARNING: Very SUN dependant Only tested under SUN 2.0 191: */ 192: #ifdef sun2 193: .globl _hack_sky 194: 195: _hack_sky: 196: moveml #0xC0C0,sp@- |save registers <d0,d1,a0,a1> 197: clrl __skybase |clear out old sky status 198: jsr __skyinit |initialize sky board 199: tstl d0 |check if successful 200: lea floatflavor,a1 201: beqs hack1 202: lea a1@(0x7e),a0 |Sky board exists 203: bras hack2 204: hack1: lea a1@(0x12),a0 |No Sky board 205: hack2: movw #0x1a,d0 206: lea fvflti,a1 |load destination 207: hack3: movl a0@+,a1@+ |copy table 208: dbra d0,hack3 209: moveml sp@+,#0x0303 |restore registers 210: rts 211: #endif /* sun2 */ 212: 213: #endif /* not HAVE_ALLOCA */