coffmain.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:3k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * BK Id: SCCS/s.coffmain.c 1.15 01/11/02 10:46:07 trini
  3.  */
  4. /*
  5.  * Copyright (C) Paul Mackerras 1997.
  6.  *
  7.  * This program is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU General Public License
  9.  * as published by the Free Software Foundation; either version
  10.  * 2 of the License, or (at your option) any later version.
  11.  */
  12. #include <asm/processor.h>
  13. #include <asm/page.h>
  14. #include "nonstdio.h"
  15. #include "zlib.h"
  16. /* Passed from the linker */
  17. extern char __image_begin, __image_end;
  18. extern char __ramdisk_begin[], __ramdisk_end;
  19. extern char _start, _end;
  20. extern char *claim(unsigned, unsigned, unsigned);
  21. extern char image_data[], initrd_data[];
  22. extern int initrd_len, image_len;
  23. extern int getprop(void *, const char *, void *, int);
  24. extern unsigned int heap_max;
  25. extern void *finddevice(const char *);
  26. extern void flush_cache(void *start, unsigned int len);
  27. extern void gunzip(void *, int, unsigned char *, int *);
  28. extern void make_bi_recs(unsigned long addr, char *name, unsigned int mach,
  29. unsigned int progend);
  30. extern void pause(void);
  31. extern void setup_bats(unsigned long start);
  32. char *avail_ram;
  33. char *begin_avail, *end_avail;
  34. char *avail_high;
  35. #define RAM_START 0
  36. #define RAM_END (RAM_START + 0x800000) /* only 8M mapped with BATs */
  37. #define PROG_START RAM_START
  38. #define PROG_SIZE 0x00400000
  39. #define SCRATCH_SIZE (128 << 10)
  40. static char heap[SCRATCH_SIZE];
  41. void boot(int a1, int a2, void *prom)
  42. {
  43.     unsigned sa, len;
  44.     void *dst;
  45.     unsigned char *im;
  46.     unsigned initrd_start, initrd_size;
  47.     
  48.     printf("coffboot starting: loaded at 0x%pn", &_start);
  49.     setup_bats(RAM_START);
  50.     initrd_size = (char *)(&__ramdisk_end) - (char *)(&__ramdisk_begin);
  51.     if (initrd_size) {
  52. initrd_start = (RAM_END - initrd_size) & ~0xFFF;
  53. a1 = initrd_start;
  54. a2 = initrd_size;
  55. claim(initrd_start, RAM_END - initrd_start, 0);
  56. printf("initial ramdisk moving 0x%x <- 0x%p (%x bytes)nr",
  57.        initrd_start, (char *)(&__ramdisk_begin), initrd_size);
  58. memcpy((char *)initrd_start, (char *)(&__ramdisk_begin), initrd_size);
  59.     } else
  60. a2 = 0xdeadbeef;
  61.     im = (char *)(&__image_begin);
  62.     len = (char *)(&__image_end) - (char *)(&__image_begin);
  63.     /* claim 4MB starting at 0 */
  64.     claim(0, PROG_SIZE, 0);
  65.     dst = (void *) RAM_START;
  66.     if (im[0] == 0x1f && im[1] == 0x8b) {
  67. /* set up scratch space */
  68. begin_avail = avail_high = avail_ram = heap;
  69. end_avail = heap + sizeof(heap);
  70. printf("heap at 0x%pn", avail_ram);
  71. printf("gunzipping (0x%p <- 0x%p:0x%p)...", dst, im, im+len);
  72. gunzip(dst, PROG_SIZE, im, &len);
  73. printf("done %u bytesn", len);
  74. printf("%u bytes of heap consumed, max in use %un",
  75.        avail_high - begin_avail, heap_max);
  76.     } else {
  77. memmove(dst, im, len);
  78.     }
  79.     flush_cache(dst, len);
  80.     make_bi_recs(((unsigned long) dst + len), "coffboot", _MACH_Pmac,
  81.     (PROG_START + PROG_SIZE));
  82.     sa = (unsigned long)PROG_START;
  83.     printf("start address = 0x%xn", sa);
  84.     (*(void (*)())sa)(a1, a2, prom);
  85.     printf("returned?n");
  86.     pause();
  87. }