xref: /openbsd-src/sys/arch/m88k/m88k/process.S (revision 5746cf2977bab637710f707ab6ffd43231ea7ce3)
1/*	$OpenBSD: process.S,v 1.27 2022/12/06 18:50:59 guenther Exp $	*/
2/*
3 * Copyright (c) 1996 Nivas Madhur
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 *    must display the following acknowledgement:
16 *      This product includes software developed by Nivas Madhur.
17 * 4. The name of the author may not be used to endorse or promote products
18 *    derived from this software without specific prior written permission
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 */
32
33#include "assym.h"
34#include <machine/asm.h>
35#include <machine/psl.h>
36
37/*
38 * void cpu_switchto(struct proc *oldproc, struct proc *newproc)
39 *
40 * Switch context from oldproc to newproc. oldproc may be NULL if there is
41 * no need to save the current context.
42 *
43 * Note that this code assumes that oldproc == curproc if not NULL.
44 */
45ENTRY(cpu_switchto)
46	/*
47	 * Save state of previous process in its pcb if required.
48	 */
49	bcnd	eq0,  %r2, 1f
50
51	ldcr	%r2,  CPU
52	ld	%r2,  %r2,  CI_CURPCB
53	st	%r1,  %r2,  PCB_PC		/* save return address */
54	bsr	__savectx
55	/* note that we don't need to recover r1 at this point */
56
57	/* inline pmap_deactivate(oldproc) */
58	ldcr	%r11, CPU
59	st	%r0,  %r11, CI_CURPMAP
60
611:
62	ldcr	%r2, PSR
63	set	%r2, %r2, 1<PSR_INTERRUPT_DISABLE_BIT>
64	stcr	%r2, PSR
65	FLUSH_PIPELINE
66
67	ldcr	%r11, CPU
68	st	%r3,  %r11, CI_CURPROC			/* curproc = newproc */
69
70	or	%r2,  %r0,  SONPROC
71	st.b	%r2,  %r3,  P_STAT
72#ifdef MULTIPROCESSOR
73	st	%r11, %r3,  P_CPU			/* p->p_cpu = curcpu */
74#endif
75	ld	%r2,  %r3,  P_ADDR
76	st	%r2,  %r11, CI_CURPCB			/* curpcb = p->p_addr */
77
78	bsr.n	pmap_activate			/* pmap_activate(newproc) */
79	 or	%r2, %r0, %r3
80
81	ldcr	%r2, PSR
82	clr	%r2, %r2, 1<PSR_INTERRUPT_DISABLE_BIT>
83	stcr	%r2, PSR
84	FLUSH_PIPELINE
85
86	ldcr	%r10,  CPU
87	ld	%r10,  %r10, CI_CURPCB
88
89	/* restore from the current context */
90	ld.d	%r2,  %r10, PCB_FCR62
91	fstcr	%r2,  %fcr62
92	fstcr	%r3,  %fcr63
93	ld	%r1,  %r10, PCB_PC
94	ld.d	%r14, %r10, PCB_R14
95	ld.d	%r16, %r10, PCB_R16
96	ld.d	%r18, %r10, PCB_R18
97	ld.d	%r20, %r10, PCB_R20
98	ld.d	%r22, %r10, PCB_R22
99	ld.d	%r24, %r10, PCB_R24
100	ld.d	%r26, %r10, PCB_R26
101	ld.d	%r28, %r10, PCB_R28
102	jmp.n	%r1
103	 ld.d	%r30, %r10, PCB_R30	/* restore frame pointer & stack */
104
105/*
106 * savectx(pcb)
107 * Update pcb, saving current processor state.
108 */
109ENTRY(savectx)
110	/*
111	 * Save preserved general register set.
112	 */
113	st	%r1,  %r2,  PCB_PC		/* save return address */
114ASLOCAL(__savectx)
115	st.d	%r14, %r2,  PCB_R14
116	st.d	%r16, %r2,  PCB_R16
117	st.d	%r18, %r2,  PCB_R18
118	st.d	%r20, %r2,  PCB_R20
119	st.d	%r22, %r2,  PCB_R22
120	st.d	%r24, %r2,  PCB_R24
121	st.d	%r26, %r2,  PCB_R26
122	st.d	%r28, %r2,  PCB_R28
123	st.d	%r30, %r2,  PCB_R30	/* save frame pointer & stack pointer */
124
125	/*
126	 * Save FP state.
127	 */
128	fldcr	%r4,  %fcr62
129	fldcr	%r5,  %fcr63
130	jmp.n	%r1
131	 st.d	%r4,  %r2, PCB_FCR62
132