Skip to contentSkip to conversation

fix serial console on LinuxBIOS

PATCH In review Robert Millan 3 participants 7 messages Nov 7, 2007 – Nov 10, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix serial console on LinuxBIOS

This patch fixes serial console on LinuxBIOS.

I'd appreciate comments (specially on the <grub/machine/machine.h> addition).

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)

* include/grub/i386/efi/machine.h: New file.
* include/grub/i386/linuxbios/machine.h: Likewise.
* include/grub/i386/pc/machine.h: Likewise.
* include/grub/powerpc/ieee1275/machine.h: Likewise.
* include/grub/sparc64/ieee1275/machine.h: Likewise.

* term/i386/pc/serial.c: Include <grub/machine/machine.h>. (serial_hw_io_addr): New variable. (serial_hw_get_port): Obtain port address from serial_hw_io_addr' instead of (unsigned short *) 0x400'.

include/grub/i386/efi/machine.h +24 -0
diff -Nurp grub2/include/grub/i386/efi/machine.h grub2.serial/include/grub/i386/efi/machine.h
@@ -0,0 +1,24 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2007  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MACHINE_MACHINE_HEADER
+#define GRUB_MACHINE_MACHINE_HEADER	1
+
+#define GRUB_MACHINE_EFI	1
+
+#endif /* ! GRUB_MACHINE_MACHINE_HEADER */
include/grub/i386/linuxbios/machine.h +24 -0
diff -Nurp grub2/include/grub/i386/linuxbios/machine.h grub2.serial/include/grub/i386/linuxbios/machine.h
@@ -0,0 +1,24 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2007  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MACHINE_MACHINE_HEADER
+#define GRUB_MACHINE_MACHINE_HEADER	1
+
+#define GRUB_MACHINE_LINUXBIOS	1
+
+#endif /* ! GRUB_MACHINE_MACHINE_HEADER */
include/grub/i386/pc/machine.h +24 -0
diff -Nurp grub2/include/grub/i386/pc/machine.h grub2.serial/include/grub/i386/pc/machine.h
@@ -0,0 +1,24 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2007  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MACHINE_MACHINE_HEADER
+#define GRUB_MACHINE_MACHINE_HEADER	1
+
+#define GRUB_MACHINE_PCBIOS	1
+
+#endif /* ! GRUB_MACHINE_MACHINE_HEADER */
include/grub/powerpc/ieee1275/machine.h +24 -0
diff -Nurp grub2/include/grub/powerpc/ieee1275/machine.h grub2.serial/include/grub/powerpc/ieee1275/machine.h
@@ -0,0 +1,24 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2007  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MACHINE_MACHINE_HEADER
+#define GRUB_MACHINE_MACHINE_HEADER	1
+
+#define GRUB_MACHINE_IEEE1275	1
+
+#endif /* ! GRUB_MACHINE_MACHINE_HEADER */
include/grub/sparc64/ieee1275/machine.h +24 -0
diff -Nurp grub2/include/grub/sparc64/ieee1275/machine.h grub2.serial/include/grub/sparc64/ieee1275/machine.h
@@ -0,0 +1,24 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2007  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MACHINE_MACHINE_HEADER
+#define GRUB_MACHINE_MACHINE_HEADER	1
+
+#define GRUB_MACHINE_IEEE1275	1
+
+#endif /* ! GRUB_MACHINE_MACHINE_HEADER */
term/i386/pc/serial.c +9 -3
diff -Nurp grub2/term/i386/pc/serial.c grub2.serial/term/i386/pc/serial.c
@@ -16,6 +16,7 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <grub/machine/machine.h>
 #include <grub/machine/serial.h>
 #include <grub/machine/console.h>
 #include <grub/term.h>
@@ -63,13 +64,18 @@ struct serial_port
 /* Serial port settings.  */
 static struct serial_port serial_settings;
 
+#ifdef GRUB_MACHINE_PCBIOS
+/* The BIOS data area.  */
+static const unsigned short *serial_hw_io_addr = (const unsigned short *) 0x0400;
+#else
+static const unsigned short serial_hw_io_addr[] = { 0x3f8, 0x2f8 };
+#endif
+
 /* Return the port number for the UNITth serial device.  */
 static inline unsigned short
 serial_hw_get_port (const unsigned short unit)
 {
-  /* The BIOS data area.  */
-  const unsigned short *addr = (const unsigned short *) 0x0400;
-  return addr[unit];
+  return serial_hw_io_addr[unit];
 }
 
 /* Fetch a key.  */
#1 lore raw

Does Linux bios only allow for two serial ports? Are theres ports addresses hard coded into
Linux BIOS?

I also creating all the machine.h for one ifdef is a little much. But it may be needed. The
ifdef in serial.c should be changed to

#ifdef GRUB_MACHINE_LINUXBIOS
<then do this>
#else
<do what everyone else does>

Also what I don't understand about the current code is that it only allows for serial ports
that have address 0x0400 and above (I'm guessing that is the c trickery that is going on
here) when using addr[unit]. And you declare addr is 0x0400.

Quoted 18 lines · Robert Millan

This patch fixes serial console on LinuxBIOS.

I'd appreciate comments (specially on the <grub/machine/machine.h> addition).

--
Robert Millan

<GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.)

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw
Quoted 1 line · Jerone Young

Does Linux bios only allow for two serial ports?

I think the PC/AT architecture is limited to 2 serial ports. Anyway, LinuxBIOS does nothing to "allow" their use; it just initialises some hardware and hands out control to GRUB in a non-intrusive manner.

Quoted 3 lines

Are theres ports
addresses hard coded into
Linux BIOS?

Yes. What is not hardcoded is the com1 vs com2 choice (chosen at build time). But that's a separate issue.

Quoted 2 lines

I also creating all the machine.h for one ifdef is a little much. But it may be needed.

Well, if it was only serial.c I wouldn't propose it. But not having these macros makes us add new one-line files every once in a while, which I think would be good to avoid.

Quoted 7 lines

The
ifdef in serial.c should be changed to

#ifdef GRUB_MACHINE_LINUXBIOS
<then do this>
#else
<do what everyone else does>

It's not really LinuxBIOS-specific. There's a (PC) BIOS-specific way, which is reading ((short *) 0x400), and a generic one which is hardcoding the information.

Quoted 5 lines

Also what I don't understand about the current code is that it only allows for serial ports
that have address 0x0400 and above (I'm guessing that is the c trickery that is going on
here) when using addr[unit]. And you declare addr is 0x0400.

No, you missread it. On BIOS, there's an array of 16-bit addresses at 0x400 (memory space). On other platforms, we just declare the array in our code instead (interestingly, the size of the whole array is the same as the size of a pointer to 0x400 :-)).

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)
#3 lore raw
In reply to Robert Millan
Quoted 11 lines · Robert Millan

This patch fixes serial console on LinuxBIOS.

I'd appreciate comments (specially on the <grub/machine/machine.h> addition).

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)

No header ;)

Quoted 10 lines

* include/grub/i386/efi/machine.h: New file.
* include/grub/i386/linuxbios/machine.h: Likewise.
* include/grub/i386/pc/machine.h: Likewise.
* include/grub/powerpc/ieee1275/machine.h: Likewise.
* include/grub/sparc64/ieee1275/machine.h: Likewise.

* term/i386/pc/serial.c: Include <grub/machine/machine.h>. (serial_hw_io_addr): New variable. (serial_hw_get_port): Obtain port address from serial_hw_io_addr' instead of (unsigned short *) 0x400'.

This seems fine to me. What is your intended use for machine.h? More than just this?

Perhaps we can even use autoconf to define this in config.h? That would be better I think.

--
Marco

#4 lore raw
Quoted 9 lines · Marco Gerards
Quoted 7 lines · Robert Millan

This patch fixes serial console on LinuxBIOS.

I'd appreciate comments (specially on the <grub/machine/machine.h> addition).

Signature · 1 line
Robert Millan
Quoted 6 lines
Quoted 4 lines

<GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.)

No header ;)

Uhm what header?

Quoted 6 lines
Quoted 6 lines

* include/grub/i386/efi/machine.h: New file.
* include/grub/i386/linuxbios/machine.h: Likewise.
* include/grub/i386/pc/machine.h: Likewise.
* include/grub/powerpc/ieee1275/machine.h: Likewise.
* include/grub/sparc64/ieee1275/machine.h: Likewise.

Quoted 7 lines
Quoted 4 lines

* term/i386/pc/serial.c: Include <grub/machine/machine.h>. (serial_hw_io_addr): New variable. (serial_hw_get_port): Obtain port address from serial_hw_io_addr' instead of (unsigned short *) 0x400'.

This seems fine to me. What is your intended use for machine.h? More than just this?

Situations very similar to this one, in that you just need to change a few unportable lines while the overall structure of the file remains portable.

Quoted 2 lines

Perhaps we can even use autoconf to define this in config.h? That would be better I think.

autoconf already setups the cpu / machine symlinks. Why ask it to tell the same info twice?

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)
#5 lore raw
Quoted 10 lines · Robert Millan
Quoted 9 lines · Marco Gerards
Quoted 7 lines · Robert Millan

This patch fixes serial console on LinuxBIOS.

I'd appreciate comments (specially on the <grub/machine/machine.h> addition).

Signature · 1 line
Robert Millan
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

<GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.)

No header ;)

Uhm what header?

That's what I said ;-)

What I meant was something like:

2007-10-31 Robert Millan <[email protected]>

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

* include/grub/i386/efi/machine.h: New file.
* include/grub/i386/linuxbios/machine.h: Likewise.
* include/grub/i386/pc/machine.h: Likewise.
* include/grub/powerpc/ieee1275/machine.h: Likewise.
* include/grub/sparc64/ieee1275/machine.h: Likewise.

* term/i386/pc/serial.c: Include <grub/machine/machine.h>. (serial_hw_io_addr): New variable. (serial_hw_get_port): Obtain port address from serial_hw_io_addr' instead of (unsigned short *) 0x400'.

Quoted 5 lines
Quoted 2 lines

This seems fine to me. What is your intended use for machine.h? More than just this?

Situations very similar to this one, in that you just need to change a few unportable lines while the overall structure of the file remains portable.

What I meant was: what should and shouldn't be added to this .h?

Quoted 5 lines
Quoted 2 lines

Perhaps we can even use autoconf to define this in config.h? That would be better I think.

autoconf already setups the cpu / machine symlinks. Why ask it to tell the same info twice?

Isn't that what you are doing now? But I have no objections to this fix, please commit it :-)

--
Marco

#6 lore raw
Quoted 10 lines · Marco Gerards
Quoted 4 lines
Quoted 2 lines

No header ;)

Uhm what header?

That's what I said ;-)

What I meant was something like:

2007-10-31 Robert Millan <[email protected]>

Ah, right. I tend to skip this because the first part becomes obsolete easily, the second part is the same for all commits (since I don't change my name too often ;-)), and the last part too.

Quoted 1 line

What I meant was: what should and shouldn't be added to this .h?

I wouldn't add anything else.

Quoted 5 lines
Quoted 2 lines

autoconf already setups the cpu / machine symlinks. Why ask it to tell the same info twice?

Isn't that what you are doing now? But I have no objections to this fix, please commit it :-)

Ok, done.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)