Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * misc.c
0004  * 
0005  * This is a collection of several routines from gzip-1.0.3 
0006  * adapted for Linux.
0007  *
0008  * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
0009  *
0010  * Modified for ARM Linux by Russell King
0011  *
0012  * Nicolas Pitre <nico@visuaide.com>  1999/04/14 :
0013  *  For this code to run directly from Flash, all constant variables must
0014  *  be marked with 'const' and all other variables initialized at run-time 
0015  *  only.  This way all non constant variables will end up in the bss segment,
0016  *  which should point to addresses in RAM and cleared to 0 on start.
0017  *  This allows for a much quicker boot time.
0018  */
0019 
0020 unsigned int __machine_arch_type;
0021 
0022 #include <linux/compiler.h> /* for inline */
0023 #include <linux/types.h>
0024 #include <linux/linkage.h>
0025 #include "misc.h"
0026 #include "misc-ep93xx.h"
0027 
0028 static void putstr(const char *ptr);
0029 
0030 #include CONFIG_UNCOMPRESS_INCLUDE
0031 
0032 #ifdef CONFIG_DEBUG_ICEDCC
0033 
0034 #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V6K) || defined(CONFIG_CPU_V7)
0035 
0036 static void icedcc_putc(int ch)
0037 {
0038     int status, i = 0x4000000;
0039 
0040     do {
0041         if (--i < 0)
0042             return;
0043 
0044         asm volatile ("mrc p14, 0, %0, c0, c1, 0" : "=r" (status));
0045     } while (status & (1 << 29));
0046 
0047     asm("mcr p14, 0, %0, c0, c5, 0" : : "r" (ch));
0048 }
0049 
0050 
0051 #elif defined(CONFIG_CPU_XSCALE)
0052 
0053 static void icedcc_putc(int ch)
0054 {
0055     int status, i = 0x4000000;
0056 
0057     do {
0058         if (--i < 0)
0059             return;
0060 
0061         asm volatile ("mrc p14, 0, %0, c14, c0, 0" : "=r" (status));
0062     } while (status & (1 << 28));
0063 
0064     asm("mcr p14, 0, %0, c8, c0, 0" : : "r" (ch));
0065 }
0066 
0067 #else
0068 
0069 static void icedcc_putc(int ch)
0070 {
0071     int status, i = 0x4000000;
0072 
0073     do {
0074         if (--i < 0)
0075             return;
0076 
0077         asm volatile ("mrc p14, 0, %0, c0, c0, 0" : "=r" (status));
0078     } while (status & 2);
0079 
0080     asm("mcr p14, 0, %0, c1, c0, 0" : : "r" (ch));
0081 }
0082 
0083 #endif
0084 
0085 #define putc(ch)    icedcc_putc(ch)
0086 #endif
0087 
0088 static void putstr(const char *ptr)
0089 {
0090     char c;
0091 
0092     while ((c = *ptr++) != '\0') {
0093         if (c == '\n')
0094             putc('\r');
0095         putc(c);
0096     }
0097 
0098     flush();
0099 }
0100 
0101 /*
0102  * gzip declarations
0103  */
0104 extern char input_data[];
0105 extern char input_data_end[];
0106 
0107 unsigned char *output_data;
0108 
0109 unsigned long free_mem_ptr;
0110 unsigned long free_mem_end_ptr;
0111 
0112 #ifndef arch_error
0113 #define arch_error(x)
0114 #endif
0115 
0116 void error(char *x)
0117 {
0118     arch_error(x);
0119 
0120     putstr("\n\n");
0121     putstr(x);
0122     putstr("\n\n -- System halted");
0123 
0124     while(1);   /* Halt */
0125 }
0126 
0127 asmlinkage void __div0(void)
0128 {
0129     error("Attempting division by 0!");
0130 }
0131 
0132 extern int do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x));
0133 
0134 
0135 void
0136 decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
0137         unsigned long free_mem_ptr_end_p,
0138         int arch_id)
0139 {
0140     int ret;
0141 
0142     output_data     = (unsigned char *)output_start;
0143     free_mem_ptr        = free_mem_ptr_p;
0144     free_mem_end_ptr    = free_mem_ptr_end_p;
0145     __machine_arch_type = arch_id;
0146 
0147 #ifdef CONFIG_ARCH_EP93XX
0148     ep93xx_decomp_setup();
0149 #endif
0150     arch_decomp_setup();
0151 
0152     putstr("Uncompressing Linux...");
0153     ret = do_decompress(input_data, input_data_end - input_data,
0154                 output_data, error);
0155     if (ret)
0156         error("decompressor returned an error");
0157     else
0158         putstr(" done, booting the kernel.\n");
0159 }
0160 
0161 void fortify_panic(const char *name)
0162 {
0163     error("detected buffer overflow");
0164 }