HEX BOOT Loader

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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Post by Brendan »

Hi,
Dkelly wrote:
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.
exkor
Member
Member
Posts: 111
Joined: Wed May 23, 2007 9:38 pm

Post by exkor »

EDITED: I meant factorial here not sqrt, oh.

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))

Code: Select all

cmp number, 20 
jle    fixed_math
fpu:
fixed_math:
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.
Dkelly
Posts: 7
Joined: Thu Nov 08, 2007 4:56 pm

Post by Dkelly »

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).

Dan K
User avatar
Red Shaya
Posts: 15
Joined: Wed Oct 03, 2007 4:21 pm
Contact:

Post by Red Shaya »

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.

http://bina-os.wikidot.com
The Bina OS - More of a challenge then an OS
The Eddie OS - OS for kids and for fun loving adults
Dkelly
Posts: 7
Joined: Thu Nov 08, 2007 4:56 pm

Post by Dkelly »

Red Shaya wrote: So here is the link to my wiki in case anyone else feels crazy enough.

http://bina-os.wikidot.com
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.

Good luck :)

Dan K
User avatar
crazygray
Member
Member
Posts: 73
Joined: Sat Nov 03, 2007 10:17 am
Location: Toky,Japan

Post by crazygray »

I think I'll try that. (Was doing bootloader but decided to do the whole thing)
Imagine if a creature came from a 4 dimensional world, would he think you to be flat?
User avatar
crazygray
Member
Member
Posts: 73
Joined: Sat Nov 03, 2007 10:17 am
Location: Toky,Japan

Post by crazygray »

Well,guys I have a basic bootloader COMPLETE!
(Applaude Now)In Hex by the way.
Imagine if a creature came from a 4 dimensional world, would he think you to be flat?
Post Reply