OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:30 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Error when loading IDT in Long Mode
PostPosted: Wed Jul 21, 2021 11:23 am 
Offline

Joined: Mon Aug 24, 2020 2:25 pm
Posts: 13
Hi everyone, I am developing a 64bit operating system. Right now I'm trying to create an Interrupt Descriptor Table (IDT), but I get an error that I can't get over. Someone can help me? Thanks!

The kernel.cpp:
Code:
#include "textPrint.cpp"
#include "idt.cpp"

extern "C" void _start(){
    setCursorPosition(positionFromCoords(0,0));
    InitializeIDT();
    return;
}


The idt.cpp:
Code:
#pragma once
#include "types.cpp"

/*Interrupt descriptor Table*/
struct IDT64{
   uint_16 offset_low;
   uint_16 selector;
   uint_8 ist;
   uint_8 types_attr;
   uint_16 offset_mid;
   uint_32 offset_high;
   uint_32 zero;
};
extern IDT64 _idt[256];
extern uint_64 isr1;
extern "C" void LoadIDT();

void InitializeIDT(){
   for (uint_64 t = 0; t < 256; t++){
      _idt[t].zero = 0;
      _idt[t].offset_low = (uint_16)(((uint_64)&isr1 & 0x000000000000ffff));
      _idt[t].offset_mid = (uint_16)(((uint_64)&isr1 & 0x00000000ffff0000) >> 16);
      _idt[t].offset_high = (uint_32)(((uint_64)&isr1 & 0xffffffff00000000) >> 32);
      _idt[t].ist = 0;
      _idt[t].selector = 0x08;
      _idt[t].types_attr = 0x8e;
   }   
   outb(0x21, 0xfd);
   outb(0xa1, 0xff);
   LoadIDT();
}

extern "C" void isr1_handler(){
   printString(HexToString(inb(0x60)));
   //uint_8 scanCode = inb(0x60);
   outb(0x20, 0x20);
   outb(0xa0, 0x20);
}


The idt.asm
Code:
[extern _idt]
idtDescriptor:
  dw 4095
  dq _idt

  %macro PUSHALL 0
     push rax
     push rcx
     push rdx
     push r8
     push r9
     push r10
     push r11
  %endmacro

  %macro POPALL 0
     pop r11
     pop r10
     pop r9
     pop r8
     pop rdx
     pop rcx
     pop rax
  %endmacro

[extern isr1_handler]
isr1:
  PUSHALL
  call isr1_handler
  POPALL
  iretq
  GLOBAL isr1

LoadIDT:
  lidt[idtDescriptor]
  sti
  ret
  GLOBAL LoadIDT


O erro acontece quando, no idt.asm, rodo a função lidt, se apagar esta linha o erro não acontece, mas a idt também não é ativada. A minha idt é inválida? Na consola de debug do Bochs (no ficheiro anexo) parace-me que o código salta para um "void":

Quote:
read() on floppy image returns 0


Por outro lado parece-me que a idt é de facto inválida:
Quote:
interrupt(long mode): gate descriptor is not valid sys seg


Attachment:
File comment: The Bochs Report
report.txt [38.72 KiB]
Downloaded 54 times


The Github Repo: https://github.com/Jmallone/os-dev/tree/main/pt12/Sector%201


Top
 Profile  
 
 Post subject: Re: Error when loading IDT in Long Mode
PostPosted: Wed Jul 21, 2021 4:54 pm 
Offline
Member
Member

Joined: Mon Jul 05, 2021 6:57 pm
Posts: 118
In GDT.ASM:

Code:
gdt_codedesc:
   dw 0xFFFF    ; Limit
   dw 0x0000   ; Base(low)
   db 0x00      ; base(medium)
   db 10011010b; Flags
   db 11001111b; Flags + upper limit
   db 0x00      ; Base(high)


The "flags + upper limit" is wrong for a long mode code segment. bit 7 should be clear, bit 6 ("L") should be set. The correct value would be 10101111b.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 86 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group