[164] | 1 | /*
|
---|
| 2 | * TOPPERS/ASP Kernel
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
| 4 | * Advanced Standard Profile Kernel
|
---|
| 5 | *
|
---|
| 6 | * Copyright (C) 2014 Cores Co., Ltd. Japan
|
---|
| 7 | *
|
---|
| 8 | * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
|
---|
| 9 | * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü
|
---|
| 10 | * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
| 11 | * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
| 12 | * \¦C±Ìpð¨æѺL̳ÛØKèªC»ÌÜÜÌ`Å\[
|
---|
| 13 | * XR[hÉÜÜêÄ¢é±ÆD
|
---|
| 14 | * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg
|
---|
| 15 | * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
| 16 | gip
|
---|
| 17 | * Ò}j
|
---|
| 18 | AÈÇjÉCãLÌì \¦C±Ìpð¨æѺL
|
---|
| 19 | * ̳ÛØKèðfÚ·é±ÆD
|
---|
| 20 | * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg
|
---|
| 21 | * pÅ«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
|
---|
| 22 | * ÆD
|
---|
| 23 | * (a) Äzzɺ¤hL
|
---|
| 24 | gipÒ}j
|
---|
| 25 | AÈÇjÉCãLÌ
|
---|
| 26 | * ì \¦C±Ìpð¨æѺL̳ÛØKèðfÚ·é±ÆD
|
---|
| 27 | * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
|
---|
| 28 | * ñ·é±ÆD
|
---|
| 29 | * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹
|
---|
| 30 | * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
| 31 | * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé
|
---|
| 32 | * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð
|
---|
| 33 | * ÆÓ·é±ÆD
|
---|
| 34 | *
|
---|
| 35 | * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
|
---|
| 36 | * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
|
---|
| 37 | * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF
|
---|
| 38 | * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC»
|
---|
| 39 | * ÌÓCðíÈ¢D
|
---|
| 40 | *
|
---|
| 41 | * @(#) $Id: prc_support.cpp 164 2016-03-07 11:33:50Z coas-nagasima $
|
---|
| 42 | */
|
---|
| 43 |
|
---|
| 44 | #include "StdAfx.h"
|
---|
| 45 | #include "prc_insn.h"
|
---|
| 46 | #include "WinKernel.h"
|
---|
| 47 |
|
---|
| 48 | #ifdef _DEBUG
|
---|
| 49 | #define new DEBUG_NEW
|
---|
| 50 | #undef THIS_FILE
|
---|
| 51 | static char THIS_FILE[] = __FILE__;
|
---|
| 52 | #endif
|
---|
| 53 |
|
---|
| 54 | // ähsqnmJ[l
|
---|
| 55 | extern CKernel *g_Kernel;
|
---|
| 56 |
|
---|
| 57 | uint32_t psw = PSW_I_MASK;
|
---|
| 58 |
|
---|
| 59 | uint32_t current_psw(void)
|
---|
| 60 | {
|
---|
| 61 | return psw;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | void set_psw(uint32_t psw)
|
---|
| 65 | {
|
---|
| 66 | uint32_t temp = ::psw ^ psw;
|
---|
| 67 |
|
---|
| 68 | ::psw = psw;
|
---|
| 69 |
|
---|
| 70 | if((temp & PSW_I_MASK) != 0) {
|
---|
| 71 | if((psw & PSW_I_MASK) != 0)
|
---|
| 72 | g_Kernel->LockCPU();
|
---|
| 73 | else
|
---|
| 74 | g_Kernel->UnlockCPU();
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | /*
|
---|
| 79 | * NMIð·×ÄÌÝÌÖ~
|
---|
| 80 | */
|
---|
| 81 | void disint(void)
|
---|
| 82 | {
|
---|
| 83 | g_Kernel->LockCPU();
|
---|
| 84 |
|
---|
| 85 | psw |= PSW_I_MASK;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | /*
|
---|
| 89 | * NMIð·×ÄÌÝÌÂ
|
---|
| 90 | */
|
---|
| 91 | void enaint(void)
|
---|
| 92 | {
|
---|
| 93 | psw &= ~PSW_I_MASK;
|
---|
| 94 |
|
---|
| 95 | g_Kernel->UnlockCPU();
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | /*
|
---|
| 99 | * ÝnhÌÝè
|
---|
| 100 | */
|
---|
| 101 | void x_define_inh(uint_t inhno, FP int_entry)
|
---|
| 102 | {
|
---|
| 103 | g_Kernel->DefineInterruptHandler(inhno, int_entry);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | void i_begin_int(INTNO intno)
|
---|
| 107 | {
|
---|
| 108 | g_Kernel->BeginInt();
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | void i_end_int(INTNO intno)
|
---|
| 112 | {
|
---|
| 113 | g_Kernel->EndInt();
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | bool starting = true;
|
---|
| 117 |
|
---|
| 118 | bool_t t_sense_lock()
|
---|
| 119 | {
|
---|
| 120 | return g_Kernel->CurrentIsLocked();
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | bool_t i_sense_lock()
|
---|
| 124 | {
|
---|
| 125 | return g_Kernel->IsLocked();
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | bool_t x_sense_lock()
|
---|
| 129 | {
|
---|
| 130 | if(g_Kernel->InTaskContext())
|
---|
| 131 | return g_Kernel->CurrentIsLocked();
|
---|
| 132 | else
|
---|
| 133 | return g_Kernel->IsLocked();
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | /*
|
---|
| 137 | * ReLXgÌQÆ
|
---|
| 138 | */
|
---|
| 139 | bool_t sense_context(void)
|
---|
| 140 | {
|
---|
| 141 | return !g_Kernel->InTaskContext() && !starting;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | /*
|
---|
| 145 | * CPUáO̶µ½ÌReLXgÌQÆ
|
---|
| 146 | */
|
---|
| 147 | bool_t exc_sense_context( void *p_excinf )
|
---|
| 148 | {
|
---|
| 149 | return !g_Kernel->InTaskContext() && !starting;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | /*
|
---|
| 153 | * J[lN®^XNfBXpb`
|
---|
| 154 | */
|
---|
| 155 | void _start_dispatch(void)
|
---|
| 156 | {
|
---|
| 157 | starting = false;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | /*
|
---|
| 161 | * ^XNfBXpb`
|
---|
| 162 | */
|
---|
| 163 | void dispatch(void)
|
---|
| 164 | {
|
---|
| 165 | g_Kernel->Dispatch();
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | /*
|
---|
| 169 | * »ÝÌReLXgðÌÄÄfBXpb`
|
---|
| 170 | */
|
---|
| 171 | void _exit_and_dispatch(void)
|
---|
| 172 | {
|
---|
| 173 | g_Kernel->ExitAndDispatch();
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | /*
|
---|
| 177 | * J[lÌI¹ÌÄoµ
|
---|
| 178 | *
|
---|
| 179 | * X^bNðñ^XNReLXgpÉØèÖ¦D
|
---|
| 180 | *
|
---|
| 181 | */
|
---|
| 182 | void call_exit_kernel(void)
|
---|
| 183 | {
|
---|
| 184 | g_Kernel->Terminate();
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | /*
|
---|
| 188 | * ^XNN®
|
---|
| 189 | *
|
---|
| 190 | */
|
---|
| 191 | void start_r(void)
|
---|
| 192 | {
|
---|
| 193 | #if TIPM_LOCK != -15
|
---|
| 194 | lock_flag = false;
|
---|
| 195 | #endif /* TIPM_LOCK != -15 */
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | extern "C" void Throw()
|
---|
| 199 | {
|
---|
| 200 | throw std::exception();
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | extern "C" void trigger_cpu_exception( void )
|
---|
| 204 | {
|
---|
| 205 | throw std::exception();
|
---|
| 206 | }
|
---|