@@ -38,6 +38,24 @@ struct BOOTINFO {
38
38
char * vram ;
39
39
};
40
40
41
+ struct SEGMENT_DESCRIPTOR {
42
+ short limit_low , base_low ;
43
+ char base_mid , access_right ;
44
+ char limit_high , base_high ;
45
+ };
46
+
47
+ struct GATE_DESCRIPTOR {
48
+ short offset_low , selector ;
49
+ char dw_count , access_right ;
50
+ short offset_high ;
51
+ };
52
+
53
+ void init_gdtidt (void );
54
+ void set_segmdesc (struct SEGMENT_DESCRIPTOR * sd , unsigned int limit , int base , int ar );
55
+ void set_gatedesc (struct GATE_DESCRIPTOR * gd , int offset , int selector , int ar );
56
+ void load_gdtr (int limit , int addr );
57
+ void load_idtr (int limit , int addr );
58
+
41
59
void HariMain (void )
42
60
{
43
61
struct BOOTINFO * binfo = (struct BOOTINFO * ) 0x0ff0 ;
@@ -217,4 +235,52 @@ void putblock8_8(char *vram, int vxsize, int pxsize,
217
235
}
218
236
}
219
237
return ;
220
- }
238
+ }
239
+
240
+ void init_gdtidt (void )
241
+ {
242
+ struct SEGMENT_DESCRIPTOR * gdt = (struct SEGMENT_DESCRIPTOR * ) 0x00270000 ;
243
+ struct GATE_DESCRIPTOR * idt = (struct GATE_DESCRIPTOR * ) 0x0026f800 ;
244
+ int i ;
245
+
246
+ /* GDT初始化 */
247
+ for (i = 0 ; i < 8192 ; i ++ ) {
248
+ set_segmdesc (gdt + i , 0 , 0 , 0 );
249
+ }
250
+ set_segmdesc (gdt + 1 , 0xffffffff , 0x00000000 , 0x4092 );
251
+ set_segmdesc (gdt + 2 , 0x0007ffff , 0x00280000 , 0x409a );
252
+ load_gdtr (0xffff , 0x00270000 );
253
+
254
+ /* IDT初始化 */
255
+ for (i = 0 ; i < 256 ; i ++ ) {
256
+ set_gatedesc (idt + i , 0 , 0 , 0 );
257
+ }
258
+ load_idtr (0x7ff , 0x0026f800 );
259
+
260
+ return ;
261
+ }
262
+
263
+ void set_segmdesc (struct SEGMENT_DESCRIPTOR * sd , unsigned int limit , int base , int ar )
264
+ {
265
+ if (limit > 0xfffff ) {
266
+ ar |= 0x8000 ; /* G_bit = 1 */
267
+ limit /= 0x1000 ;
268
+ }
269
+ sd -> limit_low = limit & 0xffff ;
270
+ sd -> base_low = base & 0xffff ;
271
+ sd -> base_mid = (base >> 16 ) & 0xff ;
272
+ sd -> access_right = ar & 0xff ;
273
+ sd -> limit_high = ((limit >> 16 ) & 0x0f ) | ((ar >> 8 ) & 0xf0 );
274
+ sd -> base_high = (base >> 24 ) & 0xff ;
275
+ return ;
276
+ }
277
+
278
+ void set_gatedesc (struct GATE_DESCRIPTOR * gd , int offset , int selector , int ar )
279
+ {
280
+ gd -> offset_low = offset & 0xffff ;
281
+ gd -> selector = selector ;
282
+ gd -> dw_count = (ar >> 8 ) & 0xff ;
283
+ gd -> access_right = ar & 0xff ;
284
+ gd -> offset_high = (offset >> 16 ) & 0xffff ;
285
+ return ;
286
+ }
0 commit comments