Initial import from FreeBSD RELENG_4:
[games.git] / sys / boot / alpha / libalpha / prom_swpal.S
1 /* 
2  * $FreeBSD: src/sys/boot/alpha/libalpha/prom_swpal.S,v 1.2 1999/08/28 00:39:29 peter Exp $
3  * From: $NetBSD: prom_swpal.S,v 1.2 1997/04/06 08:41:01 cgd Exp $ 
4  */
5
6 /*
7  * Copyright (c) 1994, 1995 Carnegie-Mellon University.
8  * All rights reserved.
9  *
10  * Author: Keith Bostic
11  * 
12  * Permission to use, copy, modify and distribute this software and
13  * its documentation is hereby granted, provided that both the copyright
14  * notice and this permission notice appear in all copies of the
15  * software, derivative works or modified versions, and any portions
16  * thereof, and that both notices appear in supporting documentation.
17  * 
18  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 
19  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 
20  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
21  * 
22  * Carnegie Mellon requests users of this software to return to
23  *
24  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
25  *  School of Computer Science
26  *  Carnegie Mellon University
27  *  Pittsburgh PA 15213-3890
28  *
29  * any improvements or extensions that they make and grant Carnegie the
30  * rights to redistribute these changes.
31  */
32
33 #define ASSEMBLER
34 #include <machine/asm.h>
35 #include <machine/prom.h>
36 #include <machine/rpb.h>
37
38 /* Offsets from base of HWRPB. */       
39 #define RPB_SELFREF     0x00    
40 #define RPB_SLOTSIZE    0x98
41 #define RPB_PERCPU_OFF  0xA0
42
43 /* Offsets in a boot PCB. */
44 #define PCB_KSP         0x00    
45 #define PCB_PTBR        0x10
46 #define PCB_ASN         0x1c
47 #define PCB_FEN         0x28                    
48
49 /* Pal values. */
50 #define PAL_RESERVED    0               /* Reserved to Digital. */
51 #define PAL_VMS         1               /* VMS */
52 #define PAL_OSF         2               /* OSF */
53
54 /*
55  * PAL code switch routine.
56  */
57 #define D_RA                     (7*8)
58 #define D_S0                     (8*8)
59 #define D_S1                     (9*8)
60 #define D_S2                    (10*8)
61 #define D_S3                    (11*8)
62 #define D_S4                    (12*8)
63 #define D_S5                    (13*8)
64 #define PALSW_FRAME_SIZE        (14*8)
65 #define PALSW_REGS              IM_RA|IM_S0|IM_S1|IM_S2|IM_S3|IM_S4|IM_S5
66
67         .comm   ptbr_save,8
68
69         .text
70         .align  4
71
72 NESTED(switch_palcode, 0, PALSW_FRAME_SIZE, ra, PALSW_REGS, 0)
73         LDGP(pv)
74 /*      ldgp    gp, 0(pv)*/
75
76         lda     sp, -PALSW_FRAME_SIZE(sp)
77         stq     ra, D_RA(sp)
78         stq     s0, D_S0(sp)
79         stq     s1, D_S1(sp)
80         stq     s2, D_S2(sp)
81         stq     s3, D_S3(sp)
82         stq     s4, D_S4(sp)
83         stq     s5, D_S5(sp)
84
85         stq     pv, 0(sp)
86         stq     gp, 8(sp)
87         
88         ldiq    s0, HWRPB_ADDR          /* s0 HWRPB_ADDR */
89         ldq     s1, RPB_SLOTSIZE(s0)
90         call_pal PAL_VMS_mfpr_whami
91         mulq    s1, v0, s1              /* s1 per_cpu offset from base */
92         ldq     s2, RPB_PERCPU_OFF(s0)
93         addq    s0, s2, s2
94         addq    s2, s1, s2              /* s2  PCB (virtual) */
95         
96         call_pal PAL_VMS_mfpr_ptbr
97         stq     v0,   PCB_PTBR(s2)
98         stq     v0,   ptbr_save         /* save PTBR for the kernel */
99         stl     zero, PCB_ASN(s2)
100         stq     zero, PCB_FEN(s2)
101         stq     sp,   PCB_KSP(s2)
102         
103         ldq     t0, RPB_SELFREF(s0)     /* HWRBP base (physical) */
104         ldq     t1, RPB_PERCPU_OFF(s0)
105         addq    t0, t1, t0
106         addq    t0, s1, t0              /* PCB base (phys) */
107         stq     t0, 16(sp)
108
109         call_pal PAL_VMS_mfpr_vptb
110         mov     v0, a3
111         ldiq    a0, PAL_OSF
112         lda     a1, contin
113         ldq     a2, 16(sp)
114
115         call_pal PAL_swppal             /* a0, a1, a2, a3 */
116
117 contin: ldq     pv, 0(sp)
118         ldq     gp, 8(sp)
119
120         ldq     ra, D_RA(sp)
121         ldq     s0, D_S0(sp)
122         ldq     s1, D_S1(sp)
123         ldq     s2, D_S2(sp)
124         ldq     s3, D_S3(sp)
125         ldq     s4, D_S4(sp)
126         ldq     s5, D_S5(sp)
127         lda     sp, PALSW_FRAME_SIZE(sp)
128         RET
129 END(switch_palcode)
130
131 #undef  D_RA
132 #undef  D_S0
133 #undef  D_S1
134 #undef  D_S2
135 #undef  D_S3
136 #undef  D_S4
137 #undef  D_S5
138 #undef  PALSW_FRAME_SIZE
139 #undef  PALSW_REGS