Weird long mode interrupt problem

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.
WindowsNT
Member
Member
Posts: 77
Joined: Thu Jun 26, 2008 12:55 pm

Weird long mode interrupt problem

Post by WindowsNT »

I 've tried to setup a simple long mode and it works. The problem starts when I call an interrupt. In bochs it works, in VMWare or VirtualBox it crashes.

GDT Entries:

Code: Select all

code64_descriptor  GDT_STR 0ffffh,0,0,9ah,0afh,0 ; 
data64_descriptor  GDT_STR 0ffffh,0,0,92h,0afh,0 ; 
IDT:

Code: Select all

lidt_PM_start      dw             lidt_size
lidt_PM_ptr dq 0
linterruptsall db 4096 dup (0)
lidt_size=$-(linterruptsall)
Setting up the IDT for one interrupt 0xF0 from real mode:

Code: Select all

 xor edx,edx
 mov edx,CODE64
 shl edx,4
 add edx,f0lm ; the handler
 
 mov eax,edx
 mov di,linterruptsall
 add di,0xf0*16
 mov word [di],ax ; lower
 add di,2
 mov word [di],pm_sel_rcode64; sel
 add di,2
 mov byte [di],0
 add di,1
 mov byte [di],08Eh; 
 add di,1
 mov eax,edx
 shr eax,16
 mov word [di],ax ; upper
 add di,2
 mov dword [di],0; 
 
  ; Set idt ptr
  xor eax,eax
  mov     ax,DATA16
  shl     eax,4
  add     ax,linterruptsall
  mov     dword [lidt_PM_ptr],eax
  mov     dword [lidt_PM_ptr + 4],0

 

ret
Interrupt routine:

Code: Select all

f0lm:
iretq
And the not working code in a CODE64 segment

Code: Select all

xor rbx,rbx
mov bx,DATA16
shl rbx,4
add rbx,lidt_PM_start
lidt tbyte [rbx]
mov ax,pm_sel_rdata64
mov ss,ax
mov es,ax
mov ds,ax
mov fs,ax
mov gs,ax
xor rsp,rsp
mov sp,RUNDATA64 ; segment for the stack
shl rsp,4
add rsp,256
sti
int 0xf0; boom in VMWare, but not in bochs.

Can you make anything of it? Note that I had to setup ss in order not to crash in bochs also, but I do not understand why. Isn't ss ignored?

Thanks :)
Last edited by WindowsNT on Wed Apr 15, 2015 9:40 am, edited 1 time in total.
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Weird long mode interrupt problem

Post by iansjack »

Have you masked off all hardware interrupts? If so, what is the purpose of the STI instruction?
WindowsNT
Member
Member
Posts: 77
Joined: Thu Jun 26, 2008 12:55 pm

Re: Weird long mode interrupt problem

Post by WindowsNT »

iansjack wrote:Have you masked off all hardware interrupts? If so, what is the purpose of the STI instruction?
You are right, I removed it, but still the same results.
WindowsNT
Member
Member
Posts: 77
Joined: Thu Jun 26, 2008 12:55 pm

Re: Weird long mode interrupt problem

Post by WindowsNT »

Here is a vbox log. If i understand correctly it crashed due to a page not present error ??

http://www.turboirc.com/temp/vbox.txt
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: Weird long mode interrupt problem

Post by Combuster »

WindowsNT wrote:Can you make anything of it?
No, because your code does not make any sense in the first place.

Code: Select all

xor rbx,rbx
mov bx,DATA16
shl rbx,4
add rbx,lidt_PM_start
lidt tbyte [rbx]
rbx should point at a structure containing a size and offset. It's probably not at lidt_pm_stack + 16 * DATA16. Instead you should have something like lidt [idtr_struct]

Code: Select all

mov ax,pm_sel_rdata64
mov ss,ax
mov es,ax
mov ds,ax
mov fs,ax
mov gs,ax
This is what you'd normally do after loading the GDT. Most certainly not after loading an IDT.

Code: Select all

xor rsp,rsp
mov sp,RUNDATA64 ; segment for the stack
shl rsp,4
add rsp,256
The stack pointer is not a general purpose register. Don't treat is as such. Besides, a 256-byte stack is not much, and the location where you put it is most likely just as bogus.


Pretty much everything looks like you stole some real mode code of which you have no clue how it works.
"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 ]
WindowsNT
Member
Member
Posts: 77
Joined: Thu Jun 26, 2008 12:55 pm

Re: Weird long mode interrupt problem

Post by WindowsNT »

Combuster wrote:
WindowsNT wrote:
Pretty much everything looks like you stole some real mode code of which you have no clue how it works.
I already said it works without the interrupt and it fails in vmware, but not bochs.

I bet you dont even understand the nature of the problem. if you cannot help, just keep your mouth shut.
False accusations are not to be tolerated. In other words, get lost.
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Weird long mode interrupt problem

Post by iansjack »

As far as I can tell, that log shows that you never reach long mode. You might want to check the validity of your page table.
WindowsNT
Member
Member
Posts: 77
Joined: Thu Jun 26, 2008 12:55 pm

Re: Weird long mode interrupt problem

Post by WindowsNT »

Long mode is reached. If i comment out the int 0xf0 call, it works fine.
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Weird long mode interrupt problem

Post by iansjack »

So why does the log only show 32-bit registers in the register dump?

How can you be sure that you are in long mode?
Octocontrabass
Member
Member
Posts: 5588
Joined: Mon Mar 25, 2013 7:01 pm

Re: Weird long mode interrupt problem

Post by Octocontrabass »

Code: Select all

00:00:30.649135 29 - AMD Long Mode                     = 0 (1)
You're absolutely sure you're in long mode... in a virtual machine that doesn't support long mode? :roll:
WindowsNT
Member
Member
Posts: 77
Joined: Thu Jun 26, 2008 12:55 pm

Re: Weird long mode interrupt problem

Post by WindowsNT »

Hm. I tested it mainly in vmware, i ran it in virtualbox only to get a log.
In that case, it might not enter long mode at all in virtualbox, but I will check it again.
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Weird long mode interrupt problem

Post by iansjack »

I'm still interested to know how you are testing that you are in long mode.
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Weird long mode interrupt problem

Post by SpyderTL »

WindowsNT wrote:
Combuster wrote:
WindowsNT wrote:
Pretty much everything looks like you stole some real mode code of which you have no clue how it works.
I already said it works without the interrupt and it fails in vmware, but not bochs.

I bet you dont even understand the nature of the problem. if you cannot help, just keep your mouth shut.
False accusations are not to be tolerated. In other words, get lost.
Ahhh.. to be the new osdev guy again. This post brings back memories.

I'll tell you the same thing I tell everyone who finds this site and inevitably asks their first question... Don't take anything you read on the osdev forums personally.

In their own "unique" way, these guys are really trying to be helpful. It just doesn't seem like it at first...

Allow me to translate for you:
Combuster wrote:Pretty much everything looks like you stole some real mode code of which you have no clue how it works.
Just because you can copy and paste text from a Japanese web site, it doesn't mean you understand Japanese. In academics, this would be called "Plagiarism", and it is almost universally frowned upon. You should really use sample code as a guide to see how someone else accomplished a task, so that you can consider their approach when you design your code. Asking an "expert" to help you fix code that you did not write yourself is like asking a college professor to make sure that your homework answers, which you copied from Wikipedia, were all correct, because you want to get a good grade.

The guys here are usually pretty helpful when trying to track down a particularly tough bug, but dumping code and error logs with multiple easy-to-spot errors will often result in some, let's say, "blow back".

Good luck on your OS, and let us know if there is anything specific that we can help you with.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
WindowsNT
Member
Member
Posts: 77
Joined: Thu Jun 26, 2008 12:55 pm

Re: Weird long mode interrupt problem

Post by WindowsNT »

iansjack wrote:I'm still interested to know how you are testing that you are in long mode.
The code later switches back to protected, and finally to real mode and exits.
In both bochs and vmware it does that. When I issue the interrupt, bochs works, vmware crashes.
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Weird long mode interrupt problem

Post by iansjack »

WindowsNT wrote:
iansjack wrote:I'm still interested to know how you are testing that you are in long mode.
The code later switches back to protected, and finally to real mode and exits.
In both bochs and vmware it does that. When I issue the interrupt, bochs works, vmware crashes.
If you consider that an answer to the question I think it's time I gave up asking.
Post Reply