From: Yinghai Lu <yinghai@kernel.org>
To: "H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@elte.hu>,
Thomas Gleixner <tglx@linutronix.de>,
Cyrill Gorcunov <gorcunov@openvz.org>,
Pekka Enberg <penberg@cs.helsinki.fi>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH 1/2] x86, setup: reorgize the early_console_setup
Date: Mon, 02 Aug 2010 00:13:31 -0700 [thread overview]
Message-ID: <4C56701B.1030000@kernel.org> (raw)
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 getchar_timeout(void)
return 0; /* Timeout! */
}
-static void early_serial_init(int port, int baud)
-{
- unsigned char c;
- unsigned divisor;
-
- outb(0x3, port + LCR); /* 8n1 */
- outb(0, port + IER); /* no interrupt */
- outb(0, port + FCR); /* no fifo */
- outb(0x3, port + MCR); /* DTR + RTS */
-
- divisor = 115200 / baud;
- c = inb(port + LCR);
- outb(c | DLAB, port + LCR);
- outb(divisor & 0xff, port + DLL);
- outb((divisor >> 8) & 0xff, port + DLH);
- outb(c & ~DLAB, port + LCR);
-
- early_serial_base = port;
-
- printf("Early serial console at I/O port 0x%x baud: %d\n", port, baud);
-}
-
-static void parse_earlyprintk(void)
-{
- int baud = DEFAULT_BAUD;
- char arg[32];
- int pos = 0;
- int port = 0;
-
- if (cmdline_find_option("earlyprintk", arg, sizeof arg) > 0) {
- char *e;
-
- if (!strncmp(arg, "serial", 6)) {
- port = DEFAULT_SERIAL_PORT;
- pos += 6;
- }
-
- if (arg[pos] == ',')
- pos++;
-
- if (!strncmp(arg, "ttyS", 4)) {
- static const int bases[] = { 0x3f8, 0x2f8 };
- int idx = 0;
-
- if (!strncmp(arg + pos, "ttyS", 4))
- pos += 4;
-
- if (arg[pos++] == '1')
- idx = 1;
-
- port = bases[idx];
- }
-
- if (arg[pos] == ',')
- pos++;
-
- baud = simple_strtoull(arg + pos, &e, 0);
- if (baud == 0 || arg + pos == e)
- baud = DEFAULT_BAUD;
- }
-
- if (port)
- early_serial_init(port, baud);
-}
-
-#define BASE_BAUD (1843200/16)
-static unsigned int probe_baud(int port)
-{
- unsigned char lcr, dll, dlh;
- unsigned int quot;
-
- lcr = inb(port + LCR);
- outb(lcr | DLAB, port + LCR);
- dll = inb(port + DLL);
- dlh = inb(port + DLH);
- outb(lcr, port + LCR);
- quot = (dlh << 8) | dll;
-
- return BASE_BAUD / quot;
-}
-
-static void parse_console_uart8250(void)
-{
- char optstr[64], *options;
- int baud = DEFAULT_BAUD;
- int port = 0;
-
- /*
- * console=uart8250,io,0x3f8,115200n8
- * need to make sure it is last one console !
- */
- if (cmdline_find_option("console", optstr, sizeof optstr) <= 0)
- return;
-
- options = optstr;
-
- if (!strncmp(options, "uart8250,io,", 12))
- port = simple_strtoull(options + 12, &options, 0);
- else if (!strncmp(options, "uart,io,", 8))
- port = simple_strtoull(options + 8, &options, 0);
- else
- return;
-
- if (options && (options[0] == ','))
- baud = simple_strtoull(options + 1, &options, 0);
- else
- baud = probe_baud(port);
-
- if (port)
- early_serial_init(port, baud);
-}
-
-void console_init(void)
-{
- parse_earlyprintk();
-
- if (!early_serial_base)
- parse_console_uart8250();
-}
Index: linux-2.6/arch/x86/boot/early_serial_console.c
===================================================================
--- /dev/null
+++ linux-2.6/arch/x86/boot/early_serial_console.c
@@ -0,0 +1,139 @@
+static int early_serial_base;
+
+#define DEFAULT_SERIAL_PORT 0x3f8 /* ttyS0 */
+
+#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
+
+static void early_serial_init(int port, int baud)
+{
+ unsigned char c;
+ unsigned divisor;
+
+ outb(0x3, port + LCR); /* 8n1 */
+ outb(0, port + IER); /* no interrupt */
+ outb(0, port + FCR); /* no fifo */
+ outb(0x3, port + MCR); /* DTR + RTS */
+
+ divisor = 115200 / baud;
+ c = inb(port + LCR);
+ outb(c | DLAB, port + LCR);
+ outb(divisor & 0xff, port + DLL);
+ outb((divisor >> 8) & 0xff, port + DLH);
+ outb(c & ~DLAB, port + LCR);
+
+ early_serial_base = port;
+}
+
+static void parse_earlyprintk(void)
+{
+ int baud = DEFAULT_BAUD;
+ char arg[32];
+ int pos = 0;
+ int port = 0;
+
+ if (cmdline_find_option("earlyprintk", arg, sizeof arg) > 0) {
+ char *e;
+
+ if (!strncmp(arg, "serial", 6)) {
+ port = DEFAULT_SERIAL_PORT;
+ pos += 6;
+ }
+
+ if (arg[pos] == ',')
+ pos++;
+
+ if (!strncmp(arg, "ttyS", 4)) {
+ static const int bases[] = { 0x3f8, 0x2f8 };
+ int idx = 0;
+
+ if (!strncmp(arg + pos, "ttyS", 4))
+ pos += 4;
+
+ if (arg[pos++] == '1')
+ idx = 1;
+
+ port = bases[idx];
+ }
+
+ if (arg[pos] == ',')
+ pos++;
+
+ baud = simple_strtoull(arg + pos, &e, 0);
+ if (baud == 0 || arg + pos == e)
+ baud = DEFAULT_BAUD;
+ }
+
+ if (port)
+ early_serial_init(port, baud);
+}
+
+#define BASE_BAUD (1843200/16)
+static unsigned int probe_baud(int port)
+{
+ unsigned char lcr, dll, dlh;
+ unsigned int quot;
+
+ lcr = inb(port + LCR);
+ outb(lcr | DLAB, port + LCR);
+ dll = inb(port + DLL);
+ dlh = inb(port + DLH);
+ outb(lcr, port + LCR);
+ quot = (dlh << 8) | dll;
+
+ return BASE_BAUD / quot;
+}
+
+static void parse_console_uart8250(void)
+{
+ char optstr[64], *options;
+ int baud = DEFAULT_BAUD;
+ int port = 0;
+
+ /*
+ * console=uart8250,io,0x3f8,115200n8
+ * need to make sure it is last one console !
+ */
+ if (cmdline_find_option("console", optstr, sizeof optstr) <= 0)
+ return;
+
+ options = optstr;
+
+ if (!strncmp(options, "uart8250,io,", 12))
+ port = simple_strtoull(options + 12, &options, 0);
+ else if (!strncmp(options, "uart,io,", 8))
+ port = simple_strtoull(options + 8, &options, 0);
+ else
+ return;
+
+ if (options && (options[0] == ','))
+ baud = simple_strtoull(options + 1, &options, 0);
+ else
+ baud = probe_baud(port);
+
+ if (port)
+ early_serial_init(port, baud);
+}
+
+void console_init(void)
+{
+ parse_earlyprintk();
+
+ if (!early_serial_base)
+ parse_console_uart8250();
+}
Index: linux-2.6/arch/x86/boot/Makefile
===================================================================
--- linux-2.6.orig/arch/x86/boot/Makefile
+++ linux-2.6/arch/x86/boot/Makefile
@@ -26,9 +26,9 @@ targets := vmlinux.bin setup.bin setup.
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 += a20.o bioscall.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 += regs.o tty.o video.o video-mode.o
setup-y += version.o
setup-$(CONFIG_X86_APM_BOOT) += apm.o
Index: linux-2.6/arch/x86/boot/printf.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/printf.c
+++ linux-2.6/arch/x86/boot/printf.c
@@ -15,8 +15,6 @@
*
*/
-#include "boot.h"
-
static int skip_atoi(const char **s)
{
int i = 0;
@@ -34,7 +32,7 @@ static int skip_atoi(const char **s)
#define SMALL 32 /* Must be 32 == 0x20 */
#define SPECIAL 64 /* 0x */
-#define do_div(n,base) ({ \
+#define __do_div(n,base) ({ \
int __res; \
__res = ((unsigned long) n) % (unsigned) base; \
n = ((unsigned long) n) / (unsigned) base; \
@@ -83,7 +81,7 @@ static char *number(char *str, long num,
tmp[i++] = '0';
else
while (num != 0)
- tmp[i++] = (digits[do_div(num, base)] | locase);
+ tmp[i++] = (digits[__do_div(num, base)] | locase);
if (i > precision)
precision = i;
size -= precision;
Index: linux-2.6/arch/x86/boot/string.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/string.c
+++ linux-2.6/arch/x86/boot/string.c
@@ -12,7 +12,21 @@
* Very basic string functions
*/
-#include "boot.h"
+static inline int isdigit(int ch)
+{
+ return (ch >= '0') && (ch <= '9');
+}
+
+static inline int isxdigit(int ch)
+{
+ if (isdigit(ch))
+ return true;
+
+ if ((ch >= 'a') && (ch <= 'f'))
+ return true;
+
+ return (ch >= 'A') && (ch <= 'F');
+}
int strcmp(const char *str1, const char *str2)
{
Index: linux-2.6/arch/x86/boot/boot.h
===================================================================
--- linux-2.6.orig/arch/x86/boot/boot.h
+++ linux-2.6/arch/x86/boot/boot.h
@@ -200,22 +200,6 @@ static inline int memcmp_gs(const void *
return diff;
}
-static inline int isdigit(int ch)
-{
- return (ch >= '0') && (ch <= '9');
-}
-
-static inline int isxdigit(int ch)
-{
- if (isdigit(ch))
- return true;
-
- if ((ch >= 'a') && (ch <= 'f'))
- return true;
-
- return (ch >= 'A') && (ch <= 'F');
-}
-
/* Heap -- available for dynamic lists. */
extern char _end[];
extern char *HEAP;
Index: linux-2.6/arch/x86/boot/cmdline.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/cmdline.c
+++ linux-2.6/arch/x86/boot/cmdline.c
@@ -12,8 +12,6 @@
* Simple command-line parser for early boot.
*/
-#include "boot.h"
-
static inline int myisspace(u8 c)
{
return c <= ' '; /* Close enough approximation */
@@ -27,9 +25,8 @@ static inline int myisspace(u8 c)
* Returns the length of the argument (regardless of if it was
* truncated to fit in the buffer), or -1 on not found.
*/
-int cmdline_find_option(const char *option, char *buffer, int bufsize)
+static int __cmdline_find_option(u32 cmdline_ptr, const char *option, char *buffer, int bufsize)
{
- u32 cmdline_ptr = boot_params.hdr.cmd_line_ptr;
addr_t cptr;
char c;
int len = -1;
@@ -100,9 +97,8 @@ int cmdline_find_option(const char *opti
* Returns the position of that option (starts counting with 1)
* or 0 on not found
*/
-int cmdline_find_option_bool(const char *option)
+static int __cmdline_find_option_bool(u32 cmdline_ptr, const char *option)
{
- u32 cmdline_ptr = boot_params.hdr.cmd_line_ptr;
addr_t cptr;
char c;
int pos = 0, wstart = 0;
Index: linux-2.6/arch/x86/boot/main.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/main.c
+++ linux-2.6/arch/x86/boot/main.c
@@ -15,6 +15,20 @@
#include "boot.h"
+#include "string.c"
+#include "printf.c"
+
+#include "cmdline.c"
+int cmdline_find_option(const char *option, char *buffer, int bufsize)
+{
+ return __cmdline_find_option(boot_params.hdr.cmd_line_ptr, option, buffer, bufsize);
+}
+
+int cmdline_find_option_bool(const char *option)
+{
+ return __cmdline_find_option_bool(boot_params.hdr.cmd_line_ptr, option);
+}
+
struct boot_params boot_params __attribute__((aligned(16)));
char *HEAP = _end;
next reply other threads:[~2010-08-02 7:14 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-02 7:13 Yinghai Lu [this message]
2010-08-02 7:14 ` [PATCH 2/2] x86: more early console output from compressed/misc.c Yinghai Lu
2010-08-02 7:16 ` [PATCH 1/2] x86, setup: reorgize the early_console_setup H. Peter Anvin
2010-08-02 8:24 ` [PATCH -v2 " Yinghai Lu
2010-08-02 8:26 ` [PATCH -v2 2/2] x86: more early console output from compressed/misc.c Yinghai Lu
2010-08-02 9:17 ` [PATCH -v3 1/2] x86, setup: reorgize the early_console_setup Yinghai Lu
2010-08-02 9:18 ` [PATCH -v3 2/2] x86: more early console output from compressed/misc.c Yinghai Lu
2010-08-02 17:49 ` Cyrill Gorcunov
2010-08-02 18:38 ` H. Peter Anvin
2010-08-02 18:54 ` Cyrill Gorcunov
2010-08-02 18:58 ` H. Peter Anvin
2010-08-02 19:35 ` Yinghai Lu
2010-08-02 20:38 ` H. Peter Anvin
2010-08-02 20:59 ` H. Peter Anvin
2010-08-02 21:08 ` H. Peter Anvin
2010-08-02 21:22 ` Yinghai Lu
2010-08-02 21:27 ` H. Peter Anvin
2010-08-02 21:36 ` Yinghai Lu
2010-08-02 22:30 ` Yinghai Lu
2010-08-02 22:46 ` H. Peter Anvin
2010-08-02 22:51 ` Yinghai Lu
2010-08-02 23:21 ` Yinghai Lu
2010-08-03 4:10 ` [tip:x86/setup] x86, setup: move isdigit.h to ctype.h, header files on top tip-bot for H. Peter Anvin
2010-08-03 3:30 ` [tip:x86/setup] x86, setup: Allow global variables and functions in the decompressor tip-bot for H. Peter Anvin
2010-08-02 17:43 ` [PATCH -v3 1/2] x86, setup: reorgize the early_console_setup Cyrill Gorcunov
2010-08-02 19:15 ` Yinghai Lu
2010-08-03 3:31 ` [tip:x86/setup] x86, setup: reorganize the early console setup tip-bot for Yinghai Lu
2010-08-02 7:18 ` [PATCH 1/2] x86, setup: reorgize the early_console_setup H. Peter Anvin
2010-08-02 15:09 ` Cyrill Gorcunov
2010-08-02 19:23 ` Yinghai Lu
2010-08-02 20:17 ` Cyrill Gorcunov
2010-08-02 20:30 ` Yinghai Lu
2010-08-02 20:36 ` Cyrill Gorcunov
2010-08-03 7:14 ` [PATCH -v3] x86: Setup early console as early as possible Yinghai Lu
2010-08-03 9:06 ` Andrew Morton
2010-08-03 9:09 ` Yinghai Lu
2010-08-03 10:14 ` Yinghai Lu
2010-08-03 15:07 ` Cyrill Gorcunov
2010-08-02 17:56 ` [PATCH 1/2] x86, setup: reorgize the early_console_setup Thiago Farina
2010-08-02 18:00 ` Thiago Farina
2010-08-02 18:27 ` H. Peter Anvin
2010-08-02 19:09 ` Thiago Farina
2010-08-02 20:33 ` H. Peter Anvin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C56701B.1030000@kernel.org \
--to=yinghai@kernel.org \
--cc=gorcunov@openvz.org \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=penberg@cs.helsinki.fi \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.