Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * arch/alpha/boot/bootp.c
0004  *
0005  * Copyright (C) 1997 Jay Estabrook
0006  *
0007  * This file is used for creating a bootp file for the Linux/AXP kernel
0008  *
0009  * based significantly on the arch/alpha/boot/main.c of Linus Torvalds
0010  */
0011 #include <linux/kernel.h>
0012 #include <linux/slab.h>
0013 #include <linux/string.h>
0014 #include <generated/utsrelease.h>
0015 #include <linux/mm.h>
0016 
0017 #include <asm/console.h>
0018 #include <asm/hwrpb.h>
0019 #include <asm/io.h>
0020 
0021 #include <stdarg.h>
0022 
0023 #include "ksize.h"
0024 
0025 extern unsigned long switch_to_osf_pal(unsigned long nr,
0026     struct pcb_struct *pcb_va, struct pcb_struct *pcb_pa,
0027     unsigned long *vptb);
0028 
0029 extern void move_stack(unsigned long new_stack);
0030 
0031 struct hwrpb_struct *hwrpb = INIT_HWRPB;
0032 static struct pcb_struct pcb_va[1];
0033 
0034 /*
0035  * Find a physical address of a virtual object..
0036  *
0037  * This is easy using the virtual page table address.
0038  */
0039 
0040 static inline void *
0041 find_pa(unsigned long *vptb, void *ptr)
0042 {
0043     unsigned long address = (unsigned long) ptr;
0044     unsigned long result;
0045 
0046     result = vptb[address >> 13];
0047     result >>= 32;
0048     result <<= 13;
0049     result |= address & 0x1fff;
0050     return (void *) result;
0051 }   
0052 
0053 /*
0054  * This function moves into OSF/1 pal-code, and has a temporary
0055  * PCB for that. The kernel proper should replace this PCB with
0056  * the real one as soon as possible.
0057  *
0058  * The page table muckery in here depends on the fact that the boot
0059  * code has the L1 page table identity-map itself in the second PTE
0060  * in the L1 page table. Thus the L1-page is virtually addressable
0061  * itself (through three levels) at virtual address 0x200802000.
0062  */
0063 
0064 #define VPTB    ((unsigned long *) 0x200000000)
0065 #define L1  ((unsigned long *) 0x200802000)
0066 
0067 void
0068 pal_init(void)
0069 {
0070     unsigned long i, rev;
0071     struct percpu_struct * percpu;
0072     struct pcb_struct * pcb_pa;
0073 
0074     /* Create the dummy PCB.  */
0075     pcb_va->ksp = 0;
0076     pcb_va->usp = 0;
0077     pcb_va->ptbr = L1[1] >> 32;
0078     pcb_va->asn = 0;
0079     pcb_va->pcc = 0;
0080     pcb_va->unique = 0;
0081     pcb_va->flags = 1;
0082     pcb_va->res1 = 0;
0083     pcb_va->res2 = 0;
0084     pcb_pa = find_pa(VPTB, pcb_va);
0085 
0086     /*
0087      * a0 = 2 (OSF)
0088      * a1 = return address, but we give the asm the vaddr of the PCB
0089      * a2 = physical addr of PCB
0090      * a3 = new virtual page table pointer
0091      * a4 = KSP (but the asm sets it)
0092      */
0093     srm_printk("Switching to OSF PAL-code .. ");
0094 
0095     i = switch_to_osf_pal(2, pcb_va, pcb_pa, VPTB);
0096     if (i) {
0097         srm_printk("failed, code %ld\n", i);
0098         __halt();
0099     }
0100 
0101     percpu = (struct percpu_struct *)
0102         (INIT_HWRPB->processor_offset + (unsigned long) INIT_HWRPB);
0103     rev = percpu->pal_revision = percpu->palcode_avail[2];
0104 
0105     srm_printk("Ok (rev %lx)\n", rev);
0106 
0107     tbia(); /* do it directly in case we are SMP */
0108 }
0109 
0110 static inline void
0111 load(unsigned long dst, unsigned long src, unsigned long count)
0112 {
0113     memcpy((void *)dst, (void *)src, count);
0114 }
0115 
0116 /*
0117  * Start the kernel.
0118  */
0119 static inline void
0120 runkernel(void)
0121 {
0122     __asm__ __volatile__(
0123         "bis %0,%0,$27\n\t"
0124         "jmp ($27)"
0125         : /* no outputs: it doesn't even return */
0126         : "r" (START_ADDR));
0127 }
0128 
0129 extern char _end;
0130 #define KERNEL_ORIGIN \
0131     ((((unsigned long)&_end) + 511) & ~511)
0132 
0133 void
0134 start_kernel(void)
0135 {
0136     /*
0137      * Note that this crufty stuff with static and envval
0138      * and envbuf is because:
0139      *
0140      * 1. Frequently, the stack is short, and we don't want to overrun;
0141      * 2. Frequently the stack is where we are going to copy the kernel to;
0142      * 3. A certain SRM console required the GET_ENV output to stack.
0143      *    ??? A comment in the aboot sources indicates that the GET_ENV
0144      *    destination must be quadword aligned.  Might this explain the
0145      *    behaviour, rather than requiring output to the stack, which
0146      *    seems rather far-fetched.
0147      */
0148     static long nbytes;
0149     static char envval[256] __attribute__((aligned(8)));
0150     static unsigned long initrd_start;
0151 
0152     srm_printk("Linux/AXP bootp loader for Linux " UTS_RELEASE "\n");
0153     if (INIT_HWRPB->pagesize != 8192) {
0154         srm_printk("Expected 8kB pages, got %ldkB\n",
0155                    INIT_HWRPB->pagesize >> 10);
0156         return;
0157     }
0158     if (INIT_HWRPB->vptb != (unsigned long) VPTB) {
0159         srm_printk("Expected vptb at %p, got %p\n",
0160                VPTB, (void *)INIT_HWRPB->vptb);
0161         return;
0162     }
0163     pal_init();
0164 
0165     /* The initrd must be page-aligned.  See below for the 
0166        cause of the magic number 5.  */
0167     initrd_start = ((START_ADDR + 5*KERNEL_SIZE + PAGE_SIZE) |
0168             (PAGE_SIZE-1)) + 1;
0169 #ifdef INITRD_IMAGE_SIZE
0170     srm_printk("Initrd positioned at %#lx\n", initrd_start);
0171 #endif
0172 
0173     /*
0174      * Move the stack to a safe place to ensure it won't be
0175      * overwritten by kernel image.
0176      */
0177     move_stack(initrd_start - PAGE_SIZE);
0178 
0179     nbytes = callback_getenv(ENV_BOOTED_OSFLAGS, envval, sizeof(envval));
0180     if (nbytes < 0 || nbytes >= sizeof(envval)) {
0181         nbytes = 0;
0182     }
0183     envval[nbytes] = '\0';
0184     srm_printk("Loading the kernel...'%s'\n", envval);
0185 
0186     /* NOTE: *no* callbacks or printouts from here on out!!! */
0187 
0188     /* This is a hack, as some consoles seem to get virtual 20000000 (ie
0189      * where the SRM console puts the kernel bootp image) memory
0190      * overlapping physical memory where the kernel wants to be put,
0191      * which causes real problems when attempting to copy the former to
0192      * the latter... :-(
0193      *
0194      * So, we first move the kernel virtual-to-physical way above where
0195      * we physically want the kernel to end up, then copy it from there
0196      * to its final resting place... ;-}
0197      *
0198      * Sigh...  */
0199 
0200 #ifdef INITRD_IMAGE_SIZE
0201     load(initrd_start, KERNEL_ORIGIN+KERNEL_SIZE, INITRD_IMAGE_SIZE);
0202 #endif
0203         load(START_ADDR+(4*KERNEL_SIZE), KERNEL_ORIGIN, KERNEL_SIZE);
0204         load(START_ADDR, START_ADDR+(4*KERNEL_SIZE), KERNEL_SIZE);
0205 
0206     memset((char*)ZERO_PGE, 0, PAGE_SIZE);
0207     strcpy((char*)ZERO_PGE, envval);
0208 #ifdef INITRD_IMAGE_SIZE
0209     ((long *)(ZERO_PGE+256))[0] = initrd_start;
0210     ((long *)(ZERO_PGE+256))[1] = INITRD_IMAGE_SIZE;
0211 #endif
0212 
0213     runkernel();
0214 }