flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > GDT and IDT arithmetic |
Author |
|
Mac2004 09 Dec 2006, 19:31
Hi Rhyno!
If I understood your question properly the answer is this: [gdt_descriptor+2] defines the start address where to add. In this case the start address is gdt_descriptor+2 bytes. The size of addition is determined by the prefix dword. So we're adding dword size number (32bit) at gdt_descriptor+2. I hope this helps you! regards, Mac2004 |
|||
09 Dec 2006, 19:31 |
|
rhyno_dagreat 09 Dec 2006, 19:39
Thanks Mac! It does, but I still must wonder about the first question about subtracting the labels.
|
|||
09 Dec 2006, 19:39 |
|
cod3b453 09 Dec 2006, 20:28
The first word in GPTR is the size of the GDT, the dword after it is the address of the GDT.
Code: GDTR: .Size dw (_GDT - GDT) .Address dd GDT GDT: ; GDT entires here _GDT: I honestly don't know why people subtract 1 as well - it always gives me triple fault... add dword [gdt_descriptor+2], 600h is the same as add dword [GDTR.Address], 600h - this was probably the offset of your kernel. |
|||
09 Dec 2006, 20:28 |
|
rhyno_dagreat 09 Dec 2006, 20:43
Yeah, it was. Thanks! But still, what is the subtraction subtracting? Memory addresses?
|
|||
09 Dec 2006, 20:43 |
|
cod3b453 09 Dec 2006, 21:03
yes.
Basically, the memory addresses of the labels gdt and _gdt are calculated at compile time once everything else has been "filled in" and then (_gdt - gdt) is evaluated and put in as the value for size.[/code] |
|||
09 Dec 2006, 21:03 |
|
Tomasz Grysztar 09 Dec 2006, 21:54
rhyno_dagreat wrote: but when you subtract labels from one another in ASM, what's really happening? In NASM and FASM syntax the label represents an address (in FASM it can also have some data size attached, but it still can be used juat as an address), so when you substract labels, you substract addresses. rhyno_dagreat wrote: What I don't understand about this is when you add 2 to the GDT Descriptor, how many units is it going up each time? 2 Bytes? 2 Words? 2 DWords? The addresses are alway byte-granular, so if you increment address by 1, you point to the next byte. Adding 2 moves you two bytes forward. cod3b453 wrote: I honestly don't know why people subtract 1 as well - it always gives me triple fault... From the "Intel 80386 Programmer's Reference Manual" (year 1986), section 6.3.1.2: Quote: The limit field of descriptors for descriptor tables is used by the ...and from the more up-to-date "IA-32 Intel Architecture Software Developer’s Manual", volume 3, section 3.5: Quote: The limit value for the GDT is I guess your triple fault must have been for some other reason. |
|||
09 Dec 2006, 21:54 |
|
rhyno_dagreat 09 Dec 2006, 22:47
Ah, this all makes sense now!
So say you have the following assembler code: Code: jmp Addr1 Addr1: ;Say this is at offset 0x0002 mov ax, bx Addr2: ;And this is at offset 0x0004 mov bx, cx Addr3: Addr2 - Addr1 ;Would be equivalent to 0x0004 - 0x0002 = 0x0002? ;Which would mean Addr3 points to the same offset as Addr1, right? |
|||
09 Dec 2006, 22:47 |
|
Tomasz Grysztar 09 Dec 2006, 23:19
Perhaps you did mean:
Code: jmp Addr1 Addr1: ; 0x0002 mov ax, bx Addr2: ; 0x0004 mov bx, cx Addr3 = Addr2 - Addr1 ; equivalent to Addr3 = 0x0004 - 0x0002 |
|||
09 Dec 2006, 23:19 |
|
rhyno_dagreat 09 Dec 2006, 23:21
Oops, no, I meant:
Code: jmp Addr1 Addr1: ;Say this is at offset 0x0002 mov ax, bx Addr2: ;And this is at offset 0x0004 mov bx, cx Addr3: db Addr2 - Addr1 ;Would be equivalent to 0x0004 - 0x0002 = 0x0002? ;Which would mean Addr3 points to the same offset as Addr1, right? |
|||
09 Dec 2006, 23:21 |
|
Tomasz Grysztar 09 Dec 2006, 23:32
Then you've got Addr1 = 0x0002 and Addr3 = 0x0006.
The byte at address 0x0006 (Addr3) holds the value 0x0002, so you might say that byte[Addr3]=Addr1 - did you mean this by saying "points to the same offset as"? |
|||
09 Dec 2006, 23:32 |
|
rhyno_dagreat 10 Dec 2006, 00:30
Yeah, thanks Tomasz! But while we're on the subject of memory addressing and all, could you check out my 16 bit os thread? I show the code and the changes I've made to it, but it still doesn't work. Basically the second sector starts a new program.
|
|||
10 Dec 2006, 00:30 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.