newworldmain.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 *start, unsigned int len);
  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_END (16 << 20)
  27. #define PROG_START 0x00010000
  28. #define PROG_SIZE 0x007f0000
  29. #define SCRATCH_SIZE (128 << 10)
  30. typedef void (*kernel_start_t)(int, int, void *);
  31. void boot(int a1, int a2, void *prom)
  32. {
  33. unsigned sa, len;
  34. void *dst;
  35. unsigned char *im;
  36. unsigned initrd_start, initrd_size;
  37. printf("chrpboot starting: loaded at 0x%p\n", &_start);
  38. initrd_size = (char *)(&__ramdisk_end) - (char *)(&__ramdisk_begin);
  39. if (initrd_size) {
  40. initrd_start = (RAM_END - initrd_size) & ~0xFFF;
  41. a1 = initrd_start;
  42. a2 = initrd_size;
  43. claim(initrd_start, RAM_END - initrd_start, 0);
  44. printf("initial ramdisk moving 0x%x <- 0x%p (%x bytes)\n\r",
  45. initrd_start, (char *)(&__ramdisk_begin), initrd_size);
  46. memcpy((char *)initrd_start, (char *)(&__ramdisk_begin), initrd_size);
  47. } else
  48. a2 = 0xdeadbeef;
  49. im = (char *)(&__image_begin);
  50. len = (char *)(&__image_end) - (char *)(&__image_begin);
  51. /* claim 3MB starting at PROG_START */
  52. claim(PROG_START, PROG_SIZE, 0);
  53. dst = (void *) PROG_START;
  54. if (im[0] == 0x1f && im[1] == 0x8b) {
  55. /* claim some memory for scratch space */
  56. avail_ram = (char *) claim(0, SCRATCH_SIZE, 0x10);
  57. begin_avail = avail_high = avail_ram;
  58. end_avail = avail_ram + SCRATCH_SIZE;
  59. printf("heap at 0x%p\n", avail_ram);
  60. printf("gunzipping (0x%p <- 0x%p:0x%p)...", dst, im, im+len);
  61. gunzip(dst, PROG_SIZE, im, &len);
  62. printf("done %u bytes\n", len);
  63. printf("%u bytes of heap consumed, max in use %u\n",
  64. avail_high - begin_avail, heap_max);
  65. release(begin_avail, SCRATCH_SIZE);
  66. } else {
  67. memmove(dst, im, len);
  68. }
  69. flush_cache(dst, len);
  70. make_bi_recs(((unsigned long) dst + len), "chrpboot", _MACH_Pmac,
  71. (PROG_START + PROG_SIZE));
  72. sa = (unsigned long)PROG_START;
  73. printf("start address = 0x%x\n", sa);
  74. (*(kernel_start_t)sa)(a1, a2, prom);
  75. printf("returned?\n");
  76. pause();
  77. }