04-13-2016, 06:54 AM
(This post was last modified: 04-13-2016, 02:40 PM by MichaelMeissner.)
Well, it depends on what you mean.
Bear in mind, the normal way pine64 is run is you are running an operating system (written in C with some assembly thrown in, perhaps in C++) kernel that runs programs on demand. Could you replace the operating system with something you wrote from scratch? You could, but it might take person-years if not person-decades to get all of the interfaces correct. I suspect by the time you finish, this version of the pine64 will have been replaced by the next generations. If you have not programmed in assembly before, it may be too complex to do anything but simple toy programs.
If you really want to do this, perhaps using a different ARM board that is setup to download code from a host, and has debug support via JTAG or other means built-in would be simpler than using a system setup to run a normal OS. Note, even in this arena it is extremely rare that the whole system is written in assembly. Normally only bits and pieces are written in assembly, and everything else is written in higher level languages like C/C++ (and yeah, I know C is not particularly high level compared to other languages, but it still is a lot higher than assembly language).
Ok, maybe writing a complete OS isn't your cup of tea, could you write a Linux/Android program completely in assembly language? Sure. Not only would you have to learn the ARM assembly language, you would have to replicate the whole interface between the operating system, and the programs that is normally handled by the standard libraries. This is doable, but it is perhaps a bit of work tracking down all of the interface details. This might be 1-2 person-weeks worth of effort if you are already familiar with ARM assembly and just need to figure out the details on the pine64 system, or it might be several person-months of effort if you have not have programmed in assembly before (as it appears from your question).
Now, if you just wanted to learn ARM assembly, and are willing to use the standard libraries, then it is possible, and in fact is probably the simplest method to learn assembly. First write a program in C, and compile it with gcc -O2 -S foo.c, and it will provide a foo.s file. Hack on this to your hearts content, using gcc -o foo.exe foo.s to build it, and then run foo.ex (or whatever name you call it). You can use the debugger (gdb) to place breakpoints at locations, you can single step at the instruction level, and look at registers. You will need to figure out the application binary interface (ABI) to learn what the conventions for the stack layout, what registers are used for passing/return parameters, what registers are preserved across calls, etc.
You can also write assembly code that is a function called from C/C++, rather than the whole program.
You can also use GCC's inline assembly feature (https://gcc.gnu.org/onlinedocs/gcc-5.3.0...age-with-C).
Bear in mind, the normal way pine64 is run is you are running an operating system (written in C with some assembly thrown in, perhaps in C++) kernel that runs programs on demand. Could you replace the operating system with something you wrote from scratch? You could, but it might take person-years if not person-decades to get all of the interfaces correct. I suspect by the time you finish, this version of the pine64 will have been replaced by the next generations. If you have not programmed in assembly before, it may be too complex to do anything but simple toy programs.
If you really want to do this, perhaps using a different ARM board that is setup to download code from a host, and has debug support via JTAG or other means built-in would be simpler than using a system setup to run a normal OS. Note, even in this arena it is extremely rare that the whole system is written in assembly. Normally only bits and pieces are written in assembly, and everything else is written in higher level languages like C/C++ (and yeah, I know C is not particularly high level compared to other languages, but it still is a lot higher than assembly language).
Ok, maybe writing a complete OS isn't your cup of tea, could you write a Linux/Android program completely in assembly language? Sure. Not only would you have to learn the ARM assembly language, you would have to replicate the whole interface between the operating system, and the programs that is normally handled by the standard libraries. This is doable, but it is perhaps a bit of work tracking down all of the interface details. This might be 1-2 person-weeks worth of effort if you are already familiar with ARM assembly and just need to figure out the details on the pine64 system, or it might be several person-months of effort if you have not have programmed in assembly before (as it appears from your question).
Now, if you just wanted to learn ARM assembly, and are willing to use the standard libraries, then it is possible, and in fact is probably the simplest method to learn assembly. First write a program in C, and compile it with gcc -O2 -S foo.c, and it will provide a foo.s file. Hack on this to your hearts content, using gcc -o foo.exe foo.s to build it, and then run foo.ex (or whatever name you call it). You can use the debugger (gdb) to place breakpoints at locations, you can single step at the instruction level, and look at registers. You will need to figure out the application binary interface (ABI) to learn what the conventions for the stack layout, what registers are used for passing/return parameters, what registers are preserved across calls, etc.
You can also write assembly code that is a function called from C/C++, rather than the whole program.
You can also use GCC's inline assembly feature (https://gcc.gnu.org/onlinedocs/gcc-5.3.0...age-with-C).