Skip to content

Commit a0d7749

Browse files
TechnoElfknickish
andauthored
[M68k] implement move to and from sr (#111145)
This PR enables the use of the status register in inline assembly. This is necessary to, for example, set and retrieve the current interrupt mask. --------- Co-authored-by: kirk <[email protected]>
1 parent 5ff7f47 commit a0d7749

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

llvm/lib/Target/M68k/AsmParser/M68kAsmParser.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ static inline unsigned getRegisterIndex(unsigned Register) {
258258
// We don't care about the indices of these registers.
259259
case M68k::PC:
260260
case M68k::CCR:
261+
case M68k::SR:
261262
case M68k::FPC:
262263
case M68k::FPS:
263264
case M68k::FPIAR:
@@ -636,10 +637,13 @@ bool M68kAsmParser::parseRegisterName(MCRegister &RegNo, SMLoc Loc,
636637
StringRef RegisterName) {
637638
auto RegisterNameLower = RegisterName.lower();
638639

639-
// CCR register
640+
// CCR and SR register
640641
if (RegisterNameLower == "ccr") {
641642
RegNo = M68k::CCR;
642643
return true;
644+
} else if (RegisterNameLower == "sr") {
645+
RegNo = M68k::SR;
646+
return true;
643647
}
644648

645649
// Parse simple general-purpose registers.

llvm/lib/Target/M68k/Disassembler/M68kDisassembler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ static DecodeStatus DecodeCCRCRegisterClass(MCInst &Inst, APInt &Insn,
117117
llvm_unreachable("unimplemented");
118118
}
119119

120+
static DecodeStatus DecodeSRCRegisterClass(MCInst &Inst, APInt &Insn,
121+
uint64_t Address,
122+
const void *Decoder) {
123+
llvm_unreachable("unimplemented");
124+
}
125+
120126
static DecodeStatus DecodeImm32(MCInst &Inst, uint64_t Imm, uint64_t Address,
121127
const void *Decoder) {
122128
Inst.addOperand(MCOperand::createImm(M68k::swapWord<uint32_t>(Imm)));

llvm/lib/Target/M68k/M68kInstrData.td

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,14 @@ def MOVM32mp_P : MxMOVEM_RM_Pseudo<MxType32r, MxType32.POp>;
365365
// ons that will be resolved sometime after RA pass.
366366
//===----------------------------------------------------------------------===//
367367

368+
/// Move to CCR
368369
/// --------------------------------------------------
369370
/// F E D C B A 9 8 7 6 | 5 4 3 | 2 1 0
370371
/// --------------------------------------------------
371372
/// | EFFECTIVE ADDRESS
372373
/// 0 1 0 0 0 1 0 0 1 1 | MODE | REG
373374
/// --------------------------------------------------
374-
let Defs = [CCR] in
375+
let Defs = [CCR] in {
375376
class MxMoveToCCR<MxOperand MEMOp, MxEncMemOp SRC_ENC>
376377
: MxInst<(outs CCRC:$dst), (ins MEMOp:$src), "move.w\t$src, $dst", []> {
377378
let Inst = (ascend
@@ -382,6 +383,7 @@ class MxMoveToCCR<MxOperand MEMOp, MxEncMemOp SRC_ENC>
382383

383384
class MxMoveToCCRPseudo<MxOperand MEMOp>
384385
: MxPseudo<(outs CCRC:$dst), (ins MEMOp:$src)>;
386+
} // let Defs = [CCR]
385387

386388
let mayLoad = 1 in
387389
foreach AM = MxMoveSupportedAMs in {
@@ -436,6 +438,64 @@ foreach AM = MxMoveSupportedAMs in {
436438
def MOV16dc : MxMoveFromCCR_R;
437439
def MOV8dc : MxMoveFromCCR_RPseudo<MxOp8AddrMode_d.Op>;
438440

441+
/// Move to SR
442+
/// --------------------------------------------------
443+
/// F E D C B A 9 8 7 6 | 5 4 3 | 2 1 0
444+
/// --------------------------------------------------
445+
/// | EFFECTIVE ADDRESS
446+
/// 0 1 0 0 0 1 1 0 1 1 | MODE | REG
447+
/// --------------------------------------------------
448+
let Defs = [SR] in {
449+
class MxMoveToSR<MxOperand MEMOp, MxEncMemOp SRC_ENC>
450+
: MxInst<(outs SRC:$dst), (ins MEMOp:$src), "move.w\t$src, $dst", []> {
451+
let Inst = (ascend
452+
(descend 0b0100011011, SRC_ENC.EA),
453+
SRC_ENC.Supplement
454+
);
455+
}
456+
} // let Defs = [SR]
457+
458+
let mayLoad = 1 in
459+
foreach AM = MxMoveSupportedAMs in {
460+
def MOV16s # AM : MxMoveToSR<!cast<MxOpBundle>("MxOp16AddrMode_"#AM).Op,
461+
!cast<MxEncMemOp>("MxMoveSrcOpEnc_"#AM)>;
462+
} // foreach AM
463+
464+
def MOV16sd : MxMoveToSR<MxOp16AddrMode_d.Op, MxMoveSrcOpEnc_d>;
465+
466+
/// Move from SR
467+
/// --------------------------------------------------
468+
/// F E D C B A 9 8 7 6 | 5 4 3 | 2 1 0
469+
/// --------------------------------------------------
470+
/// | EFFECTIVE ADDRESS
471+
/// 0 1 0 0 0 0 0 0 1 1 | MODE | REG
472+
/// --------------------------------------------------
473+
let Uses = [SR] in {
474+
class MxMoveFromSR_R
475+
: MxInst<(outs MxDRD16:$dst), (ins SRC:$src), "move.w\t$src, $dst", []>,
476+
Requires<[ AtLeastM68010 ]> {
477+
let Inst = (descend 0b0100000011, MxEncAddrMode_d<"dst">.EA);
478+
}
479+
480+
class MxMoveFromSR_M<MxOperand MEMOp, MxEncMemOp DST_ENC>
481+
: MxInst<(outs), (ins MEMOp:$dst, SRC:$src), "move.w\t$src, $dst", []>,
482+
Requires<[ AtLeastM68010 ]> {
483+
let Inst = (ascend
484+
(descend 0b0100000011, DST_ENC.EA),
485+
DST_ENC.Supplement
486+
);
487+
}
488+
} // let Uses = [SR]
489+
490+
let mayStore = 1 in
491+
foreach AM = MxMoveSupportedAMs in {
492+
def MOV16 # AM # s
493+
: MxMoveFromSR_M<!cast<MxOpBundle>("MxOp16AddrMode_"#AM).Op,
494+
!cast<MxEncMemOp>("MxMoveDstOpEnc_"#AM)>;
495+
} // foreach AM
496+
497+
def MOV16ds : MxMoveFromSR_R;
498+
439499
//===----------------------------------------------------------------------===//
440500
// LEA
441501
//===----------------------------------------------------------------------===//
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; RUN: llvm-mc -triple=m68k -mcpu=M68000 -show-encoding %s | FileCheck %s
2+
3+
; CHECK: move.w %d1, %sr
4+
; CHECK-SAME: encoding: [0x46,0xc1]
5+
move.w %d1, %sr
6+
7+
; CHECK: move.w %sr, %d1
8+
; CHECK-SAME: encoding: [0x40,0xc1]
9+
move.w %sr, %d1

0 commit comments

Comments
 (0)