Ababo's Personal Blog

projects

Toy OS: Revised design

13 Apr 2014

Before starting to deepen in a next iteration of coding I decided to review my previous architectural design. There are my previous design points:

Domains

Storage devices are mounted on a single 64-bit address space. Each device takes some contiguous region (let’s call it domain). It is possible to mount a storage device on arbitrary address (in case if there is enough unoccupied place).

single 64-bit address space

After mounting domain threads resume running. The cheapest function calls are calls inside a domain. They impose no additional overhead than regular C-functions. Inter-domain calls (including kernel calls) are not so cheap (e.g. need to handle caller/callee domain unmount during the call). Still there is no need to serialize in/out data (single address space).

This will not work

As for me the scheme above is very beautiful. Unfortunately it has a hidden defect which make it impossible. There is no simple way to make domain code position independent (PIC). It’s needed to enable mounting on arbitrary address (otherwise there’s no guarantee that two given drives could be mounted simultaneously - their addresses could overlap).

Yes, there are useful techniques and tricks which are widely used in shared libraries. But they don’t work for living code (code which is unloaded and reloaded again). Think about allocating memory. You call malloc and save the returned memory address to some variable. Now the domain gets unmounted and remounted on a different address. Here the code operates absolute addresses so the techniques based on instruction pointer offsets are not working.

The x86_64 could help us here, because of its segmentation capability. Indeed we could dynamically create memory segment for domain we’re going to mount. All domain code addresses are absolute, starting from its beginning. They are implicitly incremented by the segment address inside CPU. But:

Conclusion ---------- The multiple address spaces scheme is unavoidable. Persistence mechanism must be built on top of it. Each domain should occupy its own address space. **P.S.** *I've been reminded of lack of segmentation support in x86\_64 (unlike x86), so all the far pointers stuff mentioned above is not relevant.* **P.P.S.** *Although x86\_64 does not support full-fledged segmentation later x86\_64 CPUs actually support base+offset addressing (for FS and GS segment registers).*