File: tyaasm.S

package info (click to toggle)
tya 1.6-1
  • links: PTS
  • area: contrib
  • in suites: potato
  • size: 628 kB
  • ctags: 843
  • sloc: ansic: 7,028; asm: 618; java: 497; makefile: 88; sh: 18
file content (350 lines) | stat: -rw-r--r-- 8,114 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
// Copyright (c) 1998 Albrecht Kleine    All rights reserved
// file version #300

#define TYAASM_S
#include "tyaconfig.h"
#include "tya.h"

#undef  TYAASM_S

.text

#ifdef USEASM

.globl FastInvPrepare
//
// this looks from C side as follows: 
//
// void* FastInvPrepare(struct execenv *ee,struct methodblock *mbpcalled,stack_item *sp);
//                                = ecx                   = eax          = 12(%esp)
//
	.type	FastInvPrepare,@function
	.align 16
FastInvPrepare:
	movl CFR_OFF(%ecx),%edx	// cfr
	leal 44(%edx),%ebx	// new JF
//
//	if ((char*)JF > (char*)ee->current_frame->javastack->end_data)
// 	  StOvExcHandler();
//
	movl 20(%edx),%edx	// cfr->jstc
	//
	movl 12(%edx),%edx	// end_data @ 12
	subl $100,%edx
	cmpl %ebx,%edx
	movl CFR_OFF(%ecx),%edx	// == ee->current_frame
	//
	jb .FICheckStackOver	// stackoverflow handling
	// ====== ebx is the desired new JF ========
	movl %edx,16(%ebx)	// JF->prev=ee->current_frame;
	movl 20(%edx),%edx	//
	movl %eax,28(%ebx)	// JF->current_method=mbpcalled;	
	movl %edx,20(%ebx)	// JF->javastack=ee->current_frame->javastack;
	leal 40(%ebx),%edx	// 
	movl %edx,8(%ebx)	// JF->optop=JF->ostack;
	
	movl 12(%esp),%edx	// == stack_item *sp
	movl %edx,12(%ebx)	// JF->vars=sp;
	
	movl %ebx,CFR_OFF(%ecx)	// ee->current_frame=JF
	movl 16(%ebx),%ebx	// == now the prev frame
	ret


.globl FastInvCheck32,FastInvNoCheck32
//
// this looks from C side as follows: 
//
// void* FastInvCheck(struct execenv *ee,struct methodblock *mbpcalled,stack_item *sp);
//                                = ecx                   = eax          = 12(%esp)
//
	.type	FastInvCheck32,@function
	
	.align 16
FastInvCheck32:
	movl 68(%eax),%edx
	testl %edx,%edx

	je FICheck32_2	
FastInvNoCheck32:
	movl CFR_OFF(%ecx),%edx	// cfr
	leal 44(%edx),%ebx	// new JF
//
//	if ((char*)JF > (char*)ee->current_frame->javastack->end_data)
// 	  StOvExcHandler();
//
	movl 20(%edx),%edx	// cfr->jstc
	//// OLD: cmpl %ebx,12(%edx)	// end_data @ 12
	//
	movl 12(%edx),%edx	// end_data @ 12
	subl $100,%edx
	cmpl %ebx,%edx
	movl CFR_OFF(%ecx),%edx	// == ee->current_frame
	//
	jb .FICheckStackOver	// stackoverflow handling
	// ====== ebx is the desired new JF ========
	movl %edx,16(%ebx)	// JF->prev=ee->current_frame;
	movl 20(%edx),%edx	//
	movl %eax,28(%ebx)	// JF->current_method=mbpcalled;	
	movl %edx,20(%ebx)	// JF->javastack=ee->current_frame->javastack;
	leal 40(%ebx),%edx	// 
	movl %edx,8(%ebx)	// JF->optop=JF->ostack;
	
	movl 12(%esp),%edx	// == stack_item *sp
	movl %edx,12(%ebx)	// JF->vars=sp;
	
	movw LV_OFF(%eax),%edx	// current_method->nlocals in lower 16 bit
	movl %ebx,CFR_OFF(%ecx)	// ee->current_frame=JF
	//
	shll $16,%edx
	movl 68(%eax),%eax	// == compiled code
	shrl $14,%edx		// shl,shr is for mul 4
	//	
	movl 16(%ebx),%ebx	// == now the prev frame
	ret
	
	// returning:
	// eax is mbpcalled->CompiledCode  /  ecx is ee   /  ebx is ee->current_frame->prev
//	
//	JF++;
//	JF->vars=sp;
//	JF->prev=ee->current_frame;
//	JF->current_method=mbpcalled;
//	JF->javastack=ee->current_frame->javastack;
//	JF->optop=JF->ostack;
//	ee->current_frame=JF;
//
	.align 16
FICheck32_2:
#ifndef JDK12
	testb $1,17(%eax)		// this is ACC_NATIVE's hibyte
#else	
	testb $1,13(%eax)		// this is ACC_NATIVE's hibyte
#endif
	jne FICheck32_3

	pushl %ecx 
	pushl %eax 
	call JITCompileMethod
	testl %eax,%eax
	popl %eax
	popl %ecx
	jne FastInvNoCheck32
FICheck32_3:
	movl CFR_OFF(%ecx),%ebx
	movl $CodeRunner32_withDummies,%eax
	movl $0,%edx
	ret

/////////////////////////////////////////////////////////////////

.globl FastInvCheck64,FastInvNoCheck64
	.type	 FastInvCheck64,@function
	.align 16
FastInvCheck64:
	movl 68(%eax),%edx
	testl %edx,%edx

	je FICheck64_2
FastInvNoCheck64:
	movl CFR_OFF(%ecx),%edx	// cfr
	leal 44(%edx),%ebx	// new JF
//
//	if ((char*)JF > (char*)ee->current_frame->javastack->end_data)
// 	  StOvExcHandler();
//
	movl 20(%edx),%edx	// cfr->jstc
	//// OLD: cmpl %ebx,12(%edx)	// end_data @ 12
	//
	movl 12(%edx),%edx	// end_data @ 12
	subl $100,%edx
	cmpl %ebx,%edx
	movl CFR_OFF(%ecx),%edx	// == ee->current_frame
	//
	jb .FICheckStackOver	// stackoverflow handling
	//
	movl %edx,16(%ebx)
	movl 20(%edx),%edx
	movl %eax,28(%ebx)	// JF->current_method=mbpcalled;	
	movl %edx,20(%ebx)
	leal 40(%ebx),%edx
	movl %edx,8(%ebx)	// ebx is ee->current_frame

	movl 12(%esp),%edx	// == stack_item *sp	
	movl %edx,12(%ebx)
	
	movw LV_OFF(%eax),%edx	// we need (short) current_method->nlocals
	movl %ebx,CFR_OFF(%ecx)	// ee->current_frame=JF
	//
	shll $16,%edx
	movl 68(%eax),%eax	// == compiled code
	//	
	shrl $14,%edx
	movl 16(%ebx),%ebx	// ...->prev    [ also via subl $44,%ebx ]
	ret
	// returning:
	// eax is mbpcalled->CompiledCode  /  ecx is ee   /  ebx is ee->current_frame->prev
//	
//	JF++;
//	JF->vars=sp;
//	JF->prev=ee->current_frame;
//	JF->current_method=mbpcalled;
//	JF->javastack=ee->current_frame->javastack;
//	JF->optop=JF->ostack;
//	ee->current_frame=JF;
//
	.align 16
FICheck64_2:
#ifndef JDK12
	testb $1,17(%eax)		// this is ACC_NATIVE's hibyte
#else	
	testb $1,13(%eax)		// this is ACC_NATIVE's hibyte
#endif
	jne FICheck64_3

	pushl %ecx 
	pushl %eax 
	call JITCompileMethod
	testl %eax,%eax
	popl %eax
	popl %ecx
	jne FastInvNoCheck64
	
FICheck64_3:
	movl $CodeRunner64_withDummies,%eax
	movl CFR_OFF(%ecx),%ebx
	movl $0,%edx
	ret

//////////////////////////////////////////////////////////////

//FIXME12

// special stack overflow handling: similar above, but not the same.....
// jmp'd by all FastInvCheckXX if no more space on Java stack condition

	.align 16
.FICheckStackOver:
	movl 20(%edx),%edx	// cfr->jstc

	cmpl $TYA_JSTACK,16(%edx)// stack_so_far @ 16 compared with max (def. in tya.h)
	jb  .FICSOver1
	call StOvExcHandler

.FICSOver1:
	pushl %eax		// save mbp
	movl 8(%edx),%eax 	// edx this_stack, eax nextstack
	testl %eax,%eax
	jnz nextstack

#ifdef JDK12
	pushl min_javastack_chunk_size
#endif	
	pushl %edx	// prev stac
	pushl %ecx	// ee
	call CreateNewJavaStack
	popl %ecx
	popl %edx
#ifdef JDK12	
	popl %ebx	// dummy
#endif	
nextstack:
	// eax = new stack
	leal 20(%eax),%ebx	// data @ 20
	// ====== ebx is the desired new JF ========
		
	movl 16(%esp),%edx	// == stack_item *sp
	/* ==16 because pushax above */

	movl %edx,12(%ebx)	// JF->vars=sp;
	movl CFR_OFF(%ecx),%edx	// 
	movl %edx,16(%ebx)	// JF->prev=ee->current_frame;
	movl %eax,20(%ebx)	// JF->javastack=NEW_created_java_stack;
	//	
	popl %eax		// restore mbp
	movl %eax,28(%ebx)	// JF->current_method=mbpcalled;
	leal 40(%ebx),%edx	// 
	movl %edx,8(%ebx)	// JF->optop=JF->ostack;
	movl %ebx,CFR_OFF(%ecx)	// ee->current_frame=JF
	//
	movzwl LV_OFF(%eax),%edx	// (short) current_method->nlocals
	shll $2,%edx		// * 4
	movl 68(%eax),%eax	// == compiled code
	//	
	movl 16(%ebx),%ebx	// == now the prev frame
	ret

#endif


//////////////////////////////////////////////////////////////
#ifdef USEASM
#ifdef INIT0
	.align 16
.globl MyObjAlloc
	.type	 MyObjAlloc,@function
MyObjAlloc:
	// expecting class in eax
	pushl $0
	pushl %eax
	call ObjAlloc
	popl %ebx
	popl %ecx
	testl %eax,%eax
	je .MyObjAlloc2
	movl (%ebx),%edx	// unhand(class)
	movl %edi,%ebx		// save edi
	movl (%eax),%edi	// unhand(object)

	movzwl 84(%edx),%ecx
	movl %eax,%edx
	shrl $0x2,%ecx
	xorl %eax,%eax
	cld
	rep 
	stosl %es:(%edi)
	movl %edx,%eax
	movl %ebx,%edi		// restore edi
	ret
.MyObjAlloc2:
	jmp out_of_memory
#endif
#endif
//////////////////////////////////////////////////////////////


	.align 16
.globl StOvExcHandler
	.type	 StOvExcHandler,@function
StOvExcHandler:

#ifndef USEASM
	movl %ebp,%esp			// discard caller's C stack frame
	popl %ebp			// for access to stack pointer
#endif
	call EE
	pushl StOvExc			// params for ExecExcep
	pushl %eax
	jmp SEH1			// exc is not catchable inside method


/////////////////////////////////////////////////////////////


	.align 16
.globl SimpleExcHandler
	.type	 SimpleExcHandler,@function
SimpleExcHandler:
	pushl %eax			// expecting in eax: ExcObject
	movl (LOCSTART-16)(%ebp),%edx	// get EE into ecx
	pushl %edx
SEH1:	
	call ExecExcep
	movl %ebp,%esp			// standard epilog
	popl %ebp
	popl %edi
	popl %esi
	popl %ebx
	ret