x86_64: rename struct cpu_context; move to machine/cpu.h

This commit is contained in:
2026-02-08 11:32:09 +00:00
parent c04b33647c
commit 564d4f9ba0
5 changed files with 23 additions and 21 deletions

View File

@@ -11,6 +11,8 @@ extern "C" {
#define NR_IDT_ENTRIES 256 #define NR_IDT_ENTRIES 256
struct ml_cpu_context;
enum irq_vector { enum irq_vector {
IRQ0 = 32, IRQ0 = 32,
IRQ1, IRQ1,
@@ -35,13 +37,6 @@ struct irq_hook {
int (*irq_callback)(void); int (*irq_callback)(void);
}; };
struct 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;
struct idt_entry { struct idt_entry {
uint16_t base_low; uint16_t base_low;
uint16_t selector; uint16_t selector;
@@ -64,7 +59,7 @@ struct idt_ptr {
uintptr_t i_base; uintptr_t i_base;
} __packed; } __packed;
typedef void (*int_hook)(struct cpu_context *); typedef void (*int_hook)(struct ml_cpu_context *);
extern int idt_init(struct idt_ptr *idtp); extern int idt_init(struct idt_ptr *idtp);
extern int idt_load(struct idt_ptr *idtp); extern int idt_load(struct idt_ptr *idtp);

View File

@@ -27,11 +27,18 @@ typedef struct ml_cpu_block {
struct cpu_data *c_data; struct cpu_data *c_data;
} ml_cpu_block; } ml_cpu_block;
#define ml_cpu_pause() __asm__ __volatile__("hlt") struct ml_cpu_context {
#define ml_cpu_relax() __asm__ __volatile__("pause") 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_disable() __asm__ __volatile__("cli")
#define ml_int_enable() __asm__ __volatile__("sti") #define ml_int_enable() __asm__ __volatile__("sti")
extern int ml_init_bootcpu(void); extern int ml_init_bootcpu(void);

View File

@@ -3,10 +3,10 @@
#include <stdint.h> #include <stdint.h>
struct cpu_context; struct ml_cpu_context;
extern void ml_print_cpu_state(struct cpu_context *ctx); extern void ml_print_cpu_state(struct ml_cpu_context *ctx);
extern void ml_print_stack_trace(uintptr_t ip); extern void ml_print_stack_trace(uintptr_t ip);
extern void ml_print_stack_trace_irq(struct cpu_context *ctx); extern void ml_print_stack_trace_irq(struct ml_cpu_context *ctx);
#endif #endif

View File

@@ -39,7 +39,7 @@ static void set_idt_gate(
idt->i_entries[index].reserved = 0; idt->i_entries[index].reserved = 0;
} }
static void gpf_handler(struct cpu_context *regs) static void gpf_handler(struct ml_cpu_context *regs)
{ {
int ext = regs->err_no & 1; int ext = regs->err_no & 1;
int table = (regs->err_no >> 1) & 0x03; int table = (regs->err_no >> 1) & 0x03;
@@ -55,7 +55,7 @@ static void gpf_handler(struct cpu_context *regs)
regs->rip); regs->rip);
} }
static void pf_handler(struct cpu_context *regs) static void pf_handler(struct ml_cpu_context *regs)
{ {
panic_irq( panic_irq(
regs, regs,
@@ -141,7 +141,7 @@ int idt_load(struct idt_ptr *ptr)
return 0; return 0;
} }
void isr_dispatch(struct cpu_context *regs) void isr_dispatch(struct ml_cpu_context *regs)
{ {
int_hook h = isr_handlers[regs->int_no]; int_hook h = isr_handlers[regs->int_no];
if (h) { if (h) {
@@ -160,7 +160,7 @@ void irq_ack(unsigned int vec)
outportb(0x20, 0x20); outportb(0x20, 0x20);
} }
void irq_dispatch(struct cpu_context *regs) void irq_dispatch(struct ml_cpu_context *regs)
{ {
end_charge_period(); end_charge_period();
@@ -178,7 +178,7 @@ void irq_dispatch(struct cpu_context *regs)
start_charge_period(); start_charge_period();
} }
void syscall_dispatch(struct cpu_context *regs) void syscall_dispatch(struct ml_cpu_context *regs)
{ {
} }

View File

@@ -91,7 +91,7 @@ static void print_rflags(uintptr_t rflags)
printk(buf); printk(buf);
} }
void ml_print_cpu_state(struct cpu_context *ctx) void ml_print_cpu_state(struct ml_cpu_context *ctx)
{ {
printk("cpu state:"); printk("cpu state:");
if (ctx) { if (ctx) {
@@ -173,7 +173,7 @@ void ml_print_stack_trace(uintptr_t ip)
print_stack_trace(ip, bp); print_stack_trace(ip, bp);
} }
void ml_print_stack_trace_irq(struct cpu_context *ctx) void ml_print_stack_trace_irq(struct ml_cpu_context *ctx)
{ {
print_stack_trace(ctx->rip, (uintptr_t *)ctx->rbp); print_stack_trace(ctx->rip, (uintptr_t *)ctx->rbp);
} }