Getting Started » History » Version 3
Sergey Smolov, 07/10/2018 07:08 PM
1 | 1 | Sergey Smolov | h1. Getting Started |
---|---|---|---|
2 | |||
3 | {{toc}} |
||
4 | |||
5 | 3 | Sergey Smolov | h2. General notes |
6 | |||
7 | It is possible to terminate QEMU by hands only. Neither Ctrl-C nor Ctrl-Z works, use _kill <process-id>_ or _killall qemu-system*_. |
||
8 | |||
9 | 1 | Sergey Smolov | h2. Aarch64 |
10 | |||
11 | It is supposed that the following tools are successfully installed in your system: |
||
12 | - 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). |
||
13 | |||
14 | 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: |
15 | 1 | Sergey Smolov | <pre> |
16 | .text |
||
17 | .globl _start |
||
18 | bl _start |
||
19 | _start: |
||
20 | movz x1, #0x10, LSL #0 |
||
21 | hlt #57005 |
||
22 | </pre> |
||
23 | 3 | Sergey Smolov | # To compile the Aarch64 assembler program, do the following: |
24 | 1 | Sergey Smolov | <pre> |
25 | aarch64-linux-gnu-as sample.s -o sample.o |
||
26 | aarch64-linux-gnu-ld sample.o -o sample.elf |
||
27 | aarch64-linux-gnu-objcopy -O binary sample.elf sample.bin |
||
28 | </pre> |
||
29 | # Finally, run _QEMU4V_ emulator with enabled option of microprocessor execution trace logging: |
||
30 | <pre> |
||
31 | qemu-system-aarch64 -M virt -cpu cortex-a57 -bios sample.bin -d nochain,in_asm -singlestep -nographic -trace-log -D log-file.txt |
||
32 | </pre> |
||
33 | 3 | Sergey Smolov | # Wait for a while, then stop QEMU. The following @log-file.txt@ trace file should be generated: |
34 | 1 | Sergey Smolov | <pre> |
35 | 0 clk IT (0) 0000000000000000 94000001 A svc_ns : bl #+0x4 (addr 0x4) |
||
36 | 1 clk IT (1) 0000000000000004 d2800201 A svc_ns : movz x1, #0x10, LSL #0 |
||
37 | 2 clk IT (2) 0000000000000008 d45bd5a0 A svc_ns : hlt #57005 |
||
38 | </pre> |
||
39 | |||
40 | 3 | Sergey Smolov | h2. MIPS |
41 | |||
42 | It is supposed that the following tools are successfully installed in your system: |
||
43 | - Toolchain for MIPS assembler programs compilation, linking, etc. (a list of toolchains is available "here":https://www.linux-mips.org/wiki/Toolchains). |
||
44 | |||
45 | # 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: |
||
46 | <pre> |
||
47 | .text |
||
48 | .globl _start |
||
49 | _start: |
||
50 | lui $1, 0x1234 |
||
51 | ori $1, $1, 0x5678 |
||
52 | addi $8, $0, 10 |
||
53 | sw $8, 0($1) |
||
54 | </pre> |
||
55 | # To compile the MIPS assembler program, do the following: |
||
56 | <pre> |
||
57 | mips-linux-gnu-as sample.s -o sample.o |
||
58 | mips-linux-gnu-ld sample.o -Ttext 0xbfc00000 -o sample.elf |
||
59 | </pre> |
||
60 | # Finally, run _QEMU4V_ emulator: |
||
61 | <pre> |
||
62 | qemu-system-mips -M mips -cpu mips32r6-generic -d unimp,nochain,in_asm -nographic -singlestep -D log.txt -bios sample.elf |
||
63 | </pre> |
||
64 | # Wait for a while, then stop QEMU. The following @log-file.txt@ trace file should be generated: |
||
65 | <pre> |
||
66 | ... |
||
67 | ---------------- |
||
68 | IN: |
||
69 | 0xbfc0fffc: nop |
||
70 | |||
71 | ---------------- |
||
72 | IN: |
||
73 | 0xbfc10000: lui at,0x1234 |
||
74 | |||
75 | ---------------- |
||
76 | IN: |
||
77 | 0xbfc10004: ori at,at,0x5678 |
||
78 | |||
79 | ---------------- |
||
80 | IN: |
||
81 | 0xbfc10008: beqzalc zero,t0,0xbfc10034 |
||
82 | |||
83 | ---------------- |
||
84 | IN: |
||
85 | 0xbfc10034: cache 0x0,0(s8) |
||
86 | </pre> |
||
87 | |||
88 | 1 | Sergey Smolov | h2. RISC-V |
89 | |||
90 | It is supposed that the following tools are successfully installed in your system: |
||
91 | - 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). |
||
92 | |||
93 | 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: |
94 | 1 | Sergey Smolov | <pre> |
95 | .text |
||
96 | .globl _start |
||
97 | _start: |
||
98 | addi t1, zero, 0x18 |
||
99 | addi t2, zero, 0x21 |
||
100 | </pre> |
||
101 | 3 | Sergey Smolov | # To compile the RISC-V assembler program, do the following: |
102 | 1 | Sergey Smolov | <pre> |
103 | aarch64-linux-gnu-as sample.s -o sample.o |
||
104 | aarch64-linux-gnu-ld sample.o -Ttext 0x1000 -o sample.elf |
||
105 | </pre> |
||
106 | # Finally, run _QEMU4V_ emulator with enabled option of microprocessor execution trace logging (0x1000 value was used by linker because of QEMU-related features): |
||
107 | <pre> |
||
108 | 2 | Sergey Smolov | qemu-system-riscv64 -M spike_v1.10 -cpu any -d unimp,nochain,in_asm -nographic -singlestep -trace-log -kernel sample.elf |
109 | 1 | Sergey Smolov | </pre> |
110 | 3 | Sergey Smolov | # Wait for a while, then stop QEMU. The following trace should be generated: |
111 | 1 | Sergey Smolov | <pre> |
112 | 0 clk 0 IT (0) 0000000000001000 01800313 A svc_ns : li t1,24 |
||
113 | 1 clk R t1 0000000000000018 |
||
114 | 1 clk 0 IT (1) 0000000000001004 02100393 A svc_ns : li t2,33 |
||
115 | 2 clk R t2 0000000000000021 |
||
116 | 2 clk 0 IT (2) 0000000000001008 00000000 A svc_ns : unimp |
||
117 | 3 clk 0 IT (3) 0000000000001010 00000000 A svc_ns : unimp |
||
118 | 3 | Sergey Smolov | </pre> |
119 | |||
120 | h2. X86 |
||
121 | |||
122 | It is supposed that the following tools are successfully installed in your system: |
||
123 | - Toolchain for X86 assembler programs compilation, linking, etc. (we use "GCC":https://gcc.gnu.org/). |
||
124 | |||
125 | # First of all, let's write a simple X86 program (it is called @sample.s@) that performs some calculations: |
||
126 | <pre> |
||
127 | .text |
||
128 | .globl _start |
||
129 | _start: |
||
130 | movl -8(%ebp, %edx, 4), %eax |
||
131 | movl -4(%ebp), %eax |
||
132 | movl (%ecx), %edx |
||
133 | ret |
||
134 | </pre> |
||
135 | # To compile the X86 GNU assembler program, do the following: |
||
136 | <pre> |
||
137 | x86_64-linux-gnu-as sample.s -o sample.o |
||
138 | x86_64-linux-gnu-ld sample.o -o sample.elf |
||
139 | </pre> |
||
140 | # Finally, run _QEMU4V_ emulator: |
||
141 | <pre> |
||
142 | qemu-system-i386 -M pc -cpu 486 -d unimp,nochain,in_asm -nographic -singlestep -D log.txt -bios sample.elf |
||
143 | </pre> |
||
144 | # Wait for a while, then stop QEMU. The following @log-file.txt@ trace file should be generated: |
||
145 | <pre> |
||
146 | // TODO: generate log |
||
147 | 1 | Sergey Smolov | </pre> |