ASIC/FPGA Design and Verification Out Source Services
ARM c (or assembly) code to VERILOG readmemhex format
- In this document I show how to generate code for ARM processor and use it in VHDL or VERILOG simulation.
- The flow is from C code or assembly into VERILOG READMEMHEX format.
- First you need to write a program in C or assembly. This program is later run in simulation on an ARM sub-system. An example for such a c program is shown below:
int main(void) {
char *p;
char *c;
char c1;
asm volatile ("nop");
asm volatile ("nop");
asm volatile ("nop");
asm volatile ("mov r0, r0");
*(char *)0x12345670=0;
asm volatile ("nop");
asm volatile ("nop");
}
- Next step is to compile the program. Note: only the object is required and the final elf is not needed. To do that you need to enter the following command:
arm-elf-gcc -c ../a.c
- The next step is to convert the object output file, namely a.o, to a readable ASCII text file. Readable means a file that is easily manipulated by a PERL script. Such an example follows:
a.o: file format elf32-littlearm
Disassembly of section .text:
00000000 :
0: e1a0c00d mov ip, sp
4: e92dd800 stmdb sp!, {fp, ip, lr, pc}
8: e24cb004 sub fp, ip, #4 ; 0x4
c: e24dd00c sub sp, sp, #12 ; 0xc
10: e1a00000 nop (mov r0,r0)
14: e1a00000 nop (mov r0,r0)
18: e1a00000 nop (mov r0,r0)
1c: e1a00000 nop (mov r0,r0)
20: e59f2018 ldr r2, [pc, #24] ; 40 <.text+0x40>
24: e3a03000 mov r3, #0 ; 0x0
28: e5c23000 strb r3, [r2]
2c: e1a00000 nop (mov r0,r0)
30: e1a00000 nop (mov r0,r0)
34: e1a00003 mov r0, r3
38: e24bd00c sub sp, fp, #12 ; 0xc
3c: e89da800 ldmia sp, {fp, sp, pc}
40: 12345670 eornes r5, r4, #117440512 ; 0x7000000
Disassembly of section .comment:
00000000 <.comment>:
0: 43434700 cmpmi r3, #0 ; 0x0
4: 4728203a undefined
8: 2029554e eorcs r5, r9, lr, asr #10
c: 2e342e33 mrccs 14, 1, r2, cr4, cr3, {1}
10: Address 0x10 is out of bounds.
- All that is required is to extract the hex data followed by a comment containing the assembly code, which shown below. The latter is for debug purposes only.
e1a0c00d // mov ip, sp
e92dd800 // stmdb sp!, {fp, ip, lr, pc}
...
- The command to generate this report:
arm-elf-objdump -D a.o
- An example for a PERL script that extracts the data and creates file for simulation in verilog readmemh format is in the following link: perl script
- A simple assembly code is shown it the following link. simple assembly code
Please let me know what you think on my site.
Contact me now at: |