GDT code - boom
from what I can uderstand from this is that DS isn't set (or is set to NULL), which would cause the general protection fault. In which case the code isn't even getting up to part of loading the GDT.ehird wrote:Code: Select all
00017504444e[CPU0 ] interrupt(): gate descriptor is not valid sys seg 00017504444e[CPU0 ] interrupt(): gate descriptor is not valid sys seg 00017504444i[CPU0 ] protected mode 00017504444i[CPU0 ] CS.d_b = 32 bit 00017504444i[CPU0 ] SS.d_b = 32 bit 00017504444i[CPU0 ] | EAX=00106814 EBX=0002bdc0 ECX=00000000 EDX=00000000 00017504444i[CPU0 ] | ESP=00106810 EBP=00106870 ESI=0002bf1a EDI=0002bf1b 00017504444i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf ZF af PF cf 00017504444i[CPU0 ] | SEG selector base limit G D 00017504444i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D 00017504444i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 000fffff 1 1 00017504444i[CPU0 ] | DS:0000( 0000| 0| 0) 00000000 000fffff 1 1 00017504444i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 000fffff 1 1 00017504444i[CPU0 ] | ES:0000( 0000| 0| 0) 00000000 000fffff 1 1 00017504444i[CPU0 ] | FS:0000( 0000| 0| 0) 00000000 000fffff 1 1 00017504444i[CPU0 ] | GS:0000( 0000| 0| 0) 00000000 000fffff 1 1 00017504444i[CPU0 ] | EIP=001006fd (001006fd) 00017504444i[CPU0 ] | CR0=0x00000011 CR1=0 CR2=0x00000000 00017504444i[CPU0 ] | CR3=0x00000000 CR4=0x00000000 00017504444i[CPU0 ] >> mov eax, dword ptr ds:0x100223 : A123021000 00017504444e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting 00017504444i[SYS ] bx_pc_system_c::Reset(SOFTWARE) called
If this has change in the new version can someone post the new one. I'm also wondering, if you operating system is multi-tasking. It could be the TSS (or your process block) that may be causing this.
Anyway I got to get back to work
![Sad :(](./images/smilies/icon_sad.gif)
![Sad :(](./images/smilies/icon_sad.gif)
![Image](http://www.danasoft.com/sig/ExposingTruth.jpg)
Microsoft: "let everyone run after us. We'll just INNOV~1"
-
- 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:
Try this before any GDT init:
Note that SS should be a high value as well, as the stack grows downwards.
Code: Select all
mov ax,0x10
mov cs,ax
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
Code: Select all
gdt_flush:
mov ax, 0x10
mov cs, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
lgdt [gp]
jmp 0x08:flush2
If on (Un)Real Mode, try:
Code: Select all
lgdt [cs:gp]
Trying things at random will at best give you code that works in some cases. The only way to build reliable code is to figure out why something does not work, and fix it based on the gathered information... not just randomly change stuff until something seems to run.pcmattman wrote:I still say, try it.
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.
This won't work. CS can't be the same as the rest, plus as said, you can't load CS that way, as you have to use FAR-jump instead.pcmattman wrote:Try this before any GDT init:
Code: Select all
mov ax,0x10 mov cs,ax mov ds,ax mov es,ax mov fs,ax mov gs,ax
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.
From the Bochs log above, it's obvious that since you are loading DS as the first new segment from the new GDT, and Bochs panics with invalid gate and DS=NULL in the register dump, your gate descriptor isn't valid, or your LGDT inststruction doesn't load the right stuff..
Interesting questions would be, do you have paging enabled, and if so, is your GDT mapped at the same address in physical and virtual memory?
If you scroll backwards in the Bochs log, what does it say about the LGDT? Enable CPU debug=log (in per-device log options) if it doesn't say anything. It could be simply that it fails to load the GDT if it's not aligned properly.
That won't get aligned right. You need to align it so that the 'base' (which is 4 bytes) get's properly aligned to 4 bytes. Easiest way to do it would be something like this:
If you still get tripple-fault after you've fixed that one, then there might also be something else wrong, but start by fixing that one. ![Smile :)](./images/smilies/icon_smile.gif)
edit: Also add 2 bytes to the address you load with LGDT, like this:[/i]
Interesting questions would be, do you have paging enabled, and if so, is your GDT mapped at the same address in physical and virtual memory?
If you scroll backwards in the Bochs log, what does it say about the LGDT? Enable CPU debug=log (in per-device log options) if it doesn't say anything. It could be simply that it fails to load the GDT if it's not aligned properly.
Code: Select all
struct gdt_ptr {
unsigned short limit;
unsigned int base;
} __attribute__((packed));
struct gdt_ptr gp;
Code: Select all
// You don't really need the attributes, since it'll get aligned to 4 anyway
// and since you have two shorts = 4bytes, and one int = 4bytes, it'll
// stay packed even without the attributes.
// They are good to have for documentation though, or in case future
// compiler versions start aligned differently.
struct gdt_ptr {
unsigned short _dummy; // <- 2 bytes, to offset the alignment
unsigned short limit;
unsigned int base;
} __attribute__((aligned(4), packed));
struct gdt_ptr gp;
![Smile :)](./images/smilies/icon_smile.gif)
edit: Also add 2 bytes to the address you load with LGDT, like this:
Code: Select all
lgdt [gp+2] // <- if I'm not mistaken, you want [] around it in Intel syntax? not sure to be honest
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.