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 | |
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; |
Paul Mundt | df8ce25 | 2009-07-12 01:37:30 +0900 | [diff] [blame^] | 33 | static unsigned char *output; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | static void error(char *m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | int puts(const char *); |
| 38 | |
| 39 | extern int _text; /* Defined in vmlinux.lds.S */ |
| 40 | extern int _end; |
| 41 | static unsigned long free_mem_ptr; |
| 42 | static unsigned long free_mem_end_ptr; |
| 43 | |
| 44 | #define HEAP_SIZE 0x10000 |
| 45 | |
Paul Mundt | df8ce25 | 2009-07-12 01:37:30 +0900 | [diff] [blame^] | 46 | #ifdef CONFIG_KERNEL_GZIP |
| 47 | #include "../../../../lib/decompress_inflate.c" |
| 48 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #ifdef CONFIG_SH_STANDARD_BIOS |
| 51 | size_t strlen(const char *s) |
| 52 | { |
| 53 | int i = 0; |
| 54 | |
| 55 | while (*s++) |
| 56 | i++; |
| 57 | return i; |
| 58 | } |
| 59 | |
| 60 | int puts(const char *s) |
| 61 | { |
| 62 | int len = strlen(s); |
| 63 | sh_bios_console_write(s, len); |
| 64 | return len; |
| 65 | } |
| 66 | #else |
| 67 | int puts(const char *s) |
| 68 | { |
| 69 | /* This should be updated to use the sh-sci routines */ |
| 70 | return 0; |
| 71 | } |
| 72 | #endif |
| 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 | |
| 102 | #define STACK_SIZE (4096) |
| 103 | long user_stack [STACK_SIZE]; |
| 104 | long* stack_start = &user_stack[STACK_SIZE]; |
| 105 | |
| 106 | void decompress_kernel(void) |
| 107 | { |
Paul Mundt | df8ce25 | 2009-07-12 01:37:30 +0900 | [diff] [blame^] | 108 | unsigned long output_addr; |
| 109 | |
| 110 | output_addr = PHYSADDR((unsigned long)&_text+PAGE_SIZE); |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 111 | #ifdef CONFIG_29BIT |
Paul Mundt | df8ce25 | 2009-07-12 01:37:30 +0900 | [diff] [blame^] | 112 | output_addr |= P2SEG; |
Stuart Menefy | d02b08f | 2007-11-30 17:52:53 +0900 | [diff] [blame] | 113 | #endif |
Paul Mundt | df8ce25 | 2009-07-12 01:37:30 +0900 | [diff] [blame^] | 114 | |
| 115 | output = (unsigned char *)output_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | free_mem_ptr = (unsigned long)&_end; |
| 117 | free_mem_end_ptr = free_mem_ptr + HEAP_SIZE; |
| 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | puts("Uncompressing Linux... "); |
Paul Mundt | df8ce25 | 2009-07-12 01:37:30 +0900 | [diff] [blame^] | 120 | decompress(input_data, input_len, NULL, NULL, output, NULL, error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | puts("Ok, booting the kernel.\n"); |
| 122 | } |