IDT Causes OS to Crash And Reboot

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
NanoSoft
Posts: 1
Joined: Sun Sep 15, 2024 9:12 am

IDT Causes OS to Crash And Reboot

Post by NanoSoft »

https://www.github.com/NanoSoftDevTeam/BreezeOS
(My Github Repo)

on IDT initailiztion my os crashes in IDT.cpp from line 27 to line 32
sebihepp
Member
Member
Posts: 177
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Re: IDT Causes OS to Crash And Reboot

Post by sebihepp »

Where do you define _idt[] ? In idt.cpp you only declare it as extern. Where is it defined?
MichaelPetch
Member
Member
Posts: 729
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: IDT Causes OS to Crash And Reboot

Post by MichaelPetch »

I don't see where you call `RemapPic` to remap the pic to 0x20 and 0x28. At the start of InitializeIDT add a call to RemapPic. What also helps is if you add `-d int -no-shutdown -no reboot` to QEMU and then provide the last 100 or so lines (the last few interrupts and exceptions that occur). It aids being able to help you identify problems.

Is there a reason why you are allocating space for `_idt` in a linker script rather than just putting it in a CPP file?
MichaelPetch
Member
Member
Posts: 729
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: IDT Causes OS to Crash And Reboot

Post by MichaelPetch »

I cloned your repository and ran the ISO file you committed. When I run QEMU with `-d int -no-shutdown -no-reboot` I see this:

Code: Select all

1211: v=0e e=0003 i=0 cpl=0 IP=0028:ffffffff8000000b pc=ffffffff8000000b SP=0030:ffff80007fe18e80 CR2=ffffffff80003010
RAX=ffffffff800025ea RBX=0000000000000000 RCX=0000000000000033 RDX=00000000000000e9
RSI=000000000000000a RDI=00000000000000e9 RBP=ffff80007fe18e80 RSP=ffff80007fe18e80
R8 =ffff80007feea000 R9 =0000000000000000 R10=00000000001f58f0 R11=ffff8000c0000000
R12=0000000000000438 R13=0000000000000000 R14=0000000000000439 R15=0000000000000781
RIP=ffffffff8000000b RFL=00000082 [--S----] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0030 0000000000000000 00000000 00009300 DPL=0 DS   [-WA]
CS =0028 0000000000000000 00000000 00209b00 DPL=0 CS64 [-RA]
SS =0030 0000000000000000 00000000 00009300 DPL=0 DS   [-WA]
DS =0030 0000000000000000 00000000 00009300 DPL=0 DS   [-WA]
FS =0030 0000000000000000 00000000 00009300 DPL=0 DS   [-WA]
GS =0030 0000000000000000 00000000 00009300 DPL=0 DS   [-WA]
LDT=0000 0000000000000000 00000000 00008200 DPL=0 LDT
TR =0000 0000000000000000 0000ffff 00008b00 DPL=0 TSS64-busy
GDT=     ffff80007fee8000 00000037
IDT=     0000000000000000 00000000
CR0=80010011 CR2=ffffffff80003010 CR3=000000007fe08000 CR4=00000020
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=0000000000000008 CCD=ffff80007fe18e68 CCO=ADDQ
EFER=0000000000000d00
You are getting a page fault (v=0e) when accessing 0xffffffff80003010 (CR2). The errorcode e=0003 (0x0003) means that you got a page protection violation when trying to write to the memory address in CR2. See this to decode the error code: https://wiki.osdev.org/Exceptions#Page_Fault . In the QEMU monitor I issued `info mem` command and saw this:

Code: Select all

(qemu) info mem
ffff800000000000-ffff800100000000 0000000100000000 -rw
ffffffff80000000-ffffffff80005000 0000000000005000 -r-
ffffffff80005000-ffffffff80006000 0000000000001000 -rw
The memory being accessed (written to) is marked as read only. So this is why you are getting an exception. When I dump your kernel.sys file (in the ISO) with objdump I see this:

Code: Select all

1 .idt          00001000  ffffffff80003000  ffffffff80003000  00004000  2**12
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
Your `_idt` array starts at 0xffffffff80003000 and is in a read only section. This is because you defined `_idt` in the linker script and the default for the section was made readonly.

Obviously you need to put `_idt` in a read/write section. If you defined `_idt` in a CPP file as a global array you could avoid this problem.
Post Reply