Page 1 of 2
Weird long mode interrupt problem
Posted: Wed Apr 15, 2015 9:27 am
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:
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
Re: Weird long mode interrupt problem
Posted: Wed Apr 15, 2015 10:07 am
by iansjack
Have you masked off all hardware interrupts? If so, what is the purpose of the STI instruction?
Re: Weird long mode interrupt problem
Posted: Wed Apr 15, 2015 10:22 am
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.
Re: Weird long mode interrupt problem
Posted: Wed Apr 15, 2015 11:57 pm
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
Re: Weird long mode interrupt problem
Posted: Thu Apr 16, 2015 1:46 am
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.
Re: Weird long mode interrupt problem
Posted: Thu Apr 16, 2015 2:51 am
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.
Re: Weird long mode interrupt problem
Posted: Thu Apr 16, 2015 4:35 am
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.
Re: Weird long mode interrupt problem
Posted: Thu Apr 16, 2015 5:44 am
by WindowsNT
Long mode is reached. If i comment out the int 0xf0 call, it works fine.
Re: Weird long mode interrupt problem
Posted: Thu Apr 16, 2015 5:48 am
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?
Re: Weird long mode interrupt problem
Posted: Thu Apr 16, 2015 6:29 am
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?
Re: Weird long mode interrupt problem
Posted: Thu Apr 16, 2015 7:16 am
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.
Re: Weird long mode interrupt problem
Posted: Thu Apr 16, 2015 8:09 am
by iansjack
I'm still interested to know how you are testing that you are in long mode.
Re: Weird long mode interrupt problem
Posted: Thu Apr 16, 2015 8:31 am
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.
Re: Weird long mode interrupt problem
Posted: Thu Apr 16, 2015 9:27 am
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.
Re: Weird long mode interrupt problem
Posted: Thu Apr 16, 2015 10:20 am
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.