[363] | 1 | /*
|
---|
| 2 | * TOPPERS/JSP Kernel
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
| 4 | * Just Standard Profile Kernel
|
---|
| 5 | *
|
---|
| 6 | * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
|
---|
| 7 | * Toyohashi Univ. of Technology, JAPAN
|
---|
| 8 | *
|
---|
| 9 | * ä¸è¨èä½æ¨©è
|
---|
| 10 | ã¯ï¼ä»¥ä¸ã® (1)ã(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
| 11 | * ã«ãã£ã¦å
|
---|
| 12 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
| 13 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
| 14 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
| 15 | å¸ï¼ä»¥ä¸ï¼
|
---|
| 16 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 17 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 18 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 19 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 20 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 21 | * ç¨ã§ããå½¢ã§åé
|
---|
| 22 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 23 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 24 | * è
|
---|
| 25 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 26 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 27 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 28 | * ç¨ã§ããªãå½¢ã§åé
|
---|
| 29 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 30 | * ã¨ï¼
|
---|
| 31 | * (a) åé
|
---|
| 32 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 33 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 34 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 35 | * (b) åé
|
---|
| 36 | å¸ã®å½¢æ
|
---|
| 37 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 38 | * å ±åãããã¨ï¼
|
---|
| 39 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 40 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 41 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 42 | 責ãããã¨ï¼
|
---|
| 43 | *
|
---|
| 44 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 45 | ã
|
---|
| 46 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
| 47 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
| 48 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
| 49 | *
|
---|
| 50 | * @(#) $Id: stdafx.cpp,v 1.11 2003/12/24 07:40:42 takayuki Exp $
|
---|
| 51 | */
|
---|
| 52 |
|
---|
| 53 | /*
|
---|
| 54 | * ããã¤ã¹ããã¼ã¸ã£ æ¬ä½(CExeModule)
|
---|
| 55 | */
|
---|
| 56 |
|
---|
| 57 | #pragma warning(disable:4786) //ãããã°æååã255æåã«åãè©°ãã¾ãã
|
---|
| 58 | #pragma warning(disable:4200) //éæ¨æºã®æ¡å¼µæ©è½ã使ã£ã¦ãã¾ã (é·ãä¸å®ã®é
|
---|
| 59 | å:465è¡ç®)
|
---|
| 60 |
|
---|
| 61 | #include "stdafx.h"
|
---|
| 62 |
|
---|
| 63 | #ifdef _ATL_STATIC_REGISTRY
|
---|
| 64 | #include <statreg.h>
|
---|
| 65 | #include <statreg.cpp>
|
---|
| 66 | #endif
|
---|
| 67 |
|
---|
| 68 | #include <atlimpl.cpp>
|
---|
| 69 | #include <algorithm>
|
---|
| 70 |
|
---|
| 71 | #include <initguid.h>
|
---|
| 72 | #include "devicemanager.h"
|
---|
| 73 | #include "device.h"
|
---|
| 74 | #include "kernel.h"
|
---|
| 75 | #include "information.h"
|
---|
| 76 | #include "kernellog.h"
|
---|
| 77 |
|
---|
| 78 | using namespace std;
|
---|
| 79 |
|
---|
| 80 | #ifdef _DEBUG
|
---|
| 81 | DWORD Count;
|
---|
| 82 | char Buffer[1024];
|
---|
| 83 | #define DebugOut(x) ::WriteFile(::GetStdHandle(STD_OUTPUT_HANDLE),Buffer, (x), &Count, NULL)
|
---|
| 84 | #else
|
---|
| 85 | #define DebugOut(x) /##/
|
---|
| 86 | #endif
|
---|
| 87 |
|
---|
| 88 | CExeModule::CExeModule(void) : Kernel(0)
|
---|
| 89 | {
|
---|
| 90 | ::InitializeCriticalSection(&cs);
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 | DeviceID CExeModule::AddDevice(CDevice *device)
|
---|
| 95 | {
|
---|
| 96 | list<CDevice *>::iterator scope;
|
---|
| 97 | list<CInformation *>::iterator view;
|
---|
| 98 |
|
---|
| 99 | ::EnterCriticalSection(&cs);
|
---|
| 100 |
|
---|
| 101 | scope = find(DeviceList.begin(), DeviceList.end(), device);
|
---|
| 102 | if(scope != DeviceList.end())
|
---|
| 103 | {
|
---|
| 104 | ::LeaveCriticalSection(&cs);
|
---|
| 105 | return 0;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | DebugOut(::wsprintfA(Buffer,"AddDevice\n"));
|
---|
| 109 | view = ViewerList.begin();
|
---|
| 110 | while(view != ViewerList.end())
|
---|
| 111 | {
|
---|
| 112 | (*view)->Fire_OnDeviceChanged(1,reinterpret_cast<long>(device));
|
---|
| 113 | view ++;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | DeviceList.push_back(device);
|
---|
| 117 |
|
---|
| 118 | ::LeaveCriticalSection(&cs);
|
---|
| 119 | return reinterpret_cast<DeviceID>(device);
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | bool CExeModule::DeleteDevice(CDevice *device)
|
---|
| 123 | {
|
---|
| 124 | list<CDevice *>::iterator dev;
|
---|
| 125 | map<Range,CDevice *>::iterator mem[2];
|
---|
| 126 |
|
---|
| 127 | ::EnterCriticalSection(&cs);
|
---|
| 128 |
|
---|
| 129 | DebugOut(::wsprintfA(Buffer,"DelDevice\n"));
|
---|
| 130 |
|
---|
| 131 | dev = find(DeviceList.begin(), DeviceList.end(), device);
|
---|
| 132 | if(dev == DeviceList.end())
|
---|
| 133 | {
|
---|
| 134 | ::LeaveCriticalSection(&cs);
|
---|
| 135 | return false;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | mem[0] = DeviceMap.begin();
|
---|
| 139 | while(mem[0] != DeviceMap.end())
|
---|
| 140 | {
|
---|
| 141 | if((*mem[0]).second == device)
|
---|
| 142 | {
|
---|
| 143 | mem[1] = mem[0];
|
---|
| 144 | mem[0] ++;
|
---|
| 145 |
|
---|
| 146 | DeviceMap.erase(mem[1]);
|
---|
| 147 | }else
|
---|
| 148 | mem[0] ++;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | DeviceList.erase(dev);
|
---|
| 152 |
|
---|
| 153 | list<CInformation *>::iterator view;
|
---|
| 154 | view = ViewerList.begin();
|
---|
| 155 | while(view != ViewerList.end())
|
---|
| 156 | {
|
---|
| 157 | (*view)->Fire_OnDeviceChanged(2,reinterpret_cast<long>(device));
|
---|
| 158 | view ++;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | ::LeaveCriticalSection(&cs);
|
---|
| 162 | return true;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | bool CExeModule::Map(CDevice *device, Range area)
|
---|
| 166 | {
|
---|
| 167 | map<Range,CDevice *>::iterator scope;
|
---|
| 168 |
|
---|
| 169 | ::EnterCriticalSection(&cs);
|
---|
| 170 |
|
---|
| 171 |
|
---|
| 172 | scope = DeviceMap.begin();
|
---|
| 173 | while(scope != DeviceMap.end())
|
---|
| 174 | {
|
---|
| 175 | if( area.IsIncludedIn((*scope).first) )
|
---|
| 176 | {
|
---|
| 177 | ::LeaveCriticalSection(&cs);
|
---|
| 178 | return false;
|
---|
| 179 | }
|
---|
| 180 | scope ++;
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | DeviceMap[area] = device;
|
---|
| 184 |
|
---|
| 185 | DebugOut(::wsprintfA(Buffer,"Map\n"));
|
---|
| 186 | list<CInformation *>::iterator view;
|
---|
| 187 | view = ViewerList.begin();
|
---|
| 188 | while(view != ViewerList.end())
|
---|
| 189 | {
|
---|
| 190 | (*view)->Fire_OnDeviceChanged(3,reinterpret_cast<long>(device),area.GetBase());
|
---|
| 191 | view ++;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | ::LeaveCriticalSection(&cs);
|
---|
| 195 | return true;
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 |
|
---|
| 199 | bool CExeModule::Unmap(CDevice *device, unsigned long address)
|
---|
| 200 | {
|
---|
| 201 | map<Range,CDevice *>::iterator scope;
|
---|
| 202 | Range work(address);
|
---|
| 203 |
|
---|
| 204 | ::EnterCriticalSection(&cs);
|
---|
| 205 |
|
---|
| 206 | scope = DeviceMap.begin();
|
---|
| 207 | while(scope != DeviceMap.end())
|
---|
| 208 | {
|
---|
| 209 | if( (*scope).second == device && work.IsIncludedIn((*scope).first) )
|
---|
| 210 | {
|
---|
| 211 | DeviceMap.erase(scope);
|
---|
| 212 |
|
---|
| 213 | DebugOut(::wsprintfA(Buffer,"Unmap\n"));
|
---|
| 214 | list<CInformation *>::iterator view;
|
---|
| 215 | view = ViewerList.begin();
|
---|
| 216 | while(view != ViewerList.end())
|
---|
| 217 | {
|
---|
| 218 | (*view)->Fire_OnDeviceChanged(4,reinterpret_cast<long>(device),address);
|
---|
| 219 | view ++;
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | ::LeaveCriticalSection(&cs);
|
---|
| 223 |
|
---|
| 224 | return true;
|
---|
| 225 | }
|
---|
| 226 | scope ++;
|
---|
| 227 | }
|
---|
| 228 | ::LeaveCriticalSection(&cs);
|
---|
| 229 |
|
---|
| 230 | return false;
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | void CExeModule::AddViewer(CInformation *view)
|
---|
| 234 | {
|
---|
| 235 | list<CInformation *>::iterator scope;
|
---|
| 236 |
|
---|
| 237 | ::EnterCriticalSection(&cs);
|
---|
| 238 | scope = find(ViewerList.begin(), ViewerList.end(), view);
|
---|
| 239 | if(scope == ViewerList.end())
|
---|
| 240 | ViewerList.push_back(view);
|
---|
| 241 | ::LeaveCriticalSection(&cs);
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | void CExeModule::RemoveViewer(CInformation *view)
|
---|
| 245 | {
|
---|
| 246 | list<CInformation *>::iterator scope;
|
---|
| 247 |
|
---|
| 248 | ::EnterCriticalSection(&cs);
|
---|
| 249 | scope = find(ViewerList.begin(), ViewerList.end(), view);
|
---|
| 250 | if(scope != ViewerList.end())
|
---|
| 251 | ViewerList.erase(scope);
|
---|
| 252 | ::LeaveCriticalSection(&cs);
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | bool CExeModule::AttachKernel(CKernel *kernel)
|
---|
| 256 | {
|
---|
| 257 | bool result = false;
|
---|
| 258 | list<CDevice *>::iterator scope;
|
---|
| 259 | list<CInformation *>::iterator view;
|
---|
| 260 | list<CKernelLog *>::iterator watcher;
|
---|
| 261 |
|
---|
| 262 | DebugOut(::wsprintfA(Buffer,"AttachKernel\n"));
|
---|
| 263 |
|
---|
| 264 | ::EnterCriticalSection(&cs);
|
---|
| 265 | if((Kernel != 0) && (Kernel != kernel))
|
---|
| 266 | {
|
---|
| 267 | //å²è¾¼ã¿-1 => ã«ã¼ãã«ã®KeepAlive
|
---|
| 268 | if(FAILED(Kernel->Fire_OnInterruptRequest(-1)))
|
---|
| 269 | {
|
---|
| 270 | //æ¥ç¶ã失ã£ãã«ã¼ãã«ã®ãã¿ãã
|
---|
| 271 | DetachKernel(Kernel);
|
---|
| 272 | }else
|
---|
| 273 | {
|
---|
| 274 | //æ¥ç¶æ¸ã¿ã«ã¼ãã«ããã
|
---|
| 275 | if(::MessageBox(NULL,_T("æ°ããã«ã¼ãã«ãèµ·åãããããã¤ã¹ããã¼ã¸ã£ã«æ¥ç¶ãããã¨ãã¦ãã¾ãã\næ°ããã«ã¼ãã«ã«æ¥ç¶å
|
---|
| 276 | ãåãæ¿ãã¾ãã?"),_T("TOPPERS/JSP Windows - DeviceManager"),MB_YESNO) == IDYES)
|
---|
| 277 | DetachKernel(Kernel);
|
---|
| 278 | }
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 | if(Kernel == 0)
|
---|
| 282 | {
|
---|
| 283 | Kernel = kernel;
|
---|
| 284 |
|
---|
| 285 | scope = DeviceList.begin();
|
---|
| 286 | while(scope != DeviceList.end())
|
---|
| 287 | {
|
---|
| 288 | (*scope)->Fire_OnKernelStart();
|
---|
| 289 | scope ++;
|
---|
| 290 | }
|
---|
| 291 |
|
---|
| 292 | view = ViewerList.begin();
|
---|
| 293 | while(view != ViewerList.end())
|
---|
| 294 | {
|
---|
| 295 | (*view)->Fire_OnKernelChanged(1);
|
---|
| 296 | view ++;
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 | watcher = WatcherList.begin();
|
---|
| 300 | while(watcher != WatcherList.end())
|
---|
| 301 | {
|
---|
| 302 | (*watcher)->Fire_OnKernelStart();
|
---|
| 303 | watcher ++;
|
---|
| 304 | }
|
---|
| 305 |
|
---|
| 306 | DebugOut(::wsprintfA(Buffer,"AttachKernel was performed successfully\n"));
|
---|
| 307 | result = true;
|
---|
| 308 | }
|
---|
| 309 | ::LeaveCriticalSection(&cs);
|
---|
| 310 |
|
---|
| 311 | return result;
|
---|
| 312 | }
|
---|
| 313 |
|
---|
| 314 | bool CExeModule::DetachKernel(CKernel *kernel)
|
---|
| 315 | {
|
---|
| 316 | bool result;
|
---|
| 317 | list<CDevice *>::iterator scope;
|
---|
| 318 | list<CInformation *>::iterator view;
|
---|
| 319 | list<CKernelLog *>::iterator watcher;
|
---|
| 320 |
|
---|
| 321 | DebugOut(::wsprintfA(Buffer,"DetachKernel\n"));
|
---|
| 322 |
|
---|
| 323 | ::EnterCriticalSection(&cs);
|
---|
| 324 | if( (result = Kernel == kernel) )
|
---|
| 325 | {
|
---|
| 326 | scope = DeviceList.begin();
|
---|
| 327 | while(scope != DeviceList.end())
|
---|
| 328 | {
|
---|
| 329 | (*scope)->Fire_OnKernelExit();
|
---|
| 330 | scope ++;
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 | view = ViewerList.begin();
|
---|
| 334 | while(view != ViewerList.end())
|
---|
| 335 | {
|
---|
| 336 | (*view)->Fire_OnKernelChanged(2);
|
---|
| 337 | view ++;
|
---|
| 338 | }
|
---|
| 339 |
|
---|
| 340 | watcher = WatcherList.begin();
|
---|
| 341 | while(watcher != WatcherList.end())
|
---|
| 342 | {
|
---|
| 343 | (*watcher)->Fire_OnKernelExit();
|
---|
| 344 | watcher ++;
|
---|
| 345 | }
|
---|
| 346 |
|
---|
| 347 | Kernel = 0l;
|
---|
| 348 | DebugOut(::wsprintfA(Buffer,"DetachKernel was performed successfully\n"));
|
---|
| 349 | }
|
---|
| 350 | ::LeaveCriticalSection(&cs);
|
---|
| 351 |
|
---|
| 352 | return result;
|
---|
| 353 | }
|
---|
| 354 |
|
---|
| 355 | bool CExeModule::Read(CKernel * kernel, unsigned long address, unsigned long sz, unsigned char data[])
|
---|
| 356 | {
|
---|
| 357 | bool result;
|
---|
| 358 | map<Range,CDevice *>::iterator scope;
|
---|
| 359 |
|
---|
| 360 | DebugOut(::wsprintfA(Buffer,"Read\n"));
|
---|
| 361 |
|
---|
| 362 | ::EnterCriticalSection(&cs);
|
---|
| 363 |
|
---|
| 364 | if(Kernel != kernel)
|
---|
| 365 | {
|
---|
| 366 | ::LeaveCriticalSection(&cs);
|
---|
| 367 |
|
---|
| 368 | DebugOut(::wsprintfA(Buffer,"Illegal Kernel\n"));
|
---|
| 369 |
|
---|
| 370 | return false;
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | scope = DeviceMap.find(Range(address,sz));
|
---|
| 374 |
|
---|
| 375 | result = (scope != DeviceMap.end());
|
---|
| 376 | if(result)
|
---|
| 377 | (*scope).second->Fire_OnRead(address, sz, data);
|
---|
| 378 |
|
---|
| 379 | ::LeaveCriticalSection(&cs);
|
---|
| 380 |
|
---|
| 381 | return result;
|
---|
| 382 |
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | bool CExeModule::Write(CKernel *kernel, unsigned long address, unsigned long sz, unsigned char *data)
|
---|
| 386 | {
|
---|
| 387 | bool result;
|
---|
| 388 | map<Range,CDevice *>::iterator scope;
|
---|
| 389 |
|
---|
| 390 | DebugOut(::wsprintfA(Buffer,"Write\n"));
|
---|
| 391 |
|
---|
| 392 | ::EnterCriticalSection(&cs);
|
---|
| 393 |
|
---|
| 394 | if(Kernel != kernel)
|
---|
| 395 | {
|
---|
| 396 | ::LeaveCriticalSection(&cs);
|
---|
| 397 | DebugOut(::wsprintfA(Buffer,"Request performed by Illegal Kernel\n"));
|
---|
| 398 | return false;
|
---|
| 399 | }
|
---|
| 400 |
|
---|
| 401 | scope = DeviceMap.find(Range(address,sz));
|
---|
| 402 |
|
---|
| 403 | result = (scope != DeviceMap.end());
|
---|
| 404 | if(result)
|
---|
| 405 | {
|
---|
| 406 | DebugOut(::wsprintfA(Buffer,"FireWrite\n"));
|
---|
| 407 | (*scope).second->Fire_OnWrite(address, sz,data);
|
---|
| 408 | }
|
---|
| 409 | ::LeaveCriticalSection(&cs);
|
---|
| 410 |
|
---|
| 411 | return result;
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 | bool CExeModule::RaiseInterrupt(unsigned long inhno)
|
---|
| 415 | {
|
---|
| 416 | bool result = false;
|
---|
| 417 |
|
---|
| 418 | ::EnterCriticalSection(&cs);
|
---|
| 419 |
|
---|
| 420 | if(Kernel != 0 && Kernel->Fire_OnInterruptRequest(inhno) >= 0)
|
---|
| 421 | result = true;
|
---|
| 422 |
|
---|
| 423 | ::LeaveCriticalSection(&cs);
|
---|
| 424 |
|
---|
| 425 | return result;
|
---|
| 426 | }
|
---|
| 427 |
|
---|
| 428 | bool CExeModule::AddLogWatcher(CKernelLog * watcher)
|
---|
| 429 | {
|
---|
| 430 | if( find(WatcherList.begin(), WatcherList.end(), watcher) != WatcherList.end() )
|
---|
| 431 | return false; //å¤éç»é²
|
---|
| 432 |
|
---|
| 433 | ::EnterCriticalSection(&cs);
|
---|
| 434 | WatcherList.push_back(watcher);
|
---|
| 435 | ::LeaveCriticalSection(&cs);
|
---|
| 436 |
|
---|
| 437 | DebugOut(::wsprintfA(Buffer,"Log watcher inserted into the queue successfully\n"));
|
---|
| 438 |
|
---|
| 439 | return true;
|
---|
| 440 | }
|
---|
| 441 |
|
---|
| 442 |
|
---|
| 443 | void CExeModule::RemoveLogWatcher(CKernelLog * watcher)
|
---|
| 444 | {
|
---|
| 445 | list<CKernelLog *>::iterator scope;
|
---|
| 446 |
|
---|
| 447 | ::EnterCriticalSection(&cs);
|
---|
| 448 | scope = find(WatcherList.begin(), WatcherList.end(), watcher);
|
---|
| 449 | if(scope != WatcherList.end())
|
---|
| 450 | WatcherList.erase(scope);
|
---|
| 451 | ::LeaveCriticalSection(&cs);
|
---|
| 452 |
|
---|
| 453 | DebugOut(::wsprintfA(Buffer,"Log watcher removed from the queue successfully\n"));
|
---|
| 454 | }
|
---|
| 455 |
|
---|
| 456 |
|
---|
| 457 |
|
---|
| 458 | /*
|
---|
| 459 | * ãã°æ
|
---|
| 460 | å ±ã®ç¨®å¥ã®å®ç¾©
|
---|
| 461 | */
|
---|
| 462 | #define LOG_TYP_INTERRUPT 0x01 /* å²è¾¼ã¿ãã³ãã© */
|
---|
| 463 | #define LOG_TYP_ISR 0x02 /* å²è¾¼ã¿ãµã¼ãã¹ãã³ãã© */
|
---|
| 464 | #define LOG_TYP_TIMERHDR 0x03 /* ã¿ã¤ã ã¤ãã³ããã³ãã© */
|
---|
| 465 | #define LOG_TYP_CPUEXC 0x04 /* CPUä¾å¤ãã³ãã© */
|
---|
| 466 | #define LOG_TYP_TSKEXC 0x05 /* ã¿ã¹ã¯ä¾å¤å¦çã«ã¼ãã³ */
|
---|
| 467 | #define LOG_TYP_TSKSTAT 0x06 /* ã¿ã¹ã¯ç¶æ
|
---|
| 468 | å¤å */
|
---|
| 469 | #define LOG_TYP_DISPATCH 0x07 /* ãã£ã¹ããã㣠*/
|
---|
| 470 | #define LOG_TYP_SVC 0x08 /* ãµã¼ãã¹ã³ã¼ã« */
|
---|
| 471 | #define LOG_TYP_COMMENT 0x09 /* ã³ã¡ã³ãï¼æååã®ã¿ã®ãã°ï¼ */
|
---|
| 472 | #define LOG_ENTER 0x00 /* å
|
---|
| 473 | ¥å£ï¼éå§ */
|
---|
| 474 | #define LOG_LEAVE 0x80 /* åºå£ï¼çµäº */
|
---|
| 475 |
|
---|
| 476 |
|
---|
| 477 | typedef unsigned int BITMASK;
|
---|
| 478 |
|
---|
| 479 | typedef struct {
|
---|
| 480 | unsigned int logtype;
|
---|
| 481 | unsigned int logtim;
|
---|
| 482 | BITMASK valid;
|
---|
| 483 | unsigned int bufsz;
|
---|
| 484 | unsigned char buf[];
|
---|
| 485 | } DBIFLOG;
|
---|
| 486 | #define DBIFLOG_BUFMARGIN (sizeof(unsigned int)*4)
|
---|
| 487 |
|
---|
| 488 | bool CExeModule::OnLogEvent(CKernel *kernel, long sz, unsigned char *data)
|
---|
| 489 | {
|
---|
| 490 | list<CKernelLog *>::iterator scope;
|
---|
| 491 |
|
---|
| 492 | #if 0
|
---|
| 493 |
|
---|
| 494 | DBIFLOG * log = reinterpret_cast<DBIFLOG *>(data);
|
---|
| 495 |
|
---|
| 496 | DebugOut(::wsprintfA(Buffer,"LOG <%08x> ",log->logtim));
|
---|
| 497 | switch(log->logtype)
|
---|
| 498 | {
|
---|
| 499 | case LOG_TYP_TSKSTAT:
|
---|
| 500 | DebugOut(::wsprintfA(Buffer,"[STATUS] Tsk:%d ",*(int*)log->buf));
|
---|
| 501 | switch(*((int*)log->buf+1))
|
---|
| 502 | {
|
---|
| 503 | case 0x01:
|
---|
| 504 | case 0x02:
|
---|
| 505 | DebugOut(::wsprintfA(Buffer,"<Runnable [Ready+Running]>\n",*(int*)log->buf));
|
---|
| 506 | break;
|
---|
| 507 | case 0x04:
|
---|
| 508 | case 0x0c:
|
---|
| 509 | if(*((int*)log->buf+1) == 0x04)
|
---|
| 510 | DebugOut(::wsprintfA(Buffer,"<Waiting : "));
|
---|
| 511 | else
|
---|
| 512 | DebugOut(::wsprintfA(Buffer,"<Wait-Suspend : "));
|
---|
| 513 |
|
---|
| 514 | switch(*((int*)log->buf+2))
|
---|
| 515 | {
|
---|
| 516 | case 0x1:
|
---|
| 517 | DebugOut(::wsprintfA(Buffer,"Sleep>\n"));
|
---|
| 518 | break;
|
---|
| 519 | case 0x2:
|
---|
| 520 | DebugOut(::wsprintfA(Buffer,"Delay>\n"));
|
---|
| 521 | break;
|
---|
| 522 | case 0x4:
|
---|
| 523 | DebugOut(::wsprintfA(Buffer,"Semaphore>\n"));
|
---|
| 524 | break;
|
---|
| 525 | default:
|
---|
| 526 | DebugOut(::wsprintfA(Buffer," complex [%04x]>\n", *((int*)log->buf+2)));
|
---|
| 527 | break;
|
---|
| 528 | }
|
---|
| 529 |
|
---|
| 530 | break;
|
---|
| 531 | case 0x08:
|
---|
| 532 | DebugOut(::wsprintfA(Buffer,"<Suspended>\n"));
|
---|
| 533 | break;
|
---|
| 534 | case 0x10:
|
---|
| 535 | DebugOut(::wsprintfA(Buffer,"<Dormant>\n"));
|
---|
| 536 | break;
|
---|
| 537 | default:
|
---|
| 538 | DebugOut(::wsprintfA(Buffer,"<Unknown : %d>",*(int*)log->buf));
|
---|
| 539 | break;
|
---|
| 540 | }
|
---|
| 541 | break;
|
---|
| 542 |
|
---|
| 543 | case LOG_TYP_TSKEXC:
|
---|
| 544 | DebugOut(::wsprintfA(Buffer,"[TSKEXC|ENT] Tsk:%d\n",*(int*)log->buf));
|
---|
| 545 | break;
|
---|
| 546 |
|
---|
| 547 | case LOG_TYP_TSKEXC | LOG_LEAVE:
|
---|
| 548 | DebugOut(::wsprintfA(Buffer,"[TSKEXC|LEA] Tsk:%d\n",*(int*)log->buf));
|
---|
| 549 | break;
|
---|
| 550 |
|
---|
| 551 | case LOG_TYP_DISPATCH:
|
---|
| 552 | if(*((int*)log->buf+1) == 0)
|
---|
| 553 | DebugOut(::wsprintfA(Buffer,"[DSP|ENT] Tsk:%d Task-context\n",*(int*)log->buf));
|
---|
| 554 | else
|
---|
| 555 | DebugOut(::wsprintfA(Buffer,"[DSP|ENT] Tsk:%d Nontask-context\n",*(int*)log->buf));
|
---|
| 556 | break;
|
---|
| 557 |
|
---|
| 558 | case LOG_TYP_DISPATCH | LOG_LEAVE:
|
---|
| 559 | DebugOut(::wsprintfA(Buffer,"[DSP|LEA] Tsk:%d\n",*(int*)log->buf));
|
---|
| 560 | break;
|
---|
| 561 |
|
---|
| 562 | case LOG_TYP_COMMENT:
|
---|
| 563 | DebugOut(::wsprintfA(Buffer,"[COMMENT (%d)] : ",log->bufsz));
|
---|
| 564 | ::WriteFile(::GetStdHandle(STD_OUTPUT_HANDLE), log->buf, log->bufsz-1, &Count, NULL);
|
---|
| 565 | break;
|
---|
| 566 |
|
---|
| 567 | case LOG_TYP_INTERRUPT:
|
---|
| 568 | DebugOut(::wsprintfA(Buffer,"[INT|ENT] %d\n",*(int*)log->buf));
|
---|
| 569 | break;
|
---|
| 570 |
|
---|
| 571 | case LOG_TYP_INTERRUPT | LOG_LEAVE:
|
---|
| 572 | DebugOut(::wsprintfA(Buffer,"[INT|LEA] %d\n",*(int*)log->buf));
|
---|
| 573 | break;
|
---|
| 574 |
|
---|
| 575 | case LOG_TYP_CPUEXC:
|
---|
| 576 | DebugOut(::wsprintfA(Buffer,"[CPUEXC|ENT] Tsk:%d\n",*(int*)log->buf));
|
---|
| 577 | break;
|
---|
| 578 |
|
---|
| 579 | case LOG_TYP_CPUEXC | LOG_LEAVE:
|
---|
| 580 | DebugOut(::wsprintfA(Buffer,"[CPUEXC|LEA] Tsk:%d\n",*(int*)log->buf));
|
---|
| 581 | break;
|
---|
| 582 |
|
---|
| 583 | case LOG_TYP_TIMERHDR:
|
---|
| 584 | case LOG_TYP_TIMERHDR | LOG_LEAVE:
|
---|
| 585 | if((log->logtype & LOG_LEAVE) != 0)
|
---|
| 586 | DebugOut(::wsprintfA(Buffer,"[INT|LEA]"));
|
---|
| 587 | else
|
---|
| 588 | DebugOut(::wsprintfA(Buffer,"[INT|ENT]"));
|
---|
| 589 |
|
---|
| 590 | if( *(int*)log->buf == 0x8d )
|
---|
| 591 | DebugOut(::wsprintfA(Buffer," cyclic "));
|
---|
| 592 | else
|
---|
| 593 | DebugOut(::wsprintfA(Buffer," OBJ(%02x) ", *(int*)log->buf));
|
---|
| 594 |
|
---|
| 595 | DebugOut(::wsprintf(Buffer," ID:%d EXINF:0x%08x\n",*((int*)log->buf+1), *((int*)log->buf+2)));
|
---|
| 596 | break;
|
---|
| 597 |
|
---|
| 598 | default:
|
---|
| 599 | DebugOut(::wsprintfA(Buffer,"[UNKNOWN:0x%x]\n",log->logtype));
|
---|
| 600 | };
|
---|
| 601 | #endif
|
---|
| 602 |
|
---|
| 603 | if(Kernel != kernel)
|
---|
| 604 | {
|
---|
| 605 | DebugOut(::wsprintfA(Buffer,"Request performed by Illegal Kernel\n"));
|
---|
| 606 | return false;
|
---|
| 607 | }
|
---|
| 608 |
|
---|
| 609 | ::EnterCriticalSection(&cs);
|
---|
| 610 | scope = WatcherList.begin();
|
---|
| 611 | while(scope != WatcherList.end())
|
---|
| 612 | {
|
---|
| 613 | (*scope)->Fire_OnLogEvent(sz, data);
|
---|
| 614 | scope ++;
|
---|
| 615 | }
|
---|
| 616 | ::LeaveCriticalSection(&cs);
|
---|
| 617 |
|
---|
| 618 | return true;
|
---|
| 619 | }
|
---|
| 620 |
|
---|