aboutsummaryrefslogtreecommitdiff
path: root/mirai/crimson/panic/gather.zig
blob: dfdc658ff8ea136abb3c8cc6d27b81d6f66c86c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Gather System State

const asm_cpu = @import("../../asm/cpu/cpu.zig");
const types = @import("../types/types.zig");
const context_ops = @import("../context/context.zig");

const Context = types.Context;
const FloatState = types.FloatState;
const DebugState = types.DebugState;

pub fn capture_current_context(context: *Context) void {
    context.clear();

    context.cr0 = asm_cpu.read_cr0();
    context.cr2 = asm_cpu.read_cr2();
    context.cr3 = asm_cpu.read_cr3();
    context.cr4 = asm_cpu.read_cr4();

    context.rflags = asm_cpu.read_flags();
    context.rsp = asm_cpu.read_rsp();

    context_ops.capture_segments(context);
}

pub fn capture_float_state(state: *FloatState) void {
    context_ops.capture_float(state);
}

pub fn capture_debug_state(state: *DebugState) void {
    context_ops.capture_debug(state);
}

pub fn get_current_cpu() u32 {
    return 0;
}

pub fn get_uptime_ticks() u64 {
    return asm_cpu.rdtsc();
}