source:
rtems/cpukit/score/inline/rtems/score/address.inl
@
d8dbdc0
Last change on this file since d8dbdc0 was d6154c7, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/29/04 at 16:41:13 | |
---|---|
|
|
File size: 2.7 KB |
Line | |
---|---|
1 | /* inline/address.inl |
2 | * |
3 | * This include file contains the bodies of the routines |
4 | * about addresses which are inlined. |
5 | * |
6 | * COPYRIGHT (c) 1989-1999. |
7 | * On-Line Applications Research Corporation (OAR). |
8 | * |
9 | * The license and distribution terms for this file may be |
10 | * found in the file LICENSE in this distribution or at |
11 | * http://www.rtems.com/license/LICENSE. |
12 | * |
13 | * $Id$ |
14 | */ |
15 | |
16 | #ifndef __INLINE_ADDRESSES_inl |
17 | #define __INLINE_ADDRESSES_inl |
18 | |
19 | /*PAGE |
20 | * |
21 | * _Addresses_Add_offset |
22 | * |
23 | * DESCRIPTION: |
24 | * |
25 | * This function is used to add an offset to a base address. |
26 | * It returns the resulting address. This address is typically |
27 | * converted to an access type before being used further. |
28 | */ |
29 | |
30 | RTEMS_INLINE_ROUTINE void *_Addresses_Add_offset ( |
31 | void *base, |
32 | uint32_t offset |
33 | ) |
34 | { |
35 | return (void *)((char *)base + offset); |
36 | } |
37 | |
38 | /*PAGE |
39 | * |
40 | * _Addresses_Subtract_offset |
41 | * |
42 | * DESCRIPTION: |
43 | * |
44 | * This function is used to subtract an offset from a base |
45 | * address. It returns the resulting address. This address is |
46 | * typically converted to an access type before being used further. |
47 | */ |
48 | |
49 | RTEMS_INLINE_ROUTINE void *_Addresses_Subtract_offset ( |
50 | void *base, |
51 | uint32_t offset |
52 | ) |
53 | { |
54 | return (void *)((char *)base - offset); |
55 | } |
56 | |
57 | /*PAGE |
58 | * |
59 | * _Addresses_Subtract |
60 | * |
61 | * DESCRIPTION: |
62 | * |
63 | * This function is used to subtract two addresses. It returns the |
64 | * resulting offset. |
65 | * |
66 | * NOTE: The cast of an address to an uint32_t makes this code |
67 | * dependent on an addresses being thirty two bits. |
68 | */ |
69 | |
70 | RTEMS_INLINE_ROUTINE uint32_t _Addresses_Subtract ( |
71 | void *left, |
72 | void *right |
73 | ) |
74 | { |
75 | return ((char *) left - (char *) right); |
76 | } |
77 | |
78 | /*PAGE |
79 | * |
80 | * _Addresses_Is_aligned |
81 | * |
82 | * DESCRIPTION: |
83 | * |
84 | * This function returns TRUE if the given address is correctly |
85 | * aligned for this processor and FALSE otherwise. Proper alignment |
86 | * is based on correctness and efficiency. |
87 | */ |
88 | |
89 | RTEMS_INLINE_ROUTINE boolean _Addresses_Is_aligned ( |
90 | void *address |
91 | ) |
92 | { |
93 | #if (CPU_ALIGNMENT == 0) |
94 | return TRUE; |
95 | #elif defined(RTEMS_CPU_HAS_16_BIT_ADDRESSES) |
96 | return ( ( (unsigned short)address % CPU_ALIGNMENT ) == 0 ); |
97 | #else |
98 | return ( ( (uint32_t )address % CPU_ALIGNMENT ) == 0 ); |
99 | #endif |
100 | } |
101 | |
102 | /*PAGE |
103 | * |
104 | * _Addresses_Is_in_range |
105 | * |
106 | * DESCRIPTION: |
107 | * |
108 | * This function returns TRUE if the given address is within the |
109 | * memory range specified and FALSE otherwise. base is the address |
110 | * of the first byte in the memory range and limit is the address |
111 | * of the last byte in the memory range. The base address is |
112 | * assumed to be lower than the limit address. |
113 | */ |
114 | |
115 | RTEMS_INLINE_ROUTINE boolean _Addresses_Is_in_range ( |
116 | void *address, |
117 | void *base, |
118 | void *limit |
119 | ) |
120 | { |
121 | return ( address >= base && address <= limit ); |
122 | } |
123 | |
124 | #endif |
125 | /* end of include file */ |
Note: See TracBrowser
for help on using the repository browser.