forked from tenstorrent/whisper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPte.hpp
876 lines (674 loc) · 24.4 KB
/
Pte.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
// Copyright 2020 Western Digital Corporation or its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <cstdint>
#include <cassert>
namespace WdRiscv
{
/// Structure to unpack the fields of a 32-bit page table entry.
struct Pte32Bits
{
unsigned valid_ : 1;
unsigned read_ : 1;
unsigned write_ : 1;
unsigned exec_ : 1;
unsigned user_ : 1;
unsigned global_ : 1;
unsigned accessed_ : 1;
unsigned dirty_ : 1;
unsigned rsw_ : 2; // Reserved for supervisor.
unsigned ppn0_ : 10; // Physical page num
unsigned ppn1_ : 12; // Physical page num
} __attribute__((packed));
/// 32-bit page table entry.
union Pte32
{
Pte32Bits bits_;
uint32_t data_ = 0;
/// Constructor: Intialize from the the given data value.
Pte32(uint32_t word) : data_(word)
{ }
/// Return true if valid bit is on in this PTE.
bool valid() const { return bits_.valid_; }
/// Return true if read permission bit is on in this PTE.
bool read() const { return bits_.read_; }
/// Return true if write permission bit is on in this PTE.
bool write() const { return bits_.write_; }
/// Return true if execute permission bit is on in this PTE.
bool exec() const { return bits_.exec_; }
/// Return true if this PTE is marked for user privilege.
bool user() const { return bits_.user_; }
/// Return true if this PTE is marked global.
bool global() const { return bits_.global_; }
/// Return true if this PTE is marked accessed.
bool accessed() const { return bits_.accessed_; }
/// Return true if this PTE is marked dirty.
bool dirty() const { return bits_.dirty_; }
/// Return rsw value (reserved for supervisor).
uint64_t rsw() const { return bits_.rsw_; }
/// Return true if this PTE is a leaf.
bool leaf() const { return valid() and (read() or exec()); }
/// Physical page number in this PTE (see Sv32 PTE in the
/// privileged spec.)
uint32_t ppn() const { return ppn0() | (ppn1() << 10); }
/// Physical page number field 0 in this PTE (see Sv32 PTE in the
/// privileged spec.)
uint32_t ppn0() const { return bits_.ppn0_; }
/// Physical page number field 1 in this PTE (see Sv32 PTE in the
/// privileged spec.)
uint32_t ppn1() const { return bits_.ppn1_; }
/// Set physical page number field 0 in this PTE to v.
void setPpn0(unsigned v) { bits_.ppn0_ = v; }
/// Return reserved bits value. NA for Sv32.
static constexpr uint64_t res() { return 0; }
/// Number of levels of an Sv32 PTE.
static constexpr uint32_t levels() { return 2; }
/// Size in bytes of this object.
static constexpr uint32_t size() { return sizeof(data_); }
/// Page based memory type. NA for Sv32.
static constexpr uint32_t pbmt() { return 0; }
/// Naturally aligned power of 2 translation. NA for Sv32.
static constexpr bool hasNapot() { return false; }
/// Return the ith physical page number (PPN) field encoded in
/// this PTE. The index i must be smaller than the number of
/// levels of Sv32. See the Sv32 PTE in the privileged spec.
uint32_t ppn(int i) const
{
if (i == 0) return ppn0();
if (i == 1) return ppn1();
assert(0); return 0;
}
/// Set the physical phage number (ppn1,ppn0) to the least
/// significant 22 bits of value.
void setPpn(uint64_t value)
{ bits_.ppn0_ = value & 0x3ff; bits_.ppn1_ = (value >> 10) & 0xfff; }
/// Return the right shift amount to right justify the ith
/// physical page number (ppn) in a physical address for Sv32. The
/// index i must be smaller than the number of levels of Sv32. See
/// the Sv32 physical address in the privileged spec.
static constexpr uint32_t paPpnShift(int i)
{
if (i == 0) return 12;
if (i == 1) return 22;
assert(0); return 0;
}
};
/// Struct to unpack the fields of a page table entry for Sv39.
struct Pte39Bits
{
unsigned valid_ : 1;
unsigned read_ : 1;
unsigned write_ : 1;
unsigned exec_ : 1;
unsigned user_ : 1;
unsigned global_ : 1;
unsigned accessed_ : 1;
unsigned dirty_ : 1;
unsigned rsw_ : 2; // Reserved for supervisor.
unsigned ppn0_ : 9; // Physical page num
unsigned ppn1_ : 9; // Physical page num
unsigned ppn2_ : 26; // Physical page num
unsigned res_ : 7; // Reserved
unsigned pbmt_ : 2; // Page based memory type
unsigned n_ : 1;
} __attribute__((packed));
/// Page table entry for Sv39
union Pte39
{
Pte39Bits bits_;
uint64_t data_ = 0;
/// Constructor: Intialize from the the given data value.
Pte39(uint64_t data) : data_(data)
{ }
/// Return true if valid bit is on in this PTE.
bool valid() const { return bits_.valid_; }
/// Return true if read permission bit is on in this PTE.
bool read() const { return bits_.read_; }
/// Return true if write permission bit is on in this PTE.
bool write() const { return bits_.write_; }
/// Return true if execute permission bit is on in this PTE.
bool exec() const { return bits_.exec_; }
/// Return true if this PTE is marked for user privilege.
bool user() const { return bits_.user_; }
/// Return true if this PTE is marked global.
bool global() const { return bits_.global_; }
/// Return true if this PTE is marked accessed.
bool accessed() const { return bits_.accessed_; }
/// Return true if this PTE is marked dirty.
bool dirty() const { return bits_.dirty_; }
/// Return rsw value (reserved for supervisor).
uint64_t rsw() const { return bits_.rsw_; }
/// Return true if this PTE is a leaf.
bool leaf() const { return valid() and (read() or exec()); }
/// Physical page number in this PTE (see Sv39 PTE in the
/// privileged spec.)
uint64_t ppn() const { return ppn0() | (ppn1() << 9) | (ppn2() << 18); }
/// Physical page number field 0 in this PTE (see Sv39 PTE in the
/// privileged spec.)
uint64_t ppn0() const { return bits_.ppn0_; }
/// Physical page number field 1 in this PTE (see Sv39 PTE in the
/// privileged spec.)
uint64_t ppn1() const { return bits_.ppn1_; }
/// Physical page number field 2 in this PTE (see Sv39 PTE in the
/// privileged spec.)
uint64_t ppn2() const { return bits_.ppn2_; }
/// Set physical page number field 0 in this PTE to v.
void setPpn0(unsigned v) { bits_.ppn0_ = v; }
/// Return reserved bits value
uint64_t res() const { return bits_.res_; }
/// Number of levels of an Sv39 PTE.
static uint32_t levels() { return 3; }
/// Size in bytes of this object.
static uint32_t size() { return sizeof(data_); }
/// Page based memory type.
uint32_t pbmt() const { return bits_.pbmt_; }
/// Naturally aligned power of 2 translation.
bool hasNapot() const { return bits_.n_; }
/// Return the ith physical page number (PPN) field encoded in
/// this PTE. The index i must be smaller than the number of
/// levels of Sv39. See the Sv39 PTE in the privileged spec.
uint64_t ppn(int i) const
{
if (i == 0) { return ppn0(); }
if (i == 1) { return ppn1(); }
if (i == 2) { return ppn2(); }
assert(0);
return 0;
}
/// Set the physical phage number (ppn2,ppn1,ppn0) to the least
/// significant 44 bits of value.
void setPpn(uint64_t value)
{
bits_.ppn0_ = value & 0x1ff;
bits_.ppn1_ = (value >> 9) & 0x1ff;
bits_.ppn2_ = (value >> 18) & 0x3ffffff;
}
/// Return the right shift amount to right justify the ith
/// physical page number (ppn) in a physical address for Sv39. The
/// index i must be smaller than the number of levels of Sv39. See
/// the Sv39 physical address in the privileged spec.
static constexpr uint32_t paPpnShift(int i)
{
if (i == 0) { return 12; }
if (i == 1) { return 21; }
if (i == 2) { return 30; }
assert(0);
return 0;
}
};
/// Struct to unpack the fields of a page table entry for Sv48.
struct Pte48Bits
{
unsigned valid_ : 1;
unsigned read_ : 1;
unsigned write_ : 1;
unsigned exec_ : 1;
unsigned user_ : 1;
unsigned global_ : 1;
unsigned accessed_ : 1;
unsigned dirty_ : 1;
unsigned rsw_ : 2; // Reserved for supervisor.
unsigned ppn0_ : 9; // Physical page num
unsigned ppn1_ : 9; // Physical page num
unsigned ppn2_ : 9; // Physical page num
unsigned ppn3_ : 17; // Physical page num
unsigned res_ : 7; // Reserved
unsigned pbmt_ : 2; // Page based memory type
unsigned n_ : 1;
} __attribute__((packed));
/// Page table entry for Sv48
union Pte48
{
Pte48Bits bits_;
uint64_t data_ = 0;
/// Constructor: Intialize from the the given data value.
Pte48(uint64_t data) : data_(data)
{ }
/// Return true if valid bit is on in this PTE.
bool valid() const { return bits_.valid_; }
/// Return true if read permission bit is on in this PTE.
bool read() const { return bits_.read_; }
/// Return true if write permission bit is on in this PTE.
bool write() const { return bits_.write_; }
/// Return true if execute permission bit is on in this PTE.
bool exec() const { return bits_.exec_; }
/// Return true if this PTE is marked for user privilege.
bool user() const { return bits_.user_; }
/// Return true if this PTE is marked global.
bool global() const { return bits_.global_; }
/// Return true if this PTE is marked accessed.
bool accessed() const { return bits_.accessed_; }
/// Return true if this PTE is marked dirty.
bool dirty() const { return bits_.dirty_; }
/// Return rsw value (reserved for supervisor).
uint64_t rsw() const { return bits_.rsw_; }
/// Return true if this PTE is a leaf.
bool leaf() const { return valid() and (read() or exec()); }
/// Physical page number in this PTE (see Sv48 PTE in the
/// privileged spec.)
uint64_t ppn() const { return ppn0() | (ppn1() << 9) | (ppn2() << 18) | (ppn3() << 27); }
/// Physical page number field 0 in this PTE (see Sv48 PTE in the
/// privileged spec.)
uint64_t ppn0() const { return bits_.ppn0_; }
/// Physical page number field 1 in this PTE (see Sv48 PTE in the
/// privileged spec.)
uint64_t ppn1() const { return bits_.ppn1_; }
/// Physical page number field 2 in this PTE (see Sv48 PTE in the
/// privileged spec.)
uint64_t ppn2() const { return bits_.ppn2_; }
/// Physical page number field 3 in this PTE (see Sv48 PTE in the
/// privileged spec.)
uint64_t ppn3() const { return bits_.ppn3_; }
/// Set physical page number field 0 in this PTE to v.
void setPpn0(unsigned v) { bits_.ppn0_ = v; }
/// Return reserved bits value
uint64_t res() const { return bits_.res_; }
/// Number of levels of an Sv48 PTE.
static uint32_t levels() { return 4; }
/// Size in bytes of this object.
static uint32_t size() { return sizeof(data_); }
/// Page based memory type.
uint32_t pbmt() const { return bits_.pbmt_; }
/// Naturally aligned power of 2 translation.
bool hasNapot() const { return bits_.n_; }
/// Return the ith physical page number (PPN) field encoded in
/// this PTE. The index i must be smaller than the number of
/// levels of Sv48. See the Sv48 PTE in the privileged spec.
uint64_t ppn(int i) const
{
if (i == 0) { return ppn0(); }
if (i == 1) { return ppn1(); }
if (i == 2) { return ppn2(); }
if (i == 3) { return ppn3(); }
assert(0);
return 0;
}
/// Set the physical phage number (ppn3,ppn2,ppn1,ppn0) to the least
/// significant 44 bits of value.
void setPpn(uint64_t value)
{
bits_.ppn0_ = value & 0x1ff;
bits_.ppn1_ = (value >> 9) & 0x1ff;
bits_.ppn2_ = (value >> 18) & 0x1ff;
bits_.ppn3_ = (value >> 27) & 0x1ffff;
}
/// Return the right shift amount to right justify the ith
/// physical page number (ppn) in a physical address for Sv48. The
/// index i must be smaller than the number of levels of Sv48. See
/// the Sv48 physical address in the privileged spec.
static constexpr uint32_t paPpnShift(int i)
{
if (i == 0) { return 12; }
if (i == 1) { return 21; }
if (i == 2) { return 30; }
if (i == 3) { return 39; }
assert(0);
return 0;
}
};
/// Struct to unpack the fields of a page table entry for Sv57.
struct Pte57Bits
{
unsigned valid_ : 1;
unsigned read_ : 1;
unsigned write_ : 1;
unsigned exec_ : 1;
unsigned user_ : 1;
unsigned global_ : 1;
unsigned accessed_ : 1;
unsigned dirty_ : 1;
unsigned rsw_ : 2; // Reserved for supervisor.
unsigned ppn0_ : 9; // Physical page num
unsigned ppn1_ : 9; // Physical page num
unsigned ppn2_ : 9; // Physical page num
unsigned ppn3_ : 9; // Physical page num
unsigned ppn4_ : 8; // Physical page num
unsigned res_ : 7; // Reserved
unsigned pbmt_ : 2; // Page based memory type.
unsigned n_ : 1;
} __attribute__((packed));
/// Page table entry for Sv57
union Pte57
{
Pte57Bits bits_;
uint64_t data_ = 0;
/// Constructor: Intialize from the the given data value.
Pte57(uint64_t data) : data_(data)
{ }
/// Return true if valid bit is on in this PTE.
bool valid() const { return bits_.valid_; }
/// Return true if read permission bit is on in this PTE.
bool read() const { return bits_.read_; }
/// Return true if write permission bit is on in this PTE.
bool write() const { return bits_.write_; }
/// Return true if execute permission bit is on in this PTE.
bool exec() const { return bits_.exec_; }
/// Return true if this PTE is marked for user privilege.
bool user() const { return bits_.user_; }
/// Return true if this PTE is marked global.
bool global() const { return bits_.global_; }
/// Return true if this PTE is marked accessed.
bool accessed() const { return bits_.accessed_; }
/// Return true if this PTE is marked dirty.
bool dirty() const { return bits_.dirty_; }
/// Return rsw value (reserved for supervisor).
uint64_t rsw() const { return bits_.rsw_; }
/// Return true if this PTE is a leaf.
bool leaf() const { return valid() and (read() or exec()); }
/// Physical page number in this PTE (see Sv57 PTE in the
/// privileged spec.)
uint64_t ppn() const { return ppn0() | (ppn1() << 9) | (ppn2() << 18) | (ppn3() << 27) | (ppn4() << 36); }
/// Physical page number field 0 in this PTE (see Sv57 PTE in the
/// privileged spec.)
uint64_t ppn0() const { return bits_.ppn0_; }
/// Physical page number field 1 in this PTE (see Sv57 PTE in the
/// privileged spec.)
uint64_t ppn1() const { return bits_.ppn1_; }
/// Physical page number field 2 in this PTE (see Sv57 PTE in the
/// privileged spec.)
uint64_t ppn2() const { return bits_.ppn2_; }
/// Physical page number field 3 in this PTE (see Sv57 PTE in the
/// privileged spec.)
uint64_t ppn3() const { return bits_.ppn3_; }
/// Physical page number field 4 in this PTE (see Sv57 PTE in the
/// privileged spec.)
uint64_t ppn4() const { return bits_.ppn4_; }
/// Set physical page number field 0 in this PTE to v.
void setPpn0(unsigned v) { bits_.ppn0_ = v; }
/// Return reserved bits value
uint64_t res() const { return bits_.res_; }
/// Number of levels of an Sv57 PTE.
static uint32_t levels() { return 5; }
/// Size in bytes of this object.
static uint32_t size() { return sizeof(data_); }
/// Page based memory type.
uint32_t pbmt() const { return bits_.pbmt_; }
/// Naturally aligned power of 2 translation.
bool hasNapot() const { return bits_.n_; }
/// Return the ith physical page number (PPN) field encoded in
/// this PTE. The index i must be smaller than the number of
/// levels of Sv57. See the Sv57 PTE in the privileged spec.
uint64_t ppn(int i) const
{
if (i == 0) { return ppn0(); }
if (i == 1) { return ppn1(); }
if (i == 2) { return ppn2(); }
if (i == 3) { return ppn3(); }
if (i == 4) { return ppn4(); }
assert(0);
return 0;
}
/// Set the physical phage number (ppn4,ppn3,ppn2,ppn1,ppn0) to the least
/// significant 44 bits of value.
void setPpn(uint64_t value)
{
bits_.ppn0_ = value & 0x1ff;
bits_.ppn1_ = (value >> 9) & 0x1ff;
bits_.ppn2_ = (value >> 18) & 0x1ff;
bits_.ppn3_ = (value >> 27) & 0x1ff;
bits_.ppn4_ = (value >> 36) & 0xff;
}
/// Return the right shift amount to right justify the ith
/// physical page number (ppn) in a physical address for Sv57. The
/// index i must be smaller than the number of levels of Sv57. See
/// the Sv57 physical address in the privileged spec.
static constexpr uint32_t paPpnShift(int i)
{
if (i == 0) { return 12; }
if (i == 1) { return 21; }
if (i == 2) { return 30; }
if (i == 3) { return 39; }
if (i == 4) { return 48; }
assert(0);
return 0;
}
};
/// Structure to unpack the fields of 32-bit virtual address.
struct Va32Bits
{
unsigned offset_ : 12;
unsigned vpn0_ : 10;
unsigned vpn1_ : 10;
} __attribute__((packed));
/// 32-bit virtual address.
union Va32
{
Va32Bits bits_;
uint32_t data_ = 0;
Va32(uint32_t word) : data_(word)
{ }
uint32_t offset() const { return bits_.offset_; }
uint32_t vpn0() const { return bits_.vpn0_; }
uint32_t vpn1() const { return bits_.vpn1_; }
uint32_t vpn(int i) const
{
if (i == 0) return vpn0();
if (i == 1) return vpn1();
assert(0);
return 0;
}
};
/// Structure to unpack the fields of Sv39 virtual address.
struct Va39Bits
{
unsigned offset_ : 12;
unsigned vpn0_ : 9;
unsigned vpn1_ : 9;
unsigned vpn2_ : 9;
} __attribute__((packed));
/// 39-bit virtual address.
union Va39
{
Va39Bits bits_;
uint64_t data_ = 0;
Va39(uint64_t data) : data_(data)
{ }
uint64_t offset() const { return bits_.offset_; }
uint64_t vpn0() const { return bits_.vpn0_; }
uint64_t vpn1() const { return bits_.vpn1_; }
uint64_t vpn2() const { return bits_.vpn2_; }
uint64_t vpn(int i) const
{
if (i == 0) return vpn0();
if (i == 1) return vpn1();
if (i == 2) return vpn2();
assert(0);
return 0;
}
};
/// Structure to unpack the fields of Sv48 virtual address.
struct Va48Bits
{
unsigned offset_ : 12;
unsigned vpn0_ : 9;
unsigned vpn1_ : 9;
unsigned vpn2_ : 9;
unsigned vpn3_ : 9;
} __attribute__((packed));
/// 48-bit virtual address.
union Va48
{
Va48Bits bits_;
uint64_t data_ = 0;
Va48(uint64_t data) : data_(data)
{ }
uint64_t offset() const { return bits_.offset_; }
uint64_t vpn0() const { return bits_.vpn0_; }
uint64_t vpn1() const { return bits_.vpn1_; }
uint64_t vpn2() const { return bits_.vpn2_; }
uint64_t vpn3() const { return bits_.vpn3_; }
uint64_t vpn(int i) const
{
if (i == 0) return vpn0();
if (i == 1) return vpn1();
if (i == 2) return vpn2();
if (i == 3) return vpn3();
assert(0);
return 0;
}
};
/// Structure to unpack the fields of Sv57 virtual address.
struct Va57Bits
{
unsigned offset_ : 12;
unsigned vpn0_ : 9;
unsigned vpn1_ : 9;
unsigned vpn2_ : 9;
unsigned vpn3_ : 9;
unsigned vpn4_ : 9;
} __attribute__((packed));
/// 57-bit virtual address.
union Va57
{
Va57Bits bits_;
uint64_t data_ = 0;
Va57(uint64_t data) : data_(data)
{ }
uint64_t offset() const { return bits_.offset_; }
uint64_t vpn0() const { return bits_.vpn0_; }
uint64_t vpn1() const { return bits_.vpn1_; }
uint64_t vpn2() const { return bits_.vpn2_; }
uint64_t vpn3() const { return bits_.vpn3_; }
uint64_t vpn4() const { return bits_.vpn4_; }
uint64_t vpn(int i) const
{
if (i == 0) return vpn0();
if (i == 1) return vpn1();
if (i == 2) return vpn2();
if (i == 3) return vpn3();
if (i == 4) return vpn4();
assert(0);
return 0;
}
};
/// Structure to unpack the fields of an Sv32x4 virtual address
/// (guest physical address).
struct Va32x4Bits
{
unsigned offset_ : 12;
unsigned vpn0_ : 10;
unsigned vpn1_ : 12;
} __attribute__((packed));
/// Sv32x4 virtual address (guest physical address).
union Va32x4
{
Va32x4Bits bits_;
uint64_t data_ = 0;
Va32x4(uint32_t word) : data_(word)
{ }
uint32_t offset() const { return bits_.offset_; }
uint32_t vpn0() const { return bits_.vpn0_; }
uint32_t vpn1() const { return bits_.vpn1_; }
uint32_t vpn(int i) const
{
if (i == 0) return vpn0();
if (i == 1) return vpn1();
assert(0);
return 0;
}
};
/// Structure to unpack the fields of Sv39x4 virtual address.
struct Va39x4Bits
{
unsigned offset_ : 12;
unsigned vpn0_ : 9;
unsigned vpn1_ : 9;
unsigned vpn2_ : 11;
} __attribute__((packed));
/// Sv39x4 virtual address.
union Va39x4
{
Va39x4Bits bits_;
uint64_t data_ = 0;
Va39x4(uint64_t data) : data_(data)
{ }
uint64_t offset() const { return bits_.offset_; }
uint64_t vpn0() const { return bits_.vpn0_; }
uint64_t vpn1() const { return bits_.vpn1_; }
uint64_t vpn2() const { return bits_.vpn2_; }
uint64_t vpn(int i) const
{
if (i == 0) return vpn0();
if (i == 1) return vpn1();
if (i == 2) return vpn2();
assert(0);
return 0;
}
};
/// Structure to unpack the fields of Sv48x4 virtual address.
struct Va48x4Bits
{
unsigned offset_ : 12;
unsigned vpn0_ : 9;
unsigned vpn1_ : 9;
unsigned vpn2_ : 9;
unsigned vpn3_ : 11;
} __attribute__((packed));
/// Sv48x4 virtual address.
union Va48x4
{
Va48x4Bits bits_;
uint64_t data_ = 0;
Va48x4(uint64_t data) : data_(data)
{ }
uint64_t offset() const { return bits_.offset_; }
uint64_t vpn0() const { return bits_.vpn0_; }
uint64_t vpn1() const { return bits_.vpn1_; }
uint64_t vpn2() const { return bits_.vpn2_; }
uint64_t vpn3() const { return bits_.vpn3_; }
uint64_t vpn(int i) const
{
if (i == 0) return vpn0();
if (i == 1) return vpn1();
if (i == 2) return vpn2();
if (i == 3) return vpn3();
assert(0);
return 0;
}
};
/// Structure to unpack the fields of Sv57x4 virtual address.
struct Va57x4Bits
{
unsigned offset_ : 12;
unsigned vpn0_ : 9;
unsigned vpn1_ : 9;
unsigned vpn2_ : 9;
unsigned vpn3_ : 9;
unsigned vpn4_ : 11;
} __attribute__((packed));
/// Sv57x4 virtual address.
union Va57x4
{
Va57x4Bits bits_;
uint64_t data_ = 0;
Va57x4(uint64_t data) : data_(data)
{ }
uint64_t offset() const { return bits_.offset_; }
uint64_t vpn0() const { return bits_.vpn0_; }
uint64_t vpn1() const { return bits_.vpn1_; }
uint64_t vpn2() const { return bits_.vpn2_; }
uint64_t vpn3() const { return bits_.vpn3_; }
uint64_t vpn4() const { return bits_.vpn4_; }
uint64_t vpn(int i) const
{
if (i == 0) return vpn0();
if (i == 1) return vpn1();
if (i == 2) return vpn2();
if (i == 3) return vpn3();
if (i == 4) return vpn4();
assert(0);
return 0;
}
};
}