18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * include/asm-m68k/processor.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 1995 Hamish Macdonald
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef __ASM_M68K_PROCESSOR_H
98c2ecf20Sopenharmony_ci#define __ASM_M68K_PROCESSOR_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/thread_info.h>
128c2ecf20Sopenharmony_ci#include <asm/segment.h>
138c2ecf20Sopenharmony_ci#include <asm/fpu.h>
148c2ecf20Sopenharmony_ci#include <asm/ptrace.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cistatic inline unsigned long rdusp(void)
178c2ecf20Sopenharmony_ci{
188c2ecf20Sopenharmony_ci#ifdef CONFIG_COLDFIRE_SW_A7
198c2ecf20Sopenharmony_ci	extern unsigned int sw_usp;
208c2ecf20Sopenharmony_ci	return sw_usp;
218c2ecf20Sopenharmony_ci#else
228c2ecf20Sopenharmony_ci	register unsigned long usp __asm__("a0");
238c2ecf20Sopenharmony_ci	/* move %usp,%a0 */
248c2ecf20Sopenharmony_ci	__asm__ __volatile__(".word 0x4e68" : "=a" (usp));
258c2ecf20Sopenharmony_ci	return usp;
268c2ecf20Sopenharmony_ci#endif
278c2ecf20Sopenharmony_ci}
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cistatic inline void wrusp(unsigned long usp)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci#ifdef CONFIG_COLDFIRE_SW_A7
328c2ecf20Sopenharmony_ci	extern unsigned int sw_usp;
338c2ecf20Sopenharmony_ci	sw_usp = usp;
348c2ecf20Sopenharmony_ci#else
358c2ecf20Sopenharmony_ci	register unsigned long a0 __asm__("a0") = usp;
368c2ecf20Sopenharmony_ci	/* move %a0,%usp */
378c2ecf20Sopenharmony_ci	__asm__ __volatile__(".word 0x4e60" : : "a" (a0) );
388c2ecf20Sopenharmony_ci#endif
398c2ecf20Sopenharmony_ci}
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/*
428c2ecf20Sopenharmony_ci * User space process size: 3.75GB. This is hardcoded into a few places,
438c2ecf20Sopenharmony_ci * so don't change it unless you know what you are doing.
448c2ecf20Sopenharmony_ci */
458c2ecf20Sopenharmony_ci#ifdef CONFIG_MMU
468c2ecf20Sopenharmony_ci#if defined(CONFIG_COLDFIRE)
478c2ecf20Sopenharmony_ci#define TASK_SIZE	(0xC0000000UL)
488c2ecf20Sopenharmony_ci#elif defined(CONFIG_SUN3)
498c2ecf20Sopenharmony_ci#define TASK_SIZE	(0x0E000000UL)
508c2ecf20Sopenharmony_ci#else
518c2ecf20Sopenharmony_ci#define TASK_SIZE	(0xF0000000UL)
528c2ecf20Sopenharmony_ci#endif
538c2ecf20Sopenharmony_ci#else
548c2ecf20Sopenharmony_ci#define TASK_SIZE	(0xFFFFFFFFUL)
558c2ecf20Sopenharmony_ci#endif
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#ifdef __KERNEL__
588c2ecf20Sopenharmony_ci#define STACK_TOP	TASK_SIZE
598c2ecf20Sopenharmony_ci#define STACK_TOP_MAX	STACK_TOP
608c2ecf20Sopenharmony_ci#endif
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci/* This decides where the kernel will search for a free chunk of vm
638c2ecf20Sopenharmony_ci * space during mmap's.
648c2ecf20Sopenharmony_ci */
658c2ecf20Sopenharmony_ci#ifdef CONFIG_MMU
668c2ecf20Sopenharmony_ci#if defined(CONFIG_COLDFIRE)
678c2ecf20Sopenharmony_ci#define TASK_UNMAPPED_BASE	0x60000000UL
688c2ecf20Sopenharmony_ci#elif defined(CONFIG_SUN3)
698c2ecf20Sopenharmony_ci#define TASK_UNMAPPED_BASE	0x0A000000UL
708c2ecf20Sopenharmony_ci#else
718c2ecf20Sopenharmony_ci#define TASK_UNMAPPED_BASE	0xC0000000UL
728c2ecf20Sopenharmony_ci#endif
738c2ecf20Sopenharmony_ci#define TASK_UNMAPPED_ALIGN(addr, off)	PAGE_ALIGN(addr)
748c2ecf20Sopenharmony_ci#else
758c2ecf20Sopenharmony_ci#define TASK_UNMAPPED_BASE	0
768c2ecf20Sopenharmony_ci#endif
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_cistruct thread_struct {
798c2ecf20Sopenharmony_ci	unsigned long  ksp;		/* kernel stack pointer */
808c2ecf20Sopenharmony_ci	unsigned long  usp;		/* user stack pointer */
818c2ecf20Sopenharmony_ci	unsigned short sr;		/* saved status register */
828c2ecf20Sopenharmony_ci	unsigned short fs;		/* saved fs (sfc, dfc) */
838c2ecf20Sopenharmony_ci	unsigned long  crp[2];		/* cpu root pointer */
848c2ecf20Sopenharmony_ci	unsigned long  esp0;		/* points to SR of stack frame */
858c2ecf20Sopenharmony_ci	unsigned long  faddr;		/* info about last fault */
868c2ecf20Sopenharmony_ci	int            signo, code;
878c2ecf20Sopenharmony_ci	unsigned long  fp[8*3];
888c2ecf20Sopenharmony_ci	unsigned long  fpcntl[3];	/* fp control regs */
898c2ecf20Sopenharmony_ci	unsigned char  fpstate[FPSTATESIZE];  /* floating point state */
908c2ecf20Sopenharmony_ci};
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#define INIT_THREAD  {							\
938c2ecf20Sopenharmony_ci	.ksp	= sizeof(init_stack) + (unsigned long) init_stack,	\
948c2ecf20Sopenharmony_ci	.sr	= PS_S,							\
958c2ecf20Sopenharmony_ci	.fs	= __KERNEL_DS,						\
968c2ecf20Sopenharmony_ci}
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci/*
998c2ecf20Sopenharmony_ci * ColdFire stack format sbould be 0x4 for an aligned usp (will always be
1008c2ecf20Sopenharmony_ci * true on thread creation). We need to set this explicitly.
1018c2ecf20Sopenharmony_ci */
1028c2ecf20Sopenharmony_ci#ifdef CONFIG_COLDFIRE
1038c2ecf20Sopenharmony_ci#define setframeformat(_regs)	do { (_regs)->format = 0x4; } while(0)
1048c2ecf20Sopenharmony_ci#else
1058c2ecf20Sopenharmony_ci#define setframeformat(_regs)	do { } while (0)
1068c2ecf20Sopenharmony_ci#endif
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/*
1098c2ecf20Sopenharmony_ci * Do necessary setup to start up a newly executed thread.
1108c2ecf20Sopenharmony_ci */
1118c2ecf20Sopenharmony_cistatic inline void start_thread(struct pt_regs * regs, unsigned long pc,
1128c2ecf20Sopenharmony_ci				unsigned long usp)
1138c2ecf20Sopenharmony_ci{
1148c2ecf20Sopenharmony_ci	regs->pc = pc;
1158c2ecf20Sopenharmony_ci	regs->sr &= ~0x2000;
1168c2ecf20Sopenharmony_ci	setframeformat(regs);
1178c2ecf20Sopenharmony_ci	wrusp(usp);
1188c2ecf20Sopenharmony_ci}
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci/* Forward declaration, a strange C thing */
1218c2ecf20Sopenharmony_cistruct task_struct;
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci/* Free all resources held by a thread. */
1248c2ecf20Sopenharmony_cistatic inline void release_thread(struct task_struct *dead_task)
1258c2ecf20Sopenharmony_ci{
1268c2ecf20Sopenharmony_ci}
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ciunsigned long get_wchan(struct task_struct *p);
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci#define	KSTK_EIP(tsk)	\
1318c2ecf20Sopenharmony_ci    ({			\
1328c2ecf20Sopenharmony_ci	unsigned long eip = 0;	 \
1338c2ecf20Sopenharmony_ci	if ((tsk)->thread.esp0 > PAGE_SIZE && \
1348c2ecf20Sopenharmony_ci	    (virt_addr_valid((tsk)->thread.esp0))) \
1358c2ecf20Sopenharmony_ci	      eip = ((struct pt_regs *) (tsk)->thread.esp0)->pc; \
1368c2ecf20Sopenharmony_ci	eip; })
1378c2ecf20Sopenharmony_ci#define	KSTK_ESP(tsk)	((tsk) == current ? rdusp() : (tsk)->thread.usp)
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci#define task_pt_regs(tsk)	((struct pt_regs *) ((tsk)->thread.esp0))
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci#define cpu_relax()	barrier()
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci#endif
144