OSDN Git Service

import
[hos/hos-v4a.git] / cfgrtr / source / intstk.cpp
1 // ---------------------------------------------------------------------------
2 //  Hyper Operating System V4  コンフィギュレーター                           
3 //    HOS_INT_STK API の処理                                                  
4 //                                                                            
5 //                                    Copyright (C) 1998-2003 by Project HOS  
6 //                                    http://sourceforge.jp/projects/hos/     
7 // ---------------------------------------------------------------------------
8
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include "defercd.h"
14 #include "intstk.h"
15 #include "analyze.h"
16 #include "readcfg.h"
17
18
19 #define INTSTK_STKSZ            0
20 #define INTSTK_STK                      1
21
22
23 // コンストラクタ
24 CApiIntStack::CApiIntStack()
25 {
26         // パラメーター構文設定
27         m_iParamSyntax[0] = 0;          // 単独パラメーター
28         m_iParams = 2;
29
30         // スタックポインタ
31         m_szStackPointer[0] = '\0';
32 }
33
34
35 // デストラクタ
36 CApiIntStack::~CApiIntStack()
37 {
38 }
39
40
41 // 自動ID番号割り当て
42 int CApiIntStack::AutoId(void)
43 {
44         return CFG_ERR_OK;
45 }
46
47
48 // APIの解析
49 int CApiIntStack::AnalyzeApi(const char* pszApiName, const char* pszParams)
50 {
51         if ( strcmp(pszApiName, "KERNEL_INT_STK") == 0 )
52         {
53                 if ( m_iObjs > 0 )
54                 {
55                         return CFG_ERR_MULTIDEF;
56                 }
57
58                 if ( m_szStackPointer[0] != '\0' )
59                 {
60                         return CFG_ERR_DEF_CONFLICT;
61                 }
62
63                 return AddParams(pszParams);
64         }
65         else if ( strcmp(pszApiName, "KERNEL_INT_ISP") == 0 )
66         {
67                 if ( m_iObjs > 0 )
68                 {
69                         return CFG_ERR_DEF_CONFLICT;
70                 }
71
72                 if ( m_szStackPointer[0] != '\0' )
73                 {
74                         return CFG_ERR_MULTIDEF;
75                 }
76
77                 strcpy(m_szStackPointer, pszParams);
78                 return CFG_ERR_OK;
79         }
80
81         return CFG_ERR_NOPROC;
82 }
83
84
85 // cfgファイル定義部書き出し
86 void  CApiIntStack::WriteCfgDef(FILE* fp)
87 {
88         const char* pszSize;
89         const char* pszStack;
90         int i;
91
92         // パラメータ読み出し
93         if ( m_iObjs <= 0 && m_szStackPointer[0] == '\0' )
94         {
95                 return ;
96         }
97
98         // コメント出力
99         fputs(
100                 "\n\n\n"
101                 "/* ------------------------------------------ */\n"
102                 "/*             interrupt stack                */\n"
103                 "/* ------------------------------------------ */\n\n"
104                 , fp);
105
106         // 割り込み用スタックポインタ出力
107         if ( m_szStackPointer[0] != '\0' )
108         {
109                 fprintf(
110                         fp,
111                         "const VP _kernel_int_isp[1] = {(VP)(%s)};\t/* interrupt initial stack pointer */\n",
112                         m_szStackPointer);
113         }
114         else
115         {
116                 pszSize  = m_pParamPacks[0]->GetParam(INTSTK_STKSZ);
117                 pszStack = m_pParamPacks[0]->GetParam(INTSTK_STK);
118                 
119                 if ( strcmp(pszStack, "NULL") == 0 )
120                 {
121                         fprintf(
122                                 fp,
123                                 "VP         _kernel_int_stkblk[((%s) + sizeof(VP) - 1) / sizeof(VP)];\t/* interrupt stack block*/\n",
124                                 pszSize, _KERNE_INTSTK_NUM);
125                                 pszStack = "_kernel_int_stkblk";
126                 }
127                 else
128                 {
129                         fprintf(
130                                 fp,
131                                 "const VP _kernel_int_isp[1] = {(VP)((VB *)(%s) + (%s))};\t/* interrupt initial stack pointer */\n",
132                                 pszStack, pszSize);
133                 }
134
135                 fprintf(
136                         fp,
137                         "\n/* interrupt initial stack pointer */\n"
138                         "const VP   _kernel_int_isp[%d] =\n{\n",
139                         _KERNE_INTSTK_NUM);
140
141                 for ( i = 0; i < _KERNE_INTSTK_NUM; i++ )
142                 {
143                         fprintf(
144                                 fp,
145                                         "\t(VP)((VB *)(%s) + ((((%s) / %d) & ~(sizeof(VP) - 1)) * %d)),\n",
146                                         pszStack, pszSize, _KERNE_INTSTK_NUM, i+1);
147                 }
148
149                 fprintf(
150                         fp,
151                         "};\n\n");
152         }
153 }
154
155
156 // ---------------------------------------------------------------------------
157 //  Copyright (C) 1998-2006 by Project HOS                                    
158 // ---------------------------------------------------------------------------