1use bitflags::bitflags;
3use lazy_static::lazy_static;
4
5use std::collections::{HashMap, hash_map};
6use super::ast::RegId;
7
8use std::fmt;
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum Template {
14 Compressed(u16),
16 Single(u32),
18 Double(u32, u32),
20 Many(&'static [u32])
22}
23
24
25bitflags! {
26 #[derive(Debug, Clone, Copy)]
28 pub struct ISAFlags: u8 {
29 const RV32 = 0x01;
30 const RV64 = 0x02;
31 }
32
33
34 #[derive(Debug, Clone, Copy)]
38 pub struct ExtensionFlags: u64 {
39 const Ex_A = 0x0000_0000_0000_0001;
41 const Ex_C = 0x0000_0000_0000_0002;
43 const Ex_D = 0x0000_0000_0000_0004;
45 const Ex_F = 0x0000_0000_0000_0008;
47 const Ex_I = 0x0000_0000_0000_0010;
49 const Ex_M = 0x0000_0000_0000_0020;
51 const Ex_Q = 0x0000_0000_0000_0040;
53 const Ex_Zabha = 0x0000_0000_0000_0080;
55 const Ex_Zacas = 0x0000_0000_0000_0100;
57 const Ex_Zawrs = 0x0000_0000_0000_0200;
59 const Ex_Zba = 0x0000_0000_0000_0400;
61 const Ex_Zbb = 0x0000_0000_0000_0800;
63 const Ex_Zbc = 0x0000_0000_0000_1000;
65 const Ex_Zbkb = 0x0000_0000_0000_2000;
67 const Ex_Zbkc = 0x0000_0000_0000_4000;
69 const Ex_Zbkx = 0x0000_0000_0000_8000;
71 const Ex_Zbs = 0x0000_0000_0001_0000;
73 const Ex_Zcb = 0x0000_0000_0002_0000;
75 const Ex_Zcmop = 0x0000_0000_0004_0000;
77 const Ex_Zcmp = 0x0000_0000_0008_0000;
79 const Ex_Zcmt = 0x0000_0000_0010_0000;
81 const Ex_Zdinx = 0x0000_0000_0020_0000;
83 const Ex_Zfa = 0x0000_0000_0040_0000;
85 const Ex_Zfbfmin = 0x0000_0000_0080_0000;
87 const Ex_Zfh = 0x0000_0000_0100_0000;
89 const Ex_Zfhmin = 0x0000_0000_0200_0000;
91 const Ex_Zfinx = 0x0000_0000_0400_0000;
93 const Ex_Zhinx = 0x0000_0000_0800_0000;
95 const Ex_Zhinxmin = 0x0000_0000_1000_0000;
97 const Ex_Zicbom = 0x0000_0000_2000_0000;
99 const Ex_Zicbop = 0x0000_0000_4000_0000;
101 const Ex_Zicboz = 0x0000_0000_8000_0000;
103 const Ex_Zicfilp = 0x0000_0001_0000_0000;
105 const Ex_Zicfiss = 0x0000_0002_0000_0000;
107 const Ex_Zicntr = 0x0000_0004_0000_0000;
109 const Ex_Zicond = 0x0000_0008_0000_0000;
111 const Ex_Zicsr = 0x0000_0010_0000_0000;
113 const Ex_Zifencei = 0x0000_0020_0000_0000;
115 const Ex_Zihintntl = 0x0000_0040_0000_0000;
117 const Ex_Zihintpause = 0x0000_0080_0000_0000;
119 const Ex_Zimop = 0x0000_0100_0000_0000;
121 const Ex_Zk = 0x0000_0200_0000_0000;
123 const Ex_Zkn = 0x0000_0400_0000_0000;
125 const Ex_Zknd = 0x0000_0800_0000_0000;
127 const Ex_Zkne = 0x0000_1000_0000_0000;
129 const Ex_Zknh = 0x0000_2000_0000_0000;
131 const Ex_Zks = 0x0000_4000_0000_0000;
133 const Ex_Zksed = 0x0000_8000_0000_0000;
135 const Ex_Zksh = 0x0001_0000_0000_0000;
137 }
138}
139
140
141impl ISAFlags {
142 const fn make(bits: u8) -> ISAFlags {
143 ISAFlags::from_bits_truncate(bits)
144 }
145}
146
147
148impl ExtensionFlags {
149 const fn make(bits: u64) -> ExtensionFlags {
150 ExtensionFlags::from_bits_truncate(bits)
151 }
152}
153
154impl fmt::Display for ExtensionFlags {
155 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
156 let mut encountered_z = false;
157
158 for (flag, bits) in self.iter_names() {
160 let flag = &flag[3..];
161
162 if encountered_z {
163 write!(f, "_")?;
164 }
165
166 write!(f, "{}", flag)?;
167
168 if flag.starts_with("Z") {
169 encountered_z = true;
170 }
171 }
172 Ok(())
173 }
174}
175
176impl Default for ExtensionFlags {
177 fn default() -> ExtensionFlags {
178 ExtensionFlags::Ex_I
179 }
180}
181
182
183#[derive(Debug, Clone, Copy, PartialEq)]
185pub enum Matcher {
186 X,
188
189 F,
191
192 Reg(RegId),
194
195 Ref,
200
201 RefOffset,
203
204 RefSp,
206
207 RefLabel,
210
211 Imm,
213
214 Offset,
216
217 Ident,
219
220 Xlist,
222
223 Lit(Literal)
225}
226
227#[derive(Debug, Clone, Copy, PartialEq)]
228pub enum Literal {
229 RTZ
230}
231
232impl Literal {
233 pub fn as_str(&self) -> &'static str {
234 match self {
235 Literal::RTZ => "rtz"
236 }
237 }
238}
239
240
241#[derive(Debug, Clone)]
245pub enum Command {
246 Repeat,
250
251 Next,
253
254 R(u8),
258
259 Reven(u8),
261
262 Rno0(u8),
264
265 Rno02(u8),
267
268 Rpop(u8),
270
271 Rpops(u8),
273
274 Rpops2(u8),
277
278 Rlist(u8),
280
281 RoundingMode(u8),
285
286 FenceSpec(u8),
289
290 Csr(u8),
292
293 FloatingPointImmediate(u8),
295
296 SPImm(u8, bool),
299
300 UImm(u8, u8),
305
306 SImm(u8, u8),
309
310 BigImm(u8),
312
313 UImmNo0(u8, u8),
316
317 SImmNo0(u8, u8),
320
321 UImmOdd(u8, u8),
324
325 UImmRange(u16, u16),
327
328 BitRange(u8, u8, u8),
332
333 RBitRange(u8, u8, u8),
336
337 Offset(Relocation),
339}
340
341#[derive(Debug, Clone, Copy, PartialEq, Eq)]
342pub enum Relocation {
343 B = 0,
346 J = 1,
349 BC = 2,
352 JC = 3,
355 HI20 = 4,
358 LO12 = 5,
361 LO12S = 6,
364 SPLIT32 = 7,
367 SPLIT32S = 8,
370}
371
372impl Relocation {
373 pub fn to_id(self) -> u8 {
374 self as u8
375 }
376
377 pub fn size(self) -> u8 {
378 match self {
379 Relocation::BC
380 | Relocation::JC => 2,
381 Relocation::B
382 | Relocation::J
383 | Relocation::HI20
384 | Relocation::LO12
385 | Relocation::LO12S => 4,
386 Relocation::SPLIT32
387 | Relocation::SPLIT32S => 8
388 }
389 }
390}
391
392
393#[derive(Debug, Clone, Copy)]
394pub struct Opdata {
395 pub template: Template,
397 pub isa_flags: ISAFlags,
399 pub ext_flags: &'static [ExtensionFlags],
401 pub matchers: &'static [Matcher],
403 pub commands: &'static [Command],
405}
406
407macro_rules! SingleOp {
408 ( $template:expr, $isa:expr, [ $( $matcher:expr ),* ], [ $( $command:expr ),* ], [ $( $extension:expr ),* ] ) => {
409 {
410 const MATCHERS: &'static [Matcher] = {
411 #[allow(unused_imports)]
412 use self::Matcher::*;
413 &[ $(
414 $matcher
415 ),* ]
416 };
417 const COMMANDS: &'static [Command] = {
418 #[allow(unused_imports)]
419 use self::Command::*;
420 #[allow(unused_imports)]
421 use self::Relocation::*;
422 &[ $(
423 $command
424 ),* ]
425 };
426 const EXTENSIONS: &'static [ExtensionFlags] = {
427 #[allow(unused_imports)]
428 &[ $(
429 ExtensionFlags::make($extension)
430 ),* ]
431 };
432
433 use self::Template::*;
434 Opdata {
435 template: $template,
436 isa_flags: ISAFlags::make($isa),
437 ext_flags: EXTENSIONS,
438 matchers: MATCHERS,
439 commands: COMMANDS,
440 }
441 }
442 }
443}
444
445macro_rules! Ops {
446 ( $( $name:tt = [ $( $template:expr , $isa:expr , [ $( $matcher:expr ),* ] => [ $( $command:expr ),* ] , [ $( $extension:expr ),* ] ; )+ ] , )* ) => {
447 [ $(
448 (
449 $name,
450 &[ $(
451 SingleOp!( $template, $isa, [ $( $matcher ),* ], [ $( $command ),* ], [ $( $extension ),* ] )
452 ),+ ] as &[_]
453 )
454 ),* ]
455 }
456}
457
458pub fn get_mnemonic_data(name: &str) -> Option<&'static [Opdata]> {
459 OPMAP.get(&name).cloned()
460}
461
462#[allow(dead_code)]
463pub fn mnemonics() -> hash_map::Keys<'static, &'static str, &'static [Opdata]> {
464 OPMAP.keys()
465}
466
467
468lazy_static!{
469 static ref OPMAP: HashMap<&'static str, &'static [Opdata]> = {
470 #![allow(non_upper_case_globals)]
471
472 const RV32: u8 = ISAFlags::RV32.bits();
474 const RV64: u8 = ISAFlags::RV64.bits();
475
476 const Ex_A: u64 = ExtensionFlags::Ex_A.bits();
478 const Ex_C: u64 = ExtensionFlags::Ex_C.bits();
479 const Ex_D: u64 = ExtensionFlags::Ex_D.bits();
480 const Ex_F: u64 = ExtensionFlags::Ex_F.bits();
481 const Ex_I: u64 = ExtensionFlags::Ex_I.bits();
482 const Ex_M: u64 = ExtensionFlags::Ex_M.bits();
483 const Ex_Q: u64 = ExtensionFlags::Ex_Q.bits();
484 const Ex_Zabha: u64 = ExtensionFlags::Ex_Zabha.bits();
485 const Ex_Zacas: u64 = ExtensionFlags::Ex_Zacas.bits();
486 const Ex_Zawrs: u64 = ExtensionFlags::Ex_Zawrs.bits();
487 const Ex_Zba: u64 = ExtensionFlags::Ex_Zba.bits();
488 const Ex_Zbb: u64 = ExtensionFlags::Ex_Zbb.bits();
489 const Ex_Zbc: u64 = ExtensionFlags::Ex_Zbc.bits();
490 const Ex_Zbkb: u64 = ExtensionFlags::Ex_Zbkb.bits();
491 const Ex_Zbkc: u64 = ExtensionFlags::Ex_Zbkc.bits();
492 const Ex_Zbkx: u64 = ExtensionFlags::Ex_Zbkx.bits();
493 const Ex_Zbs: u64 = ExtensionFlags::Ex_Zbs.bits();
494 const Ex_Zcb: u64 = ExtensionFlags::Ex_Zcb.bits();
495 const Ex_Zcmop: u64 = ExtensionFlags::Ex_Zcmop.bits();
496 const Ex_Zcmp: u64 = ExtensionFlags::Ex_Zcmp.bits();
497 const Ex_Zcmt: u64 = ExtensionFlags::Ex_Zcmt.bits();
498 const Ex_Zdinx: u64 = ExtensionFlags::Ex_Zdinx.bits();
499 const Ex_Zfa: u64 = ExtensionFlags::Ex_Zfa.bits();
500 const Ex_Zfbfmin: u64 = ExtensionFlags::Ex_Zfbfmin.bits();
501 const Ex_Zfh: u64 = ExtensionFlags::Ex_Zfh.bits();
502 const Ex_Zfhmin: u64 = ExtensionFlags::Ex_Zfhmin.bits();
503 const Ex_Zfinx: u64 = ExtensionFlags::Ex_Zfinx.bits();
504 const Ex_Zhinx: u64 = ExtensionFlags::Ex_Zhinx.bits();
505 const Ex_Zhinxmin: u64 = ExtensionFlags::Ex_Zhinxmin.bits();
506 const Ex_Zicbom: u64 = ExtensionFlags::Ex_Zicbom.bits();
507 const Ex_Zicbop: u64 = ExtensionFlags::Ex_Zicbop.bits();
508 const Ex_Zicboz: u64 = ExtensionFlags::Ex_Zicboz.bits();
509 const Ex_Zicfilp: u64 = ExtensionFlags::Ex_Zicfilp.bits();
510 const Ex_Zicfiss: u64 = ExtensionFlags::Ex_Zicfiss.bits();
511 const Ex_Zicntr: u64 = ExtensionFlags::Ex_Zicntr.bits();
512 const Ex_Zicond: u64 = ExtensionFlags::Ex_Zicond.bits();
513 const Ex_Zicsr: u64 = ExtensionFlags::Ex_Zicsr.bits();
514 const Ex_Zifencei: u64 = ExtensionFlags::Ex_Zifencei.bits();
515 const Ex_Zihintntl: u64 = ExtensionFlags::Ex_Zihintntl.bits();
516 const Ex_Zihintpause: u64 = ExtensionFlags::Ex_Zihintpause.bits();
517 const Ex_Zimop: u64 = ExtensionFlags::Ex_Zimop.bits();
518 const Ex_Zk: u64 = ExtensionFlags::Ex_Zk.bits();
519 const Ex_Zkn: u64 = ExtensionFlags::Ex_Zkn.bits();
520 const Ex_Zknd: u64 = ExtensionFlags::Ex_Zknd.bits();
521 const Ex_Zkne: u64 = ExtensionFlags::Ex_Zkne.bits();
522 const Ex_Zknh: u64 = ExtensionFlags::Ex_Zknh.bits();
523 const Ex_Zks: u64 = ExtensionFlags::Ex_Zks.bits();
524 const Ex_Zksed: u64 = ExtensionFlags::Ex_Zksed.bits();
525 const Ex_Zksh: u64 = ExtensionFlags::Ex_Zksh.bits();
526
527
528 static MAP: &[(&str, &[Opdata])] = &include!("opmap.rs");
529 MAP.iter().cloned().collect()
530 };
531
532 pub static ref ROUNDMODE_MAP: HashMap<&'static str, u8> = {
533 let mut map = HashMap::new();
534
535 map.insert("rne", 0);
536 map.insert("rtz", 1);
537 map.insert("rdn", 2);
538 map.insert("rup", 3);
539 map.insert("rmm", 4);
540 map.insert("dyn", 7);
541
542 map
543 };
544
545 pub static ref FENCESPEC_MAP: HashMap<&'static str, u8> = {
546 let mut map = HashMap::new();
547
548 map.insert("w", 1);
549 map.insert("r", 2);
550 map.insert("rw", 3);
551 map.insert("o", 4);
552 map.insert("ow", 5);
553 map.insert("or", 6);
554 map.insert("orw", 7);
555 map.insert("i", 8);
556 map.insert("iw", 9);
557 map.insert("ir", 10);
558 map.insert("irw", 11);
559 map.insert("io", 12);
560 map.insert("iow", 13);
561 map.insert("ior", 14);
562 map.insert("iorw", 15);
563
564 map
565 };
566
567 pub static ref CSR_MAP: HashMap<&'static str, u16> = {
568 let mut map = HashMap::new();
569
570 map.insert("fflags", 0x001);
571 map.insert("frm", 0x002);
572 map.insert("fcsr", 0x003);
573 map.insert("vstart", 0x008);
574 map.insert("vxsat", 0x009);
575 map.insert("vxrm", 0x00A);
576 map.insert("vcsr", 0x00F);
577 map.insert("ssp", 0x011);
578 map.insert("seed", 0x015);
579 map.insert("jvt", 0x017);
580 map.insert("cycle", 0xC00);
581 map.insert("time", 0xC01);
582 map.insert("instret", 0xC02);
583 map.insert("hpmcounter3", 0xC03);
584 map.insert("hpmcounter4", 0xC04);
585 map.insert("hpmcounter5", 0xC05);
586 map.insert("hpmcounter6", 0xC06);
587 map.insert("hpmcounter7", 0xC07);
588 map.insert("hpmcounter8", 0xC08);
589 map.insert("hpmcounter9", 0xC09);
590 map.insert("hpmcounter10", 0xC0A);
591 map.insert("hpmcounter11", 0xC0B);
592 map.insert("hpmcounter12", 0xC0C);
593 map.insert("hpmcounter13", 0xC0D);
594 map.insert("hpmcounter14", 0xC0E);
595 map.insert("hpmcounter15", 0xC0F);
596 map.insert("hpmcounter16", 0xC10);
597 map.insert("hpmcounter17", 0xC11);
598 map.insert("hpmcounter18", 0xC12);
599 map.insert("hpmcounter19", 0xC13);
600 map.insert("hpmcounter20", 0xC14);
601 map.insert("hpmcounter21", 0xC15);
602 map.insert("hpmcounter22", 0xC16);
603 map.insert("hpmcounter23", 0xC17);
604 map.insert("hpmcounter24", 0xC18);
605 map.insert("hpmcounter25", 0xC19);
606 map.insert("hpmcounter26", 0xC1A);
607 map.insert("hpmcounter27", 0xC1B);
608 map.insert("hpmcounter28", 0xC1C);
609 map.insert("hpmcounter29", 0xC1D);
610 map.insert("hpmcounter30", 0xC1E);
611 map.insert("hpmcounter31", 0xC1F);
612 map.insert("vl", 0xC20);
613 map.insert("vtype", 0xC21);
614 map.insert("vlenb", 0xC22);
615 map.insert("sstatus", 0x100);
616 map.insert("sedeleg", 0x102);
617 map.insert("sideleg", 0x103);
618 map.insert("sie", 0x104);
619 map.insert("stvec", 0x105);
620 map.insert("scounteren", 0x106);
621 map.insert("senvcfg", 0x10A);
622 map.insert("sstateen0", 0x10C);
623 map.insert("sstateen1", 0x10D);
624 map.insert("sstateen2", 0x10E);
625 map.insert("sstateen3", 0x10F);
626 map.insert("scountinhibit", 0x120);
627 map.insert("sscratch", 0x140);
628 map.insert("sepc", 0x141);
629 map.insert("scause", 0x142);
630 map.insert("stval", 0x143);
631 map.insert("sip", 0x144);
632 map.insert("stimecmp", 0x14D);
633 map.insert("sctrctl", 0x14E);
634 map.insert("sctrstatus", 0x14F);
635 map.insert("siselect", 0x150);
636 map.insert("sireg", 0x151);
637 map.insert("sireg2", 0x152);
638 map.insert("sireg3", 0x153);
639 map.insert("sireg4", 0x155);
640 map.insert("sireg5", 0x156);
641 map.insert("sireg6", 0x157);
642 map.insert("stopei", 0x15C);
643 map.insert("sctrdepth", 0x15F);
644 map.insert("satp", 0x180);
645 map.insert("srmcfg", 0x181);
646 map.insert("scontext", 0x5A8);
647 map.insert("vsstatus", 0x200);
648 map.insert("vsie", 0x204);
649 map.insert("vstvec", 0x205);
650 map.insert("vsscratch", 0x240);
651 map.insert("vsepc", 0x241);
652 map.insert("vscause", 0x242);
653 map.insert("vstval", 0x243);
654 map.insert("vsip", 0x244);
655 map.insert("vstimecmp", 0x24D);
656 map.insert("vsctrctl", 0x24E);
657 map.insert("vsiselect", 0x250);
658 map.insert("vsireg", 0x251);
659 map.insert("vsireg2", 0x252);
660 map.insert("vsireg3", 0x253);
661 map.insert("vsireg4", 0x255);
662 map.insert("vsireg5", 0x256);
663 map.insert("vsireg6", 0x257);
664 map.insert("vstopei", 0x25C);
665 map.insert("vsatp", 0x280);
666 map.insert("hstatus", 0x600);
667 map.insert("hedeleg", 0x602);
668 map.insert("hideleg", 0x603);
669 map.insert("hie", 0x604);
670 map.insert("htimedelta", 0x605);
671 map.insert("hcounteren", 0x606);
672 map.insert("hgeie", 0x607);
673 map.insert("hvien", 0x608);
674 map.insert("hvictl", 0x609);
675 map.insert("henvcfg", 0x60A);
676 map.insert("hstateen0", 0x60C);
677 map.insert("hstateen1", 0x60D);
678 map.insert("hstateen2", 0x60E);
679 map.insert("hstateen3", 0x60F);
680 map.insert("htval", 0x643);
681 map.insert("hip", 0x644);
682 map.insert("hvip", 0x645);
683 map.insert("hviprio1", 0x646);
684 map.insert("hviprio2", 0x647);
685 map.insert("htinst", 0x64A);
686 map.insert("hgatp", 0x680);
687 map.insert("hcontext", 0x6A8);
688 map.insert("hgeip", 0xE12);
689 map.insert("vstopi", 0xEB0);
690 map.insert("scountovf", 0xDA0);
691 map.insert("stopi", 0xDB0);
692 map.insert("utvt", 0x007);
693 map.insert("unxti", 0x045);
694 map.insert("uintstatus", 0x046);
695 map.insert("uscratchcsw", 0x048);
696 map.insert("uscratchcswl", 0x049);
697 map.insert("stvt", 0x107);
698 map.insert("snxti", 0x145);
699 map.insert("sintstatus", 0x146);
700 map.insert("sscratchcsw", 0x148);
701 map.insert("sscratchcswl", 0x149);
702 map.insert("mtvt", 0x307);
703 map.insert("mnxti", 0x345);
704 map.insert("mintstatus", 0x346);
705 map.insert("mscratchcsw", 0x348);
706 map.insert("mscratchcswl", 0x349);
707 map.insert("mstatus", 0x300);
708 map.insert("misa", 0x301);
709 map.insert("medeleg", 0x302);
710 map.insert("mideleg", 0x303);
711 map.insert("mie", 0x304);
712 map.insert("mtvec", 0x305);
713 map.insert("mcounteren", 0x306);
714 map.insert("mvien", 0x308);
715 map.insert("mvip", 0x309);
716 map.insert("menvcfg", 0x30a);
717 map.insert("mstateen0", 0x30C);
718 map.insert("mstateen1", 0x30D);
719 map.insert("mstateen2", 0x30E);
720 map.insert("mstateen3", 0x30F);
721 map.insert("mcountinhibit", 0x320);
722 map.insert("mscratch", 0x340);
723 map.insert("mepc", 0x341);
724 map.insert("mcause", 0x342);
725 map.insert("mtval", 0x343);
726 map.insert("mip", 0x344);
727 map.insert("mtinst", 0x34a);
728 map.insert("mtval2", 0x34b);
729 map.insert("mctrctl", 0x34E);
730 map.insert("miselect", 0x350);
731 map.insert("mireg", 0x351);
732 map.insert("mireg2", 0x352);
733 map.insert("mireg3", 0x353);
734 map.insert("mireg4", 0x355);
735 map.insert("mireg5", 0x356);
736 map.insert("mireg6", 0x357);
737 map.insert("mtopei", 0x35c);
738 map.insert("pmpcfg0", 0x3a0);
739 map.insert("pmpcfg1", 0x3a1);
740 map.insert("pmpcfg2", 0x3a2);
741 map.insert("pmpcfg3", 0x3a3);
742 map.insert("pmpcfg4", 0x3a4);
743 map.insert("pmpcfg5", 0x3a5);
744 map.insert("pmpcfg6", 0x3a6);
745 map.insert("pmpcfg7", 0x3a7);
746 map.insert("pmpcfg8", 0x3a8);
747 map.insert("pmpcfg9", 0x3a9);
748 map.insert("pmpcfg10", 0x3aa);
749 map.insert("pmpcfg11", 0x3ab);
750 map.insert("pmpcfg12", 0x3ac);
751 map.insert("pmpcfg13", 0x3ad);
752 map.insert("pmpcfg14", 0x3ae);
753 map.insert("pmpcfg15", 0x3af);
754 map.insert("pmpaddr0", 0x3b0);
755 map.insert("pmpaddr1", 0x3b1);
756 map.insert("pmpaddr2", 0x3b2);
757 map.insert("pmpaddr3", 0x3b3);
758 map.insert("pmpaddr4", 0x3b4);
759 map.insert("pmpaddr5", 0x3b5);
760 map.insert("pmpaddr6", 0x3b6);
761 map.insert("pmpaddr7", 0x3b7);
762 map.insert("pmpaddr8", 0x3b8);
763 map.insert("pmpaddr9", 0x3b9);
764 map.insert("pmpaddr10", 0x3ba);
765 map.insert("pmpaddr11", 0x3bb);
766 map.insert("pmpaddr12", 0x3bc);
767 map.insert("pmpaddr13", 0x3bd);
768 map.insert("pmpaddr14", 0x3be);
769 map.insert("pmpaddr15", 0x3bf);
770 map.insert("pmpaddr16", 0x3c0);
771 map.insert("pmpaddr17", 0x3c1);
772 map.insert("pmpaddr18", 0x3c2);
773 map.insert("pmpaddr19", 0x3c3);
774 map.insert("pmpaddr20", 0x3c4);
775 map.insert("pmpaddr21", 0x3c5);
776 map.insert("pmpaddr22", 0x3c6);
777 map.insert("pmpaddr23", 0x3c7);
778 map.insert("pmpaddr24", 0x3c8);
779 map.insert("pmpaddr25", 0x3c9);
780 map.insert("pmpaddr26", 0x3ca);
781 map.insert("pmpaddr27", 0x3cb);
782 map.insert("pmpaddr28", 0x3cc);
783 map.insert("pmpaddr29", 0x3cd);
784 map.insert("pmpaddr30", 0x3ce);
785 map.insert("pmpaddr31", 0x3cf);
786 map.insert("pmpaddr32", 0x3d0);
787 map.insert("pmpaddr33", 0x3d1);
788 map.insert("pmpaddr34", 0x3d2);
789 map.insert("pmpaddr35", 0x3d3);
790 map.insert("pmpaddr36", 0x3d4);
791 map.insert("pmpaddr37", 0x3d5);
792 map.insert("pmpaddr38", 0x3d6);
793 map.insert("pmpaddr39", 0x3d7);
794 map.insert("pmpaddr40", 0x3d8);
795 map.insert("pmpaddr41", 0x3d9);
796 map.insert("pmpaddr42", 0x3da);
797 map.insert("pmpaddr43", 0x3db);
798 map.insert("pmpaddr44", 0x3dc);
799 map.insert("pmpaddr45", 0x3dd);
800 map.insert("pmpaddr46", 0x3de);
801 map.insert("pmpaddr47", 0x3df);
802 map.insert("pmpaddr48", 0x3e0);
803 map.insert("pmpaddr49", 0x3e1);
804 map.insert("pmpaddr50", 0x3e2);
805 map.insert("pmpaddr51", 0x3e3);
806 map.insert("pmpaddr52", 0x3e4);
807 map.insert("pmpaddr53", 0x3e5);
808 map.insert("pmpaddr54", 0x3e6);
809 map.insert("pmpaddr55", 0x3e7);
810 map.insert("pmpaddr56", 0x3e8);
811 map.insert("pmpaddr57", 0x3e9);
812 map.insert("pmpaddr58", 0x3ea);
813 map.insert("pmpaddr59", 0x3eb);
814 map.insert("pmpaddr60", 0x3ec);
815 map.insert("pmpaddr61", 0x3ed);
816 map.insert("pmpaddr62", 0x3ee);
817 map.insert("pmpaddr63", 0x3ef);
818 map.insert("mseccfg", 0x747);
819 map.insert("tselect", 0x7a0);
820 map.insert("tdata1", 0x7a1);
821 map.insert("tdata2", 0x7a2);
822 map.insert("tdata3", 0x7a3);
823 map.insert("tinfo", 0x7a4);
824 map.insert("tcontrol", 0x7a5);
825 map.insert("mcontext", 0x7a8);
826 map.insert("mscontext", 0x7aa);
827 map.insert("dcsr", 0x7b0);
828 map.insert("dpc", 0x7b1);
829 map.insert("dscratch0", 0x7b2);
830 map.insert("dscratch1", 0x7b3);
831 map.insert("mcycle", 0xB00);
832 map.insert("minstret", 0xB02);
833 map.insert("mhpmcounter3", 0xB03);
834 map.insert("mhpmcounter4", 0xB04);
835 map.insert("mhpmcounter5", 0xB05);
836 map.insert("mhpmcounter6", 0xB06);
837 map.insert("mhpmcounter7", 0xB07);
838 map.insert("mhpmcounter8", 0xB08);
839 map.insert("mhpmcounter9", 0xB09);
840 map.insert("mhpmcounter10", 0xB0A);
841 map.insert("mhpmcounter11", 0xB0B);
842 map.insert("mhpmcounter12", 0xB0C);
843 map.insert("mhpmcounter13", 0xB0D);
844 map.insert("mhpmcounter14", 0xB0E);
845 map.insert("mhpmcounter15", 0xB0F);
846 map.insert("mhpmcounter16", 0xB10);
847 map.insert("mhpmcounter17", 0xB11);
848 map.insert("mhpmcounter18", 0xB12);
849 map.insert("mhpmcounter19", 0xB13);
850 map.insert("mhpmcounter20", 0xB14);
851 map.insert("mhpmcounter21", 0xB15);
852 map.insert("mhpmcounter22", 0xB16);
853 map.insert("mhpmcounter23", 0xB17);
854 map.insert("mhpmcounter24", 0xB18);
855 map.insert("mhpmcounter25", 0xB19);
856 map.insert("mhpmcounter26", 0xB1A);
857 map.insert("mhpmcounter27", 0xB1B);
858 map.insert("mhpmcounter28", 0xB1C);
859 map.insert("mhpmcounter29", 0xB1D);
860 map.insert("mhpmcounter30", 0xB1E);
861 map.insert("mhpmcounter31", 0xB1F);
862 map.insert("mcyclecfg", 0x321);
863 map.insert("minstretcfg", 0x322);
864 map.insert("mhpmevent3", 0x323);
865 map.insert("mhpmevent4", 0x324);
866 map.insert("mhpmevent5", 0x325);
867 map.insert("mhpmevent6", 0x326);
868 map.insert("mhpmevent7", 0x327);
869 map.insert("mhpmevent8", 0x328);
870 map.insert("mhpmevent9", 0x329);
871 map.insert("mhpmevent10", 0x32A);
872 map.insert("mhpmevent11", 0x32B);
873 map.insert("mhpmevent12", 0x32C);
874 map.insert("mhpmevent13", 0x32D);
875 map.insert("mhpmevent14", 0x32E);
876 map.insert("mhpmevent15", 0x32F);
877 map.insert("mhpmevent16", 0x330);
878 map.insert("mhpmevent17", 0x331);
879 map.insert("mhpmevent18", 0x332);
880 map.insert("mhpmevent19", 0x333);
881 map.insert("mhpmevent20", 0x334);
882 map.insert("mhpmevent21", 0x335);
883 map.insert("mhpmevent22", 0x336);
884 map.insert("mhpmevent23", 0x337);
885 map.insert("mhpmevent24", 0x338);
886 map.insert("mhpmevent25", 0x339);
887 map.insert("mhpmevent26", 0x33A);
888 map.insert("mhpmevent27", 0x33B);
889 map.insert("mhpmevent28", 0x33C);
890 map.insert("mhpmevent29", 0x33D);
891 map.insert("mhpmevent30", 0x33E);
892 map.insert("mhpmevent31", 0x33F);
893 map.insert("mvendorid", 0xF11);
894 map.insert("marchid", 0xF12);
895 map.insert("mimpid", 0xF13);
896 map.insert("mhartid", 0xF14);
897 map.insert("mconfigptr", 0xF15);
898 map.insert("mtopi", 0xFB0);
899
900 map.insert("sieh", 0x114);
902 map.insert("siph", 0x154);
903 map.insert("stimecmph", 0x15D);
904 map.insert("vsieh", 0x214);
905 map.insert("vsiph", 0x254);
906 map.insert("vstimecmph", 0x25D);
907 map.insert("hedelegh", 0x612);
908 map.insert("htimedeltah", 0x615);
909 map.insert("hidelegh", 0x613);
910 map.insert("hvienh", 0x618);
911 map.insert("henvcfgh", 0x61A);
912 map.insert("hviph", 0x655);
913 map.insert("hviprio1h", 0x656);
914 map.insert("hviprio2h", 0x657);
915 map.insert("hstateen0h", 0x61C);
916 map.insert("hstateen1h", 0x61D);
917 map.insert("hstateen2h", 0x61E);
918 map.insert("hstateen3h", 0x61F);
919 map.insert("cycleh", 0xC80);
920 map.insert("timeh", 0xC81);
921 map.insert("instreth", 0xC82);
922 map.insert("hpmcounter3h", 0xC83);
923 map.insert("hpmcounter4h", 0xC84);
924 map.insert("hpmcounter5h", 0xC85);
925 map.insert("hpmcounter6h", 0xC86);
926 map.insert("hpmcounter7h", 0xC87);
927 map.insert("hpmcounter8h", 0xC88);
928 map.insert("hpmcounter9h", 0xC89);
929 map.insert("hpmcounter10h", 0xC8A);
930 map.insert("hpmcounter11h", 0xC8B);
931 map.insert("hpmcounter12h", 0xC8C);
932 map.insert("hpmcounter13h", 0xC8D);
933 map.insert("hpmcounter14h", 0xC8E);
934 map.insert("hpmcounter15h", 0xC8F);
935 map.insert("hpmcounter16h", 0xC90);
936 map.insert("hpmcounter17h", 0xC91);
937 map.insert("hpmcounter18h", 0xC92);
938 map.insert("hpmcounter19h", 0xC93);
939 map.insert("hpmcounter20h", 0xC94);
940 map.insert("hpmcounter21h", 0xC95);
941 map.insert("hpmcounter22h", 0xC96);
942 map.insert("hpmcounter23h", 0xC97);
943 map.insert("hpmcounter24h", 0xC98);
944 map.insert("hpmcounter25h", 0xC99);
945 map.insert("hpmcounter26h", 0xC9A);
946 map.insert("hpmcounter27h", 0xC9B);
947 map.insert("hpmcounter28h", 0xC9C);
948 map.insert("hpmcounter29h", 0xC9D);
949 map.insert("hpmcounter30h", 0xC9E);
950 map.insert("hpmcounter31h", 0xC9F);
951 map.insert("mstatush", 0x310);
952 map.insert("midelegh", 0x313);
953 map.insert("mieh", 0x314);
954 map.insert("mvienh", 0x318);
955 map.insert("mviph", 0x319);
956 map.insert("menvcfgh", 0x31A);
957 map.insert("mstateen0h", 0x31C);
958 map.insert("mstateen1h", 0x31D);
959 map.insert("mstateen2h", 0x31E);
960 map.insert("mstateen3h", 0x31F);
961 map.insert("miph", 0x354);
962 map.insert("mcyclecfgh", 0x721);
963 map.insert("minstretcfgh", 0x722);
964 map.insert("mhpmevent3h", 0x723);
965 map.insert("mhpmevent4h", 0x724);
966 map.insert("mhpmevent5h", 0x725);
967 map.insert("mhpmevent6h", 0x726);
968 map.insert("mhpmevent7h", 0x727);
969 map.insert("mhpmevent8h", 0x728);
970 map.insert("mhpmevent9h", 0x729);
971 map.insert("mhpmevent10h", 0x72A);
972 map.insert("mhpmevent11h", 0x72B);
973 map.insert("mhpmevent12h", 0x72C);
974 map.insert("mhpmevent13h", 0x72D);
975 map.insert("mhpmevent14h", 0x72E);
976 map.insert("mhpmevent15h", 0x72F);
977 map.insert("mhpmevent16h", 0x730);
978 map.insert("mhpmevent17h", 0x731);
979 map.insert("mhpmevent18h", 0x732);
980 map.insert("mhpmevent19h", 0x733);
981 map.insert("mhpmevent20h", 0x734);
982 map.insert("mhpmevent21h", 0x735);
983 map.insert("mhpmevent22h", 0x736);
984 map.insert("mhpmevent23h", 0x737);
985 map.insert("mhpmevent24h", 0x738);
986 map.insert("mhpmevent25h", 0x739);
987 map.insert("mhpmevent26h", 0x73A);
988 map.insert("mhpmevent27h", 0x73B);
989 map.insert("mhpmevent28h", 0x73C);
990 map.insert("mhpmevent29h", 0x73D);
991 map.insert("mhpmevent30h", 0x73E);
992 map.insert("mhpmevent31h", 0x73F);
993 map.insert("mnscratch", 0x740);
994 map.insert("mnepc", 0x741);
995 map.insert("mncause", 0x742);
996 map.insert("mnstatus", 0x744);
997 map.insert("mseccfgh", 0x757);
998 map.insert("mcycleh", 0xB80);
999 map.insert("minstreth", 0xB82);
1000 map.insert("mhpmcounter3h", 0xB83);
1001 map.insert("mhpmcounter4h", 0xB84);
1002 map.insert("mhpmcounter5h", 0xB85);
1003 map.insert("mhpmcounter6h", 0xB86);
1004 map.insert("mhpmcounter7h", 0xB87);
1005 map.insert("mhpmcounter8h", 0xB88);
1006 map.insert("mhpmcounter9h", 0xB89);
1007 map.insert("mhpmcounter10h", 0xB8A);
1008 map.insert("mhpmcounter11h", 0xB8B);
1009 map.insert("mhpmcounter12h", 0xB8C);
1010 map.insert("mhpmcounter13h", 0xB8D);
1011 map.insert("mhpmcounter14h", 0xB8E);
1012 map.insert("mhpmcounter15h", 0xB8F);
1013 map.insert("mhpmcounter16h", 0xB90);
1014 map.insert("mhpmcounter17h", 0xB91);
1015 map.insert("mhpmcounter18h", 0xB92);
1016 map.insert("mhpmcounter19h", 0xB93);
1017 map.insert("mhpmcounter20h", 0xB94);
1018 map.insert("mhpmcounter21h", 0xB95);
1019 map.insert("mhpmcounter22h", 0xB96);
1020 map.insert("mhpmcounter23h", 0xB97);
1021 map.insert("mhpmcounter24h", 0xB98);
1022 map.insert("mhpmcounter25h", 0xB99);
1023 map.insert("mhpmcounter26h", 0xB9A);
1024 map.insert("mhpmcounter27h", 0xB9B);
1025 map.insert("mhpmcounter28h", 0xB9C);
1026 map.insert("mhpmcounter29h", 0xB9D);
1027 map.insert("mhpmcounter30h", 0xB9E);
1028 map.insert("mhpmcounter31h", 0xB9F);
1029
1030 map
1031 };
1032
1033
1034
1035
1036 pub static ref FP_IMM_IDENT_MAP: HashMap<&'static str, u8> = {
1037 let mut map = HashMap::new();
1038
1039 map.insert("min", 1);
1040 map.insert("inf", 30);
1041 map.insert("nan", 31);
1042
1043 map
1044 };
1045
1046 pub static ref FP_IMM_VALUE_MAP: &'static [(f32, u8)] = &[
1047 (-1.0, 0),
1048 (1.52587890625e-05, 2),
1049 (3.0517578125e-05, 3),
1050 (3.90625e-03, 4),
1051 (7.8125e-03, 5),
1052 (0.0625, 6),
1053 (0.125, 7),
1054 (0.25, 8),
1055 (0.3125, 9),
1056 (0.375, 10),
1057 (0.4375, 11),
1058 (0.5, 12),
1059 (0.625, 13),
1060 (0.75, 14),
1061 (0.875, 15),
1062 (1.0, 16),
1063 (1.25, 17),
1064 (1.5, 18),
1065 (1.75, 19),
1066 (2.0, 20),
1067 (2.5, 21),
1068 (3.0, 22),
1069 (4.0, 23),
1070 (8.0, 24),
1071 (16.0, 25),
1072 (128.0, 26),
1073 (256.0, 27),
1074 (32768.0, 28),
1075 (65536.0, 29),
1076 ];
1077}