OR1K support
 All Functions Typedefs Groups
or1k-asm.h
1 /* or1k-asm.h -- OR1K assembly helper macros
2 
3  Copyright (c) 2014 OpenRISC Project Maintainers
4  Copyright (C) 2012-2014 Peter Gavin <pgavin@gmail.com>
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without
8  modification, are permitted provided that the following condition
9  is met:
10 
11  1. Redistributions of source code must retain the above copyright
12  notice, this list of conditions and the following disclaimer.
13 
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
17  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
18  COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
19  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
25  OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27  */
28 
29 #ifndef OR1K_ASM_H
30 #define OR1K_ASM_H
31 
32 /* The purpose of the OR1K_INST macro is simply to protect the commas
33  embedded within an instruction from the C preprocessor. An entire
34  instruction can be safely embedded within its arguments, including
35  an arbitrary number of commas, and it will be reproduced
36  exactly. */
37 #define OR1K_INST(...) __VA_ARGS__
38 
39 /* OR1K_DELAYED takes two arguments which must be instructions. They
40  should be wrapped in OR1K_INST if the instructions require commas.
41  The second argument should be a jump or branch instruction. If we
42  are assembling the code in delay-slot mode (e.g., for the standard
43  OR1K) the first instruction will be emitted in the delay slot of
44  the second instruction. In no-delay-slot mode they will be emitted
45  in order. If we are using compat-delay mode, they will be emitted
46  in order, but an l.nop instruction will be emitted immediately
47  after. */
48 
49 /* OR1K_DELAYED_NOP takes a single argument, which should be a
50  branch/jump instruction. In delay-slot or compat-delay modes, the
51  instruction will be emitted with an l.nop in its delay slot. In
52  no-delay mode, the instruction will be emitted by itself. */
53 
54 #if defined(__OR1K_NODELAY__)
55 
56 #define OR1K_DELAYED(a, b) a; b
57 #define OR1K_DELAYED_NOP(a) a
58 
59 /* Go ahead and emit the .nodelay directive when in no-delay mode, so
60  that the flags are appropriately set in the binary. */
61 .nodelay
62 
63 #elif defined(__OR1K_DELAY__)
64 
65 #define OR1K_DELAYED(a, b) b; a
66 #define OR1K_DELAYED_NOP(a) a; l.nop
67 
68 #elif defined(__OR1K_DELAY_COMPAT__)
69 
70 #define OR1K_DELAYED(a, b) a; b; l.nop
71 #define OR1K_DELAYED_NOP(a) a; l.nop
72 
73 #else
74 
75 #error One of __OR1K_NODELAY__, __OR1K_DELAY__, or __OR1K_DELAY_COMPAT__ must be defined
76 
77 #endif
78 
79 #define LOAD_SYMBOL_2_GPR(gpr,symbol) \
80  .global symbol ; \
81  l.movhi gpr, hi(symbol) ; \
82  l.ori gpr, gpr, lo(symbol)
83 #endif