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
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

JAAman wrote:i have done that... wrote a section in ASM, then translated it into hex -- its quite fun actually, and after a while, you find patters which give incite into the instruction-set design

quite enjoyable, although quite time-consuming also...
I would prefer if it incited insight.
User avatar
crazygray
Member
Member
Posts: 73
Joined: Sat Nov 03, 2007 10:17 am
Location: Toky,Japan

Post by crazygray »

I know it would take way to long to write an entire os in Hex it's just the bootloader that I am going to write that way.
Imagine if a creature came from a 4 dimensional world, would he think you to be flat?
Tyler
Member
Member
Posts: 514
Joined: Tue Nov 07, 2006 7:37 am
Location: York, England

Post by Tyler »

Am i the only one that thinks "writing in Hex" sounds as stupid as the classic "computer's speak binary"? It's like saying you speak another language if you use a different set of symbols to represent the same alphabet.
User avatar
crazygray
Member
Member
Posts: 73
Joined: Sat Nov 03, 2007 10:17 am
Location: Toky,Japan

Post by crazygray »

It is not exactly the same, there are some instructions I haven't been able to use with an assembler. I enjoy it anyway, it's an intresting thing to do. :D
Imagine if a creature came from a 4 dimensional world, would he think you to be flat?
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

crazygray wrote:It is not exactly the same, there are some instructions I haven't been able to use with an assembler. I enjoy it anyway, it's an intresting thing to do. :D
I use GAS and have yet to find an instruction i couldnt make.
Author of COBOS
exkor
Member
Member
Posts: 111
Joined: Wed May 23, 2007 9:38 pm

Post by exkor »

there are some undocumented instructions such as SALC (Set AL on Carry).
Some asm compilers don't support long jumps, dont know how its with gas.

But the real use of hex still with self modified code or doing patches to the code(which is about the same). But it'll cost you some execution speed(Pentium4 for instance invalidates several cache(code cache) lines).
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

Most assemblers allow you to use SALC...

With GAS you can use .byte 0xd6, YASM/NASM and FASM should all support the opcode mnemonic salc..

Later versions of GAS may support the SALC mnemonic, but I'm using the version bundled with OpenBSD.

I still don't see any benefits of writing out opcodes manually though, even assembly code is barely maintainable :P
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
crazygray
Member
Member
Posts: 73
Joined: Sat Nov 03, 2007 10:17 am
Location: Toky,Japan

Post by crazygray »

I don't think there is really a benefit of writing the code in hex, but I think it is sort of a learning expirience.
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 »

I wouldn't know about gas I've never used it before.
Imagine if a creature came from a 4 dimensional world, would he think you to be flat?
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post by JAAman »

its not that there is a benefit to doing it, its simply fun! have you never done anything just because its fun?

it is also a good exercise, as i mentioned, you can learn from it as well, but the real reason to do it, is because its fun
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Post by cyr1x »

If you can remeber all the hex numbers then it should be as easy as ASM.
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post by JAAman »

not really... since there arent numbers to represent the ASM -- instead you have partial numbers, with bitfields to represent registers and methods of addressing memory -- so you dont have to memorize numbers, but patterns, and unless you are really skilled at arithmetic and binary/hex conversion in your head, you will need to do it will a calculator in your hand (or running on the computer...)

first you have a selection of override codes, then each instruction opcode can be 1,2 or 3 bytes in length (longer with certain escape codes, but those arnt common), plus some instructions will have a SIB byte, some will have a mod/rm byte, and then some will have immediate/offset/displacement data which (depending on the formation of the mod/rm & SIB bytes, and the particular instruction, can be 1, 2, 4, 6, 8, or 10 bytes -- unless there are some which require more than that...)

the overrides are easy, there are only a few of them, and they are always the same, so all you have to do is remember how they affect each instruction (some are not exactly obvious -- such as a16 affecting the size of eCX in loop instructins...)

many of the opcodes, however, contain bitfields, which must be filled in with the proper size, direction, register, etc fields, for the particular instruction

then the mod/rm byte is very complicated, with 3 bit fields, some of which change meaning based on the specific entries in other fields, and others are not permitted on specific instructions, and some instructions only use some of the fields, with the others containing instruction-specific entries -- and not all instructions have a mod/rm byte at all...

i dont have enough experience with the SIB byte to say much, but its not always there -- its presence is dependent on the specific instruction, and the entries in the mod/rm byte... and it contains more variable bitfields

then the immediate data -- this isnt present for every combination of opcode/mod/rm/SIB -- and is dependent on the specific combination of all of these to whether it is present, how large it is, how it is encoded, and what it means

in all, there are a lot of bitfields, and many contain the same information, encoded in different ways (for example, there are 2 separate bitfields for encoding segment registers -- some instructions use a 2-bit bitfield, which can only encode SS/DS/CS/ES, and others use a 3-bit bitfield which can encode SS/DS/CS/ES/FS/GS and 2 reserved combinations

so its a lot more complicated than just memorizing the opcodes...
User avatar
crazygray
Member
Member
Posts: 73
Joined: Sat Nov 03, 2007 10:17 am
Location: Toky,Japan

Post by crazygray »

so its a lot more complicated than just memorizing the opcodes...
Imagine if a creature came from a 4 dimensional world, would he think you to be flat?
Dkelly
Posts: 7
Joined: Thu Nov 08, 2007 4:56 pm

Post by Dkelly »

Brendan wrote:Hi,
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 :)

Dan K
Dkelly
Posts: 7
Joined: Thu Nov 08, 2007 4:56 pm

Post by Dkelly »

JAAman wrote:not really... since there arent numbers to represent the ASM -- instead you have partial numbers, with bitfields to represent registers and methods of addressing memory -- so you dont have to memorize numbers, but patterns, and unless you are really skilled at arithmetic and binary/hex conversion in your head, you will need to do it will a calculator in your hand (or running on the computer...)
Nice overview :)

For the most part though, when coding by hand, you just remember that xor ax,ax is 31 C0, and mov cx, (byte) is b9 (byte). The bit fields are rarely if ever thought of... in fact there are referenecs that don't even mention them, they just translate every possible permutation into their hex counterpart.

It's all rather pointless though, unless you're prone to making statements like "My dad can beat up your dad", you're better off using assember, and there's really no reason not to... I mean, Every PC that's shipped with microsoft software has shipped with an assembler.... and for the opcodes it doesn't support, then you can drop back to inserting a few dbs as above.

Dan K
Post Reply