aboutsummaryrefslogtreecommitdiff
path: root/mirai/crimson/context/capture.zig
blob: 896d1a6eb4979ad5c55143e2d814d6a9b0f8d4d9 (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
//! Capture CPU Context

const asm_cpu = @import("../../asm/cpu/cpu.zig");
const types = @import("../types/types.zig");
const Context = types.Context;
const Frame = types.Frame;

pub fn capture_from_frame(context: *Context, frame: *const Frame) void {
    context.rip = frame.rip;
    context.cs = @truncate(frame.cs);
    context.rflags = frame.rflags;
    context.rsp = frame.rsp;
    context.ss = @truncate(frame.ss);
    context.cr0 = asm_cpu.read_cr0();
    context.cr2 = asm_cpu.read_cr2();
    context.cr3 = asm_cpu.read_cr3();
    context.cr4 = asm_cpu.read_cr4();
}

pub fn capture_segments(context: *Context) void {
    context.ds = asm_cpu.read_ds();
    context.es = asm_cpu.read_es();
    context.fs = asm_cpu.read_fs();
    context.gs = asm_cpu.read_gs();
}