Manually creating an ELF executable
negrebskoh.net
negrebskoh.net
Relatedly, I wrote a tiny quasi-Forth in itself that generates ELF executables directly at https://github.com/kragen/stoneknifeforth. Its executables also stopped running around Linux 2.6.27, and I still haven't bothered to figure out why.
Feel free to email me if you notice any of the teensy executables not working. I don't follow the bleeding edge very closely, but I do make a serious effort to keep all of them working.
~$ file a.out
a.out: ELF 32-bit invalid byte order (SYSV)
But that's probably to be expected, given how close to the edges of the ELF spec it treads :)Edit: Hmm, apparently not — I must be cutting a corner of the ELF spec that teensy isn't, since teensy works for me too. I'm on 3.2.0-35 here.
The project you've worked on looks interesting, too! It's a little late for me to be reading too much code, but I'll make sure to take a good look at it tomorrow. Thanks for the link.
The obvious first step to reporting the bug (after looking at diffs, which I did try) would be to instrument the ELF loading code with printk calls to explain why it's failing to exec a supposedly ELF executable, so that I could report what it was about the executable it was that made the kernel barf. And then I could fix the executable. I just haven't gotten around to recompiling my kernel with a modified ELF loader.
What does nullify the backwards-compatibility rule is no-one noticing or caring that it has changed.
I believe that one of the reasons the Arduino has the appeal it does is because you can know everything there is to know about the program it is running. That is a lot of fun for a technologist.
It would be fun to have this blog posting written from within a debugger. I always found it intriguing to 'debug a program into existence' as it were.
Now, if only somebody would make a ring-0 OS for ARM... Now THAT would be fun.
http://www.ocp.inf.ethz.ch/wiki/
Not sure how workable this version is, but you can check on the forums,
ftp://ftp.lrz.de/transfer/BlueBottle-A2/ARMRelease.zip
You just need to enjoy using Pascal syntax languages for system programming.
This is so fascinating I'm starting to get palpitations. I've always wanted to know how to program in machine code. I've looked through the web countless times in search of something like this, and haven't ever found it, until now.
Thanks for the great insight. This kind of stuff makes C/C++ look like stuff for total newbies. Getting this close to the hardware really is quite mind-boggling.
1) Decide which processor you want to program. I'm going to use a Z80, since that's one I'm familiar with.
2) Get hold of a good book, making sure it includes a section that exhaustively describes each instruction and the machine code for each. Eg. "Programming the Z80" by Rodnay Zaks. The microprocessor's datasheet will generally do if your familiar with other processors.
3) Read the book, cover to cover.
4) Make three vertical columns on a sheet of paper.
5) Write your program, in assembly language, in the middle column. Use alphanumeric labels (label means variable name) for all addresses.
6) Decide at what address you want your program to start (the origin)
7) Write the numeric address in the left hand column, next to the first instruction.
8) Look up the machine code, for the instruction in the middle column, in the Zaks book.
9) Write the machine code in the right hand column.
10) Add the length of the instruction (# bytes) that you have just written down to the address, and write the answer on the next row of the left hand column. You might have to leave labels in place for instructions that refer to parts of the program that you have not yet assembled.
11) Repeat from step 8, until the entire program has been assembled.
12) Go back and fill in the numerical addresses for any addresses that are still labels.
13) Now you have to get the program in memory. We're going to assume that a programming language, such as BASIC is available. The alternative is a keypad with address/data entry functions and a method to get an initial value into the program counter.
14) Create a big array, in BASIC, with all the numbers from the right hand column.
15) Write a loop which POKES each numeric value into memory, starting from the origin address.
16) Transfer execution to the origin address, using the a USR(nnnn) instruction, where nnnn is the origin address.
17) Hopefully your program works, but if not, make changes and go back to step 4 until your program works.
Enjoy! In time, the process gets quicker, as you eventually remember the machine code for the the most common instructions and don't have to refer to the book.
If you're writing timing critical code, have a fourth column, in which you record the number of clock cycles for each instruction to execute, and sum those numbers to determine execution time. If you have a target execution time, you will need to add/remove instructions to achieve the target.
Also, that Zaks book rocks. To this day one of the best programming references I've ever used. http://www.z80.info/zaks.html
In high school, I would print out 2 pages of all the Z80 opcodes and put them on my desk during class. The calculators let you directly input hex and then run your program with asm(), so I would write my program by hand on paper, and then next to each line translate it to machine code and put it into the calculator. A lot of TI routines are easily accessible with bcalls, so you don't have to reinvent the wheel with each program.
Plus Z80 is a lot easier than x86. (I still remember the return code: C9)
I had a lot of fun taking friend's calculators and disabling the LCD and power button in assembly :)
http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm...
Manually picking out hex opcodes is maybe a bit over the top. A nice assembler like nasm should be "low level enough" while still providing a lot more convenience and flexibility.
Asm, at least for me, is still too low-level for me to do any sort of serious work. I make desktop/mobile apps, and don't really do any sort of kernel hacking, so currently, I'll stick with C++ and Java. It is a nice thing to know, however, I don't see myself learning it right now. It's inevitable that I'll have to learn it sometime in the future if I ever want to broaden my prospects, but it's nice to play around with, but isn't all too useful for me.
That is the first lesson you have in assembly language: program in assembly language, then in C because it spares you the time (and the mistakes involved in the process) to do such a thing.
Thousands of men year efforts and wisdom ruined in a post, showing how people have too much time on their hands, and so few imaginations (well he could have written something interesting on how to display p0rn pictures in ASCII art at least).
You won't ever do this in the Real World (TM), but it's a fantastic way to get into things.
What do you learn in Computer Science then?!
Gibbering useless concepts that makes you non-sensical experts in the field of not delivering your software neither in time, nor in the frame of the specification? Or just
If you see nothing but a huge waste of time in this post, you're probably on the wrong site. HN in its prime would have really pissed you off, no doubt...