pmode Triple Fault

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
gudenau
Posts: 8
Joined: Tue Sep 09, 2014 3:00 pm

pmode Triple Fault

Post by gudenau »

So, I have started to work on a little OS. I attempted to get into pmode but it seems to create a triple fault in Virtual Box and my laptop. I have attached the source and it appears that it happens around line 7 in loader/pmode.asm

Any help would be appreciated, as I am missing somthing here.

Edit:
Source
Last edited by gudenau on Sat Oct 18, 2014 6:20 pm, edited 1 time in total.
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: pmode Triple Fault

Post by b.zaar »

gudenau wrote: Any help would be appreciated, as I am missing somthing here.
The attachment...
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
gudenau
Posts: 8
Joined: Tue Sep 09, 2014 3:00 pm

Re: pmode Triple Fault

Post by gudenau »

b.zaar wrote:
gudenau wrote: Any help would be appreciated, as I am missing somthing here.
The attachment...
Where did that go?

Source
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: pmode Triple Fault

Post by thepowersgang »

Here's a hint - Nobody here (well... none of the expirenced members, unless they're really bored) will just download and open an archive.

You think you've discovered the offending line, why do you think that? Is it a guess, or have you checked the manuals but don't know how to solve the failure?

Have you run in bochs and checked what its log says? (And actually read that log, if you don't understand what the message means then search the bochs source, some of the messages are a little cryptic)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
gudenau
Posts: 8
Joined: Tue Sep 09, 2014 3:00 pm

Re: pmode Triple Fault

Post by gudenau »

thepowersgang wrote:Here's a hint - Nobody here (well... none of the expirenced members, unless they're really bored) will just download and open an archive.

You think you've discovered the offending line, why do you think that? Is it a guess, or have you checked the manuals but don't know how to solve the failure?

Have you run in bochs and checked what its log says? (And actually read that log, if you don't understand what the message means then search the bochs source, some of the messages are a little cryptic)
It crashes around here:

Code: Select all

	xor ah, ah
	int 0x16
	
	cli
	lgdt [pmode_toc]
	mov eax, cr0
	or eax, 1
	mov cr0, eax
	
	jmp dword 08h:pmode_entry
	
bits 32
pmode_entry:
	mov ax, 0x10
	mov ds, ax
	mov es, ax
	mov fs, ax
	mov gs, ax
	mov ss, ax
	
	jmp $
GDT

Code: Select all

pmode_basicGDT:
	; Null
	dw 0x0000		; Limit low
	dw 0x0000		; Base low
	db 0x00			; Base middle
	db 0b00000000	; Access
	db 0b00000000	; Granularity
	db 0x00			; Base high
	
	; Code
	dw 0xFFFF		; Limit low
	dw 0x0000		; Base low
	db 0x00			; Base middle
	db 0b10011010	; Access
	db 0b11001111	; Granularity
	db 0x00			; Base high
	
	; Data
	dw 0xFFFF		; Limit low
	dw 0x0000		; Base low
	db 0x00			; Base middle
	db 0b10010010	; Access
	db 0b11001111	; Granularity
	db 0x00			; Base high
pmode_GDTSize equ $ - pmode_basicGDT
	
pmode_toc:
	dw pmode_GDTSize - 1
	dd pmode_basicGDT
I will also look into Bochs.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: pmode Triple Fault

Post by Combuster »

I took a quick look at the code, and it appears you're making the common mistake of mixing up virtual and linear addresses.

In other words, you're using garbage for the GDT.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
CelestialMechanic
Member
Member
Posts: 52
Joined: Mon Oct 11, 2010 11:37 pm
Location: Milwaukee, Wisconsin

Re: pmode Triple Fault

Post by CelestialMechanic »

Code: Select all

bits 32
pmode_entry:
   mov ax, 0x10
   mov ds, ax
   mov es, ax
   mov fs, ax
   mov gs, ax
   mov ss, ax
   
   jmp $
I see an awful lot of this these days. You should have "mov esp, something" immediately after the mov ss, ax. Where is your stack? Did you set up a proper IDT? Faults can occur and just one of them to a defective stack can add up to a triple fault mucho prestissimo bingo.
Microsoft is over if you want it.
gudenau
Posts: 8
Joined: Tue Sep 09, 2014 3:00 pm

Re: pmode Triple Fault

Post by gudenau »

CelestialMechanic wrote:

Code: Select all

bits 32
pmode_entry:
   mov ax, 0x10
   mov ds, ax
   mov es, ax
   mov fs, ax
   mov gs, ax
   mov ss, ax
   
   jmp $
I see an awful lot of this these days. You should have "mov esp, something" immediately after the mov ss, ax. Where is your stack? Did you set up a proper IDT? Faults can occur and just one of them to a defective stack can add up to a triple fault mucho prestissimo bingo.
I thought that you only needed an IDT if interrupts were enabled, so I was going to do that next.

Edit:
Apparently my segment stuff was not correct, yay. :-P
User avatar
jrhetf4xb
Member
Member
Posts: 38
Joined: Fri May 16, 2014 11:50 am
Location: Bulgaria

Re: pmode Triple Fault

Post by jrhetf4xb »

gudenau wrote: Edit:
Apparently my segment stuff was not correct, yay. :-P
Could you point out what you did to fix it?
Practice makes perfect.
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: pmode Triple Fault

Post by iansjack »

gudenau wrote: I thought that you only needed an IDT if interrupts were enabled, so I was going to do that next.
As well as interrupts, the IDT points to handlers for exceptions. Exceptions happen whether interrupts are enabled or not. This means that if you have no exception handlers (and an IDT to point to them) any error in your code leads to an instant triple fault. This makes debugging more difficult. It is useful to know where an error occurs, what sort of error it is, and further information that the exception provides in an error code; for example, your exception handler could print these to the screen and then halt the processor.

When your OS is more refined the exception handlers will actually take steps to allow for common exceptions and keep the system running (in particular, page faults are not always errors).

So, although not absolutely essential, not having exception handlers is like working with both hands tied behind your back.
Post Reply