Advice on OS Language please...

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.
magicstuff
Posts: 4
Joined: Wed Mar 11, 2009 1:29 am

Advice on OS Language please...

Post by magicstuff »

hiya,

I'm new here and i've been browsing the forums. I always thought thay OS's were written in C or C++, but from what i've seen, many people use assembly language.

Should i learn this language, then make my OS in it (In about 2 years :o)

Thanks,
Magicstuff.

EDIT: or do i need to know C++ and Assembly??

Thanks.
magicstuff
Posts: 4
Joined: Wed Mar 11, 2009 1:29 am

Re: Advice on OS Language please...

Post by magicstuff »

wait, so asm is assembly?

Hmmm.....

Looks like i've got some research to do!

Thanks.
User avatar
david
Member
Member
Posts: 93
Joined: Tue Aug 21, 2007 4:22 am
Location: Beijing.China
Contact:

Re: Advice on OS Language please...

Post by david »

I think every language could be used to write OS,
you can use your favourite language(ASM/C/C++/Perl/PHP etc).

I think your OS is only just for fun, it's hard to let market accept your OS as a product .

so, don't care more, write write and write..
Just For Fun
User avatar
Steve the Pirate
Member
Member
Posts: 152
Joined: Fri Dec 15, 2006 7:01 am
Location: Brisbane, Australia
Contact:

Re: Advice on OS Language please...

Post by Steve the Pirate »

You need to know a fair bit of Assembly, as there are a lot of things you can't do without it (such as loading the GDT and IDT, setting registers to enable paging, move stacks etc.). On top of that, if you want to use a higher level language (most people do) you should have a very good understanding (and lots of experience) in either C, C++ or possibly Pascal.
My Site | My Blog
Symmetry - My operating system.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Advice on OS Language please...

Post by Solar »

Yes, "Assembly" and "ASM" mean the same thing. Basic knowledge is a must, because some things cannot be done without knowledge of ASM: Bootloaders, interrupt service routines, low-level memory management are examples for this. Beware: ASM source syntax is depending on the assembler tool used. There is a group of assemblers that is quite similar to each others, and a couple of very different others (GAS, most prominently). I'll leave the details to the ASM gurus of this board.

Then you need in-depth knowledge of the high level language of your choice. You don't have to know more than one, but that one you must have detailed knowledge of, especially the runtime support requirements (something you don't get in touch with when coding "normal" applications). The one best documented, with the lowest runtime requirements, is C. C++ without exceptions and RTTI comes a close second, the rest are more complex.

Edit: And while there will always be someone telling you that you can write in any language you like, de facto there is a limited number of languages suited to the task. Yes, you can build a bicycle with square wheels, and it will even give a smooth ride - if you build the right roads...
Every good solution is obvious once you've found it.
magicstuff
Posts: 4
Joined: Wed Mar 11, 2009 1:29 am

Re: Advice on OS Language please...

Post by magicstuff »

david wrote:I think every language could be used to write OS,
you can use your favourite language(ASM/C/C++/Perl/PHP etc).

I think your OS is only just for fun, it's hard to let market accept your OS as a product .

so, don't care more, write write and write..

Wait a minute, you say i can write an OS in PHP??????!!!!?

I have about 2 years experience of PHP so it would be my primary language. :)

Although i am guessing that the booter etc, would have to be assembly...
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Advice on OS Language please...

Post by Solar »

You can drive a screw with a hammer, if you take the hammer to a grinder first and shape some part of it into something resembling a screwdriver.
Every good solution is obvious once you've found it.
User avatar
Steve the Pirate
Member
Member
Posts: 152
Joined: Fri Dec 15, 2006 7:01 am
Location: Brisbane, Australia
Contact:

Re: Advice on OS Language please...

Post by Steve the Pirate »

magicstuff wrote:Wait a minute, you say i can write an OS in PHP??????!!!!?

I have about 2 years experience of PHP so it would be my primary language. :)
PHP is a scripting language, not a programming language - there's no way you could write an operating system in it, since it needs an interpreter. You can't really (easily) do it with languages that need virtual machines and/or just-in-time compilation, like Java and C#.

Anyway, all of this is in the wiki - look at the Getting Started and Beginner Mistakes pages.
magicstuff wrote:Although i am guessing that the booter etc, would have to be assembly...
Yes, although I think someone has done it in C, but it still needed a lot of inline assembly
My Site | My Blog
Symmetry - My operating system.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Advice on OS Language please...

Post by Combuster »

You have about three kinds of languages

The first set is those who map directly to something the processor understands, and are complete enough that it does not need anything in another language to write a full-fledged OS. That holds for assembly, and if you allow inline assembly, that includes C, C++ and pascal.

The second set are those who compile to native code, but need support of another language (part of the first set) to get complete coverage. That includes things like FreeBasic, but Haskell fits that as well (albeit at a much higher level). That causes several dependencies within the kernel that can blow you out, especially when they turn out to bi circular.

The third set does not compile to native code, so you need to write a compiler/interpreter/VM to even run that code. That means you get to write yourself another project before you can even start on the real OS. Those things include C#, Java, PHP, and everything else that's scripted and doesn't have a native compiler.
"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 ]
User avatar
yemista
Member
Member
Posts: 299
Joined: Fri Dec 26, 2008 12:31 pm
Location: Boston
Contact:

Re: Advice on OS Language please...

Post by yemista »

It may be a whole extra step to write an operating system in Java, but this also seems to be the direction many developers are going for writing portable operating systems, like on phones and handheld devices. Interpretted languages are not slower if they byte code is designed well
User avatar
Steve the Pirate
Member
Member
Posts: 152
Joined: Fri Dec 15, 2006 7:01 am
Location: Brisbane, Australia
Contact:

Re: Advice on OS Language please...

Post by Steve the Pirate »

yemista wrote:It may be a whole extra step to write an operating system in Java, but this also seems to be the direction many developers are going for writing portable operating systems, like on phones and handheld devices. Interpretted languages are not slower if they byte code is designed well
A whole extra step... like writing the Java interpreter (which is technically the kernel, not the java that runs on it) for every platform the system runs on?
My Site | My Blog
Symmetry - My operating system.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Advice on OS Language please...

Post by AJ »

Steve the Pirate wrote:A whole extra step... like writing the Java interpreter (which is technically the kernel, not the java that runs on it) for every platform the system runs on?
Basically, yes. Of course, you could write the interpreter in C or C++ and therefore retain a level of portability.

The main exception to this would be a CPU that runs Java bytecode directly.

Cheers,
Adam
User avatar
yemista
Member
Member
Posts: 299
Joined: Fri Dec 26, 2008 12:31 pm
Location: Boston
Contact:

Re: Advice on OS Language please...

Post by yemista »

Steve the Pirate wrote:
yemista wrote:It may be a whole extra step to write an operating system in Java, but this also seems to be the direction many developers are going for writing portable operating systems, like on phones and handheld devices. Interpretted languages are not slower if they byte code is designed well
A whole extra step... like writing the Java interpreter (which is technically the kernel, not the java that runs on it) for every platform the system runs on?
Yes precisley. Im not meaning to say this is a good idea for OS development because Im pretty sure most people here are developing OS's to learn about writing the OS as opposed to writing Java interpreters, but it certainly is a possibility for anyone who might have the know how or drive to do it. I think the Android has been designed this way, and it looks like this is the route future development will take and it should not be dismissed as a way to do it. The kernel itself is written in Java and has access through the hardware from an API that must also be written, but the interpreter itself just makes sure to compile the source in a way that is most efficient for the hardware
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Advice on OS Language please...

Post by Troy Martin »

berkus wrote:Just to add a note about php requiring interpreter - there's llvm-based roadsend php compiler, but you will most probably require a lot of runtime support (the higher the language level - the more runtime support it requires, usually).
Ahhhh, but can pointers and I/O ports be accessed in PHP? (never learnt the language more than a few simple bits of the syntax.)
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Advice on OS Language please...

Post by neon »

Ahhhh, but can pointers and I/O ports be accessed in PHP? (never learnt the language more than a few simple bits of the syntax.)
I dont think any general purpose HLL would support I/O ports nativity do to it being dependent on the architecture and platform. (C relies on asm to use port I/O) I dont know about PHPs usage on pointers though.

Any language(s) can be used so long as the tool environment can produce supervisor-mode code that is supported by your hardware environment. In the case of PC's, technically, the only code that must be written in asm is the MBR and bootstrap code. Everything else can be written in a HLL if you wanted.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Post Reply