DCPU-32 - Specification and Implementation

All discussions related to the DCPU and in game hardware (equipment, vehicles)

DCPU-32 - Specification and Implementation

Postby Longor1996 » Sun Sep 29, 2013 7:20 pm

First off:
This is NOT a proposal to replace the existing DCPU-16!
This is merely an experiment to look at and use for testing!

Actual Post:

Hello everyone.

This is the first time I am posting something, so please be nice.

After a week of coding and thinking, I came up with a simple specification for a 32-Bit DCPU.
You can read the specification here. (Note that some things may be missing and are a bit confusing)

After another week of coding, I can also give you a fully working Java-based implementation of it.
You can download it here (OUTDATED+BUGGY). Be aware that it is a library file, and thus not runnable.
You need to implement it into another application for it to work.
The source-code is also included to read trough and experiment with.
The code is very messy at some places, so brace yourself for a lot of confusion.

Please tell me what you think and what I might add to the specification.
Also, if you find mistakes/errors/bugs in some of the here provided content, please tell me here.


Note that I made this in my free-time, for fun and learning purposes!

- Longor1996

PS: This post was written from a tired Java-coder with a headache, please forgive the bad grammar!
Last edited by Longor1996 on Mon Jan 13, 2014 3:59 pm, edited 1 time in total.
User avatar
Longor1996
 
Posts: 14
Joined: Mon Aug 19, 2013 11:00 pm

Re: DCPU-32 - Specification and Implementation

Postby lamogui » Tue Oct 01, 2013 6:59 pm

Post these into hardware section please !
please correct my english errors
lamogui
 
Posts: 42
Joined: Mon Aug 19, 2013 5:33 pm

Re: DCPU-32 - Specification and Implementation

Postby adam » Tue Oct 01, 2013 8:53 pm

Done
adam
 
Posts: 113
Joined: Tue Aug 20, 2013 11:58 am

Re: DCPU-32 - Specification and Implementation

Postby Longor1996 » Mon Jan 13, 2014 3:58 pm

I am kind of sad that I get no feedback on this.
Let me just update the specification...

- Longor1996
#define Longor1996 "Programmer that loves to write small tools for quick usage. He writes code mainly in Java, but understands C++ and similar languages as well. Is also reading science articles/books/papers/news since he is 5 years old".
User avatar
Longor1996
 
Posts: 14
Joined: Mon Aug 19, 2013 11:00 pm

Re: DCPU-32 - Specification and Implementation

Postby Zardoz » Mon Jan 13, 2014 7:18 pm

How is supposed to work the stack ?? If I read correctly, you are using a fixed size, internal stack of 256 entries of 32 bit ?? If its true, it will make the life more hard to who desires to make a OS in these CPU, or simply use the stack as a stack to do some algorithm.

Also I recommend to you, to add a SLEEP mode, were the CPU can wake if receives a interrupt.

If you drop the HWI/HWN/HWQ/HWT, it could be implemented in the Virtual Computer.
Yep, I have a blog : http://zardoz.es
Emulator DCPU-16 VM
User avatar
Zardoz
 
Posts: 359
Joined: Mon Aug 12, 2013 8:54 pm
Location: Spain

Re: DCPU-32 - Specification and Implementation

Postby Longor1996 » Mon Jan 13, 2014 7:36 pm

Oh man.. I forgot to add the SLEEP instruction to the specification.
I already implemented the SLEEP instruction, and the stack actually doesn't have a limit.
I simply forgot to remove the text saying that the stack has a limit.

And about removing the HW* instructions:
I am working on that. Just thinking about how I should go about it.
Sure is that I will replace them with 'IN port' and 'OUT port'.

Let me just correct some things in the spec... Corrected some things.

Have a nice day.

- Longor1996
#define Longor1996 "Programmer that loves to write small tools for quick usage. He writes code mainly in Java, but understands C++ and similar languages as well. Is also reading science articles/books/papers/news since he is 5 years old".
User avatar
Longor1996
 
Posts: 14
Joined: Mon Aug 19, 2013 11:00 pm

Re: DCPU-32 - Specification and Implementation

Postby Zardoz » Mon Jan 13, 2014 11:00 pm

IN & OUT have sense if you are working with a 16 or 8 bit CPU, were you have a very limited address space. With a 32 bit address space, you can have the luxury of reserving, for example, the last 16 MiB of the address space for devices (from 0xFF000000 to 0xFFFFFFFF).
Yep, I have a blog : http://zardoz.es
Emulator DCPU-16 VM
User avatar
Zardoz
 
Posts: 359
Joined: Mon Aug 12, 2013 8:54 pm
Location: Spain

Re: DCPU-32 - Specification and Implementation

Postby Longor1996 » Tue Jan 14, 2014 2:35 pm

Zardoz wrote:IN & OUT have sense if you are working with a 16 or 8 bit CPU, were you have a very limited address space. With a 32 bit address space, you can have the luxury of reserving, for example, the last 16 MiB of the address space for devices (from 0xFF000000 to 0xFFFFFFFF).


This is probably a dumb question, but: Reserved for what?
I am not a CPU architekt, and I never gave thought on how computers communicate with the hardware on Assembler-level in a 32-Bit System.
The only thing I know about is hardware-interrupts, and how they basically work.

Care to explain or give a link to a helpful article? Thanks in advance.
(I will try to get information on the os-dev website too)

- Longor1996
#define Longor1996 "Programmer that loves to write small tools for quick usage. He writes code mainly in Java, but understands C++ and similar languages as well. Is also reading science articles/books/papers/news since he is 5 years old".
User avatar
Longor1996
 
Posts: 14
Joined: Mon Aug 19, 2013 11:00 pm

Re: DCPU-32 - Specification and Implementation

Postby Zardoz » Tue Jan 14, 2014 4:15 pm

First, you must understand that you must separate the computer architecture from the CPU. You can have the same computer architecture running with a different CPU. The computer architecture defines what and how works the devices in the system, how many ram, at what address they are, etc...

I going to try to explain it at a basic level so all can understand, and I'm sorry if my poorly English don't allow me to do that.

What is a computer :
In a schematic representation, is this :
Image

Clearly we can see 4 things here : The CPU, the memory, the I/O devices and the system bus.
The CPU DON'T KNOW how many or what are the devices or how talk to they. It only knows that can read & write data in addresses. Also, is reading instructions from the address pointed by the Program Counter register and executing it.

So, how can use the devices ?

As you can see, the devices are attached to the system bus, like the Memory, so why not use addresses to read or write data to the devices ? Well, this is know as Memory Mapped I/O. It's usual reserve a range of addresses were the devices will be placed, as we not like to have devices address in middle of the Memory blocks, as this make more complex programming and building the machine. We only have a problem, that is that you are losing potential memory addresses to talk with the devices. If you are using a 32 or 64 bit CPU you can spare this loss, as there a lot of address space, but this is a big problem for 8 and 16 bit CPUs were you have a very little address space (256 bytes in 8 bit cpus and 64KiB in 16 bit cpus), so you are being limited a lot your max possible memory and how many devices could do have. There is tricks like banking, but this becomes slow and complex.

Another solution is having a separate address bus for only devices. To read & write data to the devices you uses special instructions like IN and OUT instructions that uses these special address bus for devices. In this case, the address is called "Port", and we have what is called Port Mapped I/O.

The Port Mapped I/O is useful if you are using a CPU that only can generate 8 or 16 bit address, as give you a separate address space for devices (and someone could say that is more clear), but with a 32 bit cpu not have sense.... you have address space of 4 GiB ! You can spare a few MiB in the top of the address space for Memory Mapped I/O and avoid adding special instructions for it, making the CPU more simple.

Interrupts
An interrupt is what the name says. Interrupts what is doing the CPU to doing other thing.
The CPU interrupts comes from two possibles sources :
- Software (INT instruction)
- Hardware interrupt (toggling a interrupt signal)

When the interrupt happens, the CPU will jump to another place, and begin to execute different code. Were and/or what does will depend of the interrupt message (INT parameter or a value that the CPU will read from Data bus when the interrupt signal is toggle).

The Hardware interrupts are usually used to signal to the program (or the OS), that something has append and that need to check it. Software interrupts are usually used as a call method to the OS functions that expose to the programs.

Edit : More info here : http://en.wikipedia.org/wiki/Memory-mapped_I/O
Yep, I have a blog : http://zardoz.es
Emulator DCPU-16 VM
User avatar
Zardoz
 
Posts: 359
Joined: Mon Aug 12, 2013 8:54 pm
Location: Spain

Re: DCPU-32 - Specification and Implementation

Postby Meisaka » Wed Jan 15, 2014 8:40 am

I would like to point the fact that is possible to have something like the DCPU16's HWx instructions in actual hardware. They would not go directly to the hardware, instead they would go to a hardware controller that handles counting/enumerating devices and assigning them ID numbers (addresses). At startup, the hardware controller would count all the attached devices (and save that value for HWN) while at the same time assigning them sequential addresses (used by HWQ/HWI).

The resulting system would something like this:
Image

Now because the original DCPU16 spec says nothing about how the hardware is connected to the CPU, it would be very plausible that all kinds memory mapped IO and virtual memory operations are happening with HWx instructions, but it is kept so transparent that the program has no idea this is happening.
The DCPU16 spec also does not say how long this would take at startup, it could take (for example) 2 seconds which is 200000 cycles at 100kHz, which would be plenty of time.
User avatar
Meisaka
 
Posts: 14
Joined: Thu Sep 12, 2013 4:35 am

Next

Return to Hardware

Who is online

Users browsing this forum: No registered users and 1 guest

cron