rellermeyer / course_os

CS 439 course OS
BSD 3-Clause "New" or "Revised" License
38 stars 26 forks source link

os_memset Undefined Instruction Exception #28

Closed lkolbly closed 9 years ago

lkolbly commented 9 years ago

Whenever I use os_memset the undefined instruction exception gets triggered a couple of times. This can be reproduced by putting the following code:

    char c[256];
    os_memset(c, 0, 256);

immediately after the init_vector_table function in start2 (in the master branch). Then boot the kernel, and near the top you should see:

Enabling MMU...
5
100
first_level_pt=204000
Got here
UNDEFINED INSTRUCTION HANDLER
UNDEFINED INSTRUCTION HANDLER
UNDEFINED INSTRUCTION HANDLER
UNDEFINED INSTRUCTION HANDLER
UNDEFINED INSTRUCTION HANDLER
MMU enabled

Does anyone have any idea what's going on?

lkolbly commented 9 years ago

Appears to be because in functions where char values are assigned to an int value (e.g. os_memcpy, __strchrnul) the compiler generates a uxtb instruction (zero-extend byte) which is not supported by QEMU. However, a patch was submitted to QEMU in February of 2015 https://lists.gnu.org/archive/html/qemu-devel/2015-02/msg04030.html

I don't believe this patch has become mainstream.

I worked around it in the virtual_memory branch (f842113606ba71c6d328beab73a105fdca4369de), it'll get merged in with master in due course.