18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci// Copyright (C) 2005-2017 Andes Technology Corporation
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#ifndef __ASM_NDS32_PROCESSOR_H
58c2ecf20Sopenharmony_ci#define __ASM_NDS32_PROCESSOR_H
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifdef __KERNEL__
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <asm/ptrace.h>
108c2ecf20Sopenharmony_ci#include <asm/types.h>
118c2ecf20Sopenharmony_ci#include <asm/sigcontext.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define KERNEL_STACK_SIZE	PAGE_SIZE
148c2ecf20Sopenharmony_ci#define STACK_TOP	TASK_SIZE
158c2ecf20Sopenharmony_ci#define STACK_TOP_MAX   TASK_SIZE
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistruct cpu_context {
188c2ecf20Sopenharmony_ci	unsigned long r6;
198c2ecf20Sopenharmony_ci	unsigned long r7;
208c2ecf20Sopenharmony_ci	unsigned long r8;
218c2ecf20Sopenharmony_ci	unsigned long r9;
228c2ecf20Sopenharmony_ci	unsigned long r10;
238c2ecf20Sopenharmony_ci	unsigned long r11;
248c2ecf20Sopenharmony_ci	unsigned long r12;
258c2ecf20Sopenharmony_ci	unsigned long r13;
268c2ecf20Sopenharmony_ci	unsigned long r14;
278c2ecf20Sopenharmony_ci	unsigned long fp;
288c2ecf20Sopenharmony_ci	unsigned long pc;
298c2ecf20Sopenharmony_ci	unsigned long sp;
308c2ecf20Sopenharmony_ci};
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistruct thread_struct {
338c2ecf20Sopenharmony_ci	struct cpu_context cpu_context;	/* cpu context */
348c2ecf20Sopenharmony_ci	/* fault info     */
358c2ecf20Sopenharmony_ci	unsigned long address;
368c2ecf20Sopenharmony_ci	unsigned long trap_no;
378c2ecf20Sopenharmony_ci	unsigned long error_code;
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	struct fpu_struct fpu;
408c2ecf20Sopenharmony_ci};
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define INIT_THREAD  {	}
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#ifdef __NDS32_EB__
458c2ecf20Sopenharmony_ci#define PSW_DE	PSW_mskBE
468c2ecf20Sopenharmony_ci#else
478c2ecf20Sopenharmony_ci#define PSW_DE	0x0
488c2ecf20Sopenharmony_ci#endif
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#ifdef CONFIG_WBNA
518c2ecf20Sopenharmony_ci#define PSW_valWBNA	PSW_mskWBNA
528c2ecf20Sopenharmony_ci#else
538c2ecf20Sopenharmony_ci#define PSW_valWBNA	0x0
548c2ecf20Sopenharmony_ci#endif
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#ifdef CONFIG_HWZOL
578c2ecf20Sopenharmony_ci#define	PSW_valINIT (PSW_CPL_ANY | PSW_mskAEN | PSW_valWBNA | PSW_mskDT | PSW_mskIT | PSW_DE | PSW_mskGIE)
588c2ecf20Sopenharmony_ci#else
598c2ecf20Sopenharmony_ci#define	PSW_valINIT (PSW_CPL_ANY | PSW_valWBNA | PSW_mskDT | PSW_mskIT | PSW_DE | PSW_mskGIE)
608c2ecf20Sopenharmony_ci#endif
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#define start_thread(regs,pc,stack)			\
638c2ecf20Sopenharmony_ci({							\
648c2ecf20Sopenharmony_ci	memzero(regs, sizeof(struct pt_regs));		\
658c2ecf20Sopenharmony_ci	forget_syscall(regs);				\
668c2ecf20Sopenharmony_ci	regs->ipsw = PSW_valINIT;			\
678c2ecf20Sopenharmony_ci	regs->ir0 = (PSW_CPL_ANY | PSW_valWBNA | PSW_mskDT | PSW_mskIT | PSW_DE | PSW_SYSTEM | PSW_INTL_1);	\
688c2ecf20Sopenharmony_ci	regs->ipc = pc;					\
698c2ecf20Sopenharmony_ci	regs->sp = stack;				\
708c2ecf20Sopenharmony_ci})
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/* Forward declaration, a strange C thing */
738c2ecf20Sopenharmony_cistruct task_struct;
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/* Free all resources held by a thread. */
768c2ecf20Sopenharmony_ci#define release_thread(thread) do { } while(0)
778c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_FPU)
788c2ecf20Sopenharmony_ci#if !IS_ENABLED(CONFIG_UNLAZU_FPU)
798c2ecf20Sopenharmony_ciextern struct task_struct *last_task_used_math;
808c2ecf20Sopenharmony_ci#endif
818c2ecf20Sopenharmony_ci#endif
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci/* Prepare to copy thread state - unlazy all lazy status */
848c2ecf20Sopenharmony_ci#define prepare_to_copy(tsk)	do { } while (0)
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ciunsigned long get_wchan(struct task_struct *p);
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci#define cpu_relax()			barrier()
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#define task_pt_regs(task) \
918c2ecf20Sopenharmony_ci	((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE \
928c2ecf20Sopenharmony_ci		- 8) - 1)
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/*
958c2ecf20Sopenharmony_ci * Create a new kernel thread
968c2ecf20Sopenharmony_ci */
978c2ecf20Sopenharmony_ciextern int kernel_thread(int (*fn) (void *), void *arg, unsigned long flags);
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#define KSTK_EIP(tsk)	instruction_pointer(task_pt_regs(tsk))
1008c2ecf20Sopenharmony_ci#define KSTK_ESP(tsk)	user_stack_pointer(task_pt_regs(tsk))
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci#endif
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci#endif /* __ASM_NDS32_PROCESSOR_H */
105