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);
}