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