Hi,
I'm trying to follow the HigherHalf with GDT tutorial but I've run into a small problem. My Loader (boot.asm -> loader.o) reports it can't find the GP Struct (which I define in gdt.c and also extern in gdt.h) and gdt.c reports it can't find the function (which is created in the boot.asm) gdt_flush() which it prototypes.
What stupidly obvious thing am I missing here?
Trouble Follow HH tutorial
Re:Trouble Follow HH tutorial
Sorry having an off day Forgot to include any code
gdt.c -
gdt.h -
Linking batch file -
Linker Script and Boot.asm are exactly as appear in the tutorial.
gdt.c -
Code: Select all
#include "../includes/gdt.h"
// We'll need at least 3 entries in our GDT...
struct gdt_entry gdt[3];
struct gdt_ptr gp;
// Extern assembler function
void gdt_flush();
// Very simple: fills a GDT entry using the parameters
void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran)
{
gdt[num].base_low = (base & 0xFFFF);
gdt[num].base_middle = (base >> 16) & 0xFF;
gdt[num].base_high = (base >> 24) & 0xFF;
gdt[num].limit_low = (limit & 0xFFFF);
gdt[num].granularity = ((limit >> 16) & 0x0F);
gdt[num].granularity |= (gran & 0xF0);
gdt[num].access = access;
}
// Sets our 3 gates and installs the real GDT through the assembler function
void gdt_install()
{
gp.limit = (sizeof(struct gdt_entry) * 6) - 1;
gp.base = (unsigned int)&gdt;
gdt_set_gate(0, 0, 0, 0, 0);
gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
gdt_flush();
};
Code: Select all
#ifndef KERNEL_GDT_H
#define KERNEL_GDT_H
/*=============
PROTOTYPES
==============*/
void gdt_install();
/*=============
STRUCTURES
==============*/
struct gdt_entry
{
unsigned short limit_low;
unsigned short base_low;
unsigned char base_middle;
unsigned char access;
unsigned char granularity;
unsigned char base_high;
} __attribute__((packed));
struct gdt_ptr
{
unsigned short limit;
unsigned int base;
} __attribute__((packed));
/*=============
EXTERNALS
==============*/
extern struct gdt_ptr gp;
#endif
Code: Select all
@echo off
set DJGPP=C:\DJGPP\DJGPP.ENV
set PATH=C:\DJGPP\BIN;%PATH%
echo Building Bootstrap...
nasmw -f elf boot.asm -o Release\loader.o
move Kernel\*.o .\Release
move Kernel\mem\*.o .\Release
echo Linking...
ld-elf -T kernel.ld -o Release\kernel.bin Release\loader.o Release\gdt.o Release\paging.o Release\main.o
Re:Trouble Follow HH tutorial
I resolved it incidentally and thought I'd better include it here for anyone searching at a later date.
I simply renamed all instances of gdt_flush and gp in the boot.asm to _gdt_flush and _gp respectivly
I simply renamed all instances of gdt_flush and gp in the boot.asm to _gdt_flush and _gp respectivly
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Trouble Follow HH tutorial
aah. the good old issue of auto-prepend'd underscores ... DOS & WIndows export C main() as "_main" while the rest of the known universe exports it as "main" ... if you're using GCC, you can use -fno-leading-underscore so that your cygwin/djgpp/mingw behave likes the rest of known universe (alternatively, you can use -fleading-underscore to ease following a cygwin/djgpp tutorial under linux).elaverick wrote: I resolved it incidentally and thought I'd better include it here for anyone searching at a later date.
I simply renamed all instances of gdt_flush and gp in the boot.asm to _gdt_flush and _gp respectivly