Subversion Repositories HelenOS

Rev

Rev 3022 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3022 Rev 4055
Line 34... Line 34...
34
 
34
 
35
#ifndef KERN_ia64_ASM_H_
35
#ifndef KERN_ia64_ASM_H_
36
#define KERN_ia64_ASM_H_
36
#define KERN_ia64_ASM_H_
37
 
37
 
38
#include <config.h>
38
#include <config.h>
-
 
39
#include <typedefs.h>
39
#include <arch/types.h>
40
#include <arch/types.h>
40
#include <arch/register.h>
41
#include <arch/register.h>
41
 
42
 
42
 
-
 
43
#define IA64_IOSPACE_ADDRESS 0xE001000000000000ULL
43
#define IA64_IOSPACE_ADDRESS 0xE001000000000000ULL
44
 
44
 
45
static inline void  outb(uint64_t port,uint8_t v)
45
static inline void pio_write_8(ioport8_t *port, uint8_t v)
46
{
46
{
-
 
47
    uintptr_t prt = (uintptr_t) port;
-
 
48
 
-
 
49
    *((uint8_t *)(IA64_IOSPACE_ADDRESS +
47
    *((char *)(IA64_IOSPACE_ADDRESS + ( (port & 0xfff) | ( (port >> 2) << 12 )))) = v;
50
        ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
48
 
51
 
49
    asm volatile ("mf\n" ::: "memory");
52
    asm volatile ("mf\n" ::: "memory");
50
}
53
}
51
 
54
 
-
 
55
static inline void pio_write_16(ioport16_t *port, uint16_t v)
-
 
56
{
-
 
57
    uintptr_t prt = (uintptr_t) port;
-
 
58
 
-
 
59
    *((uint16_t *)(IA64_IOSPACE_ADDRESS +
-
 
60
        ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
-
 
61
 
-
 
62
    asm volatile ("mf\n" ::: "memory");
-
 
63
}
-
 
64
 
-
 
65
static inline void pio_write_32(ioport32_t *port, uint32_t v)
-
 
66
{
-
 
67
    uintptr_t prt = (uintptr_t) port;
-
 
68
 
-
 
69
    *((uint32_t *)(IA64_IOSPACE_ADDRESS +
-
 
70
        ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
-
 
71
 
-
 
72
    asm volatile ("mf\n" ::: "memory");
-
 
73
}
-
 
74
 
-
 
75
static inline uint8_t pio_read_8(ioport8_t *port)
-
 
76
{
-
 
77
    uintptr_t prt = (uintptr_t) port;
-
 
78
 
-
 
79
    asm volatile ("mf\n" ::: "memory");
-
 
80
 
-
 
81
    return *((uint8_t *)(IA64_IOSPACE_ADDRESS +
-
 
82
        ((prt & 0xfff) | ((prt >> 2) << 12))));
-
 
83
}
52
 
84
 
53
static inline uint8_t inb(uint64_t port)
85
static inline uint16_t pio_read_16(ioport16_t *port)
54
{
86
{
-
 
87
    uintptr_t prt = (uintptr_t) port;
-
 
88
 
55
    asm volatile ("mf\n" ::: "memory");
89
    asm volatile ("mf\n" ::: "memory");
56
 
90
 
-
 
91
    return *((uint16_t *)(IA64_IOSPACE_ADDRESS +
57
    return *((char *)(IA64_IOSPACE_ADDRESS + ( (port & 0xfff) | ( (port >> 2) << 12 ))));
92
        ((prt & 0xfff) | ((prt >> 2) << 12))));
58
}
93
}
59
 
94
 
-
 
95
static inline uint32_t pio_read_32(ioport32_t *port)
-
 
96
{
-
 
97
    uintptr_t prt = (uintptr_t) port;
60
 
98
 
-
 
99
    asm volatile ("mf\n" ::: "memory");
-
 
100
 
-
 
101
    return *((uint32_t *)(IA64_IOSPACE_ADDRESS +
-
 
102
        ((prt & 0xfff) | ((prt >> 2) << 12))));
-
 
103
}
61
 
104
 
62
/** Return base address of current stack
105
/** Return base address of current stack
63
 *
106
 *
64
 * Return the base address of the current stack.
107
 * Return the base address of the current stack.
65
 * The stack is assumed to be STACK_SIZE long.
108
 * The stack is assumed to be STACK_SIZE long.
Line 67... Line 110...
67
 */
110
 */
68
static inline uintptr_t get_stack_base(void)
111
static inline uintptr_t get_stack_base(void)
69
{
112
{
70
    uint64_t v;
113
    uint64_t v;
71
 
114
 
-
 
115
    //I'm not sure why but this code bad inlines in scheduler, 
-
 
116
    //so THE shifts about 16B and causes kernel panic
72
    asm volatile ("and %0 = %1, r12" : "=r" (v) : "r" (~(STACK_SIZE-1)));
117
    //asm volatile ("and %0 = %1, r12" : "=r" (v) : "r" (~(STACK_SIZE-1)));
-
 
118
    //return v;
73
   
119
   
-
 
120
    //this code have the same meaning but inlines well
-
 
121
    asm volatile ("mov %0 = r12" : "=r" (v)  );
74
    return v;
122
    return v & (~(STACK_SIZE-1));
75
}
123
}
76
 
124
 
77
/** Return Processor State Register.
125
/** Return Processor State Register.
78
 *
126
 *
79
 * @return PSR.
127
 * @return PSR.
Line 121... Line 169...
121
    asm volatile ("mov %0 = cr.ivr\n" : "=r" (v));
169
    asm volatile ("mov %0 = cr.ivr\n" : "=r" (v));
122
   
170
   
123
    return v;
171
    return v;
124
}
172
}
125
 
173
 
-
 
174
static inline uint64_t cr64_read(void)
-
 
175
{
-
 
176
    uint64_t v;
-
 
177
   
-
 
178
    asm volatile ("mov %0 = cr64\n" : "=r" (v));
-
 
179
   
-
 
180
    return v;
-
 
181
}
-
 
182
 
-
 
183
 
126
/** Write ITC (Interval Timer Counter) register.
184
/** Write ITC (Interval Timer Counter) register.
127
 *
185
 *
128
 * @param v New counter value.
186
 * @param v New counter value.
129
 */
187
 */
130
static inline void itc_write(uint64_t v)
188
static inline void itc_write(uint64_t v)
Line 295... Line 353...
295
 
353
 
296
extern void cpu_halt(void);
354
extern void cpu_halt(void);
297
extern void cpu_sleep(void);
355
extern void cpu_sleep(void);
298
extern void asm_delay_loop(uint32_t t);
356
extern void asm_delay_loop(uint32_t t);
299
 
357
 
300
extern void switch_to_userspace(uintptr_t entry, uintptr_t sp, uintptr_t bsp, uintptr_t uspace_uarg, uint64_t ipsr, uint64_t rsc);
358
extern void switch_to_userspace(uintptr_t, uintptr_t, uintptr_t, uintptr_t,
-
 
359
    uint64_t, uint64_t);
301
 
360
 
302
#endif
361
#endif
303
 
362
 
304
/** @}
363
/** @}
305
 */
364
 */