misc.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * arch/sh/boot/compressed/misc.c
  3. *
  4. * This is a collection of several routines from gzip-1.0.3
  5. * adapted for Linux.
  6. *
  7. * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
  8. *
  9. * Adapted for SH by Stuart Menefy, Aug 1999
  10. *
  11. * Modified to use standard LinuxSH BIOS by Greg Banks 7Jul2000
  12. */
  13. #include <asm/uaccess.h>
  14. #include <asm/addrspace.h>
  15. #include <asm/page.h>
  16. #include <asm/sh_bios.h>
  17. /*
  18. * gzip declarations
  19. */
  20. #define STATIC static
  21. #undef memset
  22. #undef memcpy
  23. #define memzero(s, n) memset ((s), 0, (n))
  24. /* cache.c */
  25. #define CACHE_ENABLE 0
  26. #define CACHE_DISABLE 1
  27. int cache_control(unsigned int command);
  28. extern char input_data[];
  29. extern int input_len;
  30. static unsigned char *output;
  31. static void error(char *m);
  32. int puts(const char *);
  33. extern int _text; /* Defined in vmlinux.lds.S */
  34. extern int _end;
  35. static unsigned long free_mem_ptr;
  36. static unsigned long free_mem_end_ptr;
  37. #ifdef CONFIG_HAVE_KERNEL_BZIP2
  38. #define HEAP_SIZE 0x400000
  39. #else
  40. #define HEAP_SIZE 0x10000
  41. #endif
  42. #ifdef CONFIG_KERNEL_GZIP
  43. #include "../../../../lib/decompress_inflate.c"
  44. #endif
  45. #ifdef CONFIG_KERNEL_BZIP2
  46. #include "../../../../lib/decompress_bunzip2.c"
  47. #endif
  48. #ifdef CONFIG_KERNEL_LZMA
  49. #include "../../../../lib/decompress_unlzma.c"
  50. #endif
  51. #ifdef CONFIG_KERNEL_LZO
  52. #include "../../../../lib/decompress_unlzo.c"
  53. #endif
  54. #ifdef CONFIG_SH_STANDARD_BIOS
  55. size_t strlen(const char *s)
  56. {
  57. int i = 0;
  58. while (*s++)
  59. i++;
  60. return i;
  61. }
  62. int puts(const char *s)
  63. {
  64. int len = strlen(s);
  65. sh_bios_console_write(s, len);
  66. return len;
  67. }
  68. #else
  69. int puts(const char *s)
  70. {
  71. /* This should be updated to use the sh-sci routines */
  72. return 0;
  73. }
  74. #endif
  75. void* memset(void* s, int c, size_t n)
  76. {
  77. int i;
  78. char *ss = (char*)s;
  79. for (i=0;i<n;i++) ss[i] = c;
  80. return s;
  81. }
  82. void* memcpy(void* __dest, __const void* __src,
  83. size_t __n)
  84. {
  85. int i;
  86. char *d = (char *)__dest, *s = (char *)__src;
  87. for (i=0;i<__n;i++) d[i] = s[i];
  88. return __dest;
  89. }
  90. static void error(char *x)
  91. {
  92. puts("\n\n");
  93. puts(x);
  94. puts("\n\n -- System halted");
  95. while(1); /* Halt */
  96. }
  97. #ifdef CONFIG_SUPERH64
  98. #define stackalign 8
  99. #else
  100. #define stackalign 4
  101. #endif
  102. #define STACK_SIZE (4096)
  103. long __attribute__ ((aligned(stackalign))) user_stack[STACK_SIZE];
  104. long *stack_start = &user_stack[STACK_SIZE];
  105. void decompress_kernel(void)
  106. {
  107. unsigned long output_addr;
  108. #ifdef CONFIG_SUPERH64
  109. output_addr = (CONFIG_MEMORY_START + 0x2000);
  110. #else
  111. output_addr = __pa((unsigned long)&_text+PAGE_SIZE);
  112. #ifdef CONFIG_29BIT
  113. output_addr |= P2SEG;
  114. #endif
  115. #endif
  116. output = (unsigned char *)output_addr;
  117. free_mem_ptr = (unsigned long)&_end;
  118. free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
  119. puts("Uncompressing Linux... ");
  120. cache_control(CACHE_ENABLE);
  121. decompress(input_data, input_len, NULL, NULL, output, NULL, error);
  122. cache_control(CACHE_DISABLE);
  123. puts("Ok, booting the kernel.\n");
  124. }