Page 1 of 1

Jump protect error when trying to get into protected mode

Posted: Wed Sep 28, 2022 3:42 pm
by 343GuiltySpark
when I boot into protected mode (or try to rather), Bochs gives me the following error.

jump_protected: gate type 13 unsupported

I'm not sure why it's doing this, I've searched everywhere for info but can't find anything on type 13 specifically.

here's the code repo

https://github.com/343GuiltySpark-04/Vo ... ter/kernel

I'm really loving OS development and thanks for the amazing wiki resources to help aspiring hobbyists.

Re: Jump protect error when trying to get into protected mod

Posted: Sat Oct 01, 2022 10:28 pm
by Octocontrabass
If you dump your registers, you'll see that there's garbage in GDTR because the limit is a word, not a byte.

You'll still have problems after you fix that because your jump destination is nonsense.

It looks like you've adapted a lot of your startup code from a real mode bootloader. GRUB switches to protected mode and enables A20, so you don't need to do either of those things.

Re: Jump protect error when trying to get into protected mod

Posted: Sun Oct 02, 2022 8:17 am
by 343GuiltySpark
I had some help from the discord server before the post was approved, thanks anyway though (I wasn't sure how or if I could cancel the post, I'm not used to using forums).
my apologies.

Re: Jump protect error when trying to get into protected mod

Posted: Sun Oct 02, 2022 11:37 am
by 343GuiltySpark
Octocontrabass wrote:If you dump your registers, you'll see that there's garbage in GDTR because the limit is a word, not a byte.

You'll still have problems after you fix that because your jump destination is nonsense.

It looks like you've adapted a lot of your startup code from a real mode bootloader. GRUB switches to protected mode and enables A20, so you don't need to do either of those things.
how do I dump them? (I'm using Bochs)
and yes this was a carried-over project from when I barely knew ASM, I'm actually considering starting from scratch.

Re: Jump protect error when trying to get into protected mod

Posted: Sun Oct 02, 2022 12:26 pm
by Octocontrabass
343GuiltySpark wrote:how do I dump them? (I'm using Bochs)
Use the debugger. I think the "regs" command will show it, but I haven't used Bochs in a while so I might be remembering wrong.

Re: Jump protect error when trying to get into protected mod

Posted: Sun Oct 02, 2022 12:51 pm
by 343GuiltySpark
Octocontrabass wrote:
343GuiltySpark wrote:how do I dump them? (I'm using Bochs)
Use the debugger. I think the "regs" command will show it, but I haven't used Bochs in a while so I might be remembering wrong.

yeah that's the right command, but when the fault occurs it locks up and I cant dump the regs while its showing the error message.

Re: Jump protect error when trying to get into protected mod

Posted: Fri Oct 07, 2022 6:28 am
by devc1
In your repo, kernel.c, the function init_idt()

Code: Select all

struct IDT_pointer idt_ptr;
	idt_ptr.limit = (sizeof(struct IDT_entry) * IDT_SIZE) - 1;
	idt_ptr.base = (unsigned int)&IDT;
	// Now load this IDT
	load_idt(&idt_ptr);
You are declaring the IDTR in the stack, and soon it will be overwritten. You should declare it as a global variable instead.

The stack is a temporal store of informations and when you exit a function it gets cleared and overwritten by other functions.

Gate 13 may be an interrupt, and your corrupt IDTR does no longer reference your IDT.
Try this fix and tell me if it has an effect.

I am still looking for problems in your code.

Re: Jump protect error when trying to get into protected mod

Posted: Fri Oct 07, 2022 6:35 am
by devc1
What is this ?

Code: Select all

pmodeinit:
   
    cli
    lgdt [gdt_desc]
    mov eax,cr0
    or eax,0x1
    mov cr0,eax
    jmp dword 0x8:0x18
Can you explain this line of code to me ?

Code: Select all

 jmp dword 0x8:0x18 

Re: Jump protect error when trying to get into protected mod

Posted: Fri Oct 07, 2022 9:24 am
by Minoto
devc1 wrote:In your repo, kernel.c, the function init_idt()

Code: Select all

struct IDT_pointer idt_ptr;
	idt_ptr.limit = (sizeof(struct IDT_entry) * IDT_SIZE) - 1;
	idt_ptr.base = (unsigned int)&IDT;
	// Now load this IDT
	load_idt(&idt_ptr);
You are declaring the IDTR in the stack, and soon it will be overwritten. You should declare it as a global variable instead.
This code is not declaring the IDTR in the stack -- it's a hardware register, after all. It just constructs the IDT descriptor to be loaded into that register, then loads it, after which point it's no longer needed. This is not a problem, and there's no need to keep the descriptor around in a global variable.

Re: Jump protect error when trying to get into protected mod

Posted: Fri Oct 07, 2022 10:40 am
by devc1
You are right, however he should fix his jump and replace it with :

Code: Select all

jmp dword 0x08:_start