对PowerPC的学习笔记

来源:互联网 发布:python 递归深度 编辑:程序博客网 时间:2024/05/22 13:33

寄存器

GPR(General Purpose Registers)                                       32个64bitGPR0到GPR31。在某些情况,GPR0代表数值0,而非GPR0的内容。

Floating Point

         FPR(Floating Point Register)                                       32个,FPR0到FPR31。

         FPSCR(Floating Point Status and Control Register)   对FPSCR的访问,需要通过FPR。

Vector Register

          VR(Vector Register)                                                                32个128bit

          VSCR(Vector Status and Control Register)                        32bit。

VSR(Vector Scalar Extension)                                                        64个128bit。

SPR(Special Purpose Registers)

         PC(Program Counter)/NIP(Next Instruction Pointer) / IAR(Instruction Address Register) 下一条指令

         LR(Link Register)                                                          函数返回地址,64bit。

         CR(Condition Register)                                                分为八个字段,每字段4bit,共32bit。

         XER(Fixed-Point Exception Register)                           整数运算的进位和溢出。

         CTR(Counter Register)                                                 计数寄存器,64bit。

         PVR(Processor Version Register)                                版本,这都做成寄存器了。。。

         


指令

使用RISC架构,每条指令为32-bit。

汇编语言中,寄存器使用数字来表示的。

立即数指令,通常以 i 结尾。如, addi, li


powerpc指令可以划分为三大类

book1   :  用户指令,不需要特权及

book2   :  略高级的用户指令,如缓存管理,原子操作。不需要特权级,但通常通过系统调用完成。

book3   :  操作系统使用,需要特权及。如异常向量处理,内存管理。


数据长度的单位,老是记不住,就写着把。

字节(8 位)、半字(16 位)、字(32 位) 和双字(64 位)



指令格式


因为每条指令的长度固定,32bit,所以立即数的执行,一次最多只能存取16bit。

-----------------------------------------------------------------------------------|    opcode    | src register | dest register |     immediate value      ||    6 bits       |   5 bits         |    5 bits         |         16 bits                  |-----------------------------------------------------------------------------------


格式06111621263031D-formopcdtgt/srcsrc/tgtimmediateX-formopcdtgt/srcsrc/tgtsrcextended opcdA-formopcdtgt/srcsrc/tgtsrcsrcextended opcdRcBD-formopcdBOBIBDAALKI-formopcdLIAALK

D-form:  立即数操作

BD-form: 条件转移指令使用这个格式

I-form: 绝对转移指令


指令分类

指令类别基本指令Branchbranch, branch conditional, branch to LR, branch to CTRCondition registercrand, crnor, creqv, crxor, crandc, crorc, crnand, cror, CR moveStorage accessload GPR/FPR, store GPR/FPRInteger arithmeticadd, subtract, negate, multiply, divideInteger comparisoncompare algebraic, compare algebraic immediate,
compare logical,compare logical immediateInteger logicaland, andc, nand, or, orc, nor, xor, eqv, sign extension,
countleading zerosInteger rotate/shiftrotate, rotate and mask, shift left, shift rightFloating-point arithmeticadd, subtract, negate, multiply, divide, square root,
multiply-add,multiply-subtract, negative multiply-add,
negative multiply-subtractFloating-point comparisoncompare ordered, compare unorderedFloating-point conversionround to single, convert from/to integer word/doublewordFPSCR managementmove to/from FPSCR, set/clear FPSCR bit,
copy FPSCR field to CRCache controltouch, zero, flush, storeProcessor managementsystem call, move to/from special purpose registers, mtcrf, mfcr


ABI

ppc32遵从svr4 

ppc64遵从PowerOpen ABI



中断函数

在PowerISA 6.5 Interrupt Definitions中定义了可用的中断,和对应的Effective Address。

中断发生时,会跳转到相应的地址。


在代码中对应的地方是 arch/powerpc/kernel/exceptions-64s.S 中的 __start_interrupts.

在不同的偏移量上注册了相应的中断处理函数,正好和PowerISA上的对应。


根据注释,这段代码会被拷贝到read address 0x100的位置。


@toc

经常看到这个,但是不懂什么意思。今天查到,记录一下。


首先在ELF格式中有TOC(或者GOC)这么一个表,我觉得这个表存储了一些符号的地址。

通常这个表的首地址放在R2中。

Symbol@toc表示的是Symbol这个符号在TOC中的偏移。

Symbol@toc(r2) 我感觉就是这个符号的地址了。


觉得描述大小端很好的一张图


从PowerISA 文档中截取。


Storage Control

从PowerISA 5.7摘录

1. Effective Address                         ->               Virtual Address                 ->                 Real Address

                                      Segment Lookaside Buffer                      Page Table

2. Effective Address Space 2^64 bytes

3. Real Address space 2^m bytes, m <= 60



General Picture for Address Translation




 Effective Address -> Virtual Address


SLB Entry 


Each SLB Entry map one ESID to VSID


ESID:  Effective Segment ID

VSID:  Virtual Segment ID









原创粉丝点击