1 /****************************************************************************
3 * SciTech OS Portability Manager Library
5 * ========================================================================
7 * The contents of this file are subject to the SciTech MGL Public
8 * License Version 1.0 (the "License"); you may not use this file
9 * except in compliance with the License. You may obtain a copy of
10 * the License at http://www.scitechsoft.com/mgl-license.txt
12 * Software distributed under the License is distributed on an
13 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * rights and limitations under the License.
17 * The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
19 * The Initial Developer of the Original Code is SciTech Software, Inc.
20 * All Rights Reserved.
22 * ========================================================================
27 * Description: MTRR helper functions module. To make it easier to implement
28 * the MTRR support under QNX, we simply put our ring 0 helper
29 * functions into stubs that run them at ring 0 using whatever
30 * mechanism is available.
32 ****************************************************************************/
39 #include <sys/neutrino.h>
40 #include <sys/syspage.h>
43 #include <sys/irqinfo.h>
46 /*--------------------------- Global variables ----------------------------*/
48 #define R0_FLUSH_TLB 0
50 #define R0_RESTORE_CR4 2
52 #define R0_WRITE_MSR 4
61 extern volatile R0_data _PM_R0;
63 /*----------------------------- Implementation ----------------------------*/
66 const struct sigevent * _ASMAPI _PM_ring0_isr(void *arg, int id);
68 pid_t far _ASMAPI _PM_ring0_isr();
71 /****************************************************************************
73 Return true if ring 0 (or if we can call the helpers functions at ring 0)
74 ****************************************************************************/
75 ibool _ASMAPI _MTRR_isRing0(void)
78 return false; // Not implemented yet!
84 /****************************************************************************
86 Function to execute a service at ring 0. This is done using the clock
87 interrupt handler since the code we attach to it will always run at ring 0.
88 ****************************************************************************/
89 static void CallRing0(void)
92 uint clock_intno = SYSPAGE_ENTRY(qtime)->intr;
94 uint clock_intno = 0; /* clock irq */
99 mlock((void*)&_PM_R0, sizeof(_PM_R0));
100 ThreadCtl(_NTO_TCTL_IO, 0);
103 if ((intrid = InterruptAttach(_NTO_INTR_CLASS_EXTERNAL | clock_intno,
104 _PM_ring0_isr, (void*)&_PM_R0, sizeof(_PM_R0), _NTO_INTR_FLAGS_END)) == -1) {
106 if ((intrid = qnx_hint_attach(clock_intno, _PM_ring0_isr, FP_SEG(&_PM_R0))) == -1) {
111 while (_PM_R0.service != -1)
114 InterruptDetachId(intrid);
116 qnx_hint_detach(intrid);
120 /****************************************************************************
122 Flush the translation lookaside buffer.
123 ****************************************************************************/
124 void PMAPI PM_flushTLB(void)
126 _PM_R0.service = R0_FLUSH_TLB;
130 /****************************************************************************
132 Read and return the value of the CR4 register
133 ****************************************************************************/
134 ulong _ASMAPI _MTRR_saveCR4(void)
136 _PM_R0.service = R0_SAVE_CR4;
141 /****************************************************************************
143 Restore the value of the CR4 register
144 ****************************************************************************/
145 void _ASMAPI _MTRR_restoreCR4(ulong cr4Val)
147 _PM_R0.service = R0_RESTORE_CR4;
152 /****************************************************************************
154 Read a machine status register for the CPU.
155 ****************************************************************************/
156 void _ASMAPI _MTRR_readMSR(
161 _PM_R0.service = R0_READ_MSR;
168 /****************************************************************************
170 Write a machine status register for the CPU.
171 ****************************************************************************/
172 void _ASMAPI _MTRR_writeMSR(
177 _PM_R0.service = R0_WRITE_MSR;