Javascript Kernel

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.
QuentinRain
Posts: 8
Joined: Fri Jun 14, 2013 11:29 pm

Javascript Kernel

Post 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!
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Javascript Kernel

Post by iansjack »

How are you going to interpret the Javascript? Have you written a bare-metal interpreter? What language did you use for that?
QuentinRain
Posts: 8
Joined: Fri Jun 14, 2013 11:29 pm

Re: Javascript Kernel

Post 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...
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: Javascript Kernel

Post 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?
Last edited by zhiayang on Sat Jun 15, 2013 12:51 am, edited 1 time in total.
User avatar
BMW
Member
Member
Posts: 286
Joined: Mon Nov 05, 2012 8:31 pm
Location: New Zealand

Re: Javascript Kernel

Post 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.
Last edited by BMW on Sat Jun 15, 2013 12:51 am, edited 1 time in total.
Currently developing Lithium OS (LiOS).

Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
QuentinRain
Posts: 8
Joined: Fri Jun 14, 2013 11:29 pm

Re: Javascript Kernel

Post by QuentinRain »

requimrar wrote:Beginner_Mistakes
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...
QuentinRain
Posts: 8
Joined: Fri Jun 14, 2013 11:29 pm

Re: Javascript Kernel

Post 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++.)
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: Javascript Kernel

Post by zhiayang »

QuentinRain wrote:
requimrar wrote:Beginner_Mistakes
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.
User avatar
BMW
Member
Member
Posts: 286
Joined: Mon Nov 05, 2012 8:31 pm
Location: New Zealand

Re: Javascript Kernel

Post 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.
Last edited by BMW on Sat Jun 15, 2013 12:57 am, edited 1 time in total.
Currently developing Lithium OS (LiOS).

Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: Javascript Kernel

Post 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.
QuentinRain
Posts: 8
Joined: Fri Jun 14, 2013 11:29 pm

Re: Javascript Kernel

Post 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!
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: Javascript Kernel

Post 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.
QuentinRain
Posts: 8
Joined: Fri Jun 14, 2013 11:29 pm

Re: Javascript Kernel

Post 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! ;)
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: Javascript Kernel

Post by zhiayang »

I see your $0x2710 and raise you $0x10000.
User avatar
BMW
Member
Member
Posts: 286
Joined: Mon Nov 05, 2012 8:31 pm
Location: New Zealand

Re: Javascript Kernel

Post 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.
Currently developing Lithium OS (LiOS).

Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
Locked