prettify

Jan 29, 2016

mutex in armv8

Finally I am working on armv8 soc now. At the very beginning I need a mutex, which is essential for multiple core processors. The old strex/lderx on longer available, now we have ldxr/stxr instead

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dht0008a/ch01s03s02.html


get_lock PROC
mov w1, #0x1
try_loop
ldaxr w2, [x0]
cbnz w2, try_loop
stxr w2, w1, [x0]
cbnz w2, try_loop
ret
ENDP


free_lock PROC
mov w1, #0x0
stlr w1, [x0]
ret
ENDP

try_lock PROC
mov w1, #0x1
ldaxr w2, [x0]
cbnz w2, exit
stxr w2, w1, [x0]
exit
mov w0, w2
ret
ENDP

Jan 28, 2016

C++ string::split

I can understand the reason why C does not provide the string split function, but C++ is another story. A guy told me today C++ is going to add an split function, but not in C++11. It is been so late. I always have to write something like this

#include <sstream>
#include <vector>

std::vector<std::string> split(const std::string& s, const char delim){
    std::vector<std::string> res;
    std::string item;
    std:stringstream ss(s);
    while(std::getline(ss, item, delim)) {
        if(!item.empty()) res.push_back(item);
    }
    return res;
}

that's too much job from Java's split, no mention the powerful regex based split in Perl.

Assembly conditional compile for armcc

I have a bare metal code based which runs good on ARM Cortex-A7. Now I want run the same code on ARM Cortex-R5 without major change of the code, and keep the 2 projects share the same code base by compiling options.  It is easy to identify the target by defining pre-processor marcos in make file and use #ifdef for C language.

It has the similar thing for armcc. Just define flags for ARM assembler like this
--predefine "CORTEX5 SETA 1"

This option defines a marco CORTEXR5, and assign value 1 to it, In the assembly I can easily use (make sure you have tab before IF/ELSE/ENDIF)

IF CORTEXR5 == 1
nop
ELSE ;Cortex-A7
smc #0
ENDIF


An alternative way is to define the marco in assembly source file
GBLA CORTEXR5
CORTEXR5 SETA 1

I prefer the previous one since it is easier to manage thru makefile or DS-5's build configuration.