OSDev.org

The Place to Start for Operating System Developers
It is currently Sun Apr 20, 2014 12:38 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: gcc 16bit
PostPosted: Fri Jun 08, 2007 5:46 am 
Offline
Member
Member
User avatar

Joined: Fri Sep 29, 2006 8:59 am
Posts: 390
Hi...
I'm using DJGPP to write my kernel,
does any one know how to create a 16 bit code with gcc,
there is wrong with http://www.delorie.com it doesn't open.


Top
 Profile  
 
 Post subject: Re: gcc 16bit
PostPosted: Fri Jun 08, 2007 7:32 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2526
Location: Devon, UK
abuashraf wrote:
there is wrong with http://www.delorie.com it doesn't open.


Works ok for me. If you want to navigate directly, try http://www.delorie.com/djgpp/ .


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 8:07 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 27, 2004 11:00 pm
Posts: 730
Location: CA
one note: while GCC can produce 16bit code, it is not true 16bit code, and may not work properly in RMode/VMode and certainly wont work on a 8086/8

all it does is prefix all 32bit references with an override (and removes prefixes from 16bit references), this makes it suitable for use in a 16bit PMode segment, but may or may not work in RMode (and definitely wont work if you must use different segments -- GCC assumes DS.base=SS.base=ES.base, and if you need more than one data segment, it may not work properly)

i dont know what you want to use it for, but this is something important to keep in mind

_________________
## ---- ----- ------ Intel Manuals
OSdev wiki


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 8:48 am 
Offline
Member
Member
User avatar

Joined: Thu Apr 05, 2007 6:07 am
Posts: 214
wayttd?
http://freshmeat.net/projects/bin86/
16-bit code in GAS: objdump --disassemble -mi8086


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 9:28 am 
Offline
Member
Member
User avatar

Joined: Fri Sep 29, 2006 8:59 am
Posts: 390
Hi...

Quote:
i dont know what you want to use it for


I need it for my virtual task,virtul mode doesn't accept 32bit,
and It gives gpf,so would some one please give me a simple example
on how to create 16bit code using GCC,or any link speaks about that.

Quote:
Works ok for me. If you want to navigate directly, try http://www.delorie.com/djgpp/ .


It didn't work again...I don't know maybe the wrong comes form my server.

Thanx.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 12:15 pm 
Offline
Member
Member

Joined: Thu Jul 07, 2005 11:00 pm
Posts: 1544
try http://207.22.48.162 your DNS server might be stupid and not work on certain websites..I use to have that problem, you can fix it by setting your DNS server to 216.231.41.2
that is a very good free DNS server(it's what I use)


I saw a GCC based 16bit compiler..it didn't support segments iirc, but it didn't use 32bit opcodes..


edited...

_________________
My new NEW blag


Last edited by earlz on Fri Jun 08, 2007 1:54 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 1:42 pm 
Offline
Member
Member

Joined: Mon Apr 09, 2007 12:10 pm
Posts: 586
Location: London, UK
I think, although I haven't tested this, if you add the line:

Code:
asm(".code16gcc\n");


to the start of each C file you wish to be compiled as 16 bit code, then gas will generate proper 16-bit code (not 32-bit with the 66 prefix). It limits you to a single segment, however (ie. 64kB code, 64kB data) and you can't use anything that assumes 32-bit operation, e.g. long ints and the like.

edit: if anyone's interested, http://gujin.org has a boot loader written in 16-bit code using gcc.

edit2: and open watcom natively supports 16-bit, if you can tear yourself away from gcc...

Regards,
John.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 5:18 pm 
Offline
Member
Member

Joined: Mon Apr 09, 2007 12:10 pm
Posts: 586
Location: London, UK
A bit of an update.

Using the method I described above, it is possible to have gcc generate code that will execute in real mode (and presumably v8086), but only on a 386 or above, as it still insists on using the 32-bit registers, even for 2 byte wide variables. Be prepared to get lots of 66 and 67 prefixes.

In actuality it is gas which produces the 16-bit code - the asm instruction just inserts the .code16gcc line at the top of the intermediate assembly file.

In addition, as it is gcc, it is completely unaware of segments. Therefore, if you wish to access any memory outside the segment which ds/es are set to, you need to create your own farpeek/farpoke functions with inline asm (see [wiki]Inline_Assembly/Examples[/wiki] - I can't seem to link to this, its something to do with the slash in the title).

As a small test, I compiled the following, both with and without the .code16asm header. I attach the disassembly for reference. No optimisations were used in the compilation, otherwise this would have become really small :wink:

Code:
asm(".code16gcc\n");

int add2(int a);

int main()
{
        int a = 31;

        int b = add2(a);

        return b;
}

int add2(int a)
{
        return a + 2;
}



If you use short ints instead of ints then the code produced still uses 32-bit registers with prefixes, but the values on the stack are 2-byte aligned.

The .code16gcc option can be changed to .code16, which is similar in its output except that it does not necessarily manipulate the stack pointer in the same way as gcc does making it more difficult to walk the stack from a 32-bit monitor.

The disassembly, produced by the NASM disassembler is attached.

Regards,
John.


Attachments:
File comment: short ints instead of ints, compiled with .code16gcc
test16-short.16.txt [1.26 KiB]
Downloaded 208 times
File comment: compiled with .code16
test16.16-nogcc.txt [1.04 KiB]
Downloaded 130 times
File comment: compiled with .code16gcc
test16.16.txt [1.05 KiB]
Downloaded 168 times
Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 9:46 pm 
Offline
Member
Member

Joined: Thu Jul 07, 2005 11:00 pm
Posts: 1544
Really, if you could find a way past the one segment bit in g++ by making your own far_pointer class...

What about the gcc that minix uses? it would be 16bit wouldn't it?

_________________
My new NEW blag


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 9:54 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 9:29 pm
Posts: 2347
Location: Canada
hckr83 wrote:
Really, if you could find a way past the one segment bit in g++ by making your own far_pointer class...

What about the gcc that minix uses? it would be 16bit wouldn't it?

Uhh, The early Minix releases used "ACK" as a C compiler, Which seems to have a new life here: http://tack.sourceforge.net/

Supports the 8086 and 80386.. Is even support for other systems as well.. :)

_________________
Image
UNIX&BSD's, are what every OS should aspire to be! 8)
Windows, are an opening in an otherwise solid and opaque surface through which light and, sometimes, even air can pass through; nothing more.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group