stack operations after sti
stack operations after sti
I received a #DF when it's trying to push/pop after sti in bochs: after sti, wherever there's a stack operation, there's a #DF.
However, there's no exception in VMware. It's confusing.
Is it a bug of bochs? Or is it my code's fault?
(My OS is in 64-bit, and it has enabled specific paging(not one-to-one). The canonical stack linear address is properly mapped to present memory address.)
(After checking, it doesn't seem that the first exception is #GP or #SS.)
(I've enabled APIC LVT timer.)
However, there's no exception in VMware. It's confusing.
Is it a bug of bochs? Or is it my code's fault?
(My OS is in 64-bit, and it has enabled specific paging(not one-to-one). The canonical stack linear address is properly mapped to present memory address.)
(After checking, it doesn't seem that the first exception is #GP or #SS.)
(I've enabled APIC LVT timer.)
Doing steadfastly, or doing nil.
Re: stack operations after sti
It is your code's fault (not that I have seen your code). Such a catastrophic bug in Boch's would have been found long ago.
I would imagine that there is a pending interrupt which is triggered when you enable interrupts, and some fault in your interrupt-handling code. An invalid stack?
I would imagine that there is a pending interrupt which is triggered when you enable interrupts, and some fault in your interrupt-handling code. An invalid stack?
Re: stack operations after sti
Are you sure you aren't getting an interrupt on vector 8 (this would be timer/IRQ0 by default / until you reconfigure interrupts)? Your dump says EXT=1, implying the external source of the event. It totally makes sense after enabling interrupts with the STI instruction.
Re: stack operations after sti
So here's my code:iansjack wrote:(not that I have seen your code).
Code: Select all
mov ecx, IA32_X2APIC_LVT_LINT0
rdmsr
bts eax, 16
wrmsr ; disable 8259 PIC
mov rax, 0
mov cr8, rax ; set TPR = 0
call EnableTimer ; enable timer
mov rdi, PreparLock
call LeaveSpinLock ; leave spinlock
sti
jmp kernel_main
Last edited by Js2xxx on Mon Apr 10, 2017 1:14 am, edited 1 time in total.
Doing steadfastly, or doing nil.
Re: stack operations after sti
Well, I use APIC LVT timer (Int vector 0x20), not 8259 PIC. For external interrupt, I use I/O APIC and I 've masked all of them (Int vector 0x21 ~ 0x37).alexfru wrote:timer/IRQ0 by default
And here's my code for I/O APIC:
Code: Select all
SegSelector sel;
sel.RPL = 0;
sel.TI = 0;
sel.Index = 4;
SetIntGate(0x21, KeyboardHandler, sel, INT_GATE | DESC_P, 0); //For example, the keyboard handler (others are the same as it.)
...
SetIOAPICVector(0x12, 0x21);
...
Doing steadfastly, or doing nil.
Re: stack operations after sti
It would be interesting to see the PIC state (pending and in service flags for IRQ0) and/or the code that disables the PIC interrupts. It could be a different kind of bug, though.Js2xxx wrote:Well, I use APIC LVT timer (Int vector 0x20), not 8259 PIC. For external interrupt, I use I/O APIC and I 've masked all of them (Int vector 0x21 ~ 0x37).alexfru wrote:timer/IRQ0 by default
Re: stack operations after sti
So here's the code:alexfru wrote:see the code that disables the PIC interrupts.
Code: Select all
mov ecx, IA32_X2APIC_LVT_LINT0 ;0x835
rdmsr
bts eax, 16
wrmsr
Doing steadfastly, or doing nil.
Re: stack operations after sti
Hi,
Cheers,
Brendan
This is completely broken - there's no guarantee that the PIC chip/s are connected to LINT0. For example; the PIC chips can be connected to an IO APIC input (configured as "extInt").Js2xxx wrote:So here's the code:alexfru wrote:see the code that disables the PIC interrupts.
I disable LINT0 so I disconnect my kernel with 8259 PIC.Code: Select all
mov ecx, IA32_X2APIC_LVT_LINT0 ;0x835 rdmsr bts eax, 16 wrmsr
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re: stack operations after sti
So I add this to that code:Brendan wrote: This is completely broken - there's no guarantee that the PIC chip/s are connected to LINT0. For example; the PIC chips can be connected to an IO APIC input (configured as "extInt").
Code: Select all
mov rax, 10h
mov ebx, 0FEC00000h
mov [ebx], eax
mov rax, 0
bts rax, 16
mov ebx, 0FEC00010h
mov [ebx], eax
Thanks for any advice.
Doing steadfastly, or doing nil.
Re: stack operations after sti
This would make a little more sense:Js2xxx wrote:So I add this to that code:Brendan wrote: This is completely broken - there's no guarantee that the PIC chip/s are connected to LINT0. For example; the PIC chips can be connected to an IO APIC input (configured as "extInt").However, it makes little sense.Code: Select all
mov rax, 10h mov ebx, 0FEC00000h mov [ebx], eax mov rax, 0 bts rax, 16 mov ebx, 0FEC00010h mov [ebx], eax
Code: Select all
mov dword [0FEC00000h], 10h
mov dword [0FEC00010h], (1 << 16)
My advice is:
- Mask the PIC's IRQs in the PIC chips themselves
- Do "STI" to allow BIOS/firmware/whatever to handle any IRQs that were buffered/postponed before you masked them
- Don't bother using CLI after this because there is no point (all IRQs masked)
- Configure PICs regardless of whether you use them or not; to ensure that spurious IRQs don't cause "interrupt 0x0F" (or "interrupt 0x77") but will use something nicer (like "interrupt 0x37" and "interrupt 0x3F" instead).
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re: stack operations after sti
Your advice benefits me. The address has been sign-extended and has made a #PF, though.Brendan wrote:Code: Select all
mov dword [0FEC00000h], 10h mov dword [0FEC00010h], (1 << 16)
Doing steadfastly, or doing nil.