OpenCores
URL https://opencores.org/ocsvn/ao486/ao486/trunk

Subversion Repositories ao486

[/] [ao486/] [trunk/] [syn/] [components/] [sd_card/] [firmware/] [bsp/] [HAL/] [inc/] [sys/] [alt_exceptions.h] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 alfik
#ifndef __ALT_EXCEPTIONS_H__
2
#define __ALT_EXCEPTIONS_H__
3
 
4
/******************************************************************************
5
*                                                                             *
6
* License Agreement                                                           *
7
*                                                                             *
8
* Copyright (c) 2008 Altera Corporation, San Jose, California, USA.           *
9
* All rights reserved.                                                        *
10
*                                                                             *
11
* Permission is hereby granted, free of charge, to any person obtaining a     *
12
* copy of this software and associated documentation files (the "Software"),  *
13
* to deal in the Software without restriction, including without limitation   *
14
* the rights to use, copy, modify, merge, publish, distribute, sublicense,    *
15
* and/or sell copies of the Software, and to permit persons to whom the       *
16
* Software is furnished to do so, subject to the following conditions:        *
17
*                                                                             *
18
* The above copyright notice and this permission notice shall be included in  *
19
* all copies or substantial portions of the Software.                         *
20
*                                                                             *
21
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  *
22
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,    *
23
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
24
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      *
25
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING     *
26
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER         *
27
* DEALINGS IN THE SOFTWARE.                                                   *
28
*                                                                             *
29
* This agreement shall be governed in all respects by the laws of the State   *
30
* of California and by the laws of the United States of America.              *
31
*                                                                             *
32
******************************************************************************/
33
#include "alt_types.h"
34
#include "system.h"
35
 
36
#ifdef __cplusplus
37
extern "C"
38
{
39
#endif /* __cplusplus */
40
 
41
/*
42
 * This file defines instruction-generated exception handling and registry
43
 * API, exception type enumeration, and handler return value enumeration for
44
 * Nios II.
45
 */
46
 
47
/*
48
 * The following enumeration describes the value in the CPU EXCEPTION
49
 * register CAUSE bit field.
50
 */
51
enum alt_exception_cause_e {
52
  /*
53
   * This value is passed to an exception handler's cause argument if
54
   * "extra exceptions" information (EXECPTION) register is not
55
   * present in the processor hardware configuration.
56
   */
57
  NIOS2_EXCEPTION_CAUSE_NOT_PRESENT            = -1,
58
 
59
  /*
60
   * Real values
61
   */
62
  NIOS2_EXCEPTION_RESET                        = 0,
63
  NIOS2_EXCEPTION_CPU_ONLY_RESET_REQUEST       = 1,
64
  NIOS2_EXCEPTION_INTERRUPT                    = 2,
65
  NIOS2_EXCEPTION_TRAP_INST                    = 3,
66
  NIOS2_EXCEPTION_UNIMPLEMENTED_INST           = 4,
67
  NIOS2_EXCEPTION_ILLEGAL_INST                 = 5,
68
  NIOS2_EXCEPTION_MISALIGNED_DATA_ADDR         = 6,
69
  NIOS2_EXCEPTION_MISALIGNED_TARGET_PC         = 7,
70
  NIOS2_EXCEPTION_DIVISION_ERROR               = 8,
71
  NIOS2_EXCEPTION_SUPERVISOR_ONLY_INST_ADDR    = 9,
72
  NIOS2_EXCEPTION_SUPERVISOR_ONLY_INST         = 10,
73
  NIOS2_EXCEPTION_SUPERVISOR_ONLY_DATA_ADDR    = 11,
74
  NIOS2_EXCEPTION_TLB_MISS                     = 12,
75
  NIOS2_EXCEPTION_TLB_EXECUTE_PERM_VIOLATION   = 13,
76
  NIOS2_EXCEPTION_TLB_READ_PERM_VIOLATION      = 14,
77
  NIOS2_EXCEPTION_TLB_WRITE_PERM_VIOLATION     = 15,
78
  NIOS2_EXCEPTION_MPU_INST_REGION_VIOLATION    = 16,
79
  NIOS2_EXCEPTION_MPU_DATA_REGION_VIOLATION    = 17,
80
  NIOS2_EXCEPTION_ECC_TLB_ERR                  = 18,
81
  NIOS2_EXCEPTION_ECC_FETCH_ERR                = 19,
82
  NIOS2_EXCEPTION_ECC_REGISTER_FILE_ERR        = 20,
83
  NIOS2_EXCEPTION_ECC_DATA_ERR                 = 21,
84
  NIOS2_EXCEPTION_ECC_DATA_CACHE_WRITEBACK_ERR = 22
85
};
86
typedef enum alt_exception_cause_e alt_exception_cause;
87
 
88
/*
89
 * These define valid return values for a user-defined instruction-generated
90
 * exception handler. The handler should return one of these to indicate
91
 * whether to re-issue the instruction that triggered the exception, or to
92
 * skip it.
93
 */
94
enum alt_exception_result_e {
95
  NIOS2_EXCEPTION_RETURN_REISSUE_INST = 0,
96
  NIOS2_EXCEPTION_RETURN_SKIP_INST    = 1
97
};
98
typedef enum alt_exception_result_e alt_exception_result;
99
 
100
/*
101
 * alt_instruction_exception_register() can be used to register an exception
102
 * handler for instruction-generated exceptions that are not handled by the
103
 * built-in exception handler (i.e. for interrupts).
104
 *
105
 * The registry API is optionally enabled through the "Enable
106
 * Instruction-related Exception API" HAL BSP setting, which will
107
 * define the macro below.
108
 */
109
#ifdef ALT_INCLUDE_INSTRUCTION_RELATED_EXCEPTION_API
110
void alt_instruction_exception_register (
111
  alt_exception_result (*exception_handler)(
112
    alt_exception_cause cause,
113
    alt_u32 exception_pc,
114
    alt_u32 bad_addr) );
115
#endif /*ALT_INCLUDE_INSTRUCTION_RELATED_EXCEPTION_API */
116
 
117
/*
118
 * alt_exception_cause_generated_bad_addr() indicates whether a particular
119
 * exception cause value was from an exception-type that generated a valid
120
 * address in the BADADDR register. The contents of BADADDR is passed to
121
 * a user-registered exception handler in all cases, whether valid or not.
122
 * This routine should be called to validate the bad_addr argument to
123
 * your exception handler.
124
 *
125
 * Note that this routine will return false (0) for causes
126
 * NIOS2_EXCEPTION_TLB_MISS and NIOS2_EXCEPTION_ECC_TLB_ERR.
127
 * You must read the TLBMISC.D field to determine if BADADDR
128
 * is valid for these (valid if TLBMISC.D = 1).
129
 */
130
int alt_exception_cause_generated_bad_addr(alt_exception_cause cause);
131
 
132
/*
133
 * alt_ecc_fatal_exception_register() is called to register a handler to
134
 * service likely fatal ECC error exceptions. Likely the handler will
135
 * assume that correct execution of the running software is not possible
136
 * and re-initialize the processor (e.g. jump to reset address).
137
 *
138
 * Passing null (0x0) in the handler argument will disable a previously-
139
 * registered handler.
140
 *
141
 * Note that if no handler is registered, just normal exception processing
142
 * occurs on a likely fatal ECC exception and the exception processing
143
 * code might trigger an infinite exception loop.
144
 *
145
 * Note that the handler isn't a C function: it must be written in
146
 * assembly-code because it doesn't support C language calling conventions
147
 * and it can't return.
148
 *
149
 * The handler code must be carefully written to avoid triggering
150
 * another fatal ECC exception and creating an infinite exception loop.
151
 * The handler must avoid reading registers in case the fatal ECC
152
 * error is a register file ECC error.
153
 * If a data cache is present, the handler must avoid instructions that
154
 * access the data cache in case the fatal ECC error is a data cache
155
 * related ECC error. This includes cacheable load, cacheable store,
156
 * non-cacheable store (because it looks in the data cache to update the
157
 * data cache if it hits), and all data cache management instructions except
158
 * for INITD.
159
 */
160
void alt_ecc_fatal_exception_register(alt_u32 handler);
161
 
162
#ifdef __cplusplus
163
}
164
#endif /* __cplusplus */
165
 
166
#endif /* __ALT_EXCEPTIONS_H__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.