5 #include <machine/vm.h>
7 #define K_STACK_SIZE I386_PAGE_SIZE
11 /* Hardware interrupt handlers. */
29 /* Exception handlers (real or protected mode), in numerical order. */
30 void int00(void), divide_error (void);
31 void int01(void), single_step_exception (void);
32 void int02(void), nmi (void);
33 void int03(void), breakpoint_exception (void);
34 void int04(void), overflow (void);
35 void int05(void), bounds_check (void);
36 void int06(void), inval_opcode (void);
37 void int07(void), copr_not_available (void);
38 void double_fault(void);
39 void copr_seg_overrun(void);
41 void segment_not_present(void);
42 void stack_exception(void);
43 void general_protection(void);
44 void page_fault(void);
45 void copr_error(void);
46 void alignment_check(void);
47 void machine_check(void);
48 void simd_exception(void);
50 void restore_user_context_int(struct proc
*);
51 void restore_user_context_sysenter(struct proc
*);
52 void restore_user_context_syscall(struct proc
*);
54 /* Software interrupt handlers, in numerical order. */
56 void ipc_entry_softint_orig(void);
57 void ipc_entry_softint_um(void);
58 void ipc_entry_sysenter(void);
59 void ipc_entry_syscall_cpu0(void);
60 void ipc_entry_syscall_cpu1(void);
61 void ipc_entry_syscall_cpu2(void);
62 void ipc_entry_syscall_cpu3(void);
63 void ipc_entry_syscall_cpu4(void);
64 void ipc_entry_syscall_cpu5(void);
65 void ipc_entry_syscall_cpu6(void);
66 void ipc_entry_syscall_cpu7(void);
67 void kernel_call_entry_orig(void);
68 void kernel_call_entry_um(void);
69 void level0_call(void);
72 struct exception_frame
{
73 reg_t vector
; /* which interrupt vector was triggered */
74 reg_t errcode
; /* zero if no exception does not push err code */
78 reg_t esp
; /* undefined if trap is nested */
79 reg_t ss
; /* undefined if trap is nested */
82 void exception(struct exception_frame
* frame
);
85 __dead
void monitor(void);
86 __dead
void reset(void);
87 __dead
void x86_triplefault(void);
90 void write_cr0(unsigned long value
);
91 unsigned long read_cr4(void);
92 void write_cr4(unsigned long value
);
93 void write_cr3(unsigned long value
);
94 unsigned long read_cpu_flags(void);
95 phys_bytes
vir2phys(void *);
96 void phys_insb(u16_t port
, phys_bytes buf
, size_t count
);
97 void phys_insw(u16_t port
, phys_bytes buf
, size_t count
);
98 void phys_outsb(u16_t port
, phys_bytes buf
, size_t count
);
99 void phys_outsw(u16_t port
, phys_bytes buf
, size_t count
);
100 u32_t
read_cr3(void);
101 void reload_cr3(void);
102 void i386_invlpg(phys_bytes linaddr
);
103 vir_bytes
phys_memset(phys_bytes ph
, u32_t c
, phys_bytes bytes
);
104 void reload_ds(void);
105 void ia32_msr_read(u32_t reg
, u32_t
* hi
, u32_t
* lo
);
106 void ia32_msr_write(u32_t reg
, u32_t hi
, u32_t lo
);
112 int __fxrstor_end(void *);
114 int __frstor_end(void *);
115 int __frstor_failure(void *);
116 unsigned short fnstsw(void);
117 void fnstcw(unsigned short* cw
);
118 void x86_lgdt(void *);
119 void x86_lldt(u32_t
);
121 void x86_lidt(void *);
122 void x86_load_kerncs(void);
123 void x86_load_ds(u32_t
);
124 void x86_load_ss(u32_t
);
125 void x86_load_es(u32_t
);
126 void x86_load_fs(u32_t
);
127 void x86_load_gs(u32_t
);
129 /* ipc functions in usermapped_ipc.S */
130 int usermapped_send_softint(endpoint_t dest
, message
*m_ptr
);
131 int usermapped_receive_softint(endpoint_t src
, message
*m_ptr
, int *status_ptr
);
132 int usermapped_sendrec_softint(endpoint_t src_dest
, message
*m_ptr
);
133 int usermapped_sendnb_softint(endpoint_t dest
, message
*m_ptr
);
134 int usermapped_notify_softint(endpoint_t dest
);
135 int usermapped_do_kernel_call_softint(message
*m_ptr
);
136 int usermapped_senda_softint(asynmsg_t
*table
, size_t count
);
138 int usermapped_send_syscall(endpoint_t dest
, message
*m_ptr
);
139 int usermapped_receive_syscall(endpoint_t src
, message
*m_ptr
, int *status_ptr
);
140 int usermapped_sendrec_syscall(endpoint_t src_dest
, message
*m_ptr
);
141 int usermapped_sendnb_syscall(endpoint_t dest
, message
*m_ptr
);
142 int usermapped_notify_syscall(endpoint_t dest
);
143 int usermapped_do_kernel_call_syscall(message
*m_ptr
);
144 int usermapped_senda_syscall(asynmsg_t
*table
, size_t count
);
146 int usermapped_send_sysenter(endpoint_t dest
, message
*m_ptr
);
147 int usermapped_receive_sysenter(endpoint_t src
, message
*m_ptr
, int *status_ptr
);
148 int usermapped_sendrec_sysenter(endpoint_t src_dest
, message
*m_ptr
);
149 int usermapped_sendnb_sysenter(endpoint_t dest
, message
*m_ptr
);
150 int usermapped_notify_sysenter(endpoint_t dest
);
151 int usermapped_do_kernel_call_sysenter(message
*m_ptr
);
152 int usermapped_senda_sysenter(asynmsg_t
*table
, size_t count
);
154 void switch_k_stack(void * esp
, void (* continuation
)(void));
156 void __switch_address_space(struct proc
* p
, struct proc
** __ptproc
);
157 #define switch_address_space(proc) \
158 __switch_address_space(proc, get_cpulocal_var_ptr(ptproc))
160 void refresh_tlb(void);
163 void multiboot_init(void);
168 reg_t sp0
; /* stack pointer to use during interrupt */
169 reg_t ss0
; /* " segment " " " " */
195 } __attribute__((packed
));
197 void enable_iop(struct proc
*pp
);
202 void add_memmap(kinfo_t
*cbi
, u64_t addr
, u64_t len
);
203 phys_bytes
alloc_lowest(kinfo_t
*cbi
, phys_bytes len
);
204 void vm_enable_paging(void);
205 void cut_memmap(kinfo_t
*cbi
, phys_bytes start
, phys_bytes end
);
206 phys_bytes
pg_roundup(phys_bytes b
);
207 void pg_info(reg_t
*, u32_t
**);
209 void pg_identity(kinfo_t
*);
210 phys_bytes
pg_load(void);
211 void pg_map(phys_bytes phys
, vir_bytes vaddr
, vir_bytes vaddr_end
, kinfo_t
*cbi
);
212 int pg_mapkernel(void);
213 void pg_mapproc(struct proc
*p
, struct boot_image
*ip
, kinfo_t
*cbi
);
215 /* prototype of an interrupt vector table entry */
216 struct gate_table_s
{
218 unsigned char vec_nr
;
219 unsigned char privilege
;
222 /* copies an array of vectors to the IDT. The last vector must be zero filled */
223 void idt_copy_vectors(struct gate_table_s
* first
);
224 void idt_copy_vectors_pic(void);
225 void idt_reload(void);
227 EXTERN
void * k_stacks_start
;
228 extern void * k_stacks
;
230 #define get_k_stack_top(cpu) ((void *)(((char*)(k_stacks)) \
231 + 2 * ((cpu) + 1) * K_STACK_SIZE))
234 #define barrier() do { mfence(); } while(0)
238 /* call a function to read the stack fram pointer (%ebp) */
239 reg_t
read_ebp(void);
240 #define get_stack_frame(__X) ((reg_t)read_ebp())
242 /* read %ebp directly */
243 #define get_stack_frame(__X) ((reg_t)__builtin_frame_address(0))
247 * sets up TSS for a cpu and assigns kernel stack and cpu id
249 int tss_init(unsigned cpu
, void * kernel_stack
);
251 void int_gate_idt(unsigned vec_nr
, vir_bytes offset
, unsigned dpl_type
);
253 void __copy_msg_from_user_end(void);
254 void __copy_msg_to_user_end(void);
255 void __user_copy_msg_pointer_failure(void);
257 int platform_tbl_checksum_ok(void *ptr
, unsigned int length
);
258 int platform_tbl_ptr(phys_bytes start
, phys_bytes end
, unsigned
259 increment
, void * buff
, unsigned size
, phys_bytes
* phys_addr
, int ((*
263 int breakpoint_set(phys_bytes linaddr
, int bp
, const int flags
);
264 #define BREAKPOINT_COUNT 4
265 #define BREAKPOINT_FLAG_RW_MASK (3 << 0)
266 #define BREAKPOINT_FLAG_RW_EXEC (0 << 0)
267 #define BREAKPOINT_FLAG_RW_WRITE (1 << 0)
268 #define BREAKPOINT_FLAG_RW_RW (2 << 0)
269 #define BREAKPOINT_FLAG_LEN_MASK (3 << 2)
270 #define BREAKPOINT_FLAG_LEN_1 (0 << 2)
271 #define BREAKPOINT_FLAG_LEN_2 (1 << 2)
272 #define BREAKPOINT_FLAG_LEN_4 (2 << 2)
273 #define BREAKPOINT_FLAG_MODE_MASK (3 << 4)
274 #define BREAKPOINT_FLAG_MODE_OFF (0 << 4)
275 #define BREAKPOINT_FLAG_MODE_LOCAL (1 << 4)
276 #define BREAKPOINT_FLAG_MODE_GLOBAL (2 << 4)
278 /* functions defined in architecture-independent kernel source. */
279 #include "kernel/proto.h"
281 #endif /* __ASSEMBLY__ */