Writing an OS in a custom language
Writing an OS in a custom language
Hi All,
This query is based on both OS theory and Compilers. Let's say I want to write a new OS in language X. Language X is strongly typed and has all the features that are generally necessary to do systems programming in, but has intrinsic support for concurrency a.k.a CSP (i.e. via channels and a 'spawn' keyword).
The trouble is that multi-threading (or running concurrent processes) is something that is highly dependent on the OS. However, given that the language's purpose itself is to write an OS, I've reached a Catch-22 of sorts.
I want to write an OS in the language, but I can't write a compiler for it until I write the OS itself. Any suggestions?
Cheers,
--
Anant
This query is based on both OS theory and Compilers. Let's say I want to write a new OS in language X. Language X is strongly typed and has all the features that are generally necessary to do systems programming in, but has intrinsic support for concurrency a.k.a CSP (i.e. via channels and a 'spawn' keyword).
The trouble is that multi-threading (or running concurrent processes) is something that is highly dependent on the OS. However, given that the language's purpose itself is to write an OS, I've reached a Catch-22 of sorts.
I want to write an OS in the language, but I can't write a compiler for it until I write the OS itself. Any suggestions?
Cheers,
--
Anant
- AndrewAPrice
- Member
- Posts: 2299
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
Re: Writing an OS in a custom language
Write a compiler for Linux/Windows to compile the kernel with. That's like writing a compiler for a new language in the language itself.KillerX wrote:I want to write an OS in the language, but I can't write a compiler for it until I write the OS itself. Any suggestions?
My OS is Perception.
That's how the java compiler was made. The java compiler is written in java - they made a small, crappy compiler in C, compiled the compiler in that then used the new java compiler to recompile nicelyI guess this means developing a tiny kernel using a subset of the language, and then extend it after spawn has been enabled
bootstrapping
I wrote my ZC compiler in QBASIC first. Then once I had it working good enough I re-wrote it in ZC. Although if you're planning on doing something like this... maybe QBASIC isn't quite the best place to start...
http://jjinux.blogspot.com/2007/03/erno ... ystem.html
http://en.wikipedia.org/wiki/BitC
plan9 with plain their own c compiler.
http://en.wikipedia.org/wiki/BitC
plan9 with plain their own c compiler.
-
- Member
- Posts: 566
- Joined: Tue Jun 20, 2006 9:17 am
Solar is correct
... bootstrapping ... ,Take a look at project Oberon .. Also i feel that
bootstrapping is sometimes not needed ... Eg when you write C
compiler that implements a subset of standard C using a good C++
compiler .. U rewrite ur compiler with this C compiler .. The readability
of the orginal code is lost ... But it assures that your compiler is
pretty well implemented .... Am i right ???
bootstrapping is sometimes not needed ... Eg when you write C
compiler that implements a subset of standard C using a good C++
compiler .. U rewrite ur compiler with this C compiler .. The readability
of the orginal code is lost ... But it assures that your compiler is
pretty well implemented .... Am i right ???
- AndrewAPrice
- Member
- Posts: 2299
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
99%+ of compilers output to assembly, and then call an assembler, then your linker. Of course you could manually output directly to a binary, just get Volume 3 of the Intel docs and it contains a listing of every instruction including their opcode and usage.crazygray wrote:How would you go about writing a compiler? Do you need to know machine language first.
My OS is Perception.
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
Effective? Dunno about that, the easiest way I can think of is first pick up a compiler book. I'd suggest the dragon book by Aho. Writing a compiler is a very satisfying project. I was required to write one from scratch in school. If it didn't work you failed and you weren't allowed to use any of the compiler tools. It's difficult in, but very rewarding when you do it. So, um get ready for the fire hose.crazygray wrote:I was more looking for the most effective way to write a compiler.
Your compiler will basically follow this pattern:
1) Lexical Analysis (develop tokens from the source it is compiling). You can use one of the many compiler tools to generate this code. If you don't want to do that, then develop a FSM that can detect the lexemes.
2) Syntax Analysis. If the language is of a certain form and you are smart in writing your grammar, then you can develop a LL(1) grammar which requires a look ahead of only 1. Then you can develop a recursive descent parser that can parse the language. This is where you will spend A LOT of time on paper before you even begin coding. Design before you implement! It can be painful if you don't.
3) Intermediate code generation. A lot of people use separate syntax trees in order to generate code, but if you do a recursive descent parser, you're really walking the syntax tree already so just go ahead and do your code gen at that point while parsing. This can be accomplished by smartly passing parameters and returning values from the methods in your parser.
4) From your intermediate code you can gen the asm or do the machine code directly.
To do it right is no small project, but it is still one of the most loved and hated things I have ever programmed.
Thanks for all the fish.