From: Robert Millan <rmh@aybabtu.com>
To: grub-devel@gnu.org
Subject: [PATCH] io.h (inb/outb/etc)
Date: Wed, 3 Oct 2007 15:20:12 +0200 [thread overview]
Message-ID: <20071003132012.GA18208@thorin> (raw)
[-- Attachment #1: Type: text/plain, Size: 398 bytes --]
Hi!
There seems to be a few duplicated inb/outb inline declarations around
different parts of GRUB. New code that makes use of them has to implement
them again, etc. I'd like to add this patch to get them from <grub/cpu/io.h>
instead.
Any comments?
--
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 /.)
[-- Attachment #2: io.diff --]
[-- Type: text/x-diff, Size: 5516 bytes --]
2007-10-03 Robert Millan <rmh@aybabtu.com>
* include/grub/i386/io.h: New file. Provides in*/out* inline
declarations.
* commands/i386/pc/play.c: Remove inb/outb declarations and #include
<grub/cpu/io.h> instead.
* term/i386/pc/serial.c: Likewise.
* term/i386/pc/vga.c: Likewise.
diff -Nur grub2/commands/i386/pc/play.c grub2.io/commands/i386/pc/play.c
--- grub2/commands/i386/pc/play.c 2007-07-22 01:32:19.000000000 +0200
+++ grub2.io/commands/i386/pc/play.c 2007-10-03 15:09:45.000000000 +0200
@@ -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
diff -Nur grub2/DISTLIST grub2.io/DISTLIST
--- grub2/DISTLIST 2007-08-28 12:16:49.000000000 +0200
+++ grub2.io/DISTLIST 2007-10-03 15:14:18.000000000 +0200
@@ -142,6 +142,7 @@
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 -Nur grub2/include/grub/i386/io.h grub2.io/include/grub/i386/io.h
--- grub2/include/grub/i386/io.h 1970-01-01 01:00:00.000000000 +0100
+++ grub2.io/include/grub/i386/io.h 2007-10-03 15:11:45.000000000 +0200
@@ -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
+inb (unsigned short int port)
+{
+ unsigned char _v;
+
+ __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
+ return _v;
+}
+
+static __inline unsigned short int
+inw (unsigned short int port)
+{
+ unsigned short _v;
+
+ __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port));
+ return _v;
+}
+
+static __inline unsigned int
+inl (unsigned short int port)
+{
+ unsigned int _v;
+
+ __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port));
+ return _v;
+}
+
+static __inline void
+outb (unsigned char value, unsigned short int port)
+{
+ __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
+}
+
+static __inline void
+outw (unsigned short int value, unsigned short int port)
+{
+ __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
+
+}
+
+static __inline void
+outl (unsigned int value, unsigned short int port)
+{
+ __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
+}
+
+#endif /* _SYS_IO_H */
diff -Nur grub2/term/i386/pc/serial.c grub2.io/term/i386/pc/serial.c
--- grub2/term/i386/pc/serial.c 2007-07-22 01:32:30.000000000 +0200
+++ grub2.io/term/i386/pc/serial.c 2007-10-03 15:09:45.000000000 +0200
@@ -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 @@
/* 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)
diff -Nur grub2/term/i386/pc/vga.c grub2.io/term/i386/pc/vga.c
--- grub2/term/i386/pc/vga.c 2007-07-22 01:32:31.000000000 +0200
+++ grub2.io/term/i386/pc/vga.c 2007-10-03 15:09:45.000000000 +0200
@@ -66,26 +66,6 @@
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
next reply other threads:[~2007-10-03 13:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-03 13:20 Robert Millan [this message]
2007-10-05 12:30 ` [PATCH] io.h (inb/outb/etc) Robert Millan
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=20071003132012.GA18208@thorin \
--to=rmh@aybabtu.com \
--cc=grub-devel@gnu.org \
/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.