Hex Artifact Content
Not logged in

Artifact 376a75f35dd83bbd0e9588391c50ef77179a24af:


0000: 2f 2a 20 3d 3d 3d 2d 2d 2d 2d 2d 20 74 72 61 6d  /* ===----- tram
0010: 70 6f 6c 69 6e 65 5f 73 65 74 75 70 2e 63 20 2d  poline_setup.c -
0020: 20 49 6d 70 6c 65 6d 65 6e 74 20 5f 5f 74 72 61   Implement __tra
0030: 6d 70 6f 6c 69 6e 65 5f 73 65 74 75 70 20 2d 2d  mpoline_setup --
0040: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 3d 3d 3d 0a 20  -----------===. 
0050: 2a 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 20  *. *            
0060: 20 20 20 20 20 20 20 20 20 54 68 65 20 4c 4c 56           The LLV
0070: 4d 20 43 6f 6d 70 69 6c 65 72 20 49 6e 66 72 61  M Compiler Infra
0080: 73 74 72 75 63 74 75 72 65 0a 20 2a 0a 20 2a 20  structure. *. * 
0090: 54 68 69 73 20 66 69 6c 65 20 69 73 20 64 75 61  This file is dua
00a0: 6c 20 6c 69 63 65 6e 73 65 64 20 75 6e 64 65 72  l licensed under
00b0: 20 74 68 65 20 4d 49 54 20 61 6e 64 20 74 68 65   the MIT and the
00c0: 20 55 6e 69 76 65 72 73 69 74 79 20 6f 66 20 49   University of I
00d0: 6c 6c 69 6e 6f 69 73 20 4f 70 65 6e 0a 20 2a 20  llinois Open. * 
00e0: 53 6f 75 72 63 65 20 4c 69 63 65 6e 73 65 73 2e  Source Licenses.
00f0: 20 53 65 65 20 4c 49 43 45 4e 53 45 2e 54 58 54   See LICENSE.TXT
0100: 20 66 6f 72 20 64 65 74 61 69 6c 73 2e 0a 20 2a   for details.. *
0110: 0a 20 2a 20 3d 3d 3d 2d 2d 2d 2d 2d 2d 2d 2d 2d  . * ===---------
0120: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0130: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0140: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0150: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 3d 3d 3d  -------------===
0160: 0a 20 2a 2f 0a 0a 23 69 6e 63 6c 75 64 65 20 22  . */..#include "
0170: 69 6e 74 5f 6c 69 62 2e 68 22 0a 0a 65 78 74 65  int_lib.h"..exte
0180: 72 6e 20 76 6f 69 64 20 5f 5f 63 6c 65 61 72 5f  rn void __clear_
0190: 63 61 63 68 65 28 76 6f 69 64 2a 20 73 74 61 72  cache(void* star
01a0: 74 2c 20 76 6f 69 64 2a 20 65 6e 64 29 3b 0a 0a  t, void* end);..
01b0: 2f 2a 0a 20 2a 20 54 68 65 20 70 70 63 20 63 6f  /*. * The ppc co
01c0: 6d 70 69 6c 65 72 20 67 65 6e 65 72 61 74 65 73  mpiler generates
01d0: 20 63 61 6c 6c 73 20 74 6f 20 5f 5f 74 72 61 6d   calls to __tram
01e0: 70 6f 6c 69 6e 65 5f 73 65 74 75 70 28 29 20 77  poline_setup() w
01f0: 68 65 6e 20 63 72 65 61 74 69 6e 67 20 0a 20 2a  hen creating . *
0200: 20 74 72 61 6d 70 6f 6c 69 6e 65 20 66 75 6e 63   trampoline func
0210: 74 69 6f 6e 73 20 6f 6e 20 74 68 65 20 73 74 61  tions on the sta
0220: 63 6b 20 66 6f 72 20 75 73 65 20 77 69 74 68 20  ck for use with 
0230: 6e 65 73 74 65 64 20 66 75 6e 63 74 69 6f 6e 73  nested functions
0240: 2e 0a 20 2a 20 54 68 69 73 20 66 75 6e 63 74 69  .. * This functi
0250: 6f 6e 20 63 72 65 61 74 65 73 20 61 20 63 75 73  on creates a cus
0260: 74 6f 6d 20 34 30 2d 62 79 74 65 20 74 72 61 6d  tom 40-byte tram
0270: 70 6f 6c 69 6e 65 20 66 75 6e 63 74 69 6f 6e 20  poline function 
0280: 6f 6e 20 74 68 65 20 73 74 61 63 6b 20 0a 20 2a  on the stack . *
0290: 20 77 68 69 63 68 20 6c 6f 61 64 73 20 72 31 31   which loads r11
02a0: 20 77 69 74 68 20 61 20 70 6f 69 6e 74 65 72 20   with a pointer 
02b0: 74 6f 20 74 68 65 20 6f 75 74 65 72 20 66 75 6e  to the outer fun
02c0: 63 74 69 6f 6e 27 73 20 6c 6f 63 61 6c 73 0a 20  ction's locals. 
02d0: 2a 20 61 6e 64 20 74 68 65 6e 20 6a 75 6d 70 73  * and then jumps
02e0: 20 74 6f 20 74 68 65 20 74 61 72 67 65 74 20 6e   to the target n
02f0: 65 73 74 65 64 20 66 75 6e 63 74 69 6f 6e 2e 0a  ested function..
0300: 20 2a 2f 0a 0a 23 69 66 20 5f 5f 70 70 63 5f 5f   */..#if __ppc__
0310: 20 26 26 20 21 64 65 66 69 6e 65 64 28 5f 5f 70   && !defined(__p
0320: 6f 77 65 72 70 63 36 34 5f 5f 29 0a 43 4f 4d 50  owerpc64__).COMP
0330: 49 4c 45 52 5f 52 54 5f 41 42 49 20 76 6f 69 64  ILER_RT_ABI void
0340: 0a 5f 5f 74 72 61 6d 70 6f 6c 69 6e 65 5f 73 65  .__trampoline_se
0350: 74 75 70 28 75 69 6e 74 33 32 5f 74 2a 20 74 72  tup(uint32_t* tr
0360: 61 6d 70 4f 6e 53 74 61 63 6b 2c 20 69 6e 74 20  ampOnStack, int 
0370: 74 72 61 6d 70 53 69 7a 65 41 6c 6c 6f 63 61 74  trampSizeAllocat
0380: 65 64 2c 20 0a 20 20 20 20 20 20 20 20 20 20 20  ed, .           
0390: 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 76 6f          const vo
03a0: 69 64 2a 20 72 65 61 6c 46 75 6e 63 2c 20 76 6f  id* realFunc, vo
03b0: 69 64 2a 20 6c 6f 63 61 6c 73 50 74 72 29 0a 7b  id* localsPtr).{
03c0: 0a 20 20 20 20 2f 2a 20 73 68 6f 75 6c 64 20 6e  .    /* should n
03d0: 65 76 65 72 20 68 61 70 70 65 6e 2c 20 62 75 74  ever happen, but
03e0: 20 69 66 20 63 6f 6d 70 69 6c 65 72 20 64 69 64   if compiler did
03f0: 20 6e 6f 74 20 61 6c 6c 6f 63 61 74 65 20 2a 2f   not allocate */
0400: 0a 20 20 20 20 2f 2a 20 65 6e 6f 75 67 68 20 73  .    /* enough s
0410: 70 61 63 65 20 6f 6e 20 73 74 61 63 6b 20 66 6f  pace on stack fo
0420: 72 20 74 68 65 20 74 72 61 6d 70 6f 6c 69 6e 65  r the trampoline
0430: 2c 20 61 62 6f 72 74 20 2a 2f 0a 20 20 20 20 69  , abort */.    i
0440: 66 20 28 20 74 72 61 6d 70 53 69 7a 65 41 6c 6c  f ( trampSizeAll
0450: 6f 63 61 74 65 64 20 3c 20 34 30 20 29 0a 20 20  ocated < 40 ).  
0460: 20 20 20 20 20 20 63 6f 6d 70 69 6c 65 72 72 74        compilerrt
0470: 5f 61 62 6f 72 74 28 29 3b 0a 20 20 20 20 0a 20  _abort();.    . 
0480: 20 20 20 2f 2a 20 63 72 65 61 74 65 20 74 72 61     /* create tra
0490: 6d 70 6f 6c 69 6e 65 20 2a 2f 0a 20 20 20 20 74  mpoline */.    t
04a0: 72 61 6d 70 4f 6e 53 74 61 63 6b 5b 30 5d 20 3d  rampOnStack[0] =
04b0: 20 30 78 37 63 30 38 30 32 61 36 3b 20 20 20 20   0x7c0802a6;    
04c0: 2f 2a 20 6d 66 6c 72 20 72 30 20 2a 2f 0a 20 20  /* mflr r0 */.  
04d0: 20 20 74 72 61 6d 70 4f 6e 53 74 61 63 6b 5b 31    trampOnStack[1
04e0: 5d 20 3d 20 30 78 34 38 30 30 30 30 30 64 3b 20  ] = 0x4800000d; 
04f0: 20 20 20 2f 2a 20 62 6c 20 4c 62 61 73 65 20 2a     /* bl Lbase *
0500: 2f 0a 20 20 20 20 74 72 61 6d 70 4f 6e 53 74 61  /.    trampOnSta
0510: 63 6b 5b 32 5d 20 3d 20 28 75 69 6e 74 33 32 5f  ck[2] = (uint32_
0520: 74 29 72 65 61 6c 46 75 6e 63 3b 0a 20 20 20 20  t)realFunc;.    
0530: 74 72 61 6d 70 4f 6e 53 74 61 63 6b 5b 33 5d 20  trampOnStack[3] 
0540: 3d 20 28 75 69 6e 74 33 32 5f 74 29 6c 6f 63 61  = (uint32_t)loca
0550: 6c 73 50 74 72 3b 0a 20 20 20 20 74 72 61 6d 70  lsPtr;.    tramp
0560: 4f 6e 53 74 61 63 6b 5b 34 5d 20 3d 20 30 78 37  OnStack[4] = 0x7
0570: 64 36 38 30 32 61 36 3b 20 20 20 20 2f 2a 20 4c  d6802a6;    /* L
0580: 62 61 73 65 3a 20 6d 66 6c 72 20 72 31 31 20 2a  base: mflr r11 *
0590: 2f 0a 20 20 20 20 74 72 61 6d 70 4f 6e 53 74 61  /.    trampOnSta
05a0: 63 6b 5b 35 5d 20 3d 20 30 78 38 31 38 62 30 30  ck[5] = 0x818b00
05b0: 30 30 3b 20 20 20 20 2f 2a 20 6c 77 7a 20 20 20  00;    /* lwz   
05c0: 20 72 31 32 2c 30 28 72 31 31 29 20 2a 2f 0a 20   r12,0(r11) */. 
05d0: 20 20 20 74 72 61 6d 70 4f 6e 53 74 61 63 6b 5b     trampOnStack[
05e0: 36 5d 20 3d 20 30 78 37 63 30 38 30 33 61 36 3b  6] = 0x7c0803a6;
05f0: 20 20 20 20 2f 2a 20 6d 74 6c 72 20 72 30 20 2a      /* mtlr r0 *
0600: 2f 0a 20 20 20 20 74 72 61 6d 70 4f 6e 53 74 61  /.    trampOnSta
0610: 63 6b 5b 37 5d 20 3d 20 30 78 37 64 38 39 30 33  ck[7] = 0x7d8903
0620: 61 36 3b 20 20 20 20 2f 2a 20 6d 74 63 74 72 20  a6;    /* mtctr 
0630: 72 31 32 20 2a 2f 0a 20 20 20 20 74 72 61 6d 70  r12 */.    tramp
0640: 4f 6e 53 74 61 63 6b 5b 38 5d 20 3d 20 30 78 38  OnStack[8] = 0x8
0650: 31 36 62 30 30 30 34 3b 20 20 20 20 2f 2a 20 6c  16b0004;    /* l
0660: 77 7a 20 20 20 20 72 31 31 2c 34 28 72 31 31 29  wz    r11,4(r11)
0670: 20 2a 2f 0a 20 20 20 20 74 72 61 6d 70 4f 6e 53   */.    trampOnS
0680: 74 61 63 6b 5b 39 5d 20 3d 20 30 78 34 65 38 30  tack[9] = 0x4e80
0690: 30 34 32 30 3b 20 20 20 20 2f 2a 20 62 63 74 72  0420;    /* bctr
06a0: 20 2a 2f 0a 20 20 20 20 0a 20 20 20 20 2f 2a 20   */.    .    /* 
06b0: 63 6c 65 61 72 20 69 6e 73 74 72 75 63 74 69 6f  clear instructio
06c0: 6e 20 63 61 63 68 65 20 2a 2f 0a 20 20 20 20 5f  n cache */.    _
06d0: 5f 63 6c 65 61 72 5f 63 61 63 68 65 28 74 72 61  _clear_cache(tra
06e0: 6d 70 4f 6e 53 74 61 63 6b 2c 20 26 74 72 61 6d  mpOnStack, &tram
06f0: 70 4f 6e 53 74 61 63 6b 5b 31 30 5d 29 3b 0a 7d  pOnStack[10]);.}
0700: 0a 23 65 6e 64 69 66 20 2f 2a 20 5f 5f 70 70 63  .#endif /* __ppc
0710: 5f 5f 20 26 26 20 21 64 65 66 69 6e 65 64 28 5f  __ && !defined(_
0720: 5f 70 6f 77 65 72 70 63 36 34 5f 5f 29 20 2a 2f  _powerpc64__) */
0730: 0a                                               .