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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * BK Id: SCCS/s.chrpmain.c 1.18 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 "nonstdio.h"
  13. #include <asm/processor.h>
  14. #include <asm/page.h>
  15. /* Passed from the linker */
  16. extern char __image_begin, __image_end;
  17. extern char __ramdisk_begin[], __ramdisk_end;
  18. extern char _start, _end;
  19. extern int getprop(void *, const char *, void *, int);
  20. extern unsigned int heap_max;
  21. extern void *claim(unsigned int virt, unsigned int size, unsigned int align);
  22. extern void *finddevice(const char *);
  23. extern void flush_cache(void *start, unsigned int len);
  24. extern void gunzip(void *, int, unsigned char *, int *);
  25. extern void make_bi_recs(unsigned long addr, char *name, unsigned int mach,
  26. unsigned int progend);
  27. extern void pause(void);
  28. extern void release(void *ptr, unsigned int len);
  29. char *avail_ram;
  30. char *begin_avail, *end_avail;
  31. char *avail_high;
  32. #define RAM_END (16 << 20)
  33. #define PROG_START 0x00010000
  34. #define PROG_SIZE 0x003f0000
  35. #define SCRATCH_SIZE (128 << 10)
  36. void boot(int a1, int a2, void *prom)
  37. {
  38.     unsigned sa, len;
  39.     void *dst;
  40.     unsigned char *im;
  41.     unsigned initrd_start, initrd_size;
  42.     
  43.     printf("chrpboot starting: loaded at 0x%pn", &_start);
  44.     initrd_size = (char *)(&__ramdisk_end) - (char *)(&__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)nr",
  51.        initrd_start, (char *)(&__ramdisk_begin), initrd_size);
  52. memcpy((char *)initrd_start, (char *)(&__ramdisk_begin), initrd_size);
  53.     } else
  54. a2 = 0xdeadbeef;
  55.     im = (char *)(&__image_begin);
  56.     len = (char *)(&__image_end) - (char *)(&__image_begin);
  57.     /* claim 3MB starting at PROG_START */
  58.     claim(PROG_START, PROG_SIZE, 0);
  59.     dst = (void *) PROG_START;
  60.     if (im[0] == 0x1f && im[1] == 0x8b) {
  61. /* claim some memory for scratch space */
  62. avail_ram = (char *) claim(0, SCRATCH_SIZE, 0x10);
  63. begin_avail = avail_high = avail_ram;
  64. end_avail = avail_ram + SCRATCH_SIZE;
  65. printf("heap at 0x%pn", avail_ram);
  66. printf("gunzipping (0x%p <- 0x%p:0x%p)...", dst, im, im+len);
  67. gunzip(dst, PROG_SIZE, im, &len);
  68. printf("done %u bytesn", len);
  69. printf("%u bytes of heap consumed, max in use %un",
  70.        avail_high - begin_avail, heap_max);
  71. release(begin_avail, SCRATCH_SIZE);
  72.     } else {
  73. memmove(dst, im, len);
  74.     }
  75.     flush_cache(dst, len);
  76.     make_bi_recs(((unsigned long) dst + len), "chrpboot", _MACH_Pmac,
  77.     (PROG_START + PROG_SIZE));
  78.     sa = (unsigned long)PROG_START;
  79.     printf("start address = 0x%xn", sa);
  80.     (*(void (*)())sa)(a1, a2, prom);
  81.     printf("returned?n");
  82.     pause();
  83. }