2005-04-17 02:20:36 +04:00
/ * - * - mode : asm - * -
*
2007-07-16 10:38:36 +04:00
* linux/ a r c h / h83 0 0 / p l a t f o r m / h83 0 0 h / e n t r y . S
2005-04-17 02:20:36 +04:00
*
* Yoshinori S a t o < y s a t o @users.sourceforge.jp>
2007-07-16 10:38:36 +04:00
* David M c C u l l o u g h < d a v i d m @snapgear.com>
2005-04-17 02:20:36 +04:00
*
* /
/ *
* entry. S
* include e x c e p t i o n / i n t e r r u p t g a t e w a y
* system c a l l e n t r y
* /
# include < l i n u x / s y s . h >
# include < a s m / u n i s t d . h >
# include < a s m / s e t u p . h >
# include < a s m / s e g m e n t . h >
# include < a s m / l i n k a g e . h >
# include < a s m / a s m - o f f s e t s . h >
# include < a s m / t h r e a d _ i n f o . h >
# include < a s m / e r r n o . h >
2007-07-16 10:38:36 +04:00
# if d e f i n e d ( C O N F I G _ C P U _ H 8 3 0 0 H )
# define U S E R R E T 8
INTERRUPTS = 6 4
.h8300h
.macro SHLL2 reg
shll. l \ r e g
shll. l \ r e g
.endm
.macro SHLR2 reg
shlr. l \ r e g
shlr. l \ r e g
.endm
.macro SAVEREGS
mov. l e r0 ,@-sp
mov. l e r1 ,@-sp
mov. l e r2 ,@-sp
mov. l e r3 ,@-sp
.endm
.macro RESTOREREGS
mov. l @sp+,er3
mov. l @sp+,er2
.endm
.macro SAVEEXR
.endm
.macro RESTOREEXR
.endm
# endif
# if d e f i n e d ( C O N F I G _ C P U _ H 8 S )
# define U S E R R E T 1 0
# define U S E R E X R 8
INTERRUPTS = 1 2 8
2005-04-17 02:20:36 +04:00
.h8300s
2007-07-16 10:38:36 +04:00
.macro SHLL2 reg
shll. l #2 ,\ r e g
.endm
.macro SHLR2 reg
shlr. l #2 ,\ r e g
.endm
.macro SAVEREGS
stm. l e r0 - e r3 ,@-sp
.endm
.macro RESTOREREGS
ldm. l @sp+,er2-er3
.endm
.macro SAVEEXR
mov. w @(USEREXR:16,er0),r1
mov. w r1 ,@(LEXR-LER3:16,sp) /* copy EXR */
.endm
.macro RESTOREEXR
mov. w @(LEXR-LER1:16,sp),r1 /* restore EXR */
mov. b r1 l ,r1 h
mov. w r1 ,@(USEREXR:16,er0)
.endm
# endif
2005-04-17 02:20:36 +04:00
/* CPU context save/restore macros. */
2007-07-16 10:38:36 +04:00
2005-04-17 02:20:36 +04:00
.macro SAVE_ALL
mov. l e r0 ,@-sp
stc c c r ,r0 l / * c h e c k k e r n e l m o d e * /
btst #4 ,r0 l
bne 5 f
2007-05-07 01:50:35 +04:00
/* user mode */
mov. l s p ,@SYMBOL_NAME(sw_usp)
mov. l @sp,er0 /* restore saved er0 */
orc #0x10 ,c c r / * s w i t c h k e r n e l s t a c k * /
2005-04-17 02:20:36 +04:00
mov. l @SYMBOL_NAME(sw_ksp),sp
2007-07-16 10:38:36 +04:00
sub. l #( L R E T - L O R I G ) , s p / * a l l o c a t e L O R I G - L R E T * /
SAVEREGS
mov. l @SYMBOL_NAME(sw_usp),er0
mov. l @(USERRET:16,er0),er1 /* copy the RET addr */
mov. l e r1 ,@(LRET-LER3:16,sp)
SAVEEXR
2005-04-17 02:20:36 +04:00
mov. l @(LORIG-LER3:16,sp),er0
mov. l e r0 ,@(LER0-LER3:16,sp) /* copy ER0 */
2007-07-16 10:38:36 +04:00
mov. w e 1 ,r1 / * e 1 h i g h b y t e = c c r * /
and #0xef ,r1 h / * m a s k m o d e ? f l a g * /
2005-04-17 02:20:36 +04:00
bra 6 f
5 :
2007-05-07 01:50:35 +04:00
/* kernel mode */
mov. l @sp,er0 /* restore saved er0 */
subs #2 ,s p / * s e t d u m m y c c r * /
2007-07-16 10:38:36 +04:00
SAVEREGS
2005-04-17 02:20:36 +04:00
mov. w @(LRET-LER3:16,sp),r1 /* copy old ccr */
2007-07-16 10:38:36 +04:00
6 :
2005-04-17 02:20:36 +04:00
mov. b r1 h ,r1 l
mov. b #0 ,r1 h
2007-07-16 10:38:36 +04:00
mov. w r1 ,@(LCCR-LER3:16,sp) /* set ccr */
2005-04-17 02:20:36 +04:00
mov. l e r6 ,@-sp /* syscall arg #6 */
mov. l e r5 ,@-sp /* syscall arg #5 */
mov. l e r4 ,@-sp /* syscall arg #4 */
2007-07-16 10:38:36 +04:00
.endm /* r1 = ccr */
2005-04-17 02:20:36 +04:00
.macro RESTORE_ALL
mov. l @sp+,er4
mov. l @sp+,er5
mov. l @sp+,er6
2007-07-16 10:38:36 +04:00
RESTOREREGS
2005-04-17 02:20:36 +04:00
mov. w @(LCCR-LER1:16,sp),r0 /* check kernel mode */
btst #4 ,r0 l
bne 7 f
orc #0x80 ,c c r
mov. l @SYMBOL_NAME(sw_usp),er0
mov. l @(LER0-LER1:16,sp),er1 /* restore ER0 */
mov. l e r1 ,@er0
2007-07-16 10:38:36 +04:00
RESTOREEXR
2005-04-17 02:20:36 +04:00
mov. w @(LCCR-LER1:16,sp),r1 /* restore the RET addr */
mov. b r1 l ,r1 h
mov. b @(LRET+1-LER1:16,sp),r1l
mov. w r1 ,e 1
mov. w @(LRET+2-LER1:16,sp),r1
2007-07-16 10:38:36 +04:00
mov. l e r1 ,@(USERRET:16,er0)
2005-04-17 02:20:36 +04:00
mov. l @sp+,er1
2007-07-16 10:38:36 +04:00
add. l #( L R E T - L E R 1 ) ,s p / * r e m o v e L O R I G - L R E T * /
2005-04-17 02:20:36 +04:00
mov. l s p ,@SYMBOL_NAME(sw_ksp)
2007-05-07 01:50:35 +04:00
andc #0xef ,c c r / * s w i t c h t o u s e r m o d e * /
2005-04-17 02:20:36 +04:00
mov. l e r0 ,s p
bra 8 f
7 :
mov. l @sp+,er1
adds #4 ,s p
adds #2 ,s p
8 :
mov. l @sp+,er0
adds #4 ,s p / * r e m o v e t h e s w c r e a t e d L V E C * /
rte
.endm
2007-07-16 10:38:36 +04:00
2005-04-17 02:20:36 +04:00
.globl SYMBOL_ N A M E ( s y s t e m _ c a l l )
.globl SYMBOL_ N A M E ( r e t _ f r o m _ e x c e p t i o n )
.globl SYMBOL_ N A M E ( r e t _ f r o m _ f o r k )
.globl SYMBOL_ N A M E ( r e t _ f r o m _ i n t e r r u p t )
.globl SYMBOL_ N A M E ( i n t e r r u p t _ r e d i r e c t _ t a b l e )
.globl SYMBOL_ N A M E ( s w _ k s p ) ,S Y M B O L _ N A M E ( s w _ u s p )
.globl SYMBOL_ N A M E ( r e s u m e )
.globl SYMBOL_ N A M E ( i n t e r r u p t _ e n t r y )
2007-07-16 10:38:36 +04:00
.globl SYMBOL_ N A M E ( t r a c e _ b r e a k )
2005-04-17 02:20:36 +04:00
# if d e f i n e d ( C O N F I G _ R O M K E R N E L )
.section .int_redirect , " ax"
SYMBOL_ N A M E _ L A B E L ( i n t e r r u p t _ r e d i r e c t _ t a b l e )
2007-07-16 10:38:36 +04:00
# if d e f i n e d ( C O N F I G _ C P U _ H 8 3 0 0 H )
2005-04-17 02:20:36 +04:00
.rept 7
.long 0
.endr
2007-07-16 10:38:36 +04:00
# endif
# if d e f i n e d ( C O N F I G _ C P U _ H 8 S )
.rept 5
.long 0
.endr
jmp @SYMBOL_NAME(trace_break)
.long 0
# endif
2005-04-17 02:20:36 +04:00
jsr @SYMBOL_NAME(interrupt_entry) /* NMI */
jmp @SYMBOL_NAME(system_call) /* TRAPA #0 (System call) */
.long 0
.long 0
jmp @SYMBOL_NAME(trace_break) /* TRAPA #3 (breakpoint) */
.rept INTERRUPTS- 1 2
jsr @SYMBOL_NAME(interrupt_entry)
.endr
# endif
# if d e f i n e d ( C O N F I G _ R A M K E R N E L )
.globl SYMBOL_ N A M E ( i n t e r r u p t _ r e d i r e c t _ t a b l e )
.section .bss
SYMBOL_ N A M E _ L A B E L ( i n t e r r u p t _ r e d i r e c t _ t a b l e )
.space 4
# endif
2007-07-16 10:38:36 +04:00
2005-04-17 02:20:36 +04:00
.section .text
.align 2
SYMBOL_ N A M E _ L A B E L ( i n t e r r u p t _ e n t r y )
SAVE_ A L L
2007-07-16 10:38:36 +04:00
mov. l s p ,e r0
add. l #L V E C , e r 0
btst #4 ,r1 l
2005-04-17 02:20:36 +04:00
bne 1 f
2007-07-16 10:38:36 +04:00
/* user LVEC */
2005-04-17 02:20:36 +04:00
mov. l @SYMBOL_NAME(sw_usp),er0
2007-07-16 10:38:36 +04:00
adds #4 ,e r0
2005-04-17 02:20:36 +04:00
1 :
2007-07-16 10:38:36 +04:00
mov. l @er0,er0 /* LVEC address */
2005-04-17 02:20:36 +04:00
# if d e f i n e d ( C O N F I G _ R O M K E R N E L )
sub. l #S Y M B O L _ N A M E ( i n t e r r u p t _ r e d i r e c t _ t a b l e ) , e r 0
# endif
# if d e f i n e d ( C O N F I G _ R A M K E R N E L )
mov. l @SYMBOL_NAME(interrupt_redirect_table),er1
sub. l e r1 ,e r0
# endif
2007-07-16 10:38:36 +04:00
SHLR2 e r0
2005-04-17 02:20:36 +04:00
dec. l #1 ,e r0
mov. l s p ,e r1
subs #4 ,e r1 / * a d j u s t r e t _ p c * /
2007-07-16 10:38:36 +04:00
jsr @SYMBOL_NAME(do_IRQ)
jmp @SYMBOL_NAME(ret_from_interrupt)
2005-04-17 02:20:36 +04:00
SYMBOL_ N A M E _ L A B E L ( s y s t e m _ c a l l )
subs #4 ,s p / * d u m m y L V E C * /
SAVE_ A L L
2007-07-16 10:38:36 +04:00
andc #0x7f ,c c r
2005-04-17 02:20:36 +04:00
mov. l e r0 ,e r4
/* save top of frame */
mov. l s p ,e r0
jsr @SYMBOL_NAME(set_esp0)
mov. l s p ,e r2
and. w #0xe000 ,r2
2007-07-16 10:38:36 +04:00
mov. b @((TI_FLAGS+3-(TIF_SYSCALL_TRACE >> 3)):16,er2),r2l
2005-04-17 02:20:36 +04:00
btst #( T I F _ S Y S C A L L _ T R A C E & 7 ) ,r2 l
2007-07-16 10:38:36 +04:00
beq 1 f
jsr @SYMBOL_NAME(do_syscall_trace)
1 :
cmp. l #N R _ s y s c a l l s , e r 4
bcc b a d s y s
SHLL2 e r4
mov. l #S Y M B O L _ N A M E ( s y s _ c a l l _ t a b l e ) , e r 0
add. l e r4 ,e r0
mov. l @er0,er4
beq S Y M B O L _ N A M E ( r e t _ f r o m _ e x c e p t i o n ) : 1 6
2005-04-17 02:20:36 +04:00
mov. l @(LER1:16,sp),er0
mov. l @(LER2:16,sp),er1
mov. l @(LER3:16,sp),er2
jsr @er4
2007-07-16 10:38:36 +04:00
mov. l e r0 ,@(LER0:16,sp) /* save the return value */
mov. l s p ,e r2
and. w #0xe000 ,r2
mov. b @((TI_FLAGS+3-(TIF_SYSCALL_TRACE >> 3)):16,er2),r2l
btst #( T I F _ S Y S C A L L _ T R A C E & 7 ) ,r2 l
beq 2 f
jsr @SYMBOL_NAME(do_syscall_trace)
2 :
2005-04-17 02:20:36 +04:00
# if d e f i n e d ( C O N F I G _ S Y S C A L L _ P R I N T )
jsr @SYMBOL_NAME(syscall_print)
# endif
2007-07-16 10:38:36 +04:00
orc #0x80 ,c c r
bra r e s u m e _ u s e r s p a c e
2005-04-17 02:20:36 +04:00
2007-07-16 10:38:36 +04:00
badsys :
mov. l #- E N O S Y S , e r 0
mov. l e r0 ,@(LER0:16,sp)
bra r e s u m e _ u s e r s p a c e
2005-04-17 02:20:36 +04:00
2007-07-16 10:38:36 +04:00
# if ! d e f i n e d ( C O N F I G _ P R E E M P T )
# define r e s u m e _ k e r n e l r e s t o r e _ a l l
# endif
2005-04-17 02:20:36 +04:00
SYMBOL_ N A M E _ L A B E L ( r e t _ f r o m _ e x c e p t i o n )
# if d e f i n e d ( C O N F I G _ P R E E M P T )
orc #0x80 ,c c r
# endif
SYMBOL_ N A M E _ L A B E L ( r e t _ f r o m _ i n t e r r u p t )
mov. b @(LCCR+1:16,sp),r0l
2007-07-16 10:38:36 +04:00
btst #4 ,r0 l
bne r e s u m e _ k e r n e l : 8 / * r e t u r n f r o m k e r n e l * /
resume_userspace :
2005-04-17 02:20:36 +04:00
andc #0x7f ,c c r
mov. l s p ,e r4
2007-07-16 10:38:36 +04:00
and. w #0xe000 ,r4 / * e r4 < - c u r r e n t t h r e a d i n f o * /
2005-04-17 02:20:36 +04:00
mov. l @(TI_FLAGS:16,er4),er1
and. l #_ T I F _ W O R K _ M A S K , e r 1
2007-07-16 10:38:36 +04:00
beq r e s t o r e _ a l l : 8
work_pending :
2005-04-17 02:20:36 +04:00
btst #T I F _ N E E D _ R E S C H E D , r 1 l
2007-07-16 10:38:36 +04:00
bne w o r k _ r e s c h e d : 8
/* work notifysig */
2005-04-17 02:20:36 +04:00
mov. l s p ,e r0
2007-07-16 10:38:36 +04:00
subs #4 ,e r0 / * e r0 : p t _ r e g s * /
jsr @SYMBOL_NAME(do_notify_resume)
bra r e s t o r e _ a l l : 8
work_resched :
mov. l s p ,e r0
jsr @SYMBOL_NAME(set_esp0)
jsr @SYMBOL_NAME(schedule)
bra r e s u m e _ u s e r s p a c e : 8
restore_all :
RESTORE_ A L L / * D o e s R T E * /
2005-04-17 02:20:36 +04:00
# if d e f i n e d ( C O N F I G _ P R E E M P T )
2007-07-16 10:38:36 +04:00
resume_kernel :
mov. l @(TI_PRE_COUNT:16,er4),er0
bne r e s t o r e _ a l l : 8
need_resched :
mov. l @(TI_FLAGS:16,er4),er0
btst #T I F _ N E E D _ R E S C H E D , r 0 l
beq r e s t o r e _ a l l : 8
mov. b @(LCCR+1:16,sp),r0l /* Interrupt Enabled? */
bmi r e s t o r e _ a l l : 8
mov. l #P R E E M P T _ A C T I V E , e r 0
mov. l e r0 ,@(TI_PRE_COUNT:16,er4)
2005-04-17 02:20:36 +04:00
andc #0x7f ,c c r
2007-07-16 10:38:36 +04:00
mov. l s p ,e r0
jsr @SYMBOL_NAME(set_esp0)
2005-04-17 02:20:36 +04:00
jsr @SYMBOL_NAME(schedule)
orc #0x80 ,c c r
2007-07-16 10:38:36 +04:00
bra n e e d _ r e s c h e d : 8
2005-04-17 02:20:36 +04:00
# endif
2007-07-16 10:38:36 +04:00
SYMBOL_ N A M E _ L A B E L ( r e t _ f r o m _ f o r k )
mov. l e r2 ,e r0
jsr @SYMBOL_NAME(schedule_tail)
jmp @SYMBOL_NAME(ret_from_exception)
2005-04-17 02:20:36 +04:00
SYMBOL_ N A M E _ L A B E L ( r e s u m e )
/ *
2007-07-16 10:38:36 +04:00
* Beware - w h e n e n t e r i n g r e s u m e , o f f s e t o f t s s i s i n d1 ,
* prev ( t h e c u r r e n t t a s k ) i s i n a0 , n e x t ( t h e n e w t a s k )
* is i n a1 a n d d2 . b i s n o n - z e r o i f t h e m m s t r u c t u r e i s
* shared b e t w e e n t h e t a s k s , s o d o n ' t c h a n g e t h e s e
* registers u n t i l t h e i r c o n t e n t s a r e n o l o n g e r n e e d e d .
2005-04-17 02:20:36 +04:00
* /
/* save sr */
sub. w r3 ,r3
stc c c r ,r3 l
mov. w r3 ,@(THREAD_CCR+2:16,er0)
/* disable interrupts */
orc #0x80 ,c c r
mov. l @SYMBOL_NAME(sw_usp),er3
mov. l e r3 ,@(THREAD_USP:16,er0)
mov. l s p ,@(THREAD_KSP:16,er0)
2007-07-16 10:38:36 +04:00
2005-04-17 02:20:36 +04:00
/* Skip address space switching if they are the same. */
/* FIXME: what did we hack out of here, this does nothing! */
mov. l @(THREAD_USP:16,er1),er0
mov. l e r0 ,@SYMBOL_NAME(sw_usp)
mov. l @(THREAD_KSP:16,er1),sp
2007-07-16 10:38:36 +04:00
2005-04-17 02:20:36 +04:00
/* restore status register */
mov. w @(THREAD_CCR+2:16,er1),r3
ldc r3 l ,c c r
rts
SYMBOL_ N A M E _ L A B E L ( t r a c e _ b r e a k )
2007-07-16 10:38:36 +04:00
subs #4 ,s p
2005-04-17 02:20:36 +04:00
SAVE_ A L L
sub. l e r1 ,e r1
dec. l #1 ,e r1
2007-07-16 10:38:36 +04:00
mov. l e r1 ,@(LORIG,sp)
2005-04-17 02:20:36 +04:00
mov. l s p ,e r0
jsr @SYMBOL_NAME(set_esp0)
mov. l @SYMBOL_NAME(sw_usp),er0
mov. l @er0,er1
2007-07-16 10:38:36 +04:00
mov. w @(-2:16,er1),r2
cmp. w #0x5730 ,r2
beq 1 f
2005-04-17 02:20:36 +04:00
subs #2 ,e r1
2007-07-16 10:38:36 +04:00
mov. l e r1 ,@er0
1 :
2005-04-17 02:20:36 +04:00
and. w #0xff ,e 1
mov. l e r1 ,e r0
jsr @SYMBOL_NAME(trace_trap)
2007-07-16 10:38:36 +04:00
jmp @SYMBOL_NAME(ret_from_exception)
2005-04-17 02:20:36 +04:00
.section .bss
SYMBOL_ N A M E _ L A B E L ( s w _ k s p )
2007-07-16 10:38:36 +04:00
.space 4
2005-04-17 02:20:36 +04:00
SYMBOL_ N A M E _ L A B E L ( s w _ u s p )
2007-07-16 10:38:36 +04:00
.space 4
.end