How to use enc method of powerpc Package

Best Syzkaller code snippet using powerpc.enc

powerpc.go

Source:powerpc.go Github

copy

Full Screen

...8// ./powerisa30_to_syz /home/aik/Documents/ppc/power9/PowerISA_public.v3.0B.pdf > 1.go9// .10package powerpc11import (12 "encoding/binary"13 "errors"14 "fmt"15 "math/rand"16 "github.com/google/syzkaller/pkg/ifuzz/iset"17)18type InsnBits struct {19 Start uint // Big endian bit order.20 Length uint21}22type Insn struct {23 Name string24 M64 bool // true if the instruction is 64bit _only_.25 Priv bool26 Pseudo bool27 Fields map[string][]InsnBits // for ra/rb/rt/si/...28 Opcode uint3229 Mask uint3230 insnMap *insnSetMap31 generator func(cfg *iset.Config, r *rand.Rand) []byte32}33type insnSetMap map[string]*Insn34type InsnSet struct {35 Insns []*Insn36 modeInsns iset.ModeInsns37 insnMap insnSetMap38}39func (insnset *InsnSet) GetInsns(mode iset.Mode, typ iset.Type) []iset.Insn {40 return insnset.modeInsns[mode][typ]41}42func (insnset *InsnSet) Decode(mode iset.Mode, text []byte) (int, error) {43 if len(text) < 4 {44 return 0, errors.New("must be at least 4 bytes")45 }46 insn32 := binary.LittleEndian.Uint32(text)47 for _, ins := range insnset.Insns {48 if ins.Mask&insn32 == ins.Opcode {49 return 4, nil50 }51 }52 return 0, fmt.Errorf("unrecognised instruction %08x", insn32)53}54func (insnset *InsnSet) DecodeExt(mode iset.Mode, text []byte) (int, error) {55 return 0, fmt.Errorf("no external decoder")56}57func encodeBits(n uint, ff []InsnBits) uint32 {58 ret := uint32(0)59 for _, f := range ff {60 mask := uint(1<<f.Length) - 161 field := uint32((n & mask) << (31 - (f.Start + f.Length - 1)))62 ret = ret | field63 n = n >> f.Length64 }65 return ret66}67func (insn Insn) Encode(cfg *iset.Config, r *rand.Rand) []byte {68 if insn.Pseudo {69 return insn.generator(cfg, r)70 }71 ret := make([]byte, 0)72 insn32 := insn.Opcode73 if len(cfg.MemRegions) != 0 {74 // The PowerISA pdf parser could have missed some fields,75 // randomize them there.76 insn32 |= r.Uint32() & ^insn.Mask77 }78 for reg, bits := range insn.Fields {79 field := uint(r.Intn(1 << 16))80 insn32 |= encodeBits(field, bits)81 if len(cfg.MemRegions) != 0 && (reg == "RA" || reg == "RB" || reg == "RS") {82 val := iset.GenerateInt(cfg, r, 8)83 ret = append(ret, insn.insnMap.ld64(field, val)...)84 }85 }86 return append(ret, uint32toBytes(insn32)...)87}88func Register(insns []*Insn) {89 if len(insns) == 0 {90 panic("no instructions")91 }92 insnset := &InsnSet{93 Insns: insns,94 insnMap: make(map[string]*Insn),95 }96 for _, insn := range insnset.Insns {97 insnset.insnMap[insn.Name] = insn98 insn.insnMap = &insnset.insnMap99 }100 insnset.initPseudo()101 for _, insn := range insnset.Insns {102 insnset.modeInsns.Add(insn)103 }104 iset.Arches[iset.ArchPowerPC] = insnset105}106func (insn *Insn) Info() (string, iset.Mode, bool, bool) {107 return insn.Name, insn.mode(), insn.Pseudo, insn.Priv108}109func (insn Insn) mode() iset.Mode {110 if insn.M64 {111 return (1 << iset.ModeLong64)112 }113 return (1 << iset.ModeLong64) | (1 << iset.ModeProt32)114}115func uint32toBytes(v uint32) []byte {116 ret := make([]byte, 4)117 binary.LittleEndian.PutUint32(ret, v)118 return ret119}120func (insn *Insn) enc(v map[string]uint) []byte {121 insn32 := insn.Opcode122 for reg, bits := range insn.Fields {123 if val, ok := v[reg]; ok {124 insn32 |= encodeBits(val, bits)125 }126 }127 return uint32toBytes(insn32)128}129func (imap insnSetMap) ld64(reg uint, v uint64) []byte {130 ret := make([]byte, 0)131 // This is a widely used macro to load immediate on ppc64132 // #define LOAD64(rn,name)133 // addis rn,0,name##@highest \ lis rn,name##@highest134 // ori rn,rn,name##@higher135 // rldicr rn,rn,32,31136 // oris rn,rn,name##@h137 // ori rn,rn,name##@l138 ret = append(ret, imap["addis"].enc(map[string]uint{139 "RT": reg,140 "RA": 0, // In "addis", '0' means 0, not GPR0 .141 "SI": uint((v >> 48) & 0xffff)})...)142 ret = append(ret, imap["ori"].enc(map[string]uint{143 "RA": reg,144 "RS": reg,145 "UI": uint((v >> 32) & 0xffff)})...)146 ret = append(ret, imap["rldicr"].enc(map[string]uint{147 "RA": reg,148 "RS": reg,149 "SH": 32,150 "ME": 31})...)151 ret = append(ret, imap["oris"].enc(map[string]uint{152 "RA": reg,153 "RS": reg,154 "UI": uint((v >> 16) & 0xffff)})...)155 ret = append(ret, imap["ori"].enc(map[string]uint{156 "RA": reg,157 "RS": reg,158 "UI": uint(v & 0xffff)})...)159 return ret160}161func (imap insnSetMap) ld32(reg uint, v uint32) []byte {162 ret := make([]byte, 0)163 ret = append(ret, imap["addis"].enc(map[string]uint{164 "RT": reg,165 "RA": 0, // In "addis", '0' means 0, not GPR0166 "SI": uint((v >> 16) & 0xffff)})...)167 ret = append(ret, imap["ori"].enc(map[string]uint{168 "RA": reg,169 "RS": reg,170 "UI": uint(v & 0xffff)})...)171 return ret172}173func (imap insnSetMap) ldgpr32(regaddr, regval uint, addr uint64, v uint32) []byte {174 ret := make([]byte, 0)175 ret = append(ret, imap.ld64(regaddr, addr)...)176 ret = append(ret, imap.ld32(regval, v)...)177 ret = append(ret, imap["stw"].enc(map[string]uint{178 "RA": regaddr,179 "RS": regval})...)180 return ret181}182func (imap insnSetMap) sc(lev uint) []byte {183 return imap["sc"].enc(map[string]uint{"LEV": lev})184}...

Full Screen

Full Screen

pseudo.go

Source:pseudo.go Github

copy

Full Screen

...118 imap := gen.imap119 tmpreg := uint(gen.r.Intn(32))120 // SRR0 contains a PC121 gen.byte(imap.ld64(tmpreg, iset.GenerateInt(gen.cfg, gen.r, 8)))122 gen.byte(imap["mtspr"].enc(map[string]uint{"RS": tmpreg, "SPR": SprnSrr0}))123 // SRR1 contains an MSR124 gen.byte(imap.ld64(tmpreg, gen.r.Uint64()))125 gen.byte(imap["mtspr"].enc(map[string]uint{"RS": tmpreg, "SPR": SprnSrr1}))126 gen.byte(imap["rfid"].enc(map[string]uint{}))127}...

Full Screen

Full Screen

enc

Using AI Code Generation

copy

Full Screen

1import (2type powerpc struct {3}4func (p powerpc) enc() string {5 return fmt.Sprintf("The %s %s was released in %d", p.manufacturer, p.model, p.year)6}7func main() {8 p := powerpc{9 }10 fmt.Println(p.enc())11}12import (13type powerpc struct {14}15func (p powerpc) enc() string {16 return fmt.Sprintf("The %s %s was released in %d", p.manufacturer, p.model, p.year)17}18func main() {19 p := powerpc{20 }21 fmt.Println(p.enc())22}23import (24type powerpc struct {25}26func (p powerpc) enc() string {27 return fmt.Sprintf("The %s %s was released in %d", p.manufacturer, p.model, p.year)28}29func main() {30 p := powerpc{31 }32 fmt.Println(p.enc())33}34import (35type powerpc struct {36}37func (p powerpc) enc() string {38 return fmt.Sprintf("The %s %s was released in %d", p.manufacturer, p.model, p.year)39}40func main() {41 p := powerpc{42 }43 fmt.Println(p.enc())44}

Full Screen

Full Screen

enc

Using AI Code Generation

copy

Full Screen

1import (2type powerpc struct {3}4func (p powerpc) enc() {5 fmt.Println("Encoding data")6}7func (p powerpc) dec() {8 fmt.Println("Decoding data")9}10func main() {11 fmt.Println(p1)12 p1.enc()13 p1.dec()14}

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful