The Windows headers include a file called ioaccess.h in the ddk folder, which exposes...
authorReactOS Portable Systems Group <ros-arm-bringup@svn.reactos.org>
Tue, 5 Feb 2008 02:40:08 +0000 (02:40 +0000)
committerReactOS Portable Systems Group <ros-arm-bringup@svn.reactos.org>
Tue, 5 Feb 2008 02:40:08 +0000 (02:40 +0000)
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).

svn path=/trunk/; revision=32130

reactos/boot/freeldr/freeldr/arch/i386/portio.c [deleted file]
reactos/boot/freeldr/freeldr/arch/i386/xboxdisk.c
reactos/boot/freeldr/freeldr/freeldr_arch.rbuild
reactos/boot/freeldr/freeldr/include/freeldr.h
reactos/boot/freeldr/freeldr/include/portio.h [deleted file]
reactos/include/ddk/ioaccess.h [new file with mode: 0755]

diff --git a/reactos/boot/freeldr/freeldr/arch/i386/portio.c b/reactos/boot/freeldr/freeldr/arch/i386/portio.c
deleted file mode 100644 (file)
index 6169c5b..0000000
+++ /dev/null
@@ -1,219 +0,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 */
index 9ae21bc..45358cf 100644 (file)
@@ -152,7 +152,7 @@ static struct
  *  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))
 
index fe5bc10..07ba521 100644 (file)
@@ -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>
index eadd57b..3461355 100644 (file)
@@ -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>
diff --git a/reactos/boot/freeldr/freeldr/include/portio.h b/reactos/boot/freeldr/freeldr/include/portio.h
deleted file mode 100644 (file)
index 2f12179..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- *  FreeLoader
- *  Copyright (C) 2001  Brian Palmer  <brianp@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
diff --git a/reactos/include/ddk/ioaccess.h b/reactos/include/ddk/ioaccess.h
new file mode 100755 (executable)
index 0000000..5474222
--- /dev/null
@@ -0,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 */