Can't Link together the Descriptor Tables

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
aswinmohanme
Posts: 7
Joined: Tue Dec 01, 2015 7:01 am

Can't Link together the Descriptor Tables

Post by aswinmohanme »

I recently started James Molly's Kernel Devolpment Tutorials and has come as far as implementing the GDT and IDT .

The problem arises when I link together the high level functions with their low level assembly counterparts .

You can Find the Code here
https://github.com/aswinmohanme/Just-Another-OS

Here is the Directory Structure
.
|-- arch
|-- boot
| |-- boot.s
| |-- buildboot.sh
| |-- gdt.s
| |-- idt.s
| `-- interrupt.s
|-- build
| |-- boot.s.o
| |-- gdt.o
| |-- gdt.s.o
| |-- idt.o
| |-- idt.s.o
| |-- interrupt.s.o
| |-- io.o
| |-- isr.o
| |-- main.o
| |-- memory.o
| |-- monitor.o
| `-- stdlib.o
|-- doc
| `-- Bug_Log.md
|-- include
| |-- gdt.cc
| |-- gdt.h
| |-- gdt.o
| |-- idt.cc
| |-- idt.h
| |-- idt.o
| |-- io.cc
| |-- io.h
| |-- io.o
| |-- isr.cc
| |-- isr.h
| |-- isr.o
| |-- memory.cc
| |-- memory.h
| |-- memory.o
| |-- monitor.cc
| |-- monitor.h
| |-- monitor.o
| |-- SConstruct
| |-- stdlib.cc
| |-- stdlib.h
| |-- stdlib.o
| `-- system.h
|-- JOSMake.sh
|-- link.ld
|-- main.cc
`-- ReadMe.md

Here is the Bash Scripts
JOSmake.sh

Code: Select all

#
# Build File for JOS
#
# To Build
# 	 bash build.sh
# To Run
#	bash run.sh

# ----------------------------------------------------------------------------------------------
# JOS uses assembly to build the bootsector
# Compile the boot Sectors in boot
echo "==============================================="
echo "-------- Building Boot Sectors ----------------"
cd boot
# Run the Make Script inside the boot directory
bash buildboot.sh
cd ..
echo "==============================================="
# ----------------------------------------------------------------------------------------------

# ----------------------------------------------------------------------------------------------
# Compile the C++ Sources into Respective Objects
# Compile main.cc
echo "==============================================="
echo "--------- Compiling C++ Sources --------------"
g++ -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 -o main.o main.cc
mv main.o build
# Run scons to build the Entire Lbrary of C++ Files
cd include
rm *.o
scons
# Move all Object Files into Build Directory
cp *.o ../build
cd ..
echo "==============================================="
# ----------------------------------------------------------------------------------------------

# ----------------------------------------------------------------------------------------------
## When Everything is Finished Link together the Objects into a Kernel File
echo "==============================================="
echo "--------- Linking ----------------"
cd build
# require ld , link.ld
ld  -T '../link.ld' -m elf_i386 -o  kernel.jos *.o
# Clean Up After Build
#rm *.o
echo "==============================================="
# ----------------------------------------------------------------------------------------------

# ----------------------------------------------------------------------------------------------
## When Everything is Finished Run the Kernel
qemu-system-i386 -kernel kernel.jos
# -----------------------------------------------------------------------------------------
Here is the buildboot.sh

Code: Select all

# Builds the Boot files for JOS
# require 'nasm'

# Add all the Assembly Files Here
nasm -f elf -o boot.s.o boot.s
nasm -f elf -o gdt.s.o gdt.s
nasm -f elf -o idt.s.o idt.s
nasm -f elf -o interrupt.s.o interrupt.s

# Move the Entire Object Files into the Build Directory
mv *.o ../build
And here is the Terminal Output when I run the Script

Code: Select all

===============================================
-------- Building Boot Sectors ----------------
===============================================
===============================================
--------- Compiling C++ Sources --------------
In file included from include/system.h:22:0,
                 from main.cc:6:
include/idt.h:34:13: warning: ‘void init_idt()’ used but never defined
 static void init_idt();
             ^
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o gdt.o -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 gdt.cc
g++ -o idt.o -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 idt.cc
g++ -o io.o -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 io.cc
g++ -o isr.o -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 isr.cc
g++ -o memory.o -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 memory.cc
g++ -o monitor.o -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 monitor.cc
g++ -o stdlib.o -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 stdlib.cc
scons: done building targets.
===============================================
===============================================
--------- Linking ----------------
gdt.o: In function `init_gdt()':
gdt.cc:(.text+0xb0): undefined reference to `gdt_flush(unsigned int)'
idt.o: In function `init_idt()':
idt.cc:(.text+0x3a): undefined reference to `isr0()'
idt.cc:(.text+0x51): undefined reference to `isr1()'
idt.cc:(.text+0x68): undefined reference to `isr2()'
idt.cc:(.text+0x7f): undefined reference to `isr3()'
idt.cc:(.text+0x96): undefined reference to `isr4()'
idt.cc:(.text+0xad): undefined reference to `isr5()'
idt.cc:(.text+0xc4): undefined reference to `isr6()'
idt.cc:(.text+0xdb): undefined reference to `isr7()'
idt.cc:(.text+0xf2): undefined reference to `isr8()'
idt.cc:(.text+0x109): undefined reference to `isr9()'
idt.cc:(.text+0x120): undefined reference to `isr10()'
idt.cc:(.text+0x137): undefined reference to `isr11()'
idt.cc:(.text+0x14e): undefined reference to `isr12()'
idt.cc:(.text+0x165): undefined reference to `isr13()'
idt.cc:(.text+0x17c): undefined reference to `isr14()'
idt.cc:(.text+0x193): undefined reference to `isr15()'
idt.cc:(.text+0x1aa): undefined reference to `isr16()'
idt.cc:(.text+0x1c1): undefined reference to `isr17()'
idt.cc:(.text+0x1d8): undefined reference to `isr18()'
idt.cc:(.text+0x1ef): undefined reference to `isr19()'
idt.cc:(.text+0x206): undefined reference to `isr20()'
idt.cc:(.text+0x21d): undefined reference to `isr21()'
idt.cc:(.text+0x234): undefined reference to `isr22()'
idt.cc:(.text+0x24b): undefined reference to `isr23()'
idt.cc:(.text+0x262): undefined reference to `isr24()'
idt.cc:(.text+0x279): undefined reference to `isr25()'
idt.cc:(.text+0x290): undefined reference to `isr26()'
idt.cc:(.text+0x2a7): undefined reference to `isr27()'
idt.cc:(.text+0x2be): undefined reference to `isr28()'
idt.cc:(.text+0x2d5): undefined reference to `isr29()'
idt.cc:(.text+0x2ec): undefined reference to `isr30()'
idt.cc:(.text+0x303): undefined reference to `isr31()'
idt.cc:(.text+0x323): undefined reference to `idt_flush(unsigned int)'
interrupt.s.o: In function `isr_common_stub':
interrupt.s:(.text+0x10d): undefined reference to `isr_handler'
main.o: In function `main':
main.cc:(.text+0x17): undefined reference to `init_idt()'
===============================================
qemu: could not load kernel 'kernel.jos': No such file or directory
Please State what am I doing wrong
Octocontrabass
Member
Member
Posts: 5588
Joined: Mon Mar 25, 2013 7:01 pm

Re: Can't Link together the Descriptor Tables

Post by Octocontrabass »

aswinmohanme wrote:Please State what am I doing wrong
You are following a tutorial that is known to contain many bugs.

You are not using a cross compiler. If nothing else, you'll receive better help from us if you're using one.

You are using a C++ compiler without paying attention to the differences between C and C++ calling conventions, or perhaps without being aware there is a difference. (Hint: "extern C" and "name mangling" are good things to search for.)
aswinmohanme
Posts: 7
Joined: Tue Dec 01, 2015 7:01 am

Re: Can't Link together the Descriptor Tables

Post by aswinmohanme »

Octocontrabass wrote: (Hint: "extern C" and "name mangling" are good things to search for.)
Name Mangling was the Culprit , fixed the issue , and Setting up the Cross Compiler right now . :D :D
Thanks for the Help :D
Post Reply