OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Apr 27, 2024 4:10 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: 16BIT C comliper (Maybe GCC!)
PostPosted: Sun Jul 28, 2013 1:50 pm 
Offline
Member
Member

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
Hello guys. I'm looking for a 16bit C compiler to build my bootloader in C and use less assembly.
You may say that there are no 16bit C compilers or you don't know any of them. But what do you say if I tell you that GCC may compile 16bit C code? If you take a look at linux kernel source code there is a directory in "/arch/x86/boot" that all the code in there is only for real mode. So when we compile that kernel with GCC it should compile all the code in there and it should produce 16bit C code for the bootloader that is in real mode. But how is it possible? Please tell me if someone knows whats happening there or if I was wrong with this :mrgreen: :mrgreen:


Top
 Profile  
 
 Post subject: Re: 16BIT C comliper (Maybe GCC!)
PostPosted: Sun Jul 28, 2013 2:46 pm 
Offline
Member
Member
User avatar

Joined: Sat Apr 30, 2011 12:50 am
Posts: 308
Hello newfriend,

Surely you forgot to RTFM or even do a basic search on this very website.
Nevertheless, GCC compiles 16BIT protected mode code. There is no reason in fighting the machine and not embracing assembly for things such as boot loaders and fast-path code segments.

With best regards.



P.S Refrain from using emoticons.


Top
 Profile  
 
 Post subject: Re: 16BIT C comliper (Maybe GCC!)
PostPosted: Sun Jul 28, 2013 3:45 pm 
Offline
Member
Member

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
I'm Sorry :oops:
But I don't want 16bit protected mode. I just want 16bit flat C code. How is it possible? :D


Top
 Profile  
 
 Post subject: Re: 16BIT C comliper (Maybe GCC!)
PostPosted: Sun Jul 28, 2013 11:42 pm 
Offline
Member
Member
User avatar

Joined: Sat Apr 30, 2011 12:50 am
Posts: 308
There is no flat 16 bit mode.


Top
 Profile  
 
 Post subject: Re: 16BIT C comliper (Maybe GCC!)
PostPosted: Mon Jul 29, 2013 2:11 am 
Offline
Member
Member
User avatar

Joined: Fri Sep 16, 2011 10:00 am
Posts: 49
Location: Finland
The Watcom C compiler creates 16bit real mode code...

Can anyone tell if that can be used in unreal mode?

_________________
I'm Eino Tuominen from Finland, a web software dev learning low level stuff and reading / trying out kernel dev


Top
 Profile  
 
 Post subject: Re: 16BIT C comliper (Maybe GCC!)
PostPosted: Mon Jul 29, 2013 2:39 am 
Offline
Member
Member

Joined: Sun Feb 01, 2009 6:11 am
Posts: 1070
Location: Germany
Why don't you just run your bootloader in PM? For calling BIOS interrupts, you can have functions in assembly that temporarily switch back to RM. Compared to the complete size of a real bootloader that deserves this name, these functions should be really minimal. And you want to be able to load data to > 1 MB, so RM doesn't quite cut it anyway.

_________________
Developer of tyndur - community OS of Lowlevel (German)


Top
 Profile  
 
 Post subject: Re: 16BIT C comliper (Maybe GCC!)
PostPosted: Mon Jul 29, 2013 1:25 pm 
Offline
Member
Member

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
Kevin wrote:
Why don't you just run your bootloader in PM? For calling BIOS interrupts, you can have functions in assembly that temporarily switch back to RM. Compared to the complete size of a real bootloader that deserves this name, these functions should be really minimal. And you want to be able to load data to > 1 MB, so RM doesn't quite cut it anyway.


I know that I can switch back to real mode and use C codes. I mean is there any way to use 16 bit flat C code in bootloader(bootsector) instead of assembly?

eino wrote:
The Watcom C compiler creates 16bit real mode code...


I have heared about it but I didn't know that it can output 16bit code. I will give it a try :mrgreen:


Top
 Profile  
 
 Post subject: Re: 16BIT C comliper (Maybe GCC!)
PostPosted: Mon Jul 29, 2013 2:38 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 15, 2008 2:37 pm
Posts: 815
Location: The Fire Nation
MadZarx wrote:
heared


Your subscription is no longer qualified to the customer support here.


Top
 Profile  
 
 Post subject: Re: 16BIT C comliper (Maybe GCC!)
PostPosted: Fri Aug 02, 2013 1:38 pm 
Offline

Joined: Sun Jul 21, 2013 11:23 am
Posts: 3
I wanted to do the same, C in real mode with GCC. I found that GCC is 32 bit compiler, it can't generate 16 bit assembly. However, it's assembler, GNU AS can assemble 16 bit instructions for real mode, but you have to inform the assembler about it by the .code16 directive.
You can also tell GAS that "This code is from GCC, but I want to assemble it for 16 bit mode." by .code16gcc, read here: http://sourceware.org/binutils/docs-2.20/as/i386_002d16bit.html
I got it working this way: I've created a function in a C file and generated assembly from it with gcc -S. Then added .code16gcc to this, and called the function from another assembly file. Just watch out that the code from gcc will expect you to push 4 bytes to stack, not 2. Also when calling the function, add .code16gcc before it and .code16 after it, as gcc calculated with a 4 byte push for call, not 2 byte which is default. About passing parameters to the C function and back, read about cdecl calling convention, GCC uses this one. Good luck.


Top
 Profile  
 
 Post subject: Re: 16BIT C comliper (Maybe GCC!)
PostPosted: Fri Aug 02, 2013 3:32 pm 
Offline
Member
Member
User avatar

Joined: Fri Dec 14, 2012 6:05 pm
Posts: 88
Location: United States, Texas
How about BCC? It was designed for a port of Linux to the 8086 machines.
Quote:
This is a C-compiler for 8086 cpus which is important for the development of boot loaders or BIOS related 8086 code.

It is possible to run 8086 code under i386 Linux using an emulator, `elksemu', also included in this package.

here is a Debian BCC Package

_________________
### Z++; && S++; ###
zeitue is pronounced zeɪtə
Web Site::Bit Bucket
Programming Languages: C, C++, Java, Ruby, Common Lisp, Clojure
Languages: English, zɪ̀ŋ, 日本語, maitraiuen


Top
 Profile  
 
 Post subject: Re: 16BIT C comliper (Maybe GCC!)
PostPosted: Sun Aug 04, 2013 7:58 am 
Offline
Member
Member

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
Vaclav wrote:
I wanted to do the same, C in real mode with GCC. I found that GCC is 32 bit compiler, it can't generate 16 bit assembly. However, it's assembler, GNU AS can assemble 16 bit instructions for real mode, but you have to inform the assembler about it by the .code16 directive.
You can also tell GAS that "This code is from GCC, but I want to assemble it for 16 bit mode." by .code16gcc, read here: http://sourceware.org/binutils/docs-2.20/as/i386_002d16bit.html
I got it working this way: I've created a function in a C file and generated assembly from it with gcc -S. Then added .code16gcc to this, and called the function from another assembly file. Just watch out that the code from gcc will expect you to push 4 bytes to stack, not 2. Also when calling the function, add .code16gcc before it and .code16 after it, as gcc calculated with a 4 byte push for call, not 2 byte which is default. About passing parameters to the C function and back, read about cdecl calling convention, GCC uses this one. Good luck.


Vaclav are you sure its wroking well without any triple faults or problems?


Top
 Profile  
 
 Post subject: Re: 16BIT C comliper (Maybe GCC!)
PostPosted: Sun Aug 04, 2013 8:16 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
MadZarx wrote:
Vaclav are you sure its wroking[sic] well without any triple faults
Of course not. Neither Vaclav nor GCC is going to prevent you from screwing up yourself, and neither is going to take the blame for that when (there is no "if") you do.

You made two serious mistakes here. Fix them first:
1: Not knowing what you're asking for
2: Not trying.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: 16BIT C comliper (Maybe GCC!)
PostPosted: Sun Aug 04, 2013 9:24 am 
Offline
Member
Member
User avatar

Joined: Wed Dec 01, 2010 3:41 am
Posts: 1761
Location: Hong Kong
I don't know why anyone would want to write boot loader with 16-bit C. It's so obvious that writing a early stage (with do all the necessary real mode functions) with assembly is straightforward*, and any complex logic could be implemented with 32-bit C after entering protected mode or long mode.

* By straightforward, I meant a reasonable early stage boot loader can be implemented in about 500 lines of assembly code.
* In contrast, insist to do that with C you not only end up with almost equal amount of (inline) assembly, but also suffer from the lack of tools.


Top
 Profile  
 
 Post subject: Re: 16BIT C comliper (Maybe GCC!)
PostPosted: Mon Aug 05, 2013 1:19 pm 
Offline
Member
Member

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
Combuster I know what I am asking for. I just need a way to compile C code to 16bit object file in some way that Vaclav said how should I do it. I tested it and it worked well. And I know it's much better to build the bootloader in assembly. But what if I wanted to build a simple Real mode kernel (Like mikeos)? So it may take a long time and I should write lots of code. So This is why I need a 16bit C compiler


Top
 Profile  
 
 Post subject: Re: 16BIT C comliper (Maybe GCC!)
PostPosted: Tue Aug 06, 2013 5:33 am 
Offline
Member
Member
User avatar

Joined: Wed Mar 21, 2012 3:01 pm
Posts: 930
Don't confuse "Real mode operating system" with "Simple to write and maintain OS". In many ways, it's much nicer in 32-bit protected mode and 64-bit long mode. You are doing yourself a disfavour dealing with Real Mode that died a couple decades ago.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: eekee, Majestic-12 [Bot] and 32 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