OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: kernel.cpp Undefined Reference Error
PostPosted: Sat May 07, 2022 8:37 am 
Offline

Joined: Fri Apr 01, 2022 10:06 am
Posts: 23
Location: Türkiye, Uşak/Merkez
I am getting kernel.cpp Undefined Reference Error. I am sharing the source code of kernel.cpp, interrupts.cpp, interrupt.h interruptstubst.s files and the screenshot of the error. What is the solution for the error?

Kernel.cpp Code:
Code:
#include "types.h"
#include "gdt.h"
#include "interrupts.h"


void printf(char* str)
{
     static uint16_t* VideoMemory = (uint16_t*)0xb8000;
     
     static uint8_t x =0 , y=0;
     
     for(int i = 0; str[i] != '\0'; i++)
     {
       
        switch(str[i])
   {
       case '\n':
           y++;
      x = 0;
         break;
     default:
          VideoMemory[80*y+x] = (VideoMemory[80*y+x] & 0xFF00) | str[i];
         x++;
         break;
   }
   
   
   if(x >= 80)
   {
     y++;
     x = 0;
    
   }
   
   if(y >= 25)
   {
      for(y = 0; y < 25; y++)
          for(x = 0; x < 80; x++)
              VideoMemory[80*y+x] = (VideoMemory[80*y+x] & 0xFF00) | ' '; 
      
     x = 0;
     y=0;
   
   
   }
    }
       
}

extern "C" void kernelMain(const void* multiboot_structure, uint32_t /*multiboot_magic*/)
{
    printf("Kapilar Onyukleyicisine Hosgeldiniz...");
   
   
        GlobalDescriptorTable gdt;
   InterruptManager interrupts(&gdt);
   
   interrupts.Activate();
   
   
   
   
    while(1);
   
}




interrupts.cpp Code:
Code:
#include "interrupts.h"


void printf(char* str);

static void SetInterruptDescriptorTableEntry(
  uint8_t interruptNumber,
  uint16_t codeSegmentSelectorOffset,
  void (*handler) (),
  uint8_t DescriptorPrivlegeLevel,
  uint8_t DescriptorType)
 
{
  uint8_t const IDT_DESC_PRESENT = 0x80;

  interruptDescriptorTable[interruptNumber].handlerAdressLowBits = ((uint32_t)handler) & 0xFFFF;
  interruptDescriptorTable[interruptNumber].handlerAdressHighBits = (((uint32_t)handler) >> 16) & 0xFFFF;
  interruptDescriptorTable[interruptNumber].gdt_codeSegmentSelector = codeSegmentSelectorOffset;
  interruptDescriptorTable[interruptNumber].access = IDT_DESC_PRESENT | DescriptorType | ((DescriptorPrivlegeLevel&3) << 5);
  interruptDescriptorTable[interruptNumber].reserved = 0;
}

InterruptManager::InterruptManager(GlobalDescriptorTable* gdt)
: picMasterCommand(0x20),
  picMasterData(0x21),
  picSlaveCommand(0xA0),
  picSlaveData(0xA1)
 
{
  uint16_t CodeSegment = gdt->CodeSegmentSelector();
  const uint8_t IDT_INTERRUPT_GATE = 0xE;

  for(uint16_t i = 0; i < 256; i++)
     SetInterruptDescriptorTableEntry(i, CodeSegment, &IgnoreInterruptRequest, 0, IDT_INTERRUPT_GATE);

    SetInterruptDescriptorTableEntry(0x20, CodeSegment, &HandleInterruptRequest0x00, 0, IDT_INTERRUPT_GATE);
    SetInterruptDescriptorTableEntry(0x21, CodeSegment, &HandleInterruptRequest0x01, 0, IDT_INTERRUPT_GATE);

   picMasterCommand.Write(0x11);
   picSlaveCommand.Write(0x11);


   picMasterData.Write(0x20);
   picSlaveData.Write(0x28);

   picMasterData.Write(0x04);
   picSlaveData.Write(0x02);

   picMasterData.Write(0x01);
   picSlaveData.Write(0x01);

   picMasterData.Write(0x00);
   picSlaveData.Write(0x00);


    InterruptDescriptorTablePointer idt;
    idt.size = 256 * sizeof(GateDescriptor) - 1;
    idt.base = (uint32_t)interruptDescriptorTable;
    asm volatile("lidt %0" : : "m" (lidt));
}

InterruptManager::~InterruptManager()
{
}

void InterruptManager::Activate()
{
    asm("sti");
}


uint32_t InterruptManager::handleInterrupt(uint8_t interruptNumber, uint32_t esp)
{

    printf(" INTERRUPT");

    return esp;
}




interrupts.h
Code:

#ifndef __INTERRUPTS_H
#define __INTERRUPTS_H

#include "types.h"
#include "port.h"
#include "gdt.h"


class InterruptManager
{

  protected:

  struct GateDescriptor
  {
    uint16_t handlerAdressLowBits;
    uint16_t gdt_codeSegmentSelector;
    uint16_t reserved;
    uint16_t access;
    uint16_t handlerAdressHighBits;

  }  __attribute__((packed));

  static GateDescriptor interruptDescriptorTable[256];

  struct InterruptDescriptorTablePointer
  {
   uint16_t size;
   uint32_t base;
  } __attribute__((packed));
 

  static void SetInterruptDescriptorTableEntry(
  uint8_t interruptNumber,
  uint16_t codeSegmentSelectorOffset,
  void (*handler) (),
  uint8_t DescriptorPrivlegeLevel,
  uint8_t DescriptorType
  );

  Port8BitSlow picMasterCommand;
  Port8BitSlow picMasterData;
  Port8BitSlow picSlaveCommand;
  Port8BitSlow picSlaveData;

  public:

InterruptManager(GlobalDescriptorTable* gdt);
~InterruptManager();

void Activate();
 
  static uint32_t handleInterrupt(uint8_t interruptNumber, uint32_t esp);

  static void IgnoreInterruptRequest();
  static void HandleInterruptRequest0x00();
  static void HandleInterruptRequest0x01();
};




#endif


interruptstubst.s
Code:
.set IRQ_BASE, 0X20

.section .text

.extern _ZN16InterruptManager15handleInterruptEhj

.global _ZN16InterruptManager22IgnoreInterruptRequestEv



.macro HandleException num
.global _ZN16InterruptManager16HandleException\num\()Ev
_ZN16InterruptManager16HandleException\num\()Ev:
      movb $\num, (interruptnumber)
      jmp int_bottom
.endm

.macro HandleInterruptRequest num
.global _ZN16InterruptManager26HandleInterruptRequest\num\()Ev
_ZN16InterruptManager26HandleInterruptRequest\num\()Ev:
      movb $\num + IRQ_BASE, (interruptnumber)
      jmp int_bottom
.endm



HandleInterruptRequest 0x00
HandleInterruptRequest 0x01


int_bottom:
pusha
pushl %ds
pushl %es
pushl %fs
pushl %gs


pushl% esp
push (interruptnumber)
call _ZN16InterruptManager15handleInterruptEhj
# addl $5, %esp
movl %eax, %esp




popl %gs
popl %fs
popl %es
popl %ds
popa

_ZN16InterruptManager22IgnoreInterruptRequestEv:

iret


.data
    interruptnumber: .byte 0


Attachments:
UndifenedReference.png
UndifenedReference.png [ 25.82 KiB | Viewed 5295 times ]

_________________
M. Alp
Top
 Profile  
 
 Post subject: Re: kernel.cpp Undefined Reference Error
PostPosted: Sat May 07, 2022 9:39 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
You cannot keep coming here and asking people to solve every trivial error you encounter.

I sincerely hope that no-one is stupid enough to spoon-feed you the answer.


Top
 Profile  
 
 Post subject: Re: kernel.cpp Undefined Reference Error
PostPosted: Sat May 07, 2022 9:44 am 
Offline
Member
Member
User avatar

Joined: Fri Jun 11, 2021 6:02 am
Posts: 96
Location: Belgium
Mehmet, this is already the 10th topic where you show no sign of having tried to understand the issue on your own, let alone solve it. All you do is recite the error and paste a lot of code each time. It seems you do not even know how to copy an error from a terminal.

I suggest you:

a) Read the forum rules. Specifically, they state that:

Quote:
We are not here to babysit new programmers. Operating system development requires academic thinking and a large amount of knowledge. If you don't have the required knowledge then you may learn faster elsewhere.


b) Learn C++ and assembly outside an OS development context. With the knowledge you have demonstrated so far you will end up nowhere and only achieve endless frustration.

_________________
My OS is Norost B (website, Github, sourcehut)
My filesystem is NRFS (Github, sourcehut)


Top
 Profile  
 
 Post subject: Re: kernel.cpp Undefined Reference Error
PostPosted: Sat May 07, 2022 10:33 am 
Offline

Joined: Fri Apr 01, 2022 10:06 am
Posts: 23
Location: Türkiye, Uşak/Merkez
I am writing the codes in the development video series of your operating system https://www.youtube.com/watch?v=1rnA6wpF0o4 and I am trying to solve the error, I am opening a topic for the errors that I cannot find.

_________________
M. Alp


Top
 Profile  
 
 Post subject: Re: kernel.cpp Undefined Reference Error
PostPosted: Sat May 07, 2022 10:56 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
You should learn how to program rather than blindly following a tutorial. That tutorial is not connected with these forums.


Top
 Profile  
 
 Post subject: Re: kernel.cpp Undefined Reference Error
PostPosted: Sat May 07, 2022 12:10 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
Mehmetdev1 wrote:
I am writing the codes in the development video series of your operating system https://www.youtube.com/watch?v=1rnA6wpF0o4 and I am trying to solve the error, I am opening a topic for the errors that I cannot find.
Maybe a dumb question, but why do you keep following a tutorial after finding out it has errors? Whoever put it together obviously didn't care enough to ensure correctness, so what are you going to learn from it? Plus, if there are errors in it a compiler can find, maybe there are also errors in it a compiler can't find, and then what do you do?

_________________
Carpe diem!


Top
 Profile  
 
 Post subject: Re: kernel.cpp Undefined Reference Error
PostPosted: Sat May 07, 2022 6:45 pm 
Offline
Member
Member

Joined: Mon Jul 05, 2021 6:57 pm
Posts: 118
In general, people will be happy to help you learn and understand concepts, but nobody wants to repeatedly fix trivial compilation and link errors for you, and it's annoying when you ask for it.

You could solve this problem yourself if you learned the underlying concepts - what is linking, how does it work. Go and read up on that. Try some things out to test and build your understanding. Come back if you need clarification on any concept with specific, detailed questions. I'm personally happy to help you with understanding things, but I'm not happy to help you fix errors when you clearly don't understand what the problem is or why the fix works; that's not fulfilling. I'm sure others here feel the same way.


Top
 Profile  
 
 Post subject: Re: kernel.cpp Undefined Reference Error
PostPosted: Sun May 08, 2022 8:26 pm 
Offline
Member
Member

Joined: Sun Jun 23, 2019 5:36 pm
Posts: 618
Location: North Dakota, United States
I've just stopped trying to help at this point and usually just read the topics in question or skip them because the OP continues to show that they either cannot or will not figure out these trivial problems on their own -- which is half the battle of programming and part of what makes a good programmer to begin with. I sincerely hope that the OP develops the inclination necessary to actually learn how to code instead of blindly following what people tell them to do online. Part of learning how to code is getting your own initiative. You can have a ton of unfinished projects, but one thing you must do is practice, continuously. I'm not trying to be rude but this is getting ridiculous, and I wouldn't be surprised if the OP walks away from programming because they got too frustrated, and it was primarily due to their own refusal to try to resolve the problems themselves instead of an actual issue that was extremely difficult to solve. Like I said: trying not to be rude, but this is getting irritating.


Top
 Profile  
 
 Post subject: Re: kernel.cpp Undefined Reference Error
PostPosted: Sun May 08, 2022 11:38 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
To be fair, I think I’ve seen this before. Because the tutorial references osdev.org some people think that these forums are the place to ask questions about the tutorial.

Just to emphasise again; the tutorial that the OP is following is nothing to do with these forums. Even if it were, the questions are trivial problems caused by copying errors on the part of the OP.

Read error messages from the compiler - they normally tell you what and where the mistake is. No-one should ever need to ask “Why does the compiler tell me there is a missing ‘;’”.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 40 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