I either have an epic brainfart of gargantuan proportions, or there is something weird going on here. My OS started to have some weird crashes in QEMU, so I started to investigate. I've come to conclusion that I have some memory corruption somewhere causing memory access with non-canonical address leading to GPF. I've managed to setup a breakpoint before offending instruction and found something weird. RAX value seems to be completely bogus. I would expect RAX to become 0xffff9000000037bb and not 0x00ff90000000bd4e. Below are some screenshots showing machine state before and after problematic instruction.
It doesn't seem to be debugger artifact, because QEMU monitor says exactly the same.
Code:
QEMU 5.0.0 monitor - type 'help' for more information
(qemu) x /1g $ebp-8
ffff900000003438: 0xffff9000000037bb
(qemu) x /2i 0xffff80000011dba6
0xffff80000011dba6: 48 8b 45 f8 movq -8(%rbp), %rax
0xffff80000011dbaa: 88 10 movb %dl, (%rax)
(qemu) info registers
RAX=00ff90000000bd4e RBX=0000000000000000 RCX=ffff800000138de0 RDX=0000000000000000
RSI=ffff800000138de0 RDI=ffff9000000037b0 RBP=ffff900000003440 RSP=ffff900000003418
R8 =0000000000000002 R9 =0000000000000000 R10=0000000000000000 R11=0000000000000000
R12=0000000000000000 R13=0000000000000000 R14=0000000000000000 R15=0000000000000000
RIP=ffff80000011dbaa RFL=00000086 [--S--P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0020 0000000000000000 ffffffff 00af9300 DPL=0 DS [-WA]
CS =0018 0000000000000000 ffffffff 00af9a00 DPL=0 CS64 [-R-]
SS =0020 0000000000000000 ffffffff 00af9300 DPL=0 DS [-WA]
DS =0020 0000000000000000 ffffffff 00af9300 DPL=0 DS [-WA]
FS =0030 0000000000000000 ffffffff 00aff300 DPL=3 DS [-WA]
GS =0030 0000000000000000 ffffffff 00aff300 DPL=3 DS [-WA]
LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT
TR =003b ffff80000014bc30 00000067 00408900 DPL=0 TSS64-avl
GDT= ffff80000012b000 00001037
IDT= ffff800000131000 00000fff
. . .
Interrupts are disabled, and QEMUs -d int, doesn't show any interrupts between instructions either.