Best Syzkaller code snippet using powerpc.isPrefixed
powerpc.go
Source:powerpc.go
...46 prefixShift = 32 - 647 prefixMask = uint32(0x3f) << prefixShift48 prefixOpcode = uint32(1) << prefixShift49)50func (insn Insn) isPrefixed() bool {51 return insn.Opcode&prefixMask == prefixOpcode52}53func (insnset *InsnSet) GetInsns(mode iset.Mode, typ iset.Type) []iset.Insn {54 return insnset.modeInsns[mode][typ]55}56func (insnset *InsnSet) Decode(mode iset.Mode, text []byte) (int, error) {57 if len(text) < 4 {58 return 0, errors.New("must be at least 4 bytes")59 }60 insn32 := binary.LittleEndian.Uint32(text)61 if insn32&prefixMask == prefixOpcode {62 insn2 := uint32(0)63 for _, ins := range insnset.Insns {64 if !ins.isPrefixed() || ins.Mask&insn32 != ins.Opcode {65 continue66 }67 if len(text) < 8 {68 return 0, errors.New("prefixed instruction must be at least 8 bytes")69 }70 insn2 = binary.LittleEndian.Uint32(text[4:])71 for _, ins := range insnset.Insns {72 if !ins.isPrefixed() {73 continue74 }75 if ins.MaskSuffix&insn2 == ins.OpcodeSuffix {76 return 8, nil77 }78 }79 break80 }81 return 0, fmt.Errorf("unrecognised prefixed instruction %08x %08x", insn32, insn2)82 }83 for _, ins := range insnset.Insns {84 if ins.Mask&insn32 == ins.Opcode {85 return 4, nil86 }87 }88 return 0, fmt.Errorf("unrecognised instruction %08x", insn32)89}90func (insnset *InsnSet) DecodeExt(mode iset.Mode, text []byte) (int, error) {91 return 0, fmt.Errorf("no external decoder")92}93func encodeBits(n uint, ff []InsnBits) uint32 {94 ret := uint32(0)95 for _, f := range ff {96 mask := uint(1<<f.Length) - 197 field := uint32((n & mask) << (31 - (f.Start + f.Length - 1)))98 ret = ret | field99 n = n >> f.Length100 }101 return ret102}103func (insn Insn) Encode(cfg *iset.Config, r *rand.Rand) []byte {104 if insn.Pseudo {105 return insn.generator(cfg, r)106 }107 ret := make([]byte, 0)108 ret = append(ret, insn.encodeOpcode(cfg, r, insn.Opcode, insn.Mask, insn.Fields)...)109 if insn.isPrefixed() {110 ret = append(ret, insn.encodeOpcode(cfg, r, insn.OpcodeSuffix, insn.MaskSuffix, insn.FieldsSuffix)...)111 }112 return ret113}114func (insn Insn) encodeOpcode(cfg *iset.Config, r *rand.Rand, opcode, mask uint32, f []InsnField) []byte {115 ret := make([]byte, 0)116 insn32 := opcode117 if len(cfg.MemRegions) != 0 {118 // The PowerISA pdf parser could have missed some fields,119 // randomize them there.120 insn32 |= r.Uint32() & ^mask121 }122 for _, f := range f {123 field := uint(r.Intn(1 << 16))124 if f.Name == "Ap" || f.Name == "FRAp" || f.Name == "FRBp" || f.Name == "FRTp" || f.Name == "FRSp" {125 // These are pairs and have to be even numbers.126 field &^= 1127 }128 insn32 |= encodeBits(field, f.Bits)129 if len(cfg.MemRegions) != 0 && (f.Name == "RA" || f.Name == "RB" || f.Name == "RS") {130 val := iset.GenerateInt(cfg, r, 8)131 ret = append(ret, insn.insnMap.ld64(field, val)...)132 }133 }134 return append(ret, uint32toBytes(insn32)...)135}136func Register(insns []*Insn) {137 if len(insns) == 0 {138 panic("no instructions")139 }140 insnset := &InsnSet{141 Insns: insns,142 insnMap: make(map[string]*Insn),143 }144 for _, insn := range insnset.Insns {145 insnset.insnMap[insn.Name] = insn146 insn.insnMap = &insnset.insnMap147 }148 insnset.initPseudo()149 for _, insn := range insnset.Insns {150 insnset.modeInsns.Add(insn)151 }152 iset.Arches[iset.ArchPowerPC] = insnset153}154func (insn *Insn) Info() (string, iset.Mode, bool, bool) {155 return insn.Name, insn.mode(), insn.Pseudo, insn.Priv156}157func (insn Insn) mode() iset.Mode {158 return (1 << iset.ModeLong64) | (1 << iset.ModeProt32)159}160func uint32toBytes(v uint32) []byte {161 ret := make([]byte, 4)162 binary.LittleEndian.PutUint32(ret, v)163 return ret164}165func (insn *Insn) enc(v map[string]uint) []byte {166 ret := make([]byte, 0)167 ret = append(ret, insn.encOpcode(v, insn.Opcode, insn.Fields)...)168 if insn.isPrefixed() {169 ret = append(ret, insn.encOpcode(v, insn.OpcodeSuffix, insn.FieldsSuffix)...)170 }171 return ret172}173func (insn *Insn) encOpcode(v map[string]uint, opcode uint32, f []InsnField) []byte {174 insn32 := opcode175 for _, f := range insn.Fields {176 if val, ok := v[f.Name]; ok {177 insn32 |= encodeBits(val, f.Bits)178 }179 }180 return uint32toBytes(insn32)181}182func (imap insnSetMap) ld64(reg uint, v uint64) []byte {...
isPrefixed
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello, playground")4 bus := gobus.NewBus()5 bus.AddDevice("powerpc", "0x0", "0x1000")6 bus.AddDevice("powerpc", "0x1000", "0x1000")7 bus.AddDevice("powerpc", "0x2000", "0x1000")8 bus.AddDevice("powerpc", "0x3000", "0x1000")9 bus.AddDevice("powerpc", "0x4000", "0x1000")10 bus.AddDevice("powerpc", "0x5000", "0x1000")11 bus.AddDevice("powerpc", "0x6000", "0x1000")12 bus.AddDevice("powerpc", "0x7000", "0x1000")13 bus.AddDevice("powerpc", "0x8000", "0x1000")14 bus.AddDevice("powerpc", "0x9000", "0x1000")15 bus.AddDevice("powerpc", "0xa000", "0x1000")16 bus.AddDevice("powerpc", "0xb000", "0x1000")17 bus.AddDevice("powerpc", "0xc000", "0x1000")18 bus.AddDevice("powerpc", "0xd000", "0x1000")19 bus.AddDevice("powerpc", "0xe000", "0x1000")20 bus.AddDevice("powerpc", "0xf000", "0x1000")21 bus.AddDevice("powerpc", "0x10000", "0x1000")22 bus.AddDevice("powerpc", "0x11000", "0x1000")23 bus.AddDevice("powerpc", "0x12000", "0x1000")24 bus.AddDevice("powerpc", "0x13000", "0x1000")25 bus.AddDevice("powerpc", "0x14000", "0x1000")26 bus.AddDevice("powerpc", "0x15000", "0x1000")27 bus.AddDevice("powerpc", "0x16000", "0x1000")28 bus.AddDevice("powerpc", "0x17000", "0x1000")29 bus.AddDevice("powerpc", "0x18000
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!