Subversion Repositories HelenOS

Rev

Rev 2071 | Rev 4342 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
173 jermar 1
/*
2071 jermar 2
 * Copyright (c) 2005 Martin Decky
173 jermar 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
 
1888 jermar 29
/** @addtogroup ppc32  
1702 cejka 30
 * @{
31
 */
32
/** @file
33
 */
34
 
1888 jermar 35
#ifndef KERN_ppc32_ASM_H_
36
#define KERN_ppc32_ASM_H_
173 jermar 37
 
38
#include <arch/types.h>
39
#include <config.h>
40
 
413 jermar 41
/** Enable interrupts.
191 decky 42
 *
43
 * Enable interrupts and return previous
44
 * value of EE.
413 jermar 45
 *
46
 * @return Old interrupt priority level.
191 decky 47
 */
1283 decky 48
static inline ipl_t interrupts_enable(void)
49
{
1268 decky 50
    ipl_t v;
413 jermar 51
    ipl_t tmp;
254 decky 52
 
1267 decky 53
    asm volatile (
204 decky 54
        "mfmsr %0\n"
254 decky 55
        "mfmsr %1\n"
987 decky 56
        "ori %1, %1, 1 << 15\n"
254 decky 57
        "mtmsr %1\n"
58
        : "=r" (v), "=r" (tmp)
191 decky 59
    );
60
    return v;
61
}
62
 
413 jermar 63
/** Disable interrupts.
191 decky 64
 *
65
 * Disable interrupts and return previous
66
 * value of EE.
413 jermar 67
 *
68
 * @return Old interrupt priority level.
191 decky 69
 */
1283 decky 70
static inline ipl_t interrupts_disable(void)
71
{
413 jermar 72
    ipl_t v;
73
    ipl_t tmp;
254 decky 74
 
1267 decky 75
    asm volatile (
204 decky 76
        "mfmsr %0\n"
254 decky 77
        "mfmsr %1\n"
78
        "rlwinm %1, %1, 0, 17, 15\n"
79
        "mtmsr %1\n"
80
        : "=r" (v), "=r" (tmp)
191 decky 81
    );
82
    return v;
83
}
84
 
413 jermar 85
/** Restore interrupt priority level.
191 decky 86
 *
87
 * Restore EE.
413 jermar 88
 *
89
 * @param ipl Saved interrupt priority level.
191 decky 90
 */
1283 decky 91
static inline void interrupts_restore(ipl_t ipl)
92
{
413 jermar 93
    ipl_t tmp;
254 decky 94
 
1267 decky 95
    asm volatile (
254 decky 96
        "mfmsr %1\n"
97
        "rlwimi  %0, %1, 0, 17, 15\n"
98
        "cmpw 0, %0, %1\n"
210 decky 99
        "beq 0f\n"
204 decky 100
        "mtmsr %0\n"
210 decky 101
        "0:\n"
413 jermar 102
        : "=r" (ipl), "=r" (tmp)
103
        : "0" (ipl)
1283 decky 104
        : "cr0"
191 decky 105
    );
106
}
107
 
413 jermar 108
/** Return interrupt priority level.
210 decky 109
 *
110
 * Return EE.
413 jermar 111
 *
112
 * @return Current interrupt priority level.
210 decky 113
 */
1283 decky 114
static inline ipl_t interrupts_read(void)
115
{
413 jermar 116
    ipl_t v;
1267 decky 117
 
118
    asm volatile (
210 decky 119
        "mfmsr %0\n"
120
        : "=r" (v)
121
    );
122
    return v;
123
}
124
 
253 jermar 125
/** Return base address of current stack.
126
 *
127
 * Return the base address of the current stack.
128
 * The stack is assumed to be STACK_SIZE bytes long.
129
 * The stack must start on page boundary.
130
 */
1780 jermar 131
static inline uintptr_t get_stack_base(void)
173 jermar 132
{
1780 jermar 133
    uintptr_t v;
253 jermar 134
 
1267 decky 135
    asm volatile (
136
        "and %0, %%sp, %1\n"
137
        : "=r" (v)
138
        : "r" (~(STACK_SIZE - 1))
139
    );
253 jermar 140
    return v;
173 jermar 141
}
142
 
1007 decky 143
static inline void cpu_sleep(void)
144
{
145
}
146
 
254 decky 147
void cpu_halt(void);
1780 jermar 148
void asm_delay_loop(uint32_t t);
201 decky 149
 
1780 jermar 150
extern void userspace_asm(uintptr_t uspace_uarg, uintptr_t stack, uintptr_t entry);
1220 decky 151
 
173 jermar 152
#endif
1702 cejka 153
 
1888 jermar 154
/** @}
1702 cejka 155
 */