0
|
1 /*
|
|
2 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 *
|
|
5 * This code is free software; you can redistribute it and/or modify it
|
|
6 * under the terms of the GNU General Public License version 2 only, as
|
|
7 * published by the Free Software Foundation.
|
|
8 *
|
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 * version 2 for more details (a copy is included in the LICENSE file that
|
|
13 * accompanied this code).
|
|
14 *
|
|
15 * You should have received a copy of the GNU General Public License version
|
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 *
|
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 inline void AbstractAssembler::sync() {
|
|
26 CodeSection* cs = code_section();
|
|
27 guarantee(cs->start() == _code_begin, "must not shift code buffer");
|
|
28 cs->set_end(_code_pos);
|
|
29 }
|
|
30
|
|
31 inline void AbstractAssembler::emit_byte(int x) {
|
|
32 assert(isByte(x), "not a byte");
|
|
33 *(unsigned char*)_code_pos = (unsigned char)x;
|
|
34 _code_pos += sizeof(unsigned char);
|
|
35 sync();
|
|
36 }
|
|
37
|
|
38
|
|
39 inline void AbstractAssembler::emit_word(int x) {
|
|
40 *(short*)_code_pos = (short)x;
|
|
41 _code_pos += sizeof(short);
|
|
42 sync();
|
|
43 }
|
|
44
|
|
45
|
|
46 inline void AbstractAssembler::emit_long(jint x) {
|
|
47 *(jint*)_code_pos = x;
|
|
48 _code_pos += sizeof(jint);
|
|
49 sync();
|
|
50 }
|
|
51
|
|
52 inline void AbstractAssembler::emit_address(address x) {
|
|
53 *(address*)_code_pos = x;
|
|
54 _code_pos += sizeof(address);
|
|
55 sync();
|
|
56 }
|
|
57
|
|
58 inline address AbstractAssembler::inst_mark() const {
|
|
59 return code_section()->mark();
|
|
60 }
|
|
61
|
|
62
|
|
63 inline void AbstractAssembler::set_inst_mark() {
|
|
64 code_section()->set_mark();
|
|
65 }
|
|
66
|
|
67
|
|
68 inline void AbstractAssembler::clear_inst_mark() {
|
|
69 code_section()->clear_mark();
|
|
70 }
|
|
71
|
|
72
|
|
73 inline void AbstractAssembler::relocate(RelocationHolder const& rspec, int format) {
|
|
74 assert(!pd_check_instruction_mark()
|
|
75 || inst_mark() == NULL || inst_mark() == _code_pos,
|
|
76 "call relocate() between instructions");
|
|
77 code_section()->relocate(_code_pos, rspec, format);
|
|
78 }
|
|
79
|
|
80
|
|
81 inline CodeBuffer* AbstractAssembler::code() const {
|
|
82 return code_section()->outer();
|
|
83 }
|
|
84
|
|
85 inline int AbstractAssembler::sect() const {
|
|
86 return code_section()->index();
|
|
87 }
|
|
88
|
|
89 inline int AbstractAssembler::locator() const {
|
|
90 return CodeBuffer::locator(offset(), sect());
|
|
91 }
|
|
92
|
|
93 inline address AbstractAssembler::target(Label& L) {
|
|
94 return code_section()->target(L, pc());
|
|
95 }
|
|
96
|
|
97 inline int Label::loc_pos() const {
|
|
98 return CodeBuffer::locator_pos(loc());
|
|
99 }
|
|
100
|
|
101 inline int Label::loc_sect() const {
|
|
102 return CodeBuffer::locator_sect(loc());
|
|
103 }
|
|
104
|
|
105 inline void Label::bind_loc(int pos, int sect) {
|
|
106 bind_loc(CodeBuffer::locator(pos, sect));
|
|
107 }
|
|
108
|
|
109 address AbstractAssembler::address_constant(Label& L) {
|
|
110 address c = NULL;
|
|
111 address ptr = start_a_const(sizeof(c), sizeof(c));
|
|
112 if (ptr != NULL) {
|
|
113 relocate(Relocation::spec_simple(relocInfo::internal_word_type));
|
|
114 *(address*)ptr = c = code_section()->target(L, ptr);
|
|
115 _code_pos = ptr + sizeof(c);
|
|
116 end_a_const();
|
|
117 }
|
|
118 return ptr;
|
|
119 }
|
|
120
|
|
121 address AbstractAssembler::address_table_constant(GrowableArray<Label*> labels) {
|
|
122 int addressSize = sizeof(address);
|
|
123 int sizeLabel = addressSize * labels.length();
|
|
124 address ptr = start_a_const(sizeLabel, addressSize);
|
|
125
|
|
126 if (ptr != NULL) {
|
|
127 address *labelLoc = (address*)ptr;
|
|
128 for (int i=0; i < labels.length(); i++) {
|
|
129 emit_address(code_section()->target(*labels.at(i), (address)&labelLoc[i]));
|
|
130 code_section()->relocate((address)&labelLoc[i], relocInfo::internal_word_type);
|
|
131 }
|
|
132 end_a_const();
|
|
133 }
|
|
134 return ptr;
|
|
135 }
|