Page 1 of 2

a Python based OS

Posted: Sat Dec 10, 2011 6:31 am
by arming
Hi, I'm a newbie in OS development :D .

Well, I want to create a Python based OS. ¿How can I do it? ¿Has the kernel to be a Python interpreter?

Thanks!

Re: a Python based OS

Posted: Sat Dec 10, 2011 11:41 am
by arming
berkus wrote:No, start with learning to read.
Hey, what's the matter with you? I have asked a question, excuse me if my english is not as good as yours, Shakespeare, but I am learning this language.

Re: a Python based OS

Posted: Sat Dec 10, 2011 12:07 pm
by Brendan
Hi,
arming wrote:Well, I want to create a Python based OS. How can I do it? Has the kernel to be a Python interpreter?
If you want to nail some wood together, the best tool to use would be a hammer or maybe a nail-gun. You can try to use a tomato but even if you're very skilled a tomato isn't the right tool for the job and you'll probably get nowhere. A tomato is excellent for making pizzas though (nobody would make pizza with a hammer).

For boot code, kernels, device drivers, etc, Python is not the right tool for the job. It'll probably take you around 5 years of working on your OS before you finally get to work on something where Python might be the right tool.


Cheers,

Brendan

Re: a Python based OS

Posted: Sat Dec 10, 2011 12:37 pm
by arming
please, don't take me for a fool, I have read Operative Systems by Tanenbaum and I had done a nano-kernel in C, so I'm a newbie but I am not an ignorant.

The thing that I'm asking is if it's possible to do a operative system based in Python. Obviusly, I m not speaking about an operative system full done in Python. For example, the bootloader in ASM, a nano-kernel/Python interpreter in C and the GUI, apps,.... in Python. Why not?

Re: a Python based OS

Posted: Sat Dec 10, 2011 1:06 pm
by Kevin
I wouldn't want to restrict my userspace to Python, but if you think it's a good idea to make a Python interpreter in the kernel the only way to execute programs - why not. Keep in mind that Python doesn't quite get the same performance as C, but for most programs it doesn't matter much.

A bit more conventional approach would be to have a normal C userland, but make a Python port one of the first programs and then use it for everything where it has clear advantages over C.

Re: a Python based OS

Posted: Sat Dec 10, 2011 1:07 pm
by jnc100
There are three problems with using python for OS development. Firstly, it is interpreted, so you need some interpreter loaded first (usually written in another language e.g. C) before you can run any code. Second, it has a large runtime support library, all of which would need to be implemented prior to running any useful code. Finally, it does not support any of the functions to work directly on bare hardware that you would need in an OS, e.g. direct read/writes from certain memory locations, reading/writing certain registers, port in/out, special opcodes like lgdt, iret etc.

If you are still keen, I see three ways you could possibly do this, listed in order of increasing difficulty:

1) Write a normal kernel in C including stuff like memory and process management, IPC, drivers for NICs, input devices and display adapters and also a TCP/IP stack with all the usual syscalls, then have the first, and only, process run be a python interpreter which starts the rest of user-mode (shells, GUIs, applications etc). You could then use a stock python interpreter with minimal modification.

2) Write a minimal kernel containing only memory management, and then start a cut-down python interpreter which doesn't support fancy run-time stuff (XML, network + file IO, string functions, printing to screen etc) but does allow direct access to io ports and memory with certain special functions. This could then run python scripts for device drivers, schedulers etc, although they would obviously suffer the performance problems of interpreted code. Once the system is running properly, you would then start a fully-featured python interpreter for the rest of the system.

3) Write a python to native code compiler, and then write the whole system (bar the boot loader) in python which then compiles to machine code with your compiler.

Please note that the last option is _very_ difficult and will take you a long time, furthermore as there are few other people trying to do it, you are unlikely to be able to ask for help and will have to solve any and all problems yourself. It is for these reasons that we recommend using C/C++ (availability of tools, example code and a large support base).

Regards,
John.

Re: a Python based OS

Posted: Sat Dec 10, 2011 3:13 pm
by guyfawkes
Here is a simple example of writing a python bootloader

Call this Python.inc

Code: Select all

;==============
; Macro Python 
;==============

;_______________print_________________
macro print String{
	local a
	local Done
	local ForEachChar

		mov si,a
		mov ah,0x0E	  ; for int 0x10: write chars in teletype mode
    ForEachChar:		  ; begin loop
		lodsb		  ; load al with what si points to, increment si
		cmp al,0x00	  ; if char is null...
		je  Done	  ; .. then break out of the loop
		int 0x10	  ; call interrupt 0x10 (BIOS: print char)

		jmp ForEachChar   ; jump back to beginning of loop
	a db String,13,0
	Done:
}

;_______________sys.exit_________________

macro sys.exit{
       jmp $
}

Call this PYboot.asm

Code: Select all

org 0x7C00 
use16
include 'Python.inc'

      print "Boot Python OS"
      sys.exit

times 510-($-$$)  db 0
dw 0xaa55
Assemble with fasm
fasm PYboot.asm PYboot.bin <enter>
Test in qemu by running as a floppy image

Re: a Python based OS

Posted: Sat Dec 10, 2011 3:44 pm
by Kevin
*lol*

Nice try. ;)

Re: a Python based OS

Posted: Sat Dec 10, 2011 5:30 pm
by arming
Thanks! It sounds difficult but I'm going to try it.

Re: a Python based OS

Posted: Sat Dec 10, 2011 6:01 pm
by arming
and do you know any simple Python interpreter i C? 'cause I have looked for a Python Interpreter in C but the official one is very... heavy. I don't know.

Re: a Python based OS

Posted: Sat Dec 10, 2011 6:43 pm
by guyfawkes
What about http://www.tinypy.org/

Also there was a python OS that was started from the ash's of v2os
http://unununium.org/

Re: a Python based OS

Posted: Sat Dec 10, 2011 7:19 pm
by ACcurrent
Unless you want to rewrite the entire python stack I would not advise it.

Re: a Python based OS

Posted: Sat Dec 10, 2011 7:45 pm
by Rusky
Why would you need to rewrite anything? Just port an existing Python interpreter- most of the libraries are written in Python itself and the ones that aren't are written in C.

Re: a Python based OS

Posted: Sat Dec 10, 2011 8:13 pm
by ACcurrent
Porting is not as easy as you think. You would need to first create all the OS parts such as MMUs (may not be needed), Driver manager, context switching, etc. And then you would port TinyPy. Mind you the code in tiny py is darn messy and not as portable as you think. You would probably need to port newlib and then your python OS would not be a python OS!

Re: a Python based OS

Posted: Sun Dec 11, 2011 4:22 am
by Combuster
Summarized: If you can't figure how to go for a python OS on your own, don't. (Where python may be replaced with any higher level language.)