April 20, 2014 - Assembly Language Deficit
April 20, 2014
Assembly Language Deficit
It's been a few days since my last post, but I have been wrestling with this
problem the whole time. I wanted to post, but didn't think it would be worth it
to post again about my inability to solve the same problem.
However, I have now at least identified the problem and I can successfully work
around it.
The problem is that I need to call the mmap system call in Linux to map the
framebuffer to memory so I can write to it directly. The mmap syscall has some
quirks, but the biggest problems are the lack of Linux x86_68 assembly resources
and my own lack of assembly experience.
I figured that these two problems need to be solved, so that's what I want to
write about today.
First of all, the details of the problem I encountered are as follows. The mmap
syscall requires 6 arguments, which is easier on amd64 Linux because all
arguments are passed in registers. However, I want to call it from C, which
requires either inline assembly or a function call. The function call is the
cleaner option and can be optimized to reduce overhead, but the problem is that
I would need to pass the syscall number as well, making it a 7 argument function
call. In amd64 Linux, the first 6 function arguments get passed in registers,
and the 7th gets passed on the stack. This is where my lack of
experience comes into play, I couldn't figure out how to get that argument off
the stack (I think). Either that or there was another problem with one of the
other arguments that I never found.
I'm still working on this problem. However, I found a workaround. For all 6
argument syscalls, I create an array of 64 bit wide variables and fill it with
my arguments for the syscall. Then, I pass the address of that array to the asm
code, which populates the proper registers with values from that memory block,
and finally makes the syscall.
Using this method, I got the code working without the C library. However, with
the new code, linking to the C library is no longer an option.
Now, for the other problems.
I have been searching all over the internet to learn assembly language; there
is no single source which ever has enough information. I also, do not have
enough information. However, I am continuing to learn, and as I do, I am
amassing more and more knowledge about assembly language programming for the
amd64 archetecture. I plan take all the information I have found regarding this
subject and assemble it all into a sort of reference document. I believe this
will help me in the future as I continue to struggle with problems I have
already experienced and dealt with in the past, and it should also help to be
able to look at all that I have learned as a whole, to help me put solve new
problems by having all the pieces to the puzzle stored in one location. In
addition, it should also be of use to other who want to learn 64 bit Linux asm,
which is something I want to encourage.
Anyways, that's all for now.