2015-04-28 01:40:11 +08:00
|
|
|
/* Intel x86 GCC specific public inline assembler functions and macros */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2015, Wind River Systems, Inc.
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-04-28 01:40:11 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Either public functions or macros or invoked by public functions */
|
|
|
|
|
2018-09-15 01:43:44 +08:00
|
|
|
#ifndef ZEPHYR_INCLUDE_ARCH_X86_ASM_INLINE_GCC_H_
|
|
|
|
#define ZEPHYR_INCLUDE_ARCH_X86_ASM_INLINE_GCC_H_
|
2015-04-28 01:40:11 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The file must not be included directly
|
2016-11-06 07:52:29 +08:00
|
|
|
* Include kernel.h instead
|
2015-04-28 01:40:11 +08:00
|
|
|
*/
|
|
|
|
|
2015-08-21 17:49:57 +08:00
|
|
|
#include <sys_io.h>
|
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-04-28 01:40:11 +08:00
|
|
|
#ifndef _ASMLANGUAGE
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 23:32:08 +08:00
|
|
|
#include <zephyr/types.h>
|
2015-04-28 01:40:11 +08:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-08-13 06:31:41 +08:00
|
|
|
* @internal
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-08-13 06:31:41 +08:00
|
|
|
* @brief Disable all interrupts on the CPU
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-08-13 06:31:41 +08:00
|
|
|
* GCC assembly internals of irq_lock(). See irq_lock() for a complete
|
|
|
|
* description.
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return An architecture-dependent lock-out key representing the
|
2015-07-02 05:22:39 +08:00
|
|
|
* "interrupt disable state" prior to the call.
|
|
|
|
*/
|
2015-04-28 01:40:11 +08:00
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE unsigned int _do_irq_lock(void)
|
2015-04-28 01:40:11 +08:00
|
|
|
{
|
|
|
|
unsigned int key;
|
|
|
|
|
|
|
|
__asm__ volatile (
|
|
|
|
"pushfl;\n\t"
|
|
|
|
"cli;\n\t"
|
|
|
|
"popl %0;\n\t"
|
|
|
|
: "=g" (key)
|
|
|
|
:
|
|
|
|
: "memory"
|
|
|
|
);
|
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
2015-08-13 06:31:41 +08:00
|
|
|
*
|
|
|
|
* @internal
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Enable all interrupts on the CPU (inline)
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-08-13 06:31:41 +08:00
|
|
|
* GCC assembly internals of irq_lock_unlock(). See irq_lock_unlock() for a
|
|
|
|
* complete description.
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return N/A
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-04-28 01:40:11 +08:00
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE void _do_irq_unlock(void)
|
2015-04-28 01:40:11 +08:00
|
|
|
{
|
|
|
|
__asm__ volatile (
|
|
|
|
"sti;\n\t"
|
2016-12-03 01:18:39 +08:00
|
|
|
: : : "memory"
|
2015-04-28 01:40:11 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-08-15 05:16:16 +08:00
|
|
|
* @brief find least significant bit set in a 32-bit word
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-08-15 05:16:16 +08:00
|
|
|
* This routine finds the first bit set starting from the least significant bit
|
|
|
|
* in the argument passed in and returns the index of that bit. Bits are
|
|
|
|
* numbered starting at 1 from the least significant bit. A return value of
|
|
|
|
* zero indicates that the value passed is zero.
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-08-15 05:16:16 +08:00
|
|
|
* @return least significant bit set, 0 if @a op is 0
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-08-15 05:16:16 +08:00
|
|
|
* @internal
|
|
|
|
* For Intel64 (x86_64) architectures, the 'cmovzl' can be removed and leverage
|
|
|
|
* the fact that the 'bsfl' doesn't modify the destination operand when the
|
|
|
|
* source operand is zero. The "bitpos" variable can be preloaded into the
|
|
|
|
* destination register, and given the unconditional ++bitpos that is performed
|
|
|
|
* after the 'cmovzl', the correct results are yielded.
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-04-28 01:40:11 +08:00
|
|
|
|
2017-04-21 23:55:34 +08:00
|
|
|
static ALWAYS_INLINE unsigned int find_lsb_set(u32_t op)
|
2015-04-28 01:40:11 +08:00
|
|
|
{
|
2016-03-03 04:28:09 +08:00
|
|
|
unsigned int bitpos;
|
2015-04-28 01:40:11 +08:00
|
|
|
|
|
|
|
__asm__ volatile (
|
|
|
|
|
2015-07-23 01:34:59 +08:00
|
|
|
#if defined(CONFIG_CMOV)
|
2015-04-28 01:40:11 +08:00
|
|
|
|
|
|
|
"bsfl %1, %0;\n\t"
|
|
|
|
"cmovzl %2, %0;\n\t"
|
|
|
|
: "=r" (bitpos)
|
|
|
|
: "rm" (op), "r" (-1)
|
|
|
|
: "cc"
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
"bsfl %1, %0;\n\t"
|
|
|
|
"jnz 1f;\n\t"
|
|
|
|
"movl $-1, %0;\n\t"
|
|
|
|
"1:\n\t"
|
|
|
|
: "=r" (bitpos)
|
|
|
|
: "rm" (op)
|
|
|
|
: "cc"
|
|
|
|
|
2015-07-23 01:34:59 +08:00
|
|
|
#endif /* CONFIG_CMOV */
|
2015-04-28 01:40:11 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
return (bitpos + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-08-15 05:16:16 +08:00
|
|
|
* @brief find most significant bit set in a 32-bit word
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-08-15 05:16:16 +08:00
|
|
|
* This routine finds the first bit set starting from the most significant bit
|
|
|
|
* in the argument passed in and returns the index of that bit. Bits are
|
|
|
|
* numbered starting at 1 from the least significant bit. A return value of
|
|
|
|
* zero indicates that the value passed is zero.
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-08-15 05:16:16 +08:00
|
|
|
* @return most significant bit set, 0 if @a op is 0
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-08-15 05:16:16 +08:00
|
|
|
* @internal
|
|
|
|
* For Intel64 (x86_64) architectures, the 'cmovzl' can be removed and leverage
|
|
|
|
* the fact that the 'bsfl' doesn't modify the destination operand when the
|
|
|
|
* source operand is zero. The "bitpos" variable can be preloaded into the
|
|
|
|
* destination register, and given the unconditional ++bitpos that is performed
|
|
|
|
* after the 'cmovzl', the correct results are yielded.
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-04-28 01:40:11 +08:00
|
|
|
|
2017-04-21 23:55:34 +08:00
|
|
|
static ALWAYS_INLINE unsigned int find_msb_set(u32_t op)
|
2015-04-28 01:40:11 +08:00
|
|
|
{
|
2016-03-03 04:28:09 +08:00
|
|
|
unsigned int bitpos;
|
2015-04-28 01:40:11 +08:00
|
|
|
|
|
|
|
__asm__ volatile (
|
|
|
|
|
2015-07-23 01:34:59 +08:00
|
|
|
#if defined(CONFIG_CMOV)
|
2015-04-28 01:40:11 +08:00
|
|
|
|
|
|
|
"bsrl %1, %0;\n\t"
|
|
|
|
"cmovzl %2, %0;\n\t"
|
|
|
|
: "=r" (bitpos)
|
|
|
|
: "rm" (op), "r" (-1)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
"bsrl %1, %0;\n\t"
|
|
|
|
"jnz 1f;\n\t"
|
|
|
|
"movl $-1, %0;\n\t"
|
|
|
|
"1:\n\t"
|
|
|
|
: "=r" (bitpos)
|
|
|
|
: "rm" (op)
|
|
|
|
: "cc"
|
|
|
|
|
2015-07-23 01:34:59 +08:00
|
|
|
#endif /* CONFIG_CMOV */
|
2015-04-28 01:40:11 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
return (bitpos + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
2016-11-06 03:43:33 +08:00
|
|
|
* @brief read timestamp register ensuring serialization
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-04-28 01:40:11 +08:00
|
|
|
|
2017-04-21 23:55:34 +08:00
|
|
|
static inline u64_t _tsc_read(void)
|
2015-04-28 01:40:11 +08:00
|
|
|
{
|
|
|
|
union {
|
|
|
|
struct {
|
2017-04-21 23:55:34 +08:00
|
|
|
u32_t lo;
|
|
|
|
u32_t hi;
|
2015-04-28 01:40:11 +08:00
|
|
|
};
|
2017-04-21 23:55:34 +08:00
|
|
|
u64_t value;
|
2015-04-28 01:40:11 +08:00
|
|
|
} rv;
|
|
|
|
|
|
|
|
/* rdtsc & cpuid clobbers eax, ebx, ecx and edx registers */
|
|
|
|
__asm__ volatile (/* serialize */
|
|
|
|
"xorl %%eax,%%eax;\n\t"
|
|
|
|
"cpuid;\n\t"
|
|
|
|
:
|
|
|
|
:
|
|
|
|
: "%eax", "%ebx", "%ecx", "%edx"
|
|
|
|
);
|
|
|
|
/*
|
|
|
|
* We cannot use "=A", since this would use %rax on x86_64 and
|
|
|
|
* return only the lower 32bits of the TSC
|
|
|
|
*/
|
|
|
|
__asm__ volatile ("rdtsc" : "=a" (rv.lo), "=d" (rv.hi));
|
|
|
|
|
|
|
|
|
|
|
|
return rv.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
2015-04-28 01:40:11 +08:00
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Get a 32 bit CPU timestamp counter
|
2015-04-28 01:40:11 +08:00
|
|
|
*
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return a 32-bit number
|
2015-04-28 01:40:11 +08:00
|
|
|
*/
|
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2017-04-21 23:55:34 +08:00
|
|
|
u32_t _do_read_cpu_timestamp32(void)
|
2015-04-28 01:40:11 +08:00
|
|
|
{
|
2017-04-21 23:55:34 +08:00
|
|
|
u32_t rv;
|
2015-04-28 01:40:11 +08:00
|
|
|
|
|
|
|
__asm__ volatile("rdtsc" : "=a"(rv) : : "%edx");
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-21 17:49:57 +08:00
|
|
|
/* Implementation of sys_io.h's documented functions */
|
2015-04-28 01:40:11 +08:00
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2017-04-21 23:55:34 +08:00
|
|
|
void sys_out8(u8_t data, io_port_t port)
|
2015-04-28 01:40:11 +08:00
|
|
|
{
|
2015-11-11 20:33:43 +08:00
|
|
|
__asm__ volatile("outb %b0, %w1;\n\t"
|
|
|
|
:
|
|
|
|
: "a"(data), "Nd"(port));
|
2015-04-28 01:40:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2017-04-21 23:55:34 +08:00
|
|
|
u8_t sys_in8(io_port_t port)
|
2015-04-28 01:40:11 +08:00
|
|
|
{
|
2017-04-21 23:55:34 +08:00
|
|
|
u8_t ret;
|
2015-04-28 01:40:11 +08:00
|
|
|
|
2015-11-11 20:33:43 +08:00
|
|
|
__asm__ volatile("inb %w1, %b0;\n\t"
|
|
|
|
: "=a"(ret)
|
|
|
|
: "Nd"(port));
|
2015-08-21 17:49:57 +08:00
|
|
|
return ret;
|
2015-04-28 01:40:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2017-04-21 23:55:34 +08:00
|
|
|
void sys_out16(u16_t data, io_port_t port)
|
2015-04-28 01:40:11 +08:00
|
|
|
{
|
2015-11-11 20:33:43 +08:00
|
|
|
__asm__ volatile("outw %w0, %w1;\n\t"
|
|
|
|
:
|
|
|
|
: "a"(data), "Nd"(port));
|
2015-04-28 01:40:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2017-04-21 23:55:34 +08:00
|
|
|
u16_t sys_in16(io_port_t port)
|
2015-08-21 17:49:57 +08:00
|
|
|
{
|
2017-04-21 23:55:34 +08:00
|
|
|
u16_t ret;
|
2015-08-21 17:49:57 +08:00
|
|
|
|
2015-11-11 20:33:43 +08:00
|
|
|
__asm__ volatile("inw %w1, %w0;\n\t"
|
|
|
|
: "=a"(ret)
|
|
|
|
: "Nd"(port));
|
2015-08-21 17:49:57 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-04-28 01:40:11 +08:00
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2017-04-21 23:55:34 +08:00
|
|
|
void sys_out32(u32_t data, io_port_t port)
|
2015-04-28 01:40:11 +08:00
|
|
|
{
|
2015-11-11 20:33:43 +08:00
|
|
|
__asm__ volatile("outl %0, %w1;\n\t"
|
|
|
|
:
|
|
|
|
: "a"(data), "Nd"(port));
|
2015-08-21 17:49:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2017-04-21 23:55:34 +08:00
|
|
|
u32_t sys_in32(io_port_t port)
|
2015-08-21 17:49:57 +08:00
|
|
|
{
|
2017-04-21 23:55:34 +08:00
|
|
|
u32_t ret;
|
2015-04-28 01:40:11 +08:00
|
|
|
|
2015-11-11 20:33:43 +08:00
|
|
|
__asm__ volatile("inl %w1, %0;\n\t"
|
|
|
|
: "=a"(ret)
|
|
|
|
: "Nd"(port));
|
2015-08-21 17:49:57 +08:00
|
|
|
return ret;
|
2015-04-28 01:40:11 +08:00
|
|
|
}
|
|
|
|
|
2015-10-03 06:28:18 +08:00
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2016-03-03 04:28:09 +08:00
|
|
|
void sys_io_set_bit(io_port_t port, unsigned int bit)
|
2015-10-03 06:28:18 +08:00
|
|
|
{
|
2017-04-21 23:55:34 +08:00
|
|
|
u32_t reg = 0;
|
2015-10-03 06:28:18 +08:00
|
|
|
|
2015-11-11 00:11:52 +08:00
|
|
|
__asm__ volatile("inl %w1, %0;\n\t"
|
|
|
|
"btsl %2, %0;\n\t"
|
|
|
|
"outl %0, %w1;\n\t"
|
2015-10-03 06:28:18 +08:00
|
|
|
:
|
2015-11-11 00:11:52 +08:00
|
|
|
: "a" (reg), "Nd" (port), "Ir" (bit));
|
2015-10-03 06:28:18 +08:00
|
|
|
}
|
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2016-03-03 04:28:09 +08:00
|
|
|
void sys_io_clear_bit(io_port_t port, unsigned int bit)
|
2015-10-03 06:28:18 +08:00
|
|
|
{
|
2017-04-21 23:55:34 +08:00
|
|
|
u32_t reg = 0;
|
2015-10-03 06:28:18 +08:00
|
|
|
|
2015-11-11 00:11:52 +08:00
|
|
|
__asm__ volatile("inl %w1, %0;\n\t"
|
|
|
|
"btrl %2, %0;\n\t"
|
|
|
|
"outl %0, %w1;\n\t"
|
2015-10-03 06:28:18 +08:00
|
|
|
:
|
2015-11-11 00:11:52 +08:00
|
|
|
: "a" (reg), "Nd" (port), "Ir" (bit));
|
2015-10-03 06:28:18 +08:00
|
|
|
}
|
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2016-03-03 04:28:09 +08:00
|
|
|
int sys_io_test_bit(io_port_t port, unsigned int bit)
|
2015-10-03 06:28:18 +08:00
|
|
|
{
|
2017-04-21 23:55:34 +08:00
|
|
|
u32_t ret;
|
2015-10-03 06:28:18 +08:00
|
|
|
|
2015-11-11 00:11:52 +08:00
|
|
|
__asm__ volatile("inl %w1, %0\n\t"
|
|
|
|
"btl %2, %0\n\t"
|
|
|
|
: "=a" (ret)
|
|
|
|
: "Nd" (port), "Ir" (bit));
|
2015-10-03 06:28:18 +08:00
|
|
|
|
|
|
|
return (ret & 1);
|
|
|
|
}
|
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2016-03-03 04:28:09 +08:00
|
|
|
int sys_io_test_and_set_bit(io_port_t port, unsigned int bit)
|
2015-10-03 06:28:18 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = sys_io_test_bit(port, bit);
|
|
|
|
sys_io_set_bit(port, bit);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2016-03-03 04:28:09 +08:00
|
|
|
int sys_io_test_and_clear_bit(io_port_t port, unsigned int bit)
|
2015-10-03 06:28:18 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = sys_io_test_bit(port, bit);
|
|
|
|
sys_io_clear_bit(port, bit);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2017-04-21 23:55:34 +08:00
|
|
|
void sys_write8(u8_t data, mm_reg_t addr)
|
2015-08-21 17:49:57 +08:00
|
|
|
{
|
|
|
|
__asm__ volatile("movb %0, %1;\n\t"
|
|
|
|
:
|
2017-04-21 23:55:34 +08:00
|
|
|
: "q"(data), "m" (*(volatile u8_t *) addr)
|
2015-08-21 17:49:57 +08:00
|
|
|
: "memory");
|
|
|
|
}
|
2015-04-28 01:40:11 +08:00
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2017-04-21 23:55:34 +08:00
|
|
|
u8_t sys_read8(mm_reg_t addr)
|
2015-08-21 17:49:57 +08:00
|
|
|
{
|
2017-04-21 23:55:34 +08:00
|
|
|
u8_t ret;
|
2015-08-21 17:49:57 +08:00
|
|
|
|
|
|
|
__asm__ volatile("movb %1, %0;\n\t"
|
|
|
|
: "=q"(ret)
|
2017-04-21 23:55:34 +08:00
|
|
|
: "m" (*(volatile u8_t *) addr)
|
2015-08-21 17:49:57 +08:00
|
|
|
: "memory");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2015-04-28 01:40:11 +08:00
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2017-04-21 23:55:34 +08:00
|
|
|
void sys_write16(u16_t data, mm_reg_t addr)
|
2015-04-28 01:40:11 +08:00
|
|
|
{
|
2015-08-21 17:49:57 +08:00
|
|
|
__asm__ volatile("movw %0, %1;\n\t"
|
|
|
|
:
|
2017-04-21 23:55:34 +08:00
|
|
|
: "r"(data), "m" (*(volatile u16_t *) addr)
|
2015-08-21 17:49:57 +08:00
|
|
|
: "memory");
|
2015-04-28 01:40:11 +08:00
|
|
|
}
|
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2017-04-21 23:55:34 +08:00
|
|
|
u16_t sys_read16(mm_reg_t addr)
|
2015-08-21 17:49:57 +08:00
|
|
|
{
|
2017-04-21 23:55:34 +08:00
|
|
|
u16_t ret;
|
2015-04-28 01:40:11 +08:00
|
|
|
|
2015-08-21 17:49:57 +08:00
|
|
|
__asm__ volatile("movw %1, %0;\n\t"
|
|
|
|
: "=r"(ret)
|
2017-04-21 23:55:34 +08:00
|
|
|
: "m" (*(volatile u16_t *) addr)
|
2015-08-21 17:49:57 +08:00
|
|
|
: "memory");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2017-04-21 23:55:34 +08:00
|
|
|
void sys_write32(u32_t data, mm_reg_t addr)
|
2015-08-21 17:49:57 +08:00
|
|
|
{
|
|
|
|
__asm__ volatile("movl %0, %1;\n\t"
|
|
|
|
:
|
2017-04-21 23:55:34 +08:00
|
|
|
: "r"(data), "m" (*(volatile u32_t *) addr)
|
2015-08-21 17:49:57 +08:00
|
|
|
: "memory");
|
|
|
|
}
|
2015-04-28 01:40:11 +08:00
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2017-04-21 23:55:34 +08:00
|
|
|
u32_t sys_read32(mm_reg_t addr)
|
2015-04-28 01:40:11 +08:00
|
|
|
{
|
2017-04-21 23:55:34 +08:00
|
|
|
u32_t ret;
|
2015-04-28 01:40:11 +08:00
|
|
|
|
2015-08-21 17:49:57 +08:00
|
|
|
__asm__ volatile("movl %1, %0;\n\t"
|
|
|
|
: "=r"(ret)
|
2017-04-21 23:55:34 +08:00
|
|
|
: "m" (*(volatile u32_t *) addr)
|
2015-08-21 17:49:57 +08:00
|
|
|
: "memory");
|
|
|
|
|
|
|
|
return ret;
|
2015-04-28 01:40:11 +08:00
|
|
|
}
|
|
|
|
|
2015-08-21 17:49:57 +08:00
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2016-03-03 04:28:09 +08:00
|
|
|
void sys_set_bit(mem_addr_t addr, unsigned int bit)
|
2015-08-21 17:50:57 +08:00
|
|
|
{
|
|
|
|
__asm__ volatile("btsl %1, %0;\n\t"
|
2017-04-21 23:55:34 +08:00
|
|
|
: "+m" (*(volatile u32_t *) (addr))
|
2015-08-21 17:50:57 +08:00
|
|
|
: "Ir" (bit)
|
|
|
|
: "memory");
|
|
|
|
}
|
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2016-03-03 04:28:09 +08:00
|
|
|
void sys_clear_bit(mem_addr_t addr, unsigned int bit)
|
2015-08-21 17:50:57 +08:00
|
|
|
{
|
|
|
|
__asm__ volatile("btrl %1, %0;\n\t"
|
2017-04-21 23:55:34 +08:00
|
|
|
: "+m" (*(volatile u32_t *) (addr))
|
2015-08-21 17:50:57 +08:00
|
|
|
: "Ir" (bit));
|
|
|
|
}
|
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2016-03-03 04:28:09 +08:00
|
|
|
int sys_test_bit(mem_addr_t addr, unsigned int bit)
|
2015-08-21 17:50:57 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
__asm__ volatile("btl %2, %1;\n\t"
|
|
|
|
"sbb %0, %0\n\t"
|
2017-04-21 23:55:34 +08:00
|
|
|
: "=r" (ret), "+m" (*(volatile u32_t *) (addr))
|
2015-08-21 17:50:57 +08:00
|
|
|
: "Ir" (bit));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2016-03-03 04:28:09 +08:00
|
|
|
int sys_test_and_set_bit(mem_addr_t addr, unsigned int bit)
|
2015-08-21 17:50:57 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
__asm__ volatile("btsl %2, %1;\n\t"
|
|
|
|
"sbb %0, %0\n\t"
|
2017-04-21 23:55:34 +08:00
|
|
|
: "=r" (ret), "+m" (*(volatile u32_t *) (addr))
|
2015-08-21 17:50:57 +08:00
|
|
|
: "Ir" (bit));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-15 09:35:13 +08:00
|
|
|
static ALWAYS_INLINE
|
2016-03-03 04:28:09 +08:00
|
|
|
int sys_test_and_clear_bit(mem_addr_t addr, unsigned int bit)
|
2015-08-21 17:50:57 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
__asm__ volatile("btrl %2, %1;\n\t"
|
|
|
|
"sbb %0, %0\n\t"
|
2017-04-21 23:55:34 +08:00
|
|
|
: "=r" (ret), "+m" (*(volatile u32_t *) (addr))
|
2015-08-21 17:50:57 +08:00
|
|
|
: "Ir" (bit));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-01 05:05:55 +08:00
|
|
|
#define sys_bitfield_set_bit sys_set_bit
|
|
|
|
#define sys_bitfield_clear_bit sys_clear_bit
|
|
|
|
#define sys_bitfield_test_bit sys_test_bit
|
|
|
|
#define sys_bitfield_test_and_set_bit sys_test_and_set_bit
|
|
|
|
#define sys_bitfield_test_and_clear_bit sys_test_and_clear_bit
|
2016-03-03 02:36:17 +08:00
|
|
|
|
2015-04-28 01:40:11 +08:00
|
|
|
#endif /* _ASMLANGUAGE */
|
2016-01-23 01:38:49 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-09-15 01:43:44 +08:00
|
|
|
#endif /* ZEPHYR_INCLUDE_ARCH_X86_ASM_INLINE_GCC_H_ */
|