Jump protect error when trying to get into protected mode

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
User avatar
343GuiltySpark
Posts: 4
Joined: Sat Sep 24, 2022 5:42 pm
Location: Canada

Jump protect error when trying to get into protected mode

Post 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.

"If this code is not enough I must put my soul into it."
- Me
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

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

Post 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.
User avatar
343GuiltySpark
Posts: 4
Joined: Sat Sep 24, 2022 5:42 pm
Location: Canada

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

Post 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.

"If this code is not enough I must put my soul into it."
- Me
User avatar
343GuiltySpark
Posts: 4
Joined: Sat Sep 24, 2022 5:42 pm
Location: Canada

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

Post 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.

"If this code is not enough I must put my soul into it."
- Me
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

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

Post 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.
User avatar
343GuiltySpark
Posts: 4
Joined: Sat Sep 24, 2022 5:42 pm
Location: Canada

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

Post 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.

"If this code is not enough I must put my soul into it."
- Me
devc1
Member
Member
Posts: 439
Joined: Fri Feb 11, 2022 4:55 am
Location: behind the keyboard

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

Post 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.
devc1
Member
Member
Posts: 439
Joined: Fri Feb 11, 2022 4:55 am
Location: behind the keyboard

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

Post 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 
User avatar
Minoto
Member
Member
Posts: 89
Joined: Thu May 12, 2011 7:24 pm

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

Post 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.
Those who understand Unix are doomed to copy it, poorly.
devc1
Member
Member
Posts: 439
Joined: Fri Feb 11, 2022 4:55 am
Location: behind the keyboard

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

Post by devc1 »

You are right, however he should fix his jump and replace it with :

Code: Select all

jmp dword 0x08:_start
Post Reply