1 /*
   2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.acme;
  27 
  28 import java.foreign.annotations.NativeAddressof;
  29 import java.foreign.annotations.NativeGetter;
  30 import java.foreign.annotations.NativeHeader;
  31 import java.foreign.annotations.NativeSetter;
  32 import java.foreign.annotations.NativeStruct;
  33 import java.foreign.memory.Pointer;
  34 import java.foreign.memory.Struct;
  35 
  36 @NativeHeader(path="bitfields.h")
  37 public interface bitfields_h { // platform dependent
  38 
  39     /*
  40     class bitfields1    size(24):
  41         +---
  42      0. | x (bitstart=0,nbits=2)
  43      8. | y (bitstart=0,nbits=15)
  44     16. | z (bitstart=0,nbits=20)
  45     20. | w (bitstart=0,nbits=13)
  46         +---
  47      */
  48 
  49 
  50     @NativeStruct("[" +
  51                     "u64=[" +
  52                         "i2(x)" +
  53                         "x62]" +
  54                     "u64=[" +
  55                         "i15(y)" +
  56                         "x49]" +
  57                     "u64=[" +
  58                         "i20(z)" +
  59                         "x12" +
  60                         "i13(w)" +
  61                         "x19]" +
  62                   "](bitfields1)")
  63     interface bitfields1 extends Struct<bitfields1> {
  64         @NativeGetter("x")
  65         long x$get();
  66         @NativeSetter("x")
  67         void x$set(long value);
  68         @NativeGetter("y")
  69         long y$get();
  70         @NativeSetter("y")
  71         void y$set(long value);
  72         @NativeGetter("z")
  73         int z$get();
  74         @NativeSetter("z")
  75         void z$set(int value);
  76         @NativeGetter("w")
  77         int w$get();
  78         @NativeSetter("w")
  79         void w$set(int value);
  80     }
  81 
  82     /*
  83     class bitfields2    size(16):
  84         +---
  85      0. | c (bitstart=0,nbits=3)
  86      0. | c2 (bitstart=3,nbits=3)
  87      1. | c3 (bitstart=0,nbits=7)
  88         | <alignment member> (size=2)
  89      4. | i (bitstart=0,nbits=4)
  90      8. | l (bitstart=0,nbits=21)
  91      8. | ll (bitstart=21,nbits=42)
  92         +---
  93      */
  94 
  95     @NativeStruct("[" +
  96                     "u64=[" +
  97                         "u3(c)" +
  98                         "u3(c2)" +
  99                         "x2" +
 100                         "u7(c3)" +
 101                         "x17" + // includes 2 byte alignment member
 102                         "i4(i)" +
 103                         "x28]" +
 104                     "u64=[" +
 105                         "i21(l)" +
 106                         "i42(ll)" +
 107                         "x1]" +
 108                   "](bitfields2)")
 109     interface bitfields2 extends Struct<bitfields2> {  // platform dependent
 110         @NativeGetter("c")
 111         byte c$get();
 112         @NativeSetter("c")
 113         void c$set(byte value);
 114         @NativeGetter("c2")
 115         byte c2$get();
 116         @NativeSetter("c2")
 117         void c2$set(byte value);
 118         @NativeGetter("c3")
 119         byte c3$get();
 120         @NativeSetter("c3")
 121         void c3$set(byte value);
 122         @NativeGetter("i")
 123         int i$get();
 124         @NativeSetter("i")
 125         void i$set(int value);
 126         @NativeGetter("l")
 127         long l$get();
 128         @NativeSetter("l")
 129         void l$set(long value);
 130         @NativeGetter("ll")
 131         long ll$get();
 132         @NativeSetter("ll")
 133         void ll$set(long value);
 134     }
 135 
 136     /*
 137     class bitfields3    size(20):
 138         +---
 139      0. | c1 (bitstart=0,nbits=4)
 140         | <alignment member> (size=3)
 141      4. | i (bitstart=0,nbits=20)
 142      8. | c2 (bitstart=0,nbits=8)
 143         | <alignment member> (size=3)
 144     12. | l1 (bitstart=0,nbits=32)
 145     16. | l2 (bitstart=0,nbits=32)
 146         +---
 147      */
 148 
 149     @NativeStruct("[" +
 150                     "u32=[" +
 151                         "u4(c1)" +
 152                         "x28]" + // includes 3 byte alignment member
 153                     "u32=[" +
 154                         "i20(i)" +
 155                         "x12]" +
 156                     "u32=[" +
 157                         "u8(c2)" +
 158                         "x24]" + // 3 byte alignment member
 159                     "u32=[" +
 160                         "i32(l1)]" +
 161                     "u32=[" +
 162                         "i32(l2)]" +
 163                   "](bitfields3)")
 164     interface bitfields3 extends Struct<bitfields3> {  // platform dependent
 165         @NativeGetter("c1")
 166         byte c1$get();
 167         @NativeSetter("c1")
 168         void c1$set(byte value);
 169         @NativeGetter("i")
 170         int i$get();
 171         @NativeSetter("i")
 172         void i$set(int value);
 173         @NativeGetter("c2")
 174         byte c2$get();
 175         @NativeSetter("c2")
 176         void c2$set(byte value);
 177         @NativeGetter("l1")
 178         int l1$get();
 179         @NativeSetter("l1")
 180         void l1$set(int value);
 181         @NativeGetter("l2")
 182         int l2$get();
 183         @NativeSetter("l2")
 184         void l2$set(int value);
 185     }
 186 
 187     @NativeStruct("[" +
 188                     "i64(l)" +
 189                     "u64=[" +
 190                         "u4(c)" +
 191                         "x60]" +
 192                   "](bitfields4)")
 193     interface bitfields4 extends Struct<bitfields4> {
 194         @NativeGetter("l")
 195         long l$get();
 196         @NativeSetter("l")
 197         void l$set(long value);
 198         @NativeAddressof("l")
 199         Pointer<Long> l$ptr();
 200         @NativeGetter("c")
 201         byte c$get();
 202         @NativeSetter("c")
 203         void c$set(byte value);
 204     }
 205 
 206     @NativeStruct("[" +
 207                     "u64=[" +
 208                         "u7(c)" +
 209                         "x57]" +
 210                     "u64=[" +
 211                         "i63(l)" +
 212                         "x1]" +
 213                   "](bitfields5)")
 214     interface bitfields5 extends Struct<bitfields5> {
 215         @NativeGetter("c")
 216         byte c$get();
 217         @NativeSetter("c")
 218         void c$set(byte value);
 219         @NativeGetter("l")
 220         long l$get();
 221         @NativeSetter("l")
 222         void l$set(long value);
 223     }
 224 
 225     @NativeStruct("[" +
 226                     "u8=[" +
 227                         "u4(c1)]|" +
 228                     "i32=[" +
 229                         "i20(i)]" +
 230                   "](bitfields6)")
 231     interface bitfields6 extends Struct<bitfields6> {
 232         @NativeGetter("c1")
 233         byte c1$get();
 234         @NativeSetter("c1")
 235         void c1$set(byte value);
 236         @NativeGetter("i")
 237         int i$get();
 238         @NativeSetter("i")
 239         void i$set(int value);
 240     }
 241 
 242     @NativeStruct("[" +
 243                      "u32(x)" +
 244                      "u32=[u15(a)u17(pad)]" +
 245                    "](bitfields7)")
 246     public interface bitfields7 extends Struct<bitfields7> {
 247          @NativeGetter("x")
 248          int x$get();
 249          @NativeSetter("x")
 250          void x$set(int value);
 251          @NativeAddressof("x")
 252          Pointer<Integer> x$ptr();
 253          @NativeGetter("a")
 254          int a$get();
 255          @NativeSetter("a")
 256          void a$set(int value);
 257          @NativeGetter("pad")
 258          int pad$get();
 259          @NativeSetter("pad")
 260          void pad$set(int value);
 261     }
 262 
 263     @NativeStruct("[" +
 264                   "i32(i)" +
 265                   "i32(j)" +
 266                   "](Point)")
 267     public interface Point extends Struct<Point> {
 268          @NativeGetter("i")
 269          int i$get();
 270          @NativeSetter("i")
 271          void i$set(int value);
 272          @NativeAddressof("i")
 273          Pointer<Integer> i$ptr();
 274          @NativeGetter("j")
 275          int j$get();
 276          @NativeSetter("j")
 277          void j$set(int value);
 278          @NativeAddressof("j")
 279          Pointer<Integer> j$ptr();
 280     }
 281 
 282     @NativeStruct("[" +
 283                       "${Point}(p)" +
 284                       "u32=[i12(x)i2(y)x18]" +
 285                    "](bitfields8)")
 286     public interface bitfields8 extends Struct<bitfields8> {
 287          @NativeGetter("p")
 288          Point p$get();
 289          @NativeSetter("p")
 290          void p$set(Point value);
 291          Pointer<Point> p$ptr();
 292          @NativeGetter("x")
 293          int x$get();
 294          @NativeSetter("x")
 295          void x$set(int value);
 296          @NativeGetter("y")
 297          int y$get();
 298          @NativeSetter("y")
 299          void y$set(int value);
 300     }
 301 
 302     @NativeStruct("[" +
 303                 "u32=[u1(x)x7u8(y)x16]" +
 304                 "i32(z)" +
 305             "](bitfields9)")
 306     public interface bitfields9 extends Struct<bitfields9> {
 307         @NativeGetter("x")
 308         int x$get();
 309         @NativeSetter("x")
 310         void x$set(int var1);
 311 
 312         @NativeGetter("y")
 313         int y$get();
 314         @NativeSetter("y")
 315         void y$set(int var1);
 316 
 317         @NativeGetter("z")
 318         int z$get();
 319         @NativeSetter("z")
 320         void z$set(int var1);
 321         @NativeAddressof("z")
 322         Pointer<Integer> z$ptr();
 323     }
 324 
 325     @NativeStruct("[u32=[u1(x)]|x64](bitfields10)")
 326     public interface bitfields10 extends Struct<bitfields10> {
 327         @NativeGetter("x")
 328         int x$get();
 329 
 330         @NativeSetter("x")
 331         void x$set(int var1);
 332     }
 333 
 334 }