flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Dex4u 25 Oct 2007, 09:38
This was a great help to me, when i started OS dev:
|
|||||||||||
![]() |
|
ManOfSteel 25 Oct 2007, 12:17
1. a selector is a number representing an entry in your GDT. It's 16 bits long: the first two bits are for the privilege level (RPL), the third is for GDT/LDT, the rest is for the actual entry number (13 bits -- 2^13 = 8192 -- 8192 available descriptors). The most important part for you now is the index, so you can only care about moving the right number to the right segment register.
2. the base and the limit of your GDT. 3. you load your segment registers with valid selectors asking the system - for example - to use a valid data segment descriptor (which describes the data memory segment) everytime it needs to access some data in the memory. 4. AFAIK, you can put your descriptors in any order you wish (eg: null, RM code, RM data, PM-kernel code, PM-kernel data, PM-user code, PM-user data). You can add ones for stack, video memory, etc, or not! You can skip RM code and data if you're never getting back to RM, you can even skip PM-user code and data if your OS will always run in "administrator mode". It's all up to you as long as you don't use the first entry (reserved for null). If you want to flip them, change the selector number accordingly (eg: in "jmp 8h:Start32") and the GDT descriptors as well (the three lines you have after "gdt:"). 5. you don't! you're using 10h right now (which is 16 in decimal, i.e. your third GDT entry -- your data segment descriptor). 6. because bx is used right after that to load ds (the data segment register) with a valid data segment selector (see 5.) pointing to a descriptor describing your data segment. |
|||
![]() |
|
rhyno_dagreat 25 Oct 2007, 14:52
Thanks for the file, Dex! It has helped describe things a bit more clearer. And thanks for the answers to my questions, ManOfSteel, they've helped me understand quite a bit more about my own code! When I wrote it, I used it without having an understanding of it, and that has caused me to feel like I really don't know what I'm doing. I've noticed also that OSDev.org is good for some things but not good for others.
|
|||
![]() |
|
rhyno_dagreat 25 Oct 2007, 15:01
ManOfSteel - As far as question #4, how do I know what selector number corresponds to what descriptor?
|
|||
![]() |
|
rhyno_dagreat 25 Oct 2007, 15:09
Wait!!! So the selector number for the Data segment is 16 because it starts at byte 16 in the GDT, and the code selector would be 8 because it starts at byte 8 in the GDT, am I right?
|
|||
![]() |
|
ManOfSteel 25 Oct 2007, 18:46
Yes, you got it right.
Tip: instead of using those integers, you could insert such lines as code_sel = $ - gdt before every descriptor, and then use the more friendly code_sel instead of 8h (eg: jmp code_sel:Start32). You may find it useful when you'll have more descriptors. Also, what is xor bx, bx for? Do you really need the output file to be of 1.44 floppy image size (times 1474560-($-$$) db 0)? |
|||
![]() |
|
rhyno_dagreat 25 Oct 2007, 19:59
I put it there to make sure nothing was in bx that would screw up the data selector.
Also, I need it to be that size when I'm writing it to a floppy directly. ![]() |
|||
![]() |
|
rhyno_dagreat 25 Oct 2007, 20:03
And thanks for the tip!
![]() |
|||
![]() |
|
rhyno_dagreat 25 Oct 2007, 20:51
Now that I'm starting to truly understand 32-bit mode, it seems way better to work with than plain old 16-bit mode, however it still has it's uses.
![]() |
|||
![]() |
|
ManOfSteel 26 Oct 2007, 07:32
Quote: I put it there to make sure nothing was in bx that would screw up the data selector. How so? You store the data selector right AFTER that. How could anything screw it up from there? Quote: I need it to be that size when I'm writing it to a floppy directly rawrite, partcopy or dd can write files of any size. You don't need 1.44MB, 512 bytes will suffice! |
|||
![]() |
|
rhyno_dagreat 26 Oct 2007, 17:21
*smacks self* You're right!
And really? I've been using RawWrite, and I thought it had to be the same size as a floppy. The only rules regarding it are that it can't be greater than the size of a floppy, right? |
|||
![]() |
|
ManOfSteel 27 Oct 2007, 08:07
Quote: And really? I've been using RawWrite, and I thought it had to be the same size as a floppy. Imagine you wrote a bootloader for an HDD, that you want to test it and that the HDD happens to be 1Tb big! Quote: The only rules regarding it are that it can't be greater than the size of a floppy, right? I've never tried to do this, but it's pointless anyway, so yeah. |
|||
![]() |
|
rhyno_dagreat 27 Oct 2007, 14:08
I have tried before to see what would happen and I'll tell ya the floppy didn't like it.
![]() |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.