thumb mode fixed. (again :/)

This commit is contained in:
Sven Peter 2009-05-06 18:55:00 +02:00 committed by bushing
parent a137980ac1
commit a1a4b706be

71
utils.h
View File

@ -25,13 +25,21 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
static inline u32 read32(u32 addr) static inline u32 read32(u32 addr)
{ {
u32 data; u32 data;
#ifdef __THUMBEB__
__asm__ volatile ("ldr\t%0, [%1]" : "=l" (data) : "l" (addr));
#else
__asm__ volatile ("ldr\t%0, [%1]" : "=r" (data) : "r" (addr)); __asm__ volatile ("ldr\t%0, [%1]" : "=r" (data) : "r" (addr));
#endif
return data; return data;
} }
static inline void write32(u32 addr, u32 data) static inline void write32(u32 addr, u32 data)
{ {
#ifdef __THUMBEB__
__asm__ volatile ("str\t%0, [%1]" : : "l" (data), "l" (addr));
#else
__asm__ volatile ("str\t%0, [%1]" : : "r" (data), "r" (addr)); __asm__ volatile ("str\t%0, [%1]" : : "r" (data), "r" (addr));
#endif
} }
static inline u32 set32(u32 addr, u32 set) static inline u32 set32(u32 addr, u32 set)
@ -41,8 +49,13 @@ static inline u32 set32(u32 addr, u32 set)
"ldr\t%0, [%1]\n" "ldr\t%0, [%1]\n"
"\torr\t%0, %2\n" "\torr\t%0, %2\n"
"\tstr\t%0, [%1]" "\tstr\t%0, [%1]"
#ifdef __THUMBEB__
: "=&l" (data)
: "l" (addr), "l" (set)
#else
: "=&r" (data) : "=&r" (data)
: "r" (addr), "r" (set) : "r" (addr), "r" (set)
#endif
); );
return data; return data;
} }
@ -54,8 +67,13 @@ static inline u32 clear32(u32 addr, u32 clear)
"ldr\t%0, [%1]\n" "ldr\t%0, [%1]\n"
"\tbic\t%0, %2\n" "\tbic\t%0, %2\n"
"\tstr\t%0, [%1]" "\tstr\t%0, [%1]"
#ifdef __THUMBEB__
: "=&l" (data)
: "l" (addr), "l" (clear)
#else
: "=&r" (data) : "=&r" (data)
: "r" (addr), "r" (clear) : "r" (addr), "r" (clear)
#endif
); );
return data; return data;
} }
@ -69,8 +87,13 @@ static inline u32 mask32(u32 addr, u32 clear, u32 set)
"\tbic\t%0, %3\n" "\tbic\t%0, %3\n"
"\torr\t%0, %2\n" "\torr\t%0, %2\n"
"\tstr\t%0, [%1]" "\tstr\t%0, [%1]"
#ifdef __THUMBEB__
: "=&l" (data)
: "l" (addr), "l" (set), "l" (clear)
#else
: "=&r" (data) : "=&r" (data)
: "r" (addr), "r" (set), "r" (clear) : "r" (addr), "r" (set), "r" (clear)
#endif
); );
return data; return data;
} }
@ -78,13 +101,21 @@ static inline u32 mask32(u32 addr, u32 clear, u32 set)
static inline u16 read16(u32 addr) static inline u16 read16(u32 addr)
{ {
u32 data; u32 data;
#ifdef __THUMBEB__
__asm__ volatile ("ldrh\t%0, [%1]" : "=l" (data) : "l" (addr));
#else
__asm__ volatile ("ldrh\t%0, [%1]" : "=r" (data) : "r" (addr)); __asm__ volatile ("ldrh\t%0, [%1]" : "=r" (data) : "r" (addr));
#endif
return data; return data;
} }
static inline void write16(u32 addr, u16 data) static inline void write16(u32 addr, u16 data)
{ {
#ifdef __THUMBEB__
__asm__ volatile ("strh\t%0, [%1]" : : "l" (data), "l" (addr));
#else
__asm__ volatile ("strh\t%0, [%1]" : : "r" (data), "r" (addr)); __asm__ volatile ("strh\t%0, [%1]" : : "r" (data), "r" (addr));
#endif
} }
static inline u16 set16(u32 addr, u16 set) static inline u16 set16(u32 addr, u16 set)
@ -94,8 +125,14 @@ static inline u16 set16(u32 addr, u16 set)
"ldrh\t%0, [%1]\n" "ldrh\t%0, [%1]\n"
"\torr\t%0, %2\n" "\torr\t%0, %2\n"
"\tstrh\t%0, [%1]" "\tstrh\t%0, [%1]"
#ifdef __THUMBEB__
: "=&l" (data)
: "l" (addr), "l" (set)
#else
: "=&r" (data) : "=&r" (data)
: "r" (addr), "r" (set) : "r" (addr), "r" (set)
#endif
); );
return data; return data;
} }
@ -107,8 +144,13 @@ static inline u16 clear16(u32 addr, u16 clear)
"ldrh\t%0, [%1]\n" "ldrh\t%0, [%1]\n"
"\tbic\t%0, %2\n" "\tbic\t%0, %2\n"
"\tstrh\t%0, [%1]" "\tstrh\t%0, [%1]"
#ifdef __THUMBEB__
: "=&l" (data)
: "l" (addr), "l" (clear)
#else
: "=&r" (data) : "=&r" (data)
: "r" (addr), "r" (clear) : "r" (addr), "r" (clear)
#endif
); );
return data; return data;
} }
@ -122,8 +164,13 @@ static inline u16 mask16(u32 addr, u16 clear, u16 set)
"\tbic\t%0, %3\n" "\tbic\t%0, %3\n"
"\torr\t%0, %2\n" "\torr\t%0, %2\n"
"\tstrh\t%0, [%1]" "\tstrh\t%0, [%1]"
#ifdef __THUMBEB__
: "=&l" (data)
: "l" (addr), "l" (set), "l" (clear)
#else
: "=&r" (data) : "=&r" (data)
: "r" (addr), "r" (set), "r" (clear) : "r" (addr), "r" (set), "r" (clear)
#endif
); );
return data; return data;
} }
@ -131,13 +178,21 @@ static inline u16 mask16(u32 addr, u16 clear, u16 set)
static inline u8 read8(u32 addr) static inline u8 read8(u32 addr)
{ {
u32 data; u32 data;
#ifdef __THUMBEB__
__asm__ volatile ("ldrb\t%0, [%1]" : "=l" (data) : "l" (addr));
#else
__asm__ volatile ("ldrb\t%0, [%1]" : "=r" (data) : "r" (addr)); __asm__ volatile ("ldrb\t%0, [%1]" : "=r" (data) : "r" (addr));
#endif
return data; return data;
} }
static inline void write8(u32 addr, u8 data) static inline void write8(u32 addr, u8 data)
{ {
#ifdef __THUMBEB__
__asm__ volatile ("strb\t%0, [%1]" : : "l" (data), "l" (addr));
#else
__asm__ volatile ("strb\t%0, [%1]" : : "r" (data), "r" (addr)); __asm__ volatile ("strb\t%0, [%1]" : : "r" (data), "r" (addr));
#endif
} }
static inline u8 set8(u32 addr, u8 set) static inline u8 set8(u32 addr, u8 set)
@ -147,8 +202,13 @@ static inline u8 set8(u32 addr, u8 set)
"ldrb\t%0, [%1]\n" "ldrb\t%0, [%1]\n"
"\torr\t%0, %2\n" "\torr\t%0, %2\n"
"\tstrb\t%0, [%1]" "\tstrb\t%0, [%1]"
#ifdef __THUMBEB__
: "=&l" (data)
: "l" (addr), "l" (set)
#else
: "=&r" (data) : "=&r" (data)
: "r" (addr), "r" (set) : "r" (addr), "r" (set)
#endif
); );
return data; return data;
} }
@ -160,13 +220,17 @@ static inline u8 clear8(u32 addr, u8 clear)
"ldrb\t%0, [%1]\n" "ldrb\t%0, [%1]\n"
"\tbic\t%0, %2\n" "\tbic\t%0, %2\n"
"\tstrb\t%0, [%1]" "\tstrb\t%0, [%1]"
#ifdef __THUMBEB__
: "=&l" (data)
: "l" (addr), "l" (clear)
#else
: "=&r" (data) : "=&r" (data)
: "r" (addr), "r" (clear) : "r" (addr), "r" (clear)
#endif
); );
return data; return data;
} }
static inline u8 mask8(u32 addr, u8 clear, u8 set) static inline u8 mask8(u32 addr, u8 clear, u8 set)
{ {
u8 data; u8 data;
@ -175,8 +239,13 @@ static inline u8 mask8(u32 addr, u8 clear, u8 set)
"\tbic\t%0, %3\n" "\tbic\t%0, %3\n"
"\torr\t%0, %2\n" "\torr\t%0, %2\n"
"\tstrb\t%0, [%1]" "\tstrb\t%0, [%1]"
#ifdef __THUMBEB__
: "=&l" (data)
: "l" (addr), "l" (set), "l" (clear)
#else
: "=&r" (data) : "=&r" (data)
: "r" (addr), "r" (set), "r" (clear) : "r" (addr), "r" (set), "r" (clear)
#endif
); );
return data; return data;
} }