Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Brendan wrote:something as simple as inserting a few instructions into existing code would involve searching for all CALL, JMP and branch instructions and adjusting the target addresses,
Actually it doesn't... (For the most part), and whomever can tell me why, I'll believe you've hand coded machine language
There's 2 types of references - references that use absolute addresses and references that use relative addresses.
If you insert bytes into the middle of a binary, then all absolute addresses where the target is after the insertion point need to be changed, and all relative addresses which cross the insertion point (e.g. a conditional branch that jumps over the insertion point) need to be changed.
There is 2 ways to avoid this that I can think of. The first way is to put a table of target addresses at the start of the binary, so that the table is always before any insertion point, and so that you only need to change that table itself rather than searching through code. This increases overhead because you end up using indirect addressing (e.g. "call [fixedAddress]" instead of "call targetAddress") and doesn't help much with instructions that use relative addresses (e.g. there is no "Jcc [fixedAddress]" instruction).
The other way is to use large amounts of padding so that you can replace the padding instead of inserting bytes. The only disadvantage here is the increased size (and related cache efficiency and disk bandwidth problems).
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
I'll give you usefull example why knowing hex can be important:
say you got SQRT function - calculates quadratic root. It is fact that loop that calculates sqrt with fixed point math will be faster until count(# of loop passes) reaches some critilal value - say 20 passes.
You have in your sqrt function something like ('number' is sqrt(number))
on different CPUs with different MHz this '20' number will be different - you run you test program periodically changing '20' to see wthat is the best value for your target CPU and measuring the speed of the function.
You could use a register(if available) to store this 20 value but more efficient way would be to patch the code. You save your register and you only get execution penalty once when changing value.
Last edited by exkor on Tue Nov 13, 2007 8:58 am, edited 1 time in total.
Brendan wrote:
There's 2 types of references - references that use absolute addresses and references that use relative addresses.
Yeah if you're coding by hand you use relative addresses whenever possible, and you leave a few spare bytes after each ret. Seems like most jumps/branches are relative anyways. As last resort you can always jump out of the main program flow, execute however much you need, then jump back in. (a favorite trick of virus writers).
Well, finally I'm not feeling like the craziest guy on earth because I'm challenging the idea of writing an OS from scratch (i.e. no assembler .. or editor ... or ANYTHING)
By the way, I'm seeing questions about how long does it take to write an OS. In my case it seems like a lifetime
So here is the link to my wiki in case anyone else feels crazy enough.
Well, the end product sounds alot like the old <a href=http://oldcomputers.net/kim1.html>Kim-1 educational computer</a>. Cool idea to bring that up a little more modern. I'd bet your OS would be pretty valuable in educational environments. Generally now a days that sort of educational tool is probably best just simulated on a PC, but somehow doing it on real hardware makes it seem more exciting.