Skip to content

Commit

Permalink
asm: Add LoadMemSX instruction
Browse files Browse the repository at this point in the history
ISAv4 adds a new instruction to load a memory value and sign extend it.
To do so a new mode is used. This commit adds a new function to emit
this instruction and adds the logic to print it nicely.

Signed-off-by: Dylan Reimerink <[email protected]>
  • Loading branch information
dylandreimerink committed Nov 1, 2023
1 parent 27e3edd commit 4944213
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion asm/instruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (ins Instruction) Format(f fmt.State, c rune) {
fmt.Fprintf(f, "imm: %d", ins.Constant)
case IndMode:
fmt.Fprintf(f, "dst: %s src: %s imm: %d", ins.Dst, ins.Src, ins.Constant)
case MemMode:
case MemMode, MemSXMode:
fmt.Fprintf(f, "dst: %s src: %s off: %d imm: %d", ins.Dst, ins.Src, ins.Offset, ins.Constant)
case XAddMode:
fmt.Fprintf(f, "dst: %s src: %s", ins.Dst, ins.Src)
Expand Down
21 changes: 21 additions & 0 deletions asm/load_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (
IndMode Mode = 0x40
// MemMode - load from memory
MemMode Mode = 0x60
// MemSXMode - load from memory, sign extension
MemSXMode Mode = 0x80
// XAddMode - add atomically across processors.
XAddMode Mode = 0xc0
)
Expand Down Expand Up @@ -73,6 +75,11 @@ func LoadMemOp(size Size) OpCode {
return OpCode(LdXClass).SetMode(MemMode).SetSize(size)
}

// LoadSXMemOp returns the OpCode to load a value of given size from memory sign extended.
func LoadSXMemOp(size Size) OpCode {
return OpCode(LdXClass).SetMode(MemSXMode).SetSize(size)
}

// LoadMem emits `dst = *(size *)(src + offset)`.
func LoadMem(dst, src Register, offset int16, size Size) Instruction {
return Instruction{
Expand All @@ -83,6 +90,20 @@ func LoadMem(dst, src Register, offset int16, size Size) Instruction {
}
}

// LoadMemSX emits `dst = *(size *)(src + offset)` but sign extends dst.
func LoadMemSX(dst, src Register, offset int16, size Size) Instruction {
if size == DWord {
return Instruction{OpCode: InvalidOpCode}
}

return Instruction{
OpCode: LoadSXMemOp(size),
Dst: dst,
Src: src,
Offset: offset,
}
}

// LoadImmOp returns the OpCode to load an immediate of given size.
//
// As of kernel 4.20, only DWord size is accepted.
Expand Down
12 changes: 8 additions & 4 deletions asm/load_store_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4944213

Please sign in to comment.