19895Sandreas@sandberg.pp.se# Copyright (c) 2013 Andreas Sandberg
25081Sgblack@eecs.umich.edu# All rights reserved.
35081Sgblack@eecs.umich.edu#
47087Snate@binkert.org# Redistribution and use in source and binary forms, with or without
57087Snate@binkert.org# modification, are permitted provided that the following conditions are
67087Snate@binkert.org# met: redistributions of source code must retain the above copyright
77087Snate@binkert.org# notice, this list of conditions and the following disclaimer;
87087Snate@binkert.org# redistributions in binary form must reproduce the above copyright
97087Snate@binkert.org# notice, this list of conditions and the following disclaimer in the
107087Snate@binkert.org# documentation and/or other materials provided with the distribution;
117087Snate@binkert.org# neither the name of the copyright holders nor the names of its
125081Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from
137087Snate@binkert.org# this software without specific prior written permission.
145081Sgblack@eecs.umich.edu#
155081Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
165081Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
175081Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
185081Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
195081Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
205081Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
215081Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
225081Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
235081Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
245081Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
255081Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
265081Sgblack@eecs.umich.edu#
279895Sandreas@sandberg.pp.se# Authors: Andreas Sandberg
289895Sandreas@sandberg.pp.se
299895Sandreas@sandberg.pp.se
309895Sandreas@sandberg.pp.se# Register usage:
319895Sandreas@sandberg.pp.se#  t1, t2 == temporaries
329895Sandreas@sandberg.pp.se
339895Sandreas@sandberg.pp.sefldenvTemplate = """
349895Sandreas@sandberg.pp.se    ld t1, seg, %(mode)s, "DISPLACEMENT + 0", dataSize=2
359895Sandreas@sandberg.pp.se    wrval fcw, t1
369895Sandreas@sandberg.pp.se
379895Sandreas@sandberg.pp.se    ld t1, seg, %(mode)s, "DISPLACEMENT + 4", dataSize=2
389895Sandreas@sandberg.pp.se    wrval fsw, t1
399895Sandreas@sandberg.pp.se
409895Sandreas@sandberg.pp.se    ld t1, seg, %(mode)s, "DISPLACEMENT + 8", dataSize=2
419895Sandreas@sandberg.pp.se    wrval ftw, t1
429895Sandreas@sandberg.pp.se
439895Sandreas@sandberg.pp.se    ld t1, seg, %(mode)s, "DISPLACEMENT + 12", dataSize=4
449895Sandreas@sandberg.pp.se    wrval "InstRegIndex(MISCREG_FIOFF)", t1
459895Sandreas@sandberg.pp.se
469895Sandreas@sandberg.pp.se    ld t1, seg, %(mode)s, "DISPLACEMENT + 16 + 0", dataSize=2
479895Sandreas@sandberg.pp.se    wrval "InstRegIndex(MISCREG_FISEG)", t1
489895Sandreas@sandberg.pp.se
499895Sandreas@sandberg.pp.se    ld t1, seg, %(mode)s, "DISPLACEMENT + 16 + 2", dataSize=2
509895Sandreas@sandberg.pp.se    wrval "InstRegIndex(MISCREG_FOP)", t1
519895Sandreas@sandberg.pp.se
529895Sandreas@sandberg.pp.se    ld t1, seg, %(mode)s, "DISPLACEMENT + 20", dataSize=4
539895Sandreas@sandberg.pp.se    wrval "InstRegIndex(MISCREG_FOOFF)", t1
549895Sandreas@sandberg.pp.se
559895Sandreas@sandberg.pp.se    ld t1, seg, %(mode)s, "DISPLACEMENT + 24", dataSize=2
569895Sandreas@sandberg.pp.se    wrval "InstRegIndex(MISCREG_FOSEG)", t1
579895Sandreas@sandberg.pp.se"""
589895Sandreas@sandberg.pp.se
599895Sandreas@sandberg.pp.sefnstenvTemplate = """
609895Sandreas@sandberg.pp.se    rdval t2, fcw
619895Sandreas@sandberg.pp.se    st t2, seg, %(mode)s, "DISPLACEMENT + 0", dataSize=2
629895Sandreas@sandberg.pp.se
639895Sandreas@sandberg.pp.se    # FSW includes TOP when read
649895Sandreas@sandberg.pp.se    rdval t1, fsw
659895Sandreas@sandberg.pp.se    st t1, seg, %(mode)s, "DISPLACEMENT + 4", dataSize=2
6612368Sgabeblack@google.com    srli t1, t1, 11, dataSize=2
6712368Sgabeblack@google.com    andi t1, t1, 0x7, dataSize=2
6812368Sgabeblack@google.com    wrval "InstRegIndex(MISCREG_X87_TOP)", t1
699895Sandreas@sandberg.pp.se
709895Sandreas@sandberg.pp.se    rdval t1, ftw
719895Sandreas@sandberg.pp.se    st t1, seg, %(mode)s, "DISPLACEMENT + 8", dataSize=2
729895Sandreas@sandberg.pp.se
739895Sandreas@sandberg.pp.se    rdval t1, "InstRegIndex(MISCREG_FIOFF)"
749895Sandreas@sandberg.pp.se    st t1, seg, %(mode)s, "DISPLACEMENT + 12", dataSize=4
759895Sandreas@sandberg.pp.se
769895Sandreas@sandberg.pp.se    rdval t1, "InstRegIndex(MISCREG_FISEG)"
779895Sandreas@sandberg.pp.se    st t1, seg, %(mode)s, "DISPLACEMENT + 16 + 0", dataSize=2
789895Sandreas@sandberg.pp.se
799895Sandreas@sandberg.pp.se    rdval t1, "InstRegIndex(MISCREG_FOP)"
809895Sandreas@sandberg.pp.se    st t1, seg, %(mode)s, "DISPLACEMENT + 16 + 2", dataSize=2
819895Sandreas@sandberg.pp.se
829895Sandreas@sandberg.pp.se    rdval t1, "InstRegIndex(MISCREG_FOOFF)"
839895Sandreas@sandberg.pp.se    st t1, seg, %(mode)s, "DISPLACEMENT + 20", dataSize=4
849895Sandreas@sandberg.pp.se
859895Sandreas@sandberg.pp.se    rdval t1, "InstRegIndex(MISCREG_FOSEG)"
869895Sandreas@sandberg.pp.se    st t1, seg, %(mode)s, "DISPLACEMENT + 24", dataSize=2
879895Sandreas@sandberg.pp.se
889895Sandreas@sandberg.pp.se    # Mask exceptions
899895Sandreas@sandberg.pp.se    ori t2, t2, 0x3F
909895Sandreas@sandberg.pp.se    wrval fcw, t2
919895Sandreas@sandberg.pp.se"""
925081Sgblack@eecs.umich.edu
935081Sgblack@eecs.umich.edumicrocode = '''
949895Sandreas@sandberg.pp.sedef macroop FLDENV_M {
959895Sandreas@sandberg.pp.se''' + fldenvTemplate % { "mode" : "sib" } + '''
969895Sandreas@sandberg.pp.se};
979895Sandreas@sandberg.pp.se
989895Sandreas@sandberg.pp.sedef macroop FLDENV_P {
999895Sandreas@sandberg.pp.se    rdip t7
1009895Sandreas@sandberg.pp.se''' + fldenvTemplate % { "mode" : "riprel" } + '''
1019895Sandreas@sandberg.pp.se};
1029895Sandreas@sandberg.pp.se
1039895Sandreas@sandberg.pp.sedef macroop FNSTENV_M {
1049895Sandreas@sandberg.pp.se''' + fnstenvTemplate % { "mode" : "sib" } + '''
1059895Sandreas@sandberg.pp.se};
1069895Sandreas@sandberg.pp.se
1079895Sandreas@sandberg.pp.sedef macroop FNSTENV_P {
1089895Sandreas@sandberg.pp.se    rdip t7
1099895Sandreas@sandberg.pp.se''' + fnstenvTemplate % { "mode" : "riprel" } + '''
1109895Sandreas@sandberg.pp.se};
1115081Sgblack@eecs.umich.edu'''
112