Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check correctness of byte order, bitfield order #2

Closed
ThomasWaldmann opened this issue Mar 11, 2018 · 5 comments
Closed

check correctness of byte order, bitfield order #2

ThomasWaldmann opened this issue Mar 11, 2018 · 5 comments

Comments

@ThomasWaldmann
Copy link
Collaborator

see TODO in tests/opcodes.py.

@ThomasWaldmann
Copy link
Collaborator Author

guess this could be done by assembling some very small sample program with binutils-esp32ulp assembler and looking at the resulting machine code.

@ThomasWaldmann
Copy link
Collaborator Author

BTW, NATIVE byte order was a bad idea. It would work when running on esp32, but we want to do development and run tests on the UNIX port, so we should replace that by the correct, specific byte order esp32 ulp processor expects.

@ThomasWaldmann
Copy link
Collaborator Author

ThomasWaldmann commented Mar 12, 2018

byte order fixed (hopefully): 9982807

TODO: bitfield order

When using C structs, is the first contained bitfield at MSB position and the last mentioned one closer to LSB (or ending at LSB, if all 32bits are used)?

@ThomasWaldmann
Copy link
Collaborator Author

#include <stdio.h>

typedef unsigned int uint32;

union {
    struct {
        uint32 lsb:1;
        uint32 middle:30;
        uint32 msb:1;
    } bits;
    uint32 word;
} U;

int main(){
    printf("%u\n", U.word);
    U.bits.msb = 0;
    U.bits.lsb = 1;
    printf("%u\n", U.word);
    U.bits.msb = 1;
    U.bits.lsb = 0;
    printf("%u\n", U.word);
};

Output:

$ ./test
0
1
2147483648

So, at least a gcc on linux amd64 fills in the bitfields into an uint from lsb to msb.

@ThomasWaldmann
Copy link
Collaborator Author

According to that, opcodes.make_ins_struct_def should be correct as it also starts from lsb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant