Getting Started » History » Version 14
Maxim Chudnov, 11/13/2018 04:23 PM
1 | 1 | Sergey Smolov | h1. Getting Started |
---|---|---|---|
2 | |||
3 | {{toc}} |
||
4 | |||
5 | 3 | Sergey Smolov | h2. General notes |
6 | |||
7 | 12 | Sergey Smolov | First of all, install the QEMU4V (follow the "instruction":https://forge.ispras.ru/projects/qemu4v/wiki/Installation). |
8 | 8 | Sergey Smolov | |
9 | 3 | Sergey Smolov | It is possible to terminate QEMU by hands only. Neither Ctrl-C nor Ctrl-Z works, use _kill <process-id>_ or _killall qemu-system*_. |
10 | |||
11 | 1 | Sergey Smolov | h2. Aarch64 |
12 | |||
13 | 5 | Sergey Smolov | It is supposed that the following tools are already installed in your system: |
14 | 1 | Sergey Smolov | - Toolchain for Aarch64 assembler programs compilation, linking, etc. (can be downloaded from "Linaro website":http://releases.linaro.org/components/toolchain/binaries or just below, installation instruction is "here":http://forge.ispras.ru/projects/microtesk-armv8/wiki/Toolchain). |
15 | |||
16 | 3 | Sergey Smolov | # Write a simple Aarch64 program (it is called @sample.s@) that does nothing but puts 0x10 value to X0 register and then halts. Here it is: |
17 | 1 | Sergey Smolov | <pre> |
18 | .text |
||
19 | .globl _start |
||
20 | bl _start |
||
21 | _start: |
||
22 | movz x1, #0x10, LSL #0 |
||
23 | hlt #57005 |
||
24 | </pre> |
||
25 | 3 | Sergey Smolov | # To compile the Aarch64 assembler program, do the following: |
26 | 1 | Sergey Smolov | <pre> |
27 | aarch64-linux-gnu-as sample.s -o sample.o |
||
28 | aarch64-linux-gnu-ld sample.o -o sample.elf |
||
29 | aarch64-linux-gnu-objcopy -O binary sample.elf sample.bin |
||
30 | </pre> |
||
31 | # Finally, run _QEMU4V_ emulator with enabled option of microprocessor execution trace logging: |
||
32 | <pre> |
||
33 | qemu-system-aarch64 -M virt -cpu cortex-a57 -bios sample.bin -d nochain,in_asm -singlestep -nographic -trace-log -D log-file.txt |
||
34 | </pre> |
||
35 | 6 | Sergey Smolov | # Wait for a while, then stop QEMU4V. The following @log-file.txt@ trace file should be generated: |
36 | 1 | Sergey Smolov | <pre> |
37 | 0 clk IT (0) 0000000000000000 94000001 A svc_ns : bl #+0x4 (addr 0x4) |
||
38 | 1 clk IT (1) 0000000000000004 d2800201 A svc_ns : movz x1, #0x10, LSL #0 |
||
39 | 2 clk IT (2) 0000000000000008 d45bd5a0 A svc_ns : hlt #57005 |
||
40 | </pre> |
||
41 | |||
42 | 4 | Sergey Smolov | h2. MIPS32 |
43 | 3 | Sergey Smolov | |
44 | 5 | Sergey Smolov | It is supposed that the following tools are already installed in your system: |
45 | 3 | Sergey Smolov | - Toolchain for MIPS assembler programs compilation, linking, etc. (a list of toolchains is available "here":https://www.linux-mips.org/wiki/Toolchains). |
46 | |||
47 | # First of all, let's write a simple MIPS program (it is called @sample.s@) that stores 0x10 value at x12345678 address. Here it is: |
||
48 | <pre> |
||
49 | .text |
||
50 | .globl _start |
||
51 | _start: |
||
52 | lui $1, 0x1234 |
||
53 | ori $1, $1, 0x5678 |
||
54 | addi $8, $0, 10 |
||
55 | sw $8, 0($1) |
||
56 | </pre> |
||
57 | 6 | Sergey Smolov | # To compile the MIPS32 assembler program, do the following: |
58 | 3 | Sergey Smolov | <pre> |
59 | mips-linux-gnu-as sample.s -o sample.o |
||
60 | mips-linux-gnu-ld sample.o -Ttext 0xbfc00000 -o sample.elf |
||
61 | </pre> |
||
62 | # Finally, run _QEMU4V_ emulator: |
||
63 | <pre> |
||
64 | qemu-system-mips -M mips -cpu mips32r6-generic -d unimp,nochain,in_asm -nographic -singlestep -D log.txt -bios sample.elf |
||
65 | </pre> |
||
66 | 6 | Sergey Smolov | # Wait for a while, then stop QEMU4V. The following @log-file.txt@ trace file should be generated: |
67 | 3 | Sergey Smolov | <pre> |
68 | ... |
||
69 | ---------------- |
||
70 | IN: |
||
71 | 0xbfc0fffc: nop |
||
72 | |||
73 | ---------------- |
||
74 | IN: |
||
75 | 0xbfc10000: lui at,0x1234 |
||
76 | |||
77 | ---------------- |
||
78 | IN: |
||
79 | 0xbfc10004: ori at,at,0x5678 |
||
80 | |||
81 | ---------------- |
||
82 | IN: |
||
83 | 0xbfc10008: beqzalc zero,t0,0xbfc10034 |
||
84 | |||
85 | ---------------- |
||
86 | IN: |
||
87 | 0xbfc10034: cache 0x0,0(s8) |
||
88 | </pre> |
||
89 | |||
90 | 11 | Sergey Smolov | h2. PowerPC32 |
91 | 9 | Sergey Smolov | |
92 | 10 | Maxim Chudnov | # Write a simple PowerPC program (it is called @p1.s@). Here it is: |
93 | <pre> |
||
94 | .section .text |
||
95 | addi 4,0,5 # bad |
||
96 | la 3,3(0) # very bad |
||
97 | la 3,0(3) |
||
98 | la 5,2500(3) |
||
99 | </pre> |
||
100 | # To compile the PowerPC assembler program, do the following: |
||
101 | <pre> |
||
102 | powerpc-linux-gnu-as p1.s -o p1.o |
||
103 | 13 | Maxim Chudnov | powerpc-linux-gnu-ld p1.o -Ttext 0x1000 -o p1.elf |
104 | 10 | Maxim Chudnov | </pre> |
105 | 14 | Maxim Chudnov | # Finally, run _QEMU4V_ emulator : |
106 | <pre> |
||
107 | qemu-system-ppc -M ppce500 -cpu e500 -d unimp,nochain,in_asm -nographic -singlestep -bios p1.elf |
||
108 | </pre> |
||
109 | # Wait for a while, then stop QEMU4V. The following trace should be generated: |
||
110 | <pre> |
||
111 | IN: |
||
112 | 0x00000000: li r4,5 |
||
113 | |||
114 | IN: |
||
115 | 0x00000004: li r3,3 |
||
116 | |||
117 | IN: |
||
118 | 0x00000008: addi r3,r3,0 |
||
119 | |||
120 | IN: |
||
121 | 0x0000000c: addi r5,r3,2500 |
||
122 | |||
123 | </pre> |
||
124 | 9 | Sergey Smolov | |
125 | 1 | Sergey Smolov | h2. RISC-V |
126 | |||
127 | 5 | Sergey Smolov | It is supposed that the following tools are already installed in your system: |
128 | 1 | Sergey Smolov | - Toolchain for RISC-V assembler programs compilation, linking, etc. (the source code and the installation guide are available "here":https://github.com/riscv/riscv-gnu-toolchain). |
129 | |||
130 | 3 | Sergey Smolov | # Write a simple RISC-V program (it is called @sample.s@) that does nothing but puts 0x18 value to @t1@ register and puts 0x21 value to @t2@ register. Here it is: |
131 | 1 | Sergey Smolov | <pre> |
132 | .text |
||
133 | .globl _start |
||
134 | _start: |
||
135 | addi t1, zero, 0x18 |
||
136 | addi t2, zero, 0x21 |
||
137 | </pre> |
||
138 | 3 | Sergey Smolov | # To compile the RISC-V assembler program, do the following: |
139 | 1 | Sergey Smolov | <pre> |
140 | aarch64-linux-gnu-as sample.s -o sample.o |
||
141 | aarch64-linux-gnu-ld sample.o -Ttext 0x1000 -o sample.elf |
||
142 | </pre> |
||
143 | # Finally, run _QEMU4V_ emulator with enabled option of microprocessor execution trace logging (0x1000 value was used by linker because of QEMU-related features): |
||
144 | <pre> |
||
145 | 2 | Sergey Smolov | qemu-system-riscv64 -M spike_v1.10 -cpu any -d unimp,nochain,in_asm -nographic -singlestep -trace-log -kernel sample.elf |
146 | 1 | Sergey Smolov | </pre> |
147 | 6 | Sergey Smolov | # Wait for a while, then stop QEMU4V. The following trace should be generated: |
148 | 1 | Sergey Smolov | <pre> |
149 | 0 clk 0 IT (0) 0000000000001000 01800313 A svc_ns : li t1,24 |
||
150 | 1 clk R t1 0000000000000018 |
||
151 | 1 clk 0 IT (1) 0000000000001004 02100393 A svc_ns : li t2,33 |
||
152 | 2 clk R t2 0000000000000021 |
||
153 | 2 clk 0 IT (2) 0000000000001008 00000000 A svc_ns : unimp |
||
154 | 3 clk 0 IT (3) 0000000000001010 00000000 A svc_ns : unimp |
||
155 | 3 | Sergey Smolov | </pre> |
156 | |||
157 | 7 | Sergey Smolov | h2. X86 (8086 case) |
158 | 3 | Sergey Smolov | |
159 | 5 | Sergey Smolov | It is supposed that the following tools are already installed in your system: |
160 | 7 | Sergey Smolov | - Toolchain for X86 assembler programs compilation, linking, etc. (we use "GCC":https://gcc.gnu.org). |
161 | 1 | Sergey Smolov | |
162 | 7 | Sergey Smolov | # Write a simple X86 program (it is called @sample.s@) that performs some calculations: |
163 | 1 | Sergey Smolov | <pre> |
164 | 7 | Sergey Smolov | .code16 # tell the assembler that we're using 16 bit mode |
165 | .text |
||
166 | .global _start |
||
167 | 3 | Sergey Smolov | _start: |
168 | 7 | Sergey Smolov | mov $11, %AX |
169 | and $204, %BX |
||
170 | mov %AX, %CX |
||
171 | add %CX, %BX |
||
172 | sub %CX, %AX |
||
173 | .org 510 # magic bytes that tell BIOS that this is bootable |
||
174 | .word 0xaa55 # magic bytes that tell BIOS that this is bootable |
||
175 | 1 | Sergey Smolov | </pre> |
176 | # To compile the X86 GNU assembler program, do the following: |
||
177 | <pre> |
||
178 | x86_64-linux-gnu-as sample.s -o sample.o |
||
179 | 7 | Sergey Smolov | x86_64-linux-gnu-ld sample.o -T 0x7c00 --oformat binary -o sample.elf |
180 | 1 | Sergey Smolov | </pre> |
181 | # Finally, run _QEMU4V_ emulator: |
||
182 | <pre> |
||
183 | 7 | Sergey Smolov | qemu-system-i386 -M pc -cpu 486 -d unimp,nochain,in_asm -nographic -singlestep -D log.txt -hda sample.elf |
184 | 1 | Sergey Smolov | </pre> |
185 | 7 | Sergey Smolov | # Wait for a while, then stop QEMU4V. The following @log-file.txt@ trace file should be generated (go to the 0x7c00 address and see the program execution fragment): |
186 | 1 | Sergey Smolov | <pre> |
187 | 7 | Sergey Smolov | ---------------- |
188 | IN: |
||
189 | 0x00007c00: mov $0xb,%ax |
||
190 | |||
191 | ---------------- |
||
192 | IN: |
||
193 | 0x00007c03: and $0xcc,%bx |
||
194 | |||
195 | ---------------- |
||
196 | IN: |
||
197 | 0x00007c07: mov %ax,%cx |
||
198 | |||
199 | ---------------- |
||
200 | IN: |
||
201 | 0x00007c09: add %cx,%bx |
||
202 | |||
203 | ---------------- |
||
204 | IN: |
||
205 | 0x00007c0b: sub %cx,%ax |
||
206 | |||
207 | ---------------- |
||
208 | 1 | Sergey Smolov | </pre> |