arch/powerpc/boot/decompress.c

Source file repositories/reference/linux-study-clean/arch/powerpc/boot/decompress.c

File Facts

System
Linux kernel
Corpus path
arch/powerpc/boot/decompress.c
Extension
.c
Size
3719 bytes
Lines
144
Domain
Architecture Layer
Bucket
arch/powerpc
Inferred role
Architecture Layer: implementation source
Status
source implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Wrapper around the kernel's pre-boot decompression library.
 *
 * Copyright (C) IBM Corporation 2016.
 */

#include "elf.h"
#include "page.h"
#include "string.h"
#include "stdio.h"
#include "ops.h"
#include "reg.h"
#include "types.h"

/*
 * The decompressor_*.c files play #ifdef games so they can be used in both
 * pre-boot and regular kernel code. We need these definitions to make the
 * includes work.
 */

#define STATIC static
#define INIT

/*
 * The build process will copy the required zlib source files and headers
 * out of lib/ and "fix" the includes so they do not pull in other kernel
 * headers.
 */

#ifdef CONFIG_KERNEL_GZIP
#	include "decompress_inflate.c"
#endif

#ifdef CONFIG_KERNEL_XZ
#	include "xz_config.h"
#	include "../../../lib/decompress_unxz.c"
#endif

/* globals for tracking the state of the decompression */
static unsigned long decompressed_bytes;
static unsigned long limit;
static unsigned long skip;
static char *output_buffer;

/*
 * flush() is called by __decompress() when the decompressor's scratch buffer is
 * full.
 */
static long flush(void *v, unsigned long buffer_size)
{
	unsigned long end = decompressed_bytes + buffer_size;
	unsigned long size = buffer_size;
	unsigned long offset = 0;
	char *in = v;
	char *out;

	/*
	 * if we hit our decompression limit, we need to fake an error to abort
	 * the in-progress decompression.
	 */
	if (decompressed_bytes >= limit)
		return -1;

	/* skip this entire block */
	if (end <= skip) {
		decompressed_bytes += buffer_size;
		return buffer_size;
	}

	/* skip some data at the start, but keep the rest of the block */
	if (decompressed_bytes < skip && end > skip) {
		offset = skip - decompressed_bytes;

		in += offset;
		size -= offset;
		decompressed_bytes += offset;
	}

	out = &output_buffer[decompressed_bytes - skip];
	size = min(decompressed_bytes + size, limit) - decompressed_bytes;

	memcpy(out, in, size);
	decompressed_bytes += size;

	return buffer_size;
}

static void print_err(char *s)
{

Annotation

Implementation Notes