[f761f1eb] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2003-2004 Jakub Jermar
|
---|
[f761f1eb] | 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 |
|
---|
[1bb2e7a] | 29 | /** @addtogroup mips32
|
---|
[b45c443] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[06e1e95] | 35 | #ifndef KERN_mips32_CP0_H_
|
---|
| 36 | #define KERN_mips32_CP0_H_
|
---|
[f761f1eb] | 37 |
|
---|
[d92bf462] | 38 | #define cp0_status_ie_enabled_bit (1 << 0)
|
---|
| 39 | #define cp0_status_exl_exception_bit (1 << 1)
|
---|
| 40 | #define cp0_status_erl_error_bit (1 << 2)
|
---|
| 41 | #define cp0_status_um_bit (1 << 4)
|
---|
| 42 | #define cp0_status_bev_bootstrap_bit (1 << 22)
|
---|
| 43 | #define cp0_status_fpu_bit (1 << 29)
|
---|
[f761f1eb] | 44 |
|
---|
[c0699467] | 45 | #define cp0_status_im_shift 8
|
---|
| 46 | #define cp0_status_im_mask 0xff00
|
---|
[24241cf] | 47 |
|
---|
[c0699467] | 48 | #define cp0_cause_excno(cause) ((cause >> 2) & 0x1f)
|
---|
| 49 | #define cp0_cause_coperr(cause) ((cause >> 28) & 0x3)
|
---|
[a1493d9] | 50 |
|
---|
[c0699467] | 51 | #define fpu_cop_id 1
|
---|
[a1493d9] | 52 |
|
---|
[f761f1eb] | 53 | /*
|
---|
| 54 | * Magic value for use in msim.
|
---|
| 55 | */
|
---|
[c0699467] | 56 | #define cp0_compare_value 100000
|
---|
| 57 |
|
---|
| 58 | #define cp0_mask_all_int() \
|
---|
| 59 | cp0_status_write(cp0_status_read() & ~(cp0_status_im_mask))
|
---|
| 60 |
|
---|
| 61 | #define cp0_unmask_all_int() \
|
---|
| 62 | cp0_status_write(cp0_status_read() | cp0_status_im_mask)
|
---|
| 63 |
|
---|
| 64 | #define cp0_mask_int(it) \
|
---|
| 65 | cp0_status_write(cp0_status_read() & ~(1 << (cp0_status_im_shift + (it))))
|
---|
| 66 |
|
---|
| 67 | #define cp0_unmask_int(it) \
|
---|
| 68 | cp0_status_write(cp0_status_read() | (1 << (cp0_status_im_shift + (it))))
|
---|
| 69 |
|
---|
| 70 | #define GEN_READ_CP0(nm, reg) \
|
---|
| 71 | static inline uint32_t cp0_ ##nm##_read(void) \
|
---|
| 72 | { \
|
---|
| 73 | uint32_t retval; \
|
---|
| 74 | \
|
---|
| 75 | asm volatile ( \
|
---|
| 76 | "mfc0 %0, $" #reg \
|
---|
| 77 | : "=r"(retval) \
|
---|
| 78 | ); \
|
---|
| 79 | \
|
---|
| 80 | return retval; \
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | #define GEN_WRITE_CP0(nm, reg) \
|
---|
| 84 | static inline void cp0_ ##nm##_write(uint32_t val) \
|
---|
| 85 | { \
|
---|
| 86 | asm volatile ( \
|
---|
| 87 | "mtc0 %0, $" #reg \
|
---|
| 88 | :: "r"(val) \
|
---|
| 89 | ); \
|
---|
| 90 | }
|
---|
[f761f1eb] | 91 |
|
---|
[1b109cb] | 92 | GEN_READ_CP0(index, 0);
|
---|
| 93 | GEN_WRITE_CP0(index, 0);
|
---|
[f761f1eb] | 94 |
|
---|
[1b109cb] | 95 | GEN_READ_CP0(random, 1);
|
---|
[f761f1eb] | 96 |
|
---|
[1b109cb] | 97 | GEN_READ_CP0(entry_lo0, 2);
|
---|
| 98 | GEN_WRITE_CP0(entry_lo0, 2);
|
---|
[f761f1eb] | 99 |
|
---|
[1b109cb] | 100 | GEN_READ_CP0(entry_lo1, 3);
|
---|
| 101 | GEN_WRITE_CP0(entry_lo1, 3);
|
---|
[f761f1eb] | 102 |
|
---|
[1b109cb] | 103 | GEN_READ_CP0(context, 4);
|
---|
| 104 | GEN_WRITE_CP0(context, 4);
|
---|
[f761f1eb] | 105 |
|
---|
[1b109cb] | 106 | GEN_READ_CP0(pagemask, 5);
|
---|
| 107 | GEN_WRITE_CP0(pagemask, 5);
|
---|
[f761f1eb] | 108 |
|
---|
[1b109cb] | 109 | GEN_READ_CP0(wired, 6);
|
---|
| 110 | GEN_WRITE_CP0(wired, 6);
|
---|
[f761f1eb] | 111 |
|
---|
[1b109cb] | 112 | GEN_READ_CP0(badvaddr, 8);
|
---|
[f761f1eb] | 113 |
|
---|
[1b109cb] | 114 | GEN_READ_CP0(count, 9);
|
---|
| 115 | GEN_WRITE_CP0(count, 9);
|
---|
[f761f1eb] | 116 |
|
---|
[1b109cb] | 117 | GEN_READ_CP0(entry_hi, 10);
|
---|
| 118 | GEN_WRITE_CP0(entry_hi, 10);
|
---|
[f761f1eb] | 119 |
|
---|
[1b109cb] | 120 | GEN_READ_CP0(compare, 11);
|
---|
| 121 | GEN_WRITE_CP0(compare, 11);
|
---|
[f761f1eb] | 122 |
|
---|
[1b109cb] | 123 | GEN_READ_CP0(status, 12);
|
---|
| 124 | GEN_WRITE_CP0(status, 12);
|
---|
[f761f1eb] | 125 |
|
---|
[1b109cb] | 126 | GEN_READ_CP0(cause, 13);
|
---|
| 127 | GEN_WRITE_CP0(cause, 13);
|
---|
| 128 |
|
---|
| 129 | GEN_READ_CP0(epc, 14);
|
---|
| 130 | GEN_WRITE_CP0(epc, 14);
|
---|
| 131 |
|
---|
| 132 | GEN_READ_CP0(prid, 15);
|
---|
[f761f1eb] | 133 |
|
---|
| 134 | #endif
|
---|
[b45c443] | 135 |
|
---|
[1bb2e7a] | 136 | /** @}
|
---|
[b45c443] | 137 | */
|
---|