Commit 90b8b6c3 authored by Mao Minkai's avatar Mao Minkai Committed by guzitao
Browse files

sw64: setup stackframe at kernel entry point

Sunway inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IB73UR



--------------------------------

Manually setup a stackframe at kernel entry point to produce a more
accurate stacktrace.

Signed-off-by: default avatarMao Minkai <maominkai@wxiat.com>
Reviewed-by: default avatarHe Sheng <hesheng@wxiat.com>
Signed-off-by: default avatarGu Zitao <guzitao@wxiat.com>
parent 49d3e90f
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -241,4 +241,12 @@ void foo(void)
	BLANK();
	DEFINE(RT_SIGFRAME_SIZE, sizeof(struct rt_sigframe));
	OFFSET(RT_SIGFRAME_MCTX, rt_sigframe, uc.uc_mcontext);
	BLANK();
#ifdef CONFIG_FRAME_POINTER
	DEFINE(STACKFRAME_SIZE, sizeof(struct stackframe));
	OFFSET(STACKFRAME_PC, stackframe, pc);
	OFFSET(STACKFRAME_FP, stackframe, fp);
#else
	DEFINE(STACKFRAME_SIZE, 0);
#endif
}
+22 −14
Original line number Diff line number Diff line
@@ -70,9 +70,17 @@
	ldi	$1, NO_SYSCALL
	stl	$1, PT_REGS_ORIG_R0($sp)
	sys_call HMC_rdktp
#ifdef CONFIG_FRAME_POINTER
	ldi	$sp, -STACKFRAME_SIZE($sp)
	stl	$5, STACKFRAME_PC($sp)
	stl	$15, STACKFRAME_FP($sp)
	mov	$sp, $15
#endif
	.endm

	.macro RESTORE_ALL
	ldi	$sp, STACKFRAME_SIZE($sp)

	ldl	$16, PT_REGS_SP($sp)
	/* skip wrusp if returning to kernel */
	blt	$16, 1f
@@ -127,7 +135,7 @@
	.ent entInt
entInt:
	SAVE_ALL
	mov	$sp, $19
	ldi	$19, STACKFRAME_SIZE($sp)
	call	$26, do_entInt
	br	ret_from_sys_call
	.end entInt
@@ -137,7 +145,7 @@ entInt:
	.ent entArith
entArith:
	SAVE_ALL
	mov	$sp, $18
	ldi	$18, STACKFRAME_SIZE($sp)
	call	$26, do_entArith
	br	ret_from_sys_call
	.end entArith
@@ -147,7 +155,7 @@ entArith:
	.ent entMM
entMM:
	SAVE_ALL
	mov	$sp, $19
	ldi	$19, STACKFRAME_SIZE($sp)
	call	$26, do_page_fault
	br	ret_from_sys_call
	.end entMM
@@ -157,7 +165,7 @@ entMM:
	.ent entIF
entIF:
	SAVE_ALL
	mov	$sp, $18
	ldi	$18, STACKFRAME_SIZE($sp)
	call	$26, do_entIF
	br	ret_from_sys_call
	.end entIF
@@ -173,15 +181,15 @@ entIF:
	.ent entUna
entUna:
	SAVE_ALL
	mov	$sp, $19
	ldl	$0, PT_REGS_PS($sp)
	ldi	$19, STACKFRAME_SIZE($sp)
	ldl	$0, (PT_REGS_PS + STACKFRAME_SIZE)($sp)
	and	$0, 8, $0		/* user mode ? */
	beq	$0, 1f
	call	$26, do_entUnaUser	/* return to ret_from_syscall */
	br	ret_from_sys_call
1:	ldl	$9, PT_REGS_GP($sp)
1:	ldl	$9, (PT_REGS_GP + STACKFRAME_SIZE)($sp)
	call	$26, do_entUna
	stl	$9, PT_REGS_GP($sp)
	stl	$9, (PT_REGS_GP + STACKFRAME_SIZE)($sp)
	RESTORE_ALL
	sys_call HMC_rti
	.end entUna
@@ -202,10 +210,10 @@ entUna:
	.ent entSys
entSys:
	SAVE_ALL
	stl	$16, PT_REGS_R16($sp)
	stl	$17, PT_REGS_R17($sp)
	stl	$18, PT_REGS_R18($sp)
	mov	$sp, $16
	stl	$16, (PT_REGS_R16 + STACKFRAME_SIZE)($sp)
	stl	$17, (PT_REGS_R17 + STACKFRAME_SIZE)($sp)
	stl	$18, (PT_REGS_R18 + STACKFRAME_SIZE)($sp)
	ldi	$16, STACKFRAME_SIZE($sp)
	call	$26, do_entSys
	br	ret_from_sys_call
	.end entSys
@@ -223,14 +231,14 @@ ret_from_sys_call:
		sampling and the rti.  */
	ldi	$16, 7
	sys_call HMC_swpipl
	ldl	$0, PT_REGS_PS($sp)
	ldl	$0, (PT_REGS_PS + STACKFRAME_SIZE)($sp)
	and	$0, 8, $0
	beq	$0, restore_all
ret_to_user:
	ldw	$17, TI_FLAGS($8)
	and	$17, _TIF_WORK_MASK, $2
	beq	$2, restore_all
	mov	$sp, $16
	ldi	$16, STACKFRAME_SIZE($sp)
	call	$26, do_notify_resume
restore_all:
	RESTORE_ALL
+28 −20
Original line number Diff line number Diff line
@@ -79,12 +79,20 @@
	ldi	$1, NO_SYSCALL
	stl	$1, PT_REGS_ORIG_R0($sp)
	csrr	$8, CSR_KTP
#ifdef CONFIG_FRAME_POINTER
	ldi	$sp, -STACKFRAME_SIZE($sp)
	stl	$3, STACKFRAME_PC($sp)
	stl	$15, STACKFRAME_FP($sp)
	mov	$sp, $15
#endif
	.endm

	.macro RESTORE_ALL
	ldi     $16, 7
	sys_call HMC_swpipl

	ldi	$sp, STACKFRAME_SIZE($sp)

	ldl	$1, PT_REGS_PS($sp)
	ldl	$2, PT_REGS_PC($sp)
	csrw	$1, CSR_PS
@@ -130,7 +138,7 @@
	.macro RESTORE_IRQ
	csrr	$16, CSR_PS
	sys_call HMC_swpipl
	ldl	$16, PT_REGS_EARG0($sp)
	ldl	$16, (PT_REGS_EARG0 + STACKFRAME_SIZE)($sp)
	.endm
/*
 * Non-syscall kernel entry points.
@@ -143,7 +151,7 @@ entInt:
	SAVE_ALL
	br      $27, 1f
1:      ldgp    $29, 0($27)
	mov	$sp, $19
	ldi	$19, STACKFRAME_SIZE($sp)
	call	$26, do_entInt
	br	ret_from_sys_call
	.end entInt
@@ -153,13 +161,13 @@ entInt:
	.ent entArith
entArith:
	SAVE_ALL
	ldl     $1, PT_REGS_PC($sp)
	ldl     $1, (PT_REGS_PC + STACKFRAME_SIZE)($sp)
	ldi	$1, 4($1)
	stl     $1, PT_REGS_PC($sp)
	stl     $1, (PT_REGS_PC + STACKFRAME_SIZE)($sp)
	br      $27, 1f
1:      ldgp    $29, 0($27)
	RESTORE_IRQ
	mov	$sp, $18
	ldi	$18, STACKFRAME_SIZE($sp)
	call	$26, do_entArith
	br	ret_from_sys_call
	.end entArith
@@ -172,7 +180,7 @@ entMM:
	br      $27, 1f
1:      ldgp    $29, 0($27)
	RESTORE_IRQ
	mov	$sp, $19
	ldi	$19, STACKFRAME_SIZE($sp)
	call	$26, do_page_fault
	br	ret_from_sys_call
	.end entMM
@@ -182,13 +190,13 @@ entMM:
	.ent entIF
entIF:
	SAVE_ALL
	ldl     $1, PT_REGS_PC($sp)
	ldl     $1, (PT_REGS_PC + STACKFRAME_SIZE)($sp)
	ldi	$1, 4($1)
	stl     $1, PT_REGS_PC($sp)
	stl     $1, (PT_REGS_PC + STACKFRAME_SIZE)($sp)
	br      $27, 1f
1:      ldgp    $29, 0($27)
	RESTORE_IRQ
	mov	$sp, $18
	ldi	$18, STACKFRAME_SIZE($sp)
	call	$26, do_entIF
	br	ret_from_sys_call
	.end entIF
@@ -204,21 +212,21 @@ entIF:
	.ent entUna
entUna:
	SAVE_ALL
	ldl     $1, PT_REGS_PC($sp)
	ldl     $1, (PT_REGS_PC + STACKFRAME_SIZE)($sp)
	ldi	$1, 4($1)
	stl     $1, PT_REGS_PC($sp)
	stl     $1, (PT_REGS_PC + STACKFRAME_SIZE)($sp)
	br      $27, 1f
1:      ldgp    $29, 0($27)
	RESTORE_IRQ
	mov	$sp, $19
	ldl	$0, PT_REGS_PS($sp)
	ldi	$19, STACKFRAME_SIZE($sp)
	ldl	$0, (PT_REGS_PS + STACKFRAME_SIZE)($sp)
	and	$0, 8, $0		/* user mode ? */
	beq	$0, 1f
	call	$26, do_entUnaUser	/* return to ret_from_syscall */
	br	ret_from_sys_call
1:	ldl	$9, PT_REGS_GP($sp)
1:	ldl	$9, (PT_REGS_GP + STACKFRAME_SIZE)($sp)
	call	$26, do_entUna
	stl	$9, PT_REGS_GP($sp)
	stl	$9, (PT_REGS_GP + STACKFRAME_SIZE)($sp)
	RESTORE_ALL
	sys_call HMC_rti
	.end entUna
@@ -239,13 +247,13 @@ entUna:
	.ent entSys
entSys:
	SAVE_ALL
	ldl     $1, PT_REGS_PC($sp)
	ldl     $1, (PT_REGS_PC + STACKFRAME_SIZE)($sp)
	ldi	$1, 4($1)
	stl     $1, PT_REGS_PC($sp)
	stl     $1, (PT_REGS_PC + STACKFRAME_SIZE)($sp)
	br      $27, 1f
1:      ldgp    $29, 0($27)
	RESTORE_IRQ
	mov	$sp, $16
	ldi	$16, STACKFRAME_SIZE($sp)
	call	$26, do_entSys
	br	ret_from_sys_call
	.end entSys
@@ -260,14 +268,14 @@ ret_from_sys_call:
		sampling and the rti.  */
	ldi	$16, 7
	sys_call HMC_swpipl
	ldl	$0, PT_REGS_PS($sp)
	ldl	$0, (PT_REGS_PS + STACKFRAME_SIZE)($sp)
	and	$0, 8, $0
	beq	$0, restore_all
ret_to_user:
	ldw	$17, TI_FLAGS($8)
	and	$17, _TIF_WORK_MASK, $2
	beq	$2, restore_all
	mov	$sp, $16
	ldi	$16, STACKFRAME_SIZE($sp)
	call	$26, do_notify_resume
restore_all:
	RESTORE_ALL
+1 −1
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
	extern void ret_from_fork(void);
	extern void ret_from_kernel_thread(void);

	p->thread.sp = (unsigned long) childregs;
	p->thread.sp = (unsigned long) childregs - STACKFRAME_SIZE;

	if (unlikely(args->fn)) {
		/* kernel thread */