From fdf37ecebe55d2ef698bff348f74e3c5b8846559 Mon Sep 17 00:00:00 2001
From: Kedar Sovani <kedars@marvell.com>
Date: Wed, 19 Nov 2008 21:51:04 -0500
Subject: [PATCH] libaio: Include arm support.

Patch picked from the Debian arch patches:
http://patch-tracking.debian.net/patch/series/view/libaio/0.3.106-3/00_arches.patch

Signed-off-by: Kedar Sovani <kedars@marvell.com>
---
 libaio-arm-syscall.patch |  154 ++++++++++++++++++++++++++++++++++++++++++++++
 libaio.spec              |   11 +++-
 2 files changed, 163 insertions(+), 2 deletions(-)
 create mode 100644 libaio-arm-syscall.patch

diff --git a/libaio-arm-syscall.patch b/libaio-arm-syscall.patch
new file mode 100644
index 0000000..0d17638
--- /dev/null
+++ b/libaio-arm-syscall.patch
@@ -0,0 +1,154 @@
+Index: b/src/syscall-arm.h
+===================================================================
+--- /dev/null
++++ b/src/syscall-arm.h
+@@ -0,0 +1,116 @@
++/*
++ *  linux/include/asm-arm/unistd.h
++ *
++ *  Copyright (C) 2001-2005 Russell King
++ *
++ * This program is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License version 2 as
++ * published by the Free Software Foundation.
++ *
++ * Please forward _all_ changes to this file to rmk@arm.linux.org.uk,
++ * no matter what the change is.  Thanks!
++ */
++
++#define __NR_OABI_SYSCALL_BASE	0x900000
++
++#if defined(__thumb__) || defined(__ARM_EABI__)
++#define __NR_SYSCALL_BASE	0
++#else
++#define __NR_SYSCALL_BASE	__NR_OABI_SYSCALL_BASE
++#endif
++
++#define __NR_io_setup			(__NR_SYSCALL_BASE+243)
++#define __NR_io_destroy			(__NR_SYSCALL_BASE+244)
++#define __NR_io_getevents		(__NR_SYSCALL_BASE+245)
++#define __NR_io_submit			(__NR_SYSCALL_BASE+246)
++#define __NR_io_cancel			(__NR_SYSCALL_BASE+247)
++
++#define __sys2(x) #x
++#define __sys1(x) __sys2(x)
++
++#if defined(__thumb__) || defined(__ARM_EABI__)
++#define __SYS_REG(name) register long __sysreg __asm__("r7") = __NR_##name;
++#define __SYS_REG_LIST(regs...) "r" (__sysreg) , ##regs
++#define __syscall(name) "swi\t0"
++#else
++#define __SYS_REG(name)
++#define __SYS_REG_LIST(regs...) regs
++#define __syscall(name) "swi\t" __sys1(__NR_##name) ""
++#endif
++
++#define io_syscall1(type,fname,sname,type1,arg1)			\
++type fname(type1 arg1) {						\
++  __SYS_REG(sname)							\
++  register long __r0 __asm__("r0") = (long)arg1;			\
++  register long __res_r0 __asm__("r0");					\
++  __asm__ __volatile__ (						\
++  __syscall(sname)							\
++	: "=r" (__res_r0)						\
++	: __SYS_REG_LIST( "0" (__r0) )					\
++	: "memory" );							\
++  return (type) __res_r0;						\
++}
++
++#define io_syscall2(type,fname,sname,type1,arg1,type2,arg2)		\
++type fname(type1 arg1,type2 arg2) {					\
++  __SYS_REG(sname)							\
++  register long __r0 __asm__("r0") = (long)arg1;			\
++  register long __r1 __asm__("r1") = (long)arg2;			\
++  register long __res_r0 __asm__("r0");					\
++  __asm__ __volatile__ (						\
++  __syscall(sname)							\
++	: "=r" (__res_r0)						\
++	: __SYS_REG_LIST( "0" (__r0), "r" (__r1) )			\
++	: "memory" );							\
++  return (type) __res_r0;						\
++}
++
++#define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3)	\
++type fname(type1 arg1,type2 arg2,type3 arg3) {				\
++  __SYS_REG(sname)							\
++  register long __r0 __asm__("r0") = (long)arg1;			\
++  register long __r1 __asm__("r1") = (long)arg2;			\
++  register long __r2 __asm__("r2") = (long)arg3;			\
++  register long __res_r0 __asm__("r0");					\
++  __asm__ __volatile__ (						\
++  __syscall(sname)							\
++	: "=r" (__res_r0)						\
++	: __SYS_REG_LIST( "0" (__r0), "r" (__r1), "r" (__r2) )		\
++	: "memory" );							\
++  return (type) __res_r0;						\
++}
++
++#define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4)\
++type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4) {		\
++  __SYS_REG(sname)							\
++  register long __r0 __asm__("r0") = (long)arg1;			\
++  register long __r1 __asm__("r1") = (long)arg2;			\
++  register long __r2 __asm__("r2") = (long)arg3;			\
++  register long __r3 __asm__("r3") = (long)arg4;			\
++  register long __res_r0 __asm__("r0");					\
++  __asm__ __volatile__ (						\
++  __syscall(sname)							\
++	: "=r" (__res_r0)						\
++	: __SYS_REG_LIST( "0" (__r0), "r" (__r1), "r" (__r2), "r" (__r3) ) \
++	: "memory" );							\
++  return (type) __res_r0;						\
++}
++
++#define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5)	\
++type fname(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) {\
++  __SYS_REG(sname)							\
++  register long __r0 __asm__("r0") = (long)arg1;			\
++  register long __r1 __asm__("r1") = (long)arg2;			\
++  register long __r2 __asm__("r2") = (long)arg3;			\
++  register long __r3 __asm__("r3") = (long)arg4;			\
++  register long __r4 __asm__("r4") = (long)arg5;			\
++  register long __res_r0 __asm__("r0");					\
++  __asm__ __volatile__ (						\
++  __syscall(sname)							\
++	: "=r" (__res_r0)						\
++	: __SYS_REG_LIST( "0" (__r0), "r" (__r1), "r" (__r2),		\
++			  "r" (__r3), "r" (__r4) )			\
++	: "memory" );							\
++  return (type) __res_r0;						\
++}
++
+
+diff -u libaio-0.3.107.orig/src/syscall.h libaio-0.3.107/src/syscall.h
+--- libaio-0.3.107.orig/src/syscall.h	2005-04-01 15:31:32.000000000 -0500
++++ libaio-0.3.107/src/syscall.h	2008-11-19 23:00:26.000000000 -0500
+@@ -22,6 +22,8 @@
+ #include "syscall-s390.h"
+ #elif defined(__alpha__)
+ #include "syscall-alpha.h"
++#elif defined(__arm__)
++#include "syscall-arm.h"
+ #else
+ #error "add syscall-arch.h"
+ #endif
+diff -u libaio-0.3.107.orig/compat-libaio-0.3.107/src/libaio.h libaio-0.3.107/compat-libaio-0.3.107/src/libaio.h
+--- libaio-0.3.107.orig/src/libaio.h	2008-01-09 15:49:12.000000000 -0500
++++ libaio-0.3.107/src/libaio.h	2008-11-19 23:06:34.000000000 -0500
+@@ -73,6 +73,16 @@
+ #define PADDED(x, y)	unsigned y; x
+ #define PADDEDptr(x, y) unsigned y; x
+ #define PADDEDul(x, y)	unsigned y; unsigned long x
++#elif defined(__arm__) 
++#   if defined(__ARMEB__)
++#define PADDED(x, y)    unsigned y; x
++#define PADDEDptr(x,y)  x
++#define PADDEDul(x, y)  unsigned long x
++#   else
++#define PADDED(x, y)    x; unsigned y
++#define PADDEDptr(x, y) x; unsigned y
++#define PADDEDul(x, y)  unsigned long x; unsigned y
++#   endif
+ #else
+ #error	endian?
+ #endif
diff --git a/libaio.spec b/libaio.spec
index 53a7a9f..9f885c8 100644
--- a/libaio.spec
+++ b/libaio.spec
@@ -1,15 +1,16 @@
 Name: libaio
 Version: 0.3.107
-Release: 4%{?dist}
+Release: 4%{?dist}.fa1
 Summary: Linux-native asynchronous I/O access library
 License: LGPLv2+
 Group:  System Environment/Libraries
 Source: %{name}-%{version}.tar.gz
 BuildRoot: %{_tmppath}/%{name}-root
 Patch1: libaio-install-to-slash.patch
+Patch2: libaio-arm-syscall.patch
 
 # Fix ExclusiveArch as we implement this functionality on more architectures
-ExclusiveArch: i386 x86_64 ia64 s390 s390x ppc ppc64 ppc64pseries ppc64iseries alpha alphaev6
+ExclusiveArch: i386 x86_64 ia64 s390 s390x ppc ppc64 ppc64pseries ppc64iseries alpha alphaev6 %{arm}
 
 %description
 The Linux-native asynchronous I/O facility ("async I/O", or "aio") has a
@@ -34,7 +35,10 @@ for the Linux-native asynchronous I/O facility ("async I/O", or "aio").
 %prep
 %setup -a 0
 %patch1 -p1
+%patch2 -p1
 mv %{name}-%{version} compat-%{name}-%{version}
+cd compat-%{name}-%{version}
+%patch2 -p1
 
 %build
 # A library with a soname of 1.0.0 was inadvertantly released.  This
@@ -74,6 +78,9 @@ make destdir=$RPM_BUILD_ROOT prefix=/ libdir=%{libdir} usrlibdir=%{usrlibdir} \
 %attr(0644,root,root) %{_libdir}/libaio.a
 
 %changelog
+* Tue Dec 9 2008 Kedar Sovani <kedars@marvell.com> - 0.3.107-4.fa1
+- Include support for arm architectures. Patch picked from Debian
+
 * Wed Sep  3 2008 Jeff Moyer <jmoyer@redhat.com> - 0.3.107-4
 - Install to / instead of /usr for early users of libaio (Jeff Moyer)
 - Resolves: bz#459158
-- 
1.5.3.3

