一般保護例外の際の強制終了とスタック切り替えなどに対応。
harib18g相当。
@@ -181,7 +181,8 @@ | ||
181 | 181 | uint cons_app_hrb_start(uchar *cmdline) |
182 | 182 | { |
183 | 183 | uint i, j; |
184 | - char *p; | |
184 | + char *p, *q; | |
185 | + UI_Task *task = task_now(); | |
185 | 186 | |
186 | 187 | i = search_file(cmdline); |
187 | 188 | if(i == 0xFFFFFFFF){ |
@@ -191,6 +192,7 @@ | ||
191 | 192 | if(i != 0xFFFFFFFF){ |
192 | 193 | j = system.file.list[i].size; |
193 | 194 | p = system.io.mem.alloc(j); |
195 | + q = system.io.mem.alloc(64 * 1024); | |
194 | 196 | *((int *) 0x0fe0) = (int) p; |
195 | 197 | load_file(i, p); |
196 | 198 | if(j >= 8 && strncmp(p + 4, "Hari", 4) == 0){ |
@@ -201,9 +203,11 @@ | ||
201 | 203 | p[4] = 0x00; |
202 | 204 | p[5] = 0xcb; |
203 | 205 | } |
204 | - set_segmdesc(system.sys.gdt + 1003, j - 1, (int)p, AR_CODE32_ER); | |
205 | - farcall(0, 1003 * 8); | |
206 | + set_segmdesc(system.sys.gdt + 1003, j - 1, (int)p, AR_CODE32_ER + AR_APP); | |
207 | + set_segmdesc(system.sys.gdt + 1004, 64 * 1024 - 1, (int)q, AR_DATA32_RW + AR_APP); | |
208 | + start_app(0, 1003 * 8, 64 * 1024, 1004 * 8, &(task->tss.esp0)); | |
206 | 209 | system.io.mem.free(p, j); |
210 | + system.io.mem.free(q, 64 * 1024); | |
207 | 211 | return i; |
208 | 212 | } |
209 | 213 | return 0xFFFFFFFF; |
@@ -1,16 +1,21 @@ | ||
1 | 1 | |
2 | 2 | #include "core.h" |
3 | 3 | |
4 | -void hrb_api(uint edi, uint esi, uint ebp, uint esp, uint ebx, uint edx, uint ecx, uint eax) | |
4 | +uint hrb_api(uint edi, uint esi, uint ebp, uint esp, uint ebx, uint edx, uint ecx, uint eax) | |
5 | 5 | { |
6 | 6 | UI_Window *win = (UI_Window *) *((int *) 0x0fec); |
7 | 7 | DATA_Position2D *prompt = (DATA_Position2D *) *((int *) 0x0fe8); |
8 | 8 | DATA_Position2D *cursor = (DATA_Position2D *) *((int *) 0x0fe4); |
9 | 9 | uint app_cs_base = *((uint *) 0x0fe0); |
10 | + UI_Task *task = task_now(); | |
10 | 11 | if(edx == 1){ |
11 | 12 | cons_put_char(win, prompt, cursor, (uchar)(eax & 0xff)); |
12 | 13 | } else if(edx == 2){ |
13 | 14 | cons_put_str(win, prompt, cursor, (uchar *)(ebx + app_cs_base)); |
15 | + } else if(edx == 3){ | |
16 | + | |
17 | + } else if(edx == 4){ | |
18 | + return (uint)&(task->tss.esp0); | |
14 | 19 | } |
15 | - return; | |
20 | + return 0; | |
16 | 21 | } |
@@ -100,7 +100,7 @@ | ||
100 | 100 | "APP's SS " |
101 | 101 | }; |
102 | 102 | |
103 | -void cpu_exception_alert(int exception, int *esp) | |
103 | +void cpu_exception_abort(int exception, int *esp) | |
104 | 104 | { |
105 | 105 | int i; |
106 | 106 | char s[32]; |
@@ -130,163 +130,171 @@ | ||
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | +uint cpu_exception_fault(int exception, int *esp) | |
134 | +{ | |
135 | + UI_Task *task = task_now(); | |
136 | + | |
137 | + cons_put_str((UI_Window *) *((int *) 0x0fec), (DATA_Position2D *) *((int *) 0x0fe8), (DATA_Position2D *) *((int *) 0x0fe4), (uchar *)cpu_exceptions[exception]); | |
138 | + return (uint)&(task->tss.esp0); | |
139 | +} | |
140 | + | |
133 | 141 | void inthandler00(int *esp) |
134 | 142 | { |
135 | - cpu_exception_alert(0x00, esp); | |
143 | + cpu_exception_abort(0x00, esp); | |
136 | 144 | } |
137 | 145 | |
138 | 146 | void inthandler01(int *esp) |
139 | 147 | { |
140 | - cpu_exception_alert(0x01, esp); | |
148 | + cpu_exception_abort(0x01, esp); | |
141 | 149 | } |
142 | 150 | |
143 | 151 | void inthandler02(int *esp) |
144 | 152 | { |
145 | - cpu_exception_alert(0x02, esp); | |
153 | + cpu_exception_abort(0x02, esp); | |
146 | 154 | } |
147 | 155 | |
148 | 156 | void inthandler03(int *esp) |
149 | 157 | { |
150 | - cpu_exception_alert(0x03, esp); | |
158 | + cpu_exception_abort(0x03, esp); | |
151 | 159 | } |
152 | 160 | |
153 | 161 | void inthandler04(int *esp) |
154 | 162 | { |
155 | - cpu_exception_alert(0x04, esp); | |
163 | + cpu_exception_abort(0x04, esp); | |
156 | 164 | } |
157 | 165 | |
158 | 166 | void inthandler05(int *esp) |
159 | 167 | { |
160 | - cpu_exception_alert(0x05, esp); | |
168 | + cpu_exception_abort(0x05, esp); | |
161 | 169 | } |
162 | 170 | |
163 | 171 | void inthandler06(int *esp) |
164 | 172 | { |
165 | - cpu_exception_alert(0x06, esp); | |
173 | + cpu_exception_abort(0x06, esp); | |
166 | 174 | } |
167 | 175 | |
168 | 176 | void inthandler07(int *esp) |
169 | 177 | { |
170 | - cpu_exception_alert(0x07, esp); | |
178 | + cpu_exception_abort(0x07, esp); | |
171 | 179 | } |
172 | 180 | |
173 | 181 | void inthandler08(int *esp) |
174 | 182 | { |
175 | - cpu_exception_alert(0x08, esp); | |
183 | + cpu_exception_abort(0x08, esp); | |
176 | 184 | } |
177 | 185 | |
178 | 186 | void inthandler09(int *esp) |
179 | 187 | { |
180 | - cpu_exception_alert(0x09, esp); | |
188 | + cpu_exception_abort(0x09, esp); | |
181 | 189 | } |
182 | 190 | |
183 | 191 | void inthandler0a(int *esp) |
184 | 192 | { |
185 | - cpu_exception_alert(0x0a, esp); | |
193 | + cpu_exception_abort(0x0a, esp); | |
186 | 194 | } |
187 | 195 | |
188 | 196 | void inthandler0b(int *esp) |
189 | 197 | { |
190 | - cpu_exception_alert(0x0b, esp); | |
198 | + cpu_exception_abort(0x0b, esp); | |
191 | 199 | } |
192 | 200 | |
193 | 201 | void inthandler0c(int *esp) |
194 | 202 | { |
195 | - cpu_exception_alert(0x0c, esp); | |
203 | + cpu_exception_abort(0x0c, esp); | |
196 | 204 | } |
197 | 205 | |
198 | 206 | void inthandler0d(int *esp) |
199 | 207 | { |
200 | - cpu_exception_alert(0x0d, esp); | |
208 | + cpu_exception_fault(0x0d, esp); | |
201 | 209 | } |
202 | 210 | |
203 | 211 | void inthandler0e(int *esp) |
204 | 212 | { |
205 | - cpu_exception_alert(0x0e, esp); | |
213 | + cpu_exception_abort(0x0e, esp); | |
206 | 214 | } |
207 | 215 | |
208 | 216 | void inthandler0f(int *esp) |
209 | 217 | { |
210 | - cpu_exception_alert(0x0f, esp); | |
218 | + cpu_exception_abort(0x0f, esp); | |
211 | 219 | } |
212 | 220 | |
213 | 221 | void inthandler10(int *esp) |
214 | 222 | { |
215 | - cpu_exception_alert(0x10, esp); | |
223 | + cpu_exception_abort(0x10, esp); | |
216 | 224 | } |
217 | 225 | |
218 | 226 | void inthandler11(int *esp) |
219 | 227 | { |
220 | - cpu_exception_alert(0x11, esp); | |
228 | + cpu_exception_abort(0x11, esp); | |
221 | 229 | } |
222 | 230 | |
223 | 231 | void inthandler12(int *esp) |
224 | 232 | { |
225 | - cpu_exception_alert(0x12, esp); | |
233 | + cpu_exception_abort(0x12, esp); | |
226 | 234 | } |
227 | 235 | |
228 | 236 | void inthandler13(int *esp) |
229 | 237 | { |
230 | - cpu_exception_alert(0x13, esp); | |
238 | + cpu_exception_abort(0x13, esp); | |
231 | 239 | } |
232 | 240 | |
233 | 241 | void inthandler14(int *esp) |
234 | 242 | { |
235 | - cpu_exception_alert(0x14, esp); | |
243 | + cpu_exception_abort(0x14, esp); | |
236 | 244 | } |
237 | 245 | |
238 | 246 | void inthandler15(int *esp) |
239 | 247 | { |
240 | - cpu_exception_alert(0x15, esp); | |
248 | + cpu_exception_abort(0x15, esp); | |
241 | 249 | } |
242 | 250 | |
243 | 251 | void inthandler16(int *esp) |
244 | 252 | { |
245 | - cpu_exception_alert(0x16, esp); | |
253 | + cpu_exception_abort(0x16, esp); | |
246 | 254 | } |
247 | 255 | |
248 | 256 | void inthandler17(int *esp) |
249 | 257 | { |
250 | - cpu_exception_alert(0x17, esp); | |
258 | + cpu_exception_abort(0x17, esp); | |
251 | 259 | } |
252 | 260 | |
253 | 261 | void inthandler18(int *esp) |
254 | 262 | { |
255 | - cpu_exception_alert(0x18, esp); | |
263 | + cpu_exception_abort(0x18, esp); | |
256 | 264 | } |
257 | 265 | |
258 | 266 | void inthandler19(int *esp) |
259 | 267 | { |
260 | - cpu_exception_alert(0x19, esp); | |
268 | + cpu_exception_abort(0x19, esp); | |
261 | 269 | } |
262 | 270 | |
263 | 271 | void inthandler1a(int *esp) |
264 | 272 | { |
265 | - cpu_exception_alert(0x1a, esp); | |
273 | + cpu_exception_abort(0x1a, esp); | |
266 | 274 | } |
267 | 275 | |
268 | 276 | void inthandler1b(int *esp) |
269 | 277 | { |
270 | - cpu_exception_alert(0x1b, esp); | |
278 | + cpu_exception_abort(0x1b, esp); | |
271 | 279 | } |
272 | 280 | |
273 | 281 | void inthandler1c(int *esp) |
274 | 282 | { |
275 | - cpu_exception_alert(0x1c, esp); | |
283 | + cpu_exception_abort(0x1c, esp); | |
276 | 284 | } |
277 | 285 | |
278 | 286 | void inthandler1d(int *esp) |
279 | 287 | { |
280 | - cpu_exception_alert(0x1d, esp); | |
288 | + cpu_exception_abort(0x1d, esp); | |
281 | 289 | } |
282 | 290 | |
283 | 291 | void inthandler1e(int *esp) |
284 | 292 | { |
285 | - cpu_exception_alert(0x1e, esp); | |
293 | + cpu_exception_abort(0x1e, esp); | |
286 | 294 | } |
287 | 295 | |
288 | 296 | void inthandler1f(int *esp) |
289 | 297 | { |
290 | - cpu_exception_alert(0x1f, esp); | |
298 | + cpu_exception_abort(0x1f, esp); | |
291 | 299 | } |
292 | 300 |
@@ -56,6 +56,9 @@ | ||
56 | 56 | hello2.hrb : hello2.nas Makefile |
57 | 57 | $(NASK) hello2.nas hello2.hrb hello2.lst |
58 | 58 | |
59 | +crack2.hrb : crack2.nas Makefile | |
60 | + $(NASK) crack2.nas crack2.hrb crack2.lst | |
61 | + | |
59 | 62 | a.bim : a.obj a_nask.obj Makefile |
60 | 63 | $(OBJ2BIM) @$(RULEFILE) out:a.bim map:a.map a.obj a_nask.obj |
61 | 64 |
@@ -68,6 +71,12 @@ | ||
68 | 71 | hello3.hrb : hello3.bim Makefile |
69 | 72 | $(BIM2HRB) hello3.bim hello3.hrb 0 |
70 | 73 | |
74 | +crack1.bim : crack1.obj a_nask.obj Makefile | |
75 | + $(OBJ2BIM) @$(RULEFILE) out:crack1.bim map:crack1.map crack1.obj a_nask.obj | |
76 | + | |
77 | +crack1.hrb : crack1.bim Makefile | |
78 | + $(BIM2HRB) crack1.bim crack1.hrb 0 | |
79 | + | |
71 | 80 | bootpack.bim : $(OBJS_BOOTPACK) Makefile |
72 | 81 | $(OBJ2BIM) @$(RULEFILE) out:bootpack.bim stack:3136k map:bootpack.map \ |
73 | 82 | $(OBJS_BOOTPACK) |
@@ -79,7 +88,7 @@ | ||
79 | 88 | chnos.sys : asmhead.bin bootpack.hrb Makefile |
80 | 89 | copy /B asmhead.bin+bootpack.hrb chnos.sys |
81 | 90 | |
82 | -chnos.img : chnipl.bin chnos.sys hello.hrb hello2.hrb hello3.hrb a.hrb Makefile | |
91 | +chnos.img : chnipl.bin chnos.sys hello.hrb hello2.hrb hello3.hrb crack1.hrb crack2.hrb a.hrb Makefile | |
83 | 92 | $(EDIMG) imgin:../../z_tools/fdimg0at.tek \ |
84 | 93 | wbinimg src:chnipl.bin len:512 from:0 to:0 \ |
85 | 94 | copy from:chnos.sys to:@: \ |
@@ -109,6 +118,8 @@ | ||
109 | 118 | copy from:hello2.hrb to:@: \ |
110 | 119 | copy from:a.hrb to:@: \ |
111 | 120 | copy from:hello3.hrb to:@: \ |
121 | + copy from:crack1.hrb to:@: \ | |
122 | + copy from:crack2.hrb to:@: \ | |
112 | 123 | imgout:chnos.img |
113 | 124 | |
114 | 125 | #一般規則 |
@@ -64,6 +64,7 @@ | ||
64 | 64 | #define AR_LDT 0x0082 |
65 | 65 | #define AR_TSS32 0x0089 |
66 | 66 | #define AR_INTGATE32 0x008e |
67 | +#define AR_APP 0x60 | |
67 | 68 | |
68 | 69 | #define MEMMAN_FREES 4096 |
69 | 70 |
@@ -475,7 +476,7 @@ | ||
475 | 476 | /*functions*/ |
476 | 477 | |
477 | 478 | /*api.c*/ |
478 | -void hrb_api(uint edi, uint esi, uint ebp, uint esp, uint ebx, uint edx, uint ecx, uint eax); | |
479 | +uint hrb_api(uint edi, uint esi, uint ebp, uint esp, uint ebx, uint edx, uint ecx, uint eax); | |
479 | 480 | |
480 | 481 | /*file.c*/ |
481 | 482 | void decode_fat(ushort *fat, bool backup); |
@@ -539,6 +540,7 @@ | ||
539 | 540 | |
540 | 541 | /*int.c*/ |
541 | 542 | void cpu_exception_alert(int exception, int *esp); |
543 | +uint cpu_exception_fault(int exception, int *esp); | |
542 | 544 | void init_pic(void); |
543 | 545 | void inthandler27(int *esp); |
544 | 546 |
@@ -0,0 +1,7 @@ | ||
1 | +void api_end(void); | |
2 | + | |
3 | +void CHNMain(void) | |
4 | +{ | |
5 | + *((char *)0x00102600) = 0; | |
6 | + api_end(); | |
7 | +} |
@@ -57,7 +57,7 @@ | ||
57 | 57 | set_gatedesc(idt+0x27, (int) asm_inthandler27, 2 * 8, AR_INTGATE32); |
58 | 58 | set_gatedesc(idt+0x2c, (int) asm_inthandler2c, 2 * 8, AR_INTGATE32); |
59 | 59 | |
60 | - set_gatedesc(idt+0x40, (int) asm_hrb_api, 2 * 8, AR_INTGATE32); | |
60 | + set_gatedesc(idt+0x40, (int) asm_hrb_api, 2 * 8, AR_INTGATE32 + AR_APP); | |
61 | 61 | |
62 | 62 | return; |
63 | 63 | } |
@@ -1,7 +1,8 @@ | ||
1 | 1 | void api_putchar(unsigned char c); |
2 | +void api_end(void); | |
2 | 3 | |
3 | 4 | void CHNMain(void) |
4 | 5 | { |
5 | 6 | api_putchar('A'); |
6 | - return; | |
7 | + api_end(); | |
7 | 8 | } |
@@ -1,4 +1,5 @@ | ||
1 | 1 | void api_putchar(unsigned char c); |
2 | +void api_end(void); | |
2 | 3 | |
3 | 4 | void CHNMain(void) |
4 | 5 | { |
@@ -8,5 +9,5 @@ | ||
8 | 9 | api_putchar('l'); |
9 | 10 | api_putchar('o'); |
10 | 11 | api_putchar('3'); |
11 | - return; | |
12 | + api_end(); | |
12 | 13 | } |