segmentation.py revision 5292:a26311673ef0
12068SN/A# Copyright (c) 2007 The Hewlett-Packard Development Company
22068SN/A# All rights reserved.
32068SN/A#
42068SN/A# Redistribution and use of this software in source and binary forms,
52068SN/A# with or without modification, are permitted provided that the
62068SN/A# following conditions are met:
72068SN/A#
82068SN/A# The software must be used only for Non-Commercial Use which means any
92068SN/A# use which is NOT directed to receiving any direct monetary
102068SN/A# compensation for, or commercial advantage from such use.  Illustrative
112068SN/A# examples of non-commercial use are academic research, personal study,
122068SN/A# teaching, education and corporate research & development.
132068SN/A# Illustrative examples of commercial use are distributing products for
142068SN/A# commercial advantage and providing services using the software for
152068SN/A# commercial advantage.
162068SN/A#
172068SN/A# If you wish to use this software or functionality therein that may be
182068SN/A# covered by patents for commercial use, please contact:
192068SN/A#     Director of Intellectual Property Licensing
202068SN/A#     Office of Strategy and Technology
212068SN/A#     Hewlett-Packard Company
222068SN/A#     1501 Page Mill Road
232068SN/A#     Palo Alto, California  94304
242068SN/A#
252068SN/A# Redistributions of source code must retain the above copyright notice,
262068SN/A# this list of conditions and the following disclaimer.  Redistributions
272068SN/A# in binary form must reproduce the above copyright notice, this list of
282665Ssaidi@eecs.umich.edu# conditions and the following disclaimer in the documentation and/or
292665Ssaidi@eecs.umich.edu# other materials provided with the distribution.  Neither the name of
302068SN/A# the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
312649Ssaidi@eecs.umich.edu# contributors may be used to endorse or promote products derived from
322649Ssaidi@eecs.umich.edu# this software without specific prior written permission.  No right of
332649Ssaidi@eecs.umich.edu# sublicense is granted herewith.  Derivatives of the software and
342649Ssaidi@eecs.umich.edu# output created using the software may be prepared, but only for
352649Ssaidi@eecs.umich.edu# Non-Commercial Uses.  Derivatives of the software may be shared with
362068SN/A# others provided: (i) the others agree to abide by the list of
372068SN/A# conditions herein which includes the Non-Commercial Use restrictions;
382068SN/A# and (ii) such Derivatives of the software include the above copyright
392068SN/A# notice to acknowledge the contribution from this software where
402068SN/A# applicable, this list of conditions and the disclaimer below.
412068SN/A#
422068SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
432068SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
442068SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
452068SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
462068SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
472227SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
482068SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
492068SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
502068SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
512068SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5212616Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5312616Sgabeblack@google.com#
542068SN/A# Authors: Gabe Black
552068SN/A
562068SN/Amicrocode = '''
572068SN/Adef macroop LGDT_M
582068SN/A{
592068SN/A    .adjust_env oszForPseudoDesc
602068SN/A
612068SN/A    # Get the limit
622068SN/A    ld t1, seg, sib, disp, dataSize=2
632068SN/A    # Get the base
642068SN/A    ld t2, seg, sib, 'adjustedDisp + 2'
652068SN/A    wrbase gdtr, t2
662068SN/A    wrlimit gdtr, t1
672068SN/A};
682068SN/A
692068SN/Adef macroop LGDT_P
702068SN/A{
712068SN/A    .adjust_env oszForPseudoDesc
722068SN/A
732068SN/A    rdip t7
742068SN/A    # Get the limit
752068SN/A    ld t1, seg, riprel, disp, dataSize=2
762068SN/A    # Get the base
772068SN/A    ld t2, seg, riprel, 'adjustedDisp + 2'
782068SN/A    wrbase gdtr, t2
792068SN/A    wrlimit gdtr, t1
802068SN/A};
812068SN/A
822068SN/A#
832068SN/A# These versions are for when the original data size was 16 bits. The base is
842068SN/A# still 32 bits, but the top byte is zeroed before being used.
852068SN/A#
862068SN/A
872068SN/Adef macroop LGDT_16_M
882068SN/A{
892068SN/A    .adjust_env oszForPseudoDesc
902068SN/A
912068SN/A    # Get the limit
922068SN/A    ld t1, seg, sib, disp, dataSize=2
932068SN/A    # Get the base
942068SN/A    ld t2, seg, sib, 'adjustedDisp + 2', dataSize=4
952068SN/A    zexti t2, t2, 23
962068SN/A    wrbase gdtr, t2
972068SN/A    wrlimit gdtr, t1
982068SN/A};
992068SN/A
1002068SN/Adef macroop LGDT_16_P
1012068SN/A{
1022068SN/A    .adjust_env oszForPseudoDesc
1032068SN/A
1042068SN/A    rdip t7
1052068SN/A    # Get the limit
1062068SN/A    ld t1, seg, riprel, disp, dataSize=2
1072068SN/A    # Get the base
1082068SN/A    ld t2, seg, riprel, 'adjustedDisp + 2', dataSize=4
1092068SN/A    zexti t2, t2, 23
1102068SN/A    wrbase gdtr, t2
1112068SN/A    wrlimit gdtr, t1
1122068SN/A};
1138588Sgblack@eecs.umich.edu
1142068SN/Adef macroop LIDT_M
1152068SN/A{
1163953Sstever@eecs.umich.edu    .adjust_env oszForPseudoDesc
1172068SN/A
1182068SN/A    # Get the limit
1192068SN/A    ld t1, seg, sib, disp, dataSize=2
1202068SN/A    # Get the base
1212068SN/A    ld t2, seg, sib, 'adjustedDisp + 2'
1222068SN/A    wrbase idtr, t2
1233953Sstever@eecs.umich.edu    wrlimit idtr, t1
1242068SN/A};
1252068SN/A
1262068SN/Adef macroop LIDT_P
1272068SN/A{
1282068SN/A    .adjust_env oszForPseudoDesc
1292068SN/A
1302068SN/A    rdip t7
1312068SN/A    # Get the limit
1322068SN/A    ld t1, seg, riprel, disp, dataSize=2
1332068SN/A    # Get the base
134    ld t2, seg, riprel, 'adjustedDisp + 2'
135    wrbase idtr, t2
136    wrlimit idtr, t1
137};
138
139#
140# These versions are for when the original data size was 16 bits. The base is
141# still 32 bits, but the top byte is zeroed before being used.
142#
143
144def macroop LIDT_16_M
145{
146    .adjust_env oszForPseudoDesc
147
148    # Get the limit
149    ld t1, seg, sib, disp, dataSize=2
150    # Get the base
151    ld t2, seg, sib, 'adjustedDisp + 2', dataSize=4
152    zexti t2, t2, 23
153    wrbase idtr, t2
154    wrlimit idtr, t1
155};
156
157def macroop LIDT_16_P
158{
159    .adjust_env oszForPseudoDesc
160
161    rdip t7
162    # Get the limit
163    ld t1, seg, riprel, disp, dataSize=2
164    # Get the base
165    ld t2, seg, riprel, 'adjustedDisp + 2', dataSize=4
166    zexti t2, t2, 23
167    wrbase idtr, t2
168    wrlimit idtr, t1
169};
170'''
171