Skip to contentSkip to conversation

unicore32: new file arch/unicore32/boot/compressed/misc.c

PATCH In review Guan Xuetao 2 participants 3 messages Dec 9, 2010 – Dec 13, 2010 2 messages not in the archive Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

PATCH 8/211 unicore32: new file arch/unicore32/boot/compressed/misc.c

From: Guan Xuetao <[email protected]>

decompress_kernel call wrapper in c function

---
 arch/unicore32/boot/compressed/misc.c |  143
+++++++++++++++++++++++++++++++++
 1 files changed, 143 insertions(+), 0 deletions(-)
(quoted diff) +0 -0

b/arch/unicore32/boot/compressed/misc.c
new file mode 100644
index 0000000..28dda37

arch/unicore32/boot/compressed/misc.c new file +50 -0

50 lines not on this page · raw message

fprintf x; }
+#else

+#  define Assert(cond, msg)
+#  define Trace(x)
+#  define Tracev(x)
+#  define Tracevv(x)
+#  define Tracec(c, x)
+#  define Tracecv(c, x)

+#endif
+
+void *memcpy(void *__dest, __const void *__src, size_t __n)
+{
+ int i = 0;
+ unsigned char *d = (unsigned char *)__dest, *s = (unsigned char
*)__src;
+
+ for (i = __n >> 3; i > 0; i--) {
+ *d++ = *s++;
+ *d++ = *s++;
+ *d++ = *s++;
+ *d++ = *s++;
+ *d++ = *s++;
+ *d++ = *s++;
+ *d++ = *s++;
+ *d++ = *s++;
+ }
+
+ if (__n & 1 << 2) {
+ *d++ = *s++;
+ *d++ = *s++;
+ *d++ = *s++;
+ *d++ = *s++;
+ }
+
+ if (__n & 1 << 1) {
+ *d++ = *s++;
+ *d++ = *s++;
+ }
+
+ if (__n & 1)
+ *d++ = *s++;
+
+ return __dest;
+}
+
+void error(char *x)
+{
+
+ arch_decomp_puts("\n\n");
+ arch_decomp_puts(x);
+ arch_decomp_puts("\n\n -- System halted");
+
+ arch_decomp_error(x);
+
+ do { } while (1); /* Halt */
+}
+
+/* Heap size should be adjusted for different decompress method */ +#ifdef CONFIG_KERNEL_GZIP
+#include "../../../../lib/decompress_inflate.c"
+#endif
+
+#ifdef CONFIG_KERNEL_BZIP2
+#include "../../../../lib/decompress_bunzip2.c"
+#endif
+
+#ifdef CONFIG_KERNEL_LZO
+#include "../../../../lib/decompress_unlzo.c"
+#endif
+
+#ifdef CONFIG_KERNEL_LZMA
+#include "../../../../lib/decompress_unlzma.c"
+#endif
+
+unsigned long
+decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
+ unsigned long free_mem_ptr_end_p)
+{
+ unsigned char *tmp;
+
+ output_data = (unsigned char *)output_start;
+ free_mem_ptr = free_mem_ptr_p;
+ free_mem_end_ptr = free_mem_ptr_end_p;
+
+ arch_decomp_setup();
+
+ tmp = (unsigned char *) (((unsigned long)input_data_end) - 4);
+ output_ptr = get_unaligned_le32(tmp);
+
+ arch_decomp_puts("Uncompressing Linux...");
+ decompress(input_data, input_data_end - input_data, NULL, NULL,
+ output_data, NULL, error);
+ arch_decomp_puts(" done, booting the kernel.\n");
+ return output_ptr;
+}

#1 lore raw

Hi, some trivial tips...

Quoted 43 lines · Guan Xuetao

From: Guan Xuetao <[email protected]>

       decompress_kernel call wrapper in c function

---
 arch/unicore32/boot/compressed/misc.c |  143
+++++++++++++++++++++++++++++++++

 1 files changed, 143 insertions(+), 0 deletions(-)
arch/unicore32/boot/compressed/misc.c new file +26 -0
new file mode 100644
index 0000000..28dda37
@@ -0,0 +1,143 @@
+/*
+ * linux/arch/unicore32/boot/compressed/misc.c
+ *
+ * Code specific to PKUnity SoC and UniCore ISA
+ *
+ * Copyright (C) 2001-2010 GUAN Xue-tao
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <asm/unaligned.h>
+#include <asm/mach/uncompress.h>
+
+/*
+ * gzip delarations
+ */
+unsigned char *output_data;
+unsigned long output_ptr;
+
+unsigned int free_mem_ptr;
+unsigned int free_mem_end_ptr;
+
+#define STATIC static
+#define STATIC_RW_DATA /* non-static please */

arch/unicore32/boot/compressed/misc.c line 36

Quoted 10 lines
arch/unicore32/boot/compressed/misc.c new file +10 -0
+
+/*
+ * arch-dependent implementations
+ */
+#ifndef ARCH_HAVE_DECOMP_ERROR
+#define arch_decomp_error(x)
+#endif
+
+#ifndef ARCH_HAVE_DECOMP_SETUP
+#define        arch_decomp_setup()

Whitespace

Quoted 14 lines
arch/unicore32/boot/compressed/misc.c new file +14 -0
+#endif
+
+#ifndef ARCH_HAVE_DECOMP_PUTS
+#define arch_decomp_puts(p)
+#endif
+
+/* Diagnostic functions */
+#ifdef DEBUG
+#  define Assert(cond, msg)    { if (!(cond)) error(msg); }
+#  define Trace(x)             fprintf x
+#  define Tracev(x)            { if (verbose)                  fprintf x; }
+#  define Tracevv(x)           { if (verbose > 1)              fprintf x; }
+#  define Tracec(c, x)         { if (verbose && (c))           fprintf x; }
+#  define Tracecv(c, x)                { if ((verbose > 1) && (c))
Quoted 1 line

fprintf x; }

Maybe uppercase? Maybe do { ... } while(0)?

arch/unicore32/boot/compressed/misc.c

Quoted 10 lines
arch/unicore32/boot/compressed/misc.c new file +10 -0
+#else
+#  define Assert(cond, msg)
+#  define Trace(x)
+#  define Tracev(x)
+#  define Tracevv(x)
+#  define Tracec(c, x)
+#  define Tracecv(c, x)
+#endif
+
+void *memcpy(void *__dest, __const void *__src, size_t __n)

Why are they underscored?

Quoted 27 lines

+{
+       int i = 0;
+       unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;

arch/unicore32/boot/compressed/misc.c new file +23 -0
+
+       for (i = __n >> 3; i > 0; i--) {
+               *d++ = *s++;
+               *d++ = *s++;
+               *d++ = *s++;
+               *d++ = *s++;
+               *d++ = *s++;
+               *d++ = *s++;
+               *d++ = *s++;
+               *d++ = *s++;
+       }
+
+       if (__n & 1 << 2) {
+               *d++ = *s++;
+               *d++ = *s++;
+               *d++ = *s++;
+               *d++ = *s++;
+       }
+
+       if (__n & 1 << 1) {
+               *d++ = *s++;
+               *d++ = *s++;
+       }

arch/unicore32/boot/compressed/misc.c

Quoted 10 lines
arch/unicore32/boot/compressed/misc.c new file +10 -0
+
+       if (__n & 1)
+               *d++ = *s++;
+
+       return __dest;
+}
+
+void error(char *x)
+{
+

Newline

arch/unicore32/boot/compressed/misc.c

Quoted 7 lines

+       arch_decomp_puts("\n\n");
+       arch_decomp_puts(x);
+       arch_decomp_puts("\n\n -- System halted");

arch/unicore32/boot/compressed/misc.c new file +4 -0
+
+       arch_decomp_error(x);
+
+       do { } while (1); /* Halt */

for (;;);?

Quoted 10 lines
arch/unicore32/boot/compressed/misc.c new file +10 -0
+}
+
+/* Heap size should be adjusted for different decompress method */
+#ifdef CONFIG_KERNEL_GZIP
+#include "../../../../lib/decompress_inflate.c"
+#endif
+
+#ifdef CONFIG_KERNEL_BZIP2
+#include "../../../../lib/decompress_bunzip2.c"
+#endif

arch/unicore32/boot/compressed/misc.c

Quoted 10 lines
arch/unicore32/boot/compressed/misc.c new file +10 -0
+
+#ifdef CONFIG_KERNEL_LZO
+#include "../../../../lib/decompress_unlzo.c"
+#endif
+
+#ifdef CONFIG_KERNEL_LZMA
+#include "../../../../lib/decompress_unlzma.c"
+#endif
+
+unsigned long

I think that, for new code, no newlines should be written after the return type.

Quoted 27 lines
arch/unicore32/boot/compressed/misc.c new file +20 -1
+decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
+               unsigned long free_mem_ptr_end_p)
+{
+       unsigned char *tmp;
+
+       output_data             = (unsigned char *)output_start;
+       free_mem_ptr            = free_mem_ptr_p;
+       free_mem_end_ptr        = free_mem_ptr_end_p;
+
+       arch_decomp_setup();
+
+       tmp = (unsigned char *) (((unsigned long)input_data_end) - 4);
+       output_ptr = get_unaligned_le32(tmp);
+
+       arch_decomp_puts("Uncompressing Linux...");
+       decompress(input_data, input_data_end - input_data, NULL, NULL,
+                       output_data, NULL, error);
+       arch_decomp_puts(" done, booting the kernel.\n");
+       return output_ptr;
+}
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 19 lines
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
arch/unicore32/boot/compressed/misc.c new file +8 -0
+/* Diagnostic functions */
+#ifdef DEBUG
+#  define Assert(cond, msg)    { if (!(cond)) error(msg); }
+#  define Trace(x)             fprintf x
+#  define Tracev(x)            { if (verbose)                  fprintf x; }
+#  define Tracevv(x)           { if (verbose > 1)              fprintf x; }
+#  define Tracec(c, x)         { if (verbose && (c))           fprintf x; }
+#  define Tracecv(c, x)                { if ((verbose > 1) && (c))

fprintf x; }

Maybe uppercase? Maybe do { ... } while(0)?

Quoted 1 line

Uppercase for what? Tracexx to tracexx?

We normally don't have mixed-case identifiers, normally it would be trace() for functions vs. TRACE() for macros, though we also have a lot of lower-case macros as well.

Quoted 8 lines

For the debugging macros, I would generally recommend not having any, but simply using the standard pr_debug and dev_dbg macros that everyone knows and understands.

If you really need to do macros, make them so that they work like functions, e.g.

#define foo_tracev(...) do { if (verbose) fprintf(__va_args__); } while (0)

When reviewing misc.c, I find that Tracevv and Tracecv are not used in lib/decompress_inflate.c So these macros could be removed directly.
The same for other architectures, I think.

Guan Xuetao