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.
This commit is contained in:
parent
1a477ed638
commit
5c58b791cc
6 changed files with 120 additions and 93 deletions
10
ChangeLog
10
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.
|
||||
|
|
1
DISTLIST
1
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
|
||||
|
|
|
@ -27,25 +27,10 @@
|
|||
#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);
|
||||
|
||||
}
|
||||
|
||||
|
|
70
include/grub/i386/io.h
Normal file
70
include/grub/i386/io.h
Normal file
|
@ -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 */
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue