]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4sys/include/ARCH-arm/mem_op.h
87dbedd0c2f36ee56c15880b3a71ce88e4daf617
[l4.git] / l4 / pkg / l4sys / include / ARCH-arm / mem_op.h
1 /**
2  * \file
3  * \brief  Memory access functions (ARM specific)
4  *
5  * \date   2010-10
6  * \author Adam Lackorzynski <adam@os.inf.tu-dresden.de>
7  *
8  */
9 /*
10  * (c) 2010 Author(s)
11  *     economic rights: Technische Universität Dresden (Germany)
12  *
13  * This file is part of TUD:OS and distributed under the terms of the
14  * GNU General Public License 2.
15  * Please see the COPYING-GPL-2 file for details.
16  *
17  * As a special exception, you may use this file as part of a free software
18  * library without restriction.  Specifically, if other files instantiate
19  * templates or use macros or inline functions from this file, or you compile
20  * this file and link it with other files to produce an executable, this
21  * file does not by itself cause the resulting executable to be covered by
22  * the GNU General Public License.  This exception does not however
23  * invalidate any other reasons why the executable file might be covered by
24  * the GNU General Public License.
25  */
26 #ifndef __L4SYS__INCLUDE__ARCH_ARM__MEM_OP_H__
27 #define __L4SYS__INCLUDE__ARCH_ARM__MEM_OP_H__
28
29 #include <l4/sys/compiler.h>
30 #include <l4/sys/syscall_defs.h>
31
32 /**
33  * \brief Read memory from kernel privilege level.
34  * \param virtaddress  Virtual address in the calling task.
35  * \param width        Width of access in bytes in log2
36  *                       (i.e. allowed values: 0, 1, 2)
37  * \return Read value.
38  *
39  * Upon an given invalid address or invalid width value the function does
40  * nothing.
41  */
42 L4_INLINE unsigned long
43 l4_mem_read(unsigned long virtaddress, unsigned width);
44
45 /**
46  * \brief Write memory from kernel privilege level.
47  * \param virtaddress  Virtual address in the calling task.
48  * \param width        Width of access in bytes in log2
49  *                       (i.e. allowed values: 0, 1, 2)
50  * \param value        Value to write.
51  *
52  * Upon an given invalid address or invalid width value the function does
53  * nothing.
54  */
55 L4_INLINE void
56 l4_mem_write(unsigned long virtaddress, unsigned width,
57              unsigned long value);
58
59 enum L4_mem_ops
60 {
61   L4_MEM_OP_MEM_READ  = 0x10,
62   L4_MEM_OP_MEM_WRITE = 0x11,
63 };
64
65 /**
66  * \internal
67  */
68 L4_INLINE unsigned long
69 l4_mem_arm_op_call(unsigned long op,
70                    unsigned long va,
71                    unsigned long width,
72                    unsigned long value);
73
74 /** Implementations */
75
76 L4_INLINE unsigned long
77 l4_mem_arm_op_call(unsigned long op,
78                    unsigned long va,
79                    unsigned long width,
80                    unsigned long value)
81 {
82   register unsigned long _op    asm ("r0") = op;
83   register unsigned long _va    asm ("r1") = va;
84   register unsigned long _width asm ("r2") = width;
85   register unsigned long _value asm ("r3") = value;
86
87   __asm__ __volatile__
88     ("@ l4_cache_op_arm_call(start) \n\t"
89      "mov     lr, pc                \n\t"
90      "mov     pc, %[sc]             \n\t"
91      "@ l4_cache_op_arm_call(end)   \n\t"
92        :
93         "=r" (_op),
94         "=r" (_va),
95         "=r" (_width),
96         "=r" (_value)
97        :
98        [sc] "i" (L4_SYSCALL_MEM_OP),
99         "0" (_op),
100         "1" (_va),
101         "2" (_width),
102         "3" (_value)
103        :
104         "cc", "memory", "lr"
105        );
106
107   return _value;
108 }
109
110 L4_INLINE unsigned long
111 l4_mem_read(unsigned long virtaddress, unsigned width)
112 {
113   return l4_mem_arm_op_call(L4_MEM_OP_MEM_READ, virtaddress, width, 0);
114 }
115
116 L4_INLINE void
117 l4_mem_write(unsigned long virtaddress, unsigned width,
118              unsigned long value)
119 {
120   l4_mem_arm_op_call(L4_MEM_OP_MEM_WRITE, virtaddress, width, value);
121 }
122
123 #endif /* ! __L4SYS__INCLUDE__ARCH_ARM__MEM_OP_H__ */