Author: ros-arm-bringup
Date: Tue Feb 5 05:40:08 2008
New Revision: 32130
URL:
http://svn.reactos.org/svn/reactos?rev=32130&view=rev
Log:
The Windows headers include a file called ioaccess.h in the ddk folder, which exposes
various READ/WRITE_PORT/REGISTER_ routines as inlined macros for various architectures
(PPC, MIPS, AMD64, IA64, X86), making use of the MSVC compiler-intrinsics (inp, outp,
etc). Since ReactOS already has those intrinscs implemented, we've also created an
ioaccess.h w32api header file which makes use of them.
We can now remove the portio.h and portio.c files in FreeLDR, since there's no more
need to duplicate this code.
Additionally, this can be also done with the PPC port of FreeLDR or any other
architecture, since it doesn't require per-architecture support in FreeLDR anymore --
only the underlying intrinsics in intrin.h must be implemented (note that for PPC, MIPS
and ARM, the notion of a port doesn't even exist -- those functions map to
register-reading functions, where register basically means memory).
Added:
trunk/reactos/include/ddk/ioaccess.h (with props)
Removed:
trunk/reactos/boot/freeldr/freeldr/arch/i386/portio.c
trunk/reactos/boot/freeldr/freeldr/include/portio.h
Modified:
trunk/reactos/boot/freeldr/freeldr/arch/i386/xboxdisk.c
trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild
trunk/reactos/boot/freeldr/freeldr/include/freeldr.h
Removed: trunk/reactos/boot/freeldr/freeldr/arch/i386/portio.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/portio.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/portio.c (removed)
@@ -1,219 +1,0 @@
-/* $Id$
- *
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS kernel
- * FILE: ntoskrnl/hal/x86/portio.c
- * PURPOSE: Port I/O functions
- * PROGRAMMER: Eric Kohl
- * UPDATE HISTORY:
- * Created 18/10/99
- */
-
-//#include <ntddk.h>
-#include <freeldr.h>
-
-
-/* FUNCTIONS ****************************************************************/
-
-/*
- * This file contains the definitions for the x86 IO instructions
- * inb/inw/inl/outb/outw/outl and the "string versions" of the same
- * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
- * versions of the single-IO instructions (inb_p/inw_p/..).
- *
- * This file is not meant to be obfuscating: it's just complicated
- * to (a) handle it all in a way that makes gcc able to optimize it
- * as well as possible and (b) trying to avoid writing the same thing
- * over and over again with slight variations and possibly making a
- * mistake somewhere.
- */
-
-/*
- * Thanks to James van Artsdalen for a better timing-fix than
- * the two short jumps: using outb's to a nonexistent port seems
- * to guarantee better timings even on fast machines.
- *
- * On the other hand, I'd like to be sure of a non-existent port:
- * I feel a bit unsafe about using 0x80 (should be safe, though)
- *
- * Linus
- */
-
-#ifdef SLOW_IO_BY_JUMPING
-#define __SLOW_DOWN_IO __asm__ __volatile__("jmp 1f\n1:\tjmp 1f\n1:")
-#else
-#define __SLOW_DOWN_IO __asm__ __volatile__("outb %al,$0x80")
-#endif
-
-#ifdef REALLY_SLOW_IO
-#define SLOW_DOWN_IO { __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; }
-#else
-#define SLOW_DOWN_IO __SLOW_DOWN_IO
-#endif
-
-#undef READ_PORT_BUFFER_UCHAR
-NTHALAPI
-VOID
-DDKAPI
-READ_PORT_BUFFER_UCHAR (PUCHAR Port,
- PUCHAR Buffer,
- ULONG Count)
-{
- __asm__ __volatile__ ("cld ; rep ; insb\n\t"
- : "=D" (Buffer), "=c" (Count)
- : "d" (Port),"0" (Buffer),"1" (Count));
-}
-
-#undef READ_PORT_BUFFER_USHORT
-NTHALAPI
-VOID
-DDKAPI
-READ_PORT_BUFFER_USHORT (USHORT* Port,
- USHORT* Buffer,
- ULONG Count)
-{
- __asm__ __volatile__ ("cld ; rep ; insw"
- : "=D" (Buffer), "=c" (Count)
- : "d" (Port),"0" (Buffer),"1" (Count));
-}
-
-#undef READ_PORT_BUFFER_ULONG
-NTHALAPI
-VOID
-DDKAPI
-READ_PORT_BUFFER_ULONG (ULONG* Port,
- ULONG* Buffer,
- ULONG Count)
-{
- __asm__ __volatile__ ("cld ; rep ; insl"
- : "=D" (Buffer), "=c" (Count)
- : "d" (Port),"0" (Buffer),"1" (Count));
-}
-
-#undef READ_PORT_UCHAR
-NTHALAPI
-UCHAR
-DDKAPI
-READ_PORT_UCHAR (PUCHAR Port)
-{
- UCHAR Value;
-
- __asm__("inb %w1, %0\n\t"
- : "=a" (Value)
- : "d" (Port));
- SLOW_DOWN_IO;
- return(Value);
-}
-
-#undef READ_PORT_USHORT
-NTHALAPI
-USHORT
-DDKAPI
-READ_PORT_USHORT (USHORT* Port)
-{
- USHORT Value;
-
- __asm__("inw %w1, %0\n\t"
- : "=a" (Value)
- : "d" (Port));
- SLOW_DOWN_IO;
- return(Value);
-}
-
-#undef READ_PORT_ULONG
-NTHALAPI
-ULONG
-DDKAPI
-READ_PORT_ULONG (ULONG* Port)
-{
- ULONG Value;
-
- __asm__("inl %w1, %0\n\t"
- : "=a" (Value)
- : "d" (Port));
- SLOW_DOWN_IO;
- return(Value);
-}
-
-#undef WRITE_PORT_BUFFER_UCHAR
-NTHALAPI
-VOID
-DDKAPI
-WRITE_PORT_BUFFER_UCHAR (PUCHAR Port,
- PUCHAR Buffer,
- ULONG Count)
-{
- __asm__ __volatile__ ("cld ; rep ; outsb"
- : "=S" (Buffer), "=c" (Count)
- : "d" (Port),"0" (Buffer),"1" (Count));
-}
-
-#undef WRITE_PORT_BUFFER_USHORT
-NTHALAPI
-VOID
-DDKAPI
-WRITE_PORT_BUFFER_USHORT (USHORT* Port,
- USHORT* Buffer,
- ULONG Count)
-{
- __asm__ __volatile__ ("cld ; rep ; outsw"
- : "=S" (Buffer), "=c" (Count)
- : "d" (Port),"0" (Buffer),"1" (Count));
-}
-
-#undef WRITE_PORT_BUFFER_ULONG
-NTHALAPI
-VOID
-DDKAPI
-WRITE_PORT_BUFFER_ULONG (ULONG* Port,
- ULONG* Buffer,
- ULONG Count)
-{
- __asm__ __volatile__ ("cld ; rep ; outsl"
- : "=S" (Buffer), "=c" (Count)
- : "d" (Port),"0" (Buffer),"1" (Count));
-}
-
-#undef WRITE_PORT_UCHAR
-NTHALAPI
-VOID
-DDKAPI
-WRITE_PORT_UCHAR (PUCHAR Port,
- UCHAR Value)
-{
- __asm__("outb %0, %w1\n\t"
- :
- : "a" (Value),
- "d" (Port));
- SLOW_DOWN_IO;
-}
-
-#undef WRITE_PORT_USHORT
-NTHALAPI
-VOID
-DDKAPI
-WRITE_PORT_USHORT (USHORT* Port,
- USHORT Value)
-{
- __asm__("outw %0, %w1\n\t"
- :
- : "a" (Value),
- "d" (Port));
- SLOW_DOWN_IO;
-}
-
-#undef WRITE_PORT_ULONG
-NTHALAPI
-VOID
-DDKAPI
-WRITE_PORT_ULONG (ULONG* Port,
- ULONG Value)
-{
- __asm__("outl %0, %w1\n\t"
- :
- : "a" (Value),
- "d" (Port));
- SLOW_DOWN_IO;
-}
-
-/* EOF */
Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/xboxdisk.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/xboxdisk.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/xboxdisk.c Tue Feb 5 05:40:08 2008
@@ -152,7 +152,7 @@
* Data block read and write commands
*/
#define IDEReadBlock(Address, Buffer, Count) \
- (READ_PORT_BUFFER_USHORT((PUSHORT)((Address) + IDE_REG_DATA_PORT), (PUSHORT)(Buffer),
(Count) / 2))
+ (__inwordstring(((Address) + IDE_REG_DATA_PORT), (PUSHORT)(Buffer), (Count) / 2))
#define IDEWriteBlock(Address, Buffer, Count) \
(WRITE_PORT_BUFFER_USHORT((PUSHORT)((Address) + IDE_REG_DATA_PORT), (PUSHORT)(Buffer),
(Count) / 2))
Modified: trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/freel…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild (original)
+++ trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild Tue Feb 5 05:40:08 2008
@@ -26,7 +26,6 @@
<file>pcmem.c</file>
<file>pcrtc.c</file>
<file>pcvideo.c</file>
- <file>portio.c</file>
<file>machxbox.c</file>
<file>xboxcons.c</file>
<file>xboxdisk.c</file>
Modified: trunk/reactos/boot/freeldr/freeldr/include/freeldr.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/inclu…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/include/freeldr.h (original)
+++ trunk/reactos/boot/freeldr/freeldr/include/freeldr.h Tue Feb 5 05:40:08 2008
@@ -28,6 +28,7 @@
#define NTOSAPI
#define printf TuiPrintf
#include <ntddk.h>
+#include <ioaccess.h>
#include <arc/arc.h>
#include <ketypes.h>
#include <mmtypes.h>
@@ -44,7 +45,6 @@
#include <inifile.h>
#include <inffile.h>
#include <video.h>
-#include <portio.h>
#include <ramdisk.h>
/* NDK, needed for ReactOS/Windows loaders */
#include <ndk/rtlfuncs.h>
Removed: trunk/reactos/boot/freeldr/freeldr/include/portio.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/inclu…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/include/portio.h (original)
+++ trunk/reactos/boot/freeldr/freeldr/include/portio.h (removed)
@@ -1,90 +1,0 @@
-/*
- * FreeLoader
- * Copyright (C) 2001 Brian Palmer <brianp(a)sginet.com>
- * Copyright (C) 2001 Eric Kohl
- * Copyright (C) 2001 Emanuele Aliberti
- *
- * This program 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 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef __PORTIO_H
-#define __PORTIO_H
-
-/*
- * Port I/O functions
- */
-
-NTHALAPI
-VOID
-DDKAPI
-READ_PORT_BUFFER_UCHAR (PUCHAR Port, PUCHAR Value, ULONG Count);
-
-NTHALAPI
-VOID
-DDKAPI
-READ_PORT_BUFFER_ULONG (ULONG* Port, ULONG* Value, ULONG Count);
-
-NTHALAPI
-VOID
-DDKAPI
-READ_PORT_BUFFER_USHORT (USHORT* Port, USHORT* Value, ULONG Count);
-
-NTHALAPI
-UCHAR
-DDKAPI
-READ_PORT_UCHAR (PUCHAR Port);
-
-NTHALAPI
-ULONG
-DDKAPI
-READ_PORT_ULONG (ULONG* Port);
-
-NTHALAPI
-USHORT
-DDKAPI
-READ_PORT_USHORT (USHORT* Port);
-
-NTHALAPI
-VOID
-DDKAPI
-WRITE_PORT_BUFFER_UCHAR (PUCHAR Port, PUCHAR Value, ULONG Count);
-
-NTHALAPI
-VOID
-DDKAPI
-WRITE_PORT_BUFFER_ULONG (ULONG* Port, ULONG* Value, ULONG Count);
-
-NTHALAPI
-VOID
-DDKAPI
-WRITE_PORT_BUFFER_USHORT (USHORT* Port, USHORT* Value, ULONG Count);
-
-NTHALAPI
-VOID
-DDKAPI
-WRITE_PORT_UCHAR (PUCHAR Port, UCHAR Value);
-
-NTHALAPI
-VOID
-DDKAPI
-WRITE_PORT_ULONG (ULONG* Port, ULONG Value);
-
-NTHALAPI
-VOID
-DDKAPI
-WRITE_PORT_USHORT (USHORT* Port, USHORT Value);
-
-
-#endif // defined __PORTIO_H
Added: trunk/reactos/include/ddk/ioaccess.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ddk/ioaccess.h?rev…
==============================================================================
--- trunk/reactos/include/ddk/ioaccess.h (added)
+++ trunk/reactos/include/ddk/ioaccess.h Tue Feb 5 05:40:08 2008
@@ -1,0 +1,70 @@
+/*
+ * ioaccess.h
+ *
+ * Windows Device Driver Kit
+ *
+ * This file is part of the w32api package.
+ *
+ * THIS SOFTWARE IS NOT COPYRIGHTED
+ *
+ * This source code is offered for use in the public domain. You may
+ * use, modify or distribute it freely.
+ *
+ * This code is distributed in the hope that it will be useful but
+ * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
+ * DISCLAIMED. This includes but is not limited to warranties of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ */
+#ifndef __IOACCESS_H
+#define __IOACCESS_H
+
+#if __GNUC__ >= 3
+#pragma GCC system_header
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define H2I(p) PtrToUshort(p)
+
+#ifndef NO_PORT_MACROS
+
+#if defined(_X86_)
+#define READ_REGISTER_UCHAR(r) (*(volatile UCHAR *)(r))
+#define READ_REGISTER_USHORT(r) (*(volatile USHORT *)(r))
+#define READ_REGISTER_ULONG(r) (*(volatile ULONG *)(r))
+#define WRITE_REGISTER_UCHAR(r, v) (*(volatile UCHAR *)(r) = (v))
+#define WRITE_REGISTER_USHORT(r, v) (*(volatile USHORT *)(r) = (v))
+#define WRITE_REGISTER_ULONG(r, v) (*(volatile ULONG *)(r) = (v))
+#define READ_PORT_UCHAR(p) (UCHAR)(__inbyte H2I(p))
+#define READ_PORT_USHORT(p) (USHORT)(__inword H2I(p))
+#define READ_PORT_ULONG(p) (ULONG)(__indword H2I(p))
+#define WRITE_PORT_UCHAR(p, v) __outbyte (H2I(p), (v))
+#define WRITE_PORT_USHORT(p, v) __outword (H2I(p), (v))
+#define WRITE_PORT_ULONG(p, v) __outdword (H2I(p), (v))
+
+#elif defined(_PPC_) || defined(_MIPS_) || defined(_ARM_)
+
+#define READ_REGISTER_UCHAR(r) (*(volatile UCHAR * const)(r))
+#define READ_REGISTER_USHORT(r) (*(volatile USHORT * const)(r))
+#define READ_REGISTER_ULONG(r) (*(volatile ULONG * const)(r))
+#define WRITE_REGISTER_UCHAR(r, v) (*(volatile UCHAR * const)(r) = (v))
+#define WRITE_REGISTER_USHORT(r, v) (*(volatile USHORT * const)(r) = (v))
+#define WRITE_REGISTER_ULONG(r, v) (*(volatile ULONG * const)(r) = (v))
+#define READ_PORT_UCHAR(r) READ_REGISTER_UCHAR(r)
+#define READ_PORT_USHORT(r) READ_REGISTER_USHORT(r)
+#define READ_PORT_ULONG(r) READ_REGISTER_ULONG(r)
+#define WRITE_PORT_UCHAR(p, v) WRITE_REGISTER_UCHAR(p, (UCHAR) (v))
+#define WRITE_PORT_USHORT(p, v) WRITE_REGISTER_USHORT(p, (USHORT) (v))
+#define WRITE_PORT_ULONG(p, v) WRITE_REGISTER_ULONG(p, (ULONG) (v))
+
+#else
+
+#error Unsupported architecture
+
+#endif
+
+#endif /* NO_PORT_MACROS */
+#endif /* __IOACCESS_H */
Propchange: trunk/reactos/include/ddk/ioaccess.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/reactos/include/ddk/ioaccess.h
------------------------------------------------------------------------------
svn:executable = *
Propchange: trunk/reactos/include/ddk/ioaccess.h
------------------------------------------------------------------------------
svn:mime-type = text/plain