78 lines
1.8 KiB
C
78 lines
1.8 KiB
C
#ifndef KERNEL_X86_64_CPU_H_
|
|
#define KERNEL_X86_64_CPU_H_
|
|
|
|
#include <arch/gdt.h>
|
|
#include <arch/irq.h>
|
|
#include <arch/tss.h>
|
|
#include <kernel/types.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define ML_BIG_ENDIAN 0
|
|
|
|
#define ml_cpu_block_get_id(p) ((p)->c_cpu_id)
|
|
#define ml_cpu_block_get_data(p) ((p)->c_data)
|
|
|
|
#if 0
|
|
#define ml_read_sp(sp, bp) \
|
|
asm volatile("mov %%rsp, %0" : "=r"(sp)); \
|
|
asm volatile("mov %%rbp, %0" : "=r"(bp));
|
|
#endif
|
|
|
|
struct cpu_data;
|
|
|
|
typedef struct ml_cpu_block {
|
|
struct ml_cpu_block *c_this;
|
|
|
|
struct gdt c_gdt;
|
|
struct gdt_ptr c_gdt_ptr;
|
|
|
|
struct tss c_tss;
|
|
struct tss_ptr c_tss_ptr;
|
|
|
|
struct idt_ptr c_idt_ptr;
|
|
unsigned int c_cpu_id;
|
|
|
|
struct cpu_data *c_data;
|
|
} ml_cpu_block;
|
|
|
|
struct ml_int_context {
|
|
uint64_t rip, cs, rflags, rsp, ss;
|
|
};
|
|
|
|
struct ml_cpu_context {
|
|
uint64_t r15, r14, r13, r12, r11, r10, r9, r8;
|
|
uint64_t rdi, rsi, rbp, unused_rsp, rbx, rdx, rcx, rax;
|
|
uint64_t int_no, err_no;
|
|
uint64_t rip, cs, rflags, rsp, ss;
|
|
} __packed;
|
|
|
|
#define ml_cpu_pause() __asm__ __volatile__("hlt")
|
|
#define ml_cpu_relax() __asm__ __volatile__("pause")
|
|
|
|
#define ml_int_disable() __asm__ __volatile__("cli")
|
|
#define ml_int_enable() __asm__ __volatile__("sti")
|
|
|
|
extern int ml_init_bootcpu(void);
|
|
|
|
extern int ml_cpu_block_init(ml_cpu_block *p);
|
|
extern int ml_cpu_block_use(ml_cpu_block *p);
|
|
|
|
extern virt_addr_t ml_cpu_block_get_ustack(ml_cpu_block *p);
|
|
extern virt_addr_t ml_cpu_block_get_kstack(ml_cpu_block *p);
|
|
|
|
extern void ml_cpu_block_set_ustack(ml_cpu_block *p, virt_addr_t sp);
|
|
extern void ml_cpu_block_set_kstack(ml_cpu_block *p, virt_addr_t sp);
|
|
|
|
/* defined in cpu_ctrl.S */
|
|
extern void ml_halt_cpu(void);
|
|
extern ml_cpu_block *ml_this_cpu(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|