Files
magenta/arch/x86_64/include/mango/machine/cpu.h
T

74 lines
1.7 KiB
C
Raw Normal View History

2024-11-02 11:31:51 +00:00
#ifndef MANGO_X86_64_CPU_H_
#define MANGO_X86_64_CPU_H_
#include <arch/gdt.h>
2023-02-08 20:24:40 +00:00
#include <arch/irq.h>
2026-02-08 11:36:16 +00:00
#include <arch/tss.h>
#include <mango/types.h>
2023-03-20 20:41:39 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2026-02-08 11:36:16 +00:00
#define ML_BIG_ENDIAN 0
2023-07-08 22:14:31 +01:00
2026-02-08 11:36:16 +00:00
#define ml_cpu_block_get_id(p) ((p)->c_cpu_id)
2023-03-28 21:38:47 +01:00
#define ml_cpu_block_get_data(p) ((p)->c_data)
2026-02-08 11:36:16 +00:00
#if 0
#define ml_read_sp(sp, bp) \
asm volatile("mov %%rsp, %0" : "=r"(sp)); \
asm volatile("mov %%rbp, %0" : "=r"(bp));
#endif
2023-03-28 21:38:47 +01:00
struct cpu_data;
2022-12-24 10:28:41 +00:00
typedef struct ml_cpu_block {
struct ml_cpu_block *c_this;
2022-12-24 10:28:41 +00:00
struct gdt c_gdt;
struct gdt_ptr c_gdt_ptr;
2023-02-08 20:24:40 +00:00
struct tss c_tss;
struct tss_ptr c_tss_ptr;
2023-02-08 20:24:40 +00:00
struct idt_ptr c_idt_ptr;
unsigned int c_cpu_id;
2023-03-28 21:38:47 +01:00
struct cpu_data *c_data;
} ml_cpu_block;
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")
2022-12-24 10:28:41 +00:00
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);
2023-03-20 20:41:39 +00:00
#ifdef __cplusplus
}
#endif
#endif