Page 1 of 1

os in python?

Posted: Mon Dec 06, 2004 1:49 pm
by n0other
Hi, I'm familiar with python/php programming, learning asm/c at the momment.. So one day I found http://unununium.org/ and was really impressed. Started reading stuff then, got an idea of trying to make something myself, but I just cant understand the consepts of os written in interpreted language.
Could someone explain the boot process up to a working shell?
When the interpreter comes to work and so on. Thanks for replies.

Re:os in python?

Posted: Mon Dec 06, 2004 2:12 pm
by koni
hi,

there are a few ways to go, one for example: you can implement a virtual machine (like java does), which executes bytecode-programs. these bytecodes are produce by parsing the source code to a syntax-tree (compiler also produce a syntax-tree to compile the program).... so the virtual machine fetches a instruction from the bytecode and execute it. the instruction itself is a function call to a native code routine (a virtual instruction).

myself: i'm also trying to design a operating system written and interpreted in completly lisp... lisp has a great notation form! ;)

Re:os in python?

Posted: Tue Dec 07, 2004 3:29 am
by Pype.Clicker
And, among other things, it has C wrappers that offer a kind of "system" object that performs ports and memory I/O ...
static PyMethodDef IoMethods[] = {
{"inb", inb, METH_VARARGS,
"Input a byte."},
{"inw", inw, METH_VARARGS,
"Input two bytes."},
{"inl", inl, METH_VARARGS,
"Input four bytes."},
{"outb", outb, METH_VARARGS,
"Output a byte."},
{"outw", outw, METH_VARARGS,
"Output two bytes."},
{"outl", outl, METH_VARARGS,
"Output four bytes."},
{"mem_to_string", mem_to_string, METH_VARARGS,
"Construct a string from bytes anywhere in RAM."},
{"string_to_mem", string_to_mem, METH_VARARGS,
"Write a string anywhere in RAM."},
{"mem_to_mem", mem_to_mem, METH_VARARGS,
"Copy one block of memory to another, like memmove in C."},
{NULL, NULL, 0, NULL}
};
I'm not sure at all it's easier to write ...
// keyboard.pyx
cdef extern char c_get_key "get_key" ()

def get_key():
return chr(c_get_key())

The core components (scheduler, memory allocation, interrupts management, etc.) seems to be 100% asm ...

Re:os in python?

Posted: Tue Dec 07, 2004 4:16 am
by koni
@n0other: what advantages feature python for os developing? what's special about python?

Re:os in python?

Posted: Tue Dec 07, 2004 7:19 am
by n0other
sorry, I'm a newbie in osdev, can't tell just yet..

Re:os in python?

Posted: Tue Dec 07, 2004 7:47 am
by Solar
The "canon" language for OS implementation is C (with ASM parts). That's where you encounter the least problems with the language, where the tools available support you best, and what the vast majority of documentation will be for.

Not wanting to discourage you, but from my point of view, the only reason for using some other language / language combo can be because you are absolutely fluent in that other language, know it's runtime requirements well, and have at least half a dozen reasons in your mind why you could make a better OS using that language.

If you are a beginner, and would like to write an OS in another (especially interpreted!) language because you don't really know C / ASM and would like to stay with what you already know, you are most likely in for a long and very painful walk.

It can be done. But it is not easier than learning C / ASM.

That's my opinion, one that isn't shared by everyone on this board.

As for the boot process, have you tried the OS FAQ maintained by us lot here?

Re:os in python?

Posted: Tue Dec 07, 2004 9:09 am
by n0other
yeah, but I get Forbidden error when trying to open osfaq

Re:os in python?

Posted: Tue Dec 07, 2004 9:15 am
by KieranFoot
Have u tried again... I dont get any error

Re:os in python?

Posted: Tue Dec 07, 2004 6:06 pm
by aladdin
Python is a high level language, and is designed to be easy to use for high level programming.
but most of OS code is in low level (direct io ...etc), so i think Python won't help ....

its like codding a chip with JAVA , or using PHP to generate assembly code ;p

for Oriented Object OS i think C++ can be a good alternative but i allways preffer C with ASM in kernel developing .

Re:os in python?

Posted: Wed Dec 08, 2004 12:43 am
by mystran
Solar wrote:
Not wanting to discourage you, but from my point of view, the only reason for using some other language / language combo can be because you are absolutely fluent in that other language, know it's runtime requirements well, and have at least half a dozen reasons in your mind why you could make a better OS using that language.
Yup, I agree with this. To write OS code in something other than C, the first thing to do is to get an interpreter, or at least some runtime, running on top of bare hardware. This necessarily means you need to understand both the interpreter and the hardware pretty well.

Basicly, you are going to need a lot of stuff that normal interpreters don't need. The more you want to implement with your language, the trickier it becomes. The easiest thing in many cases might be to write your own interpreter. Even if you didn't, you probably need to know enough that you could.

Re:os in python?

Posted: Wed Dec 08, 2004 4:36 am
by koni
question: can python be compiled to native code?`

when i was desiging my lisp platform (still in development) i split up my project in two pieces:

* the system run-time environment; it's implemented as a hashtable of lisp symbols which represent system variables, lisp task environments, ... this allows to dynamicly lookup or bind symbols at runtime with a value.

* the lisp execution kernel[/]; the lisp source code is parsed and saved to a binary tree structure. normal interpreters do now execute the code, but i transform this binary tree into an acylic graph of little "codechunks". they are linked together by knowing the dependency (dataflow) of these code-chunks. a codechunks only can be executed if all its argument are avaiable.... further there are to queues which hold the ready and waiting codechunks. after execution the codechunk update all dependent codechunks...

i hope you'll understand, but ask if somethink is crazy...

Re:os in python?

Posted: Fri Dec 10, 2004 11:25 am
by ASHLEY4
As Unununium is based on the bootloader from v2os 0.70, maybe you could start there http://www.v2os.cx/

\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.