chrpmain.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C) Paul Mackerras 1997.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #include <linux/string.h>
  10. #include "nonstdio.h"
  11. #include "of1275.h"
  12. #include <asm/processor.h>
  13. #include <asm/page.h>
  14. /* Passed from the linker */
  15. extern char __image_begin, __image_end;
  16. extern char __ramdisk_begin, __ramdisk_end;
  17. extern char _start, _end;
  18. extern unsigned int heap_max;
  19. extern void flush_cache(void *, unsigned long);
  20. extern void gunzip(void *, int, unsigned char *, int *);
  21. extern void make_bi_recs(unsigned long addr, char *name, unsigned int mach,
  22. unsigned int progend);
  23. char *avail_ram;
  24. char *begin_avail, *end_avail;
  25. char *avail_high;
  26. #define RAM_START 0x00000000
  27. #define RAM_END (64<<20)
  28. #define BOOT_START ((unsigned long)_start)
  29. #define BOOT_END ((unsigned long)(_end + 0xFFF) & ~0xFFF)
  30. #define RAM_FREE ((unsigned long)(_end+0x1000)&~0xFFF)
  31. #define PROG_START 0x00010000
  32. #define PROG_SIZE 0x007f0000 /* 8MB */
  33. #define SCRATCH_SIZE (128 << 10)
  34. static char scratch[SCRATCH_SIZE]; /* 128k of scratch space for gunzip */
  35. typedef void (*kernel_start_t)(int, int, void *, unsigned int, unsigned int);
  36. void
  37. boot(int a1, int a2, void *prom)
  38. {
  39. unsigned sa, len;
  40. void *dst;
  41. unsigned char *im;
  42. unsigned int initrd_size, initrd_start;
  43. printf("chrpboot starting: loaded at 0x%p\n\r", &_start);
  44. initrd_size = &__ramdisk_end - &__ramdisk_begin;
  45. if (initrd_size) {
  46. initrd_start = (RAM_END - initrd_size) & ~0xFFF;
  47. a1 = initrd_start;
  48. a2 = initrd_size;
  49. claim(initrd_start, RAM_END - initrd_start, 0);
  50. printf("initial ramdisk moving 0x%x <- 0x%p (%x bytes)\n\r",
  51. initrd_start, &__ramdisk_begin, initrd_size);
  52. memcpy((char *)initrd_start, &__ramdisk_begin, initrd_size);
  53. } else {
  54. initrd_start = 0;
  55. initrd_size = 0;
  56. a2 = 0xdeadbeef;
  57. }
  58. im = &__image_begin;
  59. len = &__image_end - &__image_begin;
  60. /* claim 4MB starting at PROG_START */
  61. claim(PROG_START, PROG_SIZE - PROG_START, 0);
  62. dst = (void *) PROG_START;
  63. if (im[0] == 0x1f && im[1] == 0x8b) {
  64. avail_ram = scratch;
  65. begin_avail = avail_high = avail_ram;
  66. end_avail = scratch + sizeof(scratch);
  67. printf("gunzipping (0x%p <- 0x%p:0x%p)...", dst, im, im+len);
  68. gunzip(dst, 0x400000, im, &len);
  69. printf("done %u bytes\n\r", len);
  70. printf("%u bytes of heap consumed, max in use %u\n\r",
  71. avail_high - begin_avail, heap_max);
  72. } else {
  73. memmove(dst, im, len);
  74. }
  75. flush_cache(dst, len);
  76. make_bi_recs(((unsigned long) dst + len), "chrpboot", _MACH_chrp,
  77. (PROG_START + PROG_SIZE));
  78. sa = PROG_START;
  79. printf("start address = 0x%x\n\r", sa);
  80. (*(kernel_start_t)sa)(a1, a2, prom, initrd_start, initrd_size);
  81. printf("returned?\n\r");
  82. pause();
  83. }