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