bootp.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * arch/alpha/boot/bootp.c
  3. *
  4. * Copyright (C) 1997 Jay Estabrook
  5. *
  6. * This file is used for creating a bootp file for the Linux/AXP kernel
  7. *
  8. * based significantly on the arch/alpha/boot/main.c of Linus Torvalds
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/slab.h>
  12. #include <linux/string.h>
  13. #include <generated/utsrelease.h>
  14. #include <linux/mm.h>
  15. #include <asm/system.h>
  16. #include <asm/console.h>
  17. #include <asm/hwrpb.h>
  18. #include <asm/pgtable.h>
  19. #include <asm/io.h>
  20. #include <stdarg.h>
  21. #include "ksize.h"
  22. extern unsigned long switch_to_osf_pal(unsigned long nr,
  23. struct pcb_struct * pcb_va, struct pcb_struct * pcb_pa,
  24. unsigned long *vptb);
  25. extern void move_stack(unsigned long new_stack);
  26. struct hwrpb_struct *hwrpb = INIT_HWRPB;
  27. static struct pcb_struct pcb_va[1];
  28. /*
  29. * Find a physical address of a virtual object..
  30. *
  31. * This is easy using the virtual page table address.
  32. */
  33. static inline void *
  34. find_pa(unsigned long *vptb, void *ptr)
  35. {
  36. unsigned long address = (unsigned long) ptr;
  37. unsigned long result;
  38. result = vptb[address >> 13];
  39. result >>= 32;
  40. result <<= 13;
  41. result |= address & 0x1fff;
  42. return (void *) result;
  43. }
  44. /*
  45. * This function moves into OSF/1 pal-code, and has a temporary
  46. * PCB for that. The kernel proper should replace this PCB with
  47. * the real one as soon as possible.
  48. *
  49. * The page table muckery in here depends on the fact that the boot
  50. * code has the L1 page table identity-map itself in the second PTE
  51. * in the L1 page table. Thus the L1-page is virtually addressable
  52. * itself (through three levels) at virtual address 0x200802000.
  53. */
  54. #define VPTB ((unsigned long *) 0x200000000)
  55. #define L1 ((unsigned long *) 0x200802000)
  56. void
  57. pal_init(void)
  58. {
  59. unsigned long i, rev;
  60. struct percpu_struct * percpu;
  61. struct pcb_struct * pcb_pa;
  62. /* Create the dummy PCB. */
  63. pcb_va->ksp = 0;
  64. pcb_va->usp = 0;
  65. pcb_va->ptbr = L1[1] >> 32;
  66. pcb_va->asn = 0;
  67. pcb_va->pcc = 0;
  68. pcb_va->unique = 0;
  69. pcb_va->flags = 1;
  70. pcb_va->res1 = 0;
  71. pcb_va->res2 = 0;
  72. pcb_pa = find_pa(VPTB, pcb_va);
  73. /*
  74. * a0 = 2 (OSF)
  75. * a1 = return address, but we give the asm the vaddr of the PCB
  76. * a2 = physical addr of PCB
  77. * a3 = new virtual page table pointer
  78. * a4 = KSP (but the asm sets it)
  79. */
  80. srm_printk("Switching to OSF PAL-code .. ");
  81. i = switch_to_osf_pal(2, pcb_va, pcb_pa, VPTB);
  82. if (i) {
  83. srm_printk("failed, code %ld\n", i);
  84. __halt();
  85. }
  86. percpu = (struct percpu_struct *)
  87. (INIT_HWRPB->processor_offset + (unsigned long) INIT_HWRPB);
  88. rev = percpu->pal_revision = percpu->palcode_avail[2];
  89. srm_printk("Ok (rev %lx)\n", rev);
  90. tbia(); /* do it directly in case we are SMP */
  91. }
  92. static inline void
  93. load(unsigned long dst, unsigned long src, unsigned long count)
  94. {
  95. memcpy((void *)dst, (void *)src, count);
  96. }
  97. /*
  98. * Start the kernel.
  99. */
  100. static inline void
  101. runkernel(void)
  102. {
  103. __asm__ __volatile__(
  104. "bis %0,%0,$27\n\t"
  105. "jmp ($27)"
  106. : /* no outputs: it doesn't even return */
  107. : "r" (START_ADDR));
  108. }
  109. extern char _end;
  110. #define KERNEL_ORIGIN \
  111. ((((unsigned long)&_end) + 511) & ~511)
  112. void
  113. start_kernel(void)
  114. {
  115. /*
  116. * Note that this crufty stuff with static and envval
  117. * and envbuf is because:
  118. *
  119. * 1. Frequently, the stack is short, and we don't want to overrun;
  120. * 2. Frequently the stack is where we are going to copy the kernel to;
  121. * 3. A certain SRM console required the GET_ENV output to stack.
  122. * ??? A comment in the aboot sources indicates that the GET_ENV
  123. * destination must be quadword aligned. Might this explain the
  124. * behaviour, rather than requiring output to the stack, which
  125. * seems rather far-fetched.
  126. */
  127. static long nbytes;
  128. static char envval[256] __attribute__((aligned(8)));
  129. static unsigned long initrd_start;
  130. srm_printk("Linux/AXP bootp loader for Linux " UTS_RELEASE "\n");
  131. if (INIT_HWRPB->pagesize != 8192) {
  132. srm_printk("Expected 8kB pages, got %ldkB\n",
  133. INIT_HWRPB->pagesize >> 10);
  134. return;
  135. }
  136. if (INIT_HWRPB->vptb != (unsigned long) VPTB) {
  137. srm_printk("Expected vptb at %p, got %p\n",
  138. VPTB, (void *)INIT_HWRPB->vptb);
  139. return;
  140. }
  141. pal_init();
  142. /* The initrd must be page-aligned. See below for the
  143. cause of the magic number 5. */
  144. initrd_start = ((START_ADDR + 5*KERNEL_SIZE + PAGE_SIZE) |
  145. (PAGE_SIZE-1)) + 1;
  146. #ifdef INITRD_IMAGE_SIZE
  147. srm_printk("Initrd positioned at %#lx\n", initrd_start);
  148. #endif
  149. /*
  150. * Move the stack to a safe place to ensure it won't be
  151. * overwritten by kernel image.
  152. */
  153. move_stack(initrd_start - PAGE_SIZE);
  154. nbytes = callback_getenv(ENV_BOOTED_OSFLAGS, envval, sizeof(envval));
  155. if (nbytes < 0 || nbytes >= sizeof(envval)) {
  156. nbytes = 0;
  157. }
  158. envval[nbytes] = '\0';
  159. srm_printk("Loading the kernel...'%s'\n", envval);
  160. /* NOTE: *no* callbacks or printouts from here on out!!! */
  161. /* This is a hack, as some consoles seem to get virtual 20000000 (ie
  162. * where the SRM console puts the kernel bootp image) memory
  163. * overlapping physical memory where the kernel wants to be put,
  164. * which causes real problems when attempting to copy the former to
  165. * the latter... :-(
  166. *
  167. * So, we first move the kernel virtual-to-physical way above where
  168. * we physically want the kernel to end up, then copy it from there
  169. * to its final resting place... ;-}
  170. *
  171. * Sigh... */
  172. #ifdef INITRD_IMAGE_SIZE
  173. load(initrd_start, KERNEL_ORIGIN+KERNEL_SIZE, INITRD_IMAGE_SIZE);
  174. #endif
  175. load(START_ADDR+(4*KERNEL_SIZE), KERNEL_ORIGIN, KERNEL_SIZE);
  176. load(START_ADDR, START_ADDR+(4*KERNEL_SIZE), KERNEL_SIZE);
  177. memset((char*)ZERO_PGE, 0, PAGE_SIZE);
  178. strcpy((char*)ZERO_PGE, envval);
  179. #ifdef INITRD_IMAGE_SIZE
  180. ((long *)(ZERO_PGE+256))[0] = initrd_start;
  181. ((long *)(ZERO_PGE+256))[1] = INITRD_IMAGE_SIZE;
  182. #endif
  183. runkernel();
  184. }