1
2
3
4
5
6
7
8
9
10#include <linux/kernel.h>
11#include <linux/slab.h>
12#include <linux/string.h>
13#include <generated/utsrelease.h>
14#include <linux/mm.h>
15
16#include <asm/system.h>
17#include <asm/console.h>
18#include <asm/hwrpb.h>
19#include <asm/pgtable.h>
20#include <asm/io.h>
21
22#include <stdarg.h>
23
24#include "ksize.h"
25
26extern unsigned long switch_to_osf_pal(unsigned long nr,
27 struct pcb_struct * pcb_va, struct pcb_struct * pcb_pa,
28 unsigned long *vptb);
29
30extern void move_stack(unsigned long new_stack);
31
32struct hwrpb_struct *hwrpb = INIT_HWRPB;
33static struct pcb_struct pcb_va[1];
34
35
36
37
38
39
40
41static inline void *
42find_pa(unsigned long *vptb, void *ptr)
43{
44 unsigned long address = (unsigned long) ptr;
45 unsigned long result;
46
47 result = vptb[address >> 13];
48 result >>= 32;
49 result <<= 13;
50 result |= address & 0x1fff;
51 return (void *) result;
52}
53
54
55
56
57
58
59
60
61
62
63
64
65#define VPTB ((unsigned long *) 0x200000000)
66#define L1 ((unsigned long *) 0x200802000)
67
68void
69pal_init(void)
70{
71 unsigned long i, rev;
72 struct percpu_struct * percpu;
73 struct pcb_struct * pcb_pa;
74
75
76 pcb_va->ksp = 0;
77 pcb_va->usp = 0;
78 pcb_va->ptbr = L1[1] >> 32;
79 pcb_va->asn = 0;
80 pcb_va->pcc = 0;
81 pcb_va->unique = 0;
82 pcb_va->flags = 1;
83 pcb_va->res1 = 0;
84 pcb_va->res2 = 0;
85 pcb_pa = find_pa(VPTB, pcb_va);
86
87
88
89
90
91
92
93
94 srm_printk("Switching to OSF PAL-code .. ");
95
96 i = switch_to_osf_pal(2, pcb_va, pcb_pa, VPTB);
97 if (i) {
98 srm_printk("failed, code %ld\n", i);
99 __halt();
100 }
101
102 percpu = (struct percpu_struct *)
103 (INIT_HWRPB->processor_offset + (unsigned long) INIT_HWRPB);
104 rev = percpu->pal_revision = percpu->palcode_avail[2];
105
106 srm_printk("Ok (rev %lx)\n", rev);
107
108 tbia();
109}
110
111static inline void
112load(unsigned long dst, unsigned long src, unsigned long count)
113{
114 memcpy((void *)dst, (void *)src, count);
115}
116
117
118
119
120static inline void
121runkernel(void)
122{
123 __asm__ __volatile__(
124 "bis %0,%0,$27\n\t"
125 "jmp ($27)"
126 :
127 : "r" (START_ADDR));
128}
129
130extern char _end;
131#define KERNEL_ORIGIN \
132 ((((unsigned long)&_end) + 511) & ~511)
133
134void
135start_kernel(void)
136{
137
138
139
140
141
142
143
144
145
146
147
148
149 static long nbytes;
150 static char envval[256] __attribute__((aligned(8)));
151 static unsigned long initrd_start;
152
153 srm_printk("Linux/AXP bootp loader for Linux " UTS_RELEASE "\n");
154 if (INIT_HWRPB->pagesize != 8192) {
155 srm_printk("Expected 8kB pages, got %ldkB\n",
156 INIT_HWRPB->pagesize >> 10);
157 return;
158 }
159 if (INIT_HWRPB->vptb != (unsigned long) VPTB) {
160 srm_printk("Expected vptb at %p, got %p\n",
161 VPTB, (void *)INIT_HWRPB->vptb);
162 return;
163 }
164 pal_init();
165
166
167
168 initrd_start = ((START_ADDR + 5*KERNEL_SIZE + PAGE_SIZE) |
169 (PAGE_SIZE-1)) + 1;
170#ifdef INITRD_IMAGE_SIZE
171 srm_printk("Initrd positioned at %#lx\n", initrd_start);
172#endif
173
174
175
176
177
178 move_stack(initrd_start - PAGE_SIZE);
179
180 nbytes = callback_getenv(ENV_BOOTED_OSFLAGS, envval, sizeof(envval));
181 if (nbytes < 0 || nbytes >= sizeof(envval)) {
182 nbytes = 0;
183 }
184 envval[nbytes] = '\0';
185 srm_printk("Loading the kernel...'%s'\n", envval);
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201#ifdef INITRD_IMAGE_SIZE
202 load(initrd_start, KERNEL_ORIGIN+KERNEL_SIZE, INITRD_IMAGE_SIZE);
203#endif
204 load(START_ADDR+(4*KERNEL_SIZE), KERNEL_ORIGIN, KERNEL_SIZE);
205 load(START_ADDR, START_ADDR+(4*KERNEL_SIZE), KERNEL_SIZE);
206
207 memset((char*)ZERO_PGE, 0, PAGE_SIZE);
208 strcpy((char*)ZERO_PGE, envval);
209#ifdef INITRD_IMAGE_SIZE
210 ((long *)(ZERO_PGE+256))[0] = initrd_start;
211 ((long *)(ZERO_PGE+256))[1] = INITRD_IMAGE_SIZE;
212#endif
213
214 runkernel();
215}
216