Question

I've encountered an unexpected "Invalid Opcode" exception being raised in my kernel code, that only appears when:

  1. running the code in QEMU (to be fair, I haven't actually tried any other emulators/hardware)

  2. the code is compiled with -O2 or higher. If compiled with -O0 or -O1, no exception is raised.

Obviously clang is outputting some opcodes that qemu doesn't support, but I'm unsure as to how to work around this. I'd like to avoid compiling with a lower optimization level, if possible.

The relevant code seems fairly innocuous - it's just filling values in an array of bitmaps:

for (uint32_t i = 0; i < kNumBitmapEntries; i++) {
    if (i > map_index) {
        bitmaps[i] = ~0;
    } else {
        bitmaps[i] = 0;
    }
}

Is there a way to enable/add the opcodes being generated to qemu?

Was it helpful?

Solution

The instructions being generated by clang required that SSE2 be enabled before they could be used. For anyone encountering a similar issue, SSE instructions can be enabled by following the SSE article on the osdev.org wiki.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top