home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mitsch75.zip / scheme-7_5_17-src.zip / scheme-7.5.17 / src / compiler / machines / sparc / cmpint-sparc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-02  |  21.5 KB  |  660 lines

  1. /* -*-C-*-
  2.  
  3. $Id: cmpint-sparc.h,v 1.2 1999/01/02 06:06:43 cph Exp $
  4.  
  5. Copyright (c) 1989-1999 Massachusetts Institute of Technology
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. /*
  23.  *
  24.  * Compiled code interface macros.
  25.  *
  26.  * See cmpint.txt for a description of these fields.
  27.  *
  28.  * Specialized for the MIPS R2000/R3000
  29.  */
  30.  
  31. #ifndef CMPINT2_H_INCLUDED
  32. #define CMPINT2_H_INCLUDED
  33.  
  34. #define ICACHEFLUSH(addr, nbytes) flushrange ((addr), (nbytes))
  35.  
  36. #define COMPILER_NONE_TYPE            0
  37. #define COMPILER_MC68020_TYPE            1
  38. #define COMPILER_VAX_TYPE            2
  39. #define COMPILER_SPECTRUM_TYPE            3
  40. #define COMPILER_OLD_MIPS_TYPE            4
  41. #define COMPILER_MC68040_TYPE            5
  42. #define COMPILER_SPARC_TYPE            6
  43. #define COMPILER_RS6000_TYPE            7
  44. #define COMPILER_MC88K_TYPE            8
  45. #define COMPILER_I386_TYPE            9
  46. #define COMPILER_ALPHA_TYPE            10
  47. #define COMPILER_MIPS_TYPE            11
  48.  
  49. /* Machine parameters to be set by the user. */
  50.  
  51. /* Processor type.  Choose a number from the above list, or allocate your own. */
  52.  
  53. #define COMPILER_PROCESSOR_TYPE            COMPILER_SPARC_TYPE
  54.  
  55. /* Size (in long words) of the contents of a floating point register if
  56.    different from a double.  For example, an MC68881 saves registers
  57.    in 96 bit (3 longword) blocks.
  58.    Default is fine for MIPS.
  59.    define COMPILER_TEMP_SIZE            3
  60. */
  61.  
  62. /* Descriptor size.
  63.    This is the size of the offset field, and of the format field.
  64.    This definition probably does not need to be changed.
  65.  */
  66.  
  67. typedef unsigned short format_word;
  68.  
  69. /* PC alignment constraint.
  70.    Change PC_ZERO_BITS to be how many low order bits of the pc are
  71.    guaranteed to be 0 always because of PC alignment constraints.
  72. */
  73.  
  74. #define PC_ZERO_BITS                    2
  75.  
  76. /* Utilities for manipulating absolute subroutine calls.
  77.    On the SPARC this is done with:
  78.      CALL destination
  79.  
  80.     The low 30 bits of the instruction form the address. This will
  81.     automatically be shifted over 2 bits to adjust for alignment.
  82.  */
  83.  
  84. #define EXTRACT_FROM_JAL_INSTR(target, address)                \
  85. {                                    \
  86.   unsigned long * addr = ((unsigned long *) (address));            \
  87.   unsigned long jal_instr = (*addr);                    \
  88.   (target) =                                \
  89.     ((SCHEME_OBJECT)                            \
  90.      ((((long) (address)) & 0x3FFFFFFF))); \
  91. }
  92.  
  93. #define CALL_OP        (0x1 << 30)
  94. #define CALL_INSTR(dest)    (CALL_OP | (dest >> 2))
  95.  
  96. #define STORE_JAL_INSTR(entry_point, address)                \
  97. {                                    \
  98.   unsigned long ep = ((unsigned long) (entry_point));            \
  99.   unsigned long * addr = ((unsigned long *) (address));            \
  100.   if ((((long) addr) & 0x3) != 0)                    \
  101.   {                                    \
  102.     fprintf (stderr,                            \
  103.          "\nSTORE_JAL_INSTR: Bad addr in CALL 0x%x, 0x%x\n",        \
  104.          addr, ep);                            \
  105.   }                                    \
  106.   (*addr) = CALL_INSTR (ep);                \
  107. }
  108.  
  109. /* Compiled Code Register Conventions */
  110. /* This must match the compiler and cmpaux-sparc.s */
  111.  
  112. #define COMP_REG_TEMPORARY    1
  113. #define COMP_REG_RETURN        16
  114. #define COMP_REG_STACK        17
  115. #define COMP_REG_C_ARG_1        8
  116. #define COMP_REG_C_ARG_2        9
  117. #define COMP_REG_C_ARG_3        10
  118. #define COMP_REG_C_ARG_4        11
  119. #define COMP_REG_MEMTOP        18
  120. #define COMP_REG_FREE        19
  121. #define COMP_REG_SCHEME_TO_INTERFACE 20
  122. #define COMP_REG_DYNAMIC_LINK        21
  123. #define COMP_REG_TRAMP_INDEX       13
  124.  
  125. #define COMP_REG_CLOSURE_FREE        22
  126. #define COMP_REG_ADDRESS_MASK        25
  127. #define COMP_REG_REGISTERS        26
  128. #define COMP_REG_QUAD_MASK        27
  129. #define COMP_REG_CLOSURE_HOOK        28
  130.  
  131. #define COMP_REG_KERNEL_RESERVED_1    2
  132. #define COMP_REG_KERNEL_RESERVED_2    3
  133. #define COMP_REG_KERNEL_RESERVED_3    4
  134. #define COMP_REG_C_GLOBALS        
  135. #define COMP_REG_C_STACK        30
  136. #define COMP_REG_LINKAGE        31
  137.  
  138. /* Interrupt/GC polling. */
  139.  
  140. /* Skip over this many BYTES to bypass the GC check code (ordinary
  141. procedures and continuations differ from closures) */
  142.  
  143. #define ENTRY_SKIPPED_CHECK_OFFSET     12
  144. #define CLOSURE_SKIPPED_CHECK_OFFSET     40
  145.  
  146. /* The length of the GC recovery code that precedes an entry.
  147.    On the SPARC a "addi, jalr, addi" instruction sequence.
  148.  */
  149.  
  150. #define ENTRY_PREFIX_LENGTH        12
  151.  
  152. /*
  153.   The instructions for a normal entry should be something like
  154.  
  155.   ADDICC  $at,$FREE,$MEMTOP
  156.   BGE     interrupt
  157.   LD      $MEMTOP,REG_BLOCK
  158.   
  159.   For a closure
  160.  
  161.   LUI    $at,FROB(TC_CLOSURE)    ; temp <- closure tag
  162.   XOR    $1,$1,$at            ; 1 <- tagged value
  163.   ADDI    $SP,$SP,-4        ; push closure
  164.   ST         $1,0($SP)
  165.   ADDICC  $at,$FREE,$MEMTOP
  166.   BGE     interrupt
  167.   LD      $MEMTOP,REG_BLOCK
  168. */
  169.  
  170. /* A NOP on machines where instructions are longword-aligned. */
  171.  
  172. #define ADJUST_CLOSURE_AT_CALL(entry_point, location)            \
  173. do {                                    \
  174. } while (0)
  175.  
  176. /* Compiled closures */
  177.  
  178. /* Manifest closure entry block size.
  179.    Size in bytes of a compiled closure's header excluding the
  180.    TC_MANIFEST_CLOSURE header.
  181.  
  182.    On the SPARC this is 2 format_words for the format word and gc offset
  183.    words, and 12 more bytes for 3 instructions.
  184.  
  185.    The three instructions are:
  186.  
  187.    SETHI %HI(TARGET), GLOBAL_TEMP
  188.    JMPL [GLOBAL_TEMP + %LO(TARGET)], GLOBAL_TEMP
  189.    ADDI 8,GLOBAL_TEMP,GLOBAL_TEMP
  190.  */
  191.  
  192. #define SETHI_GLOBAL_TEMP_TEMPLATE  0x03000000
  193. #define NOP_INSTRUCTION 0x01000000
  194. #define JMPL_TEMPLATE 0x81c06000
  195. #define CLOSURE_JMPL_TEMPLATE 0x83c06000
  196.  
  197. #define COMPILED_CLOSURE_ENTRY_SIZE     16
  198.  
  199. /* Manifest closure entry destructuring.
  200.  
  201.    Given the entry point of a closure, extract the `real entry point'
  202.    (the address of the real code of the procedure, ie. one indirection)
  203.    from the closure.
  204.  
  205.    On the SPARC we have to extract from a SETHI/JMPL_OFFSET sequence.
  206.    
  207. */
  208.  
  209. #define EXTRACT_CLOSURE_ENTRY_ADDRESS(extracted_ep, clos_addr) do    \
  210. {                                    \
  211.   unsigned long * addr = ((unsigned long*)(clos_addr)); \
  212.   unsigned long sethi_instr = addr[0]; \
  213.   unsigned long jmpl_instr = addr[1]; \
  214.   (extracted_ep) = \
  215.    ((SCHEME_OBJECT) \
  216.     (((sethi_instr & 0x3fffff) << 10) | (jmpl_instr & 0x3ff))); \
  217. } while (0)
  218.  
  219. /* This is the inverse of EXTRACT_CLOSURE_ENTRY_ADDRESS.
  220.    Given a closure's entry point and a code entry point, store the
  221.    code entry point in the closure.
  222.  */
  223.  
  224. /* The following is a SPARC ADDI 8,G1,G1 */
  225. #define CLOSURE_BUMP_LINKAGE_TO_DATA_INSTR 0x82006008
  226.  
  227. #define STORE_CLOSURE_ENTRY_ADDRESS(ep_to_store, clos_addr) do        \
  228. {                                    \
  229.   unsigned long * addr = (unsigned long *)(clos_addr); \
  230.   unsigned long target = (unsigned long)(ep_to_store); \
  231.   addr[0] = (addr[0] & SETHI_GLOBAL_TEMP_TEMPLATE) | (target >> 10); \
  232.   addr[1] = (addr[1] & CLOSURE_JMPL_TEMPLATE) | (target & 0x000003ff); \
  233.   addr[2] = CLOSURE_BUMP_LINKAGE_TO_DATA_INSTR; \
  234. } while (0)
  235.  
  236. /* Trampolines
  237.  
  238.    On the SPARC, here's a picture of a trampoline (offset in bytes from
  239.    entry point)
  240.  
  241.      -12: MANIFEST vector header
  242.      - 8: NON_MARKED header
  243.      - 4: Format word
  244.      - 2: 0x6 (GC Offset to start of block from .+2)
  245.           Note the encoding -- divided by 2, low bit for
  246.           extended distances (see OFFSET_WORD_TO_BYTE_OFFSET)
  247.        0: ADDI  TEMP,SCHEME_TO_INTERFACE,MAGIC_CONSTANT
  248.        4: JALR    LINKAGE,TEMP
  249.        8: ADDI    TRAMP_INDEX,0,index
  250.       12: trampoline dependent storage (0 - 3 longwords)
  251.  
  252.    TRAMPOLINE_ENTRY_SIZE is the size in longwords of the machine
  253.    dependent portion of a trampoline, including the GC and format
  254.    headers.  The code in the trampoline must store an index (used to
  255.    determine which C SCHEME_UTILITY procedure to invoke) in a
  256.    register, jump to "scheme_to_interface" and leave the address of
  257.    the storage following the code in a standard location.
  258.  
  259.    TRAMPOLINE_ENTRY_POINT returns the address of the entry point of a
  260.    trampoline when given the address of the word containing
  261.    the manifest vector header.  According to the above picture,
  262.    it would add 12 bytes to its argument.
  263.  
  264.    TRAMPOLINE_STORAGE takes the address of the first instruction in a
  265.    trampoline (not the start of the trampoline block) and returns the
  266.    address of the first storage word in the trampoline.
  267.  
  268.    STORE_TRAMPOLINE_ENTRY gets the address of the first instruction in
  269.    the trampoline and stores the instructions.  It also receives the
  270.    index of the C SCHEME_UTILITY to be invoked.
  271. */
  272.  
  273. #define TRAMPOLINE_ENTRY_SIZE        5
  274. #define TRAMPOLINE_BLOCK_TO_ENTRY    3
  275.  
  276. #define TRAMPOLINE_ENTRY_POINT(tramp_block)                \
  277.   (((SCHEME_OBJECT *) (tramp_block)) + TRAMPOLINE_BLOCK_TO_ENTRY)
  278.  
  279. #define TRAMPOLINE_STORAGE(tramp_entry)                    \
  280.   ((((SCHEME_OBJECT *)(tramp_entry)) + 3))
  281.  
  282. #define SPECIAL_OPCODE    000
  283. #define ADDI_OPCODE    010
  284.  
  285. #define OP(OPCODE)    (OPCODE << 18)
  286. #define SPECIAL_OP    OP(SPECIAL_OPCODE)
  287. #define ADDI_OP        OP(ADDI_OPCODE)
  288.  
  289. #define JALR_TEMPLATE 0x81c02000
  290. #define JALR_SRC(n)    ((n & 0x1F) << 14)
  291. #define JALR_DST(n)    ((n & 0x1F) << 25)
  292. #define JALR(d,s)    (JALR_TEMPLATE|JALR_SRC(s)|JALR_DST(d))
  293.  
  294. #define ADDI_TEMPLATE 0x80002000
  295. #define ADDI_SRC(n)    ((n & 0x1F) << 14)
  296. #define ADDI_DST(n)    ((n & 0x1F) << 25)
  297. #define ADDI_IMMED(n)    (n & 0x1FFF)
  298. #define ADDI(d,s,imm)    (ADDI_TEMPLATE|ADDI_DST(d)|ADDI_SRC(s)|ADDI_IMMED(imm))
  299.  
  300. #define STORE_TRAMPOLINE_ENTRY(entry_address, index)            \
  301. { unsigned long *PC;                            \
  302.   PC = ((unsigned long *) (entry_address));                \
  303.   *PC++ = ADDI(COMP_REG_TEMPORARY, COMP_REG_SCHEME_TO_INTERFACE, -8);    \
  304.   *PC++ = JALR(COMP_REG_C_ARG_1, COMP_REG_TEMPORARY);            \
  305.   *PC = ADDI(COMP_REG_TRAMP_INDEX, 0, (4*index));            \
  306.   /* assumes index fits in 13 bits */                    \
  307. }
  308.  
  309. /* Execute cache entries.
  310.  
  311.    Execute cache entry size size in longwords.  The cache itself
  312.    contains both the number of arguments provided by the caller and
  313.    code to jump to the destination address.  Before linkage, the cache
  314.    contains the callee's name instead of the jump code.
  315.  
  316.    On SPARC: 3 instructions, the last being a NO-OP (SETHI with
  317.    constant 0, destination 0)
  318.  */
  319.  
  320. #define EXECUTE_CACHE_ENTRY_SIZE        3
  321.  
  322. /* Execute cache destructuring. */
  323.  
  324. /* Given a target location and the address of the first word of an
  325.    execute cache entry, extract from the cache cell the number of
  326.    arguments supplied by the caller and store it in target. */
  327.  
  328. /* For the SPARC (big endian), addresses in bytes from the start of
  329.    the cache:
  330.  
  331.    Before linking
  332.      +0: TC_SYMBOL || symbol address
  333.      +4: TC_FIXNUM || 0
  334.      +6: number of supplied arguments, +1
  335.     +8: ???
  336.     
  337.    After linking
  338.      +0: SETHI global_temp (top 22 bits) 
  339.     +4: JMPL global_temp (low 10 bits)
  340.      +8: NOP
  341.  
  342. */
  343.  
  344. #define SPARC_CACHE_ARITY_OFFSET 5
  345. #define SPARC_CACHE_CODE_OFFSET 8
  346.  
  347.  
  348. #define EXTRACT_EXECUTE_CACHE_ARITY(target, address)            \
  349. {                                    \
  350.   (target) =                                \
  351.     ((long)                                \
  352.      (((unsigned short *) (address)) [SPARC_CACHE_ARITY_OFFSET]) & 0x0fff);\
  353. }
  354.  
  355. #define EXTRACT_EXECUTE_CACHE_SYMBOL(target, address)            \
  356. {                                    \
  357.   (target) = (* (((SCHEME_OBJECT *) (address))));            \
  358. }
  359.  
  360. /* Extract the target address (not the code to get there) from an
  361.    execute cache cell.
  362.  */
  363.  
  364. #define EXTRACT_EXECUTE_CACHE_ADDRESS(target, address)            \
  365. {                                    \
  366.   unsigned long * addr = ((unsigned long*)(address)); \
  367.   unsigned long sethi_instr = addr[0]; \
  368.   unsigned long jmpl_instr = addr[1]; \
  369.   (target) = \
  370.    ((SCHEME_OBJECT) \
  371.     (((sethi_instr & 0x3fffff) << 10) | (jmpl_instr & 0x3ff))); \
  372. }
  373.  
  374. /* This is the inverse of EXTRACT_EXECUTE_CACHE_ADDRESS.
  375.    On the SPARC it must flush the I-cache, but there is no
  376.    need to flush the following ADDI instruction, which is a NOP.
  377.  */
  378.  
  379. #define STORE_EXECUTE_CACHE_ADDRESS(address, entry)            \
  380. {                                    \
  381.   unsigned long * addr = (unsigned long *)(address); \
  382.   unsigned long target = (unsigned long)(entry); \
  383.   addr[0] = (addr[0] & SETHI_GLOBAL_TEMP_TEMPLATE) | (target >> 10); \
  384.   addr[1] = (addr[1] & JMPL_TEMPLATE) | (target & 0x000003ff); \
  385. }
  386.  
  387. /* This stores the fixed part of the instructions leaving the
  388.    destination address and the number of arguments intact.  These are
  389.    split apart so the GC can call EXTRACT/STORE...ADDRESS but it does
  390.    NOT need to store the instructions back.  On some architectures the
  391.    instructions may change due to GC and then STORE_EXECUTE_CACHE_CODE
  392.    should become a no-op and all of the work is done by
  393.    STORE_EXECUTE_CACHE_ADDRESS instead.
  394.  */
  395.  
  396.  
  397. #define STORE_EXECUTE_CACHE_CODE(address)                \
  398. {                                    \
  399.   unsigned long* nop_addr = (((unsigned long *)(address)) + 2); \
  400.   unsigned long  nop_val; \
  401.   *((unsigned long *)address) = (SETHI_GLOBAL_TEMP_TEMPLATE); \
  402.   *(((unsigned long *)(address))+1) = JMPL_TEMPLATE; \
  403.   nop_val = (*nop_addr); \
  404.   (*nop_addr) = ADDI(0,0,nop_val); \
  405. }
  406.  
  407. /* This flushes the Scheme portion of the I-cache.
  408.    It is used after a GC or disk-restore.
  409.    It's needed because the GC has moved code around, and closures
  410.    and execute cache cells have absolute addresses that the
  411.    processor might have old copies of.
  412.  */
  413.  
  414. #define FLUSH_I_CACHE() do                        \
  415. {                                    \
  416.   ICACHEFLUSH (Heap_Bottom,                        \
  417.            ((sizeof(SCHEME_OBJECT)) *                \
  418.         (Heap_Top - Heap_Bottom)));                \
  419.   ICACHEFLUSH (Constant_Space,                        \
  420.            ((sizeof(SCHEME_OBJECT)) *                \
  421.         (Constant_Top - Constant_Space)));            \
  422.   ICACHEFLUSH (Stack_Pointer,                        \
  423.            ((sizeof(SCHEME_OBJECT)) *                \
  424.         (Stack_Top - Stack_Pointer)));                \
  425. } while (0)
  426.  
  427.  
  428. /* This flushes a region of the I-cache.
  429.    It is used after updating an execute cache while running.
  430.    Not needed during GC because FLUSH_I_CACHE will be used.
  431.  */   
  432.  
  433. #define FLUSH_I_CACHE_REGION(address, nwords) do            \
  434. {                                    \
  435.   ICACHEFLUSH ((address), ((sizeof (long)) * (nwords)));        \
  436. } while (0)
  437.  
  438. #define PUSH_D_CACHE_REGION FLUSH_I_CACHE_REGION
  439.  
  440. /* The following is misnamed.
  441.    It should really be called STORE_BACK_D_CACHE.
  442.    Neither the R2000 nor the R3000 systems have them.
  443.    I don't know about the R4000 or R6000.
  444.  */
  445.  
  446. /* #define SPLIT_CACHES */
  447.  
  448. #ifdef IN_CMPINT_C
  449.  
  450.  
  451. #define CLOSURE_ENTRY_WORDS            \
  452.   (COMPILED_CLOSURE_ENTRY_SIZE / (sizeof (SCHEME_OBJECT)))
  453.  
  454. static long closure_chunk = (1024 * CLOSURE_ENTRY_WORDS);
  455.  
  456. #define REGBLOCK_CLOSURE_LIMIT    REGBLOCK_CLOSURE_SPACE
  457.  
  458. /* The apparently random instances of the number 3 below arise from
  459.    the convention that free_closure always points to a JAL instruction
  460.    with (at least) 3 unused words preceding it.
  461.    In this way, if there is enough space, we can use free_closure
  462.    as the address of a new uni- or multi-closure.
  463.    
  464.    The code below (in the initialization loop) depends on knowing that
  465.    CLOSURE_ENTRY_WORDS is 3.
  466.    
  467.    Random hack: ADDI instructions look like TC_TRUE objects, thus of the
  468.    pre-initialized words, only the JALR looks like a pointer object
  469.    (an SCODE-QUOTE).  Since there is exactly one JALR of waste between
  470.    closures, and it is always 3 words before free_closure,
  471.    the code for uni-closure allocation (in mips.m4) bashes that word
  472.    with 0 (SHARP_F) to make the heap parseable.
  473.  */
  474.  
  475. /* size in Scheme objects of the block we need to allocate. */
  476.  
  477. void
  478. DEFUN (allocate_closure, (size), long size)
  479. {
  480.   long space;
  481.   SCHEME_OBJECT * free_closure, * limit;
  482.  
  483.   free_closure = ((SCHEME_OBJECT *) Registers[REGBLOCK_CLOSURE_FREE]);
  484.   limit = ((SCHEME_OBJECT *) Registers[REGBLOCK_CLOSURE_LIMIT]);
  485.   space =  ((limit - free_closure) + 3);
  486.  
  487.   /* Bump up to a multiple of CLOSURE_ENTRY_WORDS.
  488.      Otherwise clearing by the allocation code may clobber
  489.      a different word.
  490.    */
  491.   size = (CLOSURE_ENTRY_WORDS
  492.       * ((size + (CLOSURE_ENTRY_WORDS - 1))
  493.          / CLOSURE_ENTRY_WORDS));
  494.   if (size > space)
  495.   {
  496.     long chunk_size;
  497.     SCHEME_OBJECT *ptr;
  498.  
  499.     /* Make the heap be parseable forward by protecting the waste
  500.        in the last chunk.
  501.      */
  502.        
  503.     if ((space > 0) && (free_closure != ((SCHEME_OBJECT) NULL)))
  504.       free_closure[-3] = (MAKE_OBJECT (TC_MANIFEST_NM_VECTOR, (space - 1)));
  505.  
  506.     free_closure = Free;
  507.     if ((size <= closure_chunk) && (!(GC_Check (closure_chunk))))
  508.       limit = (free_closure + closure_chunk);
  509.     else
  510.     {
  511.       if (GC_Check (size))
  512.       {
  513.     if ((Heap_Top - Free) < size)
  514.     {
  515.       /* No way to back out -- die. */
  516.       fprintf (stderr, "\nC_allocate_closure (%d): No space.\n", size);
  517.       Microcode_Termination (TERM_NO_SPACE);
  518.       /* NOTREACHED */
  519.     }
  520.     Request_GC (0);
  521.       }
  522.       else if (size <= closure_chunk)
  523.     Request_GC (0);
  524.       limit = (free_closure + size);
  525.     }
  526.     Free = limit;
  527.     chunk_size = (limit - free_closure);
  528.  
  529.     ptr = free_closure;
  530.     while (ptr < limit)
  531.     {
  532.       *ptr++ = (JALR (COMP_REG_LINKAGE, COMP_REG_CLOSURE_HOOK));
  533.       *ptr++ = (ADDI (COMP_REG_LINKAGE, COMP_REG_LINKAGE, -8));
  534.       *ptr++ = SHARP_F;
  535.     }
  536.     PUSH_D_CACHE_REGION (free_closure, chunk_size);
  537.     Registers[REGBLOCK_CLOSURE_LIMIT] = ((SCHEME_OBJECT) limit);
  538.     Registers[REGBLOCK_CLOSURE_FREE] = ((SCHEME_OBJECT) (free_closure + 3));
  539.   }
  540.   return;
  541. }
  542.  
  543. #endif /* IN_CMPINT_C */
  544.  
  545. /* Derived parameters and macros.
  546.  
  547.    These macros expect the above definitions to be meaningful.
  548.    If they are not, the macros below may have to be changed as well.
  549.  */
  550.  
  551. #define COMPILED_ENTRY_OFFSET_WORD(entry) (((format_word *) (entry)) [-1])
  552. #define COMPILED_ENTRY_FORMAT_WORD(entry) (((format_word *) (entry)) [-2])
  553.  
  554. /* The next one assumes 2's complement integers....*/
  555. #define CLEAR_LOW_BIT(word)                     ((word) & ((unsigned long) -2))
  556. #define OFFSET_WORD_CONTINUATION_P(word)        (((word) & 1) != 0)
  557.  
  558. #if (PC_ZERO_BITS == 0)
  559. /* Instructions aligned on byte boundaries */
  560. #define BYTE_OFFSET_TO_OFFSET_WORD(offset)      ((offset) << 1)
  561. #define OFFSET_WORD_TO_BYTE_OFFSET(offset_word)                         \
  562.   ((CLEAR_LOW_BIT(offset_word)) >> 1)
  563. #endif
  564.  
  565. #if (PC_ZERO_BITS == 1)
  566. /* Instructions aligned on word (16 bit) boundaries */
  567. #define BYTE_OFFSET_TO_OFFSET_WORD(offset)      (offset)
  568. #define OFFSET_WORD_TO_BYTE_OFFSET(offset_word)                         \
  569.   (CLEAR_LOW_BIT(offset_word))
  570. #endif
  571.  
  572. #if (PC_ZERO_BITS >= 2)
  573. /* Should be OK for =2, but bets are off for >2 because of problems
  574.    mentioned earlier!
  575. */
  576. #define SHIFT_AMOUNT                            (PC_ZERO_BITS - 1)
  577. #define BYTE_OFFSET_TO_OFFSET_WORD(offset)      ((offset) >> (SHIFT_AMOUNT))
  578. #define OFFSET_WORD_TO_BYTE_OFFSET(offset_word)                         \
  579.   ((CLEAR_LOW_BIT(offset_word)) << (SHIFT_AMOUNT))
  580. #endif
  581.  
  582. #define MAKE_OFFSET_WORD(entry, block, continue)                        \
  583.   ((BYTE_OFFSET_TO_OFFSET_WORD(((char *) (entry)) -                     \
  584.                                ((char *) (block)))) |                   \
  585.    ((continue) ? 1 : 0))
  586.  
  587. #if (EXECUTE_CACHE_ENTRY_SIZE == 2)
  588. #define EXECUTE_CACHE_COUNT_TO_ENTRIES(count)                           \
  589.   ((count) >> 1)
  590. #define EXECUTE_CACHE_ENTRIES_TO_COUNT(entries)                \
  591.   ((entries) << 1)
  592. #endif
  593.  
  594. #if (EXECUTE_CACHE_ENTRY_SIZE == 4)
  595. #define EXECUTE_CACHE_COUNT_TO_ENTRIES(count)                           \
  596.   ((count) >> 2)
  597. #define EXECUTE_CACHE_ENTRIES_TO_COUNT(entries)                \
  598.   ((entries) << 2)
  599. #endif
  600.  
  601. #if (!defined(EXECUTE_CACHE_COUNT_TO_ENTRIES))
  602. #define EXECUTE_CACHE_COUNT_TO_ENTRIES(count)                           \
  603.   ((count) / EXECUTE_CACHE_ENTRY_SIZE)
  604. #define EXECUTE_CACHE_ENTRIES_TO_COUNT(entries)                \
  605.   ((entries) * EXECUTE_CACHE_ENTRY_SIZE)
  606. #endif
  607.  
  608. /* The first entry in a cc block is preceeded by 2 headers (block and nmv),
  609.    a format word and a gc offset word.   See the early part of the
  610.    TRAMPOLINE picture, above.
  611.  */
  612.  
  613. #define CC_BLOCK_FIRST_ENTRY_OFFSET                                     \
  614.   (2 * ((sizeof(SCHEME_OBJECT)) + (sizeof(format_word))))
  615.  
  616. /* Format words */
  617.  
  618. #define FORMAT_BYTE_EXPR                0xFF
  619. #define FORMAT_BYTE_COMPLR              0xFE
  620. #define FORMAT_BYTE_CMPINT              0xFD
  621. #define FORMAT_BYTE_DLINK               0xFC
  622. #define FORMAT_BYTE_RETURN              0xFB
  623.  
  624. #define FORMAT_WORD_EXPR        (MAKE_FORMAT_WORD(0xFF, FORMAT_BYTE_EXPR))
  625. #define FORMAT_WORD_CMPINT      (MAKE_FORMAT_WORD(0xFF, FORMAT_BYTE_CMPINT))
  626. #define FORMAT_WORD_RETURN      (MAKE_FORMAT_WORD(0xFF, FORMAT_BYTE_RETURN))
  627.  
  628. /* This assumes that a format word is at least 16 bits,
  629.    and the low order field is always 8 bits.
  630.  */
  631.  
  632. #define MAKE_FORMAT_WORD(field1, field2)                                \
  633.   (((field1) << 8) | ((field2) & 0xff))
  634.  
  635. #define SIGN_EXTEND_FIELD(field, size)                                  \
  636.   (((field) & ((1 << (size)) - 1)) |                                    \
  637.    ((((field) & (1 << ((size) - 1))) == 0) ? 0 :                        \
  638.     ((-1) << (size))))
  639.  
  640. #define FORMAT_WORD_LOW_BYTE(word)                                      \
  641.   (SIGN_EXTEND_FIELD ((((unsigned long) (word)) & 0xff), 8))
  642.  
  643. #define FORMAT_WORD_HIGH_BYTE(word)                    \
  644.   (SIGN_EXTEND_FIELD                            \
  645.    ((((unsigned long) (word)) >> 8),                    \
  646.     (((sizeof (format_word)) * CHAR_BIT) - 8)))
  647.  
  648. #define COMPILED_ENTRY_FORMAT_HIGH(addr)                                \
  649.   (FORMAT_WORD_HIGH_BYTE (COMPILED_ENTRY_FORMAT_WORD (addr)))
  650.  
  651. #define COMPILED_ENTRY_FORMAT_LOW(addr)                                 \
  652.   (FORMAT_WORD_LOW_BYTE (COMPILED_ENTRY_FORMAT_WORD (addr)))
  653.  
  654. #define FORMAT_BYTE_FRAMEMAX            0x7f
  655.  
  656. #define COMPILED_ENTRY_MAXIMUM_ARITY    COMPILED_ENTRY_FORMAT_LOW
  657. #define COMPILED_ENTRY_MINIMUM_ARITY    COMPILED_ENTRY_FORMAT_HIGH
  658.  
  659. #endif /* CMPINT2_H_INCLUDED */
  660.