1*b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * arch/alpha/boot/main.c 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Copyright (C) 1994, 1995 Linus Torvalds 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * This file is the bootloader for the Linux/AXP kernel 81da177e4SLinus Torvalds */ 91da177e4SLinus Torvalds #include <linux/kernel.h> 105a0e3ad6STejun Heo #include <linux/slab.h> 111da177e4SLinus Torvalds #include <linux/string.h> 12273b281fSSam Ravnborg #include <generated/utsrelease.h> 131da177e4SLinus Torvalds #include <linux/mm.h> 141da177e4SLinus Torvalds 151da177e4SLinus Torvalds #include <asm/console.h> 161da177e4SLinus Torvalds #include <asm/hwrpb.h> 171da177e4SLinus Torvalds #include <asm/pgtable.h> 181da177e4SLinus Torvalds 191da177e4SLinus Torvalds #include <stdarg.h> 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds #include "ksize.h" 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds extern unsigned long switch_to_osf_pal(unsigned long nr, 241da177e4SLinus Torvalds struct pcb_struct * pcb_va, struct pcb_struct * pcb_pa, 251da177e4SLinus Torvalds unsigned long *vptb); 261da177e4SLinus Torvalds struct hwrpb_struct *hwrpb = INIT_HWRPB; 271da177e4SLinus Torvalds static struct pcb_struct pcb_va[1]; 281da177e4SLinus Torvalds 291da177e4SLinus Torvalds /* 301da177e4SLinus Torvalds * Find a physical address of a virtual object.. 311da177e4SLinus Torvalds * 321da177e4SLinus Torvalds * This is easy using the virtual page table address. 331da177e4SLinus Torvalds */ 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds static inline void * 361da177e4SLinus Torvalds find_pa(unsigned long *vptb, void *ptr) 371da177e4SLinus Torvalds { 381da177e4SLinus Torvalds unsigned long address = (unsigned long) ptr; 391da177e4SLinus Torvalds unsigned long result; 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds result = vptb[address >> 13]; 421da177e4SLinus Torvalds result >>= 32; 431da177e4SLinus Torvalds result <<= 13; 441da177e4SLinus Torvalds result |= address & 0x1fff; 451da177e4SLinus Torvalds return (void *) result; 461da177e4SLinus Torvalds } 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds /* 491da177e4SLinus Torvalds * This function moves into OSF/1 pal-code, and has a temporary 501da177e4SLinus Torvalds * PCB for that. The kernel proper should replace this PCB with 511da177e4SLinus Torvalds * the real one as soon as possible. 521da177e4SLinus Torvalds * 531da177e4SLinus Torvalds * The page table muckery in here depends on the fact that the boot 541da177e4SLinus Torvalds * code has the L1 page table identity-map itself in the second PTE 551da177e4SLinus Torvalds * in the L1 page table. Thus the L1-page is virtually addressable 561da177e4SLinus Torvalds * itself (through three levels) at virtual address 0x200802000. 571da177e4SLinus Torvalds */ 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds #define VPTB ((unsigned long *) 0x200000000) 601da177e4SLinus Torvalds #define L1 ((unsigned long *) 0x200802000) 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds void 631da177e4SLinus Torvalds pal_init(void) 641da177e4SLinus Torvalds { 651da177e4SLinus Torvalds unsigned long i, rev; 661da177e4SLinus Torvalds struct percpu_struct * percpu; 671da177e4SLinus Torvalds struct pcb_struct * pcb_pa; 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds /* Create the dummy PCB. */ 701da177e4SLinus Torvalds pcb_va->ksp = 0; 711da177e4SLinus Torvalds pcb_va->usp = 0; 721da177e4SLinus Torvalds pcb_va->ptbr = L1[1] >> 32; 731da177e4SLinus Torvalds pcb_va->asn = 0; 741da177e4SLinus Torvalds pcb_va->pcc = 0; 751da177e4SLinus Torvalds pcb_va->unique = 0; 761da177e4SLinus Torvalds pcb_va->flags = 1; 771da177e4SLinus Torvalds pcb_va->res1 = 0; 781da177e4SLinus Torvalds pcb_va->res2 = 0; 791da177e4SLinus Torvalds pcb_pa = find_pa(VPTB, pcb_va); 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds /* 821da177e4SLinus Torvalds * a0 = 2 (OSF) 831da177e4SLinus Torvalds * a1 = return address, but we give the asm the vaddr of the PCB 841da177e4SLinus Torvalds * a2 = physical addr of PCB 851da177e4SLinus Torvalds * a3 = new virtual page table pointer 861da177e4SLinus Torvalds * a4 = KSP (but the asm sets it) 871da177e4SLinus Torvalds */ 881da177e4SLinus Torvalds srm_printk("Switching to OSF PAL-code .. "); 891da177e4SLinus Torvalds 901da177e4SLinus Torvalds i = switch_to_osf_pal(2, pcb_va, pcb_pa, VPTB); 911da177e4SLinus Torvalds if (i) { 921da177e4SLinus Torvalds srm_printk("failed, code %ld\n", i); 931da177e4SLinus Torvalds __halt(); 941da177e4SLinus Torvalds } 951da177e4SLinus Torvalds 961da177e4SLinus Torvalds percpu = (struct percpu_struct *) 971da177e4SLinus Torvalds (INIT_HWRPB->processor_offset + (unsigned long) INIT_HWRPB); 981da177e4SLinus Torvalds rev = percpu->pal_revision = percpu->palcode_avail[2]; 991da177e4SLinus Torvalds 1001da177e4SLinus Torvalds srm_printk("Ok (rev %lx)\n", rev); 1011da177e4SLinus Torvalds 1021da177e4SLinus Torvalds tbia(); /* do it directly in case we are SMP */ 1031da177e4SLinus Torvalds } 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds static inline long openboot(void) 1061da177e4SLinus Torvalds { 1071da177e4SLinus Torvalds char bootdev[256]; 1081da177e4SLinus Torvalds long result; 1091da177e4SLinus Torvalds 1101da177e4SLinus Torvalds result = callback_getenv(ENV_BOOTED_DEV, bootdev, 255); 1111da177e4SLinus Torvalds if (result < 0) 1121da177e4SLinus Torvalds return result; 1131da177e4SLinus Torvalds return callback_open(bootdev, result & 255); 1141da177e4SLinus Torvalds } 1151da177e4SLinus Torvalds 1161da177e4SLinus Torvalds static inline long close(long dev) 1171da177e4SLinus Torvalds { 1181da177e4SLinus Torvalds return callback_close(dev); 1191da177e4SLinus Torvalds } 1201da177e4SLinus Torvalds 1211da177e4SLinus Torvalds static inline long load(long dev, unsigned long addr, unsigned long count) 1221da177e4SLinus Torvalds { 1231da177e4SLinus Torvalds char bootfile[256]; 1241da177e4SLinus Torvalds extern char _end; 1251da177e4SLinus Torvalds long result, boot_size = &_end - (char *) BOOT_ADDR; 1261da177e4SLinus Torvalds 1271da177e4SLinus Torvalds result = callback_getenv(ENV_BOOTED_FILE, bootfile, 255); 1281da177e4SLinus Torvalds if (result < 0) 1291da177e4SLinus Torvalds return result; 1301da177e4SLinus Torvalds result &= 255; 1311da177e4SLinus Torvalds bootfile[result] = '\0'; 1321da177e4SLinus Torvalds if (result) 1331da177e4SLinus Torvalds srm_printk("Boot file specification (%s) not implemented\n", 1341da177e4SLinus Torvalds bootfile); 1359965a5d5SMeelis Roos return callback_read(dev, count, (void *)addr, boot_size/512 + 1); 1361da177e4SLinus Torvalds } 1371da177e4SLinus Torvalds 1381da177e4SLinus Torvalds /* 1391da177e4SLinus Torvalds * Start the kernel. 1401da177e4SLinus Torvalds */ 1411da177e4SLinus Torvalds static void runkernel(void) 1421da177e4SLinus Torvalds { 1431da177e4SLinus Torvalds __asm__ __volatile__( 1441da177e4SLinus Torvalds "bis %1,%1,$30\n\t" 1451da177e4SLinus Torvalds "bis %0,%0,$26\n\t" 1461da177e4SLinus Torvalds "ret ($26)" 1471da177e4SLinus Torvalds : /* no outputs: it doesn't even return */ 1481da177e4SLinus Torvalds : "r" (START_ADDR), 1491da177e4SLinus Torvalds "r" (PAGE_SIZE + INIT_STACK)); 1501da177e4SLinus Torvalds } 1511da177e4SLinus Torvalds 1521da177e4SLinus Torvalds void start_kernel(void) 1531da177e4SLinus Torvalds { 1541da177e4SLinus Torvalds long i; 1551da177e4SLinus Torvalds long dev; 1561da177e4SLinus Torvalds int nbytes; 1571da177e4SLinus Torvalds char envval[256]; 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvalds srm_printk("Linux/AXP bootloader for Linux " UTS_RELEASE "\n"); 1601da177e4SLinus Torvalds if (INIT_HWRPB->pagesize != 8192) { 1611da177e4SLinus Torvalds srm_printk("Expected 8kB pages, got %ldkB\n", INIT_HWRPB->pagesize >> 10); 1621da177e4SLinus Torvalds return; 1631da177e4SLinus Torvalds } 1641da177e4SLinus Torvalds pal_init(); 1651da177e4SLinus Torvalds dev = openboot(); 1661da177e4SLinus Torvalds if (dev < 0) { 1671da177e4SLinus Torvalds srm_printk("Unable to open boot device: %016lx\n", dev); 1681da177e4SLinus Torvalds return; 1691da177e4SLinus Torvalds } 1701da177e4SLinus Torvalds dev &= 0xffffffff; 1711da177e4SLinus Torvalds srm_printk("Loading vmlinux ..."); 1721da177e4SLinus Torvalds i = load(dev, START_ADDR, KERNEL_SIZE); 1731da177e4SLinus Torvalds close(dev); 1741da177e4SLinus Torvalds if (i != KERNEL_SIZE) { 1751da177e4SLinus Torvalds srm_printk("Failed (%lx)\n", i); 1761da177e4SLinus Torvalds return; 1771da177e4SLinus Torvalds } 1781da177e4SLinus Torvalds 1791da177e4SLinus Torvalds nbytes = callback_getenv(ENV_BOOTED_OSFLAGS, envval, sizeof(envval)); 1801da177e4SLinus Torvalds if (nbytes < 0) { 1811da177e4SLinus Torvalds nbytes = 0; 1821da177e4SLinus Torvalds } 1831da177e4SLinus Torvalds envval[nbytes] = '\0'; 1841da177e4SLinus Torvalds strcpy((char*)ZERO_PGE, envval); 1851da177e4SLinus Torvalds 1861da177e4SLinus Torvalds srm_printk(" Ok\nNow booting the kernel\n"); 1871da177e4SLinus Torvalds runkernel(); 1881da177e4SLinus Torvalds for (i = 0 ; i < 0x100000000 ; i++) 1891da177e4SLinus Torvalds /* nothing */; 1901da177e4SLinus Torvalds __halt(); 1911da177e4SLinus Torvalds } 192