Email: bknpk@hotmail.com Phone: +972-54-7649119
V

 

ASIC/FPGA Design and Verification Out Source Services

ARM c (or assembly) code to VERILOG readmemhex format



  1. In this document I show how to generate code for ARM processor and use it in VHDL or VERILOG simulation.
  2. The flow is from C code or assembly into VERILOG READMEMHEX format.
  3. 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:
  4. 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");
    }

  5. 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:
  6. arm-elf-gcc -c ../a.c
  7. 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:
  8. 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.



  9. 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.
  10. e1a0c00d // mov ip, sp
    e92dd800 // stmdb sp!, {fp, ip, lr, pc}
    ...
  11. The command to generate this report:
  12. arm-elf-objdump -D a.o

  13. 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
  14. A simple assembly code is shown it the following link. simple assembly code
  15. Please let me know what you think on my site.

     
    


    Contact me now at:

  ...


Home

how to run regression

A simple c-code program to read a memory array from verilog RTL, using VPI.






Search This Site


Feedback This Site




new pages on this site