some guidance for a stuck newbie

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Starter

some guidance for a stuck newbie

Post by Starter »

Greetings Everyone,
I am new to developing OS's. I started learning only last month from OS concepts by Silberschatz and Galvin. Now I have almost covered the entire book. I would like to find answers to some of the exercises given at the end of each chapter.
I want to develop my own OS also. Towards that end, I started reading Bran's tut on kernel dev. In that i am not able to understand some of the code in GDT section. There are a lot of bitwise operations for untold reasons. I didnt understand that section properly. IDT was much easier and so was the rest of it. I wud also like to know some basic details on x86 machines (very basic) just enough to understand why the assembly is written that way. i do not intend to write any assembly myself. I wud like to know the dev cycle of an OS.

Thanks for ur patience and encouragement.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:some guidance for a stuck newbie

Post by Solar »

Starter wrote: I would like to find answers to some of the exercises given at the end of each chapter.
http://cs.cramster.com/operating-system-concepts-6th-solutions-10-131.aspx could be found by Googling.
Towards that end, I started reading Bran's tut on kernel dev. In that i am not able to understand some of the code in GDT section. There are a lot of bitwise operations for untold reasons. I didnt understand that section properly.
Tell us what exactly you didn't understand, and we can tell you exactly what it's about.
I wud also like to know some basic details on x86 machines (very basic) just enough to understand why the assembly is written that way.
Chapter 3.3 of Art of Assembly explains that nicely.
I wud like to know the dev cycle of an OS.
I don't understand that question. What do you mean with "dev cycle"?
Every good solution is obvious once you've found it.
Starter

Re:some guidance for a stuck newbie

Post by Starter »

I do not understand the gdt_set_gate function. Why is performing AND with 0xFF and sometimes with 0xFFFF?
Thanks for the links. Actually i did google before but i thought cramster was paid service. Stupid of me.
Is it like this for every newbie? Sometimes i have to read thrice before understanding properly.
By OS dev cycle, i meant the route that ppl take before completing dev. There has to be certain common things that everybody does. This should help in creating an initial design. No part shld be recoded fully on addition of other stuff, though some tweakings are normal.

Thanks for the reply. I refuse to give up. I will learn.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:some guidance for a stuck newbie

Post by Brendan »

Hi,
Starter wrote:By OS dev cycle, i meant the route that ppl take before completing dev. There has to be certain common things that everybody does. This should help in creating an initial design. No part shld be recoded fully on addition of other stuff, though some tweakings are normal.
I'm not sure anyone ever completes any OS - the OS just gets bigger and supports more features, more hardware, etc. :)

As for where to start, write a list of features/goals for the project - the design of an architecture specific multi-tasking microkernel can be radically different from a portable single-tasking monolithic kernel.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:some guidance for a stuck newbie

Post by Solar »

Starter wrote: Is it like this for every newbie? Sometimes i have to read thrice before understanding properly.
It most definitely is. ;)
Every good solution is obvious once you've found it.
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:some guidance for a stuck newbie

Post by distantvoices »

welcome to debug sessions darker than night ... mwaaahahaha

Be assured, starter, that it's much reading, more drafting and mostatime thinking thinking thinking. *gg*

May I also recommend you to fetch a download of intels system programming manual? It's like the holy bible for os developers.

Development cycle you want to know? Oh, basically like the one applied to any otto normal software project: planning, implementing,testing, bugfixing,testing,bugfixing ... - planning ... you get the knack, eh?

have a nice evening. :-)
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
User avatar
KrnlHckr
Member
Member
Posts: 36
Joined: Tue Jul 17, 2007 9:16 am
Location: Washington, DC Metro Area
Contact:

Re:some guidance for a stuck newbie

Post by KrnlHckr »

Starter wrote:I do not understand the gdt_set_gate function. Why is performing AND with 0xFF and sometimes with 0xFFFF?
Let me see if I can help with this part. Mind you, I'm not a guru at OSdev by any stretch (I'm rather new at this too).

Basically what is happening with the AND and the hex values is a masking effect. The technique is using a logical operation (AND) and bit shifting ( >> 16 and >> 24) If you have a 32-bit value you can have an (unsigned) decimal of 4294967295. In hex, this is 0xFFFFFFFF. Note that there are two groups of four F's (i.e. 0xFFFF FFFF). A 16-bit value can be up to 65535 and is 0xFFFF. There is a pattern here I hope I'm making clear (and I hope I don't confuse myself in the process). To aid the process, forget about the decimal value --- it will only serve to confuse the issue.

Let's try and wrap our brain around this thing:

11111111111111111111111111111111 (that's 32-bits set in binary)
0xFFFFFFFF (same thing set in hexadecimal)

If you have a hex value, say, 0x12345678, you can use bit shifting and logical operations to "mask" values out of a 32-bit value. This works on 16- or 8-bit values too.

0x12345678 AND 0xFFFF masks the low 16-bits, setting the high 16 to 0. You'd have 0x5678 (think 0x00005678 which is, of course, the same thing).

0x12345678 AND 0xFFFF0000 would mask the high 16-bits, setting the low 16 to 0. You'd be right if you throught 0x12340000. Note the trailing zeros which hold the significant digits 0x1234 != 0x12340000.

That's logical AND. Now for the bit shifts.

Know that 0x12345678 is 10010001101000101011001111000 for the next part.

If you have a 16-bit binary value 1111111111111111 and you shift right 8-bits, you would get 11111111 (or 0000000011111111). The bits move off the right side and are lost forever. (There is a left shift operation I'll show in a second.)

If you take 0x12345678 and shift it right by 16-bits you'd get 0x1234. Why? Look at the binary.

10010001101000101011001111000 shifted 16-bits right is: 1001000110100. (Put in the leading zeros if that helps.) What is 1001000110100? 0x1234

So, to get the high 16-bits you have to shift right. What if you want the low eight-bits of the high 16? Shift right and mask 0xFF.

Shifting right gets you 0x1234, and masked yields 0x34.

If you want the high eight bits of the high 16, you shift 24 and mask 0xFF. If you have a 32-bit number the 24 bit shift will give you what you want, but the mask handles a stray 64-bit curiosity that might lurk.

Whew! :shock: I should write up a doc for this which would be better formatted...

I've attached a simple little C program that demonstrates what I've just rambled on about. I hope this all helps. My suggestion is to read a chapter on the binary and hex number systems and play with my code a bit to understand what the logical operations and bit shift operations do. (I didn't cover logical OR, but a good chapter on this will explain).

HTH,
Sean
Attachments
test.c
(494 Bytes) Downloaded 47 times
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

KrnlHckr... This post was for 2005, why revive such an old topic? :roll:
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
KrnlHckr
Member
Member
Posts: 36
Joined: Tue Jul 17, 2007 9:16 am
Location: Washington, DC Metro Area
Contact:

Post by KrnlHckr »

Brynet-Inc wrote:KrnlHckr... This post was for 2005, why revive such an old topic? :roll:
:oops: Wasn't paying attention to the date.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Brynet-Inc wrote:KrnlHckr... This post was for 2005, why revive such an old topic? :roll:
Either way, from Bran's tutorial this is a bit confusing so we may as well have an explanation.

I never understood any of the GDT/IDT stuff until I had to put a TSS entry into the GDT, and then I messed it up because I didn't understand what was happening.

We ought to have a page in the Wiki to explain (in more detail) some of those concepts, and to fix some of the errors...
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

pcmattman wrote:We ought to have a page in the Wiki to explain (in more detail) some of those concepts, and to fix some of the errors...
http://www.osdev.org/wiki/Descriptors ?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

:oops: Didn't look before I replied...
Post Reply