summaryrefslogtreecommitdiffstats
path: root/c/src/exec/score/cpu/a29k/cpu_asm.s
blob: bdbbfa604fdd718a4cd55a7b400108325bd31343 (plain) (blame)
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
;/*  cpu_asm.c  ===> cpu_asm.S or cpu_asm.s
; *
; *  Author:  Craig Lebakken <craigl@transition.com>
; *
; *  COPYRIGHT (c) 1996 by Transition Networks Inc.
; *
; *  To anyone who acknowledges that this file is provided "AS IS"
; *  without any express or implied warranty:
; *   permission to use, copy, modify, and distribute this file
; *   for any purpose is hereby granted without fee, provided that
; *   the above copyright notice and this notice appears in all
; *   copies, and that the name of Transition Networks not be used in
; *   advertising or publicity pertaining to distribution of the
; *   software without specific, written prior permission.
; *   Transition Networks makes no representations about the suitability
; *   of this software for any purpose.
; *
; *
; *  This file contains the basic algorithms for all assembly code used
; *  in an specific CPU port of RTEMS.  These algorithms must be implemented
; *  in assembly language
; *
; *  NOTE:  This is supposed to be a .S or .s file NOT a C file.
; *
; *  COPYRIGHT (c) 1989-1997.
; *  On-Line Applications Research Corporation (OAR).
; *  Copyright assigned to U.S. Government, 1994.
; *
; *  The license and distribution terms for this file may be
; *  found in the file LICENSE in this distribution or at
; *  http://www.OARcorp.com/rtems/license.html.
; *
; *  $Id$
; */

;/*
; *  This is supposed to be an assembly file.  This means that system.h
; *  and cpu.h should not be included in a "real" cpu_asm file.  An
; *  implementation in assembly should include "cpu_asm.h>
; */

;#include <cpu_asm.h>
        .include "register.ah"
        .include "amd.ah"
        .include "pswmacro.ah"
;	.extern _bsp_exit 
;
; push a register onto the struct
        .macro  spush, sp, reg
        store   0, 0, reg, sp           ; push register
        add     sp, sp, 4               ; adjust stack pointer
        .endm
; push a register onto the struct
        .macro  spushsr, sp, reg, sr
	mfsr	reg, sr
        store   0, 0, reg, sp           ; push register
        add     sp, sp, 4               ; adjust stack pointer
        .endm
; pop a register from the struct
        .macro  spop, reg, sp
        load    0, 0, reg, sp
	add	sp,sp,4
        .endm
; pop a special register from the struct
	.macro  spopsr, sreg, reg, sp
	load    0, 0, reg, sp
	mtsr    sreg, reg
	add	sp,sp,4
	.endm
;
;/*
; *  _CPU_Context_save_fp_context
; *
; *  This routine is responsible for saving the FP context
; *  at *fp_context_ptr.  If the point to load the FP context
; *  from is changed then the pointer is modified by this routine.
; *
; *  Sometimes a macro implementation of this is in cpu.h which dereferences
; *  the ** and a similarly named routine in this file is passed something
; *  like a (Context_Control_fp *).  The general rule on making this decision
; *  is to avoid writing assembly language.
; */

;#if 0
;void _CPU_Context_save_fp(
;  void **fp_context_ptr
;)
;{
;}
;#endif
	.global _CPU_Context_save_fp
_CPU_Context_save_fp:
	jmpi	lr0
	nop

;/*
; *  _CPU_Context_restore_fp_context
; *
; *  This routine is responsible for restoring the FP context
; *  at *fp_context_ptr.  If the point to load the FP context
; *  from is changed then the pointer is modified by this routine.
; *
; *  Sometimes a macro implementation of this is in cpu.h which dereferences
; *  the ** and a similarly named routine in this file is passed something
; *  like a (Context_Control_fp *).  The general rule on making this decision
; *  is to avoid writing assembly language.
; */

;#if 0
;void _CPU_Context_restore_fp(
;  void **fp_context_ptr
;)
;{
;}
;#endif
	.global __CPU_Context_restore_fp
__CPU_Context_restore_fp:
	jmpi	lr0
	nop

;/*  _CPU_Context_switch
; *
; *  This routine performs a normal non-FP context switch.
; */
;#if 0
;void _CPU_Context_switch(
;  Context_Control  *run,
;  Context_Control  *heir
;)
;{
;}
;#endif
        .global __CPU_Context_switch
__CPU_Context_switch:
        asneq   106, gr1, gr1                    	; syscall
        jmpi    lr0                                     ;
        nop                                             ;



	.global	_a29k_context_switch_sup
_a29k_context_switch_sup:
	add     pcb,lr2,0
	add     kt1,lr3,0	;move heir pointer to safe location
	constn  it0,SIG_SYNC
	spush   pcb,it0
	spush   pcb,gr1
	spush   pcb,rab     	;push rab
	spushsr pcb,it0,pc0 	;push specials
	spushsr pcb,it0,pc1
	add     pcb,pcb,1*4     ;space pc2
	spushsr pcb,it0,CHA	;push CHA
	spushsr pcb,it0,CHD  	;push CHD
	spushsr pcb,it0,CHC 	;push CHC
	add     pcb,pcb,1*4     ;space for alu
	spushsr	pcb,it0,ops     ;push OPS
	mfsr    kt0,cps         ;current status
	const   it1,FZ          ;FZ constant
	andn    it1,kt0,it1     ;clear FZ bit
	mtsr    cps,it1         ;cps without FZ
	add     pcb,pcb,1*4     ;space for tav
	mtsrim  chc,0           ;possible DERR
;
	spush   pcb,lr1 	;push R-stack
	spush   pcb,rfb 	; support
	spush   pcb,msp 	;push M-stack pnt.
;
	add	pcb,pcb,3*4	;space for floating point
;	spush   pcb,FPStat0 	;floating point
;	spush   pcb,FPStat1
;	spush   pcb,FPStat2
;
	add     pcb,pcb,4*4     ;space for IPA..Q
;
	mtsrim  cr,29-1
	storem  0,0,gr96,pcb   	;push gr96-124, optional
	add     pcb,pcb,29*4    ;space for gr96-124
;
	sub     it0,rfb,gr1     ;get bytes in cache
	srl     it0,it0,2       ;adjust to words
	sub     it0,it0,1
	spush	pcb,it0
	mtsr    cr,it0
	storem  0,0,lr0,pcb     ;save lr0-rfb
;
context_restore:
	add	pcb,kt1,0	;pcb=heir
	add	pcb,pcb,4	;space for signal num
	spop	gr1,pcb		;restore freeze registers
	add	gr1,gr1,0	;alu op
	add	pcb,pcb,9*4	;move past freeze registers
	add	pcb,pcb,1*4	;space for tav
	spop	lr1,pcb
	spop	rfb,pcb
	spop	msp,pcb
;	spop	FPStat0,pcb
;	spop	FPStat1,pcb
;	spop	FPStat2,pcb
	add	pcb,pcb,3*4	;space for floating point
	add	pcb,pcb,4*4	;space for IPA..Q
	mtsrim	cr,29-1
	loadm	0,0,gr96,pcb	;pop gr96-gr124
	add	pcb,pcb,29*4	;space for gr96-124

	spop	it1,pcb		;pop locals count
	mtsr	cr,it1
	loadm	0,0,lr0,pcb	;load locals
	
	add	pcb,kt1,0	;pcb=heir
	mtsr	cps,kt0		;cps with FZ
	nop
	add	pcb,pcb,4	;space for signal num
	spop	gr1,pcb		;restore freeze registers
	add	gr1,gr1,0	;alu op
	spop	rab,pcb
	spopsr	pc0,it1,pcb
	spopsr	pc1,it1,pcb
	add	pcb,pcb,4	;space for pc2
	spopsr	CHA,it1,pcb
	spopsr	CHD,it1,pcb
	spopsr	CHC,it1,pcb
	add	pcb,pcb,4	;space for alu
	spopsr	ops,it1,pcb
        nop
        iret


;/*
; *  _CPU_Context_restore
; *
; *  This routine is generallu used only to restart self in an
; *  efficient manner.  It may simply be a label in _CPU_Context_switch.
; *
; *  NOTE: May be unnecessary to reload some registers.
; */
;#if 0
;void _CPU_Context_restore(
;  Context_Control *new_context
;)
;{
;}
;#endif

        .global __CPU_Context_restore
__CPU_Context_restore:
        asneq   107, gr1, gr1                   ; syscall
        jmpi    lr0                                     ;
        nop                                             ;

	.global _a29k_context_restore_sup
_a29k_context_restore_sup:
	add	kt1,lr2,0	;kt1 = restore context
        mfsr    kt0,cps         ;current status
	const   it1,FZ          ;FZ constant
	andn    it1,kt0,it1     ;clear FZ bit
	mtsr    cps,it1         ;cps without FZ
	jmp	context_restore
	nop

        .global _a29k_context_save_sup
_a29k_context_save_sup:
	add	pcb,lr2,0
	constn	it0,SIG_SYNC
	spush	pcb,it0
	spush 	pcb,gr1
	spush	pcb,rab		;push rab
	spushsr pcb,it0,pc0	;push specials
	spushsr	pcb,it0,pc1
	add	pcb,pcb,1*4	;space pc2
	spushsr	pcb,it0,CHA	;push CHA
	spushsr	pcb,it0,CHD	;push CHD
	spushsr	pcb,it0,CHC	;push CHC
	add	pcb,pcb,1*4	;space for alu
	spushsr	pcb,it0,ops	;push OPS
	mfsr	it0,cps		;current status
SaveFZState	it1,it2
	add	pcb,pcb,1*4	;space for tav
	mtsrim	chc,0		;possible DERR
;
	spush 	pcb,lr1		;push R-stack
	spush 	pcb,rfb		; support
	spush	pcb,msp		;push M-stack pnt.
;
	spush	pcb,FPStat0	;floating point
	spush	pcb,FPStat1	
	spush	pcb,FPStat2
;
	add	pcb,pcb,4*4	;space for IPA..Q
;
	mtsrim	cr,29-1
	storem	0,0,gr96,pcb	;push gr96-124, optional
	add	pcb,pcb,29*4	;space for gr96-124
;
	sub 	kt0,rfb,gr1	;get bytes in cache
	srl	kt0,kt0,2	;adjust to words
	sub	kt0,kt0,1	
	spush	pcb,kt0		;push number of words
	mtsr	cr,kt0
	storem	0,0,lr0,pcb	;save lr0-rfb
;
	mtsr	cps,it0		;cps with FZ
RestoreFZState	it1,it2

	nop
	nop
	nop
;
	iret
;

        .global __CPU_Context_save
__CPU_Context_save:
        asneq   108, gr1, gr1                   ; syscall
        jmpi    lr0                                     ;
        nop                                             ;


;/*  void __ISR_Handler()
; *
; *  This routine provides the RTEMS interrupt management.
; *
; */

;#if 0
;void _ISR_Handler()
;{
;   /*
;    *  This discussion ignores a lot of the ugly details in a real
;    *  implementation such as saving enough registers/state to be
;    *  able to do something real.  Keep in mind that the goal is
;    *  to invoke a user's ISR handler which is written in C and
;    *  uses a certain set of registers.
;    *
;    *  Also note that the exact order is to a large extent flexible.
;    *  Hardware will dictate a sequence for a certain subset of
;    *  _ISR_Handler while requirements for setting
;    */

;  /*
;   *  At entry to "common" _ISR_Handler, the vector number must be
;   *  available.  On some CPUs the hardware puts either the vector
;   *  number or the offset into the vector table for this ISR in a
;   *  known place.  If the hardware does not give us this information,
;   *  then the assembly portion of RTEMS for this port will contain
;   *  a set of distinct interrupt entry points which somehow place
;   *  the vector number in a known place (which is safe if another
;   *  interrupt nests this one) and branches to _ISR_Handler.
;   *
;   *  save some or all context on stack
;   *  may need to save some special interrupt information for exit
;   *
;   *  #if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE )
;   *    if ( _ISR_Nest_level == 0 )
;   *      switch to software interrupt stack
;   *  #endif
;   *
;   *  _ISR_Nest_level++;
;   *
;   *  _Thread_Dispatch_disable_level++;
;   *
;   *  (*_ISR_Vector_table[ vector ])( vector );
;   *
;   *  --_ISR_Nest_level;
;   *
;   *  if ( _ISR_Nest_level )
;   *    goto the label "exit interrupt (simple case)"
;   *
;   *  #if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE )
;   *    restore stack
;   *  #endif
;   *  
;   *  if ( !_Context_Switch_necessary )
;   *    goto the label "exit interrupt (simple case)"
;   *  
;   *  if ( !_ISR_Signals_to_thread_executing )
;   *    goto the label "exit interrupt (simple case)"
;   *
;   *  call _Thread_Dispatch() or prepare to return to _ISR_Dispatch
;   *
;   *  prepare to get out of interrupt
;   *  return from interrupt  (maybe to _ISR_Dispatch)
;   *
;   *  LABEL "exit interrupt (simple case):
;   *  prepare to get out of interrupt
;   *  return from interrupt
;   */
;}
;#endif
;        .global __ISR_Handler
;__ISR_Handler:
;	jmpi lr0
;        nop

	.global	_a29k_getops
_a29k_getops:
	asneq 113, gr96, gr96
	jmpi lr0
	nop

	.global	_a29k_getops_sup
_a29k_getops_sup:
	mfsr	gr96, ops	; caller wants ops
	iret
	nop

	.global	_a29k_disable
_a29k_disable:
	asneq 110, gr96, gr96
	jmpi lr0
	nop

	.global	_a29k_disable_sup
_a29k_disable_sup:
	mfsr	kt0, ops
	add	gr96, kt0, 0	; return ops to caller
	const	kt1, (DI | TD)
	consth	kt1, (DI | TD)
	or	kt1, kt0, kt1
	mtsr	ops, kt1
	iret
	nop

        .global _a29k_disable_all
_a29k_disable_all:
        asneq 112, gr96, gr96
        jmpi lr0
        nop

        .global _a29k_disable_all_sup
_a29k_disable_all_sup:
        mfsr    kt0, ops
	const	kt1, (DI | TD)
	consth	kt1, (DI | TD)
        or    	kt1, kt0, kt1
        mtsr    ops, kt1
        iret
        nop

        .global _a29k_enable_all
_a29k_enable_all:
        asneq 111, gr96, gr96
        jmpi lr0
        nop

        .global _a29k_enable_all_sup
_a29k_enable_all_sup:
        mfsr    kt0, ops
	const	kt1, (DI | TD)
	consth	kt1, (DI | TD)
        andn    kt1, kt0, kt1
        mtsr    ops, kt1
        iret
        nop

	.global	_a29k_enable
_a29k_enable:
	asneq 109, gr96, gr96
	jmpi lr0
	nop

	.global	_a29k_enable_sup
_a29k_enable_sup:
	mfsr	kt0, ops
	const	kt1, (DI | TD)
	consth	kt1, (DI | TD)
	and	kt3, lr2, kt1
	andn	kt0, kt0, kt1
	or	kt1, kt0, kt3
	mtsr	ops, kt1
	iret
	nop

	.global _a29k_halt
_a29k_halt:
	halt
	jmp _a29k_halt
	nop

	.global _a29k_super_mode
_a29k_super_mode:
	mfsr gr96, ops
	or gr96, gr96, 0x10
	mtsr ops, gr96
	iret
	nop

	.global _a29k_as70
_a29k_as70:
	asneq 70,gr96,gr96
	jmpi lr0
	nop