From 5c58b791cc4d704737f5732651668a1b2d847d2a Mon Sep 17 00:00:00 2001 From: robertmh Date: Wed, 3 Oct 2007 20:13:21 +0000 Subject: [PATCH] 2007-10-03 Robert Millan * 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 | 10 ++++++ DISTLIST | 1 + commands/i386/pc/play.c | 31 +++++------------- include/grub/i386/io.h | 70 +++++++++++++++++++++++++++++++++++++++++ term/i386/pc/serial.c | 43 +++++++------------------ term/i386/pc/vga.c | 58 +++++++++++----------------------- 6 files changed, 120 insertions(+), 93 deletions(-) create mode 100644 include/grub/i386/io.h diff --git a/ChangeLog b/ChangeLog index b4589b24f..05a671b43 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-10-03 Robert Millan + + * 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 * conf/i386-efi.rmk (grub_emu_SOURCES): Add util/hostfs.c. diff --git a/DISTLIST b/DISTLIST index bd5c7cf43..b67d1be92 100644 --- 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 diff --git a/commands/i386/pc/play.c b/commands/i386/pc/play.c index 930c693f9..450470689 100644 --- a/commands/i386/pc/play.c +++ b/commands/i386/pc/play.c @@ -27,25 +27,10 @@ #include #include #include +#include #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 index 000000000..0e567766b --- /dev/null +++ b/include/grub/i386/io.h @@ -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 . + */ + +/* 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 */ diff --git a/term/i386/pc/serial.c b/term/i386/pc/serial.c index a668c8cbd..5893f38ba 100644 --- a/term/i386/pc/serial.c +++ b/term/i386/pc/serial.c @@ -25,6 +25,7 @@ #include #include #include +#include #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) diff --git a/term/i386/pc/vga.c b/term/i386/pc/vga.c index 40f09ae5a..ebda7e781 100644 --- a/term/i386/pc/vga.c +++ b/term/i386/pc/vga.c @@ -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