bootp.c 5.6 KB

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