ld and 16bit programs

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.
Post Reply
bluecode

ld and 16bit programs

Post by bluecode »

hi,

can I link a 16bit 8086 program with ld? What output formats are possible? Is it possible to use elf file format?
I need this in order to create support for 16bit real-mode programs in my 32bit protected-mode OS.
nick8325
Member
Member
Posts: 200
Joined: Wed Oct 18, 2006 5:49 am

Re:ld and 16bit programs

Post by nick8325 »

bluecode wrote: hi,

can I link a 16bit 8086 program with ld? What output formats are possible? Is it possible to use elf file format?
I need this in order to create support for 16bit real-mode programs in my 32bit protected-mode OS.
I'm not sure if ld understands 16-bit code (I'm pretty sure it doesn't understand segmentation, though). There's dev86 (http://www.cix.co.uk/~mayday/), which includes a 16-bit assembler, linker, C compiler and libc, and is apparently used to make Linux's setup.S, but I haven't tried it myself.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:ld and 16bit programs

Post by Candy »

LD can link 16-bit programs, but I'm not entirely sure about all the details. I can tell you that it can only handle 0-based segments (so that would leave 0x0000, 0x1000 etc.), and that it freaks out when you don't use 0x0000 as base (it gives warnings about every relocation). I've used it for my boot loader, which I've moved to 0x8000 for that reason.

I don't think you really want to use it, but if you use 0-based segments it's ok I guess.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:ld and 16bit programs

Post by Pype.Clicker »

- real mode programs in your 32-bit OS ?? are you _sure_ you really want that while we now have quite complete, open-source x86 emulators that can also emulate good old graphic cards, good old soundblasters, etc ?

- using ELF for 16-bit ? no, unlikely. ELF is designed for 32-bit and 64-bit, but it doesn't even has a 'target architecture' code for 16 bits x86 ...

- the most common 16-bit format are OBJ, COM and EXE (MZ). Old compilers and multi-environment assemblers (such as NASM) support it. I use EXE-MZ for my bootloader (later converted into a flat binary by some tool of mine) and i use ALINK (http://alink.sourceforge.net/) to create that EXE file. Despite it's initially a DOS program, ALINK can be quite easily adapted to Linux (and probably other unix). All those stuff should be found in my CVS under tools/bootools and tools/asm
bluecode

Re:ld and 16bit programs

Post by bluecode »

Pype.Clicker wrote:- real mode programs in your 32-bit OS ?? are you _sure_ you really want that while we now have quite complete, open-source x86 emulators that can also emulate good old graphic cards, good old soundblasters, etc ?
I don't want to run real-mode programs, I want a VBE driver or do you guys use the protected-mode interface for that task. My OS will only allow a driver to run in vm8086.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:ld and 16bit programs

Post by Pype.Clicker »

no, virtually all of us that have VBE use vm86 for it. However, afaik, only BI has a 'real' program that has 16-bit code for that ... The most common approach (which the OSLib can help you to build) consist of
- telling VM86 "task" to start execution at the first byte of INT 0x10
- writing on the stack that the return address of that interrupt call is a 'magic address' (that usually contains a 'hlt' command), which the vm monitor interpretes as 'bios interrupt completed'
bluecode

Re:ld and 16bit programs

Post by bluecode »

I'll follow the way the great Jedi beyond infinity ;D
and use real vm86 tasks and stick with raw binaries. I don't want another executable loader in my kernel.
Post Reply