1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: 16: 17: 18:
19:
20: #include "kernel.h"
21: #include "task.h"
22: #include "cpu_insn.h"
23:
24: EXPORT MONHDR SaveMonHdr;
25: EXPORT ATR available_cop;
26:
27: 28: 29:
30: EXPORT ER cpu_initialize( void )
31: {
32: IMPORT void dispatch_entry( void );
33: IMPORT void call_entry( void );
34: IMPORT void _tk_ret_int( void );
35: IMPORT void call_dbgspt( void );
36: IMPORT void rettex_entry( void );
37:
38: UW r;
39:
40:
41: SaveMonHdr.default_hdr = SCArea->intvec[VECNO_DEFAULT];
42: SaveMonHdr.idebug_hdr = SCArea->intvec[VECNO_IDEBUG];
43: SaveMonHdr.ddebug_hdr = SCArea->intvec[VECNO_DDEBUG];
44: SaveMonHdr.monitor_hdr = SCArea->intvec[VECNO_MONITOR];
45: SaveMonHdr.abortsw_hdr = SCArea->intvec[VECNO_ABORTSW];
46: SaveMonHdr.gio_hdr[0] = SCArea->intvec[VECNO_GIO0];
47: SaveMonHdr.gio_hdr[1] = SCArea->intvec[VECNO_GIO1];
48: SaveMonHdr.gio_hdr[2] = SCArea->intvec[VECNO_GIO2];
49: SaveMonHdr.gio_hdr[3] = SCArea->intvec[VECNO_GIO3];
50: SaveMonHdr.gio_hdr[4] = SCArea->intvec[VECNO_GIO4];
51: SaveMonHdr.gio_hdr[5] = SCArea->intvec[VECNO_GIO5];
52: SaveMonHdr.gio_hdr[6] = SCArea->intvec[VECNO_GIO6];
53: SaveMonHdr.gio_hdr[7] = SCArea->intvec[VECNO_GIO7];
54:
55:
56: Asm("mrc p15, 0, %0, cr2, c0, 1": "=r"(r));
57: Asm("mcr p15, 0, %0, cr2, c0, 0":: "r"(r));
58: Asm("mcr p15, 0, %0, cr13, c0, 1":: "r"(0));
59: ISB();
60: PurgeTLB();
61:
62:
63: available_cop = TA_NULL;
64:
65:
66: define_inthdr(SWI_SVC, call_entry);
67: define_inthdr(SWI_RETINT, _tk_ret_int);
68: define_inthdr(SWI_DISPATCH, dispatch_entry);
69: define_inthdr(SWI_RETTEX, rettex_entry);
70: #if USE_DBGSPT
71: define_inthdr(SWI_DEBUG, call_dbgspt);
72: #endif
73:
74: return E_OK;
75: }
76:
77: 78: 79:
80: EXPORT void cpu_shutdown( void )
81: {
82:
83: SCArea->intvec[VECNO_DEFAULT] = SaveMonHdr.default_hdr;
84: SCArea->intvec[VECNO_IDEBUG] = SaveMonHdr.idebug_hdr;
85: SCArea->intvec[VECNO_DDEBUG] = SaveMonHdr.ddebug_hdr;
86: SCArea->intvec[VECNO_MONITOR] = SaveMonHdr.monitor_hdr;
87: SCArea->intvec[VECNO_ABORTSW] = SaveMonHdr.abortsw_hdr;
88: SCArea->intvec[VECNO_GIO0] = SaveMonHdr.gio_hdr[0];
89: SCArea->intvec[VECNO_GIO1] = SaveMonHdr.gio_hdr[1];
90: SCArea->intvec[VECNO_GIO2] = SaveMonHdr.gio_hdr[2];
91: SCArea->intvec[VECNO_GIO3] = SaveMonHdr.gio_hdr[3];
92: SCArea->intvec[VECNO_GIO4] = SaveMonHdr.gio_hdr[4];
93: SCArea->intvec[VECNO_GIO5] = SaveMonHdr.gio_hdr[5];
94: SCArea->intvec[VECNO_GIO6] = SaveMonHdr.gio_hdr[6];
95: SCArea->intvec[VECNO_GIO7] = SaveMonHdr.gio_hdr[7];
96: }
97:
98:
99:
100: 101: 102:
103: EXPORT void request_tex( TCB *tcb )
104: {
105:
106: if ( tcb->isysmode == 0 ) {
107: tcb->reqdct = 1;
108: }
109: }
110:
111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129:
130: EXPORT void setup_texhdr( UW *ssp )
131: {
132: FP texhdr;
133: INT texcd;
134: UINT m;
135: UW *usp;
136:
137:
138:
139: ctxtsk->reqdct = 0;
140:
141:
142: m = 0x00000001;
143: for ( texcd = 0; texcd <= 31; texcd++ ) {
144: if ( (ctxtsk->exectex & m) != 0 ) break;
145: m <<= 1;
146: }
147: if ( texcd > 31 ) return;
148:
149: ctxtsk->exectex = 0;
150: ctxtsk->pendtex &= ~m;
151: ctxtsk->texflg |= ( texcd == 0 )? TEX0_RUNNING: TEX1_RUNNING;
152: texhdr = ctxtsk->texhdr;
153:
154:
155: Asm("stmia %0, {sp}^ ; nop":: "r"(&usp));
156:
157:
158: if ( texcd == 0 ) usp = ctxtsk->istack;
159:
160: usp -= 3;
161:
162:
163: Asm("ldmia %0, {sp}^ ; nop":: "r"(&usp));
164:
165: ENABLE_INTERRUPT;
166:
167: 168: 169: 170:
171: *(usp + 0) = texcd;
172: *(usp + 1) = *(ssp + 1);
173: *(usp + 2) = *(ssp + 2);
174: *(ssp + 1) = (UW)texhdr & ~1;
175: *(ssp + 2) &= ~(PSR_T|PSR_J);
176: if ( ((UW)texhdr & 1) != 0 ) *(ssp + 2) |= PSR_T;
177: }