Page 108 of 262

Re: What does your OS look like? (Screen Shots..)

Posted: Sat Jun 07, 2014 10:56 am
by AndrewAPrice
That's really cool Bender. I went with a stack machine because it was incredibly easy to generate from an AST, moving some of the complication to the VM.

Actually, interpreting stack byte code is simple (albiet possibly slower because stack machines generally require more instructions to represent the same operation), I want to eventually do JIT compilation. But, being a dynamic language I'd have to do polymorphic inline caching, and that starts to complicate things (for example I can't JIT "add" without knowing if it's a float, int, string, object with a custom operator, etc.)

Re: What does your OS look like? (Screen Shots..)

Posted: Mon Jun 09, 2014 2:41 pm
by AndrewAPrice
A lot of work went into this seemingly simple 'Hello World'.
VM running Hello World
VM running Hello World
helloworld.png (4.28 KiB) Viewed 6791 times
This is the first ever program written in my language Shovel that runs flawlessly on my VM (codenamed Turkey):

Code: Select all

var console = require("console");
var a = 0;
var incrementA = function() {
	a++;
};

while(a < 10) {
	incrementA();
	console.log("Hello world #" + a);
}
Function calls, closures, string manipulation, and calling native code!

Here it is the generated assembly before it assembled into bytecode:

Code: Select all

Function f0
-locals 3
-closures 1
PushString "console"
Require
Store 1
PushUnsignedInteger 0
StoreClosure 0
PushFunction f1
Store 2
Jump l1
.l0
Load 2
CallFunctionNoReturn 0
PushString "Hello world #"
LoadClosure 0
Add
PushString "log"
Load 1
LoadElement
CallFunctionNoReturn 1
.l1
LoadClosure 0
PushUnsignedInteger 10
LessThan
JumpIfTrue l0
.l2
Function f1
-locals 0
-closures 0
LoadClosure 0
Increment
StoreClosure 0
The executable file is 191 bytes (there's redundant metadata that could remove to shrink this.)

Right now, my VM is running as a userspace program in Windows (here's my userspace main.cpp that initialises the VM and runs the above file) - mostly for ease of testing, and porting to bare metal (my goal) should mainly involve re-implementing hooks.cpp.

Still to-do on the VM proper, before I start working on the kernel:
  • Garbage collection is not finished yet - string manipulation generates a lot of junk! Doesn't track when to invoke it.
  • Multithreading and multiple instances of the VM (essential for a multitasking OS.)
  • Standard library for the inbuilt types (like foreach loops over object properties, getting array sizes, etc.)
  • More compiler optimizations.
  • Port my compiler and assembler to Shovel to make a self-hosting tool chain.
I would love to have a JIT compiler one day - but I would rather make a functional OS first with a usable VM before I begin optimizing it.

Re: What does your OS look like? (Screen Shots..)

Posted: Mon Jun 09, 2014 7:53 pm
by CelestialMechanic
Looks good, but how did the "hello world!" of the Shovel source get morphed into "Hello world #" that was pushed in bytecode?

Re: What does your OS look like? (Screen Shots..)

Posted: Mon Jun 09, 2014 8:41 pm
by AndrewAPrice
Oh - I'm sorry. I was experimenting with different code, and posted the wrong change. I've corrected it now.

Edit: If your curious, a simple recursive Fibonacci test shows my interpreted language is about 7x slower than unoptimized C: https://github.com/MessiahAndrw/Perception/tree/master/shovel/tests About 180x slower than optimized C - although I'm suspicious if my C compiler was able to resolve most of the calculation at compile time.

Re: What does your OS look like? (Screen Shots..)

Posted: Sun Jun 15, 2014 5:48 pm
by sortie
I ported the Mono virtual machine to Sortix. I can now execute .NET programs such as the C# compiler MCS which is written in C#. Here I compile and execute a C# hello world program under my operating system:

Image

Re: What does your OS look like? (Screen Shots..)

Posted: Mon Jun 16, 2014 9:15 am
by AndrewAPrice
Awesome sortie - you keep impressing me!

Re: What does your OS look like? (Screen Shots..)

Posted: Fri Jun 27, 2014 6:48 am
by Bender
Finally completed the compiler for my kernel, sample source code:

Code: Select all

class MainClass {
	int volume = 500
	int damage = 300
	string string1 = " Hello, World "
	proc Main {
		LOAD_R0 MainClass->string1
		CALLF MainClass->print
		VM_EXIT
	}
	proc print {
		PUSH R1
		PUSH R0
		.loop:
		LOAD_BYTE
		CMPR R1, 0
		JMPF_E .done
		VM_CALL 0
		JMPF .loop
		.done:
		POP R0
		POP R1
		RETF
	}
	
}
The compiler's crap for now (uses goto everywhere, hacks etc. and is just one cs file), you can get System.ArrayOutofRange exceptions everywhere if you're not careful, and it isn't really HLL yet just something like OO assembly. And in other news the VM can now use ROM disks :), currently it uses the JamesM initrd format, because I didn't bother create a new disk generator yet. :wink:
Screenshots:
Fibonacci Numbers and the hello world program above (first compiled to asm by the compiler, and then by fasm using macros)
Image
I've been thinking of using DynAsm for the JIT part of my VM, as it's also used in LuaJIT and is really easy to work with.

Re: What does your OS look like? (Screen Shots..)

Posted: Tue Jul 01, 2014 5:42 am
by Bender
So today I taught my kernel about inverse trignometric functions (as if I understand them well :mrgreen: ), and here it is, calculating the value of PI using arctan(1 rad)* 4, and showing a bit more FPU instructions.
Image

Re: What does your OS look like? (Screen Shots..)

Posted: Thu Jul 10, 2014 9:19 am
by emadrezvani
its our os:
Image

Re: What does your OS look like? (Screen Shots..)

Posted: Thu Jul 10, 2014 12:15 pm
by Candy
I've got DHCP working now. This is the log from within QEMU:

Code: Select all

iphlen = 20
dhcp: tag=53 len=1
dhcp: tag=50 len=4
dhcp: tag=54 len=4
bootp packet op=1 msgtype=3RTL8139: RxBufPtr write val=0x0248
RTL8139:  CAPR write: rx buffer length 8192 head 0x04b0 read 0x0258
RTL8139: receiver buffer data available 0x0258
RTL8139: ChipCmd read val=0x000c
pktstatus = 02522001
rx packet FFFFFD000428025C length 590
received udp packet from 10.0.2.2:67 to 255.255.255.255:68
ipaddr is now 0A00020F
dhcpserver is now 0A000202
netmask is now FFFFFF00
gateway is now 0A000202
dns0 is now 0A000203
validFor is now 00015180
DHCP: Got IP Address!!! I am now 10.0.2.15
RTL8139: RxBufPtr write val=0x04a0
RTL8139:  CAPR write: rx buffer length 8192 head 0x04b0 read 0x04b0
RTL8139: receiver buffer is empty
RTL8139: ChipCmd read val=0x000d
RTL8139: IntrStatus write(w) val=0x0005
RTL8139: Set IRQ to 0 (0000 e07f)
RTL8139: entered rtl8139_set_next_tctr_time
RTL8139: Set IRQ to 0 (0000 e07f)
I even have DNS, gateway and netmask ready, so I could theoretically start building a route table for TCP/UDP. I'm going to first try to get it to ping (ARP + ICMP) though. This does show that my Ethernet/IP/UDP stack is working far enough to do this, which is good :-D.

I could paste a screenie from the terminal, but it's not quite the showpiece... network internals rarely are.

Re: What does your OS look like? (Screen Shots..)

Posted: Thu Jul 10, 2014 12:52 pm
by AndrewAPrice
Nice work Candy!
Candy wrote:I could paste a screenie from the terminal, but it's not quite the showpiece... network internals rarely are.
I understand. I want to boast about my JIT progress, but visually I have nothing to show. My fibonacci benchmark? "I could do that in C in 5 minutes!"

Re: What does your OS look like? (Screen Shots..)

Posted: Sat Jul 12, 2014 3:24 pm
by ByteBit
Image
Right now you can just move the windows and bring them to the top.
It's a complete real mode OS for now.

Re: What does your OS look like? (Screen Shots..)

Posted: Sun Jul 13, 2014 5:13 am
by zhiayang
After taking a break from actually coding my OS, I've decided to try my hand at a simple VM. Nothing too complex, it's mostly a register machine.
The following code does factorial recursively:

Code: Select all

@main
	move $0x0A -> %r01
	move $0x02 -> %r02
	call @factorial

	copy %rr -> %r03

.loop
	increment %r32
	jump -> .loop


@factorial
	cmpeq %r01, %r02
	branch -> .ret

	decrement %r01
	call @factorial

	increment %r01
	multiply %rr, %r01
	return

.ret
	move $0x2 -> %rr
	return
I would need to get the assembler to somehow link multiple source files together, then after that I can start work on the compiler proper. The VM implementation I have seems a little over-the-top; it can easily support (if I bother to implement it, that is) memory latency and caching... I mean, who intentionally slows down their VM? (I usually run it at 5 cycles/second for debugging)

Another problem is allowing immediate values directly inside opcodes; currently only a certain number of instructions handle immediate values, would be nice if I could cmpgt %r01, $0x2 instead of having to waste a register to store '2'.

Re: What does your OS look like? (Screen Shots..)

Posted: Wed Jul 16, 2014 3:08 am
by crazyender
well, this is my os, it runs Linux binaries

Thins are coming along together

Posted: Fri Jul 18, 2014 1:27 am
by mateuszb
SATA working, basic FAT32 working, native intel graphics also working. Time to work on displaying that mp4 movie :)