Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Paul Mundt | a23ba43 | 2007-11-28 20:19:38 +0900 | [diff] [blame] | 2 | * arch/sh/boot/compressed/misc_64.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 SHmedia from sh by Stuart Menefy, May 2002 |
| 10 | */ |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <asm/uaccess.h> |
| 13 | |
| 14 | /* cache.c */ |
| 15 | #define CACHE_ENABLE 0 |
| 16 | #define CACHE_DISABLE 1 |
| 17 | int cache_control(unsigned int command); |
| 18 | |
| 19 | /* |
| 20 | * gzip declarations |
| 21 | */ |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #define STATIC static |
| 24 | |
| 25 | #undef memset |
| 26 | #undef memcpy |
| 27 | #define memzero(s, n) memset ((s), 0, (n)) |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | static void error(char *m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | extern char input_data[]; |
| 32 | extern int input_len; |
| 33 | |
Paul Mundt | df8ce25 | 2009-07-12 01:37:30 +0900 | [diff] [blame] | 34 | static unsigned char *output_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | static void puts(const char *); |
| 37 | |
| 38 | extern int _text; /* Defined in vmlinux.lds.S */ |
| 39 | extern int _end; |
| 40 | static unsigned long free_mem_ptr; |
| 41 | static unsigned long free_mem_end_ptr; |
| 42 | |
Paul Mundt | 07e88e1 | 2009-07-11 13:21:19 -0400 | [diff] [blame] | 43 | #ifdef CONFIG_HAVE_KERNEL_BZIP2 |
| 44 | #define HEAP_SIZE 0x400000 |
| 45 | #else |
| 46 | #define HEAP_SIZE 0x10000 |
| 47 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Paul Mundt | df8ce25 | 2009-07-12 01:37:30 +0900 | [diff] [blame] | 49 | #ifdef CONFIG_KERNEL_GZIP |
| 50 | #include "../../../../lib/decompress_inflate.c" |
| 51 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Paul Mundt | 07e88e1 | 2009-07-11 13:21:19 -0400 | [diff] [blame] | 53 | #ifdef CONFIG_KERNEL_BZIP2 |
| 54 | #include "../../../../lib/decompress_bunzip2.c" |
| 55 | #endif |
| 56 | |
| 57 | #ifdef CONFIG_KERNEL_LZMA |
| 58 | #include "../../../../lib/decompress_unlzma.c" |
| 59 | #endif |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | void puts(const char *s) |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | void *memset(void *s, int c, size_t n) |
| 66 | { |
| 67 | int i; |
| 68 | char *ss = (char *) s; |
| 69 | |
| 70 | for (i = 0; i < n; i++) |
| 71 | ss[i] = c; |
| 72 | return s; |
| 73 | } |
| 74 | |
| 75 | void *memcpy(void *__dest, __const void *__src, size_t __n) |
| 76 | { |
| 77 | int i; |
| 78 | char *d = (char *) __dest, *s = (char *) __src; |
| 79 | |
| 80 | for (i = 0; i < __n; i++) |
| 81 | d[i] = s[i]; |
| 82 | return __dest; |
| 83 | } |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | static void error(char *x) |
| 86 | { |
| 87 | puts("\n\n"); |
| 88 | puts(x); |
| 89 | puts("\n\n -- System halted"); |
| 90 | |
| 91 | while (1) ; /* Halt */ |
| 92 | } |
| 93 | |
| 94 | #define STACK_SIZE (4096) |
| 95 | long __attribute__ ((aligned(8))) user_stack[STACK_SIZE]; |
| 96 | long *stack_start = &user_stack[STACK_SIZE]; |
| 97 | |
| 98 | void decompress_kernel(void) |
| 99 | { |
Paul Mundt | df8ce25 | 2009-07-12 01:37:30 +0900 | [diff] [blame] | 100 | output_data = (unsigned char *) (CONFIG_MEMORY_START + 0x2000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | free_mem_ptr = (unsigned long) &_end; |
| 102 | free_mem_end_ptr = free_mem_ptr + HEAP_SIZE; |
| 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | puts("Uncompressing Linux... "); |
| 105 | cache_control(CACHE_ENABLE); |
Paul Mundt | df8ce25 | 2009-07-12 01:37:30 +0900 | [diff] [blame] | 106 | decompress(input_data, input_len, NULL, NULL, output_data, NULL, error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | cache_control(CACHE_DISABLE); |
Paul Mundt | df8ce25 | 2009-07-12 01:37:30 +0900 | [diff] [blame] | 108 | puts("Ok, booting the kernel.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |