currentMemoryDefinition.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * arch/alpha/boot/bootpz.c
  3. *
  4. * Copyright (C) 1997 Jay Estabrook
  5. *
  6. * This file is used for creating a compressed BOOTP file for the
  7. * Linux/AXP kernel
  8. *
  9. * based significantly on the arch/alpha/boot/main.c of Linus Torvalds
  10. * and the decompression code from MILO.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/slab.h>
  14. #include <linux/string.h>
  15. #include <generated/utsrelease.h>
  16. #include <linux/mm.h>
  17. #include <asm/console.h>
  18. #include <asm/hwrpb.h>
  19. #include <asm/pgtable.h>
  20. #include <asm/io.h>
  21. #include <stdarg.h>
  22. #include "kzsize.h"
  23. /* FIXME FIXME FIXME */
  24. #define MALLOC_AREA_SIZE 0x200000 /* 2MB for now */
  25. /* FIXME FIXME FIXME */
  26. /*
  27. WARNING NOTE
  28. It is very possible that turning on additional messages may cause
  29. kernel image corruption due to stack usage to do the printing.
  30. */
  31. #undef DEBUG_CHECK_RANGE
  32. #undef DEBUG_ADDRESSES
  33. #undef DEBUG_LAST_STEPS
  34. extern unsigned long switch_to_osf_pal(unsigned long nr,
  35. struct pcb_struct * pcb_va, struct pcb_struct * pcb_pa,
  36. unsigned long *vptb);
  37. extern int decompress_kernel(void* destination, void *source,
  38. size_t ksize, size_t kzsize);
  39. extern void move_stack(unsigned long new_stack);
  40. struct hwrpb_struct *hwrpb = INIT_HWRPB;
  41. static struct pcb_struct pcb_va[1];
  42. /*
  43. * Find a physical address of a virtual object..
  44. *
  45. * This is easy using the virtual page table address.
  46. */
  47. #define VPTB ((unsigned long *) 0x200000000)
  48. static inline unsigned long
  49. find_pa(unsigned long address)
  50. {
  51. unsigned long result;
  52. result = VPTB[address >> 13];
  53. result >>= 32;
  54. result <<= 13;
  55. result |= address & 0x1fff;
  56. return result;
  57. }
  58. int
  59. check_range(unsigned long vstart, unsigned long vend,
  60. unsigned long kstart, unsigned long kend)
  61. {
  62. unsigned long vaddr, kaddr;
  63. #ifdef DEBUG_CHECK_RANGE
  64. srm_printk("check_range: V[0x%lx:0x%lx] K[0x%lx:0x%lx]\n",
  65. vstart, vend, kstart, kend);
  66. #endif
  67. /* do some range checking for detecting an overlap... */
  68. for (vaddr = vstart; vaddr <= vend; vaddr += PAGE_SIZE)
  69. {
  70. kaddr = (find_pa(vaddr) | PAGE_OFFSET);
  71. if (kaddr >= kstart && kaddr <= kend)
  72. {
  73. #ifdef DEBUG_CHECK_RANGE
  74. srm_printk("OVERLAP: vaddr 0x%lx kaddr 0x%lx"
  75. " [0x%lx:0x%lx]\n",
  76. vaddr, kaddr, kstart, kend);
  77. #endif
  78. return 1;
  79. }
  80. }
  81. return 0;
  82. }
  83. /*
  84. * This function moves into OSF/1 pal-code, and has a temporary
  85. * PCB for that. The kernel proper should replace this PCB with
  86. * the real one as soon as possible.
  87. *
  88. * The page table muckery in here depends on the fact that the boot
  89. * code has the L1 page table identity-map itself in the second PTE
  90. * in the L1 page table. Thus the L1-page is virtually addressable
  91. * itself (through three levels) at virtual address 0x200802000.
  92. */
  93. #define L1 ((unsigned long *) 0x200802000)
  94. void
  95. pal_init(void)
  96. {
  97. unsigned long i, rev;
  98. struct percpu_struct * percpu;
  99. struct pcb_struct * pcb_pa;
  100. /* Create the dummy PCB. */
  101. pcb_va->ksp = 0;
  102. pcb_va->usp = 0;
  103. pcb_va->ptbr = L1[1] >> 32;
  104. pcb_va->asn = 0;
  105. pcb_va->pcc = 0;
  106. pcb_va->unique = 0;
  107. pcb_va->flags = 1;
  108. pcb_va->res1 = 0;
  109. pcb_va->res2 = 0;
  110. pcb_pa = (struct pcb_struct *)find_pa((unsigned long)pcb_va);
  111. /*
  112. * a0 = 2 (OSF)
  113. * a1 = return address, but we give the asm the vaddr of the PCB
  114. * a2 = physical addr of PCB
  115. * a3 = new virtual page table pointer
  116. * a4 = KSP (but the asm sets it)
  117. */
  118. srm_printk("Switching to OSF PAL-code... ");
  119. i = switch_to_osf_pal(2, pcb_va, pcb_pa, VPTB);
  120. if (i) {
  121. srm_printk("failed, code %ld\n", i);
  122. __halt();
  123. }
  124. percpu = (struct percpu_struct *)
  125. (INIT_HWRPB->processor_offset + (unsigned long) INIT_HWRPB);
  126. rev = percpu->pal_revision = percpu->palcode_avail[2];
  127. srm_printk("OK (rev %lx)\n", rev);
  128. tbia(); /* do it directly in case we are SMP */
  129. }
  130. /*
  131. * Start the kernel.
  132. */
  133. static inline void
  134. runkernel(void)
  135. {
  136. __asm__ __volatile__(
  137. "bis %0,%0,$27\n\t"
  138. "jmp ($27)"
  139. : /* no outputs: it doesn't even return */
  140. : "r" (START_ADDR));
  141. }
  142. /* Must record the SP (it is virtual) on entry, so we can make sure
  143. not to overwrite it during movement or decompression. */
  144. unsigned long SP_on_entry;
  145. /* Calculate the kernel image address based on the end of the BOOTP
  146. bootstrapper (ie this program).
  147. */
  148. extern char _end;
  149. #define KERNEL_ORIGIN \
  150. ((((unsigned long)&_end) + 511) & ~511)
  151. /* Round address to next higher page boundary. */
  152. #define NEXT_PAGE(a) (((a) | (PAGE_SIZE - 1)) + 1)
  153. #ifdef INITRD_IMAGE_SIZE
  154. # define REAL_INITRD_SIZE INITRD_IMAGE_SIZE
  155. #else
  156. # define REAL_INITRD_SIZE 0
  157. #endif
  158. /* Defines from include/asm-alpha/system.h
  159. BOOT_ADDR Virtual address at which the consoles loads
  160. the BOOTP image.
  161. KERNEL_START KSEG address at which the kernel is built to run,
  162. which includes some initial data pages before the
  163. code.
  164. START_ADDR KSEG address of the entry point of kernel code.
  165. ZERO_PGE KSEG address of page full of zeroes, but
  166. upon entry to kerne cvan be expected
  167. to hold the parameter list and possible
  168. INTRD information.
  169. These are used in the local defines below.
  170. */
  171. /* Virtual addresses for the BOOTP image. Note that this includes the
  172. bootstrapper code as well as the compressed kernel image, and
  173. possibly the INITRD image.
  174. Oh, and do NOT forget the STACK, which appears to be placed virtually
  175. beyond the end of the loaded image.
  176. */
  177. #define V_BOOT_IMAGE_START BOOT_ADDR
  178. #define V_BOOT_IMAGE_END SP_on_entry
  179. /* Virtual addresses for just the bootstrapper part of the BOOTP image. */
  180. #define V_BOOTSTRAPPER_START BOOT_ADDR
  181. #define V_BOOTSTRAPPER_END KERNEL_ORIGIN
  182. /* Virtual addresses for just the data part of the BOOTP
  183. image. This may also include the INITRD image, but always
  184. includes the STACK.
  185. */
  186. #define V_DATA_START KERNEL_ORIGIN
  187. #define V_INITRD_START (KERNEL_ORIGIN + KERNEL_Z_SIZE)
  188. #define V_INTRD_END (V_INITRD_START + REAL_INITRD_SIZE)
  189. #define V_DATA_END V_BOOT_IMAGE_END
  190. /* KSEG addresses for the uncompressed kernel.
  191. Note that the end address includes workspace for the decompression.
  192. Note also that the DATA_START address is ZERO_PGE, to which we write
  193. just before jumping to the kernel image at START_ADDR.
  194. */
  195. #define K_KERNEL_DATA_START ZERO_PGE
  196. #define K_KERNEL_IMAGE_START START_ADDR
  197. #define K_KERNEL_IMAGE_END (START_ADDR + KERNEL_SIZE)
  198. /* Define to where we may have to decompress the kernel image, before