[PATCH -v3] x86: Setup early console as early as possible

Previous thread: kjournald and flush being blocked for 120 sec by Dieter Ries on Monday, August 2, 2010 - 12:02 am. (2 messages)

Next thread: [PATCH v2 0/3] MAX8998 changes for RTC by Joonyoung Shim on Monday, August 2, 2010 - 12:34 am. (1 message)
From: Yinghai Lu
Date: Monday, August 2, 2010 - 12:13 am

Seperate early_console_setup from tty.c
also make main.c to include printf.c/string.c/cmdline.c

will reuse early_serial_console.c/string.c/printf.c/cmdline.c in compressed/misc.c

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 arch/x86/boot/Makefile               |    4 
 arch/x86/boot/boot.h                 |   16 ---
 arch/x86/boot/cmdline.c              |    8 -
 arch/x86/boot/early_serial_console.c |  139 ++++++++++++++++++++++++++++++++++
 arch/x86/boot/main.c                 |   14 +++
 arch/x86/boot/printf.c               |    6 -
 arch/x86/boot/string.c               |   16 +++
 arch/x86/boot/tty.c                  |  141 -----------------------------------
 8 files changed, 175 insertions(+), 169 deletions(-)

Index: linux-2.6/arch/x86/boot/tty.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/tty.c
+++ linux-2.6/arch/x86/boot/tty.c
@@ -15,27 +15,7 @@
 
 #include "boot.h"
 
-#define DEFAULT_SERIAL_PORT 0x3f8 /* ttyS0 */
-
-static int	early_serial_base;
-
-#define XMTRDY          0x20
-
-#define DLAB		0x80
-
-#define TXR             0       /*  Transmit register (WRITE) */
-#define RXR             0       /*  Receive register  (READ)  */
-#define IER             1       /*  Interrupt Enable          */
-#define IIR             2       /*  Interrupt ID              */
-#define FCR             2       /*  FIFO control              */
-#define LCR             3       /*  Line control              */
-#define MCR             4       /*  Modem control             */
-#define LSR             5       /*  Line Status               */
-#define MSR             6       /*  Modem Status              */
-#define DLL             0       /*  Divisor Latch Low         */
-#define DLH             1       /*  Divisor latch High        */
-
-#define DEFAULT_BAUD 9600
+#include "early_serial_console.c"
 
 /*
  * These functions are in .inittext so they can be used to signal
@@ -152,122 +132,3 @@ int ...
From: Yinghai Lu
Date: Monday, August 2, 2010 - 12:14 am

will get

|Decompressing Linux... Parsing ELF... done.
|Booting the kernel.

in serial console.

reuse code from arch/x86/boot/
and we can use printf if needed

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 arch/x86/boot/compressed/misc.c |   60 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 59 insertions(+), 1 deletion(-)

Index: linux-2.6/arch/x86/boot/compressed/misc.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.c
+++ linux-2.6/arch/x86/boot/compressed/misc.c
@@ -125,12 +125,14 @@ static void error(char *m);
  */
 static struct boot_params *real_mode;		/* Pointer to real-mode data */
 static int quiet;
+static int debug;
 
 void *memset(void *s, int c, size_t n);
 void *memcpy(void *dest, const void *src, size_t n);
 
 static void __putstr(int, const char *);
 #define putstr(__x)  __putstr(0, __x)
+#define puts(__x)  __putstr(0, __x)
 
 #ifdef CONFIG_X86_64
 #define memptr long
@@ -145,6 +147,9 @@ static char *vidmem;
 static int vidport;
 static int lines, cols;
 
+#include "../string.c"
+#include "../printf.c"
+
 #ifdef CONFIG_KERNEL_GZIP
 #include "../../../../lib/decompress_inflate.c"
 #endif
@@ -161,6 +166,27 @@ static int lines, cols;
 #include "../../../../lib/decompress_unlzo.c"
 #endif
 
+static unsigned long fs;
+static inline void set_fs(unsigned long seg)
+{
+	fs = seg << 4;  /* shift it back */
+}
+typedef unsigned long addr_t;
+static inline char rdfs8(addr_t addr)
+{
+	return *((char *)(fs + addr));
+}
+#include "../cmdline.c"
+int cmdline_find_option(const char *option, char *buffer, int bufsize)
+{
+	return __cmdline_find_option(real_mode->hdr.cmd_line_ptr, option, buffer, bufsize);
+}
+int cmdline_find_option_bool(const char *option)
+{
+	return __cmdline_find_option_bool(real_mode->hdr.cmd_line_ptr, option);
+}
+#include "../early_serial_console.c"
+
 static void scroll(void)
 {
 	int i;
@@ -170,6 +196,16 @@ static void ...
From: H. Peter Anvin
Date: Monday, August 2, 2010 - 12:16 am

No.  We don't include .c files that way.

	-hpa

-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.

--

From: Yinghai Lu
Date: Monday, August 2, 2010 - 1:24 am

Seperate early_serial_console from tty.c

will reuse early_serial_console.c/string.c/printf.c/cmdline.c in compressed/misc.c

-v2: according to hpa, don't include string.c etc.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 arch/x86/boot/Makefile               |    8 -
 arch/x86/boot/boot.h                 |   35 ++++----
 arch/x86/boot/cmdline.c              |    6 -
 arch/x86/boot/early_serial_console.c |  141 +++++++++++++++++++++++++++++++++++
 arch/x86/boot/isdigit.h              |   21 +++++
 arch/x86/boot/printf.c               |    4 
 arch/x86/boot/tty.c                  |  136 ---------------------------------
 7 files changed, 187 insertions(+), 164 deletions(-)

Index: linux-2.6/arch/x86/boot/tty.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/tty.c
+++ linux-2.6/arch/x86/boot/tty.c
@@ -15,27 +15,10 @@
 
 #include "boot.h"
 
-#define DEFAULT_SERIAL_PORT 0x3f8 /* ttyS0 */
-
-static int	early_serial_base;
-
 #define XMTRDY          0x20
 
-#define DLAB		0x80
-
 #define TXR             0       /*  Transmit register (WRITE) */
-#define RXR             0       /*  Receive register  (READ)  */
-#define IER             1       /*  Interrupt Enable          */
-#define IIR             2       /*  Interrupt ID              */
-#define FCR             2       /*  FIFO control              */
-#define LCR             3       /*  Line control              */
-#define MCR             4       /*  Modem control             */
 #define LSR             5       /*  Line Status               */
-#define MSR             6       /*  Modem Status              */
-#define DLL             0       /*  Divisor Latch Low         */
-#define DLH             1       /*  Divisor latch High        */
-
-#define DEFAULT_BAUD 9600
 
 /*
  * These functions are in .inittext so they can be used to signal
@@ -152,122 +135,3 @@ int getchar_timeout(void)
 	return 0;		/* Timeout! */
 }
 
-static void ...
From: Yinghai Lu
Date: Monday, August 2, 2010 - 1:26 am

will get

|Decompressing Linux... Parsing ELF... done.
|Booting the kernel.

in serial console.

reuse code from arch/x86/boot/
and we can use printf if needed

-v2: define BOOT_BOOT_H to avoid include boot.h

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 arch/x86/boot/compressed/misc.c |   62 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)

Index: linux-2.6/arch/x86/boot/compressed/misc.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.c
+++ linux-2.6/arch/x86/boot/compressed/misc.c
@@ -125,12 +125,14 @@ static void error(char *m);
  */
 static struct boot_params *real_mode;		/* Pointer to real-mode data */
 static int quiet;
+static int debug;
 
 void *memset(void *s, int c, size_t n);
 void *memcpy(void *dest, const void *src, size_t n);
 
 static void __putstr(int, const char *);
 #define putstr(__x)  __putstr(0, __x)
+#define puts(__x)  __putstr(0, __x)
 
 #ifdef CONFIG_X86_64
 #define memptr long
@@ -145,6 +147,11 @@ static char *vidmem;
 static int vidport;
 static int lines, cols;
 
+#define BOOT_BOOT_H
+#include "../isdigit.h"
+#include "../string.c"
+#include "../printf.c"
+
 #ifdef CONFIG_KERNEL_GZIP
 #include "../../../../lib/decompress_inflate.c"
 #endif
@@ -161,6 +168,27 @@ static int lines, cols;
 #include "../../../../lib/decompress_unlzo.c"
 #endif
 
+static unsigned long fs;
+static inline void set_fs(unsigned long seg)
+{
+	fs = seg << 4;  /* shift it back */
+}
+typedef unsigned long addr_t;
+static inline char rdfs8(addr_t addr)
+{
+	return *((char *)(fs + addr));
+}
+#include "../cmdline.c"
+int cmdline_find_option(const char *option, char *buffer, int bufsize)
+{
+	return __cmdline_find_option(real_mode->hdr.cmd_line_ptr, option, buffer, bufsize);
+}
+int cmdline_find_option_bool(const char *option)
+{
+	return __cmdline_find_option_bool(real_mode->hdr.cmd_line_ptr, option);
+}
+#include ...
From: Yinghai Lu
Date: Monday, August 2, 2010 - 2:17 am

Seperate early_serial_console from tty.c

will reuse early_serial_console.c/string.c/printf.c/cmdline.c in compressed/misc.c

-v2: according to hpa, don't include string.c etc
-v3: compressed/misc.c must have early_serial_base as static, so move it back to tty.c
     for setup code

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 arch/x86/boot/Makefile               |    8 +-
 arch/x86/boot/boot.h                 |   35 ++++----
 arch/x86/boot/cmdline.c              |    6 -
 arch/x86/boot/early_serial_console.c |  139 +++++++++++++++++++++++++++++++++++
 arch/x86/boot/isdigit.h              |   21 +++++
 arch/x86/boot/printf.c               |    4 -
 arch/x86/boot/tty.c                  |  136 ----------------------------------
 7 files changed, 186 insertions(+), 163 deletions(-)

Index: linux-2.6/arch/x86/boot/tty.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/tty.c
+++ linux-2.6/arch/x86/boot/tty.c
@@ -15,27 +15,12 @@
 
 #include "boot.h"
 
-#define DEFAULT_SERIAL_PORT 0x3f8 /* ttyS0 */
-
-static int	early_serial_base;
+int early_serial_base;
 
 #define XMTRDY          0x20
 
-#define DLAB		0x80
-
 #define TXR             0       /*  Transmit register (WRITE) */
-#define RXR             0       /*  Receive register  (READ)  */
-#define IER             1       /*  Interrupt Enable          */
-#define IIR             2       /*  Interrupt ID              */
-#define FCR             2       /*  FIFO control              */
-#define LCR             3       /*  Line control              */
-#define MCR             4       /*  Modem control             */
 #define LSR             5       /*  Line Status               */
-#define MSR             6       /*  Modem Status              */
-#define DLL             0       /*  Divisor Latch Low         */
-#define DLH             1       /*  Divisor latch High        */
-
-#define DEFAULT_BAUD 9600
 
 /*
  * These functions are in .inittext so they ...
From: Yinghai Lu
Date: Monday, August 2, 2010 - 2:18 am

will get

|Decompressing Linux... Parsing ELF... done.
|Booting the kernel.

in serial console.

reuse code from arch/x86/boot/
and we can use printf if needed

-v2: define BOOT_BOOT_H to avoid include boot.h
-v3: early_serial_base need to be static in misc.c ?

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 arch/x86/boot/compressed/misc.c |   65 +++++++++++++++++++++++++++++++++++++++-
 arch/x86/boot/main.c            |    6 +--
 2 files changed, 66 insertions(+), 5 deletions(-)

Index: linux-2.6/arch/x86/boot/compressed/misc.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.c
+++ linux-2.6/arch/x86/boot/compressed/misc.c
@@ -125,12 +125,14 @@ static void error(char *m);
  */
 static struct boot_params *real_mode;		/* Pointer to real-mode data */
 static int quiet;
+static int debug;
 
 void *memset(void *s, int c, size_t n);
 void *memcpy(void *dest, const void *src, size_t n);
 
 static void __putstr(int, const char *);
 #define putstr(__x)  __putstr(0, __x)
+#define puts(__x)  __putstr(0, __x)
 
 #ifdef CONFIG_X86_64
 #define memptr long
@@ -145,6 +147,11 @@ static char *vidmem;
 static int vidport;
 static int lines, cols;
 
+#define BOOT_BOOT_H
+#include "../isdigit.h"
+#include "../string.c"
+#include "../printf.c"
+
 #ifdef CONFIG_KERNEL_GZIP
 #include "../../../../lib/decompress_inflate.c"
 #endif
@@ -161,6 +168,28 @@ static int lines, cols;
 #include "../../../../lib/decompress_unlzo.c"
 #endif
 
+static unsigned long fs;
+static inline void set_fs(unsigned long seg)
+{
+	fs = seg << 4;  /* shift it back */
+}
+typedef unsigned long addr_t;
+static inline char rdfs8(addr_t addr)
+{
+	return *((char *)(fs + addr));
+}
+#include "../cmdline.c"
+static inline int cmdline_find_option(const char *option, char *buffer, int bufsize)
+{
+	return __cmdline_find_option(real_mode->hdr.cmd_line_ptr, option, buffer, bufsize);
+}
+static inline int ...
From: Cyrill Gorcunov
Date: Monday, August 2, 2010 - 10:49 am

It seems eventually we just add ~80 lines of code in compare with what we had before,
just to print "Decompressing..." by serial line. Not sure Yinghai if it worth
it. Though having printf that early might be quite useful for those who debugging
or developing new compressors/decompressors. If it would be small non-intrusive
patch I would both hands for it but now I simply don't know (to be fair mine
proposal based on your initial patch not better either ;)

	-- Cyrill
--

From: H. Peter Anvin
Date: Monday, August 2, 2010 - 11:38 am

Decompressing... is one thing, and if it was only that, I'd just suggest
killing off the console I/O in boot/compressed.  Getting an error
message out when there is a decompression failure is another thing.

Processing the command line a novo is somewhat painful, but it does deal
better with bootloaders that use the 32-bit entry point by necessity
(kexec, EFI) or due to sheer stupidity (Grub2).

As such, I think it's a worthwhile addition, as long as the source code
can be cleanly shared with the boot/ directory.

	-hpa

--

From: Cyrill Gorcunov
Date: Monday, August 2, 2010 - 11:54 am

ok, fair enough, I just don't like nesting *.c inclusion you know but seems
it would be the only more-less clean way here.

	-- Cyrill
--

From: H. Peter Anvin
Date: Monday, August 2, 2010 - 11:58 am

I don't mind it *as long as* the including file contains nothing but a
single #include statement -- which is just another way to say "the same
thing as this other file".  Don't combine files.

Look at most of the .c files in arch/x86/kernel/acpi/realmode/ for an
example.

	-hpa

--

From: Yinghai Lu
Date: Monday, August 2, 2010 - 12:35 pm

it seems I can not global variables in arch/x86/boot/compressed/misc.c

and misc.c already include some decompress .c like

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

#ifdef CONFIG_KERNEL_BZIP2
#include "../../../../lib/decompress_bunzip2.c"
#endif

#ifdef CONFIG_KERNEL_LZMA
#include "../../../../lib/decompress_unlzma.c"
#endif

#ifdef CONFIG_KERNEL_LZO
#include "../../../../lib/decompress_unlzo.c"
#endif


this patch change to misc.c are following lines:

#define BOOT_BOOT_H
#include "../isdigit.h"
#include "../string.c"
#include "../printf.c"

...

static unsigned long fs;
static inline void set_fs(unsigned long seg)
{
        fs = seg << 4;  /* shift it back */
}
typedef unsigned long addr_t;
static inline char rdfs8(addr_t addr)
{
        return *((char *)(fs + addr));
}
#include "../cmdline.c"
static inline int cmdline_find_option(const char *option, char *buffer, int bufsize)
{
        return __cmdline_find_option(real_mode->hdr.cmd_line_ptr, option, buffer, bufsize);
}
static inline int cmdline_find_option_bool(const char *option)
{
        return __cmdline_find_option_bool(real_mode->hdr.cmd_line_ptr, option);
}
static int early_serial_base;
#include "../early_serial_console.c"

or put them in another file?

Thanks

Yinghai

Yinghai
--

From: H. Peter Anvin
Date: Monday, August 2, 2010 - 1:38 pm

Well, that should be fixed, then.  If we can't use the linker for what

Yes, I know; that's crap in a lot of ways too... the whole decompression
stuff is its own issue which is slowly being addressed.  It's not an

Hmf... games with set_fs() aren't a whole lot of fun at all.  I think it
would be better to define some wrappers specific to cmdline.c which
allow it to be using a real pointer in 32-bit mode.

I'll see if I can muck with it, it shouldn't take long.

	-hpa


--

From: H. Peter Anvin
Date: Monday, August 2, 2010 - 1:59 pm

I just looked at it, it's the fact that we don't relocate the GOT that
is causing problems.  It's relatively easy to fix: here is a patch, but
in grand Linus tradition it is completely untested.

	-hpa
From: H. Peter Anvin
Date: Monday, August 2, 2010 - 2:08 pm

Untested indeed... here is one which doesn't clobber live registers.

	-hpa

From: Yinghai Lu
Date: Monday, August 2, 2010 - 2:22 pm

still doesn't work.

with global early_serial_base got :

early console in setup code
[    0.000000] bootconsole [uart0] enabled


with static early_serial_base got :

early console in setup code
early console in decompress_kernel
decompress_kernel:
  input: [0x24a0269-0x2e8b234], output: 0x1000000, heap: [0x2e909c0-0x2e979bf]

Decompressing Linux... Parsing ELF... done.
Booting the kernel.
[    0.000000] bootconsole [uart0] enabled


Thanks

Yinghai
--

From: H. Peter Anvin
Date: Monday, August 2, 2010 - 2:27 pm

And of course I got the test backwards... in AT&T syntax, number
compares you!

	-hpa



From: Yinghai Lu
Date: Monday, August 2, 2010 - 2:36 pm

great, this one works.

will have updated

 [PATCH -v4 2/2] x86: more early console output from compressed/misc.c

Thanks

Yinghai
--

From: Yinghai Lu
Date: Monday, August 2, 2010 - 3:30 pm

updated version

Subject: [PATCH -v4 2/2] x86: more early console output from compressed/misc.c

will get

|Decompressing Linux... Parsing ELF... done.
|Booting the kernel.

in serial console.

reuse code from arch/x86/boot/
and we can use printf if needed

-v2: define BOOT_BOOT_H to avoid include boot.h
-v3: early_serial_base need to be static in misc.c ?
-v4: create seperate string.c printf.c cmdline.c early_serial_console.c
     after hpa's patch that allow global variables in compressed/misc stage

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 arch/x86/boot/compressed/Makefile               |    4 -
 arch/x86/boot/compressed/cmdline.c              |   21 +++++++
 arch/x86/boot/compressed/early_serial_console.c |    4 +
 arch/x86/boot/compressed/misc.c                 |   66 +++++++++++++++---------
 arch/x86/boot/compressed/misc.h                 |   38 +++++++++++++
 arch/x86/boot/compressed/printf.c               |    4 +
 arch/x86/boot/compressed/string.c               |    4 +
 arch/x86/boot/main.c                            |    6 --
 8 files changed, 118 insertions(+), 29 deletions(-)

Index: linux-2.6/arch/x86/boot/compressed/misc.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.c
+++ linux-2.6/arch/x86/boot/compressed/misc.c
@@ -9,23 +9,7 @@
  * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
  */
 
-/*
- * we have to be careful, because no indirections are allowed here, and
- * paravirt_ops is a kind of one. As it will only run in baremetal anyway,
- * we just keep it from happening
- */
-#undef CONFIG_PARAVIRT
-#ifdef CONFIG_X86_32
-#define _ASM_X86_DESC_H 1
-#endif
-
-#include <linux/linkage.h>
-#include <linux/screen_info.h>
-#include <linux/elf.h>
-#include <linux/io.h>
-#include <asm/page.h>
-#include <asm/boot.h>
-#include <asm/bootparam.h>
+#include "misc.h"
 
 /* WARNING!!
  * This code is compiled with -fPIC and it is relocated ...
From: H. Peter Anvin
Date: Monday, August 2, 2010 - 3:46 pm

First, I'm not quite sure which 1/2 patch you're expecting this to be
compiled against.


This seems to be the only user of printf() in the code.  As such, I
really suspect it's not worth pulling in all of printf().  I'd be
willing to be convinced, but if so I need (a) a concrete usage case, and
(b) it should be a separate patch.

	-hpa
--

From: Yinghai Lu
Date: Monday, August 2, 2010 - 3:51 pm

ok, will drop printf.

Yinghai
--

From: Yinghai Lu
Date: Monday, August 2, 2010 - 4:21 pm

please check..

Subject: [PATCH -v5 2/2] x86: more early console output from compressed/misc.c

will get

|Decompressing Linux... Parsing ELF... done.
|Booting the kernel.

in serial console.

reuse code from arch/x86/boot/
and we can use printf if needed

-v2: define BOOT_BOOT_H to avoid include boot.h
-v3: early_serial_base need to be static in misc.c ?
-v4: create seperate string.c printf.c cmdline.c early_serial_console.c
     after hpa's patch that allow global variables in compressed/misc stage
-v5: remove printf.c related

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 arch/x86/boot/compressed/Makefile               |    4 -
 arch/x86/boot/compressed/cmdline.c              |   21 +++++++++
 arch/x86/boot/compressed/early_serial_console.c |    5 ++
 arch/x86/boot/compressed/misc.c                 |   56 ++++++++++++++----------
 arch/x86/boot/compressed/misc.h                 |   38 ++++++++++++++++
 arch/x86/boot/compressed/string.c               |    4 +
 arch/x86/boot/main.c                            |    6 --
 7 files changed, 105 insertions(+), 29 deletions(-)

Index: linux-2.6/arch/x86/boot/compressed/misc.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.c
+++ linux-2.6/arch/x86/boot/compressed/misc.c
@@ -9,23 +9,7 @@
  * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
  */
 
-/*
- * we have to be careful, because no indirections are allowed here, and
- * paravirt_ops is a kind of one. As it will only run in baremetal anyway,
- * we just keep it from happening
- */
-#undef CONFIG_PARAVIRT
-#ifdef CONFIG_X86_32
-#define _ASM_X86_DESC_H 1
-#endif
-
-#include <linux/linkage.h>
-#include <linux/screen_info.h>
-#include <linux/elf.h>
-#include <linux/io.h>
-#include <asm/page.h>
-#include <asm/boot.h>
-#include <asm/bootparam.h>
+#include "misc.h"
 
 /* WARNING!!
  * This code is compiled with -fPIC and it is relocated dynamically
@@ -123,15 ...
From: tip-bot for H. Peter Anvin
Date: Monday, August 2, 2010 - 9:10 pm

Commit-ID:  6238b47b58480cd9c092600c05338dbe261b71ce
Gitweb:     http://git.kernel.org/tip/6238b47b58480cd9c092600c05338dbe261b71ce
Author:     H. Peter Anvin <hpa@zytor.com>
AuthorDate: Mon, 2 Aug 2010 21:03:46 -0700
Committer:  H. Peter Anvin <hpa@zytor.com>
CommitDate: Mon, 2 Aug 2010 21:07:20 -0700

x86, setup: move isdigit.h to ctype.h, header files on top.

It is a subset of <ctype.h> functionality, so name it ctype.h.  Also,
reorganize header files so #include statements are clustered near the
top as they should be.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
LKML-Reference: <4C5752F2.8030206@kernel.org>
---
 arch/x86/boot/boot.h                 |    3 +--
 arch/x86/boot/compressed/misc.h      |    1 +
 arch/x86/boot/compressed/string.c    |    2 --
 arch/x86/boot/{isdigit.h => ctype.h} |    0
 4 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
index 00cf51c..c7093bd 100644
--- a/arch/x86/boot/boot.h
+++ b/arch/x86/boot/boot.h
@@ -28,6 +28,7 @@
 #include "bitops.h"
 #include <asm/cpufeature.h>
 #include <asm/processor-flags.h>
+#include "ctype.h"
 
 /* Useful macros */
 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
@@ -200,8 +201,6 @@ static inline int memcmp_gs(const void *s1, addr_t s2, size_t len)
 	return diff;
 }
 
-#include "isdigit.h"
-
 /* Heap -- available for dynamic lists. */
 extern char _end[];
 extern char *HEAP;
diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
index a267849..3f19c81 100644
--- a/arch/x86/boot/compressed/misc.h
+++ b/arch/x86/boot/compressed/misc.h
@@ -20,6 +20,7 @@
 #include <asm/bootparam.h>
 
 #define BOOT_BOOT_H
+#include "../ctype.h"
 
 /* misc.c */
 extern struct boot_params *real_mode;		/* Pointer to real-mode data */
diff --git a/arch/x86/boot/compressed/string.c b/arch/x86/boot/compressed/string.c
index 7995c6a..19b3e69 100644
--- a/arch/x86/boot/compressed/string.c
+++ ...
From: tip-bot for H. Peter Anvin
Date: Monday, August 2, 2010 - 8:30 pm

Commit-ID:  22a57f5896df218356bae6203dfaf04bcfd6c88c
Gitweb:     http://git.kernel.org/tip/22a57f5896df218356bae6203dfaf04bcfd6c88c
Author:     H. Peter Anvin <hpa@linux.intel.com>
AuthorDate: Mon, 2 Aug 2010 15:34:44 -0700
Committer:  H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Mon, 2 Aug 2010 15:34:44 -0700

x86, setup: Allow global variables and functions in the decompressor

In order for global variables and functions to work in the
decompressor, we need to fix up the GOT in assembly code.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
LKML-Reference: <4C57382E.8050501@zytor.com>
---
 arch/x86/boot/compressed/head_32.S     |   13 +++++++++++++
 arch/x86/boot/compressed/head_64.S     |   13 +++++++++++++
 arch/x86/boot/compressed/vmlinux.lds.S |    6 ++++++
 3 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
index f543b70..67a655a 100644
--- a/arch/x86/boot/compressed/head_32.S
+++ b/arch/x86/boot/compressed/head_32.S
@@ -124,6 +124,19 @@ relocated:
 	rep	stosl
 
 /*
+ * Adjust our own GOT
+ */
+	leal	_got(%ebx), %edx
+	leal	_egot(%ebx), %ecx
+1:
+	cmpl	%ecx, %edx
+	jae	2f
+	addl	%ebx, (%edx)
+	addl	$4, %edx
+	jmp	1b
+2:
+
+/*
  * Do the decompression, and jump to the new kernel..
  */
 	leal	z_extract_offset_negative(%ebx), %ebp
diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index faff0dc..52f85a1 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -280,6 +280,19 @@ relocated:
 	rep	stosq
 
 /*
+ * Adjust our own GOT
+ */
+	leaq	_got(%rip), %rdx
+	leaq	_egot(%rip), %rcx
+1:
+	cmpq	%rcx, %rdx
+	jae	2f
+	addq	%rbx, (%rdx)
+	addq	$8, %rdx
+	jmp	1b
+2:
+	
+/*
  * Do the decompression, and jump to the new kernel..
  */
 	pushq	%rsi			/* Save the real mode argument */
diff --git a/arch/x86/boot/compressed/vmlinux.lds.S b/arch/x86/boot/compressed/vmlinux.lds.S
index ...
From: Cyrill Gorcunov
Date: Monday, August 2, 2010 - 10:43 am

On Mon, Aug 02, 2010 at 02:17:31AM -0700, Yinghai Lu wrote:

Yinghai, what was wrong with the origin do_div? After inclusion it as "printf.c"
in another *.c do_div gets clashed?

	-- Cyrill
--

From: Yinghai Lu
Date: Monday, August 2, 2010 - 12:15 pm

yes. get clashed if include that printf.c in arch/x86/boot/compressed/misc.c

Yinghai
--

From: tip-bot for Yinghai Lu
Date: Monday, August 2, 2010 - 8:31 pm

Commit-ID:  f4ed2877b16e8146427306aea8819adac5c88374
Gitweb:     http://git.kernel.org/tip/f4ed2877b16e8146427306aea8819adac5c88374
Author:     Yinghai Lu <yinghai@kernel.org>
AuthorDate: Mon, 2 Aug 2010 02:17:31 -0700
Committer:  H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Mon, 2 Aug 2010 15:51:56 -0700

x86, setup: reorganize the early console setup

Separate early_serial_console from tty.c

This allows for reuse of
early_serial_console.c/string.c/printf.c/cmdline.c in boot/compressed/.

-v2: according to hpa, don't include string.c etc
-v3: compressed/misc.c must have early_serial_base as static, so move it back to tty.c
     for setup code

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
LKML-Reference: <4C568D2B.205@kernel.org>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
---
 arch/x86/boot/Makefile               |    8 +-
 arch/x86/boot/boot.h                 |   35 ++++-----
 arch/x86/boot/cmdline.c              |    6 +-
 arch/x86/boot/early_serial_console.c |  139 ++++++++++++++++++++++++++++++++++
 arch/x86/boot/isdigit.h              |   21 +++++
 arch/x86/boot/printf.c               |    4 +-
 arch/x86/boot/tty.c                  |  136 +---------------------------------
 7 files changed, 186 insertions(+), 163 deletions(-)

diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index ec749c2..f7cb086 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -26,10 +26,10 @@ targets		:= vmlinux.bin setup.bin setup.elf bzImage
 targets		+= fdimage fdimage144 fdimage288 image.iso mtools.conf
 subdir-		:= compressed
 
-setup-y		+= a20.o bioscall.o cmdline.o copy.o cpu.o cpucheck.o edd.o
-setup-y		+= header.o main.o mca.o memory.o pm.o pmjump.o
-setup-y		+= printf.o regs.o string.o tty.o video.o video-mode.o
-setup-y		+= version.o
+setup-y		+= a20.o bioscall.o cmdline.o copy.o cpu.o cpucheck.o
+setup-y		+= early_serial_console.o edd.o header.o main.o mca.o memory.o
+setup-y		+= pm.o pmjump.o printf.o regs.o string.o tty.o ...
From: H. Peter Anvin
Date: Monday, August 2, 2010 - 12:18 am

The way to reuse files in boot/compressed/ would be just to create .c
files in boot/compressed/ with, for example:

/* string.c */
#include "../string.c"

	-hpa

-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.

--

From: Cyrill Gorcunov
Date: Monday, August 2, 2010 - 8:09 am

Hi Yinghai, I'll try to find some time for review though it looks somehow
too 'big' for me :)

Actually by reading your initial approach (which was much smaller in size) I
thought we end up in something like the patch below, though I'll review this
seris. So just to share (I've tested it under qemu). The idea is the same as
your was, so I pushed all constant parts into header and use it when needed
passing serial line base port via boot_params.

---
 arch/x86/boot/boot.h             |    2 -
 arch/x86/boot/compressed/misc.c  |   18 +++++++++++++
 arch/x86/boot/main.c             |    2 -
 arch/x86/boot/tty.c              |   51 ++++++++++-----------------------------
 arch/x86/boot/tty.h              |   45 ++++++++++++++++++++++++++++++++++
 arch/x86/include/asm/bootparam.h |    2 -
 arch/x86/kernel/early_printk.c   |   36 +++------------------------
 7 files changed, 85 insertions(+), 71 deletions(-)

Index: linux-2.6.git/arch/x86/boot/boot.h
=====================================================================
--- linux-2.6.git.orig/arch/x86/boot/boot.h
+++ linux-2.6.git/arch/x86/boot/boot.h
@@ -348,7 +348,7 @@ unsigned int atou(const char *s);
 unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base);
 
 /* tty.c */
-void console_init(void);
+void console_init(struct boot_params *boot_params);
 void puts(const char *);
 void putchar(int);
 int getchar(void);
Index: linux-2.6.git/arch/x86/boot/compressed/misc.c
=====================================================================
--- linux-2.6.git.orig/arch/x86/boot/compressed/misc.c
+++ linux-2.6.git/arch/x86/boot/compressed/misc.c
@@ -27,6 +27,8 @@
 #include <asm/boot.h>
 #include <asm/bootparam.h>
 
+#include "../tty.h"
+
 /* WARNING!!
  * This code is compiled with -fPIC and it is relocated dynamically
  * at run time, but no relocation processing is performed.
@@ -180,6 +182,21 @@ static void __putstr(int error, const ch
 		return;
 #endif
 
+	/*
+	 * write to  early serial ...
From: Yinghai Lu
Date: Monday, August 2, 2010 - 12:23 pm

Eric doesn't like early_serial_console_base in zero page. and said that is fragile.

So try to include string.c/printf.c/cmdline.c/early_serial_console.c in arch/x86/boot/compressed/misc.c
and analyze that command line again.

then kexec path will get support too. that is from arch/x86/boot/compressed/head_32.S or head_64.S, startup_32.
and skip arch/x86/boot/main.c

later with following patch for 3, we get all covered in c code.
1. arch/x86/boot/main.c: setup code.
2. arch/x86/boot/compressed/misc.c: decompress_kernel code : the 2 -v3 patches that i sent last night.
3. arch/x86/kernel/head64.c: real kernel.

maybe we can make early_serial_console.c and early_printk.c to share some .h etc later.

Thanks

Yinghai

[PATCH -v2] x86: Setup early console as early as possible

Analyze "console=uart8250,io,0x3f8,115200n8" in i386_start_kernel/x86_64_start_kernel,
and call setup_early_serial8250_console() to init early serial console.

only can handle io port kind of 8250. because mmio need ioremap.

-v2: use boot_params.hdr.version instead of adding another variable, Suggested by hpa
     update after using x86 memblock patchset

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 arch/x86/include/asm/setup.h |    2 ++
 arch/x86/kernel/head.c       |   27 +++++++++++++++++++++++++++
 arch/x86/kernel/head32.c     |    2 ++
 arch/x86/kernel/head64.c     |   13 +++++++++++--
 kernel/printk.c              |    4 ++++
 5 files changed, 46 insertions(+), 2 deletions(-)

Index: linux-2.6/arch/x86/include/asm/setup.h
===================================================================
--- linux-2.6.orig/arch/x86/include/asm/setup.h
+++ linux-2.6/arch/x86/include/asm/setup.h
@@ -42,6 +42,8 @@ static inline void visws_early_detect(vo
 #endif
 
 extern unsigned long saved_video_mode;
+int setup_early_serial8250_console(char *cmdline);
+void setup_early_console(void);
 
 extern void reserve_standard_io_resources(void);
 extern void i386_reserve_resources(void);
Index: ...
From: Cyrill Gorcunov
Date: Monday, August 2, 2010 - 1:17 pm

I think the better would be to explicitly point q=0 here, ie if (!q || ...)


And Yinghai, lets be more verbose here a bit, since for those who will
be reading this code later might be non-obvious why we have checked for
'version' here. I guess something like "an easy way to check if boot_params
were already copied". Actually it's clean from commit message but I think
... 

Other then that looks good for me, thanks! My Reviewed-by if needed.
 
	-- Cyrill
--

From: Yinghai Lu
Date: Monday, August 2, 2010 - 1:30 pm

will change to 

        /*
         * hdr.version is always not 0, so check it to see
         *  if boot_params is copied or not.
         */

will resend this patch after memblock x86 changes.

YH
--

From: Cyrill Gorcunov
Date: Monday, August 2, 2010 - 1:36 pm

On Mon, Aug 02, 2010 at 01:30:17PM -0700, Yinghai Lu wrote:

ok, thanks!

	-- Cyrill
--

From: Yinghai Lu
Date: Tuesday, August 3, 2010 - 12:14 am

Analyze "console=uart8250,io,0x3f8,115200n8" in i386_start_kernel/x86_64_start_kernel,
and call setup_early_serial8250_console() to init early serial console.

only can handle io port kind of 8250. because mmio need ioremap.

-v2: use boot_params.hdr.version instead of adding another variable, Suggested by hpa
     update after using x86 memblock patchset
-v3: x86 memblock can not make into with 2.6.36 now
     so update this patch to be applied before x86 memblock patchset again.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 arch/x86/include/asm/setup.h |    2 ++
 arch/x86/kernel/head.c       |   26 ++++++++++++++++++++++++++
 arch/x86/kernel/head32.c     |    2 ++
 arch/x86/kernel/head64.c     |   13 ++++++++++++-
 kernel/printk.c              |    4 ++++
 5 files changed, 46 insertions(+), 1 deletion(-)

Index: linux-2.6/arch/x86/include/asm/setup.h
===================================================================
--- linux-2.6.orig/arch/x86/include/asm/setup.h
+++ linux-2.6/arch/x86/include/asm/setup.h
@@ -42,6 +42,8 @@ static inline void visws_early_detect(vo
 #endif
 
 extern unsigned long saved_video_mode;
+int setup_early_serial8250_console(char *cmdline);
+void setup_early_console(void);
 
 extern void reserve_standard_io_resources(void);
 extern void i386_reserve_resources(void);
Index: linux-2.6/arch/x86/kernel/head.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/head.c
+++ linux-2.6/arch/x86/kernel/head.c
@@ -53,3 +53,29 @@ void __init reserve_ebda_region(void)
 	/* reserve all memory between lowmem and the 1MB mark */
 	reserve_early_overlap_ok(lowmem, 0x100000, "BIOS reserved");
 }
+
+void __init setup_early_console(void)
+{
+#ifdef CONFIG_SERIAL_8250_CONSOLE
+	char constr[64], *p, *q;
+
+	/* Can not handle mmio type 8250 uart yet, too early */
+	p = strstr(boot_command_line, "console=uart8250,io,");
+	if (!p)
+		p = strstr(boot_command_line, "console=uart,io,");
+	if ...
From: Andrew Morton
Date: Tuesday, August 3, 2010 - 2:06 am

Why this change?
--

From: Yinghai Lu
Date: Tuesday, August 3, 2010 - 2:09 am

it seems register the same console as early console will dead loop.

let me double check that again to see if can remove that change.

Yinghai
--

From: Yinghai Lu
Date: Tuesday, August 3, 2010 - 3:14 am

without that will get

early console in setup code
early console in decompress_kernel
decompress_kernel:
  input: [0x24a0269-0x2e8b642], output: 0x1000000, heap: [0x2e90e40-0x2e97e3f]

Decompressing Linux... Parsing ELF... done.
Booting the kernel.
[    0.000000] bootconsole [uart0] enabled
[    0.000000] Kernel Layout:
[    0.000000]   .text: [0x01000000-0x01cb210d]
[    0.000000] .rodata: [0x01cb8000-0x02419fff]
[    0.000000]   .data: [0x0241a000-0x025b583f]
[    0.000000]   .init: [0x025b7000-0x02875fff]
[    0.000000]    .bss: [0x02880000-0x0348bb6f]
[    0.000000]    .brk: [0x0348c000-0x034abfff]
[    0.000000]     memblock_x86_reserve_range: [0x01000000-0x0348bb6f]    TEXT DATA BSS
[    0.000000]     memblock_x86_reserve_range: [0x2c6b0000-0x2ffcefff]          RAMDISK
[    0.000000]     memblock_x86_reserve_range: [0x0009fc00-0x000fffff]  * BIOS reserved
[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Linux version 2.6.35-tip-yh-01758-g649ef4b-dirty (yhlu@linux-siqj) (gcc version 4.4.1 [gcc-4_4-branch revision 150839] (SUSE Linux) ) #148 SMP Tue Aug 3 03:09:06 PDT 2010
[    0.000000] Command line: BOOT_IMAGE=linux debug apic=debug ramdisk_size=262144 root=/dev/ram0 rw ip=dhcp console=uart8250,io,0x3f8,115200 initrd=initrd.img
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   Centaur CentaurHauls
[    0.000000] BIOS-provided physical RAM map:
[    0.000000]  BIOS-e820: [0x00000000000000-0x0000000009efff] (usable)
[    0.000000]  BIOS-e820: [0x0000000009f000-0x0000000009ffff] (reserved)
[    0.000000]  BIOS-e820: [0x000000000e8000-0x000000000fffff] (reserved)
[    0.000000]  BIOS-e820: [0x00000000100000-0x0000002ffeffff] (usable)
[    0.000000]  BIOS-e820: [0x0000002fff0000-0x0000002fffffff] (ACPI data)
[    0.000000]  BIOS-e820: [0x000000fffbc000-0x000000ffffffff] (reserved)
[    0.000000] Early serial console at I/O port 0x3f8 ...
From: Cyrill Gorcunov
Date: Tuesday, August 3, 2010 - 8:07 am

Looks good to me, thanks Yinghai!
 
	-- Cyrill
--

From: Thiago Farina
Date: Monday, August 2, 2010 - 10:56 am

These to functions above can be fairly simplified by writting as:

static bool inline is_hex_digit(int c) {
  return (c >= '0' && c <= '9') ||
            (c >= 'A' && c <= 'F') ||
            (c >= 'a' && c <= 'f');
}

Thanks.
--

From: Thiago Farina
Date: Monday, August 2, 2010 - 11:00 am

Wow, sorry, this should be:

static inline bool is_hex_digit(int c) { ... }
--

From: H. Peter Anvin
Date: Monday, August 2, 2010 - 11:27 am

a) You lose the isdigit() functionality, which is useful on its own.
b) Does this enahance readability in any way?
c) Your proposed renaming is nonstandard.

As such, I don't think this is a good idea.

	-hpa
--

From: Thiago Farina
Date: Monday, August 2, 2010 - 12:09 pm

What about this instead?

static inline bool isxdigit(int ch) {
  return (isdigit(ch) || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f');
--

From: H. Peter Anvin
Date: Monday, August 2, 2010 - 1:33 pm

Again, I don't think it adds any readability; the compiler will produce
the same code.

	-hpa
--

Previous thread: kjournald and flush being blocked for 120 sec by Dieter Ries on Monday, August 2, 2010 - 12:02 am. (2 messages)

Next thread: [PATCH v2 0/3] MAX8998 changes for RTC by Joonyoung Shim on Monday, August 2, 2010 - 12:34 am. (1 message)