LLVM: Compiling FreeRTOS with LLVM

It is about two more weeks before my internship at Aeste ends.

Yesterday, I finished my task of cleaning up LLVM floating points instructions and cache instructions. What I did was just hunt all these unwanted instructions inside AEMB target directory files and remove it without damaging the files or disrupt any dependencies. That was it, but I am not sure its going to be working or not.

Now, come the second part, testing the code by compiling FreeRTOS with it. You may download AEMB FreeRTOS from our git repository. The latest version of AEMB FreeRTOS, is quite different from the one originally created by Sam Ibrahiem, previous intern at Aeste, hence the wiki page might need to be updated.

By the way, lets continue with the task at hand. Now I have FreeRTOS source code and not-so-sure LLVM code. First I went to FreeRTOS code and see whats inside. It seems to have two directory called ‘demo’ and ‘FreeRTOS’. For this purpose, I’ll focus only inside demo directory. Inside it, you’ll see five files; aemb.ld, FreeRTOSConfig.h, LICENSE.txt, main.c and Makefile. That Makefile will use mb-gcc to compile the code. Then I try it:-

$ make

As a result:-

mb-gcc -Wall -mxl-barrel-shift -mno-xl-soft-mul -Os -I.. 
..
..
..
mb-objcopy -O srec freertos.o freertos.srec
mb-objdump -dSC freertos.o > freertos.S
srec_cat freertos.srec -fill 0xAE -within freertos.srec 
-range-pad 4 -o freertos.vmem -vmem 32

Which eventually will give me freertos.vmem file, a file needed to simulate it with Icarus Verilog. (I will explain how can you simulate it later in next post). So, after simulating it with Icarus Verilog, FreeRTOS was running happily I may say.

FreeRTOS
V7.0.1
Task 1
..
..
..

Task 1
Task 2 8980
Task 2 A274
Task 2 BA84
Task 2 D26F
Task 2 EA49
Task 3 60000002
Task 3 E0000006
Task 3 E0000006
Task 3 E0000006
Task 3 E0000006
Task 1
..
..
..
Task 1
Task 2 20A5C
Task 2 2233A
Task 2 23B6E
Task 2 253C3
Task 2 26C64
Task 3 E0000006..
..
..
Task 1
Task 2 38CB0
Task 2 3A5D4
Task 2 3BE7E
Task 2 3D680
Task 2 3EF03
Task 3 E000000
Task 3 E0000006
Task 1
..
..
..
Task 1
Task 2 50E3D
Task 2 52788
Task 2 53FEC
Task 2 55856
Task 2 570C0
Task 3 E0000006

*** TIMEOUT    5000050 ***

And that was it, but that obviously not what I was planning to do. It was merely to see what should I expect when using LLVM to compile that FreeRTOS.

To create a new Makefile to compile FreeRTOS with LLVM will be quite a huge task to finish in one day, so I figure, I’ll just use a tedious way to compile it for now.

$clang -pipe -O3 -isysroot /home/users/shaiful/Downloads/mblaze/ 
-I/home/users/shaiful/Downloads/mblaze/lib/gcc/microblaze-xilinx-elf/
4.1.1/include -I/home/users/shaiful/Downloads/mblaze/microblaze-xilinx
-elf/include -I../FreeRTOS/Source/include/ -I../FreeRTOS/Source/
portable/GCC/AEMB2/ -I./ -ccc-host-triple "mblaze-unknown-unknown" 
-ccc-gcc-name "mb-gcc" -S -emit-llvm -o main.ll main.c 

yes, it was a huge single command that will produce llvm code. And I convert .ll file into .bc file before asking llvm to spit out assembly .s file.

$llvm-as -o main.bc main.ll
$llc -march=aemb main.bc -o main.s

and the cruel terminal just give me this line

Segmentation Fault

Well. clearly now something somewhere is wrong with my LLVM code.

You may also like...

1 Response

  1. 2011-09-12

    […] LLVM: Compiling FreeRTOS with LLVM […]

Leave a Reply