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 / cmpaux-sparc.m4 < prev    next >
Encoding:
Text File  |  1999-01-02  |  10.1 KB  |  340 lines

  1. /* #define DEBUG_INTERFACE */ /* -*-Midas-*- */
  2.  !###
  3.  !###$Id: cmpaux-sparc.m4,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
  8.  !### modify it under the terms of the GNU General Public License as
  9.  !### published by the Free Software Foundation; either version 2 of
  10.  !### the License, or (at your option) any later version.
  11.  !###
  12.  !### This program is distributed in the hope that it will be useful,
  13.  !### but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  !### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  !### GNU General Public License for more details.
  16.  !###
  17.  !### You should have received a copy of the GNU General Public
  18.  !### License along with this program; if not, write to the Free
  19.  !### Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
  20.  !### USA.
  21.  !###
  22.  
  23.  !#### SPARC Architecture assembly language part of the compiled
  24.  !#### code interface. See cmpint.txt, cmpint.c, cmpint-mips.h, and
  25.  !#### cmpgc.h for more documentation.
  26.  !####
  27.  !#### NOTE:
  28.  !####    Assumptions:
  29.  !####
  30.  !####    1) All registers (except double floating point registers) and
  31.  !####    stack locations hold a C long object.
  32.  !####
  33.  !####    2) The C compiler divides registers into four categories:
  34.  !####        in: (%i7-%i0 or %r31-%r24) incoming parameters
  35.  !####        note: %fp is in this group
  36.  !####        note: %i7 holds the C return address, don't bash this.
  37.  !####
  38.  !####        out: (%o7-%o0 or %r15-%r8) outgoing parameters
  39.  !####        note: %sp is in this group
  40.  !####        
  41.  !####        locals: (%l7-%l0 or %r23-%r16)
  42.  !####        
  43.  !####        globals: (%g7-%g0 or %r7-%r0), reserved, essentially useless
  44.  !####
  45.  !####    The ins and locals are callee save through the standard SPARC save
  46.  !####    and restore instructions. This has the added effect of cleaning
  47.  !####    up the stack and frame pointers correctly. Globals are callee save.
  48.  !####    Note that save and restore also pose as simulataneous add
  49.  !####    instructions. This comes in handy for allocating the stack frame.
  50.  !####
  51.  !####    3) On SPARC the floating point registers are totally ungoverned.
  52.  !####    The de-facto standard is caller save.
  53.  
  54.  
  55.  !#### Compiled Scheme code uses the following register convention.
  56.  !####    - g0 is the 0 constant                (hardwired)
  57.  !####    - g1 is the designated temporary        (scheme available)
  58.  !####    - g2-g4 are available for globals        (scheme available)
  59.  !####    - g5-g7 are off limits super globals.        (don't touch!)
  60.  !####    < Start of C callee saves >
  61.  !####   - l0 is the return value register.        (scheme available)
  62.  !####    - l1 contains the Scheme stack pointer.        (scheme available)
  63.  !####    - l2 contains a cached version of MemTop.    (scheme available)
  64.  !####    - l3 contains the Scheme free pointer.        (scheme available)    
  65.  !####   - l4 contains the address of scheme_to_interface.    (scheme available)
  66.  !####    - l5 contains the dynamic link when needed.    (scheme available)
  67.  !####   - l6 contains the closure free pointer.        (scheme available)
  68.  !####    - l7 is leftover (used for tramp index)        (scheme available)
  69.  !####    - i0 is the C return value / first parameter    (scheme available)
  70.  !####    - i1 contains the address mask for machine pointers.    (scheme available)
  71.  !####    - i2 contains a pointer to the Scheme interpreter's    (scheme available)
  72.  !####           "register" block.  This block contains the compiler's
  73.  !####          copy of MemTop, the interpreter's registers (val, env,
  74.  !####          exp, etc), temporary locations for compiled code.
  75.  !####    - i3 contains the top 6 address bits for heap pointers.    (scheme available)
  76.  !####    - i4 contains the closure hook.                (scheme available)
  77.  !####    - i5 is leftover.                    (scheme available)
  78.  !####    - i6 is the C frame pointer, alternatively the old C sp.(don't touch!)
  79.  !####    - i7 is the C return address.                (don't touch!)
  80.  !####    < End of C callee saves >
  81.  !####    - o7 is the target of call instructions, ie next pc.    (scheme available)
  82.  !####    - o6 is the current C stack pointer.            (scheme available)
  83.  !####    - o5-o1 are outgoing parameters to the C world.        (scheme available)
  84.  !####    - o0 is an outgoing parameter to the C world, and the return value
  85.  !####      from there                        (scheme available)
  86.  !####    
  87.  
  88.  !#    .verstamp    1 31
  89.  
  90. define(value, l0)
  91. define(stack, l1)
  92. define(C_arg1, o0)
  93. define(C_arg2, o1)
  94. define(C_arg3, o2)
  95. define(C_arg4, o3)
  96. define(utility_index, o5)
  97.  
  98. define(memtop, l2)
  99. define(free, l3)
  100. define(s_to_i, l4)
  101. define(dynlink, l5)
  102.  
  103. define(closure_free, l6)
  104. define(addr_mask, i1)
  105. define(registers, i2)
  106. define(heap_bits, i3)
  107. define(closure_reg, i4)
  108.  
  109.     .global _Free
  110.     .global _Registers
  111.     .global _Ext_Stack_Pointer
  112.  
  113.     .text    
  114.     .align    4
  115.  
  116.  
  117.  !# Argument (in $C_arg1) is a compiled Scheme entry point
  118.  !# but save C registers first
  119.     .align     4
  120.     .global    _C_to_interface
  121.     .proc    020
  122. _C_to_interface:
  123.     save     %sp,-104,%sp
  124.  
  125.     !# Make space for interface return structs and stick a pointer to
  126.     !# on the stack. SPARC C calling conventions require this.
  127.  
  128.     add    %fp, -24, %o0
  129.     st    %o0,[%sp+64]
  130.  
  131.     !# Now stick the right interpreter registers into the right machine
  132.     !# registers.
  133.  
  134.     sethi    %hi(_Free), %g1
  135.     ld    [%g1+%lo(_Free)], %heap_bits
  136.     sethi    %hi(0xfc000000), %addr_mask
  137.     sethi    %hi(_Registers), %g1
  138.     or    %g1, %lo(_Registers), %registers
  139.     and     %heap_bits, %addr_mask, %heap_bits
  140.     xnor     %g0, %addr_mask, %addr_mask
  141.     
  142.     .align 4
  143.     .global    _interface_to_scheme
  144. _interface_to_scheme:
  145.     
  146.     sethi    %hi(_Free), %g1
  147.     ld    [%g1+%lo(_Free)], %free
  148.     sethi    %hi(_Ext_Stack_Pointer), %g1
  149.     ld    [%g1+%lo(_Ext_Stack_Pointer)], %stack
  150.  
  151.     ld     [%registers + 36],%closure_free
  152.     ld     [%registers + 8],%value
  153.     ld     [%registers],%memtop
  154.  
  155.     and    %value,%addr_mask,%dynlink
  156.     or     %dynlink,%heap_bits,%dynlink
  157.     jmpl    %i0 + 0, %o7
  158.     add    %o7,264,%s_to_i
  159.     
  160. !# Don't rearrange the following procedures. The compiler backend knows their offsets
  161. !# from scheme_to_interface and uses this knowledge to jump to them.
  162.  
  163.     .align 4
  164.     .global _cons_multi_closure
  165.     !# arg1 -> linkage data start address
  166.     !# arg2 -> number of entries
  167.     !# arg3 -> contains contents of %free
  168.     !# %s_to_1 -256
  169.     !# C_arg1 points to a manifest closure header word, followed by
  170.       !# nentries two-word structures, followed by the actual
  171.       !# instructions to return to.
  172.       !# The first word of each descriptor is the format+gc-offset word of
  173.       !# the corresponding entry point of the generated closure.
  174.       !# The second word is the offset from the entry address to the real
  175.     !# code of the closure.
  176. _cons_multi_closure:
  177.     save %sp, -96, %sp
  178.     add %i0, 0, %l0
  179.  
  180.     !# Stuff the tag word and length into the beginning of the multi-closure
  181.     !# also write in the number of entries word.
  182.     ld [%l0], %g1
  183.     st %g1, [%i2]
  184.     add %l0, 4, %l0
  185.  
  186.     sll %i1, 16, %g1
  187.     st %g1, [%i2 + 4]
  188.  
  189.     !# Setup a template for the Addi part of each entry
  190.     sethi %hi(0x82006008), %l1
  191.     add %lo(0x82006008), %l1, %l1
  192.  
  193.     !# Calcualate the first offset to the closed var.
  194.     add %i1, -1, %l2
  195.     umul %l2, 16, %l2
  196.  
  197.     !# Copy free and bump it up two words
  198.     add %i2, 8, %l3
  199.  
  200. cmc_l2:
  201.     !# Copy the format+gc-offset word into the start of the entry
  202.     ld [%l0], %g1
  203.     st %g1, [%l3]
  204.  
  205.     !# Construct the sethi(target) part of the entry
  206.     ld [%l0+4], %g1
  207.     add %i0, %g1, %g1
  208.     srl %g1, 10, %l4
  209.     sethi %hi(0x03000000), %l5
  210.     or %l4, %l5, %l5
  211.     st %l5, [%l3+4]
  212.  
  213.     !# Construct the jmpl(lo(target)) part of the entry
  214.     and %g1, 0x3ff, %l4
  215.     sethi %hi(0x83c06000), %l5
  216.     or %l4, %l5, %l5
  217.     st %l5, [%l3+8]
  218.  
  219.     !# Construct the addi offset-to-data part of the entry
  220.     add %l2, %l1, %l5
  221.     st %l5, [%l3+12]
  222.  
  223.     !# Flush the instruction cache
  224.     iflush %l3 + 4
  225.     iflush %l3 + 8
  226.     iflush %l3 + 12
  227.  
  228.     !# Bump to the next entry, next set of data
  229.  
  230.     add %l3, 16, %l3
  231.     add %l0, 8, %l0
  232.     subcc %l2, 16, %l2
  233.     bge cmc_l2
  234.     nop
  235.  
  236.     add %l0, 0, %g1
  237.     jmpl %g1, %g0
  238.     restore
  239.  
  240.     .align 4
  241.     .global _cons_closure        
  242.     !# arg1 -> return address
  243.     !# arg2 -> delta from return address
  244.     !# arg3 -> closure size (in bytes)
  245.     !# arg4 -> using as an extra temp
  246.     !# s_to_i -108
  247. _cons_closure:
  248.     ld [%C_arg1], %g1
  249.     st %g1, [%free]
  250.     ld [%C_arg1 + 4], %g1
  251.     st %g1, [%free + 4]
  252.     add %g0, %g0, %C_arg4
  253.     add %C_arg2, %C_arg1, %C_arg2
  254.     sethi %hi(0x03000000), %C_arg4
  255.     srl %C_arg2, 10, %g1
  256.     add %g1, %C_arg4, %C_arg4
  257.     st %C_arg4, [%free + 8]
  258.     sethi %hi(0x83c06000), %C_arg4
  259.     and 0x3ff, %C_arg2, %g1
  260.     add %g1, %C_arg4, %C_arg4
  261.     st %C_arg4, [%free + 12]
  262.     sethi %hi(0x82006008), %C_arg4
  263.     add %lo(0x82006008), %C_arg4, %C_arg4
  264.     st %C_arg4, [%free + 16]
  265.     iflush %free + 8
  266.     iflush %free + 12
  267.     iflush %free + 16
  268.     add %free, 8, %C_arg2
  269.     add %C_arg3, %free, %free
  270.     add %C_arg1, 8, %C_arg1
  271.     jmpl %C_arg1, %g0
  272.     nop
  273.     
  274.     .align 4
  275.     .global _trampoline_to_interface    
  276.     !# s_to_i - 8
  277. _trampoline_to_interface:
  278.     add    %C_arg1, -4, %C_arg1
  279.  
  280.     .align    4
  281.     .global _link_to_interface    
  282.     !# s_to_i - 4
  283. _link_to_interface:
  284.     add    %C_arg1, 12, %C_arg1
  285.         
  286.     .align     4
  287.     .global    _scheme_to_interface
  288.     .proc    020
  289. _scheme_to_interface:
  290.     st    %value,[%registers + 8]
  291.     st    %closure_free,[%registers + 36]
  292.  
  293.     sethi    %hi(_utility_table), %g1
  294.     or    %g1, %lo(_utility_table), %g1    !# Find table
  295.     add    %g1,%utility_index,%g1        !# Address of entry
  296.     ld    [%g1],%l7            !# l7 <- Entry
  297.     nop
  298.     sethi    %hi(_Ext_Stack_Pointer), %g1
  299.     st    %stack,[%g1+%lo(_Ext_Stack_Pointer)]    !# Save Scheme stack pointer
  300.     nop
  301.     sethi    %hi(_Free), %g1
  302.     st    %free,[%g1+%lo(_Free)]        !# Save Free
  303.     nop
  304.     jmpl    %l7 + 0, %o7        !# Off to interface code
  305.     nop
  306.     unimp    8
  307.     ld    [%o0 + 4],%i0        !# Get dispatch address
  308.     ld    [%o0],%C_arg1        !# Arg1 <- value component
  309.     jmpl    %C_arg1,%o7        !# Redispatch ...
  310.     nop                !# Branch delay
  311.     
  312.     .align    4
  313.     .global    _interface_to_C
  314.     .proc    020
  315. _interface_to_C:
  316.     add    %i0,%g0,%C_arg1        !# Return value to C
  317.     ret                !# Return to the C universe
  318.     restore                !# Restore callee save regs
  319.  
  320.     .align    4
  321.     .global    _flushrange
  322.     .proc    020
  323. _flushrange:
  324.     save     %sp,-96,%sp
  325.     !# arg1: address base, arg2: byte count
  326.     add    %g0, %g0, %l0
  327. flush_l:
  328.     iflush    %i0 + %l0
  329.     add    4, %l0, %l0
  330.     subcc    %l0,%i1,%g0
  331.     bl    flush_l            !# Continue if address < address + count
  332.     nop
  333.     nop                !# flush pipeline
  334.     nop
  335.     nop
  336.     nop
  337.     nop
  338.     ret                !# Return to caller
  339.     restore                !# Restore callee save regs
  340.