source: ssp_aarch64/trunk/arm64_gcc/prc_config.c@ 356

Last change on this file since 356 was 356, checked in by nmir-saito, 6 years ago

set svn:mime-type to files

  • Property svn:mime-type set to text/plain; charset=utf-8
File size: 6.2 KB
Line 
1/*
2 * TOPPERS/SSP Kernel
3 * Smallest Set Profile Kernel
4 *
5 * Copyright (C) 2008 by Embedded and Real-Time Systems Laboratory
6 * Graduate School of Information Science, Nagoya Univ., JAPAN
7 * Copyright (C) 2010 by Meika Sugimoto
8 * Copyright (C) 2018 by Naoki Saito
9 * Nagoya Municipal Industrial Research Institute, JAPAN
10 *
11 * 上記著作権者は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
12 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
13 * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
14 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
15 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
16 * スコード中に含まれていること.
17 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
18 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
19 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
20 * の無保証規定を掲載すること.
21 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
22 * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
23 * と.
24 * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
25 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
26 * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
27 * 報告すること.
28 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
29 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
30 * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
31 * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
32 * 免責すること.
33 *
34 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
35 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
36 * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
37 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
38 * の責任を負わない.
39 *
40 * @(#) $Id: prc_config.c 1304 2008-08-27 07:28:36Z ertl-honda $
41 */
42
43/*
44 * プロセッサ依存モジュール(ARM64用)
45 */
46
47#include "kernel_impl.h"
48#include <t_syslog.h>
49
50/* 割込みネスト数の管理 */
51uint8_t intnest;
52
53/*
54 * プロセッサ依存の初期化
55 */
56void
57prc_initialize(void)
58{
59 /* 割込みネスト数の初期化 */
60 intnest = 0u;
61
62 /*
63 * GICの設定
64 */
65 gicd_initialize();
66 gicc_initialize();
67}
68
69/*
70 * プロセッサ依存の終了処理
71 */
72void
73prc_terminate(void)
74{
75 while(1)
76 ;
77}
78
79/*
80 * 割込み要求ライン属性の設定
81 */
82void
83x_config_int(INTNO intno, ATR intatr, PRI intpri)
84{
85 assert(VALID_INTNO(intno));
86 assert(TMIN_INTPRI <= intpri && intpri <= TMAX_INTPRI);
87
88 /*
89 * 割込みを禁止
90 *
91 * 割込みを受け付けたまま,レベルトリガ/エッジトリガの設定や,割
92 * 込み優先度の設定を行うのは危険なため,割込み属性にかかわらず,
93 * 一旦マスクする.
94 */
95 x_disable_int(intno);
96
97 /*
98 * 割込みをコンフィギュレーション
99 */
100
101 if ((intatr & TA_EDGE) != 0U) {
102 gicd_config(intno, GICD_ICFGRn_EDGE);
103 x_clear_int(intno);
104 }
105 else {
106 gicd_config(intno, GICD_ICFGRn_LEVEL);
107 }
108
109 /*
110 * 割込み優先度とターゲットプロセッサを設定
111 */
112 gicd_set_priority(intno, INT_IPM(intpri));
113 gicd_set_target(intno, 1U << ARM_PRC_INDEX);
114
115 /*
116 * 割込みを許可
117 */
118 if ((intatr & TA_ENAINT) != 0U) {
119 x_enable_int(intno);
120 }
121}
122
123#ifndef OMIT_DEFAULT_EXC_HANDLER
124/*
125 * 登録されていない例外が発生すると呼び出される
126 */
127void
128default_exc_handler(void *p_excinf)
129{
130 uint64_t gicc_pmr = *(((uint64_t*)p_excinf) + 0);
131 uint64_t excno = *(((uint64_t*)p_excinf) + 1);
132 // スタックポインタの調整量
133 uint64_t adj = *(((uint64_t*)p_excinf) + 3) >> 3;
134 uint64_t esr, pc, spsr, sp;
135
136 esr = *(((uint64_t*)p_excinf) + 4 + adj);
137 pc = *(((uint64_t*)p_excinf) + 5 + adj);
138 spsr = *(((uint64_t*)p_excinf) + 6 + adj);
139 sp = *(((uint64_t*)p_excinf) + 38 + adj);
140
141 syslog(LOG_EMERG, "\nUnregistered CPU Exception occured.");
142 syslog(LOG_EMERG, "EXCNO = %08x ESR = %08x GICC_PMR = %08x ", excno, esr, gicc_pmr);
143 syslog(LOG_EMERG, "PC=%08x%08x SP = %08x%08x SPSR = %08x",
144 (uint32_t)((pc & UINT64_C(0xffffffff00000000))>>32), (uint32_t)(pc & UINT64_C(0xffffffff)),
145 (uint32_t)((sp & UINT64_C(0xffffffff00000000))>>32), (uint32_t)(sp & UINT64_C(0xffffffff)),
146 (uint32_t)spsr);
147
148 target_exit();
149}
150#endif /* OMIT_DEFAULT_EXC_HANDLER */
151
152#ifndef OMIT_DEFAULT_INT_HANDLER
153/*
154 * 未登録の割込みが発生した場合に呼び出される
155 */
156void
157default_int_handler(void)
158{
159 syslog(LOG_EMERG, "\nUnregistered Interrupt occurs.");
160
161 target_exit();
162}
163#endif /* OMIT_DEFAULT_INT_HANDLER */
164
165/*
166 * 割込みハンドラの呼び出し
167 */
168void
169call_int_handler(uint32_t intno)
170{
171 intnest++;
172
173 i_unlock_cpu();
174
175 // ハンドラの呼び出し
176 inh_table[intno]();
177
178 i_lock_cpu();
179
180 intnest--;
181}
182
183/*
184 * CPU例外ハンドラの呼び出し
185 */
186void
187call_exc_handler(void *p_excinf, uint32_t excno)
188{
189 intnest++;
190
191 // CPU例外発生時はCPUロックフラグを操作しない
192
193 // ハンドラの呼び出し
194 exc_table[excno](p_excinf);
195
196 i_lock_cpu();
197
198 intnest--;
199}
200
Note: See TracBrowser for help on using the repository browser.