main.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * arch/alpha/boot/main.c
  3. *
  4. * Copyright (C) 1994, 1995 Linus Torvalds
  5. *
  6. * This file is the bootloader for the Linux/AXP kernel
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/slab.h>
  10. #include <linux/string.h>
  11. #include <generated/utsrelease.h>
  12. #include <linux/mm.h>
  13. #include <asm/console.h>
  14. #include <asm/hwrpb.h>
  15. #include <asm/pgtable.h>
  16. #include <stdarg.h>
  17. #include "ksize.h"
  18. extern unsigned long switch_to_osf_pal(unsigned long nr,
  19. struct pcb_struct * pcb_va, struct pcb_struct * pcb_pa,
  20. unsigned long *vptb);
  21. struct hwrpb_struct *hwrpb = INIT_HWRPB;
  22. static struct pcb_struct pcb_va[1];
  23. /*
  24. * Find a physical address of a virtual object..
  25. *
  26. * This is easy using the virtual page table address.
  27. */
  28. static inline void *
  29. find_pa(unsigned long *vptb, void *ptr)
  30. {
  31. unsigned long address = (unsigned long) ptr;
  32. unsigned long result;
  33. result = vptb[address >> 13];
  34. result >>= 32;
  35. result <<= 13;
  36. result |= address & 0x1fff;
  37. return (void *) result;
  38. }
  39. /*
  40. * This function moves into OSF/1 pal-code, and has a temporary
  41. * PCB for that. The kernel proper should replace this PCB with
  42. * the real one as soon as possible.
  43. *
  44. * The page table muckery in here depends on the fact that the boot
  45. * code has the L1 page table identity-map itself in the second PTE
  46. * in the L1 page table. Thus the L1-page is virtually addressable
  47. * itself (through three levels) at virtual address 0x200802000.
  48. */
  49. #define VPTB ((unsigned long *) 0x200000000)
  50. #define L1 ((unsigned long *) 0x200802000)
  51. void
  52. pal_init(void)
  53. {
  54. unsigned long i, rev;
  55. struct percpu_struct * percpu;
  56. struct pcb_struct * pcb_pa;
  57. /* Create the dummy PCB. */
  58. pcb_va->ksp = 0;
  59. pcb_va->usp = 0;
  60. pcb_va->ptbr = L1[1] >> 32;
  61. pcb_va->asn = 0;
  62. pcb_va->pcc = 0;
  63. pcb_va->unique = 0;
  64. pcb_va->flags = 1;
  65. pcb_va->res1 = 0;
  66. pcb_va->res2 = 0;
  67. pcb_pa = find_pa(VPTB, pcb_va);
  68. /*
  69. * a0 = 2 (OSF)
  70. * a1 = return address, but we give the asm the vaddr of the PCB
  71. * a2 = physical addr of PCB
  72. * a3 = new virtual page table pointer
  73. * a4 = KSP (but the asm sets it)
  74. */
  75. srm_printk("Switching to OSF PAL-code .. ");
  76. i = switch_to_osf_pal(2, pcb_va, pcb_pa, VPTB);
  77. if (i) {
  78. srm_printk("failed, code %ld\n", i);
  79. __halt();
  80. }
  81. percpu = (struct percpu_struct *)
  82. (INIT_HWRPB->processor_offset + (unsigned long) INIT_HWRPB);
  83. rev = percpu->pal_revision = percpu->palcode_avail[2];
  84. srm_printk("Ok (rev %lx)\n", rev);
  85. tbia(); /* do it directly in case we are SMP */
  86. }
  87. static inline long openboot(void)
  88. {
  89. char bootdev[256];
  90. long result;
  91. result = callback_getenv(ENV_BOOTED_DEV, bootdev, 255);
  92. if (result < 0)
  93. return result;
  94. return callback_open(bootdev, result & 255);
  95. }
  96. static inline long close(long dev)
  97. {
  98. return callback_close(dev);
  99. }
  100. static inline long load(long dev, unsigned long addr, unsigned long count)
  101. {
  102. char bootfile[256];
  103. extern char _end;
  104. long result, boot_size = &_end - (char *) BOOT_ADDR;
  105. result = callback_getenv(ENV_BOOTED_FILE, bootfile, 255);
  106. if (result < 0)
  107. return result;
  108. result &= 255;
  109. bootfile[result] = '\0';
  110. if (result)
  111. srm_printk("Boot file specification (%s) not implemented\n",
  112. bootfile);
  113. return callback_read(dev, count, (void *)addr, boot_size/512 + 1);
  114. }
  115. /*
  116. * Start the kernel.
  117. */
  118. static void runkernel(void)
  119. {
  120. __asm__ __volatile__(
  121. "bis %1,%1,$30\n\t"
  122. "bis %0,%0,$26\n\t"
  123. "ret ($26)"
  124. : /* no outputs: it doesn't even return */
  125. : "r" (START_ADDR),
  126. "r" (PAGE_SIZE + INIT_STACK));
  127. }
  128. void start_kernel(void)
  129. {
  130. long i;
  131. long dev;
  132. int nbytes;
  133. char envval[256];
  134. srm_printk("Linux/AXP bootloader for Linux " UTS_RELEASE "\n");
  135. if (INIT_HWRPB->pagesize != 8192) {
  136. srm_printk("Expected 8kB pages, got %ldkB\n", INIT_HWRPB->pagesize >> 10);
  137. return;
  138. }
  139. pal_init();
  140. dev = openboot();
  141. if (dev < 0) {
  142. srm_printk("Unable to open boot device: %016lx\n", dev);
  143. return;
  144. }
  145. dev &= 0xffffffff;
  146. srm_printk("Loading vmlinux ...");
  147. i = load(dev, START_ADDR, KERNEL_SIZE);
  148. close(dev);
  149. if (i != KERNEL_SIZE) {
  150. srm_printk("Failed (%lx)\n", i);
  151. return;
  152. }
  153. nbytes = callback_getenv(ENV_BOOTED_OSFLAGS, envval, sizeof(envval));
  154. if (nbytes < 0) {
  155. nbytes = 0;
  156. }
  157. envval[nbytes] = '\0';
  158. strcpy((char*)ZERO_PGE, envval);
  159. srm_printk(" Ok\nNow booting the kernel\n");
  160. runkernel();
  161. for (i = 0 ; i < 0x100000000 ; i++)
  162. /* nothing */;
  163. __halt();
  164. }