1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * include/asm-m68k/processor.h
4 *
5 * Copyright (C) 1995 Hamish Macdonald
6 */
7
8#ifndef __ASM_M68K_PROCESSOR_H
9#define __ASM_M68K_PROCESSOR_H
10
11#include <linux/preempt.h>
12#include <linux/thread_info.h>
13#include <asm/fpu.h>
14#include <asm/ptrace.h>
15
16static inline unsigned long rdusp(void)
17{
18#ifdef CONFIG_COLDFIRE_SW_A7
19	extern unsigned int sw_usp;
20	return sw_usp;
21#else
22	register unsigned long usp __asm__("a0");
23	/* move %usp,%a0 */
24	__asm__ __volatile__(".word 0x4e68" : "=a" (usp));
25	return usp;
26#endif
27}
28
29static inline void wrusp(unsigned long usp)
30{
31#ifdef CONFIG_COLDFIRE_SW_A7
32	extern unsigned int sw_usp;
33	sw_usp = usp;
34#else
35	register unsigned long a0 __asm__("a0") = usp;
36	/* move %a0,%usp */
37	__asm__ __volatile__(".word 0x4e60" : : "a" (a0) );
38#endif
39}
40
41/*
42 * User space process size: 3.75GB. This is hardcoded into a few places,
43 * so don't change it unless you know what you are doing.
44 */
45#ifdef CONFIG_MMU
46#if defined(CONFIG_COLDFIRE)
47#define TASK_SIZE	(0xC0000000UL)
48#elif defined(CONFIG_SUN3)
49#define TASK_SIZE	(0x0E000000UL)
50#else
51#define TASK_SIZE	(0xF0000000UL)
52#endif
53#else
54#define TASK_SIZE	(0xFFFFFFFFUL)
55#endif
56
57#ifdef __KERNEL__
58#define STACK_TOP	TASK_SIZE
59#define STACK_TOP_MAX	STACK_TOP
60#endif
61
62/* This decides where the kernel will search for a free chunk of vm
63 * space during mmap's.
64 */
65#ifdef CONFIG_MMU
66#if defined(CONFIG_COLDFIRE)
67#define TASK_UNMAPPED_BASE	0x60000000UL
68#elif defined(CONFIG_SUN3)
69#define TASK_UNMAPPED_BASE	0x0A000000UL
70#else
71#define TASK_UNMAPPED_BASE	0xC0000000UL
72#endif
73#define TASK_UNMAPPED_ALIGN(addr, off)	PAGE_ALIGN(addr)
74#else
75#define TASK_UNMAPPED_BASE	0
76#endif
77
78/* Address spaces (or Function Codes in Motorola lingo) */
79#define USER_DATA     1
80#define USER_PROGRAM  2
81#define SUPER_DATA    5
82#define SUPER_PROGRAM 6
83#define CPU_SPACE     7
84
85#ifdef CONFIG_CPU_HAS_ADDRESS_SPACES
86/*
87 * Set the SFC/DFC registers for special MM operations.  For most normal
88 * operation these remain set to USER_DATA for the uaccess routines.
89 */
90static inline void set_fc(unsigned long val)
91{
92	WARN_ON_ONCE(in_interrupt());
93
94	__asm__ __volatile__ ("movec %0,%/sfc\n\t"
95			      "movec %0,%/dfc\n\t"
96			      : /* no outputs */ : "r" (val) : "memory");
97}
98#else
99static inline void set_fc(unsigned long val)
100{
101}
102#endif /* CONFIG_CPU_HAS_ADDRESS_SPACES */
103
104struct thread_struct {
105	unsigned long  ksp;		/* kernel stack pointer */
106	unsigned long  usp;		/* user stack pointer */
107	unsigned short sr;		/* saved status register */
108	unsigned short fc;		/* saved fc (sfc, dfc) */
109	unsigned long  crp[2];		/* cpu root pointer */
110	unsigned long  esp0;		/* points to SR of stack frame */
111	unsigned long  faddr;		/* info about last fault */
112	int            signo, code;
113	unsigned long  fp[8*3];
114	unsigned long  fpcntl[3];	/* fp control regs */
115	unsigned char  fpstate[FPSTATESIZE];  /* floating point state */
116};
117
118#define INIT_THREAD  {							\
119	.ksp	= sizeof(init_stack) + (unsigned long) init_stack,	\
120	.sr	= PS_S,							\
121	.fc	= USER_DATA,						\
122}
123
124/*
125 * ColdFire stack format sbould be 0x4 for an aligned usp (will always be
126 * true on thread creation). We need to set this explicitly.
127 */
128#ifdef CONFIG_COLDFIRE
129#define setframeformat(_regs)	do { (_regs)->format = 0x4; } while(0)
130#else
131#define setframeformat(_regs)	do { } while (0)
132#endif
133
134/*
135 * Do necessary setup to start up a newly executed thread.
136 */
137static inline void start_thread(struct pt_regs * regs, unsigned long pc,
138				unsigned long usp)
139{
140	regs->pc = pc;
141	regs->sr &= ~0x2000;
142	setframeformat(regs);
143	wrusp(usp);
144}
145
146/* Forward declaration, a strange C thing */
147struct task_struct;
148
149unsigned long __get_wchan(struct task_struct *p);
150void show_registers(struct pt_regs *regs);
151
152#define	KSTK_EIP(tsk)	\
153    ({			\
154	unsigned long eip = 0;	 \
155	if ((tsk)->thread.esp0 > PAGE_SIZE && \
156	    (virt_addr_valid((tsk)->thread.esp0))) \
157	      eip = ((struct pt_regs *) (tsk)->thread.esp0)->pc; \
158	eip; })
159#define	KSTK_ESP(tsk)	((tsk) == current ? rdusp() : (tsk)->thread.usp)
160
161#define task_pt_regs(tsk)	((struct pt_regs *) ((tsk)->thread.esp0))
162
163#define cpu_relax()	barrier()
164
165#endif
166