Skip to content

Two Steps Forward…(well maybe not two)

December 17, 2014

I had to start over again today re-downloading the repositories because GIT wants to do commits against the original repository – which would not work for the owners.

I downloaded it and combined clang with llvm and started working at getting a branch instruction to work. LEG does not implement branches and much dicking around ensued. At the end of the day I tried to do a git diff to see what changes I had done in the day and oops, no tracking. I must have had to do a git .add or something after my git .init.

So I downloaded the whole thing again and diff’d it with my work product as my baseline for next session.

I do understand where branches live now and i think if i just wanted assembly text output I could have that fairly easily. I may have to settle for now.

diff -r legc-baseline/src/CMakeLists.txt legc/src/CMakeLists.txt
134a135
> 
136d136
<   AArch64
155c155
< set(LLVM_TARGETS_TO_BUILD "all"
---
> set(LLVM_TARGETS_TO_BUILD “LEG”

diff -r legc-baseline/src/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp legc/src/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
2478a2479,2481
>     //dbgs() << "pre-switch: ";
>     //NodeToMatch->dump(CurDAG);
>     //dbgs() << '\n';
3292c3295
< 
---
> Msg<<"pigs ";

diff -r legc-baseline/src/lib/Target/LEG/InstPrinter/LEGInstPrinter.cpp legc/src/lib/Target/LEG/InstPrinter/LEGInstPrinter.cpp
50,52c50,54
<   const MCSymbolRefExpr::VariantKind Kind = SRE->getKind();
<   assert(Kind == MCSymbolRefExpr::VK_LEG_LO ||
<          Kind == MCSymbolRefExpr::VK_LEG_HI);
---
> 
>   //const MCSymbolRefExpr::VariantKind Kind = SRE->getKind();
>   SRE->dump();
>     //assert(Kind == MCSymbolRefExpr::VK_LEG_LO ||
>     //     Kind == MCSymbolRefExpr::VK_LEG_HI);

diff -r legc-baseline/src/lib/Target/LEG/LEGISelDAGToDAG.cpp legc/src/lib/Target/LEG/LEGISelDAGToDAG.cpp
87c87
<       CurDAG->getMachineNode(LEG::MOVLOi16, N, MVT::i32, ConstLo);
---
>       CurDAG->getMachineNode(LEG::COSLD2I, N, MVT::i32, ConstLo); //wjr

diff -r legc-baseline/src/lib/Target/LEG/LEGISelLowering.h legc/src/lib/Target/LEG/LEGISelLowering.h
37a38
>   COSRET_FLAG,

diff -r legc-baseline/src/lib/Target/LEG/LEGInstrFormats.td legc/src/lib/Target/LEG/LEGInstrFormats.td
8a9,61
> //===----------------------------------------------------------------------===//
> // 24 bit COSMAC global branch instruction
> //===----------------------------------------------------------------------===//
> class InstCOSLBR<dag outs, dag ins, string asmstr, list<dag> pattern>
> : Instruction {
>     field bits<24> Inst;
>     
>     let Namespace = "LEG";
>     dag OutOperandList = outs;
>     dag InOperandList = ins;
>     let AsmString   = asmstr;
>     let Pattern = pattern;
>     let Size = 3;
>     
>     // Set dummy values
>     let Inst{23-0} = 0x777777;
> }
> 
> //===----------------------------------------------------------------------===//
> // 8 bit COSMAC instruction
> //===----------------------------------------------------------------------===//
> class InstCOS<dag outs, dag ins, string asmstr, list<dag> pattern>
> : Instruction {
>     field bits<8> Inst;
>     
>     let Namespace = "LEG";
>     dag OutOperandList = outs;
>     dag InOperandList = ins;
>     let AsmString   = asmstr;
>     let Pattern = pattern;
>     let Size = 1;
>     
>     // Set a dummy pattern default
>     let Inst{7-0} = 0xAA;
> }
> 
> //===----------------------------------------------------------------------===//
> // 48 bit COSMAC load register immediate instruction
> //===----------------------------------------------------------------------===//
> class InstCOSldri<dag outs, dag ins, string asmstr, list<dag> pattern>
> : Instruction {
>     field bits<48> Inst;
>     
>     let Namespace = "LEG";
>     dag OutOperandList = outs;
>     dag InOperandList = ins;
>     let AsmString   = asmstr;
>     let Pattern = pattern;
>     let Size = 6;
>     
>     // Set dummy values
>     let Inst{47-0} = 0x777777777777;
> }

diff -r legc-baseline/src/lib/Target/LEG/LEGInstrInfo.td legc/src/lib/Target/LEG/LEGInstrInfo.td
101d100
< 
105a105,119
> def COSLD2I : InstCOSldri<(outs GRRegs:$dst),(ins i32imm:$imm),"LD2I $dst,$imm",
> [(set i32:$dst, i32imm_lo:$imm)]>{
>     bits<4> dst;
>     bits<16> imm;
>     let Inst{7-0} =0xf8;
>     let Inst{15-8}  = imm{15-8};
>     let Inst{23-16}=0xB0;
>     let Inst{19-16}=dst;
>     let Inst{31-24} =0xf8;
>     let Inst{39-32} = imm{7-0};
>     let Inst{47-40}=0xB0;
>     let Inst{47-44}=dst;
> }
> 
> 
164a179,196
> 
> //===----------------------------------------------------------------------===//
> // Dummying up a branch Instructions
> //===----------------------------------------------------------------------===//
> // Branch targets have OtherVT type (copied from SPARC)
> def brtarget : Operand<OtherVT> {
>     //let EncoderMethod = "getBranchTargetOpValue";
> }
> 
> let isBranch = 1, isTerminator = 1 in {
>     def WJRBR : InstCOSLBR<(outs), (ins brtarget:$addr),
>     "LBR $addr",
>     [(br bb:$addr)]> {
>         bits<32> addr;
>         let Inst{7-0} = 0xC4; //long branch
>         let Inst{23-8} = addr{15-0};
>     }
> }
170,173c202,205
<   def RET : InstLEG<(outs), (ins variable_ops),
<                     "bx lr",  [(LEGRetFlag)]> {
<     let Inst{27-0}  = 0b0001001011111111111100011110;
<   }
---
>     def RET : InstLEG<(outs), (ins variable_ops),
>     "bx lr",  [(LEGRetFlag)]> {
>         let Inst{27-0}  = 0b0001001011111111111100011110;
>     }
175a208,219
> //===----------------------------------------------------------------------===//
> // COSMAC Return Instruction
> //===----------------------------------------------------------------------===//
> 
> let isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [LR] in {
>     def COSRET : InstCOS<(outs), (ins variable_ops),
>     "SEP 5",  [(COSRetFlag)]> {
>         let Inst{7-0}  = 0xD5;
>     }
> }
> 
> 

diff -r legc-baseline/src/lib/Target/LEG/LEGOperators.td legc/src/lib/Target/LEG/LEGOperators.td
23a24,25
> def COSRetFlag    : SDNode<"LEGISD::COSRET_FLAG", SDTNone,
>                           [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;

diff -r legc-baseline/src/lib/Target/LEG/MCTargetDesc/LEGAsmBackend.cpp legc/src/lib/Target/LEG/MCTargetDesc/LEGAsmBackend.cpp
57a58
>       { "fixup_COS_global", 0, 16, MCFixupKindInfo::FKF_IsPCRel },
105a107,109
>       case LEG::fixup_COS_global:
>           fprintf(stderr,"Adjfixupval returns%d\n",(int)Value);
>           return Value;
141c145
< 
---
>   
142a147,154
> 
>     unsigned Kind = Fixup.getKind();//wjr
>     if (Kind==LEG::fixup_COS_global){
>         NumBytes=2;
>         fprintf(stderr,"Bingo\n\n");
>     }
>     
> fprintf(stderr,"Offset=%d, NumBytes=%d, DataSize=%d\n",Offset, NumBytes, DataSize); //wjr
152c164,169
< 
---
> /*
>  switch (Kind) {
>  default:
>  llvm_unreachable("Unknown fixup kind!");
>  case LEG::fixup_COS_global:
> */

diff -r legc-baseline/src/lib/Target/LEG/MCTargetDesc/LEGELFObjectWriter.cpp legc/src/lib/Target/LEG/MCTargetDesc/LEGELFObjectWriter.cpp
46a47,50
>       case LEG::fixup_COS_global:// wjr
>           fprintf(stderr,"global fixup\n");
>           Type = ELF::R_ARM_NONE;//wjr
>           break;//wjr

diff -r legc-baseline/src/lib/Target/LEG/MCTargetDesc/LEGFixupKinds.h legc/src/lib/Target/LEG/MCTargetDesc/LEGFixupKinds.h
19a20
>   fixup_COS_global, //wjr trying something

diff -r legc-baseline/src/lib/Target/LEG/MCTargetDesc/LEGMCCodeEmitter.cpp legc/src/lib/Target/LEG/MCTargetDesc/LEGMCCodeEmitter.cpp
115c115,117
<     llvm_unreachable("Unknown fixup kind!");
---
>     /*llvm_unreachable*/fprintf(stderr,"Unknown fixup kind! - using LEG::fixup_COS_global\n"); //wjr
>           FixupKind = LEG::fixup_COS_global;
>           break;
146,150c148,152
<   if (Desc.getSize() != 4) {
<     llvm_unreachable("Unexpected instruction size!");
<   }
< 
<   const uint32_t Binary = getBinaryCodeForInstr(MI, Fixups, STI);
---
>     if (Desc.getSize() > 8) { //wjr
>         llvm_unreachable("Single instruction can only be 8 bytes!");
>     }
>     
>     const uint64_t Binary = getBinaryCodeForInstr(MI, Fixups, STI); //wjr
Advertisements

From → LLVM

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: