blob: 1ab4f49153be00d0611e32c7909adf3bf42f6108 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/uaccess.h>
Yoshinori Sato9d4436a2006-11-05 15:40:13 +090015#include <asm/addrspace.h>
Paul Mundte2dfb912006-12-12 08:53:29 +090016#include <asm/page.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/sh_bios.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19/*
20 * gzip declarations
21 */
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#define STATIC static
24
25#undef memset
26#undef memcpy
27#define memzero(s, n) memset ((s), 0, (n))
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029static void error(char *m);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31extern char input_data[];
32extern int input_len;
Paul Mundtdf8ce252009-07-12 01:37:30 +090033static unsigned char *output;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035static void error(char *m);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37int puts(const char *);
38
39extern int _text; /* Defined in vmlinux.lds.S */
40extern int _end;
41static unsigned long free_mem_ptr;
42static unsigned long free_mem_end_ptr;
43
44#define HEAP_SIZE 0x10000
45
Paul Mundtdf8ce252009-07-12 01:37:30 +090046#ifdef CONFIG_KERNEL_GZIP
47#include "../../../../lib/decompress_inflate.c"
48#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#ifdef CONFIG_SH_STANDARD_BIOS
51size_t strlen(const char *s)
52{
53 int i = 0;
54
55 while (*s++)
56 i++;
57 return i;
58}
59
60int puts(const char *s)
61{
62 int len = strlen(s);
63 sh_bios_console_write(s, len);
64 return len;
65}
66#else
67int puts(const char *s)
68{
69 /* This should be updated to use the sh-sci routines */
70 return 0;
71}
72#endif
73
74void* 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
83void* 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 Torvalds1da177e2005-04-16 15:20:36 -070093static 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)
103long user_stack [STACK_SIZE];
104long* stack_start = &user_stack[STACK_SIZE];
105
106void decompress_kernel(void)
107{
Paul Mundtdf8ce252009-07-12 01:37:30 +0900108 unsigned long output_addr;
109
110 output_addr = PHYSADDR((unsigned long)&_text+PAGE_SIZE);
Stuart Menefyd02b08f2007-11-30 17:52:53 +0900111#ifdef CONFIG_29BIT
Paul Mundtdf8ce252009-07-12 01:37:30 +0900112 output_addr |= P2SEG;
Stuart Menefyd02b08f2007-11-30 17:52:53 +0900113#endif
Paul Mundtdf8ce252009-07-12 01:37:30 +0900114
115 output = (unsigned char *)output_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 free_mem_ptr = (unsigned long)&_end;
117 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 puts("Uncompressing Linux... ");
Paul Mundtdf8ce252009-07-12 01:37:30 +0900120 decompress(input_data, input_len, NULL, NULL, output, NULL, error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 puts("Ok, booting the kernel.\n");
122}