comparison packages/hal/i386/pc/current/src/plf_misc.c @ 76:435cced73e2f ecos-v1_3_1-release

eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
author jlarmour
date Tue, 28 Mar 2000 14:10:45 +0000
parents
children 6b5f480c6929
comparison
equal deleted inserted replaced
75:41bf073c0c32 76:435cced73e2f
1 //==========================================================================
2 //
3 // plf_misc.c
4 //
5 // HAL platform miscellaneous functions
6 //
7 //==========================================================================
8 //####COPYRIGHTBEGIN####
9 //
10 // -------------------------------------------
11 // The contents of this file are subject to the Red Hat eCos Public License
12 // Version 1.1 (the "License"); you may not use this file except in
13 // compliance with the License. You may obtain a copy of the License at
14 // http://www.redhat.com/
15 //
16 // Software distributed under the License is distributed on an "AS IS"
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
18 // License for the specific language governing rights and limitations under
19 // the License.
20 //
21 // The Original Code is eCos - Embedded Configurable Operating System,
22 // released September 30, 1998.
23 //
24 // The Initial Developer of the Original Code is Red Hat.
25 // Portions created by Red Hat are
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
27 // All Rights Reserved.
28 // -------------------------------------------
29 //
30 //####COPYRIGHTEND####
31 //==========================================================================
32 //#####DESCRIPTIONBEGIN####
33 //
34 // Author(s): nickg
35 // Contributors: nickg, jlarmour, pjo
36 // Date: 1999-01-21
37 // Purpose: HAL miscellaneous functions
38 // Description: This file contains miscellaneous functions provided by the
39 // HAL.
40 //
41 //####DESCRIPTIONEND####
42 //
43 //========================================================================*/
44
45 #include <pkgconf/hal.h>
46
47 #include <cyg/infra/cyg_type.h> // Base types
48 #include <cyg/infra/cyg_trac.h> // tracing macros
49 #include <cyg/infra/cyg_ass.h> // assertion macros
50
51 #include <cyg/hal/hal_arch.h> // architectural definitions
52
53 #include <cyg/hal/hal_intr.h> // Interrupt handling
54
55 #include <cyg/hal/hal_cache.h> // Cache handling
56
57 #include <cyg/hal/plf_misc.h>
58
59 #ifdef CYGPKG_KERNEL
60 #include <pkgconf/kernel.h>
61 #include <cyg/kernel/ktypes.h>
62 #include <cyg/kernel/kapi.h>
63 #endif /* CYGPKG_KERNEL */
64
65 /*------------------------------------------------------------------------*/
66
67 extern void patch_dbg_syscalls(void * vector);
68
69 /*------------------------------------------------------------------------*/
70 /* Floating point context switch support. */
71 /* NOTE: This code makes use of kernel API calls, which it should not do.*/
72 /* We need to rewrite this to make use of only HAL supplied facilites, */
73 /* this may require the addition of some extra HAL level support. */
74
75 #if !defined(CYGSEM_HAL_ROM_MONITOR)
76
77 volatile int hal_pc_fpe_interrupts = 0 ;
78 volatile int hal_pc_fpe_switches = 0 ;
79 volatile cyg_uint32 hal_pc_fpe_owner = 0 ;
80
81 cyg_uint32 hal_pc_fpe_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
82 {
83 return 2 ;
84 }
85
86 void hal_pc_fpe_dsr(CYG_ADDRWORD vector, cyg_ucount32 count, CYG_ADDRWORD data)
87 {
88 cyg_handle_t me ;
89 CYG_ADDRWORD stack ;
90 cyg_uint32 * p ;
91
92 hal_pc_fpe_interrupts++ ;
93
94 /* Gotta turn that darn interrupt off! Otherwise we're in a loop! */
95 asm("movl %%cr0, %%eax\n"
96 "andl $0xFFFFFFF7, %%eax\n"
97 "movl %%eax, %%cr0\n"
98 : /* No outputs. */
99 : /* No inputs. */
100 : "eax"
101 );
102
103 me = cyg_thread_self() ;
104
105 if (hal_pc_fpe_owner != me)
106 {
107 if (hal_pc_fpe_owner)
108 { /* Then save his state at the bottom of his stack. */
109 stack = cyg_thread_get_stack_base(hal_pc_fpe_owner) ;
110 p = (cyg_uint32*) stack ;
111 stack = (cyg_addrword_t) &(p[1]);
112 asm("movl %0, %%eax
113 fsave (%%eax)"
114 : /* No outputs. */
115 : "g" (stack)
116 : "eax") ;
117 p[0] = 0xCAFEBABE ;
118 }
119 hal_pc_fpe_owner = me ;
120 stack = cyg_thread_get_stack_base(hal_pc_fpe_owner) ;
121 p = (cyg_uint32*) stack ;
122 if (p[0] == 0xCAFEBABE)
123 {
124 stack = (cyg_addrword_t) &(p[1]) ;
125 asm("movl %0, %%eax\n"
126 "frstor (%%eax)\n"
127 : /* No outputs. */
128 : "g" (stack)
129 : "eax");
130 }
131
132 hal_pc_fpe_switches++ ;
133 }
134 }
135
136
137 cyg_interrupt hal_pc_fpe_interrupt_object ;
138 cyg_handle_t hal_pc_fpe_interrupt ;
139
140 #endif
141
142 /*------------------------------------------------------------------------*/
143
144 void hal_platform_init(void)
145 {
146
147 HAL_ICACHE_INVALIDATE_ALL();
148 HAL_ICACHE_ENABLE();
149 HAL_DCACHE_INVALIDATE_ALL();
150 HAL_DCACHE_ENABLE();
151
152 #if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT)
153 {
154 void hal_ctrlc_isr_init(void);
155 hal_ctrlc_isr_init();
156 }
157
158 #endif
159
160 #if defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) && \
161 defined(CYG_HAL_USE_ROM_MONITOR) && \
162 defined(CYG_HAL_USE_ROM_MONITOR_CYGMON)
163 {
164 patch_dbg_syscalls( (void *)(&hal_vsr_table[0]) );
165 }
166 #endif
167
168 #if !defined(CYGSEM_HAL_ROM_MONITOR)
169 /* Connect to the floating point interrupt. */
170 cyg_interrupt_create(CYGNUM_HAL_VECTOR_NO_DEVICE, 1, 0,
171 hal_pc_fpe_isr, hal_pc_fpe_dsr,
172 &hal_pc_fpe_interrupt, &hal_pc_fpe_interrupt_object);
173 cyg_interrupt_attach(hal_pc_fpe_interrupt);
174 #endif
175
176 }
177
178 /*------------------------------------------------------------------------*/
179
180 void hal_pc_reset(void)
181 {
182 /* Use Intel's IDT triple-fault trick. */
183 asm("movl $badIdt, %eax\n"
184 "lidt (%eax)\n"
185 "int $3\n"
186 "hlt\n"
187
188 ".align 4\n"
189
190 "badIdt:\n"
191 ".word 0\n"
192 ".long 0\n"
193 ) ;
194 }
195
196
197 /*------------------------------------------------------------------------*/
198 /* End of plf_misc.c */