rust-embedded / aarch64-cpu

Low level access to processors using the AArch64 execution state.
Apache License 2.0
73 stars 26 forks source link

Construct a register class from previously got `u64` value? #25

Closed zhouhaoan closed 7 months ago

zhouhaoan commented 10 months ago

I got a u64 register value from get() method. But when I want to parse the value to get specify fields, I can't use those API in the crate. Moreover, it seems that register modules and structs doesn't implement From<u64> trait. Are there some way to parse previously read values? Or just get values and read fields from raw registers?

vbe0201 commented 10 months ago

You could use the read() method on Field instances to extract bitfields out of raw integer values:

use aarch64_cpu::registers::*;

// Read the value of the register once
let esr = ESR_EL1.get();

// Extract fields from the `u64`
let ec = ESR_EL1::EC.read(esr);
let iss = ESR_EL1::ISS.read(esr);
nchong-at-aws commented 7 months ago

Closing as I think vbe0201's answer is what you need. Please reopen if that's not the case.