#casting int to struct

1 messages · Page 1 of 1 (latest)

jaunty dome
#

Hey,
I'm trying to type cast a usize into a struct, somehow I don't get it to work.

any help would be appriciated



pmm.getPages(1) returns a usize

const PAGE_PTE = packed struct(u32) {
    PTE_PRESENT: u1 = 0, // 1 bit for Present (P)
    PTE_WRITABLE: u1 = 0, // 1 bit for Read/Write (RW)
    PTE_USER: u1 = 0, // 1 bit for User/Supervisor (U/S)
    PTE_WRITETHROUGH: u1 = 0, // 1 bit for Write-through (PWT)
    PTE_NOT_CACHEABLE: u1 = 0, // 1 bit for Cache Disable (PCD)
    PTE_ACCESSED: u1 = 0, // 1 bit for Accessed (A)
    PTE_DIRTY: u1 = 0, // 1 bit for Dirty (D)
    PTE_PAT: u1 = 0, // 1 bit for Page Attribute Table (PAT)
    PTE_CPU_GLOBAL: u1 = 0, // 1 bit for Global Page (G)
    PTE_AVL: u3 = 0, // 3 bits (AVL/UNUSED)
    PTE_FRAME: u20 = 0, // 20 bits for the frame address (physical page)
};
grim sorrel
#

what did you try? what was the error?

jaunty dome
grim sorrel
#

to convert between packed struct and integer you want @bitCast

jaunty dome
#

I guess a workaround could be to make PAGE_PTE a pointer, I'd prefer not to do that tho