main.c 4.3 KB

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