0

Good evening.
I am currently making a Custom Operating System for education purposes. In my Bootloader, I have these section for reading and writing ports. One line in the section is producing the error(I am using AT&T Assembler):
Error: redefined symbol cannot be used on reloc
This is the code line:
mov %edx, [%esp + 4]

These are my port sections:

read_port:
    mov %edx, [%esp + 4]
    in %dx, %al
    ret

write_port:
    mov %edx, [%esp + 4]    
    mov %al, [%esp + 4 + 4]  
    out %al, %dx  
    ret

load_idt:
    mov %edx, [%esp + 4]
    lidt [edx]
    sti                 
    ret

I use them in my Keyboard driver:

#include "header/keyboard_map.h"

void keyboard_handler_main(void)
{
    unsigned char status;
    char keycode;

    write_port(0x20, 0x20);

    status = read_port(KEYBOARD_STATUS_PORT);
    if (status & 0x01)
    {
        keycode = read_port(KEYBOARD_DATA_PORT);
        if (keycode < 0)
            return;
        vidptr[current_loc++] = keyboard_map[keycode];
        vidptr[current_loc++] = 0x07;
    }
}

And in my IDT:

struct IDT_entry
{
    unsigned short int offset_lowerbits;
    unsigned short int selector;
    unsigned char zero;
    unsigned char type_attr;
    unsigned short int offset_higherbits;
};

struct IDT_entry IDT[IDT_SIZE];

void idt_init(void)
{
    unsigned long keyboard_address;
    unsigned long idt_address;
    unsigned long idt_ptr[2];

    keyboard_address = (unsigned long)keyboard_handler;
    IDT[0x21].offset_lowerbits = keyboard_address & 0xffff;
    IDT[0x21].selector = 0x08;
    IDT[0x21].zero = 0;
    IDT[0x21].type_attr = 0x8e;
    IDT[0x21].offset_higherbits = (keyboard_address & 0xffff0000) >> 16;

    write_port(0x20, 0x11);
    write_port(0xA0, 0x11);

    write_port(0x21, 0x20);
    write_port(0xA1, 0x28);

    write_port(0x21, 0x00);
    write_port(0xA1, 0x00);

    write_port(0x21, 0x01);
    write_port(0xA1, 0x01);

    write_port(0x21, 0xff);
    write_port(0xA1, 0xff);

    idt_address = (unsigned long)IDT;
    idt_ptr[0] = (sizeof(struct IDT_entry) * IDT_SIZE) + ((idt_address & 0xffff) << 1 6);

    load_idt(idt_ptr);
}

void kb_init(void)
{
    /* Enables Keyboard */
    write_port(0x21, 0xFD);
}
Teer 2008
  • 79
  • 1
  • 7
  • 3
    Please show your code or an [mcve]. This looks like you are trying to combine AT&T with Intel syntax in some weird way. Also let us know what assembler you use. – fuz May 18 '22 at 16:31
  • @fuz I'm using AT&T Assembler, I also updated my question a bit to show more of my code. – Teer 2008 May 18 '22 at 16:47
  • This is very strange. AT&T assembly uses round parentheses, not square brackets for indirection. – fuz May 18 '22 at 16:48
  • 1
    If I fix your syntax to be correct (refer to the manual for details), e.g. using `mov %edx, 4(%esp)`, then it assembles just fine. Please revisit how AT&T syntax works. – fuz May 18 '22 at 16:50
  • Thanks, it works just fine. I think the blog post I followed wasn't made for AT&T – Teer 2008 May 18 '22 at 16:53
  • 1
    It is very likely. Had you linked this blog post, I would have been able to give the correct answer immediately. – fuz May 18 '22 at 16:56
  • Note also that AT&T syntax flips all operands in comparison to Intel syntax. Revisit your code and check if the operand order is correct. – fuz May 18 '22 at 16:57

0 Answers0