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 /* Software interrupt handlers, in numerical order. */
53 void kernel_call_entry(void);
54 void level0_call(void);
57 struct exception_frame
{
58 reg_t vector
; /* which interrupt vector was triggered */
59 reg_t errcode
; /* zero if no exception does not push err code */
63 reg_t esp
; /* undefined if trap is nested */
64 reg_t ss
; /* undefined if trap is nested */
67 void exception(struct exception_frame
* frame
);
70 __dead
void monitor(void);
71 __dead
void reset(void);
72 __dead
void x86_triplefault(void);
75 void write_cr0(unsigned long value
);
76 unsigned long read_cr4(void);
77 void write_cr4(unsigned long value
);
78 void write_cr3(unsigned long value
);
79 unsigned long read_cpu_flags(void);
80 phys_bytes
vir2phys(void *);
81 void phys_insb(u16_t port
, phys_bytes buf
, size_t count
);
82 void phys_insw(u16_t port
, phys_bytes buf
, size_t count
);
83 void phys_outsb(u16_t port
, phys_bytes buf
, size_t count
);
84 void phys_outsw(u16_t port
, phys_bytes buf
, size_t count
);
86 void reload_cr3(void);
87 void i386_invlpg(phys_bytes linaddr
);
88 vir_bytes
phys_memset(phys_bytes ph
, u32_t c
, phys_bytes bytes
);
90 void ia32_msr_read(u32_t reg
, u32_t
* hi
, u32_t
* lo
);
91 void ia32_msr_write(u32_t reg
, u32_t hi
, u32_t lo
);
97 int __fxrstor_end(void *);
99 int __frstor_end(void *);
100 int __frstor_failure(void *);
101 unsigned short fnstsw(void);
102 void fnstcw(unsigned short* cw
);
103 void x86_lgdt(void *);
104 void x86_lldt(u32_t
);
106 void x86_lidt(void *);
107 void x86_load_kerncs(void);
108 void x86_load_ds(u32_t
);
109 void x86_load_ss(u32_t
);
110 void x86_load_es(u32_t
);
111 void x86_load_fs(u32_t
);
112 void x86_load_gs(u32_t
);
115 void switch_k_stack(void * esp
, void (* continuation
)(void));
117 void __switch_address_space(struct proc
* p
, struct proc
** __ptproc
);
118 #define switch_address_space(proc) \
119 __switch_address_space(proc, get_cpulocal_var_ptr(ptproc))
121 void refresh_tlb(void);
124 void multiboot_init(void);
129 reg_t sp0
; /* stack pointer to use during interrupt */
130 reg_t ss0
; /* " segment " " " " */
156 } __attribute__((packed
));
158 void enable_iop(struct proc
*pp
);
163 void add_memmap(kinfo_t
*cbi
, u64_t addr
, u64_t len
);
164 phys_bytes
alloc_lowest(kinfo_t
*cbi
, phys_bytes len
);
165 void vm_enable_paging(void);
166 void cut_memmap(kinfo_t
*cbi
, phys_bytes start
, phys_bytes end
);
167 phys_bytes
pg_roundup(phys_bytes b
);
168 void pg_info(reg_t
*, u32_t
**);
170 void pg_identity(kinfo_t
*);
171 phys_bytes
pg_load(void);
172 void pg_map(phys_bytes phys
, vir_bytes vaddr
, vir_bytes vaddr_end
, kinfo_t
*cbi
);
173 int pg_mapkernel(void);
174 void pg_mapproc(struct proc
*p
, struct boot_image
*ip
, kinfo_t
*cbi
);
176 /* prototype of an interrupt vector table entry */
177 struct gate_table_s
{
179 unsigned char vec_nr
;
180 unsigned char privilege
;
183 /* copies an array of vectors to the IDT. The last vector must be zero filled */
184 void idt_copy_vectors(struct gate_table_s
* first
);
185 void idt_copy_vectors_pic(void);
186 void idt_reload(void);
188 EXTERN
void * k_stacks_start
;
189 extern void * k_stacks
;
191 #define get_k_stack_top(cpu) ((void *)(((char*)(k_stacks)) \
192 + 2 * ((cpu) + 1) * K_STACK_SIZE))
195 #define barrier() do { mfence(); } while(0)
199 /* call a function to read the stack fram pointer (%ebp) */
200 reg_t
read_ebp(void);
201 #define get_stack_frame(__X) ((reg_t)read_ebp())
203 /* read %ebp directly */
204 #define get_stack_frame(__X) ((reg_t)__builtin_frame_address(0))
208 * sets up TSS for a cpu and assigns kernel stack and cpu id
210 int tss_init(unsigned cpu
, void * kernel_stack
);
212 void int_gate_idt(unsigned vec_nr
, vir_bytes offset
, unsigned dpl_type
);
214 void __copy_msg_from_user_end(void);
215 void __copy_msg_to_user_end(void);
216 void __user_copy_msg_pointer_failure(void);
218 int platform_tbl_checksum_ok(void *ptr
, unsigned int length
);
219 int platform_tbl_ptr(phys_bytes start
, phys_bytes end
, unsigned
220 increment
, void * buff
, unsigned size
, phys_bytes
* phys_addr
, int ((*
224 int breakpoint_set(phys_bytes linaddr
, int bp
, const int flags
);
225 #define BREAKPOINT_COUNT 4
226 #define BREAKPOINT_FLAG_RW_MASK (3 << 0)
227 #define BREAKPOINT_FLAG_RW_EXEC (0 << 0)
228 #define BREAKPOINT_FLAG_RW_WRITE (1 << 0)
229 #define BREAKPOINT_FLAG_RW_RW (2 << 0)
230 #define BREAKPOINT_FLAG_LEN_MASK (3 << 2)
231 #define BREAKPOINT_FLAG_LEN_1 (0 << 2)
232 #define BREAKPOINT_FLAG_LEN_2 (1 << 2)
233 #define BREAKPOINT_FLAG_LEN_4 (2 << 2)
234 #define BREAKPOINT_FLAG_MODE_MASK (3 << 4)
235 #define BREAKPOINT_FLAG_MODE_OFF (0 << 4)
236 #define BREAKPOINT_FLAG_MODE_LOCAL (1 << 4)
237 #define BREAKPOINT_FLAG_MODE_GLOBAL (2 << 4)
239 /* functions defined in architecture-independent kernel source. */
240 #include "kernel/proto.h"
242 #endif /* __ASSEMBLY__ */