|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 using System; |
|
18 using System.Collections.Generic; |
|
19 using System.Text; |
|
20 using System.Text.RegularExpressions; |
|
21 using System.IO; |
|
22 using SymbianStructuresLib.Arm.Registers; |
|
23 |
|
24 namespace SymbianInstructionLib.Arm.Instructions.Common |
|
25 { |
|
26 internal static class ArmInstructionUtils |
|
27 { |
|
28 public static int SignExtend24BitTo32Bit( uint aImmediate ) |
|
29 { |
|
30 int offset; |
|
31 // |
|
32 unchecked |
|
33 { |
|
34 if ( ( aImmediate & 0x00800000 ) == 0x00800000 ) |
|
35 { |
|
36 offset = (int) ( 0xff000000 | aImmediate ); |
|
37 } |
|
38 else |
|
39 { |
|
40 offset = (int) aImmediate; |
|
41 } |
|
42 } |
|
43 // |
|
44 offset <<= 2; |
|
45 offset += 8; // pipeline |
|
46 return offset; |
|
47 } |
|
48 |
|
49 public static List<TArmRegisterType> ExtractGPRegisterList( uint aEncodedList ) |
|
50 { |
|
51 List<TArmRegisterType> ret = new List<TArmRegisterType>(); |
|
52 // |
|
53 for ( int i = 15; i >= 0; i-- ) |
|
54 { |
|
55 uint mask = (uint) ( 1 << i ); |
|
56 if ( ( aEncodedList & mask ) == mask ) |
|
57 { |
|
58 ret.Add( (TArmRegisterType) i ); |
|
59 } |
|
60 } |
|
61 // |
|
62 return ret; |
|
63 } |
|
64 } |
|
65 |
|
66 internal static class ThumbInstructionUtils |
|
67 { |
|
68 public static int SignExtend11BitTo32Bit( uint aImmediate ) |
|
69 { |
|
70 int offset = SignExtend11BitTo32Bit( aImmediate, 1 ); |
|
71 offset += 4; // pipeline |
|
72 return offset; |
|
73 } |
|
74 |
|
75 public static int SignExtend11BitTo32Bit( uint aImmediate, int aLeftShiftCount ) |
|
76 { |
|
77 int offset; |
|
78 // |
|
79 unchecked |
|
80 { |
|
81 // 10 9 8 7 6 5 4 3 2 1 0 |
|
82 // ---------------------------------- |
|
83 // 1 0 0 0 0 0 0 0 0 0 0 |
|
84 if ( ( aImmediate & 0x00000400 ) == 0x00000400 ) |
|
85 { |
|
86 // 11111111111111111111100000000000 |
|
87 // 10000000000 |
|
88 offset = (int) ( 0xFFFFF800 | aImmediate ); |
|
89 } |
|
90 else |
|
91 { |
|
92 offset = (int) aImmediate; |
|
93 } |
|
94 } |
|
95 // |
|
96 offset <<= aLeftShiftCount; |
|
97 return offset; |
|
98 } |
|
99 |
|
100 public static int SignExtend8BitTo32Bit( uint aImmediate ) |
|
101 { |
|
102 int offset; |
|
103 // |
|
104 unchecked |
|
105 { |
|
106 // 7 6 5 4 3 2 1 0 |
|
107 // ------------------------ |
|
108 // 1 0 0 0 0 0 0 0 |
|
109 if ( ( aImmediate & 0x00000080 ) == 0x00000080 ) |
|
110 { |
|
111 // 11111111111111111111111100000000 |
|
112 // 10000000 |
|
113 offset = (int) ( 0xFFFFFF00 | aImmediate ); |
|
114 } |
|
115 else |
|
116 { |
|
117 offset = (int) aImmediate; |
|
118 } |
|
119 } |
|
120 // |
|
121 offset <<= 1; |
|
122 offset += 4; // pipeline |
|
123 return offset; |
|
124 } |
|
125 } |
|
126 } |