GPF after IRQ1 scrolls the screen (x86_64)

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
heat
Member
Member
Posts: 103
Joined: Sat Mar 28, 2015 11:23 am
Libera.chat IRC: heat

GPF after IRQ1 scrolls the screen (x86_64)

Post by heat »

Hi,

This problem only appeared after I create a thread running in ring 3. It worked fine until now. But after I hit enter so many times it scrolls the screen, the next IRQ0 GPF's. If I leave my OS running without touching anything, It'll run perfectly. My code calls set_kernel_stack when switching tasks. My user-space program is only an:

Code: Select all

int main()
{
while(1); 
return 0;
}
with main() being the entry point, without start() or anything. This is my IRQ0 (pushaq and popaq are macros for saving/restoring all registers except rsp/rbp):

Code: Select all

global irq0
irq0:
	cli
	pushaq
	; load the kernel's segments
	mov ax, ds
	push rax
	mov ax, 0x10
	mov ds, ax
	mov ss, ax
	mov fs, ax
	mov gs, ax
	mov es, ax
	extern timer_handler
	call timer_handler
	mov rdi, rsp
	extern sched_switch_thread
	call sched_switch_thread
	mov rsp, rax
	; reload segs
	pop rax
	mov ds, ax
	mov fs, ax
	mov gs, ax
	mov es, ax
	mov al, 0x20
	out 0x20, al
	popaq
	iretq
My IRQ stub is this:

Code: Select all

extern irq_handler
irq_common:
	mov ax, ds
	push rax
	mov ax, 0x10
	mov ss, ax
	mov ds, ax
	mov es, ax
	mov fs, ax
	mov gs, ax
	call irq_handler
	push rdi
	sub rdi, 32
	extern pic_send_eoi
	call pic_send_eoi
	pop rdi
	pop rax
	mov ds, ax
	mov es, ax
	mov fs, ax
	mov gs, ax
	popaq
	iretq
QEMU log:

Code: Select all

  3658: v=21 e=0000 i=0 cpl=0 IP=0008:ffffffff8010e457 pc=ffffffff8010e457 SP=0010:ffff800000001fe8 env->regs[R_EAX]=0000000000000000
RAX=0000000000000000 RBX=ffff800000002000 RCX=0000000000000023 RDX=0000000000802000
RSI=000000000000001b RDI=0000000000000400 RBP=ffff800000001ff8 RSP=ffff800000001fe8
R8 =0000000000002000 R9 =ffff800000404000 R10=0000000000000000 R11=0000000000000010
R12=0000000000000000 R13=0000000000000000 R14=0000000000000000 R15=0000000000000000
RIP=ffffffff8010e457 RFL=00000296 [--S-AP-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 0000000000000000 00000fff 00a09300 DPL=0 DS   [-WA]
CS =0008 0000000000000000 00000fff 00a09a00 DPL=0 CS64 [-R-]
SS =0010 0000000000000000 00000fff 00a09300 DPL=0 DS   [-WA]
DS =0010 0000000000000000 00000fff 00a09300 DPL=0 DS   [-WA]
FS =0010 0000000000000000 00000fff 00a09300 DPL=0 DS   [-WA]
GS =0010 0000000000000000 00000fff 00a09300 DPL=0 DS   [-WA]
LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT
TR =002b ffffffff8011b1b8 00067fff 0080e900 DPL=3 TSS64-avl
GDT=     ffffffff80100153 00000038
IDT=     ffffffff801199e0 00000fff
CR0=80000013 CR2=0000000000000000 CR3=0000000000101000 CR4=00000620
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=0000000000000094 CCD=0000000000000000 CCO=EFLAGS  
EFER=0000000000000d01
  3659: v=20 e=0000 i=0 cpl=0 IP=0008:ffffffff8010e457 pc=ffffffff8010e457 SP=0010:ffff800000001fe8 env->regs[R_EAX]=0000000000000000
RAX=0000000000000000 RBX=ffff800000002000 RCX=0000000000000023 RDX=0000000000802000
RSI=000000000000001b RDI=0000000000000400 RBP=ffff800000001ff8 RSP=ffff800000001fe8
R8 =0000000000002000 R9 =ffff800000404000 R10=0000000000000000 R11=0000000000000010
R12=0000000000000000 R13=0000000000000000 R14=0000000000000000 R15=0000000000000000
RIP=ffffffff8010e457 RFL=00000296 [--S-AP-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 0000000000000000 00000fff 00a09300 DPL=0 DS   [-WA]
CS =0008 0000000000000000 00000fff 00a09a00 DPL=0 CS64 [-R-]
SS =0010 0000000000000000 00000fff 00a09300 DPL=0 DS   [-WA]
DS =0010 0000000000000000 00000fff 00a09300 DPL=0 DS   [-WA]
FS =0010 0000000000000000 00000fff 00a09300 DPL=0 DS   [-WA]
GS =0010 0000000000000000 00000fff 00a09300 DPL=0 DS   [-WA]
LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT
TR =002b ffffffff8011b1b8 00067fff 0080e900 DPL=3 TSS64-avl
GDT=     ffffffff80100153 00000038
IDT=     ffffffff801199e0 00000fff
CR0=80000013 CR2=0000000000000000 CR3=0000000000101000 CR4=00000620
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=0000000000000094 CCD=ffffffffffffffda CCO=EFLAGS  
EFER=0000000000000d01
check_exception old: 0xffffffff new 0xd
  3660: v=0d e=0000 i=0 cpl=0 IP=0008:ffffffff801109a3 pc=ffffffff801109a3 SP=0010:ffff8000003c2998 env->regs[R_EAX]=0000000000000000
RAX=0000000000000000 RBX=0000000000000000 RCX=0000000000000000 RDX=0000000000000000
RSI=0000000000000000 RDI=0000000000000000 RBP=ffff800000001ff8 RSP=ffff8000003c2998
R8 =0000000000000023 R9 =0000000000000023 R10=0000000000802000 R11=0000000000000202
R12=000000000000001b R13=0000000100000080 R14=0000000000000000 R15=0000000000000000
RIP=ffffffff801109a3 RFL=00000086 [--S--P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0000 0000000000000000 00000000 00000000
CS =0008 0000000000000000 00000fff 00a09a00 DPL=0 CS64 [-R-]
SS =0010 0000000000000000 00000fff 00a09300 DPL=0 DS   [-WA]
DS =0000 0000000000000000 00000000 00000000
FS =0000 0000000000000000 00000000 00000000
GS =0000 0000000000000000 00000000 00000000
LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT
TR =002b ffffffff8011b1b8 00067fff 0080e900 DPL=3 TSS64-avl
GDT=     ffffffff80100153 00000038
IDT=     ffffffff801199e0 00000fff
CR0=80000013 CR2=0000000000000000 CR3=0000000000101000 CR4=00000620
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=0000000000000001 CCD=ffffffff70042748 CCO=LOGICQ  
EFER=0000000000000d01
check_exception old: 0xd new 0xd
  3661: v=08 e=0000 i=0 cpl=0 IP=0008:ffffffff801109a3 pc=ffffffff801109a3 SP=0010:ffff8000003c2998 env->regs[R_EAX]=0000000000000000
RAX=0000000000000000 RBX=0000000000000000 RCX=0000000000000000 RDX=0000000000000000
RSI=0000000000000000 RDI=0000000000000000 RBP=ffff800000001ff8 RSP=ffff8000003c2998
R8 =0000000000000023 R9 =0000000000000023 R10=0000000000802000 R11=0000000000000202
R12=000000000000001b R13=0000000100000080 R14=0000000000000000 R15=0000000000000000
RIP=ffffffff801109a3 RFL=00000086 [--S--P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0000 0000000000000000 00000000 00000000
CS =0008 0000000000000000 00000fff 00a09a00 DPL=0 CS64 [-R-]
SS =0010 0000000000000000 00000fff 00a09300 DPL=0 DS   [-WA]
DS =0000 0000000000000000 00000000 00000000
FS =0000 0000000000000000 00000000 00000000
GS =0000 0000000000000000 00000000 00000000
LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT
TR =002b ffffffff8011b1b8 00067fff 0080e900 DPL=3 TSS64-avl
GDT=     ffffffff80100153 00000038
IDT=     ffffffff801199e0 00000fff
CR0=80000013 CR2=0000000000000000 CR3=0000000000101000 CR4=00000620
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=0000000000000001 CCD=ffffffff70042748 CCO=LOGICQ  
EFER=0000000000000d01
EDIT: RIP on QEMU's exception log is the iretq instruction of irq0.
Thanks for the help :D
If some of you people keep insisting on having backwards compatibitity with the stone age, we'll have stone tools forever.
My Hobby OS: https://github.com/heatd/Onyx
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: GPF after IRQ1 scrolls the screen (x86_64)

Post by xenos »

Sounds to me like your screen scrolling procedure is overwriting something important...
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
heat
Member
Member
Posts: 103
Joined: Sat Mar 28, 2015 11:23 am
Libera.chat IRC: heat

Re: GPF after IRQ1 scrolls the screen (x86_64)

Post by heat »

XenOS wrote:Sounds to me like your screen scrolling procedure is overwriting something important...
I think the opposite happens, and my stack is being assigned virtual memory that belongs to the framebuffer... I definetly need to change my virtual memory allocator. Thanks anyways!
If some of you people keep insisting on having backwards compatibitity with the stone age, we'll have stone tools forever.
My Hobby OS: https://github.com/heatd/Onyx
Post Reply