<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jack&#039;s Lab</title>
	<atom:link href="http://www.jackslab.org/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.jackslab.org</link>
	<description>好奇之心，改变之力</description>
	<lastBuildDate>Sun, 02 Jul 2017 02:48:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>AboutMe</title>
		<link>http://www.jackslab.org/?p=455</link>
		<comments>http://www.jackslab.org/?p=455#comments</comments>
		<pubDate>Tue, 24 Sep 2013 04:16:45 +0000</pubDate>
		<dc:creator>Jack Tan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jackslab.org/?p=455</guid>
		<description><![CDATA[http://jackslab.org/aboutme]]></description>
			<content:encoded><![CDATA[<p>http://jackslab.org/aboutme</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jackslab.org/?feed=rss2&#038;p=455</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>快速搭建简易 ftp 服务</title>
		<link>http://www.jackslab.org/?p=408</link>
		<comments>http://www.jackslab.org/?p=408#comments</comments>
		<pubDate>Fri, 31 Aug 2012 13:15:19 +0000</pubDate>
		<dc:creator>Jack Tan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[基础设施]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[Smart Home]]></category>
		<category><![CDATA[VPS]]></category>
		<category><![CDATA[vsftpd]]></category>

		<guid isPermaLink="false">http://www.jackslab.org/?p=408</guid>
		<description><![CDATA[vftpd 快速配置，适合个人和家庭用户搭建个性私人服务和家人朋友共享]]></description>
			<content:encoded><![CDATA[<p><strong>1. 安装 vsftpd</strong></p>
<p>Debian/Ubuntu 下：</p>
<pre>$ sudo apt-get install vsftpd</pre>
<p>安装完后，会自动向 /etc/passwd 和 /etc/group 添加一个 ftp 用户，一个 ftp 组</p>
<p>&nbsp;</p>
<p><strong>2. 使用匿名用户</strong></p>
<p>配置文件 /etc/vsftpd.conf</p>
<p>vsftpd 的匿名用户 (anonymous) 需要对应系统的本地用户，默认情形下对应 ftp，可通过如下选项控制：</p>
<pre>ftp_username = ftp</pre>
<p># 允许匿名用户登录，无须密码<br />
anonymous_enable=YES<br />
no_anon_password=YES</p>
<p># 允许匿名用户建立目录<br />
anon_mkdir_write_enable=YES<br />
# 允许匿名上传文件<br />
anon_upload_enable=YES</p>
<p>上述匿名用户的 mkdir 和 upload 权限，必须打开这个选项才能生效：<br />
write_enable=YES<br />
而且匿名用户在系统中对应的用户，必须对操作的目录有写权限</p>
<p># 改变匿名用户上传之文件属于系统本地用户 ftp<br />
chown_uploads=YES # 此选项默认为 NO，则匿名用户上传的文件自己没法下载没法查看<br />
chown_username=ftp</p>
<p># 匿名上传之文件的权限<br />
chown_upload_mode=0744</p>
<p>如果 chown_upload_mode=0222<br />
则 匿名用户不能查看和下载自己上传的文件</p>
<p># 不允许 /etc/passwd 中的本地用户登录 ftp<br />
local_enable=NO</p>
<p>&nbsp;</p>
<p><strong>3. vsftpd 一般默认使用 /srv/ftp 作为匿名用户登录后的主目录</strong></p>
<p>这个目录一般在安装完成后会自动建立，大多数情形下我们还是用自己的目录：</p>
<pre class="brush:bash">
$ su root
$ mkdir /data/ftp
</pre>
<p>在配置文件中重新指定匿名用户的根目录:</p>
<p>anon_root=/data/ftp</p>
<p>不管 /data/ftp 属于谁，anonymous 对应的用户 ftp 不能对该目录有写权限（安全考虑），否则连接后会报：<br />
OOPS: vsftpd: refusing to run with writable anonymous root</p>
<p>因此，为保证匿名用户的上传权限，可在 /data/ftp 目录下，再建立一个 upload 目录，赋予 ftp 读写执行的权限即可:</p>
<pre>$ mkdir -p /data/ftp/upload
$ chown ftp /data/ftp/upload</pre>
<pre></pre>
<p><strong>4. 允许匿名用户更多的权限</strong></p>
<p>以上配置下，即使匿名用户自己上传的文件权限是 744，其也不能删除和重命名自己上传的文件，除非打开如下选项：</p>
<p>#除了上传和创建目录外，还可以重命名，删除文件<br />
anon_other_write_enable=YES （经测试，不可用）</p>
<p>&nbsp;</p>
<p><strong>5. 本地用户</strong></p>
<p>要使用本地用户，则修改配置为：</p>
<p>local_enable=YES</p>
<p>本地用户的登录控制，通过 /etc/ftpuser 文件控制:</p>
<pre class="brush:bash">
root@hahaha:/var/data# cat /etc/ftpusers
# /etc/ftpusers: list of users disallowed FTP access. See ftpusers(5).
root
daemon
bin
sys
sync
man
lp</pre>
<p>在其中挂名的，不能从 vsftpd 登录</p>
<p>对于本地用户，其 vsftpd 用户主目录默认为其 home 目录，如 jjyy，则客户端登录后直接到 /home/jjyy</p>
<p>可通过配置选项来改变这个用户登录后的 vsftpd 主目录：</p>
<p>local_root=/var/ftp</p>
<p>对本地用户没有权限限制</p>
<p>默认情形下配置选项 chroot_local_user=NO，表示本地用户可以随意访问整个系统的文件系统，即：对可登录的本地用户来说，其根目录就是整个 Linux 系统的根目录，没有被 chroot 到用户主目录下，这是一个安全隐患：</p>
<p>chroot_local_user=YES</p>
<p>则将可登录的本地用户根目录 chroot 到其的用户主目录下，这样其就不能看到和访问整个文件系统的根目录</p>
<p>对于需要开放整个文件系统的本地用户，可以通过如下选项控制之：</p>
<p>chroot_local_user=YES<br />
chroot_list_enable=YES<br />
chroot_list_file=/etc/vsftpd.chroot_list</p>
<p>在 /etc/vsftpd.chroot_list 列上需要的用户名即可</p>
<p>&nbsp;</p>
<p>6. 磁盘配额</p>
<p>为特定用户配额适当的磁盘空间，以防服务被滥用</p>
<pre class="brush:bash">
$ apt-get install quota
$ mount -o usrquota,grpquota /dev/xvdb /mnt

$ quota -uvs ftp # 查看 ftp 配额
$ edquota -u ftp # 编辑配额
Disk quotas for user hom (uid 501):

Filesystem blocks soft hard inodes soft hard

/dev/sdb5 16 0 1024 4 0 0

改列 hard，单位为 KB

$ quotaon -avu # 打开磁盘配额监控进程
$ quota -uvs ftp # 查看 ftp 配额
Disk quotas for user ftp (uid 104):
Filesystem space quota limit grace files quota limit grace
/dev/xvdb 30768K 0K 4883M 6 0 0

$ quotaoff -vug /dev/xvdb # 关闭 xvdb 的配额
</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jackslab.org/?feed=rss2&#038;p=408</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CFE Quick Start</title>
		<link>http://www.jackslab.org/?p=280</link>
		<comments>http://www.jackslab.org/?p=280#comments</comments>
		<pubDate>Wed, 23 Feb 2011 06:17:15 +0000</pubDate>
		<dc:creator>Jack Tan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[基础设施]]></category>
		<category><![CDATA[bootloader]]></category>
		<category><![CDATA[CFE]]></category>
		<category><![CDATA[quickstart]]></category>

		<guid isPermaLink="false">http://www.jackslab.org/?p=280</guid>
		<description><![CDATA[CFE 快速上手]]></description>
			<content:encoded><![CDATA[<h3>1. CFE Boot Log</h3>
<pre class="brush:bash">CFE version 1.2.4 for SWARM (64bit,MP,BE,MIPS)
Build Date: Tue Aug 30 06:45:43 PDT 2005 (mpl@lc-sj1-092)
Copyright (C) 2000,2001,2002,2003,2004,2005 Broadcom Corporation.

Initializing Arena.
Initializing PCI. [normal]
PCI bus 0 slot 1/0: Warning: SipReady already set
HyperTransport not initialized: InitDone not set
PCI bus 0 slot 0/0: SiByte, Inc. BCM1250 PCI Host Bridge (host bridge, rev 0x02)
PCI bus 0 slot 6/0: unknown vendor 0x1317 product 0x0985 (ethernet network, rev 0x11)
PCI bus 0 slot 7/0: unknown vendor 0x1045 product 0xc861 (USB serial bus, interface 0x10, rev 0x10)
Initializing Devices.
SWARM board revision 3
sbeth: found phy 1, vendor 000818 part 0E
sbeth: found phy 1, vendor 000818 part 0E
PCIIDE: 0 controllers found
Config switch: 2
CPU: BCM1250 B2
L2 Cache Status: OK
Wafer ID:   0x8FC26019  [Lot 9200, Wafer 19]
Manuf Test: Bin A [2CPU_FI_FD_F2 (OK)]
SysCfg: 0000000028DB0800 [PLL_DIV: 16, IOB0_DIV: CPUCLK/4, IOB1_DIV: CPUCLK/3]
CPU type 0x1040102: 800MHz
Total memory: 0x10000000 bytes (256MB)

Total memory used by CFE:  0x8FE9C000 - 0x8FFFFD00 (1457408)
Initialized Data:          0x8FEF69A0 - 0x8FEFD650 (27824)
BSS Area:                  0x8FEFD650 - 0x8FEFDD00 (1712)
Local Heap:                0x8FEFDD00 - 0x8FFFDD00 (1048576)
Stack Area:                0x8FFFDD00 - 0x8FFFFD00 (8192)
Text (code) segment:       0x8FE9C000 - 0x8FEF608D (368781)
Boot area (physical):      0x0FE5B000 - 0x0FE9B000
Relocation Factor:         I:F029C000 - D:F029C000

Automatic startup canceled via Ctrl-C</pre>
<p><span id="more-280"></span></p>
<h3>2. Config to bootstrap</h3>
<h4>2.0 Display devices</h4>
<pre class="brush:bash">CFE&gt; show devices

Device Name          Description
 -------------------  ---------------------------------------------------------
uart0                Si Byte DUART at 0x10060000 channel 0
promice0             Prom ICE AI2 Serial Port at 0x1FDFFC00
eeprom0              Microchip 24LC128 EEPROM on SMBus channel 1 dev 0x51
uart1                Si Byte DUART at 0x10060000 channel 1
flash0               New CFI flash at 1FC00000 size 2048KB
flash1               New CFI flash at 1F800000 size 2048KB
eeprom1              Microchip 24LC128 EEPROM on SMBus channel 0 dev 0x50
eth0                 Si Byte Ethernet at 0x10064000 (00-02-4C-FE-03-E6)
eth1                 Si Byte Ethernet at 0x10065000 (00-02-4C-FE-03-E7)
ide0.0               IDE disk unit 0 at 100B3E00
pcmcia0              PCMCIA ATA disk unit 0 at 11000000
clock0               ST M41T81 RTC on SMBus channel 1 dev 0x68
tcpconsole0          TCP Console</pre>
<h4>2.1 Config network</h4>
<pre class="brush:bash">CFE&gt; ifconfig -auto eth0
or:
  CFE&gt; ifconfig -addr=192.168.29.128 -gw=192.168.29.1 -mask=255.255.255.0 eth0

  <strong>Options</strong>

     -auto        Configure interface automatically via DHCP
     -off         Deactivate the specified interface
     -addr=*      Specifies the IP address of the interface
     -mask=*      Specifies the subnet mask for the interface
     -gw=*        Specifies the gateway address for the interface
     -dns=*       Specifies the name server address for the interface
     -domain=*    Specifies the default domain for name service queries
     -speed=*     Sets the interface speed (auto,10fdx,10hdx,100fdx,
                  100hdx,1000fdx,1000hdx)
     -loopback=*  Sets the loopback mode (off,internal,external)  External
                  loopback causes the phy to be placed in loopback mode
     -hwaddr=*    Sets the hardware address (overrides environment)</pre>
<h4>2.2 Load &amp; execute</h4>
<p>CFE support loading <span style="color: #ff00ff;">ELF, SREC, uboot image (uImage) and binary format</span>.</p>
<pre class="brush:bash">CFE&gt; load -elf 192.168.29.11:vlm-boards/8336/vmlinux              # load vmlinux at virtual 0x2000 0000 via tftp
CFE&gt; load -srec 192.168.29.11:vlm-boards/8336/vmlinux.srec        # load vmlinux.srec at virtual 0x2000 0000 via tftp
CFE&gt; load -uboot 192.168.29.11:vlm-boards/8336/uImage             # load uImage at virtual 0x2000 0000 via tftp

  <strong>Options:</strong>

     -raw         Load the file as a raw binary  (default)
     -z           Load compressed file

     -tftp        Load the file using the TFTP protocol (default)
     -fatfs       Load the file from a FAT file system
     -rawfs       Load the file from an unformatted file system
     -http        Load the file using the HTTP protocol

     -max=*       Specify the maximum number of bytes to load (raw only)
     -addr=*      Specify the load address (hex) (raw only)
     -noclose     Don't close network link before executing program

CFE&gt; go                                                             # go to the start address(entry address) to execute
CFE&gt; go  0x804117f0</pre>
<p>CFE support loading file from devices. We can use following command to load kernel from a IDE disk:</p>
<pre class="brush:bash">CFE&gt; load -elf -fatfs ide0.0:vmlinux</pre>
<p>Generally, we use &#8216;boot&#8217; to load the kernel and go to the entry address (load + go):</p>
<pre class="brush:bash">CFE&gt; boot -elf 192.168.29.11:vlm-boards/8336/vmlinux 

Loader:elf Filesys:tftp Dev:eth0 File:192.168.29.11:vlm-boards/8336/vmlinux Options:(null)
Loading: 0xffffffff80100000/4399238 0xffffffff80532086/200090 Entry at 0x804117f0
Closing network.
Starting program at 0x804117f0

Linux version 2.6.26-rc7-WR3.0zz_standard (root@Pek-JTan-d1) (gcc version 4.1.2 (Wind River Linux Sourcery G++ 4.1-91)) #2 PREEMPT Wed Jun 25 12:52:52 CST 2008
console [early0] enabled
CPU revision is: 01040102 (SiByte SB1)
FPU revision is: 000f0102
Checking for the multiply/shift bug... no.
Checking for the daddiu bug... no.
Broadcom SiByte BCM1250 B2 @ 800 MHz (SB1 rev 2)
Board type: SiByte BCM91250A (SWARM)
This kernel optimized for board runs with CFE
Determined physical RAM map:
 memory: 000000000fe9be00 @ 0000000000000000 (usable)
Initrd not found or empty - disabling initrd
......</pre>
<h4>2.3 Setting environment varible</h4>
<p>CFE use STARTUP as the automatic bootstrap commands and LINUX_CMDLINE as the kernel arguments::</p>
<pre class="brush:bash">CFE&gt; printenv
Variable Name        Value
-------------------- --------------------------------------------------
BOOT_CONSOLE         uart0
ETH0_HWADDR          00-02-4c-fe-03-e6
ETH1_HWADDR          00-02-4c-fe-03-e7
STARTUP              ifconfig -auto eth0; boot -srec 192.168.29.11:/vlm-boards/8336/kernel
LINUX_CMDLINE        root=/dev/nfs rw nfsroot=192.168.29.11:/export/pxeboot/vlm-boards/8336/rootfs ip=dhcp
CPU_TYPE             1250
CPU_SPEED            800
CPU_REVISION         B2
CPU_NUM_CORES        2
CFE_VERSION          1.2.4
CFE_BOARDNAME        SWARM
CFE_MEMORYSIZE       256</pre>
<p>After booting up, CFE automatically execute “ifconfig -auto eth0; boot -srec 192.168.29.11:/vlm-boards/8336/kernel”</p>
<p>So, maybe you need to reset the LINUX_CMDLINE:</p>
<pre class="brush:bash">CFE&gt; setenv LINUX_CMDLINE "root=/dev/nfs rw nfsroot=192.168.29.11:/export/pxeboot/vlm-boards/8336/rootfs  ip=192.168.29.148"</pre>
<p>If you want to store the environment variable permanently in the NVRAM, you need to use the -p option.</p>
<pre class="brush:bash">     -p           Store environment variable permanently in the NVRAM device, if present
     -ro          Causes variable to be read-only (cannot be changed in the future, implies -p)</pre>
<h3>3. Memory commands</h3>
<h4>3.1 Disassemble instructions</h4>
<pre class="brush:bash">CFE&gt; u 0xbfc01000 5
BFC01000: 24040000    addiu    a0,zero,#0
BFC01004: 0000328c    syscall  #202
BFC01008: 1000ffff    beq      zero,zero,0xffffffffbfc01008
BFC0100C: 00000000    sll      zero,zero,#0
BFC01010: 3c08bfc0    lui      t0,#49088</pre>
<h4>3.2 Dump memory</h4>
<pre class="brush:bash">CFE&gt; d -b 0xbfc01000 0x30
FFFFFFFFBFC01000: 24 04 00 00 00 00 32 8C 10 00 FF FF 00 00 00 00  $.....2.........
FFFFFFFFBFC01010: 3C 08 BF C0 01 00 00 08 00 00 00 00 27 BB FD B0  &lt;...........'...
FFFFFFFFBFC01020: 00 1B D8 FA 00 1B D8 F8 FF 60 00 40 FF 61 00 48  .........`.@.a.H

CFE&gt; d -h 0xbfc01000 16
FFFFFFFFBFC01000: 2404 0000 0000 328C 1000 FFFF 0000 0000  $.....2.........
FFFFFFFFBFC01010: 3C08 BFC0 0100                           &lt;.....          

CFE&gt; d -q 0xbfc01000 16
FFFFFFFFBFC01000: 240400000000328C 1000FFFF00000000  $.....2.........
FFFFFFFFBFC01010: 3C08BFC001000008                   &lt;.....</pre>
<h4>3.3 Modify memory</h4>
<pre class="brush:bash">CFE&gt; e -w 0x80000000 0x12345678
CFE&gt; d -w 0x80000000
FFFFFFFF80000000: 12345678 277BDE48 03600008 241A0008  .4Vx'{.H.`..$...
FFFFFFFF80000010: 00000000 00000000</pre>
<p>If you omit the data, CFE will enter “memory edit” mode:</p>
<pre class="brush:bash">CFE&gt; e -w 0x80000000
Type '.' to exit, '-' to back up, '=' to dump memory.
FFFFFFFF80000000: [12345678]:</pre>
<h4>3.4 Fill memory</h4>
<p>Usage:</p>
<pre class="brush:bash"> f [-b|-h|-w|-q] addr length pattern</pre>
<pre class="brush:bash">CFE&gt; f -h 80000000 0x10 0x55aa
CFE&gt; d -h 80000000 0x30
FFFFFFFF80000000: 55AA 55AA 55AA 55AA 55AA 55AA 55AA 55AA  U.U.U.U.U.U.U.U.
FFFFFFFF80000010: 55AA 55AA 55AA 55AA 55AA 55AA 55AA 55AA  U.U.U.U.U.U.U.U.
FFFFFFFF80000020: 0000 0000 0000 0000 0000 0000 0000 0000  ................</pre>
<h3>4. Flash commands</h3>
<h4>4.1 show flash</h4>
<p>This command is to display information of a flash device:</p>
<pre class="brush:bash">CFE&gt; show flash flash0
FLASH: Base 000000001FC00000 size 00200000 type 03(Flash) flags 00000001
NVRAM: Not supported by this flash</pre>
<h4>4.2 update flash</h4>
<p>To update flash we use &#8216;flash&#8217; command.</p>
<p>Under most circumstances, the file to be written to flash must be the output of the mkflashimage program in the cfe/hosttools directory.The mkflashimage program writes a header on the front of the flash image that contains version information, the file’s length and a CRC to prevent inadvertently writing a bad image into the system’s boot ROM.</p>
<pre class="brush:bash">CFE&gt; flash flash0 flash1                                          # backup flash0's data into flash1
CFE&gt; flash -noheader 192.168.29.11:vlm-boards/8336/cfe            # write data to default device flash0 via tftp
CFE&gt; flash uart0 flash0                                           # read S-records from uart0 and write the data to flash0

 <strong>OPTIONS</strong>
     -noerase     Don't erase flash before writing
     -offset=*    Begin programming at this offset in the flash device
     -size=*      Size of source device when programming from flash to flash
     -noheader    Override header verification, flash binary without checking</pre>
<h3>5. Miscellaneous</h3>
<h4>5.1 Reset system</h4>
<pre class="brush:bash">CFE&gt; reset -yes -sysreset                                                      # Full system reset
CFE&gt; reset -yes -cpu                                                           # Reset the CPUs
CFE&gt; reset -yes -softreset                                                     # Soft reset of the entire chip</pre>
<h4>5.2 Show TLB</h4>
<pre class="brush:bash">CFE&gt; show tlb
Entry 00  C0000FFFA007E000 0000000000000000 0000000000000000
Entry 01  C0000FFFA007C000 0000000000000000 0000000000000000
Entry 02  C0000FFFA007A000 0000000000000000 0000000000000000
Entry 03  C0000FFFA0078000 0000000000000000 0000000000000000
Entry 04  C0000FFFA0076000 0000000000000000 0000000000000000
Entry 05  C0000FFFA0074000 0000000000000000 0000000000000000
......
......</pre>
<h4>5.3 Show PCI</h4>
<pre class="brush:bash">CFE&gt; show pci
PCI bus 0 slot 0/0: SiByte, Inc. BCM1250 PCI Host Bridge (host bridge, rev 0x02)
PCI bus 0 slot 1/0: SiByte, Inc. BCM1250 HyperTransport Host Bridge (host bridge, rev 0x02)
PCI bus 0 slot 6/0: unknown vendor 0x1317 product 0x0985 (ethernet network, rev 0x11)
PCI bus 0 slot 7/0: unknown vendor 0x1045 product 0xc861 (USB serial bus, interface 0x10, rev 0x10)
PCI bus 1 slot 1/0: Alliance Semiconductor SP1011 HyperTransport-PCI Bridge (PCI bridge)
PCI bus 2 slot 1/0: Intel product 0x1079 (ethernet network, rev 0x03)
PCI bus 2 slot 1/1: Intel product 0x1079 (ethernet network, rev 0x03)</pre>
<h4>5.4 Help</h4>
<pre class="brush:bash">CFE&gt; help
Available commands:

copydisk            Copy a remote disk image to a local disk device via TFTP
phy set             Set the value of a PHY register
phy dump            Dump the registers on the PHY
randmemtest         Tests memory using random access pattern
memorytest          Tests all available memory
test ether          Do an ethernet test, reading packets from the net
test fatfs          Do a FAT file system test
test disk           Do a disk test, read/write sectors on the disk
test timer          Test the timer
defeature           Set the state of the defeature mask
map pci             Define a BAR0 window available to PCI devices
cpu1                Controls a test program running on CPU1
set date            Set current date
set time            Set current time
set console         Change the active console device
sleep               Wait for some period of time
loop                Loop a command
memtest             Test memory.
pci dump            Dump PCI configuration space.
reserve             Mark a region of memory as reserved
autoboot            Automatic system bootstrap.
batch               Load a batch file into memory and execute it
save                Save a region of memory to a remote file via TFTP
ttcp                TCP test command.
tcp constest        tcp console test.
tcp listen          port listener.
tcp connect         TCP connection test.
rlogin              mini rlogin client.
ping                Ping a remote IP host.
arp                 Display or modify the ARP Table.
show boot           Display boot block from device,
show spd            Display contents of memory SPD
show temp           Display CPU temperature
show time           Display current time according to RTC
show agents         Display list of SOC agents
show soc            Display SOC register contents
show defeature      Show the state of the defeature mask
show pci            Display information about PCI buses and devices
show heap           Display information about CFE's heap
show memory         Display the system physical memory map.
unsetenv            Delete an environment variable.
......
......

For more information about a command, enter 'help command-name'</pre>
<pre class="brush:bash">CFE&gt; help show pci

  SUMMARY

     Display information about PCI buses and devices

  USAGE

     show pci [-v] [[port:]bus/dev/func]

     Displays information about PCI and LDT buses and devices in the
     system.  If you specify a bus/dev/func triplet, only that device
      will be displayed.

  OPTIONS

     -v           Display verbose information
     -init        Reinitialize and rescan the PCI bus</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.jackslab.org/?feed=rss2&#038;p=280</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>YAMON Quick Start</title>
		<link>http://www.jackslab.org/?p=274</link>
		<comments>http://www.jackslab.org/?p=274#comments</comments>
		<pubDate>Wed, 23 Feb 2011 06:02:36 +0000</pubDate>
		<dc:creator>Jack Tan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[基础设施]]></category>
		<category><![CDATA[bootloader]]></category>
		<category><![CDATA[quickstart]]></category>
		<category><![CDATA[yamon]]></category>

		<guid isPermaLink="false">http://www.jackslab.org/?p=274</guid>
		<description><![CDATA[1. YAMON Boot Log YAMON ROM Monitor, Revision 02.13. Copyright (c) 1999-2006 MIPS Technologies, Inc. - All ...]]></description>
			<content:encoded><![CDATA[<h3>1. YAMON Boot Log</h3>
<pre class="brush:bash">YAMON ROM Monitor, Revision 02.13.
Copyright (c) 1999-2006 MIPS Technologies, Inc. - All Rights Reserved.

For a list of available commands, type 'help'.

Compilation time =              Dec  7 2006  19:01:12
Board type/revision =           0x02 (Malta) / 0x00
Core board type/revision =      0x04 (CoreFPGA) / 0x00
System controller/revision =    Galileo / GT_64120A-B-2
FPGA revision =                 0x0001
MAC address =                   00.d0.a0.00.05.b6
Board S/N =                     0000001194
PCI bus frequency =             33.33 MHz
Processor Company ID/options =  0x01 (MIPS Technologies, Inc.) / 0x00
Processor ID/revision =         0x81 (MIPS 5Kf) / 0x0c
Endianness =                    Big
CPU/Bus frequency =             10000 kHz / 40 MHz
Flash memory size =             4 MByte
SDRAM size =                    64 MByte
First free SDRAM address =      0x800b7160

YAMON&gt;</pre>
<p><span id="more-274"></span></p>
<h3>2. Config to bootstrap</h3>
<h4>2.0 Display enviroment variables</h4>
<p>Using &#8216;setenv&#8217; without any other arguments to display all enviroment variables:</p>
<pre class="brush:bash">YAMON&gt; setenv
baseboardserial (RO)   0000001194
bootfile        (R/W)
bootprot        (R/W)  tftp
bootserport     (R/W)  tty0
bootserver      (R/W)  0.0.0.0
cpuconfig       (R/W)
ethaddr         (RO)   00.d0.a0.00.05.b6
fpu             (R/W)
gateway         (R/W)  0.0.0.0
ipaddr          (R/W)  0.0.0.0
memsize         (RO)   0x04000000
modetty0        (R/W)  38400,n,8,1,hw
modetty1        (R/W)  38400,n,8,1,hw
prompt          (R/W)  YAMON
start           (R/W)
startdelay      (R/W)
subnetmask      (R/W)  0.0.0.0
yamonrev        (RO)   02.13</pre>
<h4>2.1 Set ethernet variables</h4>
<p>YAMON does not supply explicit ethernet configure commands. You need to set following environment variables (YAMON predefine) for supporting ethernet:</p>
<pre class="brush:bash">ipaddr
subnetmask
gateway</pre>
<p>Using &#8216;setenv&#8217; to set these variable:</p>
<pre class="brush:bash">YAMON&gt; setenv ipaddr 128.224.165.68
YAMON&gt; setenv subnetmask 255.255.255.0
YAMON&gt; setenv gateway  128.224.165.1</pre>
<p>&#8216;setenv&#8217; store the environment variable permanently in the NVRAM.</p>
<p>After seting the ethernet, you can use the &#8216;ping&#8217; command to test the network:</p>
<pre class="brush:bash">YAMON&gt; ping 192.168.29.11</pre>
<p>If the setting is OK, it&#8217;ll output like following:</p>
<pre class="brush:bash">. 64 bytes ICMP-ECHO-REPLY user data received from 192.168.29.11</pre>
<p>Otherwise:</p>
<pre class="brush:bash">Error : Gateway IP-address is not set
Diag  : Gateway IP-address: 0.0.0.0
Hint  : Check environment variable 'gateway'</pre>
<h4>2.2 Load &amp; execute</h4>
<p>YAMON supply &#8216;load&#8217; command to load image from serial port or Ethernet to RAM. The only image type currently supported is SREC:</p>
<pre class="brush:bash">YAMON&gt; load tftp://128.224.165.20/vlm-boards/15440/vmlinux.srec
YAMON&gt; load asc://tty0</pre>
<p>&#8216;load&#8217; command does not support loading file to a user specified address.</p>
<p>You can use following YAMON predefined variable to specify the default value:</p>
<pre class="brush:bash">bootprot                        -------&gt; specify the default boot protocol used by 'load' command (tftp/asc)
bootserver                      -------&gt; specify the default TFTP server ip
bootfile                        -------&gt; specify the default TFTP file
bootserport                     -------&gt; specify the default serial port used by 'load' command</pre>
<p>So after executing following commands:</p>
<pre class="brush:bash">YAMON&gt; setenv bootprot tftp
YAMON&gt; setenv bootserver 128.224.165.20
YAMON&gt; setenv bootfile vlm-boards/15440/vmlinux.srec</pre>
<p>We only need type &#8216;load&#8217; without following long strings:</p>
<pre class="brush:bash">YAMON&gt; load
About to load tftp://128.224.165.20/vlm-boards/15440/vmlinux.srec
Press Ctrl-C to break
........................................
........................................
........................................
........................................
.................
Start = 0x80410b90, range = (0x80100000,0x80533085), format = SREC</pre>
<p>After loading kernel, we need to use &#8216;go&#8217; command to start kernel at target address:</p>
<pre class="brush:bash">YAMON&gt; go . root=/dev/nfs rw nfsroot=192.168.1.1:/export/rootfs ip=192.168.1.2 console=ttyS0,38400</pre>
<p>&#8216;.&#8217; reference to the default execution address which is from the last sucessful &#8216;load&#8217; or &#8216;go&#8217; command (if any). This default address can be showed by:</p>
<pre class="brush:bash">YAMON&gt; go ? Address = 0x80410b90</pre>
<p>Following command equal to the previous command:</p>
<pre class="brush:bash">YAMON&gt; go 0x80410b90 root=/dev/nfs rw nfsroot=192.168.1.1:/export/rootfs ip=192.168.1.2 console=ttyS0,38400</pre>
<h4>2.3 Automatic bootstrap</h4>
<p>YAMON use predefined variable &#8216;start&#8217; as the automatic bootstrap command, YAMON will give the user the option to press Ctrl-C within 2 seconds to cancel execution of the start command.</p>
<p>We can set &#8216;startdelay&#8217; variable to specify the delay seconds. But if set &#8216;startdelay&#8217; to 0, the start command will not be executed.</p>
<pre class="brush:bash">YAMON&gt; setenv start "load; go . root=/dev/nfs rw nfsroot=192.168.1.1:/export/rootfs ip=192.168.1.2 console=ttyS0,38400"
YAMON&gt; setenv startdelay 1</pre>
<p>If you predefine some variables like following:</p>
<pre class="brush:bash">YAMON&gt; setenv nfsboot "root=/dev/nfs rw nfsroot=192.168.1.1:/export/rootfs"
YAMON&gt; setenv addtty "console=ttyS0,38400"
YAMON&gt; setenv ip "ip=192.168.1.2"</pre>
<p>You can define the &#8216;start&#8217; like this:</p>
<pre class="brush:bash">YAMON&gt; setenv start "load; go . ${nfsboot} ${addtty} ${ip}"</pre>
<h3>3. Memory commands</h3>
<h4>3.1 Disassemble instructions</h4>
<p>Disassemble 5 instuctions at 0xbfc00100:</p>
<pre class="brush:bash">YAMON&gt; dis 0xbfc00100 5
BFC00100:  3C1ABFC0  lui         k0,0xbfc0
BFC00104:  8F5A0010  lw          k0,16(k0)
BFC00108:  001AD682  srl         k0,k0,0x1a
BFC0010C:  335A003F  andi        k0,k0,0x3f
BFC00110:  3B5A0001  xori        k0,k0,0x1</pre>
<h4>3.2 Dump memory</h4>
<p>USAGE:</p>
<pre class="brush:bash">dump [-m][-8|-16|-32] address [size]</pre>
<pre class="brush:bash">YAMON&gt; dump -8 0xa0000000 0x40
A0000000: 08 00 ED E7 24 1A 00 00 00 00 00 02 00 00 00 03  ....$...........
A0000010: 00 00 00 04 00 00 00 05 00 00 00 06 00 00 00 07  ................
A0000020: 00 00 00 08 00 00 00 09 00 00 00 0A 00 00 00 0B  ................
A0000030: 00 00 00 0C 00 00 00 0D 00 00 00 0E 00 00 00 0F  ................

YAMON&gt; dump -32 0xa0000000 0x50
A0000000: 0800EDE7 241A0000 00000002 00000003  ....$...........
A0000010: 00000004 00000005 00000006 00000007  ................
A0000020: 00000008 00000009 0000000A 0000000B  ................
A0000030: 0000000C 0000000D 0000000E 0000000F  ................
A0000040: 00000010 00000011 00000012 00000013  ................</pre>
<h4>3.3 Modify memory</h4>
<p>Usage:</p>
<pre class="brush:bash">edit [-8|-16|-32] address</pre>
<p>&#8216;-&#8217; cause the address  to be decremented a unit (8/16/32 bit).</p>
<pre class="brush:bash">YAMON&gt; edit -32 0x81000000
0x81000000:  (00000000)  55aa55aa
0x81000004:  (00000400)  55aa55aa
0x81000008:  (00000001)  55aa55aa
0x8100000C:  (FFFFFFDF)  -
0x81000008:  (55AA55AA)  -
0x81000004:  (55AA55AA)
0x81000008:  (55AA55AA)
0x8100000C:  (FFFFFFDF)  .</pre>
<p>Typing  &#8216;.&#8217; or Ctro-c to exit edit mode.</p>
<h4>3.4 Fill memory</h4>
<p>Usage:</p>
<pre class="brush:bash">fill [-8|-16|-32] address size data</pre>
<pre class="brush:bash">YAMON&gt; fill -16 0x82000000 0x20 0x55aa
Filling from 0x82000000 to 0x8200001f with halfword data 0x55AA.

YAMON&gt; dump -16 0x82000000 0x20
82000000: 55AA 55AA 55AA 55AA 55AA 55AA 55AA 55AA  U�U�U�U�U�U�U�U�
82000010: 55AA 55AA 55AA 55AA 55AA 55AA 55AA 55AA  U�U�U�U�U�U�U�U�</pre>
<h3>4. Flash commands</h3>
<h4>4.1 Erase flash</h4>
<p>Usage:</p>
<pre class="brush:bash">erase -e | address size</pre>
<p>WARNING: Using following command, you need to be familiar with the flash start address and its size. Do not erase the YAMON!</p>
<pre class="brush:bash">erase 0xbfc00000 20</pre>
<p>Following command erase environment flash, the system environment variables are reinitialised to factory default values.</p>
<pre class="brush:bash">erase -e</pre>
<h4>4.2 update flash</h4>
<p>You can use &#8216;copy&#8217;, &#8216;disk&#8217; and &#8216;load&#8217; commands to update the flash</p>
<pre class="brush:bash">copy [-f] src_addr dst_addr size
disk [-f] read hda/b/c/d sector count dst_addr</pre>
<p>&#8216;-f&#8217;  Don&#8217;t flush caches</p>
<p>Using &#8216;load&#8217; to downloading S-records may include flash programming if the S-record is bound to a flash memory area. This area must be erased before downloading.</p>
<h3>5. Miscellaneous</h3>
<h4>5.1 Reset system</h4>
<pre class="brush:bash">YAMON&gt; reset</pre>
<h4>5.2 Read/write TLB</h4>
<pre class="brush:bash">YAMON&gt; tlb 

Index Page  VA         G ASID PA0        C0 D0 V0 PA1        C1 D1 V1
---------------------------------------------------------------------
0x0   4kB   0x00000000 n 0x00 0x00000000 0  n  n  0x00000000 0  n  n
0x1   4kB   0x00000000 n 0x00 0x00000000 0  n  n  0x00000000 0  n  n
0x2   4kB   0x00000000 n 0x00 0x00000000 0  n  n  0x00000000 0  n  n
0x3   4kB   0x00000000 n 0x00 0x00000000 0  n  n  0x00000000 0  n  n
0x4   4kB   0x00000000 n 0x00 0x00000000 0  n  n  0x00000000 0  n  n
......</pre>
<p>You can use following command to edit the TLB:</p>
<pre class="brush:bash">
YAMON&gt; tlb 2 4kB 0 y ff 200000 3 y y 300000 3 n y

YAMON&gt; tlb
Index Page  VA         G ASID PA0        C0 D0 V0 PA1        C1 D1 V1
 ---------------------------------------------------------------------
0x0   4kB   0x00000000 n 0x00 0x00000000 0  n  n  0x00000000 0  n  n
0x1   4kB   0x00000000 n 0x00 0x00000000 0  n  n  0x00000000 0  n  n
0x2   4kB   0x00000000 y 0xff 0x00200000 3  y  y  0x00300000 3  n  y
0x3   4kB   0x00000000 n 0x00 0x00000000 0  n  n  0x00000000 0  n  n
0x4   4kB   0x00000000 n 0x00 0x00000000 0  n  n  0x00000000 0  n  n
......</pre>
<h4>5.3 Read/Write CP0</h4>
<p>You can use &#8216;cp0&#8242; to read and write CP0 register:</p>
<pre class="brush:bash">YAMON&gt; cp0
BadVAddr      = 0x0000000000000000  CacheErr      = 0x00000000
Cause         = 0x00808000          Compare       = 0x00000000
Config        = 0xb601c083          Config1       = 0x5ea3519b
Context       = 0x0000000000000000  Count         = 0x33319249
DEPC          = 0x0000000000000000  DESAVE        = 0x0000000000000000
DataHi        = 0x00000000          DataLo        = 0x00000000
Debug         = 0x02010000          EPC           = 0xffffffff80028dac
EntryHi       = 0x0000000000000000  EntryLo0      = 0x0000000000000000
EntryLo1      = 0x0000000000000000  ErrCtl        = 0x00000000
ErrorEPC      = 0x0000000000000000  Index         = 0x00000013
PRId          = 0x0001810c          PageMask      = 0x00000000
PerfCntCount0 = 0x00000000          PerfCntCount1 = 0x00000000
PerfCntCtrl0  = 0x80000000          PerfCntCtrl1  = 0x00000000
Random        = 0x0000002f          Status        = 0x24002c01
TagHi         = 0x00000000          TagLo         = 0x00000000
WatchHi       = 0x0000000080000000  WatchLo       = 0x0000000000000000
Wired         = 0x00000000          XContext      = 0x0000000000000000</pre>
<pre class="brush:bash">YAMON&gt; cp0 WatchLo
WatchLo = 0x0000000000000000
YAMON&gt; cp0 WatchLo 0x55aa
YAMON&gt; cp0 WatchLo
WatchLo = 0x00000000000055aa</pre>
<h4>5.4 Help</h4>
<pre class="brush:bash">YAMON&gt; help cp1

MON&gt; help cp1

NAME
    cp1

SYNOPSIS
    cp1 [ ( | ) [] ]

DESCRIPTION
    Read/write CP1 control register(s).

    If no arguments are applied, all CP1 control registers are read.
    A register may be selected by name or number.
    If a value is given, this value is written to the register, otherwise
    the register is read.
    Writing a CP1 control register takes effect immediately.

    Settings of CP1 control registers are also applied to user applications
    (started with 'go' or 'gdb').

OPTIONS</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.jackslab.org/?feed=rss2&#038;p=274</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>U-Boot Quick Start</title>
		<link>http://www.jackslab.org/?p=260</link>
		<comments>http://www.jackslab.org/?p=260#comments</comments>
		<pubDate>Wed, 23 Feb 2011 03:15:51 +0000</pubDate>
		<dc:creator>Jack Tan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[基础设施]]></category>
		<category><![CDATA[bootloader]]></category>
		<category><![CDATA[quickstart]]></category>
		<category><![CDATA[uboot]]></category>

		<guid isPermaLink="false">http://www.jackslab.org/?p=260</guid>
		<description><![CDATA[1. U-Boot Boot Log U-Boot 1.2.0-emma-8 (Sep 21 2007 - 11:24:10) Board: EMMA3P et10068 (CPU Speed 328 ...]]></description>
			<content:encoded><![CDATA[<h3>1. U-Boot Boot Log</h3>
<pre class="brush:bash">U-Boot 1.2.0-emma-8 (Sep 21 2007 - 11:24:10)

Board: EMMA3P et10068 (CPU Speed 328 MHz, DRMA Size 768 MB)
BHIF version = 0x0000f010 (EMMA3P 1.0)
Realtek Ethernet MAC support = enable
DRAM:  160 MB
Flash: 32 MB
In:    serial
Out:   serial
Err:   serial
Net:   RTL8139#0, NEC-Candy
Hit any key to stop autoboot:  0</pre>
<p><span id="more-260"></span></p>
<h3>2. Config to bootstrap</h3>
<h4>2.0 Display enviroment variables</h4>
<p>Using &#8216;printenv&#8217; to display enviroment variables:</p>
<pre class="brush:bash">U-Boot&gt; printenv
baudrate=115200
ethaddr=12:34:56:78:9a:bb
eth1addr=12:34:56:78:9a:bc
eeprom=off
bootdelay=5
ethact=RTL8139#0
bootfile=/vlm-boards/14726/kernel
hostname=nec_emmap3p-1
autoload=yes
autostart=no
bootcmd=tftp 0x80600000 vlm-boards/14726/test;bootm
filesize=2640c5
fileaddr=80600000
gatewayip=192.168.29.1
netmask=255.255.255.0
ipaddr=192.168.29.243
serverip=192.168.29.11
bootargs=console=ttyS0,115200 root=/dev/nfs rw nfsroot=192.168.29.11:/export/pxeboot/vlm-boards/14726/rootfs ip=dhcp
stdin=serial
stdout=serial
stderr=serial</pre>
<p>Using following command to only display ipaddr:</p>
<pre class="brush:bash">U-Boot&gt; pri ipaddr
ipaddr=192.168.29.243</pre>
<h4>2.1 Set ethernet variables</h4>
<p>U-Boot does not supply explicit ethernet configure commands. You need to set following environment variables (U-Boot predefine) for supporting ethernet:</p>
<pre class="brush:bash">ipaddr
netmask
gatewayip</pre>
<p>Using &#8216;setenv&#8217; to set these variables:</p>
<pre class="brush:bash">U-Boot&gt; setenv ipaddr 192.168.29.243 U-Boot&gt; setenv netmask 255.255.255.0 U-Boot&gt; setenv gatewayip  192.168.29.1</pre>
<p><strong>NOTE:</strong> In U-Boot, &#8216;setenv&#8217; dose not store the environment variable permanently in the NVRAM. If you want to make setting permanent you need to execute &#8216;saveenv&#8217;:</p>
<pre class="brush:bash">U-Boot&gt; saveenv
Saving Environment to Flash...
. done
Un-Protected 1 sectors
Erasing Flash...
. done
Erased 1 sectors
Writing to Flash... done
. done
Protected 1 sectors</pre>
<p>After seting the ethernet, you can use the &#8216;ping&#8217; command to test the network:</p>
<pre class="brush:bash">U-Boot&gt; ping 192.168.29.11</pre>
<p>If the setting is OK, it&#8217;ll output like following:</p>
<pre class="brush:bash">Using RTL8139#0 device host 192.168.29.11 is alive</pre>
<h4>2.2 Load &amp; execute</h4>
<p>U-Boot supply &#8216;tftpboot&#8217; command to load image from Ethernet into RAM.</p>
<p>&#8216;tftpboot&#8217; use &#8216;serverip&#8217; environment varible as its default tftp server, so you need to set the &#8216;serverip&#8217; varible before you use &#8216;tftpboot&#8217;:</p>
<pre class="brush:bash">U-Boot&gt; setenv serverip 192.168.29.11
U-Boot&gt; tftpboot 0x80400000 vlm-boards/14726/uImage
Using RTL8139#0 device
TFTP from server 192.168.29.11; our IP address is 192.168.29.243
Filename 'vlm-boards/14726/uImage'.
<strong>Load address: 0x80400000</strong>
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         ######
done
Bytes transferred = 5017797 (4c90c5 hex)</pre>
<p>You can use following U-Boot predefined variable to specify the default value:</p>
<pre class="brush:bash">serverip                       -------&gt; specify the default TFTP server ip
bootfile                       -------&gt; specify the default TFTP file</pre>
<p>So after executing following commands:</p>
<pre class="brush:bash">U-Boot&gt; setenv bootfile vlm-boards/15440/uImage</pre>
<p>We only need type &#8216;tftpboot&#8217; without long strings:</p>
<pre class="brush:bash">U-Boot&gt; tftp
Using RTL8139#0 device
TFTP from server 192.168.29.11; our IP address is 192.168.29.243
Filename 'vlm-boards/14726/uImage'.
Load address: 0x80400000
Loading: #################################################################
         #################################################################
         #################################################################
         ######################################################
done
Bytes transferred = 4600006 (4630c6 hex)</pre>
<p>You can also use the &#8216;nfs&#8217; to load the kernel from nfs server:</p>
<pre class="brush:bash">U-Boot&gt; nfs 0x80400000 192.168.29.11:/export/pxeboot/vlm-boards/14726/uImage
Using RTL8139#0 device
File transfer via NFS from server 192.168.29.11; our IP address is 192.168.29.243
Filename '/export/pxeboot/vlm-boards/14726/uImage'.
Load address: 0x80400000
Loading: #################################################################
	 #################################################################
	 #################################################################
	 #################################################################
	 #################################################################
	 ######################################################
done
Bytes transferred = 4600006 (4630c6 hex)</pre>
<p>If you set the &#8216;serverip&#8217; you only need to type:</p>
<pre class="brush:bash">U-Boot&gt; nfs 0x80400000 /export/pxeboot/vlm-boards/14726/uImage</pre>
<p>If you have dhcp server, you can simply type &#8216;dhcp&#8217; to get the ipaddr, netmask, gatewayip, serverip, bootfile and can load the boot file automatically.</p>
<p>If you want to load the file via serial you can use &#8216;loadb&#8217;/'loads&#8217;:</p>
<pre class="brush:bash">U-Boot&gt; loadb 0x400000 115200                       ----------&gt; load binary file over serial line with baudrate 115200 and place the file at 0x400000
U-Boot&gt; loads 0x400000 115200                       ----------&gt; load S-Record file over serial line with baudrate 115200 and convert the S-Record to binary</pre>
<p><strong>Execute:</strong></p>
<p>After loading image, we need to parse the image header and jump to the entry address.</p>
<p>In U-Boot we use &#8216;bootm&#8217; to parse the uboot image header and jump to the entry address:</p>
<pre class="brush:bash">U-Boot&gt; bootm 0x80400000 console=ttyS0,115200 root=/dev/nfs nfsroot=192.168.29.11:/export/rootfs ip=dhcp
## Booting image at 80400000 ...
    Image Name:   Linux-2.6.21.7-hrt1-WR2.0bl_stan
    Created:      2008-04-08   8:49:42 UTC
    Image Type:   MIPS Linux Kernel Image (uncompressed)
    Data Size:    4599942 Bytes =  4.4 MB
    Load Address: 80040000
    *Entry Point:  80478000*
    Verifying Checksum ... OK
OK

Starting kernel ...

Linux version 2.6.21.7-hrt1-WR2.0bl_standard (gcc version 4.1.2) #2 PREEMPT Tue Apr 8 01:49:27 PDT 2008
CPU revision is: 00005610
FPU revision is: 00035610
Determined physical RAM map:
 memory: 0a000000 @ 00000000 (usable)
 memory: 10000000 @ 20000000 (usable)
Initrd not found or empty - disabling initrd
......</pre>
<p>&#8216;bootm&#8217; use the &#8216;bootargs&#8217; enviroment variable as the default argument passed to the kernel and use &#8216;fileaddr&#8217; varible as the default image file start address. So:</p>
<pre class="brush:bash">U-Boot&gt; setenv bootargs console=ttyS0,115200 root=/dev/nfs nfsroot=192.168.29.11:/export/rootfs ip=dhcp
U-Boot&gt; bootm</pre>
<p>&#8216;fileaddr&#8217; is automatically set by any load command.</p>
<p>If you know the entry address, you can use the &#8216;go&#8217;:</p>
<pre class="brush:bash">U-Boot&gt; go 0x80848000 root=/dev/nfs rw nfsroot=192.168.29.11:/export/rootfs ip=dhcp
</pre>
<p>&#8216;go&#8217; don&#8217;t parse the image header.</p>
<p><span style="color: #008000;"><strong>NOTE:</strong></span> If you set the variable &#8216;autostart&#8217; to yes, tftpboot/nfs will be internally calling the bootm command</p>
<h4>2.3 Automatic bootstrap</h4>
<p>U-Boot use predefined variable &#8216;bootcmd&#8217; as the automatic bootstrap command, U-Boot will give the user the option to press Ctrl-C within 10 seconds to cancel execution of the start command.</p>
<p>We can set &#8216;bootdelay&#8217; variable to specify the delay seconds. But if set &#8216;bootdelay&#8217; to -1, the start command will not be executed.</p>
<pre class="brush:bash">U-Boot&gt; setenv bootcmd tftp 0x80400000\; bootm 0x80400000 root=/dev/nfs rw nfsroot=192.168.29.11:/export/rootfs ip=dhcp console=ttyS0,115200
U-Boot&gt; setenv bootdelay 4
U-Boot&gt; reset
</pre>
<p>If you predefine some variables like following:</p>
<pre class="brush:bash">U-Boot&gt; setenv bootargs root=/dev/nfs rw nfsroot=192.168.29.11:/export/rootfs ip=dhcp console=ttyS0,115200 U-Boot&gt; setenv serverip 192.168.29.11 U-Boot&gt; setenv bootfile vlm-boards/14726/uImage U-Boot&gt; setenv bootcmd tftp 0x80400000\; bootm</pre>
<p>You can type &#8216;run bootcmd&#8217; or &#8216;bootd&#8217;:</p>
<pre class="brush:bash">U-Boot&gt; run bootcmd
</pre>
<h3>3. Memory commands</h3>
<h4>3.1 Dump memory</h4>
<pre class="brush:bash">U-Boot&gt; md.b 0x80400000 0x40
80400000: 27 05 19 56 4a e2 a0 89 47 fb 31 a6 00 46 30 86    '..VJ...G.1..F0.
80400010: 80 04 00 00 80 47 80 00 ea b4 24 c7 05 05 02 00    .....G....$.....
80400020: 4c 69 6e 75 78 2d 32 2e 36 2e 32 31 2e 37 2d 68    Linux-2.6.21.7-h
80400030: 72 74 31 2d 57 52 32 2e 30 62 6c 5f 73 74 61 6e    rt1-WR2.0bl_stan

U-Boot&gt; md.w 0x80400000 0x20
80400000: 2705 1956 4ae2 a089 47fb 31a6 0046 3086    '..VJ...G.1..F0.
80400010: 8004 0000 8047 8000 eab4 24c7 0505 0200    .....G....$.....
80400020: 4c69 6e75 782d 322e 362e 3231 2e37 2d68    Linux-2.6.21.7-h
80400030: 7274 312d 5752 322e 3062 6c5f 7374 616e    rt1-WR2.0bl_stan

U-Boot&gt; md.l 0x80400000 0x10
80400000: 27051956 4ae2a089 47fb31a6 00463086    '..VJ...G.1..F0.
80400010: 80040000 80478000 eab424c7 05050200    .....G....$.....
80400020: 4c696e75 782d322e 362e3231 2e372d68    Linux-2.6.21.7-h
80400030: 7274312d 5752322e 30626c5f 7374616e    rt1-WR2.0bl_stan
</pre>
<h4>3.2 Memory Copy</h4>
<pre class="brush:bash">cp [.b, .w, .l] source target count
</pre>
<pre class="brush:bash">U-Boot&gt; cp.b 0x80400000 0xbe000000 0x100000
</pre>
<p>Assume the 0xbe000000 is the flash address.</p>
<h4>3.3 Modify memory</h4>
<pre class="brush:bash">U-Boot&gt; mm.w 0x80000000
80000000: 0000 ? 55aa
80000002: 0000 ? 66bb
80000004: 0000 ? 77cc
80000006: 0000 ? 88dd
80000008: 0000 ? .
</pre>
<p>Type &#8216;.&#8217; to exit, &#8216;-&#8217; to back up</p>
<pre class="brush:bash">U-Boot&gt; md.w 0x80000000
80000000: 55aa 66bb 77cc 88dd 0000 0000 0000 0000    U.f.w...........
80000010: 0000 0000 0000 0000 0000 0000 0000 0000    ................
</pre>
<h4>3.4 Memory Fill</h4>
<pre class="brush:bash">U-Boot&gt; md.w 0x80000000 10
80000000: 5678 5678 5678 5678 5678 5678 5678 5678    VxVxVxVxVxVxVxVx
80000010: 5678 5678 5678 5678 5678 5678 5678 5678    VxVxVxVxVxVxVxVx
U-Boot&gt; mw.w 0x80000000 55aa 10
U-Boot&gt; md.w 0x80000000 10
80000000: 55aa 55aa 55aa 55aa 55aa 55aa 55aa 55aa    U.U.U.U.U.U.U.U.
80000010: 55aa 55aa 55aa 55aa 55aa 55aa 55aa 55aa    U.U.U.U.U.U.U.U.
</pre>
<h4>3.5 Memory Compare</h4>
<pre class="brush:bash">cmp [.b, .w, .l] addr1 addr2 count
</pre>
<h3>4. Flash commands</h3>
<h4>4.1 show flash infomation</h4>
<pre class="brush:bash">U-Boot&gt; flinfo

Bank # 1: CFI conformant FLASH (16 x 16)  Size: 32 MB in 256 Sectors
  AMD Standard command set, Manufacturer ID: 0x01, Device ID: 0x7E2201
  Erase timeout: 4096 ms, write timeout: 1 ms
  Buffer write timeout: 3 ms, buffer size: 64 bytes

  Sector Start Addresses:
  BE000000    BE020000    BE040000    BE060000    BE080000
  BE0A0000    BE0C0000    BE0E0000    BE100000    BE120000
  ........................
  ........................
  BFE00000   RO   BFE20000    BFE40000    BFE60000 E    BFE80000 E
  BFEA0000 E    BFEC0000 E    BFEE0000 E    BFF00000 E    BFF20000 E
  BFF40000 E    BFF60000 E    BFF80000 E    BFFA0000 E    BFFC0000 E
  BFFE0000 E
</pre>
<p>There is only one Bank (# 1) on current board. Sector size is 0&#215;20000.</p>
<h4>4.2 erase flash</h4>
<p><span style="color: #ff0000;"><strong>NOTE:</strong></span> <span style="color: #008000;">Before you erase the flash, you must to know the U-Boot code residing area (start address and size) and avoid to erase this area in case of you are not going to update the U-Boot.</span></p>
<pre class="brush:bash">U-Boot&gt; erase BE000000 BE07FFFF

... done
Erased 4 sectors
</pre>
<p>Or:</p>
<pre class="brush:bash">U-Boot&gt; era 0xBE000000 +0x80000
</pre>
<p>Another way to select certain areas of the flash memory is using <strong>banks</strong> and <strong>sectors</strong>. Following commands has the same function:</p>
<pre class="brush:bash">U-Boot&gt; era 1:1-4
Erase Flash Sectors 1 - 4 in Bank # 1
..done
</pre>
<p>A bank is an area of memory implemented by one or more memory chips that are connected to the same chip select signal.</p>
<p>A sector or erase unit is the smallest area that can be erased in one operation.</p>
<h4>4.3 Protect flash</h4>
<p>Use &#8216;protect&#8217; command to enable or disable FLASH write protection:</p>
<pre class="brush:bash">U-Boot&gt; protect off 0xBE000000 +0x80000          # or protect off 1:1-4

U-Boot&gt; erase 1:1-4

U-Boot&gt; protect on 0xBE000000 0xBE07FFFF
</pre>
<h4>4.3 Update flash</h4>
<pre class="brush:bash">U-Boot&gt; tftp 0x81000000 vlm-boards/14726/rootfs-jffs2                      # load rootfs (jffs2 format) image to memory

U-Boot&gt; protect off 0xBE000000 +0x1500000
U-Boot&gt; erase 0xBE000000 +0x1500000

U-Boot&gt; cp.b 0x81000000 0xBE000000 ${filesize}                             # write image to flash

U-Boot&gt; protect on 1:6-255
</pre>
<h3>5. Miscellaneous</h3>
<h4>5.1 Reset system</h4>
<pre class="brush:bash">U-Boot&gt; reset
</pre>
<h4>5.2 Show PCI</h4>
<pre class="brush:bash">U-Boot&gt; pci
Scanning PCI devices on bus 0
BusDevFun  VendorId   DeviceId   Device Class       Sub-Class
_____________________________________________________________
00.0e.00   0x1033     0x0035     Serial bus controller   0x03
00.0f.00   0x10ec     0x8139     Network controller      0x00
00.14.00   0x1033     0x0177     Multimedia device       0x80
</pre>
<h4>5.3 Help</h4>
<pre class="brush:bash">U-Boot&gt; help pci
pci [bus] [long]
    - short or long list of PCI devices on bus 'bus'
pci header b.d.f
    - show header of PCI device 'bus.device.function'
pci display[.b, .w, .l] b.d.f [address] [# of objects]
    - display PCI configuration space (CFG)
pci next[.b, .w, .l] b.d.f address
    - modify, read and keep CFG address
pci modify[.b, .w, .l] b.d.f address
    -  modify, auto increment CFG address
pci write[.b, .w, .l] b.d.f address value
    - write to CFG address
</pre>
<h3>6. Reference</h3>
<p><a href="http://www.denx.de/wiki/view/DULG/UBoot" target="_top">U-Boot user manual</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jackslab.org/?feed=rss2&#038;p=260</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerPC 体系结构之存储管理</title>
		<link>http://www.jackslab.org/?p=239</link>
		<comments>http://www.jackslab.org/?p=239#comments</comments>
		<pubDate>Tue, 22 Feb 2011 03:32:44 +0000</pubDate>
		<dc:creator>Jack Tan</dc:creator>
				<category><![CDATA[PowerPC]]></category>
		<category><![CDATA[体系结构]]></category>
		<category><![CDATA[基础设施]]></category>
		<category><![CDATA[ISA]]></category>
		<category><![CDATA[TLB]]></category>
		<category><![CDATA[存储管理]]></category>

		<guid isPermaLink="false">http://www.jackslab.org/?p=239</guid>
		<description><![CDATA[取 BOOKE 精要，兼顾 E500 规范。 E500 规范是 BOOKE 的 32-bit 实现，更详细些，大部与 BOOKE 兼容。 BOOKE 对存储管理的规范较抽象，没有非常多的细节（比如 TLB 每项的结构必须如此等等），涉及细节则多以 ...]]></description>
			<content:encoded><![CDATA[<p>取 BOOKE 精要，兼顾 E500 规范。 E500 规范是 BOOKE 的 32-bit 实现，更详细些，大部与 BOOKE 兼容。</p>
<p>BOOKE 对存储管理的规范较抽象，没有非常多的细节（比如 TLB 每项的结构必须如此等等），涉及细节则多以 E500 为例子。<br />
<strong><br />
<span style="color: #ff9900;"> 1. 概述</span></strong></p>
<p>E500 实现有两级 TLB，即：L1 TLB 和 L2 TLB。L1 TLB 可以理解为 L2 TLB 的部分缓存。访问 L1 TLB 的效率要比 L2 的效率高，相应的实现的花费也就高。L1 TLB 由硬件维护，不可编程精确控制。故下面的讨论皆针对 L2 TLB，为方便简称其为 TLB。</p>
<p>E500 没有对虚拟地址空间进行划分，即没有固定使用某段虚拟地址固定映射到某段物理地址 (MIPS，主要用于支持设备资源的固定映射以及方便内核对内存的管理)。而是引入了一个更灵活的设计：将 TLB 分为 TLB0 和 TLB1。</p>
<p>TLB0 即用于页映射的 TLB，可动态被替换，页大小固定为 4 KB。E500v1 实现为 2 路组相联，256 项；E500v2 实现为 4 路组相联，512 项。</p>
<p>TLB1 则设计用于映射大页（比如 16MB, 256MB &#8230;），支持可变页大小，E500v1 可支持 9 个页大小（最大 256MB），E500v2 则支持 11 个页大小（最大 4GB）。使用时可将某项设为永驻 TLB1 （通过置 Invalidation Protection 位，简写为 IPROT 位），不会被动态替换，实现为全相联，共 16 项，可将其理解为用于映射 16 个段的可编程固定映射机制。</p>
<p><span id="more-239"></span></p>
<p><span style="color: #3d85c6;"><strong>2. TLB 结构与工作方式</strong></span></p>
<p><strong>2.1 TLB 结构</strong></p>
<p>E500 之 TLB0 与 TLB1 每项的数据格式相似，皆由页区分域、翻译域、访问控制域和存储属性位组成。</p>
<p><strong>2.1.1  页区分域 </strong></p>
<p>页区分域 (Page Identificaion Fields) 即为查找 TLB 时的比对域。包括 EPN (Effective Page Number)，TS (Translation Address Space, 1 bit)，TID (Translation ID)，V (Valid, 1 bit)，SIZE (Page Size, 4 bits)。其中 EPN 即为虚页号。</p>
<p>PowerPC 习惯上将地址转换时需要比对的位 (IS/DS | PID | EPN) 的组合，叫做一个地址空间。<br />
其中 IS/DS 为 Instruction/Data Address Space，各 1 bit，位于 MSR，0 为地址空间 0，1 则为地址空间 1，转换时其于 TLB_Entry 之 TS 相比较，相等才会输出物理页号；</p>
<p>PID 为 Process ID，本意是用于区分不同进程的虚拟地址空间，存放于 PIDR 中，属上下文。转换时，比较 PIDR 与 TLB_Entry 之 TID 位，相等才会输出物理页号。BOOKE 规定需实现一个 PID 寄存器；E500 作了扩展，其实现有 3 个 PIDR (PID0 ~ 2)，则 E500 在转换时会形成 3 个虚拟地址。</p>
<p>将 TLB_Entry 之 TID 置 0，则硬件会忽略 PID0 ~ 2 与 TID 的比较，PowerPC Linux 设计时，就将 TID 置 0。</p>
<p><strong>2.1.2  翻译域 </strong></p>
<p>翻译域 (Translation Field) 即为经 TLB 翻译后输出的数据，其实即为物理页号，PowerPC 叫 RPN (Real Page Number)<br />
<strong> </strong></p>
<p><strong> </strong> <strong>2.1.3  访问控制域</strong></p>
<p>访问控制域 (Access Control Fields) 又称为 PERMIS，共 6 bits，分别指定该页可否被用户态读、写、可执行 (UR, UW, UX)；管理态（核心态）的读、写、可执行 (SR, SW, SX)</p>
<p><strong>2.1.4  存储属性位</strong></p>
<p>存储属性位 (Storage Attribute Bits) ，其重要的 5 bits 为： W (Write through), I (caching Inhibited), M (Memory coherence), G (Guarded), E (Endianness)，一般简写为 WIMGE；</p>
<p>E500 还实现有可用于系统软件的 X0~1，可用于用户软件的 U0 ~ U3</p>
<p>此外E500 之 TLB1 还有一位无效保护位 IPROT，置位则该项不会被置无效。</p>
<p><strong>2.1.5 完整的 E500 TLB Entry 结构</strong><br />
<a href="http://www.jackslab.org/wp-content/uploads/2011/02/tlb.entry_.structure.png"><img class="aligncenter size-full wp-image-250" title="tlb.entry.structure" src="http://www.jackslab.org/wp-content/uploads/2011/02/tlb.entry_.structure.png" alt="" width="571" height="390" /></a></p>
<p><strong>2.2 TLB 工作方式<br />
</strong></p>
<p><strong><a href="http://www.jackslab.org/wp-content/uploads/2011/02/tlb.org_.e500v1.png"><img class="aligncenter size-full wp-image-252" title="tlb.org.e500v1" src="http://www.jackslab.org/wp-content/uploads/2011/02/tlb.org_.e500v1.png" alt="" width="522" height="450" /></a></strong></p>
<p><strong><a href="http://www.jackslab.org/wp-content/uploads/2011/02/tlb.addr_.translate.png"><img class="aligncenter size-full wp-image-249" title="tlb.addr.translate" src="http://www.jackslab.org/wp-content/uploads/2011/02/tlb.addr_.translate.png" alt="" width="484" height="268" /></a></strong></p>
<p><strong><a href="http://www.jackslab.org/wp-content/uploads/2011/02/tlb.match.process.png"><img class="aligncenter size-full wp-image-251" title="tlb.match.process" src="http://www.jackslab.org/wp-content/uploads/2011/02/tlb.match.process.png" alt="" width="518" height="252" /></a></strong></p>
<p><strong><a href="http://www.jackslab.org/wp-content/uploads/2011/02/access.control.process.png"><img class="aligncenter size-full wp-image-240" title="access.control.process" src="http://www.jackslab.org/wp-content/uploads/2011/02/access.control.process.png" alt="" width="495" height="224" /></a></strong></p>
<p><span style="color: #a64d79;"><strong>3. TLB 控制接口</strong></span></p>
<p><strong> 3.1  相关寄存器</strong></p>
<p><strong>3.1.1</strong> <strong>MAS0 ~ 4, MAS6, MAS7</strong></p>
<p>MMU Assist Registers, 用于与 TLB Entry 之间的数据交换</p>
<p>MAS0，32 bits，用于选择交换对象是 TLB0  还是 TLB1 (TLBSEL)，以及是TLB1 的哪个 Entry  或者 TLB0 的哪一路 (ESEL)：</p>
<p><a href="http://www.jackslab.org/wp-content/uploads/2011/02/mas0.png"><img class="aligncenter size-full wp-image-242" title="mas0" src="http://www.jackslab.org/wp-content/uploads/2011/02/mas0.png" alt="" width="539" height="99" /></a></p>
<p>MAS1，32 bits，用于存放 V, IPROT, TID, TS, TSIZE：</p>
<p><a href="http://www.jackslab.org/wp-content/uploads/2011/02/mas1.png"><img class="aligncenter size-full wp-image-243" title="mas1" src="http://www.jackslab.org/wp-content/uploads/2011/02/mas1.png" alt="" width="529" height="99" /></a></p>
<p>MAS2，32 bits，用于存放 EPN | X0 | X1 | W | I | M | G | E：</p>
<p><a href="http://www.jackslab.org/wp-content/uploads/2011/02/mas2.png"><img class="aligncenter size-full wp-image-244" title="mas2" src="http://www.jackslab.org/wp-content/uploads/2011/02/mas2.png" alt="" width="538" height="101" /></a></p>
<p>MAS3，32 bits，用于存放 RPN | U0 &#8211; U3 | UX | SX | UW | SW | UR |SR：</p>
<p><a href="http://www.jackslab.org/wp-content/uploads/2011/02/mas3.png"><img class="aligncenter size-full wp-image-245" title="mas3" src="http://www.jackslab.org/wp-content/uploads/2011/02/mas3.png" alt="" width="532" height="102" /></a></p>
<p>MAS4，32 bits，用于加上 TLB Miss 的处理，存放默认的 TLBSEL,  TIDSEL,  TSIZE,  X0, X1, WIMGE，当 I/D TLB Miss 出现时，硬件自动将 MAS4 中的值写到 MAS0 ~ 2 的相应域中：</p>
<p><a href="http://www.jackslab.org/wp-content/uploads/2011/02/mas4.png"><img class="aligncenter size-full wp-image-246" title="mas4" src="http://www.jackslab.org/wp-content/uploads/2011/02/mas4.png" alt="" width="536" height="100" /></a></p>
<p>MAS6，32 bits，用于 tlbsx 查找 TLB  时指定 PID0 (SPID0) 和 AS (SAS)</p>
<p><a href="http://www.jackslab.org/wp-content/uploads/2011/02/mas6.png"><img class="aligncenter size-full wp-image-247" title="mas6" src="http://www.jackslab.org/wp-content/uploads/2011/02/mas6.png" alt="" width="540" height="96" /></a></p>
<p>MAS7，32 bits，E500v2 实现，用于支持 36 bits 物理地址，即其 MAS7[60:63] 用作 RPN 的高四位：</p>
<p><a href="http://www.jackslab.org/wp-content/uploads/2011/02/mas7.png"><img class="aligncenter size-full wp-image-248" title="mas7" src="http://www.jackslab.org/wp-content/uploads/2011/02/mas7.png" alt="" width="539" height="99" /></a></p>
<p><strong>3.1.2</strong> <strong>MMUCSR0</strong></p>
<p>MMU Control and Status Register 0，用于控制 TLB 的批量无效。有 2 个有效位：位 61 和位 62，其余保留为 0。</p>
<p>MMUCSR0[61]，置 1 则将 TLB0 的所有项置无效</p>
<p>MMUCSR0[62]，置 1 则将 TLB1 的所有项置无效</p>
<p><strong>3.1.3 MMU 配置状态寄存器</strong></p>
<p>MMUCFG, TLB0CFG, TLB1CFG，皆为只读。</p>
<p>MMUCFG 存放当前实现的 PID Register 的数目，PID Register 中 PID 的有效位（e500 为 8），实现的 TLB 个数（e500 为 2，TLB0 和 TLB1）</p>
<p>TLB0CFG 指示 TLB0 的特性，如：几路组相联 （e500v1 为 2，e500v2 为4），最小页大小和最大页大小（TLB0 皆为 4KB），是否支持 IPROT 位（TLB0 不支持），是否支持可变页大小（TLB0 不支持，则 AVAL = 0），有多少 Entry</p>
<p>TLB1CFG 指示 TLB1 的特性，数据域与  TLB0CFG 同。</p>
<p><strong> 3.2 相关指令</strong></p>
<p>tlbsx RA, RB &#8212; TLB Search Indexed<br />
tlbre &#8212; TLB Read Entry<br />
tlbwe &#8212; TLB Write Entry<br />
tlbivax RA, RB &#8212; TLB Invalidate Virtual Address Indexed<br />
tlbsync &#8212; TLB Sync</p>
<p><strong>3.3 实例</strong></p>
<p><strong>3.3.1 查找 TLB</strong></p>
<p>输入： MAS6，指定 PID0 (SPID0) 和 AS (SAS)<br />
执行 tlbsx RA, RB，在 TLB 中查找有效地址 RA + RB</p>
<p>若命中，则将命中项之数据输出到：MAS0 ~ MAS3，MAS1[V] = 1，MAS0[TLBSEL] 指定命中的是 TLB0 还是 TLB1，MAS0[ESEL] 指定命中项是TLB1 的哪个 Entry  或者 TLB0 的哪一路。</p>
<p>若没找到，则 MAS1[V] = 0，MAS2[RPN] 为 0</p>
<p><strong>3.3.3 写 TLB </strong></p>
<p>输入：MAS0 ~ 3 (MAS7 for E500v2)<br />
执行  tlbwe</p>
<p>其据 MAS0[TLBSEL]  和  MAS0[ESEL]  选择将被写的 TLB 入口（若为 TLB0，还需借助 EPN[45:51] 用于索引组，ESEL 用于路选），然后将 MAS0 ~ 3 (MAS7 for E500v2) 中的数据写入 TLB。</p>
<p><strong>3.3.4 读 TLB</strong><br />
<strong><br />
</strong>输入：MAS0[TLBSEL], MAS0[ESEL], MAS2[EPN]<br />
执行  tlbre<br />
输出：MAS1 ~ MAS3，若为 E500v2 且 HID0[EN_MAS7_UPDATE] 则将 RPN 的高 4 位置入  MAS7<br />
<strong> </strong></p>
<p><strong>3.3.2  置无效某项</strong></p>
<p>输入：无需借助 MAS 寄存器<br />
执行 tlbivax RA + RB</p>
<p>EA = RA + RB，为虚拟地址<br />
EA[32:51] 用于匹配 TLB 项 （组选 ＋ EPN 匹配），其不进行 PID 和 AS 的比较，则若同一组内有相同的 EPN，皆会将其置无效。<br />
EA[60] 用于选择操作的对象是 TLB0 还是 TLB1，类似 MAS0[TLBSEL]<br />
EA[61] 为 1 则置无效 TLB0 或 TLB1 的所有项</p>
<p>若 HID1[ABE] = 1 则该无效操作亦广播给其它 Core，置无效相应的项。</p>
<p>注意： TLB1 之 IPROT 位为 1 可使匹配的项免于被置无效</p>
<p><span style="color: #6aa84f;"><strong>4. TLB 相关异常</strong></span></p>
<p>Instruction TLB Error  异常，由 Instruction  TLB Miss  引起，用于从页表填充 TLB<br />
Data TLB Error 异常，由 Data TLB Miss 引起<br />
Instruction Storage 异常，由不允许的访问引起，如用户态读一个 UR 为 0（用户态不可读）的页<br />
Data Storage 异常，亦由不允许的访问引起</p>
<p><strong><span style="color: #674ea7;">5. Reset 后 TLB 的状态</span></strong></p>
<p>E500 上电后， TLB0 和 TLB1 的所有项都会被硬件自动置无效，后将 TLB1 的第一项自动初始化为：</p>
<p><a href="http://www.jackslab.org/wp-content/uploads/2011/02/tlb1.entry0_.png"><img class="aligncenter size-full wp-image-253" title="tlb1.entry0" src="http://www.jackslab.org/wp-content/uploads/2011/02/tlb1.entry0_.png" alt="" width="409" height="299" /></a></p>
<p>原因为： E500 在上电后，固定到虚拟地址 0xFFFF FFFC 处取指，但其既无实模式 (x86) 又无固定映射 (MIPS)，所以就要求 TLB 中至少有一项，映射到初始化代码处（位于 Flash 的 bootloader），故E500 规定，上电后 TLB1 的第一项始终映射 0xFFFF F000 到物理地址 0xFFFF F000 处，大小为 4KB。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jackslab.org/?feed=rss2&#038;p=239</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerPC 体系结构之中断异常</title>
		<link>http://www.jackslab.org/?p=230</link>
		<comments>http://www.jackslab.org/?p=230#comments</comments>
		<pubDate>Tue, 22 Feb 2011 03:14:53 +0000</pubDate>
		<dc:creator>Jack Tan</dc:creator>
				<category><![CDATA[PowerPC]]></category>
		<category><![CDATA[体系结构]]></category>
		<category><![CDATA[ISA]]></category>
		<category><![CDATA[中断]]></category>
		<category><![CDATA[异常]]></category>

		<guid isPermaLink="false">http://www.jackslab.org/?p=230</guid>
		<description><![CDATA[取 BOOKE 之精要。 1. 异常类型 00 Critical Interrupt     来自于外部中断控制器，具有较高的优先级 01 Machine Check    严重的内部状态错误，如 Cache 数据的校验失败 02  Data ...]]></description>
			<content:encoded><![CDATA[<p>取 BOOKE 之精要。</p>
<p><strong>1. 异常类型</strong></p>
<p><span style="color: #ff0000;"> 00</span> Critical Interrupt     来自于外部中断控制器，具有较高的优先级<br />
<span style="color: #ff0000;"> 01</span> Machine Check     严重的内部状态错误，如 Cache 数据的校验失败<br />
02  Data Storage     数据读写异常，如：用户态读一个非用户态的页 (UR=0)<br />
03  Instruction Storage    读指令异常，如：用户态时取一个用户态不可执行的页 (UX=0)<br />
<span style="color: #0baa20;"> 04</span> External Interrupt     来自于外部中断控制器<br />
05  Alignment     非对齐访问异常<br />
<span style="color: #0baa20;"> 06</span> Program     程序异常，如：执行非法指令，用户态执行特权指令<br />
07  Floating-Point unavailable    在无浮点部件的 CPU 上执行浮点指令即会触发此异常<br />
<span style="color: #0baa20;"> 08</span> System call     系统调用<br />
09  Auxiliary Processor Unavailable    在无协处理器的 CPU 上执行协处理器指令即触发此异常<br />
10     Decrementer     DEC 寄存器归零异常，DEC 是一个内部时钟计数器，Linux 用之实现时钟中断<br />
11     Fixed-interval timer interrupt<br />
<span style="color: #ff0000;"> 12</span> Watchdog timer interrupt<br />
<span style="color: #0baa20;"> 13</span> Data TLB error     数据 TLB Miss 异常<br />
<span style="color: #0baa20;"> 14</span> Instruction TLB error     指令 TLB Miss 异常<br />
<span style="color: #ff0000;"> 15</span> Debug     调试异常，用于支持调试</p>
<p>16 &#8211; 31    Reserved for future use    保留给将来体系结构升级用<br />
32 &#8211; 63   Allocated for implementation-dependent use   具体实现相关</p>
<p>其中 0，1，12，15 为 Critical Exception，当其发生时，使用 CSRR0 &amp; CSRR1 保存当前 PC 或 (PC + 4) 和 MSR；其他异常发生时，则使用 SRR0 &amp; SRR1 保存当前 PC 或 (PC + 4) 和 MSR</p>
<p>可以看到 BOOKE 体系结构层面规定的异常即为前 16 个，这其中的有些异常是个笼统的抽象（比如 Data Storage 就需要区分是读还是写导致的），为了更细地描述发生异常的原因，PowerPC 引入了一个 ESR (Exception Syndrome Register)，让硬件在异常发生时，在其中指出更具体的原因。比如 若 ESR[40] 被置位，则说明异常是由写操作引起的。</p>
<p><span id="more-230"></span></p>
<p><strong>2. 异常入口（向量）<br />
</strong><br />
BOOKE 使用可读写的内部寄存器 IVPR 和 IVOR 来指定异常的入口。</p>
<p>其中 IVPR (Interrupt Vector Prefix Register) 为 64 bit，指定所有异常入口基地址的高 48 bit，即 IVPR[48:63] 始终为 0</p>
<p>IVOR (Interrupt Vector Offset Register) 为 32 bit，指定具体异常入口相对异常基地址的偏移，每个异常一个，只使用其低 16 位。则其 IVOR[32:40] 为 0；又因所有入口 16 字节对齐，实际上 IVOR[60:63] 亦始终 0：</p>
<p>IVOR00           Critical Interrupt<br />
IVOR01           Machine Check<br />
IVOR02           Data Storage<br />
IVOR03           Instruction Storage<br />
IVOR04           External Interrupt<br />
IVOR05           Alignment<br />
IVOR06           Program<br />
IVOR07           Floating-Point unavailable<br />
IVOR08           System call<br />
IVOR09           Auxiliary Processor Unavailable<br />
IVOR10           Decrementer<br />
IVOR11           Fixed-interval timer interrupt<br />
IVOR12           Watchdog timer interrupt<br />
<strong>IVOR13 </strong> Data TLB error<br />
IVOR14           Instruction TLB error<br />
IVOR15           Debug<br />
IVOR16 ~ IVOR31<br />
IVOR32 ~ IVOR63</p>
<p>则 Data TLB Miss 的异常入口即为： IVPR[0:47] || IVOR[48:59] || 0b0000</p>
<p><strong>注意：</strong>PowerPC 没有 RESET 异常这个概念，故没有 RESET 的入口，上电后处理器直接到固定地址去取指令(E500 上为 0xFFFF FFFC)。</p>
<p><strong>3. 相关寄存器</strong></p>
<p><strong> 3.0 MSR </strong>(Machine Status Register)</p>
<p>内含部分异常使能位，清位则屏蔽相应的异常：</p>
<p>MSR[46], CE (Critical Enable) &#8212; Critical Input and Watchdog Timer Interrupts Enable<br />
MSR[48], EE (External Enable) &#8212; External Input, Decrementer and Fixed-Interval Timer Interrupts Enable<br />
MSR[51], ME (Machine Check Enable) &#8212; Machine Check Enable<br />
MSR[54], DE (Debug Enable) &#8212; Debug Enable</p>
<p>MSR[49], PR (Proble State) &#8212; 置 1 表示处理器处于用户态，置 0 则为核心态</p>
<p>当 Critical Exception 发生时，硬件将 MSR 保存于 CSRR1 后，仅保持 ME 不变，自动将 MSR 之其它位清零（PR = 0，进入核心态）</p>
<p>当一般异常发生时，硬件将 MSR 保存于 SRR1 后，保持 CE，DE，ME 不变，自动将其它位清零</p>
<p><strong><br />
3.1 SRR0</strong> (Save/Restore Register 0)</p>
<p>64 bit，用于异常发生时保存引起异常指令的地址（异常）或其下一条指令的地址（中断）。<br />
保存过程硬件自动做<br />
执行 rfi 从异常返回时，处理器会跳转到 SRR0 保存的地址处继续执行。</p>
<p><strong> 3.2 SRR1 </strong>(Save/Restore Register 1)</p>
<p>32 bit，用于异常发生时硬件自动保存 MSR (Machine Status Register)<br />
执行 rfi 从异常返回时，处理器会将 SRR1 值恢复入 MSR</p>
<p><strong> 3.3 CSRR0</strong> (Critical Save/Restore Register 0)</p>
<p>64 bit，用于 Critical Exception (0, 1, 12, 15)<br />
其它与 SRR0 同，只是该类型异常使用指令 rfci 返回</p>
<p><strong> 3.4 CSRR1</strong> (Critical Save/Restore Register 1)</p>
<p>32 bit，用于 Critical Exception (0, 1, 12, 15)<br />
其它与 SRR1 同，只是该类型异常使用指令 rfci 返回</p>
<p><strong> 3.5 DEAR</strong> (Data Exception Address Register)</p>
<p>64 bit，用于记录访存失败的地址，类似 MIPS 之 BadVAddr 或 x86 之 CR2</p>
<p><strong> 3.6 IVPR &amp; IVORi</strong></p>
<p>64 bit &amp; 32 bit，异常入口寄存器</p>
<p><strong> 3.7 ESR</strong> (Exception Syndrome Register)</p>
<p><a href="http://www.jackslab.org/wp-content/uploads/2011/02/esr.def_.png"><img class="aligncenter size-full wp-image-231" title="esr.def" src="http://www.jackslab.org/wp-content/uploads/2011/02/esr.def_.png" alt="" width="418" height="371" /></a></p>
<p><strong><br />
4. 完整的例子<br />
</strong><br />
以外设中断为例：</p>
<p>a. 外部中断控制器通过中断引脚 (#int) 触发处理器进入 External Input 异常<br />
b. 保存当前 PC + 4 入 SRR0 （异步，无需重新执行之，故下一条指令即可）<br />
c. 保存当前 MSR 入 SRR1，保持 MSR 之 CE, DE, ME，其余清除<br />
d. 跳转到入口 IVPR + IVOR4 处 （interrupt handler 之所在）<br />
e. interrupt handler 使用指令 rfi 返回，处理器在执行该指令时自动把 SRR1 恢复入 MSR，SRR0 入 PC</p>
<p>最后给一个 BOOKE 之异常的全家福：</p>
<p><a href="http://www.jackslab.org/wp-content/uploads/2011/02/esr.def_.png"><img class="aligncenter size-full wp-image-231" title="esr.def" src="http://www.jackslab.org/wp-content/uploads/2011/02/esr.def_.png" alt="" width="418" height="371" /></a></p>
<p><strong>参考文献：</strong></p>
<p>[1] Book E: Enhanced PowerPC Architecture, V1.0, 2002.5</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jackslab.org/?feed=rss2&#038;p=230</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerPC 体系结构之指令集 (II)</title>
		<link>http://www.jackslab.org/?p=221</link>
		<comments>http://www.jackslab.org/?p=221#comments</comments>
		<pubDate>Tue, 22 Feb 2011 02:53:13 +0000</pubDate>
		<dc:creator>Jack Tan</dc:creator>
				<category><![CDATA[PowerPC]]></category>
		<category><![CDATA[体系结构]]></category>
		<category><![CDATA[ISA]]></category>
		<category><![CDATA[指令集]]></category>

		<guid isPermaLink="false">http://www.jackslab.org/?p=221</guid>
		<description><![CDATA[3.3 整数指令 这类指令大致分为如下几类： 整数访存指令 整数算术运算指令 整数逻辑运算指令 整数比较指令 整数陷阱指令 整数移位指令 XER 指令 其中以整数循环移位指令最为特别。 3.3.1 整数访存指令 3.3.1.1 Load Byte/Half-word/Word ...]]></description>
			<content:encoded><![CDATA[<p><span style="color: #3399ff;"><strong> 3.3 整数指令</strong></span></p>
<p>这类指令大致分为如下几类：</p>
<p>整数访存指令<br />
整数算术运算指令<br />
整数逻辑运算指令<br />
整数比较指令<br />
整数陷阱指令<br />
整数移位指令<br />
XER 指令</p>
<p>其中以整数循环移位指令最为特别。</p>
<p><strong> 3.3.1 整数访存指令</strong></p>
<p><strong>3.3.1.1</strong> Load Byte/Half-word/Word and Zero</p>
<p>该类指令从指定地址处读取 8 位、16 位、32 位数据，置入 RT，RT  高位置 0</p>
<p>lbz/lbzu                           RT, D(RA)<br />
lbzx/lbzux                  RT,  RA, RB</p>
<p>lhz/lhzu                           RT, D(RA)<br />
lhzx/lhzux                  RT,  RA, RB</p>
<p>lwz/lwzu                        RT, D(RA)<br />
lwzx/lwzux                  RT,  RA, RB</p>
<p>RT, RA, RB 皆为 GPR，D 为有符号立即数。则有效地址的计算分别为：RA[32:63] + D，RA[32:63] + RB[32:63]，有效地址高 32 位置 0。</p>
<p>后缀 u 表示 Update，即将有效地址更新到 RA 中<br />
后缀 x 表示 Indexed，即使用 RA + RB 的寻址方式</p>
<p>以上用于 32 位，对 64 位，上述指令皆加后缀 &#8216;e&#8217;。则有效地址的 0 ~ 31 位， 不再置 0，其计算方式如下：RA + D，RA + RB。</p>
<p>此外，用于 64 位的还有对双字操作的支持：</p>
<p>lde/ldue/ldxe/lduxe<br />
<em><span id="more-221"></span></p>
<p></em><strong>3.3.1.2</strong> Load Half-word Algebraic</p>
<p>lha/lhau                           RT, D(RA)<br />
lhax/lhaux                  RT,  RA, RB<em></p>
<p></em>与 lhz 不同的是，该指令将所读取的半字的最高位 (RT[48]) 填充到 RT[32:47]，实际上就是形成一个 16 位的补码有符号数。</p>
<p>有效地址计算与上同；后缀 u, x 与上同。</p>
<p>对 64 位情形，上述指令皆加后缀 &#8216;e&#8217;，有效地址计算与上小节同。<br />
<em></p>
<p></em><strong>3.3.1.3</strong> <span style="color: #808000;">Load Halfword/Word Byte-Reverse</span><strong></p>
<p></strong>从指定地址处读取 16 位/32 位数据，将字节反转后置入 RT，RT 高位置 0<br />
<strong><br />
</strong> lhbrx        RT, RA, RB<br />
lwbrx        RT, RA, RB</p>
<p>如： lwbrx        r3, r2, r1，若 r2 + r1 地址处的数据为 0x55aa66bb，则 r3 的结果为 0xbb66aa55</p>
<p>对 64 位情形，上述指令皆加后缀 &#8216;e&#8217;，有效地址计算与上小节同。</p>
<p><strong>3.3.1.4</strong> <span style="color: #99cc00;">Load Multiple Word</span></p>
<p>lmw        RT, D(RA)</p>
<p>该指令将 RA + D 开始处的数据，顺序置入 RT ~ R31 中，共读取 31 &#8211; T 个字</p>
<p>该指令无 64 位扩展。</p>
<p><strong>3.3.1.5</strong> <span style="color: #99cc00;">Load String Word</span></p>
<p>lswi         RT, RA, NB               （后缀 i，表示立即数 Immediate）<br />
lswx         RT, RA, RB          （后缀 x，表示 Indexed 寻址方式）</p>
<p>加载 n 个字节到 RT  开始的寄存器中；<br />
当 NB == 0 时 n = 32； NB != 0 时 n = NB，NB 取值范围为 0 ~ 31</p>
<p>如 r3 = 0&#215;1000 ：</p>
<p>lswi        r4, r3, 16</p>
<p>则将 0&#215;1000 处的 16 字节，依次写入 r4, r5, r6, r7</p>
<p>对于 lswx，要加载的字节数则位于 XER[57:63]</p>
<p>该指令无 64 位扩展。</p>
<p><strong>3.3.1.6</strong> <span style="color: #009900;">Load Word/Doubleword and Reserve</span></p>
<p>lwarx         RT, RA, RB</p>
<p>该指令与 lwzx 的差别在于，其还将处理器内部的 RESERVE 位置为 1，并将有效地址对应的物理地址放入 RESERVE_ADDR 中。</p>
<p>该指令的 64 位版本为： lwarxe        RT, RA, RB，差别还是在于有效地址的 0 ~ 31 不被置 0</p>
<p>此外还有一个 ldarxe        RT, RA, RB，与 lwarxe 的差别在于其加载 8 字节的数据。</p>
<p>这三条指令常分别与 stwcx./stwcxe./stdcxe. 联用，用于实现锁操作，类似 MIPS 之 ll/sc 指令。</p>
<p><strong>3.3.1.7 </strong>Store<strong> </strong></p>
<p>stb/stbu                           RS, D(RA)<br />
stbx/stbux                  RS,  RA, RB<br />
sth/sthu                           RS, D(RA)<br />
sthx/sthux                  RS,  RA, RB<br />
stw/stwu                           RS, D(RA)<br />
stwx/stwux                  RS,  RA, RB</p>
<p>该类指令将 RS 中的 8 位、16 位、32 位数据写入有效地址处。后缀 &#8216;u&#8217;, &#8216;x&#8217; 之含义与 3.3.1.1 同。</p>
<p>上述 12 条指令加后缀 &#8216;e&#8217; 则用于 64 位。有效地址计算与与 3.3.1.1 同。</p>
<p>另用于 64 位的还有对双字操作的支持：</p>
<p>stde/stdue/stdxe/stduxe</p>
<p><strong>3.3.1.8</strong> <span style="color: #ffcc00;">Store Halfword/Word Byte-Reverse</span></p>
<p>sthbrx    RS, RA, RB<br />
stwbrx    RS, RA, RB</p>
<p>将 RS 中的 16/32 bit 的数据字节反转后置入有效地址处。该指令用于支持在大端系统上以小端序存储数据，亦或在小端系统上以大端序存储数据。</p>
<p>对 64 位情形，上述指令皆加后缀 &#8216;e&#8217;，有效地址计算与上小节同。</p>
<p><strong>3.3.1.9</strong> <span style="color: #ff9900;">Store Multiple Word</span></p>
<p>smw       RS, D(RA)</p>
<p>该指令将 RS ~ R31 中的数据 （一个字），写入到 RA + D 处</p>
<p>该指令无 64 位扩展。</p>
<p><strong>3.3.1.10</strong> <span style="color: #ff9900;">Store  String Word</span></p>
<p>stswi              RS, RA, NB           （后缀 i，表示立即数 Immediate）<br />
stswx          RS, RA, RB           （后缀 x，表示 Indexed 寻址方式）</p>
<p>与 lswi/lswx 的操作相反，其将 RS 开始的寄存器组中的 n 个字节，写入到有效地址处（位于 RA）</p>
<p>当 NB == 0 时 n = 32； NB != 0 时 n = NB，NB 取值范围为 0 ~ 31</p>
<p>如 r3 = 0&#215;1000 ：</p>
<p>stswi        r4, r3, 16</p>
<p>则将 r4, r5, r6, r7  中的 16 字节数据依次写入 0&#215;1000 处</p>
<p>对于 stswx，要加载的字节数则位于 XER[57:63]</p>
<p>该指令无 64 位扩展。</p>
<p><strong>3.3.1.11</strong> <span style="color: #ff6600;">Store  Word/Doubleword Conditional</span></p>
<p>stwcx.                RS, RA, RB</p>
<p>如果 RESERVE 位为 1，且 RA + RB 对应的物理地址与 RESERVE_ADDR 一致，则将 RS[32:63] 的内容写入到 RA + RB 处，将 CR0[eq] 位置为 1 后，再将 RESERVE 位复位为 0。</p>
<p>若条件不满足，则仅将 CR0[eq] 位置为 0</p>
<p>可用该指令与 lwarx 联用，实现 spin_lock：</p>
<p>li       r0, 1<br />
loop:<br />
lwarx       r4, 0, r3<br />
cmpwi      r4, 0                     # r4[32:63] 与 0 比较<br />
bne loop<br />
stwcw.       r0, 0, r3<br />
bne       loop<br />
isync</p>
<p>解锁则为：</p>
<p>msync<br />
li       r0, 0<br />
stw       r0, 0(r3)</p>
<p>下面的指令用于 64 位：</p>
<p>stwcxe.            RS, RA, RB<br />
stdcxe.            RS, RA, RB</p>
<p>差别在于有效地址的高 32 位不再被置为 0。</p>
<p><strong> 3.3.2 整数算术运算指令</strong></p>
<p>加、减、乘、除、取负</p>
<p><strong> 3.3.3 整数逻辑运算指令</strong></p>
<p>与、或、非、异或<br />
<strong><br />
3.3.4 整数比较指令</strong></p>
<p>cmp                   BF, L, RA, RB<br />
cmpi                BF, L, RA, SI                     # RA 与有符号立即数 SI 比较<br />
cmpl                BF, L, RA, RB                     # RA, RB 逻辑比较。l &#8212;&gt; logical<br />
cmpli                BF, L, RA, UI                     # RA 与无符号立即数 UI 逻辑比较</p>
<p>BF 取值 0 ~ 7，用于指定使用的 CR 域<br />
L 为 0，则为 32 位比较；为 1，则为 64 位比较</p>
<p>如：</p>
<p>cmpi              0, 0, r3, 5</p>
<p>若 r3 &gt; 5，则 CR0[gt] = 1；若 r3 &lt; 5，则 CR0[lt] = 1</p>
<p><strong> 3.3.5 整数陷阱指令</strong></p>
<p>tw                    TO, RA, RB<br />
twi            TO, RA, SI</p>
<p>TO 为立即数，5 位，从左到右标号为 0 ~ 4，依次表示小于、大于、等于、无符号小于、无符号大于。用于指定 Trap 的条件。<br />
SI： Signed Immediate</p>
<p>如：</p>
<p>twi       0&#215;10, r3, 5</p>
<p>则如果 r3 &lt; 5，则陷入异常。</p>
<p>以上用于单字 (32 bit) 比较，双字比较则用：</p>
<p>td                    TO, RA, RB<br />
tdi            TO, RA, SI</p>
<p><strong><br />
3.3.6 整数移位指令</strong></p>
<p><strong> 3.3.6.1</strong> <span style="color: #99cc00;"><strong>Rotate</strong></span></p>
<p>rlwimi                RA, RS, SH, MB, ME                            # Rotate Left Word Immediate then Mask Insert<br />
rlwinm                RA, RS, SH, MB, ME                            # Rotate Left Word Immediate then AND with Mask<br />
rlwnm                 RA, RS, RB, MB, ME                            # Rotate Left Word then AND with Mask</p>
<p>以下是该指令的一些例子：</p>
<p>all r11 is: 0x55aa67bb</p>
<p>r0 = 0&#215;00000000<br />
rlwimi      r0, r11, 8, 0, 31<br />
r0 is: 0xaa67bb55</p>
<p>r0 = 0&#215;12345678<br />
rlwimi      r0, r11, 8, 0, 14<br />
r0 is: 0xaa665678</p>
<p>r0 = 0&#215;1<span style="color: #99cc00;">234567</span>8<br />
rlwimi      r0, r11, 8, 28, 3<br />
r0 is: 0xa<span style="color: #99cc00;">234567</span>5</p>
<p>即：取 RS 循环左移 SH 位后的 WB 到 WE 位，替换 RA 的 WB 到 WE 位。</p>
<p>r0 = 0&#215;00000000<br />
rlwinm      r0, r11, 8, 0, 31<br />
r0 is: 0xaa67bb55</p>
<p>r0 = 0&#215;12345678<br />
rlwinm      r0, r11, 8, 0, 14<br />
r0 is: 0xaa660000</p>
<p>即：取 RS 循环左移 SH 位后的 WB 到 WE 位，替换归零后的 RA</p>
<p>rldcl<br />
rldcr<br />
rldic<br />
rldicl<br />
rldicr<br />
rldimi</p>
<p><strong> 3.3.6.2</strong> Shift</p>
<p>slw<br />
srw<br />
sraw<br />
srawi</p>
<p>slw./srw./sraw./srawi.</p>
<p>sld<br />
srd<br />
srad<br />
sradi</p>
<p><strong> 3.3.7 XER 指令</strong></p>
<p>mcrxr              BF<br />
mcrxr64            BF</p>
<p><span style="color: #3399ff;"><strong> 3.4 浮点指令</strong></span></p>
<p>这类指令包括：</p>
<p>浮点数据加载与存储指令<br />
浮点运算指令<br />
浮点数近似和转化指令<br />
浮点比较指令<br />
浮点状态和控制寄存器指令</p>
<p>有关该指令的详情留待以后以《PowerPC 浮点结构》的形式讨论吧。</p>
<p><span style="color: #3399ff;"><strong> 3.5 处理器控制指令</strong></span></p>
<p>这类指令包括用于支持异常中断处理的：</p>
<p>sc                            System Call<br />
rfci                     Return From Critical Interrupt<br />
rfi                       Return From Interrup</p>
<p>用于处理器控制寄存器维护的：</p>
<p>mfspr              RT, SPRN                     Move From SPRN (Special Purpose Register) to RT<br />
mtspr              SPRN, RS                     Move RS To SPRN</p>
<p>mfdcr              RT, DCRN                     Move From DCRN (Device Control Register) to RT<br />
mtdcr              DCRN, RS                     Move RS To DCRN</p>
<p>mfmsr              RT                            Move From MSR to RT<br />
mtmsr              RS                            Move RS To MSR</p>
<p>wrtee              RA       Write MSR External Enable, MSR[EE] = RA[48]<br />
wrteei         E       Write MSR External Enable Immediate, MSR[EE] = E</p>
<p>以及用于指令同步的：</p>
<p>isync</p>
<p>其保证在其之前的所有指令皆提交，在其自己被提交前，其之后的指令不会进入流水线</p>
<p><span style="color: #3399ff;"><strong> 3.6 存储管理相关指令<br />
</strong></span><br />
这类指令包括用于 TLB 管理的：</p>
<p>tlbivax<br />
tlbre<br />
tlbwe<br />
tlbsx<br />
tlbsync</p>
<p>tlbivaxe<br />
tlbsxe</p>
<p>用于 Cache 管理的：</p>
<p>dcba/dcbf/dcbi/dcbst/dcbt/dcbtst/dctz/icbi/icbt<br />
dcbae/dcbfe/dcbie/dcbste/dcbte/dcbtste/dctze/icbie/icbte</p>
<p>用于存储同步的：</p>
<p>msync<br />
mbar</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jackslab.org/?feed=rss2&#038;p=221</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerPC 体系结构之指令集 (I)</title>
		<link>http://www.jackslab.org/?p=209</link>
		<comments>http://www.jackslab.org/?p=209#comments</comments>
		<pubDate>Mon, 21 Feb 2011 09:30:25 +0000</pubDate>
		<dc:creator>Jack Tan</dc:creator>
				<category><![CDATA[PowerPC]]></category>
		<category><![CDATA[体系结构]]></category>
		<category><![CDATA[ISA]]></category>
		<category><![CDATA[指令集]]></category>

		<guid isPermaLink="false">http://www.jackslab.org/?p=209</guid>
		<description><![CDATA[1. 概述 Book E 定义的 PowerPC 指令集的指令可分为以下几类： 分支跳转指令 CR 指令 整数指令 浮点指令 处理器控制指令 存储管理相关指令 CR 指令主要是对 CR ...]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ff6600;"><strong>1. 概述</strong></span></p>
<p>Book E 定义的 PowerPC 指令集的指令可分为以下几类：</p>
<p>	分支跳转指令<br />
	CR 指令 整数指令<br />
	浮点指令<br />
	处理器控制指令<br />
	存储管理相关指令</p>
<p>CR 指令主要是对 CR 内部位运算支持的一些指令，如 crand, cror, crxor 等等。</p>
<p><span style="color: #009900;"><strong>2. 常用指令</strong></span></p>
<p>先看一个测试程序：</p>
<pre class="brush:cpp">int test_call(int a, int b, int c)
{
	a = b + c;
	return a;
}

int test_if(int s)
{
	int i;
	if(s &gt; 0)
		i = s;
	else if(s &lt; 0)
		i = -s;
	else
		i = s * 8;
	return i;
}

int test_cyc1(int c)
{
	int sum = 0;
	do {
		sum += c;
		c--;
	} while(c &gt; 0);
	return c;
}

int test_cyc2(int c)
{
	int sum = 0;
	for(; c &gt; 0; c--)
		sum += c;
	return c;
}

int main()
{
	int a, b, c, d;
	a = test_if(5);
	b = test_cyc1(10);
	c = test_cyc2(10);
	d = test_call(1, 2, 3);
	return a + b + c + d;
}</pre>
<p>引入的目的在于查看判断、循环和过程调用这些基本结构在 PowerPC 里怎么被支持。</p>
<p>-O2 参数编译后，objdump -S -d 反汇编，则：</p>
<p><span id="more-209"></span></p>
<pre class="brush:cpp">1000040c &lt;test_call&gt;:
int test_call(int a, int b, int c)
{
	a = b + c;
	return a;
}
1000040c:    7c 64 2a 14     add     r3,r4,r5
--&gt; 对应 a, b, c 三个参数，同时 r3 又置返回值
10000410:    4e 80 00 20     blr
--&gt; 跳转到 LR 所存放的地址处，即函数返回

10000414 &lt;test_if&gt;:
int test_if(int s)
{
	int i;
	if(s &gt; 0)
10000414:    7c 60 1b 79     mr.     r0,r3
--&gt; r3 移到 r0，若 r0 小于、大于、等于 0，则置 CR0 的相应位。指令后多一点，则说明该指令会据执行结果，设置 CR 的相应位
10000418:    7c 03 03 78     mr      r3,r0
--&gt; 此条指令多余
1000041c:    4d a1 00 20     bgtlr+
--&gt; 若 CR0[gt] 位为 1，则跳转到 LR 所存放的地址处，即直接函数返回了。此条指令等价于 bclr  13, 1
		i = s;
	else if(s &lt; 0)
10000420:    38 60 00 00     li      r3,0
10000424:    4d 82 00 20     beqlr
--&gt; 若 CR0[eq] 位为 1，则跳转到 LR 所存放的地址处，也直接函数返回了。此条指令等价于 bclr      12, 2
		i = -s;
10000428:    7c 60 00 d0     neg     r3,r0
--&gt; r0 取反，入 r3
	else
		i = s * 8;
	return i;
}
1000042c:    4e 80 00 20     blr
--&gt; 跳转到 LR 所存放的地址处，函数返回

10000430 &lt;test_cyc1&gt;:
int test_cyc1(int c)
{
10000430:    34 03 ff ff     addic. r0,r3,-1
10000434:    7c 69 03 a6     mtctr   r3
10000438:    41 80 00 10     blt-    10000448 &lt;test_cyc1+0x18&gt;
	int sum = 0;
	do {
		sum += c;
		c--;
1000043c:    38 63 ff ff     addi    r3,r3,-1
	} while(c &gt; 0);
10000440:    42 00 ff fc     bdnz+   1000043c &lt;test_cyc1+0xc&gt;
	return c;
}
10000444:    4e 80 00 20     blr
10000448:    38 00 00 01     li      r0,1
1000044c:    7c 09 03 a6     mtctr   r0
10000450:    4b ff ff ec     b       1000043c &lt;test_cyc1+0xc&gt;

10000454 &lt;test_cyc2&gt;:
int test_cyc2(int c)
{
10000454:    2c 03 00 00     cmpwi   r3,0
10000458:    39 20 00 00     li      r9,0
1000045c:    7d 23 48 1e     .long 0x7d23481e
	int sum = 0;
	for(; c &gt; 0; c--)
		sum += c;
	return c;
}
10000460:    7d 23 4b 78     mr      r3,r9
10000464:    4e 80 00 20     blr

int main()
{
10000468:   94 21 ff e0     stwu    r1,-32(r1)
1000046c:   7c 08 02 a6     mflr    r0
	int a, b, c, d;
	a = test_if(5);
10000470:   38 60 00 05     li      r3,5
10000474:   90 01 00 24     stw     r0,36(r1)
10000478:   93 61 00 0c     stw     r27,12(r1)
1000047c:   93 81 00 10     stw     r28,16(r1)
10000480:   93 a1 00 14     stw     r29,20(r1)
10000484:   4b ff ff 91     bl      10000414 &lt;test_if&gt;
10000488:   7c 7d 1b 78     mr      r29,r3
	b = test_cyc1(10);
1000048c:   38 60 00 0a     li      r3,10
10000490:   4b ff ff a1     bl      10000430 &lt;test_cyc1&gt;
10000494:   7c 7b 1b 78     mr      r27,r3
	c = test_cyc2(10);
10000498:   38 60 00 0a     li      r3,10
	d = test_call(1, 2, 3);
1000049c:   7f bd da 14     add     r29,r29,r27
100004a0:   4b ff ff b5     bl      10000454 &lt;test_cyc2&gt;
100004a4:   38 80 00 02     li      r4,2
100004a8:   7c 7c 1b 78     mr      r28,r3
100004ac:   38 a0 00 03     li      r5,3
100004b0:   38 60 00 01     li      r3,1
100004b4:   4b ff ff 59     bl      1000040c &lt;test_call&gt;
	return a + b + c + d;
}
100004b8:   80 01 00 24     lwz     r0,36(r1)
100004bc:   7f 9c 1a 14     add     r28,r28,r3
100004c0:   83 61 00 0c     lwz     r27,12(r1)
100004c4:   7c 7d e2 14     add     r3,r29,r28
100004c8:   83 81 00 10     lwz     r28,16(r1)
100004cc:   83 a1 00 14     lwz     r29,20(r1)
100004d0:   7c 08 03 a6     mtlr    r0
100004d4:   38 21 00 20     addi    r1,r1,32
100004d8:   4e 80 00 20     blr</pre>
<p><span style="color: #3399ff;"><strong>3. 分类概述</strong></span></p>
<p><strong> 3.1 分支跳转指令</strong></p>
<p>这类指令算是 PowerPC 里比较有特色的，也是稍显复杂的。这类指令与 CR, LR 和 CTR 紧密相联，建构起判断、循环和过程调用这些程序的基本结构。其大致可分为四类：</p>
<p>Branch<br />
Branch Conditional<br />
Branch Conditional to Count Register<br />
Branch Conditional to Link Register<br />
<strong> </strong></p>
<p><strong> 3.1.1 Branch</strong></p>
<p>这类指令与 CR 没有联系，即为非条件跳转，助记符后直接跟立即数地址。指令内为立即数地址预留 26 位，即可跳转 2^26 大小的空间，如：(CIA, Current Instruction Address)</p>
<p>b                                             0&#215;20                       &#8212;&#8211;&gt; 以当前指令地址为基点，往后跳转 0&#215;20 字节，即 PC = CIA + 0&#215;20<br />
ba                               0&#215;20                                                            &#8212;&#8211;&gt; 直接跳转到地址 0&#215;20 处。<strong>后缀为 a，则表示使用 Absolute Address，PC = 0&#215;20</strong>。<br />
bl                   0&#215;20                                                            &#8212;&#8211;&gt; 在 b 0&#215;20 的基础上，将 LR 更新为 CIA + 4<br />
bla                 0&#215;20                                                            &#8212;&#8211;&gt; 使用绝对地址，且更新 LR。<strong>后缀带 l，则表示更新 LR 为 CIA + 4</strong></p>
<p>以上针对 32 位的情形，对 64 位则使用指令 be, bea, bel, bela 功能与上同。</p>
<p><strong>3.1.2 Branch Conditional</strong></p>
<p>此类为条件跳转指令。皆以 bc 开头，带 3 个操作数，如：</p>
<p>bc                        BO, BI, BD<br />
bca               BO, BI, BD<br />
bcl                  BO, BI, BD<br />
bcla              BO, BI, BD</p>
<p>后缀 a, l 的含义与 branch 类指令同。BO 指定跳转的条件，5 位；BI 指定关联的 CR 位，也是 5 位；BD 为跳转的立即数地址，16 位。</p>
<p>其中以 BO 的编码最为复杂（BO 从左到右编号为 0 ~ 4）：</p>
<p>BO[0]: 为 1，则直接跳转<br />
BO[1]: 为 1，则条件为真时，跳转。否则条件为假时，跳转<br />
BO[2]: 为 1，则 CTR 不自动减 1<br />
BO[3]: 为 1 时，则 CTR == 0 时跳转；为 0 时，则 CTR != 0 时跳转<br />
BO[4]: 静态预测位，1 表示 unlikely，0 表示 likely</p>
<p>则常见的 BO 值：<br />
20 (0b10100) 则表示无条件跳转<br />
12 (0b01100) 则表示 CR 的某个位为 1 时跳转<br />
4 (0b00100) 则表示 CR 的某个位为 0 时跳转</p>
<p>至于静态预测的策略位，默认被置为<strong> 0</strong>，则其行为为：</p>
<p>b1. 目标地址小于当前指令地址，预测为<span style="color: #ff9900;">跳转</span><br />
b2. 目标地址大于当前指令地址，预测为<span style="color: #ff9900;">不跳转</span><br />
b3. 对于目标地址在 CTR/LR 中的条件跳转指令，一律预测为<span style="color: #ff9900;">不跳转</span></p>
<p>若该位被置 <strong>1</strong>，则上述 b1, b2, b3 的静态预测行为分别为：<span style="color: #99cc00;">不跳转</span>，<span style="color: #99cc00;">跳转</span>，<span style="color: #99cc00;">跳转</span>。</p>
<p>可以给分支指令加一个 +/- 的后缀，来简化。加 &#8216;+&#8217; 的指令，一律预测为跳转。加 &#8216;-&#8217; 的分支指令，一律预测为不跳转。</p>
<p>则对于 b1，后缀 &#8216;+&#8217; 会将 y 位置 0，&#8217;-&#8217; 则将 y 位置 1。<br />
对于 b2，后缀 &#8216;+&#8217; 会将 y 位置 1，&#8217;-&#8217; 则将 y 位置 0。<br />
对于 b3，后缀 &#8216;+&#8217; 会将 y 位置 1，&#8217;-&#8217; 则将 y 位置 0。</p>
<p>BI 与关联 CR 位的关系为：</p>
<p>32 + BI</p>
<p>即，若 BI 为 2，则对应于 CR[34]，即为 CR0[gt] 位。</p>
<p>以上针对 32 位的情形，对 64 位则使用指令 bce, bcea, bcel, bcela 功能与上同。</p>
<p><strong>3.1.3 Branch Conditional to Count Register</strong></p>
<p>bcctr                BO, BI<br />
bcctrl               BO, BI</p>
<p>后缀 l 的含义与 branch 类指令同。<br />
BO，BI 的编码与 Branch Conditional 类指令同。<br />
跳转目标地址位于 CTR 中。</p>
<p>以上针对 32 位的情形，对 64 位则使用指令 bcctre, bcctrel 功能与上同。</p>
<p><strong>3.1.4 Branch Conditional to Link Register</strong></p>
<p>bclr                BO, BI<br />
bclrl               BO, BI</p>
<p>后缀 l 的含义与 branch 类指令同。<br />
BO，BI 的编码与 Branch Conditional 类指令同。<br />
跳转目标地址位于 LR 中。</p>
<p>以上针对 32 位的情形，对 64 位则使用指令 bclre, bclrel 功能与上同。</p>
<p><span style="color: #3399ff;"><strong>3.2 CR 指令</strong></span></p>
<p>这类指令包括用来支持 CR 内部位运算的指令和 CR 与 GPR 之间的数据交换指令。</p>
<p><strong>3.2.1 CR 内</strong><strong>位运算指令</strong></p>
<p>这类指令的格式皆为：           crxxx            BT, BA, BB</p>
<p>BT, BA, BB 是 CR 内的位编号，取值范围为 0 ~ 31，如 crand    0, 8, 12，则将 CR[32+8] (CR2[lt]) 与 CR[32+12] (CR3[lt]) 作与操作后，将结果置入 CR[32+0] (CR0[lt])，即 CR[32] = CR[40] &amp; CR[44]</p>
<p>crand:                                                CR[32+BA] &amp; CR[32+BB]<br />
crandc:                                      CR[32+BA] &amp; (~CR[32+BB])<br />
creqv:                                                ~(CR[32+BA] ^ CR[32+BB])，即位相等，则置 1；不等则置 0<br />
crnand:                        ~(CR[32+BA] &amp; CR[32+BB])<br />
crnor:                                       ~(CR[32+BA] | CR[32+BB])<br />
cror:                                       CR[32+BA] | CR[32+BB]<br />
crorc:                          CR[32+BA] | (~CR[32+BB])，先取反后再或<br />
crxor:                              CR[32+BA] ^ CR[32+BB]，位异或</p>
<p><strong>3.2.2  CR 与 GPR 间</strong><strong>数据交换指令</strong><br />
<strong><br />
3.2.2.1</strong> mcrf                                    BF, BFA          &#8212;          Move Condition Register Fields</p>
<p>将 CR 之 BFA 域复制到 BF 域。如 mcrf            0, 3 则将 CR3 拷入 CR0</p>
<p><strong><br />
3.2.2.2</strong> mtcrf                          FXM, RS          &#8212;          Move To Condition Register Fields</p>
<p>通用寄存器 RS 之 32 ~ 63 位以 4 位为单位，对应于 CR 的 8 个域，编号为 RS0 ~ RS7；<br />
FXM 为域掩码，8 位，从左到右编号为 0 ~ 7，对应于 RS、CR 的 8 个域。某位为 1，则将对应的 RS 域拷贝到对应的 CR 域中。<br />
若 FXM 为 0&#215;80，则只将 CR0 = RS0<br />
若 FXM 为 0xc8，则将 CR0 = RS0, CR1 = RS1, CR4 = RS4</p>
<p><strong> 3.2.2.3</strong> mfcr                          RT          &#8212;          Move From Condition Register</p>
<p>将 CR 的内容移入通用寄存器 RT 的 32 ~ 63 位。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jackslab.org/?feed=rss2&#038;p=209</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerPC 体系结构之 ULR 和 ABI</title>
		<link>http://www.jackslab.org/?p=203</link>
		<comments>http://www.jackslab.org/?p=203#comments</comments>
		<pubDate>Mon, 21 Feb 2011 09:21:54 +0000</pubDate>
		<dc:creator>Jack Tan</dc:creator>
				<category><![CDATA[PowerPC]]></category>
		<category><![CDATA[体系结构]]></category>
		<category><![CDATA[ISA]]></category>
		<category><![CDATA[ULR]]></category>

		<guid isPermaLink="false">http://www.jackslab.org/?p=203</guid>
		<description><![CDATA[A. 以下取 Book E 之 ULR 精要 ULR (User Level Register) 即用户态程序能用的寄存器，包括只读的和可读写的。 最常用的 ULR 包括以下寄存器： 1. GRP ...]]></description>
			<content:encoded><![CDATA[<p><span style="color: #99cc00;"><strong>A. 以下取 Book E 之 ULR 精要</strong></span></p>
<p>ULR (User Level Register)  即用户态程序能用的寄存器，包括只读的和可读写的。</p>
<p>最常用的 ULR 包括以下寄存器：</p>
<p><strong> 1.</strong> GRP (General Purpose Register)  通用寄存器，即用于定点运算的寄存器，共 32 个</p>
<p><strong> 2.</strong> <span style="color: #ff9900;">CR</span> (Condition Register) 指令状态寄存器，其格式如下所示：</p>
<p><a href="http://www.jackslab.org/wp-content/uploads/2011/02/CR.png"><img class="aligncenter size-full wp-image-204" title="CR" src="http://www.jackslab.org/wp-content/uploads/2011/02/CR.png" alt="" width="336" height="63" /></a><br />
<span style="color: #ff0000;"><strong>注意：</strong></span>Book E 对寄存器的位编号与通常不同，因其支持 PowerPC 64，故其将 64 位寄存器从最高位 (MSB) 到最低位 (LSB) 编号为 0 ~ 63，32 位寄存器则编号为 32 ~ 63。</p>
<p>CR 以4位为单位分成 8 个域，每个域能描述 4 种状态。</p>
<p><strong> 2.1</strong> CR0 用于存放 RC 位为1 的整数指令执行后的状态。CR[32:35] 依次表示小于、大于、等于和溢出。当指令执行的结果小于、大于或等于 0 时则置相应的CR[32:34] 的位；CR[35] 的值则直接复制自XER 的 SO (Summary Overflow)位。</p>
<p><strong> 2.2</strong> CR1用于存放 RC 位为 1 的所有浮点指令执行后的浮点异常状态。其内容直接复制于浮点状态与控制寄存器 (FPSCR)，CR[36:39] 依次对应于浮点异常 (FX)、浮点使能异常 (FEX)、浮点非法操作异常 (VX) 和浮点溢出异常 (OX)。</p>
<p>RC 位为 1 的指令，其助记符的最后有一个 &#8216;<strong>.</strong>&#8216; ，如 addic./divw./mullw./neg./and./or./xor./nand./nor.</p>
<p><strong> 2.3</strong> 对于比较指令（整数和浮点），可以通过操作数 BF 指定比较结果所存储的 CR 域：</p>
<p>cmp      <span style="color: #99cc00;"><strong>3</strong></span>, 0, r3, r4         (cmp     BF, L, RA, RB)</p>
<p>操作数 L = 0，表示此为 32 位比较，即只比较 r3, r4 的 32 ~ 63 位。若 r3 &gt; r4，则将 CR<span style="color: #99cc00;"><strong>3</strong></span>[gt] (CR[45]) 置位。浮点比较类似，但域内第 4 位含义与整数不同，整数依然表示溢出 (SO)，且其值拷贝自 XER[SO]；而对浮点比较，若该位被置，则表示某一浮点操作数不是数值。</p>
<p><strong> 2.4</strong> 此外 RC 位为 1 的条件存储指令 (stwcx<strong>.</strong>/stwcxe<strong>.</strong>/stdcxe<strong>.</strong>)，在存储操作成功时置 CR0[2] (EQ 位) 为 1。</p>
<p><span id="more-203"></span></p>
<p><strong>3. </strong>LR (Link Register) 链接寄存器，用于存放返回地址<br />
Branch and Link 类指令（如 bl，指令内 LK 位为 1）会将下条指令的地址自动写入 LR。bl 用于调用子过程，则置入 LR 的即为返回地址<br />
Branch Conditional to Link Register 类指令（如 bclr）则使用 LR 作为跳转的目标地址，该类指令通常用于子过程返回</p>
<p><strong> 4. </strong>CTR (Count Register) 计数寄存器，常用于存放跳转目标地址，与 Branch Conditional to Count Register 类指令配合使用；亦可存放循环变量与条件分支指令 (Branch Conditional) 配合，实现循环</p>
<p>CR，LR 和 CTR 是与分支指令紧密联系的，在实现基本程序结构之判断、循环以及过程调用方面作用巨大。</p>
<p><strong> 5. </strong>XER (Integer eXception Register) 整数异常寄存器，用于置整数运算的溢出 (Overflow)、进位 (Carry Out) 以及批量加载和存储指令要操作的字节数</p>
<p><strong>6. E500 ULR</strong></p>
<p>下图为 e500 之 ULR 概览：</p>
<p><a href="http://www.jackslab.org/wp-content/uploads/2011/02/e500-ulr.png"><img class="aligncenter size-full wp-image-205" title="e500-ulr" src="http://www.jackslab.org/wp-content/uploads/2011/02/e500-ulr.png" alt="" width="689" height="278" /></a></p>
<p>可以看到 e500 没有浮点寄存器，其没有浮点部件。</p>
<p><strong>7. E600 ULR</strong></p>
<p>下图为 e600 之 ULR 概览：</p>
<p><a href="http://www.jackslab.org/wp-content/uploads/2011/02/e600-ulr.png"><img class="aligncenter size-full wp-image-206" title="e600-ulr" src="http://www.jackslab.org/wp-content/uploads/2011/02/e600-ulr.png" alt="" width="258" height="541" /></a></p>
<p>e600 则含32个浮点寄存器，且含 32 个向量寄存器 (VR0 ~ VR31) 用于支持向量计算。</p>
<p><strong><span style="color: #ff6600;"><br />
B. ABI</span></strong></p>
<p>ABI 即 Application Binary Interface。其主要规定通用寄存器的使用约定，以及过程调用的栈的组织。一般最常用的就是通用寄存器的使用约定。Linux 下常用SYS V ABI。</p>
<p>以下是比较诸多 PowerPC ABI 版本后的一个交集：</p>
<p>GPR1: Stack Pointer<br />
GPR3 ~ GPR4: 参数1 ~ 2，同时复用之，置 2 个返回值<br />
GPR5 ~ GPR10: 参数 3 ~ 8</p>
<p>e500 ABI 继承于 System V ABI PowerPC Processor Supplement</p>
<p>以较为常用的 System V ABI 为准，其他寄存器的约定如下：</p>
<p>GPR0: volatile, may be used by function linkage<br />
GPR2: reserved for system<br />
GPR11 ~ 12: volatile, may be used by function linkage<br />
GPR13: small data area pointer<br />
GPR14 ~ 31: saved</p>
<p><span style="color: #3366ff;"><strong>C. Reference</strong></span></p>
<p>[1] Book E: Enhanced PowerPC Architecture, v1.0, 2002.7<br />
[2] PowerPC e500 Core Family Reference Manual, Rev. 1, 2005.4<br />
[3] e600 PowerPC Core Reference Manual, Rev. 0, 2006.3<br />
[4] SYSTEM V APPLICATION BINARY INTERFACE PowerPC Processor Supplement (SYS V ABI), Rev. A, 1995.9<br />
[5] PowerPC Embedded Application Binary Interface (EABI), v1.0, 1995.1<br />
[6] PowerPC e500 Application Binary Interface User’s Guide, Rev. 1.0, 2003.3</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jackslab.org/?feed=rss2&#038;p=203</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
