Perl for OS Development?
Perl for OS Development?
OK, this is probably a stupid question. But, is it possible to develop an OS using Perl.
I have been using Perl for some 3 years, and have always been interested in OS development.
Currently, the only problem I see in using Perl is that it is an interpreted language. However, I have heard that there is a way to compile a Perl program into a binary file.
Am I just building castles in the sky, or is there a real chance of using Perl for writing an OS?
Thanks,
Martin Sanders
Software Developer
www.publiclinux.net
I have been using Perl for some 3 years, and have always been interested in OS development.
Currently, the only problem I see in using Perl is that it is an interpreted language. However, I have heard that there is a way to compile a Perl program into a binary file.
Am I just building castles in the sky, or is there a real chance of using Perl for writing an OS?
Thanks,
Martin Sanders
Software Developer
www.publiclinux.net
Re:Perl for OS Development?
No. Not unless you write a perl interpreter to run at the OS level. Even then you will have problems doing lowlevel data manipulation with perl. You will probably need your own dialect. Just use C + asm like the rest of us.
Re:Perl for OS Development?
.... or you could close yer eyes, click the heels, salute with closed eyes whilst mumbling "it's a beautiful day" and wait for the magic fairy queen to wave her wand... If you lack support by magic fairy queens you could do all the work yourself and code it in c and asm. ]:->
this sentence on your website has been too ... inviting for me to resist.
this sentence on your website has been too ... inviting for me to resist.
Re:Perl for OS Development?
Well, Perl is a bit different from your average VB, since it can be compiled to native.
So, technically, I would say it is possible.
However, there are several drawbacks:
* Existing Perl implementations assume a "hosted" environment; you would have to write your environment first (a task which you cannot do in Perl);
* Perl is not known for ease of maintenance;
* You will still need to do quite some things in ASM;
* I don't know how good Perl is in interacting with ASM modules;
* You will be very much on your own.
There are no "OS in Perl" tutorials, you would have to "translate" any code examples, and if you encounter a problem, chances are that a) the people able to identify your problem don't know Perl well enough, and b) the people knowing Perl don't know enough of OS development to identify your problem.
So, yes, I would say it is possible - technically. But you would basically go to great lengths setting your development environment, before you could even start working on the OS itself, and even then the drawbacks are severe.
So, technically, I would say it is possible.
However, there are several drawbacks:
* Existing Perl implementations assume a "hosted" environment; you would have to write your environment first (a task which you cannot do in Perl);
* Perl is not known for ease of maintenance;
* You will still need to do quite some things in ASM;
* I don't know how good Perl is in interacting with ASM modules;
* You will be very much on your own.
There are no "OS in Perl" tutorials, you would have to "translate" any code examples, and if you encounter a problem, chances are that a) the people able to identify your problem don't know Perl well enough, and b) the people knowing Perl don't know enough of OS development to identify your problem.
So, yes, I would say it is possible - technically. But you would basically go to great lengths setting your development environment, before you could even start working on the OS itself, and even then the drawbacks are severe.
Every good solution is obvious once you've found it.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Perl for OS Development?
Hmm ... i'll ask some fairy close to my heart if she can do something for you, but i fear fairies don't see pearls the same way we do ...BI lazy wrote: If you lack support by magic fairy queens you could do all the work yourself and code it in c and asm. ]:->
Btw, there are several things you should consider before you start programming an OS in perl.
- perl is mainly useful for text-based processing, and you'll have very little text at the kernel level (except maybe for configuration files). So i'm not sure it will be so convenient.
- The way Perl handles atomic variable is not very handy for low-level programming. In perl, the same variable is an integer, a float and a string altogether. I'm not sure this will be convenient for system programming
- a lot of perl things are based on the underlying posix OS (like manipulating files, etc). and those stuff are built in the language (rather than being available through a library as in C -- correct me if i'm wrong)
Which of course introduces a sub-question: can't you just add this feature with a library to C (of course, it'll be a bit less nice, but you'll be able to use what you want with a more conventionnal framework)
Re:Perl for OS Development?
There are several things in this world which, even though possible are outside the realm of sanity. Your dream of writing an OS in PERL comes under this category
Try learning a real programming language like C/ASM for real hardware bashing
Try learning a real programming language like C/ASM for real hardware bashing
Re:Perl for OS Development?
Thankyou for your responses, sadly my magic fairy queens are not yet educated in C or ASM... so I will have to force myself to conquer those languages myself.
I'm teaching myself C and ASM, but I keep coming into code that makes me ask myself 'This is so much easier in Perl' and then I start day dreaming of a Perl OS!
I am having difficulty finding a good book to teach ASM. I have Linux Assembly Language Programming (ISBN: 0-13-087940-1) which does go deeply into the theory of using ASM, with some examples of Code.
However, the book does not actually show how to compile ASM code, not even a single example of how to use ASM compilers (such as gas & nasm).
I find free online ASM tutorials are proving to be more usefull than the 35 pounds I spent on the book.
Enough of me ranting!
Yours forever,
Martin Sanders
I'm teaching myself C and ASM, but I keep coming into code that makes me ask myself 'This is so much easier in Perl' and then I start day dreaming of a Perl OS!
I am having difficulty finding a good book to teach ASM. I have Linux Assembly Language Programming (ISBN: 0-13-087940-1) which does go deeply into the theory of using ASM, with some examples of Code.
However, the book does not actually show how to compile ASM code, not even a single example of how to use ASM compilers (such as gas & nasm).
I find free online ASM tutorials are proving to be more usefull than the 35 pounds I spent on the book.
Enough of me ranting!
Yours forever,
Martin Sanders
Re:Perl for OS Development?
"The Art of Assembly", http://webster.cs.ucr.edu/Page_asm/0_ArtOfAsm.html, is a good start (it was for me); just stay away from the high-level constructs Webster is talking about, sicne they are specific to his assembler.sanders wrote: I am having difficulty finding a good book to teach ASM.
The act of assembling code with as is very similar to compiling code with gcc - small wonder, since they are part of the same toolchain:
Code: Select all
gcc -o <output.o> <input.c>
as -o <output.o> <input.asm>
Every good solution is obvious once you've found it.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Perl for OS Development?
Btw, Perl is massively inspired from C in its syntax (for,while and if blocks, integer operators, etc. ). What you'll really have to learn is the notions of memory address, pointers, stackframe and other stuff that are mandatory to develop an OS (as for instance, you, as the kernel developer, will be the sole responsible of allocated memory)
Re:Perl for OS Development?
The good news is, as Pype points out, large sections of the syntax of Perl and C are very similiar, if not the same. Learning Perl first was the right move; it is a much easier language to work in as a novice, despite it's complexity.sanders wrote: Thankyou for your responses, sadly my magic fairy queens are not yet educated in C or ASM... so I will have to force myself to conquer those languages myself.
That shouldn't be surprising. Perl was written to be a utility language - one which you could use to write powerful scripts quickly. It incorporates a large number of complex tools to make it easy to throw together a script for, say, filtering a mail spool for key words or phrases out a particular list, extracting the messages containing them, generating mail messages with the extracted message attached, and sending it to an anti-spam organization. Perl combines influences not only from C, but also from C shell and Bourne shell scripting, AWK, Emacs LISP, SNOBOL, and Icon, and possibly others (you'd have to ask Larry Wall), and can mix paradigms and metaphors with ease. Lastly, it takes advantage of the interpreted environment to allow such constructs as [tt]eval()[/tt], which allows you to run code stored in a string. For that matter, while it is rarely done, it is possible to run Perl interactively, in the debugger (try running '[tt]perl -de 0[/tt]' some time and see what I mean); there is talk of adding a true interactive mode, like those of Scheme or Python, but nothing has come of it AFAIK.I'm teaching myself C and ASM, but I keep coming into code that makes me ask myself 'This is so much easier in Perl' [[...]]
The price for this flexibility is that the language is complex, and implementing is even more so. It requires a huge amount of runtime support, so much so that it that it is more efficient to run it interpreted rather than compiled - a natively compiled Perl program would, in essence, have to link in the equivalent of the interpreter anyway (this is what compiled VB programs do, BTW - the runtime DLLs needed by them amount to the whole of the VB interpreter). Because of this overhead, writing a Perl compiler that could generate completely standalone code would be more difficult than writing a whole operating system - or rather, it would be writing a whole operating system, just for the language interpreter! (This has been done before; see JavaOS, or the original Smalltalk systems, or the UCSD-p system, for examples of this approach).
C, by contrast, is a much simpler language, aimed at allowing programmers to build systems from the ground up with no more support than a text editor, a compiler, and a link-loader. But because of that, it requires more programming effort to do anything in C; even with the equivalent libraries available (which they won't be, in OS development, until you've written them yourself), it takes more work to write some kinds of programs, simply because Perl has a lot of built-in support for e.g., regexps, in the form of special syntax, whereas in C you must use function calls.
It is entirely possible to write the bulk of the OS in a very high level language like Perl, running on top of a small kernel and an interpreter, as mentioned before; but the low-level parts must be written in assembly, or a combination of assembly with some low-level, low overhead language like C, Modula-2, or Forth (which, while interpreted, is quite well suited for this sort of programming; the interpreter is usually less than 32K of assembly code even on modern processors). I myself plan such an approach. Keep in mind, however, that to do that, you not only need to write the OS, but the language interpreter/compiler as well, a major undertaking in it's own right.
It sounds like it is a more advanced book than you need right now; for an assembly language novice, I'd recommend (as I always do) Jeff Duntemann's Assembly Language Step by Step, if you can get a copy. It covers the basics in detail, with all examples in NASM; the first half of the book gives examples of DOS real-mode programming (which should run under WINE without a problem), while the rest discusses programming under Linux. You'll probably need to get through it, and into the more advanced book a bit, before you reach a point which is really applicable to OS programming, but for a beginner, it is great. Duntemann explains assembly programming with far more wit and clarity than most other writers can for high-level languages.I am having difficulty finding a good book to teach ASM.
Re:Perl for OS Development?
WOW, I'm pretty overwelmed with all the help you are providing me, maybe OS programmers are as nice as Perl programmers
And the gas syntax will prove to be very usefull, Cheers
I don't realy mind learning C, I'm just used to taking the easy way out when working on a project, which is probably why I mainly use Perl at work.
I am fond of some of C's features, such as playing with the preprocessor (a crude example is on my site www.publiclinux.net in the Free Shell section with the C code to the kernel for an in-house system I wrote... please don't laugh at it).
So far pointers seem like a fun thing to play with. The thing that affects whether I enjoy a language often boils down to whether it is fun or not!
Have any of your read 'Just For Fun' by Linus Torvalds (probably a stupid question to ask on an OS site). That book is probably my main drive in wanting to develop my own OS.
Your forever,
Martin Sanders
Software Developer
www.publiclinux.net
And the gas syntax will prove to be very usefull, Cheers
I don't realy mind learning C, I'm just used to taking the easy way out when working on a project, which is probably why I mainly use Perl at work.
I am fond of some of C's features, such as playing with the preprocessor (a crude example is on my site www.publiclinux.net in the Free Shell section with the C code to the kernel for an in-house system I wrote... please don't laugh at it).
So far pointers seem like a fun thing to play with. The thing that affects whether I enjoy a language often boils down to whether it is fun or not!
Have any of your read 'Just For Fun' by Linus Torvalds (probably a stupid question to ask on an OS site). That book is probably my main drive in wanting to develop my own OS.
Your forever,
Martin Sanders
Software Developer
www.publiclinux.net
Re:Perl for OS Development?
you & your magic fairy queens gonna do well. ];->
You can also provide yourself a copy of "C for Dummies". It's funny to read and eases learning quite much. Also, a Copy of Kerrigan & Ritchie C-Book might prove helpful.
Ah, and you'll be very pleased with the #include "file.h" preprocessor command. It eases life in endless ways.
regarding 'nice': no, I am not a Nice Guy (tm).
You can also provide yourself a copy of "C for Dummies". It's funny to read and eases learning quite much. Also, a Copy of Kerrigan & Ritchie C-Book might prove helpful.
Ah, and you'll be very pleased with the #include "file.h" preprocessor command. It eases life in endless ways.
regarding 'nice': no, I am not a Nice Guy (tm).
Re:Perl for OS Development?
Thankyou, funny you should mention 'C for dummies' I was recently handed a copy by a friend who programs C/C++.
So far it looks pretty good, from what I have read so far it slowly introduces one small part at a time, i'll probably concentrate on that one book for now.
My other C manuals seem to dive straight into the hard stuff (not that i'm afraid of being thrown in at the deep end).
I realy love the way C lets you play with the preprocessor, like so:
#define HELLO system("/bin/freemenu.login");
Then I can execute that sub-routine anytime I want to simply by sticking in a :
HELLO
It makes the abstract idea of 'Software Construction' seem more real.
Your forever,
Martin Sanders
Software Developer
www.publiclinux.net
So far it looks pretty good, from what I have read so far it slowly introduces one small part at a time, i'll probably concentrate on that one book for now.
My other C manuals seem to dive straight into the hard stuff (not that i'm afraid of being thrown in at the deep end).
I realy love the way C lets you play with the preprocessor, like so:
#define HELLO system("/bin/freemenu.login");
Then I can execute that sub-routine anytime I want to simply by sticking in a :
HELLO
It makes the abstract idea of 'Software Construction' seem more real.
Your forever,
Martin Sanders
Software Developer
www.publiclinux.net
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Perl for OS Development?
preprocessor is for sure a powerful tool, but beware its abuse. You can quickly reach a point where you are the only one to be able to work on your project because there are too much "new keywords" to learn for newbies.
Make sure you document these "language extensions" clearly and group them by theme so that a new programmer just have to print one or two .h files in order to get a reference on your macros.
Make sure you document these "language extensions" clearly and group them by theme so that a new programmer just have to print one or two .h files in order to get a reference on your macros.
Re:Perl for OS Development?
Thankyou for the advice. I have to admit that I dont usually write code that I expect anyone else to modify. I mostly write in-house systems for the business I run, Applications released commercially, or Vertical Applications for Business Customers. Ergo: not used by programmers!
Having said that, my plan for my (little) OS is to have it as commented as possible, and make it easy for other Programmers to modify.
I don't plan to just boot it at home and look at it stroking my chin all day, my desire is to release it for others to play with and (probably) improve it. So i'll try to be as conservative with the preprocessor as possible
Hold on, female soccer team on TV in tight shorts... ok i'm back, that was nice... where was I, oh yes the OS
Sorry my mind is blank now.
Yours forever,
Martin Sanders
Software Developer
www.publiclinux.net
Having said that, my plan for my (little) OS is to have it as commented as possible, and make it easy for other Programmers to modify.
I don't plan to just boot it at home and look at it stroking my chin all day, my desire is to release it for others to play with and (probably) improve it. So i'll try to be as conservative with the preprocessor as possible
Hold on, female soccer team on TV in tight shorts... ok i'm back, that was nice... where was I, oh yes the OS
Sorry my mind is blank now.
Yours forever,
Martin Sanders
Software Developer
www.publiclinux.net