a Python based OS

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.
arming
Member
Member
Posts: 38
Joined: Sat Dec 10, 2011 6:23 am

a Python based OS

Post 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!
Last edited by arming on Sat Dec 10, 2011 11:36 am, edited 1 time in total.
arming
Member
Member
Posts: 38
Joined: Sat Dec 10, 2011 6:23 am

Re: a Python based OS

Post 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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: a Python based OS

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
arming
Member
Member
Posts: 38
Joined: Sat Dec 10, 2011 6:23 am

Re: a Python based OS

Post 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?
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: a Python based OS

Post 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.
Developer of tyndur - community OS of Lowlevel (German)
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: a Python based OS

Post 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.
guyfawkes
Member
Member
Posts: 93
Joined: Mon Jul 18, 2011 9:47 am

Re: a Python based OS

Post 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
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: a Python based OS

Post by Kevin »

*lol*

Nice try. ;)
Developer of tyndur - community OS of Lowlevel (German)
arming
Member
Member
Posts: 38
Joined: Sat Dec 10, 2011 6:23 am

Re: a Python based OS

Post by arming »

Thanks! It sounds difficult but I'm going to try it.
arming
Member
Member
Posts: 38
Joined: Sat Dec 10, 2011 6:23 am

Re: a Python based OS

Post 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.
guyfawkes
Member
Member
Posts: 93
Joined: Mon Jul 18, 2011 9:47 am

Re: a Python based OS

Post 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/
ACcurrent
Member
Member
Posts: 125
Joined: Thu Aug 11, 2011 12:04 am
Location: Watching You

Re: a Python based OS

Post by ACcurrent »

Unless you want to rewrite the entire python stack I would not advise it.
Get back to work!
Github
User avatar
Rusky
Member
Member
Posts: 792
Joined: Wed Jan 06, 2010 7:07 pm

Re: a Python based OS

Post 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.
ACcurrent
Member
Member
Posts: 125
Joined: Thu Aug 11, 2011 12:04 am
Location: Watching You

Re: a Python based OS

Post 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!
Get back to work!
Github
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: a Python based OS

Post 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.)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply