misc.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_SH_STANDARD_BIOS
  52. size_t strlen(const char *s)
  53. {
  54. int i = 0;
  55. while (*s++)
  56. i++;
  57. return i;
  58. }
  59. int puts(const char *s)
  60. {
  61. int len = strlen(s);
  62. sh_bios_console_write(s, len);
  63. return len;
  64. }
  65. #else
  66. int puts(const char *s)
  67. {
  68. /* This should be updated to use the sh-sci routines */
  69. return 0;
  70. }
  71. #endif
  72. void* memset(void* s, int c, size_t n)
  73. {
  74. int i;
  75. char *ss = (char*)s;
  76. for (i=0;i<n;i++) ss[i] = c;
  77. return s;
  78. }
  79. void* memcpy(void* __dest, __const void* __src,
  80. size_t __n)
  81. {
  82. int i;
  83. char *d = (char *)__dest, *s = (char *)__src;
  84. for (i=0;i<__n;i++) d[i] = s[i];
  85. return __dest;
  86. }
  87. static void error(char *x)
  88. {
  89. puts("\n\n");
  90. puts(x);
  91. puts("\n\n -- System halted");
  92. while(1); /* Halt */
  93. }
  94. #ifdef CONFIG_SUPERH64
  95. #define stackalign 8
  96. #else
  97. #define stackalign 4
  98. #endif
  99. #define STACK_SIZE (4096)
  100. long __attribute__ ((aligned(stackalign))) user_stack[STACK_SIZE];
  101. long *stack_start = &user_stack[STACK_SIZE];
  102. void decompress_kernel(void)
  103. {
  104. unsigned long output_addr;
  105. #ifdef CONFIG_SUPERH64
  106. output_addr = (CONFIG_MEMORY_START + 0x2000);
  107. #else
  108. output_addr = PHYSADDR((unsigned long)&_text+PAGE_SIZE);
  109. #ifdef CONFIG_29BIT
  110. output_addr |= P2SEG;
  111. #endif
  112. #endif
  113. output = (unsigned char *)output_addr;
  114. free_mem_ptr = (unsigned long)&_end;
  115. free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
  116. puts("Uncompressing Linux... ");
  117. cache_control(CACHE_ENABLE);
  118. decompress(input_data, input_len, NULL, NULL, output, NULL, error);
  119. cache_control(CACHE_DISABLE);
  120. puts("Ok, booting the kernel.\n");
  121. }