0x10cStandardsCommittee / 0x10c-Standards

0x10c Computing Standards. This repository is intended to contain as many relevant/popular standards as possible.
211 stars 18 forks source link

Standardise the System API #8

Open eXeC64 opened 12 years ago

eXeC64 commented 12 years ago

This is an idea for a way to provide a consistent OS API across various system implementations to improve software portability for the DCPU-16.

Instead of software having to static link large amounts of code or doing some dynamic library magic the method suggested is to provide specific functions at predefined addresses.

For example, provide a standard library "pointer" at a standard memory address and then each function has a specific offset from the address pointed to.

Example: SLP + 0x00 -> malloc SLP + 0x02 -> free SLP + 0x04 -> fopen SLP + 0x06 -> fclose SLP + 0x08 -> fread SLP + 0x09 -> fwrite ...

Note: The functions are not implemented at these addresses, the addresses merely SET PC, actual function address. This way the addresses of them are not dependent on the length of the function.

All functions should be fully defined in behaviour and conform to the ABI. Differing implementations should be interchangeable. If a function is not implemented the SLP + offset address should be set to a specific value ( 0x00 0x00 perhaps? ) so that software can check whether the function is implemented, like: IFE [SLP+0x02], 0

Disclaimer: I am not an expert by any means, this is just the simplest solution I can come up with,

eXeC64 commented 12 years ago

Clarification:

This is aimed at system calls, such as io and memory managment. However, shared libraries could be located using a system call.

0xabad1dea commented 12 years ago

This is a good idea, but you know we're going to bikeshed to death what the library should contain :)

eXeC64 commented 12 years ago

Hopefully it should be fairly clear what is necessary.

If the OS doesn't need to do anything to process the call then it probably doesn't need to be in the api. A shared library would be better suited.

strangeglyph commented 12 years ago

Wouldn't we need a 4 byte offset? Two bytes for the jump to the actual routine, and two bytes to pop the instructions pointer back from the stack?

eXeC64 commented 12 years ago

All it's doing is jumping straight to the function without changing anything. It shouldn't need to touch the stack at all. It's basically an alias for the function, not a wrapper.

Returning to the original address using the stack will be done by the function itself as usual.

kksym commented 12 years ago

Let's assume we implemented some sort of linkable binary format into the standard instead. Not only would this allow people to write their own libraries, assemble them and then they could be used in other projects that are using a different assembler (More discussion here), which may perhaps be more convenient for developers than @eXeC64's proposal where library positions will be obtained through a syscall, but it could also be a nice way to implement a standard library, where the standard library is linked just like any other library.

0xabad1dea commented 12 years ago

If we do go with a standard library, I would like to insist that every function be re-entrant.

enkore commented 12 years ago

I think everyone agrees on that, because everything else would shatter the dream of multitasking, wouldn't it?

Jarvix commented 12 years ago

It should be possible, when interrupts are implemented, to temporarily disable interrupts to prevent something bad to be interrupted. I dont see a feature in adding a LOCK# and implementing mutexes and semaphores :)