1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 by Jens Arnold
11 * Based on the work of Alan Korr and others
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
22 #ifndef SYSTEM_TARGET_H
23 #define SYSTEM_TARGET_H
25 #define or_b(mask, address) \
27 ("or.b %0,@(r0,gbr)" \
29 : /* %0 */ I_CONSTRAINT((char)(mask)), \
30 /* %1 */ "z"(address-GBR))
32 #define and_b(mask, address) \
34 ("and.b %0,@(r0,gbr)" \
36 : /* %0 */ I_CONSTRAINT((char)(mask)), \
37 /* %1 */ "z"(address-GBR))
39 #define xor_b(mask, address) \
41 ("xor.b %0,@(r0,gbr)" \
43 : /* %0 */ I_CONSTRAINT((char)(mask)), \
44 /* %1 */ "z"(address-GBR))
47 /****************************************************************************
48 * Interrupt level setting
49 * The level is left shifted 4 bits
50 ****************************************************************************/
51 #define HIGHEST_IRQ_LEVEL (15<<4)
53 static inline int set_irq_level(int level
)
56 /* Read the old level and set the new one */
58 /* Not volatile - will be optimized away if the return value isn't used */
59 asm ("stc sr, %0" : "=r" (i
));
60 asm volatile ("ldc %0, sr" : : "r" (level
));
64 static inline void enable_irq(void)
67 asm volatile ("mov %1, %0 \n" /* Save a constant load from RAM */
68 "ldc %0, sr \n" : "=&r"(i
) : "i"(0));
71 #define disable_irq() \
72 ((void)set_irq_level(HIGHEST_IRQ_LEVEL))
74 #define disable_irq_save() \
75 set_irq_level(HIGHEST_IRQ_LEVEL)
77 #define restore_irq(i) \
78 ((void)set_irq_level(i))
80 static inline uint16_t swap16(uint16_t value
)
82 result[15..8] = value[ 7..0];
83 result[ 7..0] = value[15..8];
87 asm volatile ("swap.b\t%1,%0" : "=r"(result
) : "r"(value
));
91 static inline uint32_t SWAW32(uint32_t value
)
93 result[31..16] = value[15.. 0];
94 result[15.. 0] = value[31..16];
98 asm volatile ("swap.w\t%1,%0" : "=r"(result
) : "r"(value
));
102 static inline uint32_t swap32(uint32_t value
)
104 result[31..24] = value[ 7.. 0];
105 result[23..16] = value[15.. 8];
106 result[15.. 8] = value[23..16];
107 result[ 7.. 0] = value[31..24];
110 asm volatile ("swap.b\t%0,%0\n"
112 "swap.b\t%0,%0\n" : "+r"(value
));
116 static inline uint32_t swap_odd_even32(uint32_t value
)
119 result[31..24],[15.. 8] = value[23..16],[ 7.. 0]
120 result[23..16],[ 7.. 0] = value[31..24],[15.. 8]
122 asm volatile ("swap.b\t%0,%0\n"
125 "swap.w\t%0,%0\n" : "+r"(value
));
129 extern const unsigned bit_n_table
[32];
131 __builtin_constant_p(n) \
136 #endif /* SYSTEM_TARGET_H */