Page 1 of 2
Javascript Kernel
Posted: Fri Jun 14, 2013 11:32 pm
by QuentinRain
Hey, everyone! I'm new to OS development, and was wondering if anyone has ever written a kernel in Javascript before? That's going to be a project of mine for the next couple of months!
Re: Javascript Kernel
Posted: Sat Jun 15, 2013 12:20 am
by iansjack
How are you going to interpret the Javascript? Have you written a bare-metal interpreter? What language did you use for that?
Re: Javascript Kernel
Posted: Sat Jun 15, 2013 12:33 am
by QuentinRain
I was thinking I could use this:
https://developer.mozilla.org/en-US/docs/SpiderMonkey
I'm sure it wouldn't be that hard to make it bootable...
Re: Javascript Kernel
Posted: Sat Jun 15, 2013 12:48 am
by zhiayang
Beginner_Mistakes,
FAQ
One does not simply *make a kernel in javascript*. Unless, of course, you have already created a bare-bones C/C++ boilerplate, complete with memory management, processes, etc...
Javascript, among other things, is not a good language for making a kernel (if at all). It does not offer low-level bit-twiddling, which is essential to OSDev, or pointers, or any good interface with assembly. Even if you succeed, it will *not* be a kernel, but an application -- it cannot handle anything such as ring0/3, interrupts, etc.
Also: wasn't there something in the beginner mistakes page about this?
Re: Javascript Kernel
Posted: Sat Jun 15, 2013 12:49 am
by BMW
To make a bootloader, you need machine code. Javascript doesn't compile to anything such like C\C++ does. Javascript is just a script which is interpreted at runtime. If you wanted to make a bootloader with JavaScript, you would have to make a compiler which compiles the JavaScript to machine code.
However you could make a kernel with JS if you really wanted to, although it would be easier(IMO) to just learn C and do it in C.
You would have to make some sort of base for the JS interpreter to run off though, e.g. a basic kernel which manages memory etc.
Re: Javascript Kernel
Posted: Sat Jun 15, 2013 12:50 am
by QuentinRain
Well, I might be new to OS development, but I'm certainly not new to programming. I've been writing jQuery plugins for a couple of years, now...
Re: Javascript Kernel
Posted: Sat Jun 15, 2013 12:51 am
by QuentinRain
BMW wrote:To make a bootloader, you need machine code. Javascript doesn't compile to anything such like C\C++ does. Javascript is just a script which is interpreted at runtime. If you wanted to make a bootloader with JavaScript, you would have to make a compiler which compiles the JavaScript to machine code.
However you could make a kernel with JS if you really wanted to, although it would be easier(IMO) to just learn C and do it in C.
Well, that's what I was hoping Spidermonkey would do for me (that's written in C/C++.)
Re: Javascript Kernel
Posted: Sat Jun 15, 2013 12:53 am
by zhiayang
QuentinRain wrote:
Well, I might be new to OS development, but I'm certainly not new to programming. I've been writing jQuery plugins for a couple of years, now...
You have been writing jQuery plugins for years yes. That does not expose you to the low-level of OSDev. As BMW said, it would either require running a javascript interpreter as a program, which needs a basic/intermediate OS already....
OR, to compile javascript code into asm/opcodes, to be executed by the CPU directly. That's going into compiler theory, which is out of the scope of this discussion.
Re: Javascript Kernel
Posted: Sat Jun 15, 2013 12:55 am
by BMW
QuentinRain wrote:BMW wrote:To make a bootloader, you need machine code. Javascript doesn't compile to anything such like C\C++ does. Javascript is just a script which is interpreted at runtime. If you wanted to make a bootloader with JavaScript, you would have to make a compiler which compiles the JavaScript to machine code.
However you could make a kernel with JS if you really wanted to, although it would be easier(IMO) to just learn C and do it in C.
Well, that's what I was hoping Spidermonkey would do for me (that's written in C/C++.)
SpiderMonkey doesn't compile JS if that's what you were hoping... all it does is interprets it.
If you were hoping that you could sort of "boot" SpiderMonkey and use it to run your JS, think again. SpiderMonkey needs a system to run off.
I suggest learning C (if you don't know it) - the syntax isn't too different from JS.
Re: Javascript Kernel
Posted: Sat Jun 15, 2013 12:57 am
by zhiayang
QuentinRain wrote:BMW wrote:To make a bootloader, you need machine code. Javascript doesn't compile to anything such like C\C++ does. Javascript is just a script which is interpreted at runtime. If you wanted to make a bootloader with JavaScript, you would have to make a compiler which compiles the JavaScript to machine code.
However you could make a kernel with JS if you really wanted to, although it would be easier(IMO) to just learn C and do it in C.
Well, that's what I was hoping Spidermonkey would do for me (that's written in C/C++.)
I wish to drive a car with the power of my mind.
The mind reader I have. But the car, I do not. Neither do I have any fuel, seats, or gearbox.
I'm sorry to disappoint, but it is simply impractical. Look at the people managing COSMOS -- It's a OS framework for writing an 'OS' in C#. C# is a high-level language, requiring a working
everything.
Javascript being an even higher-level language...
EDIT: As BMW said;
Indeed, you cannot. If you wish to port spider monkey.... it'd require a working toolchain for your OS, which implies self-hostability.
Re: Javascript Kernel
Posted: Sat Jun 15, 2013 1:00 am
by QuentinRain
BMW wrote:QuentinRain wrote:BMW wrote:To make a bootloader, you need machine code. Javascript doesn't compile to anything such like C\C++ does. Javascript is just a script which is interpreted at runtime. If you wanted to make a bootloader with JavaScript, you would have to make a compiler which compiles the JavaScript to machine code.
However you could make a kernel with JS if you really wanted to, although it would be easier(IMO) to just learn C and do it in C.
Well, that's what I was hoping Spidermonkey would do for me (that's written in C/C++.)
SpiderMonkey doesn't compile JS if that's what you were hoping... all it does is interprets it.
If you were hoping that you could sort of "boot" SpiderMonkey and use it to run your JS, think again. SpiderMonkey needs a system to run off.
I suggest learning C (if you don't know it) - the syntax isn't too different from JS.
I have a system for it to run off of. My computer is a 3.0GHz i7. I think that's a plenty powerful system. I can just compile Spidermonkey and dd it to a floppy. That should do the trick. I would use C, but it's hard.
Thanks for all the advice so far, guys!
Re: Javascript Kernel
Posted: Sat Jun 15, 2013 1:01 am
by Kazinsal
QuentinRain wrote:I have a system for it to run off of. My computer is a 3.0GHz i7. I think that's a plenty powerful system. I can just compile Spidermonkey and dd it to a floppy. That should do the trick.
You have literally no idea how low-level systems programming and architecture works. I will put five thousand dollars on this plan of yours not working.
Re: Javascript Kernel
Posted: Sat Jun 15, 2013 1:02 am
by QuentinRain
Blacklight wrote:QuentinRain wrote:I have a system for it to run off of. My computer is a 3.0GHz i7. I think that's a plenty powerful system. I can just compile Spidermonkey and dd it to a floppy. That should do the trick.
You have literally no idea how low-level systems programming and architecture works. I will put five thousand dollars on this plan of yours not working.
Yeah, well I'll see your $5,000 and raise you another $10,000!
Re: Javascript Kernel
Posted: Sat Jun 15, 2013 1:03 am
by zhiayang
I see your $0x2710 and raise you $0x10000.
Re: Javascript Kernel
Posted: Sat Jun 15, 2013 1:03 am
by BMW
If you REALLY wanted to do this, the easiest way (IMO) would be to make a really basic kernel in C which has a JavaScript interpreter/executer built in, then get it to execute your JS.
However, making a JS interpreter is a big task, and you would have to learn C anyway, and making a OS in JS would kill performance.
QuentinRain wrote:
I have a system for it to run off of. My computer is a 3.0GHz i7. I think that's a plenty powerful system. I can just compile Spidermonkey and dd it to a floppy. That should do the trick. I would use C, but it's hard.
Not sure if you are trolling or not...
What I meant by system was a kernel. E.g. in Firefox, it runs off Windows or Linux or whatever. If you compile SpiderMonkey and dd it to a floppy, it would in no way work. You would be compiling it with all the Windows/Linux system calls etc in it, which would not work without the OS.
I suggest you research low-level programming and architecture.