~bengal/helenos/openrisc

« back to all changes in this revision

Viewing changes to kernel/arch/or32/include/arch/asm.h

  • Committer: Beniamino Galvani
  • Date: 2013-12-01 21:14:39 UTC
  • Revision ID: b.galvani@gmail.com-20131201211439-17md1iweu6gas14u
Add support for OpenRISC

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2013 Beniamino Galvani
 
3
 * All rights reserved.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
8
 *
 
9
 * - Redistributions of source code must retain the above copyright
 
10
 *   notice, this list of conditions and the following disclaimer.
 
11
 * - Redistributions in binary form must reproduce the above copyright
 
12
 *   notice, this list of conditions and the following disclaimer in the
 
13
 *   documentation and/or other materials provided with the distribution.
 
14
 * - The name of the author may not be used to endorse or promote products
 
15
 *   derived from this software without specific prior written permission.
 
16
 *
 
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
27
 */
 
28
 
 
29
/** @addtogroup or32
 
30
 * @{
 
31
 */
 
32
/** @file
 
33
 */
 
34
 
 
35
#ifndef KERN_or32_ASM_H_
 
36
#define KERN_or32_ASM_H_
 
37
 
 
38
#include <typedefs.h>
 
39
#include <config.h>
 
40
#include <arch/spr.h>
 
41
#include <trace.h>
 
42
 
 
43
#define SR_INT_MASK (SPR_SR_IEE | SPR_SR_TEE)
 
44
 
 
45
NO_TRACE static inline void asm_delay_loop(uint32_t usec)
 
46
{
 
47
}
 
48
 
 
49
NO_TRACE static inline __attribute__((noreturn)) void cpu_halt(void)
 
50
{
 
51
        /* On real hardware this should stop processing further
 
52
           instructions on the CPU (and possibly putting it into
 
53
           low-power mode) without any possibility of exitting
 
54
           this function. */
 
55
 
 
56
        while (true);
 
57
}
 
58
 
 
59
NO_TRACE static inline void cpu_sleep(void)
 
60
{
 
61
        /* On real hardware this should put the CPU into low-power
 
62
           mode. However, the CPU is free to continue processing
 
63
           futher instructions any time. The CPU also wakes up
 
64
           upon an interrupt. */
 
65
}
 
66
 
 
67
NO_TRACE static inline void pio_write_8(ioport8_t *port, uint8_t val)
 
68
{
 
69
        *port = val;
 
70
}
 
71
 
 
72
/** Word to port
 
73
 *
 
74
 * Output word to port
 
75
 *
 
76
 * @param port Port to write to
 
77
 * @param val Value to write
 
78
 *
 
79
 */
 
80
NO_TRACE static inline void pio_write_16(ioport16_t *port, uint16_t val)
 
81
{
 
82
        *port = val;
 
83
}
 
84
 
 
85
/** Double word to port
 
86
 *
 
87
 * Output double word to port
 
88
 *
 
89
 * @param port Port to write to
 
90
 * @param val Value to write
 
91
 *
 
92
 */
 
93
NO_TRACE static inline void pio_write_32(ioport32_t *port, uint32_t val)
 
94
{
 
95
        *port = val;
 
96
}
 
97
 
 
98
/** Byte from port
 
99
 *
 
100
 * Get byte from port
 
101
 *
 
102
 * @param port Port to read from
 
103
 * @return Value read
 
104
 *
 
105
 */
 
106
NO_TRACE static inline uint8_t pio_read_8(ioport8_t *port)
 
107
{
 
108
        return *port;
 
109
}
 
110
 
 
111
/** Word from port
 
112
 *
 
113
 * Get word from port
 
114
 *
 
115
 * @param port Port to read from
 
116
 * @return Value read
 
117
 *
 
118
 */
 
119
NO_TRACE static inline uint16_t pio_read_16(ioport16_t *port)
 
120
{
 
121
        return *port;
 
122
}
 
123
 
 
124
/** Double word from port
 
125
 *
 
126
 * Get double word from port
 
127
 *
 
128
 * @param port Port to read from
 
129
 * @return Value read
 
130
 *
 
131
 */
 
132
NO_TRACE static inline uint32_t pio_read_32(ioport32_t *port)
 
133
{
 
134
        return *port;
 
135
}
 
136
 
 
137
NO_TRACE static inline ipl_t interrupts_enable(void)
 
138
{
 
139
        ipl_t ipl = (ipl_t) spr_sr_read();
 
140
        spr_sr_write(ipl | SR_INT_MASK);
 
141
        return ipl;
 
142
}
 
143
 
 
144
NO_TRACE static inline ipl_t interrupts_disable(void)
 
145
{
 
146
        ipl_t ipl = (ipl_t) spr_sr_read();
 
147
        spr_sr_write(ipl & ~SR_INT_MASK);
 
148
        return ipl;
 
149
}
 
150
 
 
151
NO_TRACE static inline void interrupts_restore(ipl_t ipl)
 
152
{
 
153
        spr_sr_write((spr_sr_read() & ~SR_INT_MASK) | (ipl & SR_INT_MASK));
 
154
}
 
155
 
 
156
NO_TRACE static inline ipl_t interrupts_read(void)
 
157
{
 
158
        return spr_sr_read();
 
159
}
 
160
 
 
161
NO_TRACE static inline bool interrupts_disabled(void)
 
162
{
 
163
        return !(spr_sr_read() & SR_INT_MASK);
 
164
}
 
165
 
 
166
NO_TRACE static inline uintptr_t get_stack_base(void)
 
167
{
 
168
        uintptr_t base;
 
169
 
 
170
        asm volatile (
 
171
                "l.and %[base], r1, %[mask]\n"
 
172
                : [base] "=r" (base)
 
173
                : [mask] "r" (~(STACK_SIZE - 1))
 
174
        );
 
175
 
 
176
        return base;
 
177
}
 
178
 
 
179
#endif
 
180
 
 
181
/** @}
 
182
 */