1778cb929SIan Campbell /* 2778cb929SIan Campbell * misc.c 3778cb929SIan Campbell * 4778cb929SIan Campbell * This is a collection of several routines from gzip-1.0.3 5778cb929SIan Campbell * adapted for Linux. 6778cb929SIan Campbell * 7778cb929SIan Campbell * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994 8778cb929SIan Campbell * puts by Nick Holloway 1993, better puts by Martin Mares 1995 9778cb929SIan Campbell * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996 10778cb929SIan Campbell */ 11778cb929SIan Campbell 12778cb929SIan Campbell /* 13778cb929SIan Campbell * we have to be careful, because no indirections are allowed here, and 14778cb929SIan Campbell * paravirt_ops is a kind of one. As it will only run in baremetal anyway, 15778cb929SIan Campbell * we just keep it from happening 16778cb929SIan Campbell */ 17778cb929SIan Campbell #undef CONFIG_PARAVIRT 18099e1377SIan Campbell #ifdef CONFIG_X86_32 19099e1377SIan Campbell #define _ASM_DESC_H_ 1 20099e1377SIan Campbell #endif 21099e1377SIan Campbell 22778cb929SIan Campbell #ifdef CONFIG_X86_64 23778cb929SIan Campbell #define _LINUX_STRING_H_ 1 24778cb929SIan Campbell #define __LINUX_BITMAP_H 1 25778cb929SIan Campbell #endif 26778cb929SIan Campbell 27778cb929SIan Campbell #include <linux/linkage.h> 28778cb929SIan Campbell #include <linux/screen_info.h> 29099e1377SIan Campbell #include <linux/elf.h> 30778cb929SIan Campbell #include <asm/io.h> 31778cb929SIan Campbell #include <asm/page.h> 32778cb929SIan Campbell #include <asm/boot.h> 33778cb929SIan Campbell 34778cb929SIan Campbell /* WARNING!! 35778cb929SIan Campbell * This code is compiled with -fPIC and it is relocated dynamically 36778cb929SIan Campbell * at run time, but no relocation processing is performed. 37778cb929SIan Campbell * This means that it is not safe to place pointers in static structures. 38778cb929SIan Campbell */ 39778cb929SIan Campbell 40778cb929SIan Campbell /* 41778cb929SIan Campbell * Getting to provable safe in place decompression is hard. 42778cb929SIan Campbell * Worst case behaviours need to be analyzed. 43778cb929SIan Campbell * Background information: 44778cb929SIan Campbell * 45778cb929SIan Campbell * The file layout is: 46778cb929SIan Campbell * magic[2] 47778cb929SIan Campbell * method[1] 48778cb929SIan Campbell * flags[1] 49778cb929SIan Campbell * timestamp[4] 50778cb929SIan Campbell * extraflags[1] 51778cb929SIan Campbell * os[1] 52778cb929SIan Campbell * compressed data blocks[N] 53778cb929SIan Campbell * crc[4] orig_len[4] 54778cb929SIan Campbell * 55778cb929SIan Campbell * resulting in 18 bytes of non compressed data overhead. 56778cb929SIan Campbell * 57778cb929SIan Campbell * Files divided into blocks 58778cb929SIan Campbell * 1 bit (last block flag) 59778cb929SIan Campbell * 2 bits (block type) 60778cb929SIan Campbell * 61778cb929SIan Campbell * 1 block occurs every 32K -1 bytes or when there 50% compression has been achieved. 62778cb929SIan Campbell * The smallest block type encoding is always used. 63778cb929SIan Campbell * 64778cb929SIan Campbell * stored: 65778cb929SIan Campbell * 32 bits length in bytes. 66778cb929SIan Campbell * 67778cb929SIan Campbell * fixed: 68778cb929SIan Campbell * magic fixed tree. 69778cb929SIan Campbell * symbols. 70778cb929SIan Campbell * 71778cb929SIan Campbell * dynamic: 72778cb929SIan Campbell * dynamic tree encoding. 73778cb929SIan Campbell * symbols. 74778cb929SIan Campbell * 75778cb929SIan Campbell * 76778cb929SIan Campbell * The buffer for decompression in place is the length of the 77778cb929SIan Campbell * uncompressed data, plus a small amount extra to keep the algorithm safe. 78778cb929SIan Campbell * The compressed data is placed at the end of the buffer. The output 79778cb929SIan Campbell * pointer is placed at the start of the buffer and the input pointer 80778cb929SIan Campbell * is placed where the compressed data starts. Problems will occur 81778cb929SIan Campbell * when the output pointer overruns the input pointer. 82778cb929SIan Campbell * 83778cb929SIan Campbell * The output pointer can only overrun the input pointer if the input 84778cb929SIan Campbell * pointer is moving faster than the output pointer. A condition only 85778cb929SIan Campbell * triggered by data whose compressed form is larger than the uncompressed 86778cb929SIan Campbell * form. 87778cb929SIan Campbell * 88778cb929SIan Campbell * The worst case at the block level is a growth of the compressed data 89778cb929SIan Campbell * of 5 bytes per 32767 bytes. 90778cb929SIan Campbell * 91778cb929SIan Campbell * The worst case internal to a compressed block is very hard to figure. 92778cb929SIan Campbell * The worst case can at least be boundined by having one bit that represents 93778cb929SIan Campbell * 32764 bytes and then all of the rest of the bytes representing the very 94778cb929SIan Campbell * very last byte. 95778cb929SIan Campbell * 96778cb929SIan Campbell * All of which is enough to compute an amount of extra data that is required 97778cb929SIan Campbell * to be safe. To avoid problems at the block level allocating 5 extra bytes 98778cb929SIan Campbell * per 32767 bytes of data is sufficient. To avoind problems internal to a block 99778cb929SIan Campbell * adding an extra 32767 bytes (the worst case uncompressed block size) is 100778cb929SIan Campbell * sufficient, to ensure that in the worst case the decompressed data for 101778cb929SIan Campbell * block will stop the byte before the compressed data for a block begins. 102778cb929SIan Campbell * To avoid problems with the compressed data's meta information an extra 18 103778cb929SIan Campbell * bytes are needed. Leading to the formula: 104778cb929SIan Campbell * 105778cb929SIan Campbell * extra_bytes = (uncompressed_size >> 12) + 32768 + 18 + decompressor_size. 106778cb929SIan Campbell * 107778cb929SIan Campbell * Adding 8 bytes per 32K is a bit excessive but much easier to calculate. 108778cb929SIan Campbell * Adding 32768 instead of 32767 just makes for round numbers. 109778cb929SIan Campbell * Adding the decompressor_size is necessary as it musht live after all 110778cb929SIan Campbell * of the data as well. Last I measured the decompressor is about 14K. 111778cb929SIan Campbell * 10K of actual data and 4K of bss. 112778cb929SIan Campbell * 113778cb929SIan Campbell */ 114778cb929SIan Campbell 115778cb929SIan Campbell /* 116778cb929SIan Campbell * gzip declarations 117778cb929SIan Campbell */ 118778cb929SIan Campbell 119778cb929SIan Campbell #define OF(args) args 120778cb929SIan Campbell #define STATIC static 121778cb929SIan Campbell 122778cb929SIan Campbell #undef memset 123778cb929SIan Campbell #undef memcpy 124778cb929SIan Campbell #define memzero(s, n) memset ((s), 0, (n)) 125778cb929SIan Campbell 126778cb929SIan Campbell typedef unsigned char uch; 127778cb929SIan Campbell typedef unsigned short ush; 128778cb929SIan Campbell typedef unsigned long ulg; 129778cb929SIan Campbell 130*fd77c7caSPaolo Ciarrocchi #define WSIZE 0x80000000 /* 131*fd77c7caSPaolo Ciarrocchi * Window size must be at least 32k, 132778cb929SIan Campbell * and a power of two 133778cb929SIan Campbell * We don't actually have a window just 134778cb929SIan Campbell * a huge output buffer so I report 135778cb929SIan Campbell * a 2G windows size, as that should 136778cb929SIan Campbell * always be larger than our output buffer. 137778cb929SIan Campbell */ 138778cb929SIan Campbell 139778cb929SIan Campbell static uch *inbuf; /* input buffer */ 140778cb929SIan Campbell static uch *window; /* Sliding window buffer, (and final output buffer) */ 141778cb929SIan Campbell 142778cb929SIan Campbell static unsigned insize; /* valid bytes in inbuf */ 143778cb929SIan Campbell static unsigned inptr; /* index of next byte to be processed in inbuf */ 144778cb929SIan Campbell static unsigned outcnt; /* bytes in output buffer */ 145778cb929SIan Campbell 146778cb929SIan Campbell /* gzip flag byte */ 147778cb929SIan Campbell #define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */ 148778cb929SIan Campbell #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */ 149778cb929SIan Campbell #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ 150778cb929SIan Campbell #define ORIG_NAME 0x08 /* bit 3 set: original file name present */ 151778cb929SIan Campbell #define COMMENT 0x10 /* bit 4 set: file comment present */ 152778cb929SIan Campbell #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */ 153778cb929SIan Campbell #define RESERVED 0xC0 /* bit 6,7: reserved */ 154778cb929SIan Campbell 155778cb929SIan Campbell #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf()) 156778cb929SIan Campbell 157778cb929SIan Campbell /* Diagnostic functions */ 158778cb929SIan Campbell #ifdef DEBUG 159778cb929SIan Campbell # define Assert(cond, msg) {if(!(cond)) error(msg); } 160778cb929SIan Campbell # define Trace(x) fprintf x 161778cb929SIan Campbell # define Tracev(x) {if (verbose) fprintf x ; } 162778cb929SIan Campbell # define Tracevv(x) {if (verbose > 1) fprintf x ; } 163778cb929SIan Campbell # define Tracec(c, x) {if (verbose && (c)) fprintf x ; } 164778cb929SIan Campbell # define Tracecv(c, x) {if (verbose > 1 && (c)) fprintf x ; } 165778cb929SIan Campbell #else 166778cb929SIan Campbell # define Assert(cond, msg) 167778cb929SIan Campbell # define Trace(x) 168778cb929SIan Campbell # define Tracev(x) 169778cb929SIan Campbell # define Tracevv(x) 170778cb929SIan Campbell # define Tracec(c, x) 171778cb929SIan Campbell # define Tracecv(c, x) 172778cb929SIan Campbell #endif 173778cb929SIan Campbell 174778cb929SIan Campbell static int fill_inbuf(void); 175778cb929SIan Campbell static void flush_window(void); 176778cb929SIan Campbell static void error(char *m); 177778cb929SIan Campbell static void gzip_mark(void **); 178778cb929SIan Campbell static void gzip_release(void **); 179778cb929SIan Campbell 180778cb929SIan Campbell /* 181778cb929SIan Campbell * This is set up by the setup-routine at boot-time 182778cb929SIan Campbell */ 183778cb929SIan Campbell static unsigned char *real_mode; /* Pointer to real-mode data */ 184778cb929SIan Campbell 185778cb929SIan Campbell #define RM_EXT_MEM_K (*(unsigned short *)(real_mode + 0x2)) 186778cb929SIan Campbell #ifndef STANDARD_MEMORY_BIOS_CALL 187778cb929SIan Campbell #define RM_ALT_MEM_K (*(unsigned long *)(real_mode + 0x1e0)) 188778cb929SIan Campbell #endif 189778cb929SIan Campbell #define RM_SCREEN_INFO (*(struct screen_info *)(real_mode+0)) 190778cb929SIan Campbell 191778cb929SIan Campbell extern unsigned char input_data[]; 192778cb929SIan Campbell extern int input_len; 193778cb929SIan Campbell 194*fd77c7caSPaolo Ciarrocchi static long bytes_out; 195778cb929SIan Campbell 196778cb929SIan Campbell static void *malloc(int size); 197778cb929SIan Campbell static void free(void *where); 198778cb929SIan Campbell 199778cb929SIan Campbell static void *memset(void *s, int c, unsigned n); 200778cb929SIan Campbell static void *memcpy(void *dest, const void *src, unsigned n); 201778cb929SIan Campbell 202778cb929SIan Campbell static void putstr(const char *); 203778cb929SIan Campbell 204778cb929SIan Campbell #ifdef CONFIG_X86_64 205778cb929SIan Campbell #define memptr long 206778cb929SIan Campbell #else 207778cb929SIan Campbell #define memptr unsigned 208778cb929SIan Campbell #endif 209778cb929SIan Campbell 210778cb929SIan Campbell static memptr free_mem_ptr; 211778cb929SIan Campbell static memptr free_mem_end_ptr; 212778cb929SIan Campbell 213778cb929SIan Campbell #ifdef CONFIG_X86_64 214778cb929SIan Campbell #define HEAP_SIZE 0x7000 215778cb929SIan Campbell #else 216778cb929SIan Campbell #define HEAP_SIZE 0x4000 217778cb929SIan Campbell #endif 218778cb929SIan Campbell 219778cb929SIan Campbell static char *vidmem = (char *)0xb8000; 220778cb929SIan Campbell static int vidport; 221778cb929SIan Campbell static int lines, cols; 222778cb929SIan Campbell 223778cb929SIan Campbell #ifdef CONFIG_X86_NUMAQ 224778cb929SIan Campbell void *xquad_portio; 225778cb929SIan Campbell #endif 226778cb929SIan Campbell 227778cb929SIan Campbell #include "../../../../lib/inflate.c" 228778cb929SIan Campbell 229778cb929SIan Campbell static void *malloc(int size) 230778cb929SIan Campbell { 231778cb929SIan Campbell void *p; 232778cb929SIan Campbell 233*fd77c7caSPaolo Ciarrocchi if (size < 0) 234*fd77c7caSPaolo Ciarrocchi error("Malloc error"); 235*fd77c7caSPaolo Ciarrocchi if (free_mem_ptr <= 0) 236*fd77c7caSPaolo Ciarrocchi error("Memory error"); 237778cb929SIan Campbell 238778cb929SIan Campbell free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */ 239778cb929SIan Campbell 240778cb929SIan Campbell p = (void *)free_mem_ptr; 241778cb929SIan Campbell free_mem_ptr += size; 242778cb929SIan Campbell 243778cb929SIan Campbell if (free_mem_ptr >= free_mem_end_ptr) 244778cb929SIan Campbell error("Out of memory"); 245778cb929SIan Campbell 246778cb929SIan Campbell return p; 247778cb929SIan Campbell } 248778cb929SIan Campbell 249778cb929SIan Campbell static void free(void *where) 250778cb929SIan Campbell { /* Don't care */ 251778cb929SIan Campbell } 252778cb929SIan Campbell 253778cb929SIan Campbell static void gzip_mark(void **ptr) 254778cb929SIan Campbell { 255778cb929SIan Campbell *ptr = (void *) free_mem_ptr; 256778cb929SIan Campbell } 257778cb929SIan Campbell 258778cb929SIan Campbell static void gzip_release(void **ptr) 259778cb929SIan Campbell { 260778cb929SIan Campbell free_mem_ptr = (memptr) *ptr; 261778cb929SIan Campbell } 262778cb929SIan Campbell 263778cb929SIan Campbell static void scroll(void) 264778cb929SIan Campbell { 265778cb929SIan Campbell int i; 266778cb929SIan Campbell 267778cb929SIan Campbell memcpy(vidmem, vidmem + cols * 2, (lines - 1) * cols * 2); 268778cb929SIan Campbell for (i = (lines - 1) * cols * 2; i < lines * cols * 2; i += 2) 269778cb929SIan Campbell vidmem[i] = ' '; 270778cb929SIan Campbell } 271778cb929SIan Campbell 272778cb929SIan Campbell static void putstr(const char *s) 273778cb929SIan Campbell { 274778cb929SIan Campbell int x, y, pos; 275778cb929SIan Campbell char c; 276778cb929SIan Campbell 277778cb929SIan Campbell #ifdef CONFIG_X86_32 278778cb929SIan Campbell if (RM_SCREEN_INFO.orig_video_mode == 0 && lines == 0 && cols == 0) 279778cb929SIan Campbell return; 280778cb929SIan Campbell #endif 281778cb929SIan Campbell 282778cb929SIan Campbell x = RM_SCREEN_INFO.orig_x; 283778cb929SIan Campbell y = RM_SCREEN_INFO.orig_y; 284778cb929SIan Campbell 285778cb929SIan Campbell while ((c = *s++) != '\0') { 286778cb929SIan Campbell if (c == '\n') { 287778cb929SIan Campbell x = 0; 288778cb929SIan Campbell if (++y >= lines) { 289778cb929SIan Campbell scroll(); 290778cb929SIan Campbell y--; 291778cb929SIan Campbell } 292778cb929SIan Campbell } else { 293778cb929SIan Campbell vidmem [(x + cols * y) * 2] = c; 294778cb929SIan Campbell if (++x >= cols) { 295778cb929SIan Campbell x = 0; 296778cb929SIan Campbell if (++y >= lines) { 297778cb929SIan Campbell scroll(); 298778cb929SIan Campbell y--; 299778cb929SIan Campbell } 300778cb929SIan Campbell } 301778cb929SIan Campbell } 302778cb929SIan Campbell } 303778cb929SIan Campbell 304778cb929SIan Campbell RM_SCREEN_INFO.orig_x = x; 305778cb929SIan Campbell RM_SCREEN_INFO.orig_y = y; 306778cb929SIan Campbell 307778cb929SIan Campbell pos = (x + cols * y) * 2; /* Update cursor position */ 308778cb929SIan Campbell outb(14, vidport); 309778cb929SIan Campbell outb(0xff & (pos >> 9), vidport+1); 310778cb929SIan Campbell outb(15, vidport); 311778cb929SIan Campbell outb(0xff & (pos >> 1), vidport+1); 312778cb929SIan Campbell } 313778cb929SIan Campbell 314778cb929SIan Campbell static void *memset(void *s, int c, unsigned n) 315778cb929SIan Campbell { 316778cb929SIan Campbell int i; 317778cb929SIan Campbell char *ss = s; 318778cb929SIan Campbell 319778cb929SIan Campbell for (i = 0; i < n; i++) ss[i] = c; 320778cb929SIan Campbell return s; 321778cb929SIan Campbell } 322778cb929SIan Campbell 323778cb929SIan Campbell static void *memcpy(void *dest, const void *src, unsigned n) 324778cb929SIan Campbell { 325778cb929SIan Campbell int i; 326778cb929SIan Campbell const char *s = src; 327778cb929SIan Campbell char *d = dest; 328778cb929SIan Campbell 329778cb929SIan Campbell for (i = 0; i < n; i++) d[i] = s[i]; 330778cb929SIan Campbell return dest; 331778cb929SIan Campbell } 332778cb929SIan Campbell 333778cb929SIan Campbell /* =========================================================================== 334778cb929SIan Campbell * Fill the input buffer. This is called only when the buffer is empty 335778cb929SIan Campbell * and at least one byte is really needed. 336778cb929SIan Campbell */ 337778cb929SIan Campbell static int fill_inbuf(void) 338778cb929SIan Campbell { 339778cb929SIan Campbell error("ran out of input data"); 340778cb929SIan Campbell return 0; 341778cb929SIan Campbell } 342778cb929SIan Campbell 343778cb929SIan Campbell /* =========================================================================== 344778cb929SIan Campbell * Write the output window window[0..outcnt-1] and update crc and bytes_out. 345778cb929SIan Campbell * (Used for the decompressed data only.) 346778cb929SIan Campbell */ 347778cb929SIan Campbell static void flush_window(void) 348778cb929SIan Campbell { 349778cb929SIan Campbell /* With my window equal to my output buffer 350778cb929SIan Campbell * I only need to compute the crc here. 351778cb929SIan Campbell */ 352778cb929SIan Campbell ulg c = crc; /* temporary variable */ 353778cb929SIan Campbell unsigned n; 354778cb929SIan Campbell uch *in, ch; 355778cb929SIan Campbell 356778cb929SIan Campbell in = window; 357778cb929SIan Campbell for (n = 0; n < outcnt; n++) { 358778cb929SIan Campbell ch = *in++; 359778cb929SIan Campbell c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8); 360778cb929SIan Campbell } 361778cb929SIan Campbell crc = c; 362778cb929SIan Campbell bytes_out += (ulg)outcnt; 363778cb929SIan Campbell outcnt = 0; 364778cb929SIan Campbell } 365778cb929SIan Campbell 366778cb929SIan Campbell static void error(char *x) 367778cb929SIan Campbell { 368778cb929SIan Campbell putstr("\n\n"); 369778cb929SIan Campbell putstr(x); 370778cb929SIan Campbell putstr("\n\n -- System halted"); 371778cb929SIan Campbell 372778cb929SIan Campbell while (1) 373778cb929SIan Campbell asm("hlt"); 374778cb929SIan Campbell } 375778cb929SIan Campbell 376099e1377SIan Campbell static void parse_elf(void *output) 377099e1377SIan Campbell { 378099e1377SIan Campbell #ifdef CONFIG_X86_64 379099e1377SIan Campbell Elf64_Ehdr ehdr; 380099e1377SIan Campbell Elf64_Phdr *phdrs, *phdr; 381099e1377SIan Campbell #else 382099e1377SIan Campbell Elf32_Ehdr ehdr; 383099e1377SIan Campbell Elf32_Phdr *phdrs, *phdr; 384099e1377SIan Campbell #endif 385099e1377SIan Campbell void *dest; 386099e1377SIan Campbell int i; 387099e1377SIan Campbell 388099e1377SIan Campbell memcpy(&ehdr, output, sizeof(ehdr)); 389099e1377SIan Campbell if (ehdr.e_ident[EI_MAG0] != ELFMAG0 || 390099e1377SIan Campbell ehdr.e_ident[EI_MAG1] != ELFMAG1 || 391099e1377SIan Campbell ehdr.e_ident[EI_MAG2] != ELFMAG2 || 392*fd77c7caSPaolo Ciarrocchi ehdr.e_ident[EI_MAG3] != ELFMAG3) { 393099e1377SIan Campbell error("Kernel is not a valid ELF file"); 394099e1377SIan Campbell return; 395099e1377SIan Campbell } 396099e1377SIan Campbell 397099e1377SIan Campbell putstr("Parsing ELF... "); 398099e1377SIan Campbell 399099e1377SIan Campbell phdrs = malloc(sizeof(*phdrs) * ehdr.e_phnum); 400099e1377SIan Campbell if (!phdrs) 401099e1377SIan Campbell error("Failed to allocate space for phdrs"); 402099e1377SIan Campbell 403099e1377SIan Campbell memcpy(phdrs, output + ehdr.e_phoff, sizeof(*phdrs) * ehdr.e_phnum); 404099e1377SIan Campbell 405099e1377SIan Campbell for (i = 0; i < ehdr.e_phnum; i++) { 406099e1377SIan Campbell phdr = &phdrs[i]; 407099e1377SIan Campbell 408099e1377SIan Campbell switch (phdr->p_type) { 409099e1377SIan Campbell case PT_LOAD: 410099e1377SIan Campbell #ifdef CONFIG_RELOCATABLE 411099e1377SIan Campbell dest = output; 412099e1377SIan Campbell dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR); 413099e1377SIan Campbell #else 414099e1377SIan Campbell dest = (void *)(phdr->p_paddr); 415099e1377SIan Campbell #endif 416099e1377SIan Campbell memcpy(dest, 417099e1377SIan Campbell output + phdr->p_offset, 418099e1377SIan Campbell phdr->p_filesz); 419099e1377SIan Campbell break; 420099e1377SIan Campbell default: /* Ignore other PT_* */ break; 421099e1377SIan Campbell } 422099e1377SIan Campbell } 423099e1377SIan Campbell } 424099e1377SIan Campbell 425778cb929SIan Campbell asmlinkage void decompress_kernel(void *rmode, memptr heap, 426778cb929SIan Campbell uch *input_data, unsigned long input_len, 427778cb929SIan Campbell uch *output) 428778cb929SIan Campbell { 429778cb929SIan Campbell real_mode = rmode; 430778cb929SIan Campbell 431778cb929SIan Campbell if (RM_SCREEN_INFO.orig_video_mode == 7) { 432778cb929SIan Campbell vidmem = (char *) 0xb0000; 433778cb929SIan Campbell vidport = 0x3b4; 434778cb929SIan Campbell } else { 435778cb929SIan Campbell vidmem = (char *) 0xb8000; 436778cb929SIan Campbell vidport = 0x3d4; 437778cb929SIan Campbell } 438778cb929SIan Campbell 439778cb929SIan Campbell lines = RM_SCREEN_INFO.orig_video_lines; 440778cb929SIan Campbell cols = RM_SCREEN_INFO.orig_video_cols; 441778cb929SIan Campbell 442778cb929SIan Campbell window = output; /* Output buffer (Normally at 1M) */ 443778cb929SIan Campbell free_mem_ptr = heap; /* Heap */ 444778cb929SIan Campbell free_mem_end_ptr = heap + HEAP_SIZE; 445778cb929SIan Campbell inbuf = input_data; /* Input buffer */ 446778cb929SIan Campbell insize = input_len; 447778cb929SIan Campbell inptr = 0; 448778cb929SIan Campbell 449778cb929SIan Campbell #ifdef CONFIG_X86_64 450778cb929SIan Campbell if ((ulg)output & (__KERNEL_ALIGN - 1)) 451778cb929SIan Campbell error("Destination address not 2M aligned"); 452778cb929SIan Campbell if ((ulg)output >= 0xffffffffffUL) 453778cb929SIan Campbell error("Destination address too large"); 454778cb929SIan Campbell #else 455778cb929SIan Campbell if ((u32)output & (CONFIG_PHYSICAL_ALIGN -1)) 456778cb929SIan Campbell error("Destination address not CONFIG_PHYSICAL_ALIGN aligned"); 457778cb929SIan Campbell if (heap > ((-__PAGE_OFFSET-(512<<20)-1) & 0x7fffffff)) 458778cb929SIan Campbell error("Destination address too large"); 459778cb929SIan Campbell #ifndef CONFIG_RELOCATABLE 460778cb929SIan Campbell if ((u32)output != LOAD_PHYSICAL_ADDR) 461778cb929SIan Campbell error("Wrong destination address"); 462778cb929SIan Campbell #endif 463778cb929SIan Campbell #endif 464778cb929SIan Campbell 465778cb929SIan Campbell makecrc(); 466778cb929SIan Campbell putstr("\nDecompressing Linux... "); 467778cb929SIan Campbell gunzip(); 468099e1377SIan Campbell parse_elf(output); 469778cb929SIan Campbell putstr("done.\nBooting the kernel.\n"); 470778cb929SIan Campbell return; 471778cb929SIan Campbell } 472