Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <asm/uaccess.h> |
Yoshinori Sato | 9d4436a | 2006-11-05 15:40:13 +0900 | [diff] [blame] | 15 | #include <asm/addrspace.h> |
Paul Mundt | e2dfb91 | 2006-12-12 08:53:29 +0900 | [diff] [blame] | 16 | #include <asm/page.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | /* |
| 19 | * gzip declarations |
| 20 | */ |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #define STATIC static |
| 23 | |
| 24 | #undef memset |
| 25 | #undef memcpy |
| 26 | #define memzero(s, n) memset ((s), 0, (n)) |
| 27 | |
Paul Mundt | b14c6d4 | 2009-07-11 13:30:38 -0400 | [diff] [blame] | 28 | /* cache.c */ |
| 29 | #define CACHE_ENABLE 0 |
| 30 | #define CACHE_DISABLE 1 |
| 31 | int cache_control(unsigned int command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | extern char input_data[]; |
| 34 | extern int input_len; |
Paul Mundt | df8ce25 | 2009-07-12 01:37:30 +0900 | [diff] [blame] | 35 | static unsigned char *output; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | static void error(char *m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | int puts(const char *); |
| 40 | |
| 41 | extern int _text; /* Defined in vmlinux.lds.S */ |
| 42 | extern int _end; |
| 43 | static unsigned long free_mem_ptr; |
| 44 | static unsigned long free_mem_end_ptr; |
| 45 | |
Paul Mundt | 07e88e1 | 2009-07-11 13:21:19 -0400 | [diff] [blame] | 46 | #ifdef CONFIG_HAVE_KERNEL_BZIP2 |
| 47 | #define HEAP_SIZE 0x400000 |
| 48 | #else |
| 49 | #define HEAP_SIZE 0x10000 |
| 50 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Paul Mundt | df8ce25 | 2009-07-12 01:37:30 +0900 | [diff] [blame] | 52 | #ifdef CONFIG_KERNEL_GZIP |
| 53 | #include "../../../../lib/decompress_inflate.c" |
| 54 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Paul Mundt | 07e88e1 | 2009-07-11 13:21:19 -0400 | [diff] [blame] | 56 | #ifdef CONFIG_KERNEL_BZIP2 |
| 57 | #include "../../../../lib/decompress_bunzip2.c" |
| 58 | #endif |
| 59 | |
| 60 | #ifdef CONFIG_KERNEL_LZMA |
| 61 | #include "../../../../lib/decompress_unlzma.c" |
| 62 | #endif |
| 63 | |
Paul Mundt | c7b16ef | 2010-01-13 13:29:19 +0900 | [diff] [blame] | 64 | #ifdef CONFIG_KERNEL_LZO |
| 65 | #include "../../../../lib/decompress_unlzo.c" |
| 66 | #endif |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | int puts(const char *s) |
| 69 | { |
| 70 | /* This should be updated to use the sh-sci routines */ |
| 71 | return 0; |
| 72 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
| 74 | void* memset(void* s, int c, size_t n) |
| 75 | { |
| 76 | int i; |
| 77 | char *ss = (char*)s; |
| 78 | |
| 79 | for (i=0;i<n;i++) ss[i] = c; |
| 80 | return s; |
| 81 | } |
| 82 | |
| 83 | void* memcpy(void* __dest, __const void* __src, |
| 84 | size_t __n) |
| 85 | { |
| 86 | int i; |
| 87 | char *d = (char *)__dest, *s = (char *)__src; |
| 88 | |
| 89 | for (i=0;i<__n;i++) d[i] = s[i]; |
| 90 | return __dest; |
| 91 | } |
| 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | static void error(char *x) |
| 94 | { |
| 95 | puts("\n\n"); |
| 96 | puts(x); |
| 97 | puts("\n\n -- System halted"); |
| 98 | |
| 99 | while(1); /* Halt */ |
| 100 | } |
| 101 | |
Paul Mundt | b14c6d4 | 2009-07-11 13:30:38 -0400 | [diff] [blame] | 102 | #ifdef CONFIG_SUPERH64 |
| 103 | #define stackalign 8 |
| 104 | #else |
| 105 | #define stackalign 4 |
| 106 | #endif |
| 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | #define STACK_SIZE (4096) |
Paul Mundt | b14c6d4 | 2009-07-11 13:30:38 -0400 | [diff] [blame] | 109 | long __attribute__ ((aligned(stackalign))) user_stack[STACK_SIZE]; |
| 110 | long *stack_start = &user_stack[STACK_SIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | void decompress_kernel(void) |
| 113 | { |
Paul Mundt | df8ce25 | 2009-07-12 01:37:30 +0900 | [diff] [blame] | 114 | unsigned long output_addr; |
| 115 | |
Paul Mundt | 040f43e | 2009-07-11 13:36:25 -0400 | [diff] [blame] | 116 | #ifdef CONFIG_SUPERH64 |
| 117 | output_addr = (CONFIG_MEMORY_START + 0x2000); |
| 118 | #else |
Matt Fleming | 8bd642b | 2009-10-06 21:22:24 +0000 | [diff] [blame] | 119 | output_addr = __pa((unsigned long)&_text+PAGE_SIZE); |
Paul Mundt | d01447b | 2010-02-18 18:13:51 +0900 | [diff] [blame^] | 120 | #if defined(CONFIG_29BIT) |
Paul Mundt | df8ce25 | 2009-07-12 01:37:30 +0900 | [diff] [blame] | 121 | output_addr |= P2SEG; |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 122 | #endif |
Paul Mundt | 040f43e | 2009-07-11 13:36:25 -0400 | [diff] [blame] | 123 | #endif |
Paul Mundt | df8ce25 | 2009-07-12 01:37:30 +0900 | [diff] [blame] | 124 | |
| 125 | output = (unsigned char *)output_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | free_mem_ptr = (unsigned long)&_end; |
| 127 | free_mem_end_ptr = free_mem_ptr + HEAP_SIZE; |
| 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | puts("Uncompressing Linux... "); |
Paul Mundt | b14c6d4 | 2009-07-11 13:30:38 -0400 | [diff] [blame] | 130 | cache_control(CACHE_ENABLE); |
Paul Mundt | df8ce25 | 2009-07-12 01:37:30 +0900 | [diff] [blame] | 131 | decompress(input_data, input_len, NULL, NULL, output, NULL, error); |
Paul Mundt | b14c6d4 | 2009-07-11 13:30:38 -0400 | [diff] [blame] | 132 | cache_control(CACHE_DISABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | puts("Ok, booting the kernel.\n"); |
| 134 | } |