March 12th, 2008 Michael Clarke
This week I’ve been on the Solaris Internals course at work and I’ve already learnt an awful lot about how Solaris deals with processes (including threads and light weight processes), system calls, scheduling, memory management (hardware and software), paging and swapping! All of this and it’s only 3 days in.
However, one of the things about this is I’ve very quickly realised how far I’ve still got to go with MouthOS and how much I’ve still got to learn. A great example of this is in regards to memory management… Intel, it would appear, offer two different methods of dealing with memory - segmentation and paging. It was my impression that you could basically choose which you wanted to use when writing your OS and so I decided to use segmentation for MouthOS initially.
Unfortunately the Solaris Internals course has given me a bit of a rude awaking - I’ve realised that in order to use Paging you must first enable Segmentation. However, there are many different ways you can section off your RAM before you even get to paging….
Flat Model (which is what I’m going to be changing to) is where you basically say all of the address space (i.e. 32Bit address space is 4GBytes, even if you system only has 2GBytes) can be used for anything with no restrictions on who can do what - i.e. there is no hardware translation of memory accesses in regards to segments. When I say ‘no translation’ that’s not strictly true… because you still have to specific a segment in the GDT the processor will basically prefix every memory address with 0, so the effect is that there is no ‘translation’ but at the same time there is!
There is obviously a problem with this - if I have a process running, and paging isn’t enabled, and I try and access more than 2GBytes of memory from my process it won’t actually physically exist. However, because there are no checks - no exceptions will be raised and your system is likely to fall over pretty quickly. If you’ve got paging going on then there is no problem, a page fault will be generated and the kernel can load in the appropriate page somewhere else.
Protected Flat Model (which is what Solaris, Linux etc use) is where you limit the segment size to the size of the Physical Memory. In other words, instead of providing your processes with the fully available address space, you provide them with an address space that matches the amount of physical RAM. As such, if anything tries to access a memory address greater than the physically available memory a general protection exception will fire and the kernel will be able to deal with it.
Generally when using the Protected Flat Model you would have 4 sections. 2 of these sections will be in Ring 0 and two will be in Ring 3. Ring 0 is the Kernel ring and the two sections will define the text and data sections. It will start at memory location 0 and proceed to the maximum memory location available in physical memory. I.e. 0 -> 2MBytes. The LDT in Ring 3 (user space) will start at 0 + size of kernel and will end at the maximum memory location available in memory.
For example, assuming the Kernel is 2MBytes and the available RAM is 2GBytes, the LDTs would be along the following lines:
Section Ring Protection Base Offset
TEXT 0 r-x 0 2GBytes
DATA 0 rwx 0 2GBytes
TEXT 3 r-x 2MBytes 2GBytes
DATA 3 rwx 2MBytes 2GBytes
This prevents anything which runs in Ring 3 from ever touching the first 2MBytes of memory where the Kernel is stored, however, the Kernel running in Ring 0 can access its own structures and text, and that of Ring 3 also.
Multi-Segment Model basically uses a similar principle to the protected flat model except it adds yet more sections, this time as many as you could care to imagine - each one defining text, data, bss, stacks, heap sections which are available for individual processes and even thread within a process.
Once you’ve sorted out your segmentation, reading my ‘Intel 64 and IA-32 Architectures Software Developer’s Manual’, enabling paging seems to be relatively simple. From what I can tell I need to setup a page directory, pass the memory location of this page directory to cr3 (control register 3 - which actually acts as a context register) and then set bit31 of cr0 (control register 0) to 1… dah da! Oh, and then of course I’ll have to sort out all the other entertaining things such as a page_fault() handler for when we get a request for a page that isn’t currently in memory - however, for the moment I think I’ve got quite enough to be getting on with.
So far my beautiful “proc_enable_paging” assembly routine is looking a little bare….
proc_enable_paging:
mov eax, cr0
and eax, 0x80000000 ; Set bit 31 (PE) = 1.
mov cr0, eax
ret
Posted in MouthOS, Operating Systems | No Comments »
March 10th, 2008 Michael Clarke
I was reading my managers blog this morning and he has done a short post on his visit to the Shell sponsored Wildlife Photographer of the year Exhibition. I was looking at some of the pictures that he’s linked to from his visit and I have to admit that I think this one of a herd of Zebras running is pretty amazing so I thought I’d link to it - it’s well worth a view 
Posted in Uncategorized | No Comments »
March 10th, 2008 Michael Clarke
This morning I am about to go on the week long Solaris 10 Internals course at Sun. This is a course that I’ve been looking forward to for some time as it goes into detail about the implementation of the Solaris 10 Kernel - including things such as memory management, file systems, multi-tasking support etc. This started me thinking how great working for Sun really is…
- Everyone at Sun is really friendly and always willing to help and tell you about (and ask for feedback regarding) their own little (or sometimes rather larger) projects.
- The training provided is excellent - so far in a year I’ve been on four courses starting with a mid-range Serengeti course, then the Solaris Intermediate and Solaris Advanced course, and then the high-range Starcat course. I’ve got another two courses to go, the first one being the Solaris Internels and the other one I’ve got to decide on still!
- Sitting where I sit I get prime access to some of the highest level support engineers in Sun - and some of the conversations are immense - but the really great thing is the engineers are always willing to accept suggestions and comments - even from me and my peers - lowly interns.
- Working mostly in the Lab we get access to all of the latest Sun equipment usually before it has been released, and quite often beta versions during the development cycle before the products have even been announced.
- There are always opportunities available - if you want to have a little go at something else for a while you’re encouraged to do so - take for example my recent DTrace work thanks to Paul Humphreys (my manager) and Jon Haslam (one of the DTrace engineers) - it’s not my job, but they’re both being really supportive and offering help and advice - not many jobs you get that sort of support and encouragement…
- You get to travel. Recently I went to our Paris lab in France. Matt has been to Sweeden. Fraser is about to go to Germany and Robin and David are both scheduled to go abroad at some point during the rest of the year - not bad for an internship.
- You really are considered to be a part of the team - not just ‘the students’…. well, we are referred to as ‘the students’ some times, but it doesn’t hold any prejudice… We’re often asked our opinions and suggestions on subjects concerning the lab (and indeed the future of the lab when we’ll have left) and we’re left to (for the most part) manage our workload ourselves - we’re not micro-managed
Thinking about it, I should really have posted this some time ago whilst we were looking for new interns for next year. Unfortunately (or should that be fortunately?) we’ve now filled the three positions for next year - surprisingly all from Aber, so I’m a little bit late… However, I’m sure next years students are going to have a great time in the lab (just like we have).
If you’re interested in working for Sun (as an intern) there are still opportunities available in other departments. I’m not sure of a specific page but if you need/want more info leave a comment and I’ll get you the info… Otherwise, if you’re after a job more permanently then you should visit http://uk.sun.com/aboutsun/employment/
Posted in Solaris, Work | No Comments »
March 2nd, 2008 Michael Clarke
Yesterday I went looking for a new car. After some time browsing Auto Trader I found a truly amazing car. It was a 2.0L P’ Reg Vectra Saloon in Black with Electric Mirrors, Electric Windows, Air Con, CD Multi Changer, Traction Control, Factory Alarm and Immobiliser, Power Steering and only 80,000 miles on the clock. The most amazing thing though was the price - £695!
So, off I went to Flint (about 50 minutes drive from home) to test drive this car. My initial inspection revealed no faults and everything was looking good. The car was in immaculate condition inside and out - could this be too good to be true? Unfortunately the answer to this question was - yes, it was.
After the inspection I got ready for the test drive. At first the car needed to be jump-started because the battery was a little low (fair enough - it has obviously been standing for a while). As I left the garage the car felt a little jerky - initially I suspected this was simply because I wasn’t used to the clutch, however it very quickly became apparent that it was something more serious when after about 2 minutes into the drive the car broke down!
My first thoughts were - oh it’ll just be low on petrol - no, it had almost a quarter of a tank. Perhaps the battery was the problem still. After a few attempts to push start it, it became quite apparent that I needed to call the garage so they could bring their battery pack and get the car going again. So 5 minutes later the guy from the garage arrived… could he get it going? No. I’m still not entirely sure what was wrong with it, but I suspect it’s probably a fault with the immobiliser or the starter motor - either way, I ended up going home without a new car… never mind! It just shows how important a test drive is when buying a car.
So, I’m still on the lookout for a 1.8/2.0 litre Vectra/Mondeo with reasonable mileage if anyone’s got one that they’re selling. Even better would be a MG ZT if anyone has one of them? No? Ah well, pity. For the moment I’m going to borrow one of my parents cars that they’re not using at the moment - a Fiat Marea Weekend, not quite what I was looking for - but never the less a car that is big enough for my needs 
Posted in Cars | 2 Comments »