pcg object/debug generation - uefi · –intel® c compiler for efi byte code, version 1.2 build...

44
EBC Compiler EBC Compiler Ravi Narayanaswamy Ravi Narayanaswamy Jiang Ning Liu Jiang Ning Liu Copyright Copyright © © 2007 Intel Corporation 2007 Intel Corporation

Upload: others

Post on 06-Aug-2020

28 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

EBC CompilerEBC Compiler

Ravi NarayanaswamyRavi NarayanaswamyJiang Ning LiuJiang Ning Liu

Copyright Copyright ©© 2007 Intel Corporation2007 Intel Corporation

Page 2: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

2

DisclaimerDisclaimer

THIS INFORMATION COTNAINED IN THIS DOCUMENT, INCLUDING ANY TEST THIS INFORMATION COTNAINED IN THIS DOCUMENT, INCLUDING ANY TEST RESULTS ARE PROVIDED RESULTS ARE PROVIDED "AS IS" WITH NO WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF"AS IS" WITH NO WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY, MERCHANTABILITY, NONINFRINGEMENT FITNESS FOR ANY PARTICULAR PURPOSE, OR ANY WARRANONINFRINGEMENT FITNESS FOR ANY PARTICULAR PURPOSE, OR ANY WARRANTY OTHERWISE ARISING NTY OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE.INFORMATION IN THISOUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE.INFORMATION IN THIS DOCUMENT IS PROVIDED IN DOCUMENT IS PROVIDED IN CONNECTION WITH INTELCONNECTION WITH INTEL®® PRODUCTS. NO LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR PRODUCTS. NO LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, TO ANY INTELLECTUAL PROPERTY RIGHTS IS GRANTED BY THIOTHERWISE, TO ANY INTELLECTUAL PROPERTY RIGHTS IS GRANTED BY THIS DOCUMENT OR BY THE S DOCUMENT OR BY THE SALE OF INTEL PRODUCTS. EXCEPT AS PROVIDED IN INTEL'S TERMS AND SALE OF INTEL PRODUCTS. EXCEPT AS PROVIDED IN INTEL'S TERMS AND CONDITIONS OF SALE FOR CONDITIONS OF SALE FOR SUCH PRODUCTS, INTEL ASSUMES NO LIABILITY WHATSOEVER, AND INTEL SUCH PRODUCTS, INTEL ASSUMES NO LIABILITY WHATSOEVER, AND INTEL DISCLAIMS ANY EXPRESS DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY, RELATING TO SALE AND/OR USE OF INTEL PRODUCOR IMPLIED WARRANTY, RELATING TO SALE AND/OR USE OF INTEL PRODUCTS INCLUDING LIABILITY TS INCLUDING LIABILITY OR WARRANTIES RELATING TO FITNESS FOR A PARTICULAR PURPOSE, MERCOR WARRANTIES RELATING TO FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR HANTABILITY, OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPINFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT. Intel products ERTY RIGHT. Intel products are not intended for use in medical, life saving, or life sustaiare not intended for use in medical, life saving, or life sustaining applications.ning applications.

Intel retains the right to make changes to its specifications atIntel retains the right to make changes to its specifications at any time, without notice.any time, without notice.

Recipients of this information remain solely responsible for theRecipients of this information remain solely responsible for the design, sale and functionality of their design, sale and functionality of their products, including any liability arising from product infringemproducts, including any liability arising from product infringement or product warranty.ent or product warranty.

Intel may make changes to specifications, product roadmaps and pIntel may make changes to specifications, product roadmaps and product descriptions at any time, roduct descriptions at any time, without notice. without notice.

Intel and the Intel logo are trademarks or registered trademarksIntel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in of Intel Corporation or its subsidiaries in the United States and other countries.the United States and other countries.

*Other names and brands may be claimed as the property of others*Other names and brands may be claimed as the property of others..

Copyright Copyright ©© 2007, Intel Corporation2007, Intel Corporation

Page 3: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

3

AgendaAgenda

Source LanguageSource Language

Virtual MachineVirtual Machine

Development EnvironmentDevelopment Environment

EBC CompilerEBC Compiler

DemosDemos

Page 4: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

4

Source LanguageSource Language

Run on various platformRun on various platform

–– 6464--bit Cleanbit Clean

Small imageSmall image

–– No floating point types/operationsNo floating point types/operations

–– No C++ (runtime library, exception handling)No C++ (runtime library, exception handling)

DebuggabilityDebuggability/Maintenance/Maintenance

–– No inline No inline asmasm

Page 5: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

5

Source Language Source Language --64bitness64bitness

Natural TypesNatural Types––PointerPointer

––INTN/UINTNINTN/UINTN

No static initialization using sizeof on No static initialization using sizeof on natural typesnatural types

Page 6: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

6

Language Examples(1)Language Examples(1)

main()main()

{{

intint **xpxp, x, y;, x, y;

y = 8;y = 8;

xpxp = &y;= &y;

x = *x = *xpxp;;

}}

Page 7: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

7

Language Examples(2)Language Examples(2)

intint PASS;PASS;long long f(longf(long x)x){{

return return x+sizeof(intx+sizeof(int););}}main()main(){{

long x, y;long x, y;

x=4;x=4;y = y = f(xf(x););if ((if ((y+f(xy+f(x))==16) ))==16) PASS=1;PASS=1;else PASS=0;else PASS=0;

}}

Page 8: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

8

Virtual MachineVirtual Machine

RegistersRegisters

Instruction encodingInstruction encoding

Operand Register encodingOperand Register encoding

Natural indexing Natural indexing

Instruction SetInstruction Set

Page 9: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

9

RegistersRegisters

General purpose RegistersGeneral purpose Registers––8 8 -- 64 bit registers (R0 64 bit registers (R0 –– R7)R7)

Special RegistersSpecial Registers––64 bit registers64 bit registers

––Currently only 2 definedCurrently only 2 defined

Page 10: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

10

Registers cont.Registers cont.

General purpose RegistersGeneral purpose Registers

Special RegistersSpecial Registers

IndexIndex RegisterRegister DescriptionDescription

00 R0R0 Points to the top of the stackPoints to the top of the stack

11--33 R1R1--R3R3 Preserved across callsPreserved across calls

44--77 R4R4--R7R7 Scratch, not preserved across Scratch, not preserved across callscalls

IndexIndex RegisterRegister DescriptionDescription

00 FLAGSFLAGS 0 : Condition Code, 1..63 0 : Condition Code, 1..63 ReservedReserved

1 1 IPIP Points to current instructionPoints to current instruction

2..72..7 ReservedReserved Not definedNot defined

Page 11: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

11

Instruction EncodingInstruction Encoding

OpcodeOpcode operand1 operand2operand1 operand2

BitBit SymSym DescriptionDescription

00--55 OpOp The The opcodeopcode of the of the instructioninstruction

66 WW WidthWidth

77 II Immediate data PresentImmediate data Present

Page 12: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

12

Operand Register EncodingOperand Register Encoding

[@][@]RnRn

BitBit DescriptionDescription

0..20..2 Operand 1 RegisterOperand 1 Register

33 0 = Operand 1 is direct 0 = Operand 1 is direct

1 = Operand 1 is indirect1 = Operand 1 is indirect

4..64..6 Operand 2 registerOperand 2 register

77 0 = Operand 2 is direct 0 = Operand 2 is direct

1 = Operand 2 is indirect1 = Operand 2 is indirect

Page 13: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

13

Natural IndexingNatural Indexing

Immediate data for indirect operandsImmediate data for indirect operands

Index = C + N * (Size of pointer in bytes)Index = C + N * (Size of pointer in bytes)

Indexes can be 16, 32 or 64 bit wideIndexes can be 16, 32 or 64 bit wide

BitBit DescriptionDescription

x+4x+4 Sign bit, most significant bitSign bit, most significant bit

x+1..x+3x+1..x+3 Bits assigned to natural units (w)Bits assigned to natural units (w)

a+1..xa+1..x Constant units (C )Constant units (C )

0..a0..a Natural units (N)Natural units (N)

Page 14: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

14

Instruction SetInstruction Set

Program FlowProgram Flow

CompareCompare

Data ManipulationData Manipulation

Data MovementData Movement

Page 15: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

15

Program Flow InstructionsProgram Flow Instructions

BREAKBREAK

JMPJMP

CALLCALL

RETURNRETURN

Page 16: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

16

Program Flow InstructionsProgram Flow Instructions

Break Break break_codebreak_code

ByteByte DescriptionDescription00

11 Break CodeBreak Code

BitBit DescriptionDescription

5..75..7 Reserved, must be 0Reserved, must be 0

0..40..4 Opcode=0Opcode=0

Page 17: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

17

Program Flow InstructionsProgram Flow Instructions

Break CodeBreak Code

CodeCode DescriptionDescription00 Runaway program breakRunaway program break

11 VM Revision numberVM Revision number

44 System Call. System Call.

55 Create Create ThunkThunk

66 Set Compiler VersionSet Compiler Version

7..2557..255 ReservedReserved

22 SkipSkip

33 Debug Break. Debug Break.

Page 18: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

18

Program Flow InstructionsProgram Flow Instructions

JMP64 [JMP64 [cs|cccs|cc] Imm64] Imm64

JMP32 [JMP32 [cs|cccs|cc], [@]R1 [Imm32]], [@]R1 [Imm32]

JMP8 [JMP8 [cs|cccs|cc] Imm8] Imm8

Page 19: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

19

Program Flow InstructionsProgram Flow Instructions

JMPJMPByteByte DescriptionDescription

00

11

2..52..5 Optional 32 bit immediate dataOptional 32 bit immediate data

2..72..7 Optional 64 bit immediate dataOptional 64 bit immediate data

BitBit DescriptionDescription

77 1=Immediate data present1=Immediate data present

66 0=32 bit immediate data 1 = 64 bit immediate data0=32 bit immediate data 1 = 64 bit immediate data

0..50..5 Opcode 1Opcode 1

BitBit DescriptionDescription

77 0= unconditional 1= conditional0= unconditional 1= conditional

66 0= CC 1=CS0= CC 1=CS

33 0 = Operand1 direct 1= Operand1 indirect0 = Operand1 direct 1= Operand1 indirect

0..20..2 Operand1Operand1

55 ReservedReserved

44 0= Absolute address 1= Relative address0= Absolute address 1= Relative address

Page 20: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

20

Program Flow InstructionsProgram Flow Instructions

JMP8JMP8

ByteByte DescriptionDescription00

11 8 bit offset8 bit offset

BitBit DescriptionDescription

77 0= Unconditional 0= Unconditional 1=Conditional1=Conditional

66 0=CC 1=CS0=CC 1=CS

0..50..5 Opcode 2Opcode 2

Page 21: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

21

Program Flow InstructionsProgram Flow Instructions

CALL32 [EX] [a] [@] R1 [Imm32]CALL32 [EX] [a] [@] R1 [Imm32]

CALL64 [EX] [a] Imm64CALL64 [EX] [a] Imm64

Page 22: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

22

Program Flow InstructionsProgram Flow Instructions

CALLCALLByteByte DescriptionDescription

00

11

2..32..3 Optional 32 bit dataOptional 32 bit data

2..72..7 Optional 64 bit immediate dataOptional 64 bit immediate data

BitBit DescriptionDescription

77 1=Immediate data present1=Immediate data present

66 0=Call32 1 = Call640=Call32 1 = Call64

0..50..5 Opcode 3Opcode 3

BitBit DescriptionDescription

66--77 Reserved, must be 0Reserved, must be 0

33 0 = Operand1 direct 1= Operand1 indirect0 = Operand1 direct 1= Operand1 indirect

0..20..2 Operand1Operand1

55 0= Call to EBC code 1= Call to Native code0= Call to EBC code 1= Call to Native code

44 0= Absolute address 1= Relative address0= Absolute address 1= Relative address

Page 23: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

23

Program Flow InstructionsProgram Flow Instructions

RETRET

ByteByte DescriptionDescription

00

11 ReservedReserved

BitBit DescriptionDescription

7..47..4 Reserved, must be 0Reserved, must be 0

0..50..5 Opcode=4Opcode=4

Page 24: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

24

CompareCompare

OpcodeOpcode cccc DescriptionDescription5/455/45 eqeq Compare Signed Equal/Not EqualCompare Signed Equal/Not Equal

6/466/46 ltelte Compare Signed Less Than or Equal/Greater Compare Signed Less Than or Equal/Greater ThanThan

7/477/47 gtegte Compare Signed Greater Than or Equal/Less Compare Signed Greater Than or Equal/Less ThanThan

8/488/48 ulteulte Compare Unsigned Less Than or Equal/Greater Compare Unsigned Less Than or Equal/Greater ThanThan

9/499/49 ugteugte Compare Unsigned Greater Than or Equal/Less Compare Unsigned Greater Than or Equal/Less ThanThan

Page 25: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

25

CompareCompare

CMP[32|64]cc R1,[@]R2[Imm16]CMP[32|64]cc R1,[@]R2[Imm16]

ByteByte DescriptionDescription00

11 OperandOperand

2..32..3 Optional 16 bit immediate dataOptional 16 bit immediate data

BitBit DescriptionDescription

77 0= No immediate data0= No immediate data

1=Immediate data present1=Immediate data present

66 0=32 bit operand width0=32 bit operand width

1=64 bit operand width1=64 bit operand width

0..50..5 CMP CMP opcodesopcodes

Page 26: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

26

CompareCompare

CMPI[32|64]cc R1,[Imm16|32]CMPI[32|64]cc R1,[Imm16|32]

ByteByte DescriptionDescription00

11 OperandOperand

2..32..3 16 bit immediate data16 bit immediate data

2..52..5 32 bit immediate data32 bit immediate data

BitBit DescriptionDescription

77 0= 16 bit immediate data0= 16 bit immediate data

1= 32 bit Immediate data 1= 32 bit Immediate data

66 0=32 bit operand width0=32 bit operand width

1=64 bit operand width1=64 bit operand width

0..50..5 CMP CMP opcodesopcodes

Page 27: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

27

Data ManipulationData Manipulation

OpcodeOpcode DescriptionDescription1010 NOT[64|32] R1,[@]R2[Imm16]NOT[64|32] R1,[@]R2[Imm16] R1 = NOT R2R1 = NOT R2

1111 NEG[64|32] R1,[@]R2[Imm16]NEG[64|32] R1,[@]R2[Imm16] R1 = NEG R2R1 = NEG R2

1212 ADD[64|32] R1,[@]R2[Imm16]ADD[64|32] R1,[@]R2[Imm16] R1 = R1+R2R1 = R1+R2

1313 SUB[64|32] R1,[@]R2[Imm16]SUB[64|32] R1,[@]R2[Imm16] R1 = R1R1 = R1--R2R2

1414 MUL[64|32] R1,[@]R2[Imm16]MUL[64|32] R1,[@]R2[Imm16] R1 = R1*R2R1 = R1*R2

1515 MULU[64|32] R1,[@]R2[Imm16]MULU[64|32] R1,[@]R2[Imm16] R1 = R1*R2R1 = R1*R2

1616 DIV [64|32] R1,[@]R2[Imm16]DIV [64|32] R1,[@]R2[Imm16] R1 = R1/R2R1 = R1/R2

1717 DIVU [64|32] R1,[@]R2[Imm16]DIVU [64|32] R1,[@]R2[Imm16] R1 = R1/R2R1 = R1/R2

1818 MOD [64|32] R1,[@]R2[Imm16]MOD [64|32] R1,[@]R2[Imm16] R1 = R1 mod R2R1 = R1 mod R2

1919 MODU [64|32] R1,[@]R2[Imm16]MODU [64|32] R1,[@]R2[Imm16] R1 = R1 mod R2R1 = R1 mod R2

2020 AND [64|32] R1,[@]R2[Imm16]AND [64|32] R1,[@]R2[Imm16] R1 = R1 and R2R1 = R1 and R2

2121 OR [64|32] R1,[@]R2[Imm16]OR [64|32] R1,[@]R2[Imm16] R1 = R1 or R2R1 = R1 or R2

Page 28: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

28

Data ManipulationData Manipulation

OpcodeOpcode DescriptionDescription2222 XOR[64|32] R1,[@]R2[Imm16]XOR[64|32] R1,[@]R2[Imm16] R1 = R1 R1 = R1 xorxor R2R2

2323 SHL[64|32] R1,[@]R2[Imm16]SHL[64|32] R1,[@]R2[Imm16] R1 = R1 R1 = R1 shlshl R2R2

2424 SHR[64|32] R1,[@]R2[Imm16]SHR[64|32] R1,[@]R2[Imm16] R1 = R1 R1 = R1 shrshr R2R2

2525 ASHR[64|32] R1,[@]R2[Imm16]ASHR[64|32] R1,[@]R2[Imm16] R1 = R1 R1 = R1 ashrashr R2R2

2626 EXTNDB[64|32] R1,[@]R2[Imm16]EXTNDB[64|32] R1,[@]R2[Imm16] Extract Byte R2, sign extend to 64 Extract Byte R2, sign extend to 64 bits and store back in R1bits and store back in R1

2727 EXTNDW[64|32] R1,[@]R2[Imm16]EXTNDW[64|32] R1,[@]R2[Imm16] Extract Word R2, sign extend to Extract Word R2, sign extend to 64 bits and store back in R164 bits and store back in R1

2828 EXTNDD [64|32] R1,[@]R2[Imm16]EXTNDD [64|32] R1,[@]R2[Imm16] Extract Extract DwordDword R2, sign extend to R2, sign extend to 64 bits and store back in R164 bits and store back in R1

Page 29: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

29

Data ManipulationData Manipulation

ByteByte DescriptionDescription

00

11 OperandOperand

2..32..3 Optional 16 bit immediate dataOptional 16 bit immediate data

BitBit DescriptionDescription

77 0= No immediate data0= No immediate data

1= Immediate data present 1= Immediate data present

66 0=32 bit operand width0=32 bit operand width

1=64 bit operand width1=64 bit operand width

0..50..5 Data Manipulation Data Manipulation opcodesopcodes

Page 30: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

30

Data MovementData Movement

MOV[s][n][B|W|D|Q][W|D|QMOV[s][n][B|W|D|Q][W|D|Q] [@]R1,[@]R2[Imm16|32|64]] [@]R1,[@]R2[Imm16|32|64]

MOV[s][n][B|W|D|Q][W|D|QMOV[s][n][B|W|D|Q][W|D|Q] [@]R1[Imm16|32|64],[@]R2] [@]R1[Imm16|32|64],[@]R2

MOVI[B|W|D|Q][W|D|Q] [@]R1[Imm16],Imm16|32|64MOVI[B|W|D|Q][W|D|Q] [@]R1[Imm16],Imm16|32|64

MOVIn[W|D|QMOVIn[W|D|Q] [@]R1[Imm16],Imm16|32|64] [@]R1[Imm16],Imm16|32|64

MOVREL{W|D|Q] [@]R1[Imm16],Imm16|32|64MOVREL{W|D|Q] [@]R1[Imm16],Imm16|32|64

Page 31: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

31

Data MovementData Movement

OpcodeOpcode DescriptionDescription2929 MOVbwMOVbw [@]R1[Imm16],[@]R2[Imm16][@]R1[Imm16],[@]R2[Imm16]

3030 MOVwwMOVww [@]R1[Imm16],[@]R2[Imm16][@]R1[Imm16],[@]R2[Imm16]

3131 MOVdwMOVdw [@]R1[Imm16],[@]R2[Imm16][@]R1[Imm16],[@]R2[Imm16]

3232 MOVqwMOVqw [@]R1[Imm16,[@]R2[Imm16][@]R1[Imm16,[@]R2[Imm16]

3333 MOVbdMOVbd [@]R1[Imm32],[@]R2[Imm32][@]R1[Imm32],[@]R2[Imm32]

3434 MOVwdMOVwd [@]R1 [Imm32],[@]R2[Imm32][@]R1 [Imm32],[@]R2[Imm32]

3535 MOVddMOVdd [@]R1 [Imm32],[@]R2[Imm32][@]R1 [Imm32],[@]R2[Imm32]

3636 MOVqdMOVqd [@]R1 [Imm32],[@]R2[Imm32][@]R1 [Imm32],[@]R2[Imm32]

Page 32: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

32

Data MovementData Movement

OpcodeOpcode DescriptionDescription3737 MOVsnwMOVsnw [@]R1[Imm16],[@]R2[Imm16][@]R1[Imm16],[@]R2[Imm16]

3838 MOVsndMOVsnd [@]R1[Imm32],[@]R2[Imm32][@]R1[Imm32],[@]R2[Imm32]

4040 MOVqqMOVqq [@]R1[Imm64],[@]R2[Imm64][@]R1[Imm64],[@]R2[Imm64]

5050 MOVnwMOVnw [@]R1[Imm16],[@]R2[Imm16][@]R1[Imm16],[@]R2[Imm16]

5151 MOVndMOVnd [@]R1[Imm32,[@]R2[Imm32][@]R1[Imm32,[@]R2[Imm32]

Page 33: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

33

Data MovementData Movement

MOV/MOV/MOVnMOVn

ByteByte DescriptionDescription

00

11 OperandOperand

2..32..3 Optional 16 bit immediate dataOptional 16 bit immediate data

2..52..5 Optional 32 bit immediate dataOptional 32 bit immediate data

2..92..9 Optional 64 bit immediate dataOptional 64 bit immediate data

BitBit DescriptionDescription

77 0= Operand 1 index absent0= Operand 1 index absent

1= Operand 1 index present1= Operand 1 index present

66 0= Operand 2 index absent0= Operand 2 index absent

1= Operand 2 index present1= Operand 2 index present

0..50..5 MovMov opcodesopcodes

Page 34: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

34

Data MovementData Movement

MOVI/MOVI/MOVInMOVInByteByte DescriptionDescription

00

11

2..32..3 16 bit immediate index (Optional)16 bit immediate index (Optional)

4..54..5 16 bit immediate data16 bit immediate data

4..74..7 32 bit immediate data32 bit immediate data

4..114..11 64 bit immediate data64 bit immediate data

BitBit DescriptionDescription

6..76..7 0 = Reserved, 1=16bits, 2=32 bits 3=64bits0 = Reserved, 1=16bits, 2=32 bits 3=64bits

0..50..5 Opcode 55=MOVI 56=Opcode 55=MOVI 56=MOVInMOVIn

BitBit DescriptionDescription

77 Reserved, must be 0Reserved, must be 0

33 0=Operand 1 direct, 1= Operand 1 indirect0=Operand 1 direct, 1= Operand 1 indirect

0..20..2 Operand 1Operand 1

66 0 = Optional immediate absent,0 = Optional immediate absent,

1= Optional immediate present1= Optional immediate present

4..54..5 0=8bit move, 1=16bit 0=8bit move, 1=16bit movmov, 2=32bit move , 2=32bit move 3=64bit move3=64bit move

Page 35: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

35

Data MovementData Movement

PUSH/POPPUSH/POP

OpcodeOpcode DescriptionDescription

4343 PUSH [@] R1 [Imm16]PUSH [@] R1 [Imm16]

4444 POP [@] R1 [Imm16]POP [@] R1 [Imm16]

5353 PUSHnPUSHn [@] R1 [Imm16][@] R1 [Imm16]

5454 POPnPOPn [@] R1 [Imm16][@] R1 [Imm16]

Page 36: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

36

Data MovementData Movement

ByteByte DescriptionDescription

00BitBit DescriptionDescription

77 0= No immediate data0= No immediate data

1= Immediate data present 1= Immediate data present

66 0=32 bit operand width0=32 bit operand width

1=64 bit operand width1=64 bit operand width

0..50..5 Push or Pop Push or Pop OpcodesOpcodes

Page 37: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

37

Special Register MoveSpecial Register Move

LOADSP SP1,R2 LOADSP SP1,R2

ByteByte DescriptionDescription

00

11

BitBit DescriptionDescription

6..76..7 Reserved, must be 0Reserved, must be 0

0..50..5 Opcode =41Opcode =41

BitBit DescriptionDescription

77 Reserved, must be 0Reserved, must be 0

0..20..2 Operand1. Special purpose registerOperand1. Special purpose register

4..64..6 OperandOperand--2. General purpose 2. General purpose registerregister

33 Reserved, must be 0Reserved, must be 0

Page 38: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

38

Special Register MoveSpecial Register Move

STORESP R1,SP1STORESP R1,SP1

ByteByte DescriptionDescription

00

11

BitBit DescriptionDescription

6..76..7 Reserved, must be 0Reserved, must be 0

0..50..5 Opcode =42Opcode =42

BitBit DescriptionDescription

77 Reserved, must be 0Reserved, must be 0

0..20..2 Operand2. General purpose registerOperand2. General purpose register

4..64..6 Operand1. Special purpose registerOperand1. Special purpose register

33 Reserved, must be 0Reserved, must be 0

Page 39: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

39

Development EnvironmentDevelopment Environment

Windows* 32Windows* 32–– IntelIntel®® C Compiler for EFI Byte Code, Version 1.2 Build C Compiler for EFI Byte Code, Version 1.2 Build

2004012320040123

–– Use "C:Use "C:\\Program FilesProgram Files\\IntelIntel\\EBCEBC\\binbin\\iecvars.batiecvars.bat" to launch " to launch EBC compilation and linking environmentEBC compilation and linking environment

LinkerLinker–– Microsoft* linker Version 7.10.3077 and aboveMicrosoft* linker Version 7.10.3077 and above

*Other names and brands may be claimed as the property of others*Other names and brands may be claimed as the property of others..

Page 40: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

40

Calling conventionCalling convention

CDECL onlyCDECL only–– R0: Stack Pointer, R7: return valueR0: Stack Pointer, R7: return value–– Like IA32. Like IA32.

–– All parameters are passed through stack including 8All parameters are passed through stack including 8--byte structure/long byte structure/long long.long.

–– Return value is passed through stack if larger than 8Return value is passed through stack if larger than 8--bytebyte

Between EBC and nativeBetween EBC and native–– EBC EBC EBCEBC

–– Call/RetCall/Ret–– May imply EBC May imply EBC nativenative EBCEBC

–– EBC EBC native codenative code–– CallExCallEx, VM to handle calling convention, VM to handle calling convention

–– Native code Native code EBCEBC–– Break 5, to create Break 5, to create thunkthunk for address taken EBC functions when EBC image for address taken EBC functions when EBC image

loadingloading–– One level indirect assignment for EBC function pointer due to thOne level indirect assignment for EBC function pointer due to the existence e existence

of of thunkingthunking entryentry

Page 41: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

41

Object/Image formatObject/Image format

Object Format Object Format ––COFFCOFF

Executable FormatExecutable Format––MS PE32 formatMS PE32 format

SegmentsSegments–– TEXT, DATA, BSSTEXT, DATA, BSS–– ..CRT$xxxCRT$xxx–– _VARBSS_INIT_VARBSS_INIT

Page 42: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

42

Language Examples(1)Language Examples(1)

main()main()

{{

intint **xpxp, x, y;, x, y;

y = 8;y = 8;

xpxp = &y;= &y;

x = *x = *xpxp;;

}}

MOVqw R0, R0(+0,MOVqw R0, R0(+0,--16) 16)

MOVIdw @R0(+0,+8), +8 MOVIdw @R0(+0,+8), +8

MOVnw @R0, R0(+0,+8) MOVnw @R0, R0(+0,+8)

MOVnw R7, @R0 MOVnw R7, @R0

MOVdw @R0(+0, +12), @R7 MOVdw @R0(+0, +12), @R7

MOVqd R7, R6 MOVqd R7, R6

MOVqw R0, R0(+0,+16) MOVqw R0, R0(+0,+16)

RET RET

Page 43: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

43

Language Examples(2)Language Examples(2)

intint PASS;PASS;long long f(longf(long x)x){{return return x+sizeof(intx+sizeof(int););

}}main()main(){{long x, y;long x, y;

x=4;x=4;y = y = f(xf(x););if ((if ((y+f(xy+f(x))==16) PASS=1;))==16) PASS=1;else PASS=0;else PASS=0;

}}

f: f:

MOVsnwMOVsnw R7, @R0(+0,+16) R7, @R0(+0,+16)

MOVIqwMOVIqw R4, 4 R4, 4

ADD R7, R4 ADD R7, R4

RETRET

main: main:

MOVqwMOVqw R0, R0(+0,R0, R0(+0,--48) 48)

MOVInwMOVInw @R0(0,8), (0,4) @R0(0,8), (0,4)

MOVsnwMOVsnw @R0, @R0(+0,+8) @R0, @R0(+0,+8)

CALL f CALL f

MOVnwMOVnw @R0(+0,+24), R7 @R0(+0,+24), R7

MOVsnwMOVsnw @R0(+0,+16), @R0(+0,+24)@R0(+0,+16), @R0(+0,+24)

MOVsnwMOVsnw @R0, @R0(+0,+8) @R0, @R0(+0,+8)

CALL f CALL f

MOVnwMOVnw @R0(+0,+32), R7 @R0(+0,+32), R7

MOVsnwMOVsnw R7, @R0(+0,+16) R7, @R0(+0,+16)

MOVnwMOVnw R4, @R0(+0,+32) R4, @R0(+0,+32)

ADD R7, R4 ADD R7, R4

MOVsnwMOVsnw R7, R7 R7, R7

CMPIeqCMPIeq R7, 16 R7, 16

JMP8cc $B2$5 JMP8cc $B2$5

MOVreldMOVreld R7, PASS R7, PASS

MOVIdwMOVIdw @R7, +1 @R7, +1

JMP8 $B2$6 JMP8 $B2$6

$B2$5: $B2$5:

MOVreldMOVreld R7, PASS R7, PASS

MOVdwMOVdw @R7, R6 @R7, R6

$B2$6: $B2$6:

MOVqdMOVqd R7, R6 R7, R6

MOVqwMOVqw R0, R0(+0,+48) R0, R0(+0,+48)

RETRET

Page 44: Pcg object/debug generation - UEFI · –Intel® C Compiler for EFI Byte Code, Version 1.2 Build 20040123 –Use "C:\Program Files\Intel\EBC\bin\iecvars.bat" to launch EBC compilation

DemoDemo