[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,2001 by Embedded and Real-Time Systems Laboratory
|
---|
| 7 | * Toyohashi Univ. of Technology, JAPAN
|
---|
| 8 | * Copyright (C) 2002 by Monami software, Limited Partners.
|
---|
| 9 | * Copyright (C) 2008- by Monami Software Limited Partnership, JAPAN
|
---|
| 10 | *
|
---|
| 11 | * ä¸è¨èä½æ¨©è
|
---|
| 12 | ã¯ï¼ä»¥ä¸ã®(1)ã(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
| 13 | * ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
| 14 | * å¤ã»åé
|
---|
| 15 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 16 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 17 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 18 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 19 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 20 | * ç¨ã§ããå½¢ã§åé
|
---|
| 21 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 22 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 23 | * è
|
---|
| 24 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 25 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 26 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 27 | * ç¨ã§ããªãå½¢ã§åé
|
---|
| 28 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 29 | * ã¨ï¼
|
---|
| 30 | * (a) åé
|
---|
| 31 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 32 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 33 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 34 | * (b) åé
|
---|
| 35 | å¸ã®å½¢æ
|
---|
| 36 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 37 | * å ±åãããã¨ï¼
|
---|
| 38 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 39 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 40 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 41 | 責ãããã¨ï¼
|
---|
| 42 | * ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
| 43 | * ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 44 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
| 45 | * å
|
---|
| 46 | 責ãããã¨ï¼
|
---|
| 47 | *
|
---|
| 48 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 49 | ã
|
---|
| 50 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
| 51 | * ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
| 52 | * ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
| 53 | * ã®è²¬ä»»ãè² ããªãï¼
|
---|
| 54 | *
|
---|
| 55 | * @(#) $Id: cpu_config.c,v 1.1 2004/07/21 02:49:36 monaka Exp $
|
---|
| 56 | */
|
---|
| 57 |
|
---|
| 58 | /*
|
---|
| 59 | * ããã»ããµä¾åã¢ã¸ã¥ã¼ã«ï¼i386ç¨ï¼
|
---|
| 60 | */
|
---|
| 61 |
|
---|
| 62 | #include "jsp_kernel.h"
|
---|
| 63 | #include "check.h"
|
---|
| 64 | #include "task.h"
|
---|
| 65 | #include <i386.h>
|
---|
| 66 |
|
---|
| 67 | UW nest = 0; /* å²ãè¾¼ã¿ãã¹ãåæ° */
|
---|
| 68 | FP exc_table[0x20]; /* CPUä¾å¤ãã³ãã©ã®ãã¼ãã« */
|
---|
| 69 |
|
---|
| 70 | static SEGDESC gdt[3]; /* ã°ãã¼ãã«ãã£ã¹ã¯ãªãã¿ãã¼ãã« */
|
---|
| 71 | static GATEDESC idt[256]; /* å²ãè¾¼ã¿ãã£ã¹ã¯ãªãã¿ãã¼ãã« */
|
---|
| 72 |
|
---|
| 73 | /*
|
---|
| 74 | * ããã»ããµä¾åã®åæå
|
---|
| 75 | */
|
---|
| 76 | void
|
---|
| 77 | cpu_initialize()
|
---|
| 78 | {
|
---|
| 79 | DESCPTR desc_ptr;
|
---|
| 80 |
|
---|
| 81 | /* Flat model */
|
---|
| 82 | set_segment_descriptor(0, 0x0, 0x00000, 0x00, 0);
|
---|
| 83 | set_segment_descriptor(1, 0x0, 0xfffff, I386_TYPE_SEG_CODE | I386_TYPE_SEG_READABLE, 0);
|
---|
| 84 | set_segment_descriptor(2, 0x0, 0xfffff, I386_TYPE_SEG_DATA | I386_TYPE_SEG_WRITEABLE, 0);
|
---|
| 85 |
|
---|
| 86 | desc_ptr.limit = sizeof(gdt) - 1;
|
---|
| 87 | desc_ptr.base = (unsigned)gdt;
|
---|
| 88 |
|
---|
| 89 | Asm("movl %0, %%eax": : "g"(&desc_ptr) : "eax");
|
---|
| 90 | Asm("lgdt (%eax) \n"
|
---|
| 91 | "ljmp $0x8, $csinit \n" /* ãã¤ãã©ã¤ã³ã«å
|
---|
| 92 | èªã¿ããå½ä»¤ãã¯ãªã¢ãã */
|
---|
| 93 | "csinit: \n"
|
---|
| 94 | "movw $0x10, %ax \n"
|
---|
| 95 | "movw %ax, %ds \n"
|
---|
| 96 | "movw %ax, %es \n"
|
---|
| 97 | "movw %ax, %fs \n"
|
---|
| 98 | "movw %ax, %gs \n"
|
---|
| 99 | "movw %ax, %ss");
|
---|
| 100 |
|
---|
| 101 | set_gate_descriptor( 0, 0x8, exception0, I386_TYPE_GATE_INTR, 0);
|
---|
| 102 | set_gate_descriptor( 1, 0x8, exception1, I386_TYPE_GATE_INTR, 0);
|
---|
| 103 | set_gate_descriptor( 2, 0x8, exception2, I386_TYPE_GATE_INTR, 0);
|
---|
| 104 | set_gate_descriptor( 3, 0x8, exception3, I386_TYPE_GATE_INTR, 0);
|
---|
| 105 | set_gate_descriptor( 4, 0x8, exception4, I386_TYPE_GATE_INTR, 0);
|
---|
| 106 | set_gate_descriptor( 5, 0x8, exception5, I386_TYPE_GATE_INTR, 0);
|
---|
| 107 | set_gate_descriptor( 6, 0x8, exception6, I386_TYPE_GATE_INTR, 0);
|
---|
| 108 | set_gate_descriptor( 7, 0x8, exception7, I386_TYPE_GATE_INTR, 0);
|
---|
| 109 | set_gate_descriptor( 8, 0x8, exception8, I386_TYPE_GATE_INTR, 0);
|
---|
| 110 | set_gate_descriptor( 9, 0x8, exception9, I386_TYPE_GATE_INTR, 0);
|
---|
| 111 | set_gate_descriptor(10, 0x8, exception10, I386_TYPE_GATE_INTR, 0);
|
---|
| 112 | set_gate_descriptor(11, 0x8, exception11, I386_TYPE_GATE_INTR, 0);
|
---|
| 113 | set_gate_descriptor(12, 0x8, exception12, I386_TYPE_GATE_INTR, 0);
|
---|
| 114 | set_gate_descriptor(13, 0x8, exception13, I386_TYPE_GATE_INTR, 0);
|
---|
| 115 | set_gate_descriptor(14, 0x8, exception14, I386_TYPE_GATE_INTR, 0);
|
---|
| 116 | set_gate_descriptor(16, 0x8, exception16, I386_TYPE_GATE_INTR, 0);
|
---|
| 117 | set_gate_descriptor(17, 0x8, exception17, I386_TYPE_GATE_INTR, 0);
|
---|
| 118 | set_gate_descriptor(18, 0x8, exception18, I386_TYPE_GATE_INTR, 0);
|
---|
| 119 | set_gate_descriptor(19, 0x8, exception19, I386_TYPE_GATE_INTR, 0);
|
---|
| 120 |
|
---|
| 121 | desc_ptr.limit = sizeof(idt) - 1;
|
---|
| 122 | desc_ptr.base = (unsigned)idt;
|
---|
| 123 |
|
---|
| 124 | Asm("movl %0, %%eax " : : "g"(&desc_ptr) : "eax");
|
---|
| 125 | Asm("lidt (%eax) ");
|
---|
| 126 |
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | /*
|
---|
| 130 | * ããã»ããµä¾åã®çµäºå¦ç
|
---|
| 131 | */
|
---|
| 132 | void
|
---|
| 133 | cpu_terminate()
|
---|
| 134 | {
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 |
|
---|
| 138 | /*
|
---|
| 139 | * i386ã»ã°ã¡ã³ããã¹ã¯ãªãã¿ã®è¨å®
|
---|
| 140 | */
|
---|
| 141 | void
|
---|
| 142 | set_segment_descriptor(int sel, unsigned addr, unsigned limit, unsigned type, unsigned dpl)
|
---|
| 143 | {
|
---|
| 144 | SEGDESC *desc;
|
---|
| 145 | desc = &gdt[sel];
|
---|
| 146 | desc->base_L = (addr & 0xffffff);
|
---|
| 147 | desc->base_H = ((addr >> 24) & 0xff);
|
---|
| 148 | desc->limit_L = (limit & 0xffff);
|
---|
| 149 | desc->limit_H = ((limit >> 16) & 0xf);
|
---|
| 150 | desc->type = (type & 0xf);
|
---|
| 151 | desc->s = 1; /* code/data segment */
|
---|
| 152 | desc->dpl = dpl;
|
---|
| 153 | desc->p = 1; /* segment is existing */
|
---|
| 154 | desc->avl = 0; /* unused */
|
---|
| 155 | desc->x = 0; /* reserved */
|
---|
| 156 | desc->db = 1; /* 32bits segment */
|
---|
| 157 | desc->g = 1; /* 4KB limits */
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | void
|
---|
| 161 | set_gate_descriptor(int sel, unsigned selector, void *func, unsigned type, unsigned dpl)
|
---|
| 162 | {
|
---|
| 163 | GATEDESC *desc;
|
---|
| 164 | desc = &idt[sel];
|
---|
| 165 | desc->offset_L = ((unsigned)func & 0xffff);
|
---|
| 166 | desc->offset_H = (((unsigned)func >> 16) & 0xffff);
|
---|
| 167 | desc->selector = selector;
|
---|
| 168 | desc->copy = 0;
|
---|
| 169 | desc->type = type;
|
---|
| 170 | desc->s = 0;
|
---|
| 171 | desc->dpl = dpl;
|
---|
| 172 | desc->p = 1;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 |
|
---|
| 176 | void
|
---|
| 177 | define_exc(EXCNO excno, FP exchdr)
|
---|
| 178 | {
|
---|
| 179 | #if 0
|
---|
| 180 | if (inhno >= 0x20 || inthdr == NULL)
|
---|
| 181 | {
|
---|
| 182 | return; /*??? Should I generate assertion? */
|
---|
| 183 | }
|
---|
| 184 | #endif
|
---|
| 185 | exc_table[excno] = exchdr;
|
---|
| 186 | }
|
---|