1 | /* |
---|
2 | * Intel i386 Dependent Source |
---|
3 | * |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * All rights assigned to U.S. Government, 1994. |
---|
8 | * |
---|
9 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
10 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
11 | * notice must appear in all copies of this file and its derivatives. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #include <rtems/system.h> |
---|
17 | #include <rtems/fatal.h> |
---|
18 | #include <rtems/isr.h> |
---|
19 | #include <rtems/wkspace.h> |
---|
20 | |
---|
21 | /* _CPU_Initialize |
---|
22 | * |
---|
23 | * This routine performs processor dependent initialization. |
---|
24 | * |
---|
25 | * INPUT PARAMETERS: |
---|
26 | * cpu_table - CPU table to initialize |
---|
27 | * thread_dispatch - address of disptaching routine |
---|
28 | */ |
---|
29 | |
---|
30 | |
---|
31 | void _CPU_Initialize( |
---|
32 | rtems_cpu_table *cpu_table, |
---|
33 | void (*thread_dispatch) /* ignored on this CPU */ |
---|
34 | ) |
---|
35 | { |
---|
36 | register unsigned16 fp_status asm ("ax"); |
---|
37 | register unsigned8 *fp_context; |
---|
38 | |
---|
39 | if ( cpu_table == NULL ) |
---|
40 | rtems_fatal_error_occurred( RTEMS_NOT_CONFIGURED ); |
---|
41 | |
---|
42 | _CPU_Table = *cpu_table; |
---|
43 | |
---|
44 | /* |
---|
45 | * The following code saves a NULL i387 context which is given |
---|
46 | * to each task at start and restart time. The following code |
---|
47 | * is based upon that provided in the i386 Programmer's |
---|
48 | * Manual and should work on any coprocessor greater than |
---|
49 | * the i80287. |
---|
50 | * |
---|
51 | * NOTE: The NO RTEMS_WAIT form of the coprocessor instructions |
---|
52 | * MUST be used in case there is not a coprocessor |
---|
53 | * to wait for. |
---|
54 | */ |
---|
55 | |
---|
56 | fp_status = 0xa5a5; |
---|
57 | asm volatile( "fninit" ); |
---|
58 | asm volatile( "fnstsw %0" : "=a" (fp_status) : "0" (fp_status) ); |
---|
59 | |
---|
60 | if ( fp_status == 0 ) { |
---|
61 | |
---|
62 | fp_context = _CPU_Null_fp_context; |
---|
63 | |
---|
64 | asm volatile( "fsave (%0)" : "=r" (fp_context) |
---|
65 | : "0" (fp_context) |
---|
66 | ); |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | /* _CPU_ISR_install_vector |
---|
71 | * |
---|
72 | * This kernel routine installs the RTEMS handler for the |
---|
73 | * specified vector. |
---|
74 | * |
---|
75 | * Input parameters: |
---|
76 | * vector - interrupt vector number |
---|
77 | * old_handler - former ISR for this vector number |
---|
78 | * new_handler - replacement ISR for this vector number |
---|
79 | * |
---|
80 | * Output parameters: NONE |
---|
81 | * |
---|
82 | */ |
---|
83 | |
---|
84 | void _ISR_Handler_0(), _ISR_Handler_1(); |
---|
85 | |
---|
86 | #define PER_ISR_ENTRY \ |
---|
87 | (((unsigned32) _ISR_Handler_1 - (unsigned32) _ISR_Handler_0)) |
---|
88 | |
---|
89 | #define _Interrupt_Handler_entry( _vector ) \ |
---|
90 | (((unsigned32)_ISR_Handler_0) + ((_vector) * PER_ISR_ENTRY)) |
---|
91 | |
---|
92 | void _CPU_ISR_install_vector( |
---|
93 | unsigned32 vector, |
---|
94 | proc_ptr new_handler, |
---|
95 | proc_ptr *old_handler |
---|
96 | ) |
---|
97 | { |
---|
98 | i386_IDT_slot idt; |
---|
99 | unsigned32 unique_handler; |
---|
100 | |
---|
101 | /* calculate the unique entry point for this vector */ |
---|
102 | unique_handler = _Interrupt_Handler_entry( vector ); |
---|
103 | |
---|
104 | /* build the IDT entry */ |
---|
105 | idt.offset_0_15 = ((unsigned32) unique_handler) & 0xffff; |
---|
106 | idt.segment_selector = i386_get_cs(); |
---|
107 | idt.reserved = 0x00; |
---|
108 | idt.p_dpl = 0x8e; /* present, ISR */ |
---|
109 | idt.offset_16_31 = ((unsigned32) unique_handler) >> 16; |
---|
110 | |
---|
111 | /* install the IDT entry */ |
---|
112 | i386_Install_idt( |
---|
113 | (unsigned32) &idt, |
---|
114 | _CPU_Table.interrupt_table_segment, |
---|
115 | (unsigned32) _CPU_Table.interrupt_table_offset + (8 * vector) |
---|
116 | ); |
---|
117 | |
---|
118 | /* "portable" part */ |
---|
119 | *old_handler = _ISR_Vector_table[ vector ]; |
---|
120 | _ISR_Vector_table[ vector ] = new_handler; |
---|
121 | } |
---|