]> git.proxmox.com Git - grub2.git/commitdiff
2007-10-03 Robert Millan <rmh@aybabtu.com>
authorrobertmh <robertmh@localhost>
Wed, 3 Oct 2007 20:13:21 +0000 (20:13 +0000)
committerrobertmh <robertmh@localhost>
Wed, 3 Oct 2007 20:13:21 +0000 (20:13 +0000)
* include/grub/i386/io.h: New file.
* commands/i386/pc/play.c (inb): Removed.
(outb): Removed.
Include grub/cpu/io.h.  Replace inb() with grub_inb() and outb()
with grub_outb().
* term/i386/pc/serial.c: Likewise.
* term/i386/pc/vga.c: Likewise.

ChangeLog
DISTLIST
commands/i386/pc/play.c
include/grub/i386/io.h [new file with mode: 0644]
term/i386/pc/serial.c
term/i386/pc/vga.c

index b4589b24f5b3c0ac8a2017dfbda282353c3f8a4a..05a671b43372ce0f435fd9a47caf2dc068e2c3e7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2007-10-03  Robert Millan  <rmh@aybabtu.com>
+
+       * include/grub/i386/io.h: New file.
+       * commands/i386/pc/play.c (inb): Removed.
+       (outb): Removed.
+       Include grub/cpu/io.h.  Replace inb() with grub_inb() and outb()
+       with grub_outb().
+       * term/i386/pc/serial.c: Likewise.
+       * term/i386/pc/vga.c: Likewise.
+
 2007-10-02  Robert Millan  <rmh@aybabtu.com>
 
        * conf/i386-efi.rmk (grub_emu_SOURCES): Add util/hostfs.c.
index bd5c7cf43a17b6298c4408c8fcea7beaf7ff9b27..b67d1be927096bfb31303913dbe9826a71c287ea 100644 (file)
--- a/DISTLIST
+++ b/DISTLIST
@@ -142,6 +142,7 @@ include/grub/i386/types.h
 include/grub/i386/efi/kernel.h
 include/grub/i386/efi/loader.h
 include/grub/i386/efi/time.h
+include/grub/i386/io.h
 include/grub/i386/pc/biosdisk.h
 include/grub/i386/pc/boot.h
 include/grub/i386/pc/chainloader.h
index 930c693f952908b8bb05d5a49996fa9b79a782cd..450470689e560d012dba65940784c187d77ccaaa 100644 (file)
 #include <grub/term.h>
 #include <grub/misc.h>
 #include <grub/machine/time.h>
+#include <grub/cpu/io.h>
 
 #define BASE_TEMPO 120
 
-/* Read a byte from a port.  */
-static inline unsigned char
-inb (unsigned short port)
-{
-  unsigned char value;
-  asm volatile ("inb    %w1, %0" : "=a" (value) : "Nd" (port));
-  return value;
-}
-
-/* Write a byte to a port.  */
-static inline void
-outb (unsigned short port, unsigned char value)
-{
-  asm volatile ("outb   %b0, %w1" : : "a" (value), "Nd" (port));
-}
-
 /* The speaker port.  */
 #define SPEAKER                        0x61
 
@@ -130,8 +115,8 @@ beep_off (void)
 {
   unsigned char status;
 
-  status = inb (SPEAKER);
-  outb (SPEAKER, status & ~(SPEAKER_TMR2 | SPEAKER_DATA));
+  status = grub_inb (SPEAKER);
+  grub_outb (SPEAKER, status & ~(SPEAKER_TMR2 | SPEAKER_DATA));
 }
 
 static void
@@ -148,14 +133,14 @@ beep_on (short pitch)
   counter = PIT_FREQUENCY / pitch;
 
   /* Program timer 2.  */
-  outb (PIT_CTRL, PIT_CTRL_SELECT_2 | PIT_CTRL_READLOAD_WORD
+  grub_outb (PIT_CTRL, PIT_CTRL_SELECT_2 | PIT_CTRL_READLOAD_WORD
        | PIT_CTRL_SQUAREWAVE_GEN | PIT_CTRL_COUNT_BINARY);
-  outb (PIT_COUNTER_2, counter & 0xff);                /* LSB */
-  outb (PIT_COUNTER_2, (counter >> 8) & 0xff); /* MSB */
+  grub_outb (PIT_COUNTER_2, counter & 0xff);           /* LSB */
+  grub_outb (PIT_COUNTER_2, (counter >> 8) & 0xff);    /* MSB */
 
   /* Start speaker.  */
-  status = inb (SPEAKER);
-  outb (SPEAKER, status | SPEAKER_TMR2 | SPEAKER_DATA);
+  status = grub_inb (SPEAKER);
+  grub_outb (SPEAKER, status | SPEAKER_TMR2 | SPEAKER_DATA);
 
 }
 
diff --git a/include/grub/i386/io.h b/include/grub/i386/io.h
new file mode 100644 (file)
index 0000000..0e56776
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 1996,2000,2002,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/>.
+ */
+
+/* Based on sys/io.h from GNU libc. */
+
+#ifndef        GRUB_IO_H
+#define        GRUB_IO_H       1
+
+static __inline unsigned char
+grub_inb (unsigned short int port)
+{
+  unsigned char _v;
+
+  __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
+  return _v;
+}
+
+static __inline unsigned short int
+grub_inw (unsigned short int port)
+{
+  unsigned short _v;
+
+  __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port));
+  return _v;
+}
+
+static __inline unsigned int
+grub_inl (unsigned short int port)
+{
+  unsigned int _v;
+
+  __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port));
+  return _v;
+}
+
+static __inline void
+grub_outb (unsigned char value, unsigned short int port)
+{
+  __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
+}
+
+static __inline void
+grub_outw (unsigned short int value, unsigned short int port)
+{
+  __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
+
+}
+
+static __inline void
+grub_outl (unsigned int value, unsigned short int port)
+{
+  __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
+}
+
+#endif /* _SYS_IO_H */
index a668c8cbd419bb19f81f3157db9712a48a7d262d..5893f38ba32d136a640d53c1f241fb04d5a83d0a 100644 (file)
@@ -25,6 +25,7 @@
 #include <grub/normal.h>
 #include <grub/arg.h>
 #include <grub/terminfo.h>
+#include <grub/cpu/io.h>
 
 #define TEXT_WIDTH     80
 #define TEXT_HEIGHT    25
@@ -62,26 +63,6 @@ struct serial_port
 /* Serial port settings.  */
 static struct serial_port serial_settings;
 
-/* Read a byte from a port.  */
-static inline unsigned char
-inb (const unsigned short port)
-{
-  unsigned char value;
-
-  asm volatile ("inb    %w1, %0" : "=a" (value) : "Nd" (port));
-  asm volatile ("outb   %%al, $0x80" : : );
-
-  return value;
-}
-
-/* Write a byte to a port.  */
-static inline void
-outb (const unsigned short port, const unsigned char value)
-{
-  asm volatile ("outb   %b0, %w1" : : "a" (value), "Nd" (port));
-  asm volatile ("outb   %%al, $0x80" : : );
-}
-
 /* Return the port number for the UNITth serial device.  */
 static inline unsigned short
 serial_hw_get_port (const unsigned short unit)
@@ -95,8 +76,8 @@ serial_hw_get_port (const unsigned short unit)
 static int
 serial_hw_fetch (void)
 {
-  if (inb (serial_settings.port + UART_LSR) & UART_DATA_READY)
-    return inb (serial_settings.port + UART_RX);
+  if (grub_inb (serial_settings.port + UART_LSR) & UART_DATA_READY)
+    return grub_inb (serial_settings.port + UART_RX);
 
   return -1;
 }
@@ -108,14 +89,14 @@ serial_hw_put (const int c)
   unsigned int timeout = 100000;
 
   /* Wait until the transmitter holding register is empty.  */
-  while ((inb (serial_settings.port + UART_LSR) & UART_EMPTY_TRANSMITTER) == 0)
+  while ((grub_inb (serial_settings.port + UART_LSR) & UART_EMPTY_TRANSMITTER) == 0)
     {
       if (--timeout == 0)
         /* There is something wrong. But what can I do?  */
         return;
     }
 
-  outb (serial_settings.port + UART_TX, c);
+  grub_outb (serial_settings.port + UART_TX, c);
 }
 
 static void
@@ -287,26 +268,26 @@ serial_hw_init (void)
   unsigned char status = 0;
 
   /* Turn off the interupt.  */
-  outb (serial_settings.port + UART_IER, 0);
+  grub_outb (serial_settings.port + UART_IER, 0);
 
   /* Set DLAB.  */
-  outb (serial_settings.port + UART_LCR, UART_DLAB);
+  grub_outb (serial_settings.port + UART_LCR, UART_DLAB);
 
   /* Set the baud rate.  */
-  outb (serial_settings.port + UART_DLL, serial_settings.divisor & 0xFF);
-  outb (serial_settings.port + UART_DLH, serial_settings.divisor >> 8 );
+  grub_outb (serial_settings.port + UART_DLL, serial_settings.divisor & 0xFF);
+  grub_outb (serial_settings.port + UART_DLH, serial_settings.divisor >> 8 );
 
   /* Set the line status.  */
   status |= (serial_settings.parity
             | serial_settings.word_len
             | serial_settings.stop_bits);
-  outb (serial_settings.port + UART_LCR, status);
+  grub_outb (serial_settings.port + UART_LCR, status);
 
   /* Enable the FIFO.  */
-  outb (serial_settings.port + UART_FCR, UART_ENABLE_FIFO);
+  grub_outb (serial_settings.port + UART_FCR, UART_ENABLE_FIFO);
 
   /* Turn on DTR, RTS, and OUT2.  */
-  outb (serial_settings.port + UART_MCR, UART_ENABLE_MODEM);
+  grub_outb (serial_settings.port + UART_MCR, UART_ENABLE_MODEM);
 
   /* Drain the input buffer.  */
   while (grub_serial_checkkey () != -1)
index 40f09ae5a904dfe9fe3f4fef1fe577e54d990e10..ebda7e781a3e023572dfd64d27101c78edd68bc0 100644 (file)
@@ -66,26 +66,6 @@ static unsigned char *vga_font;
 static unsigned char saved_map_mask;
 static int page = 0;
 
-/* Read a byte from a port.  */
-static inline unsigned char
-inb (unsigned short port)
-{
-  unsigned char value;
-
-  asm volatile ("inb    %w1, %0" : "=a" (value) : "Nd" (port));
-  asm volatile ("outb   %%al, $0x80" : : );
-  
-  return value;
-}
-
-/* Write a byte to a port.  */
-static inline void
-outb (unsigned short port, unsigned char value)
-{
-  asm volatile ("outb   %b0, %w1" : : "a" (value), "Nd" (port));
-  asm volatile ("outb   %%al, $0x80" : : );
-}
-
 #define SEQUENCER_ADDR_PORT    0x3C4
 #define SEQUENCER_DATA_PORT    0x3C5
 #define MAP_MASK_REGISTER      0x02
@@ -106,7 +86,7 @@ static inline void
 wait_vretrace (void)
 {
   /* Wait until there is a vertical retrace.  */
-  while (! (inb (INPUT_STATUS1_REGISTER) & INPUT_STATUS1_VERTR_BIT));
+  while (! (grub_inb (INPUT_STATUS1_REGISTER) & INPUT_STATUS1_VERTR_BIT));
 }
 
 /* Get Map Mask Register.  */
@@ -116,12 +96,12 @@ get_map_mask (void)
   unsigned char old_addr;
   unsigned char old_data;
   
-  old_addr = inb (SEQUENCER_ADDR_PORT);
-  outb (SEQUENCER_ADDR_PORT, MAP_MASK_REGISTER);
+  old_addr = grub_inb (SEQUENCER_ADDR_PORT);
+  grub_outb (SEQUENCER_ADDR_PORT, MAP_MASK_REGISTER);
   
-  old_data = inb (SEQUENCER_DATA_PORT);
+  old_data = grub_inb (SEQUENCER_DATA_PORT);
   
-  outb (SEQUENCER_ADDR_PORT, old_addr);
+  grub_outb (SEQUENCER_ADDR_PORT, old_addr);
 
   return old_data;
 }
@@ -132,12 +112,12 @@ set_map_mask (unsigned char mask)
 {
   unsigned char old_addr;
   
-  old_addr = inb (SEQUENCER_ADDR_PORT);
-  outb (SEQUENCER_ADDR_PORT, MAP_MASK_REGISTER);
+  old_addr = grub_inb (SEQUENCER_ADDR_PORT);
+  grub_outb (SEQUENCER_ADDR_PORT, MAP_MASK_REGISTER);
   
-  outb (SEQUENCER_DATA_PORT, mask);
+  grub_outb (SEQUENCER_DATA_PORT, mask);
   
-  outb (SEQUENCER_ADDR_PORT, old_addr);
+  grub_outb (SEQUENCER_ADDR_PORT, old_addr);
 }
 
 /* Set Read Map Register.  */
@@ -146,12 +126,12 @@ set_read_map (unsigned char map)
 {
   unsigned char old_addr;
   
-  old_addr = inb (GRAPHICS_ADDR_PORT);
+  old_addr = grub_inb (GRAPHICS_ADDR_PORT);
 
-  outb (GRAPHICS_ADDR_PORT, READ_MAP_REGISTER);
-  outb (GRAPHICS_DATA_PORT, map);
+  grub_outb (GRAPHICS_ADDR_PORT, READ_MAP_REGISTER);
+  grub_outb (GRAPHICS_DATA_PORT, map);
 
-  outb (GRAPHICS_ADDR_PORT, old_addr);
+  grub_outb (GRAPHICS_ADDR_PORT, old_addr);
 }
 
 /* Set start address.  */
@@ -160,15 +140,15 @@ set_start_address (unsigned int start)
 {
   unsigned char old_addr;
   
-  old_addr = inb (CRTC_ADDR_PORT);
+  old_addr = grub_inb (CRTC_ADDR_PORT);
   
-  outb (CRTC_ADDR_PORT, START_ADDR_LOW_REGISTER);
-  outb (CRTC_DATA_PORT, start & 0xFF);
+  grub_outb (CRTC_ADDR_PORT, START_ADDR_LOW_REGISTER);
+  grub_outb (CRTC_DATA_PORT, start & 0xFF);
   
-  outb (CRTC_ADDR_PORT, START_ADDR_HIGH_REGISTER);
-  outb (CRTC_DATA_PORT, start >> 8);
+  grub_outb (CRTC_ADDR_PORT, START_ADDR_HIGH_REGISTER);
+  grub_outb (CRTC_DATA_PORT, start >> 8);
 
-  outb (CRTC_ADDR_PORT, old_addr);
+  grub_outb (CRTC_ADDR_PORT, old_addr);
 }
 
 static grub_err_t