kernel.cpp Undefined Reference Error

Programming, for all ages and all languages.
Post Reply
Mehmetdev1
Posts: 23
Joined: Fri Apr 01, 2022 10:06 am
Location: Türkiye, Uşak/Merkez

kernel.cpp Undefined Reference Error

Post by Mehmetdev1 »

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: Select all

#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: Select all

#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: Select all

 
#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: Select all

.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
M. Alp
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: kernel.cpp Undefined Reference Error

Post by iansjack »

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.
User avatar
Demindiro
Member
Member
Posts: 96
Joined: Fri Jun 11, 2021 6:02 am
Libera.chat IRC: demindiro
Location: Belgium
Contact:

Re: kernel.cpp Undefined Reference Error

Post by Demindiro »

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:
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)
Mehmetdev1
Posts: 23
Joined: Fri Apr 01, 2022 10:06 am
Location: Türkiye, Uşak/Merkez

Re: kernel.cpp Undefined Reference Error

Post by Mehmetdev1 »

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
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: kernel.cpp Undefined Reference Error

Post by iansjack »

You should learn how to program rather than blindly following a tutorial. That tutorial is not connected with these forums.
nullplan
Member
Member
Posts: 1766
Joined: Wed Aug 30, 2017 8:24 am

Re: kernel.cpp Undefined Reference Error

Post by nullplan »

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!
davmac314
Member
Member
Posts: 121
Joined: Mon Jul 05, 2021 6:57 pm

Re: kernel.cpp Undefined Reference Error

Post by davmac314 »

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.
Ethin
Member
Member
Posts: 625
Joined: Sun Jun 23, 2019 5:36 pm
Location: North Dakota, United States

Re: kernel.cpp Undefined Reference Error

Post by Ethin »

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.
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: kernel.cpp Undefined Reference Error

Post by iansjack »

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 ‘;’”.
Post Reply