Raphael S.Carvalho's Programming Blog

raphael.scarv@gmail.com

"A programmer that cannot debug effectively is blind."

Tuesday, December 11, 2012

Unknown Title

Well, it's been a long time since I posted on this blog. So I felt engaged and excited to write another post.
I'm not sure if you know, though my main area of interest is kernel development and low-level languages like Assembly.
Nonetheless, I also love C as it's the lingua franca of programmers around the world.
C language does provide a syntax which makes it easy both to learn and read other people's source code.
Believe me, that's one of the most beautiful things in the field of computer science (At least I think so).

My opinion about the Free Software movement:
As we know, millions of people contribute for free software projects.
The reason for contributing towards a project is that you share values with the project's ethos. Programming isn't necessarily a job, it's often a hobby.

Getting Started in the Linux Kernel:
In the past few weeks I started studying the Linux Kernel. By the way, the Linux kernel development book is one of the best books which approach the Linux internals.
You should take a look into it :)

My own hobby-purpose kernel:
I have also been designing my own kernel. By reading the aforementioned statement you could ask me:
Aren't you reinventing the wheel?
Not at all, creating your own kernel gives an in-depth knowledge that would not be possible to get without doing that.

How do I get started?
There are lot of free Operating System courses on the internet, and they do their work very well.
Taking OS courses may reduce the time you work on "useless" things, such as: Configuring the GDT (Global Descriptor table), among other things.
If you feel interested, I would recommend the 6828 MIT Operating system course. It's a free and open course for everyone else to play.

Follow the link:
http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-828-operating-system-engineering-fall-2006/index.htm

I hope you like it.
Raphael S.Carvalho <raphael.scarv@gmail.com>

Saturday, November 17, 2012

Address Space Layout Alternatives

So, I enrolled myself in a course provided by MIT opencourseware. It has been an enjoyable course so far, though I found myself overwhelmed.

Challenge! Write up an outline of how a kernel could be designed to allow user environments unrestricted use of the full 4GB virtual and linear address space. Hint: the technique is sometimes known as "follow the bouncing kernel. Finally, think about and describe the advantages and disadvantages of such a scheme in terms of flexibility, performance, kernel complexity, and other factors you can think of.

* Question:
"In your design, be sure to address exactly what has to happen when the processor transitions between kernel and user modes,"
* Answer:
There are two ways in which processor transitions between kernel and user mode.
1 - Interruptions
    - Hardware
    - Software (System call)
2 - Call Gates

* Question:
"and how the kernel would accomplish such transitions."
* Answer:
1 - Also note that for the question to make any sense, "unrestricted use of the full 4GB virtual and linear address space" needs to be considered a typo and should be replaced with "unrestricted use of *almost* the full 4GB virtual and linear address space".

2 - It's impossible because the GDT and IDT (which should not be considered part of the process) must be in the virtual address space.
    * For IDT, GDT, TSS and SYSCALL/SYSEXT the CPU uses linear addresses.

It also would have to reload the CR3 register with the kernel page directory's physical address.
Consequently, flushing the TLB (Translation lookaside buffer) and loading the kernel address space.

* Question:
"Also describe how the kernel would access physical memory and I/O
devices in this scheme,
* Answer:
The kernel could map virtual addresses into the same physical addresses,
so that access to memory would occur as if "paging "wasn't enabled".
In fact, it might use I/O instructions normally since the processor is in the supervisor mode.

* Question:
"and how the kernel would access a user
environment's virtual address space during system calls and the like."
* Answer:
Kernel address space is the main responsible to allocate a page structure, then it could access
the user environment's virtual address space by looking into its respective page directory.

- Conclusion:
First of all, it increases the kernel complexity significantly, and reduces the performance in orders of magnitude.
However, it improves the kernel flexibility since it might address memory as if "paging was disabled".