1int
2main (int argc, char **argv)
3{
4  // Since MPX is disabled all these are just NOPS.
5  // Some of these instructions are just random.
6  // Once the GCC support is merged creating real test cases will be easier.
7  // http://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler
8
9  // This is what ld.so does in _dl_runtime_resolve to save the bnds.
10  asm ("bndmov %bnd0, (%rsp)");
11  asm ("bndmov %bnd1, 16(%rsp)");
12  asm ("bndmov %bnd2, 32(%rsp)");
13  asm ("bndmov %bnd3, 48(%rsp)");
14
15  // Create a bnd, check lower and upper...
16  asm ("bndmk (%rax,%rdx), %bnd0");
17  asm ("bndcl (%rax,%rdi,4), %bnd0");
18  asm ("bndcu 3(%rax,%rdi,4), %bnd0");
19  asm ("bndcn 3(%rax,%rdi,4), %bnd0");
20
21  // Load bnd pointer and update...
22  asm ("bndldx 3(%rbx,%rdx), %bnd2");
23  asm ("bndstx %bnd2, 3(,%r12,1)");
24
25  // "bnd" prefixed call, return and jmp...
26  asm ("bnd call foo\n\
27        bnd jmp  end\n\
28        foo: bnd ret\n\
29        end: nop");
30
31  // And set the bnds back...
32  asm ("bndmov 48(%rsp), %bnd3");
33  asm ("bndmov 32(%rsp), %bnd2");
34  asm ("bndmov 16(%rsp), %bnd1");
35  asm ("bndmov (%rsp), %bnd0");
36
37  return 0;
38}
39