- My kernel binary is in a elf32-i386 file format, I'm using the GNU assembler and Clang as the compiler, lastly my code is supposed to output 'a' to the screen
I'm guessing the linker can't find the Start code because it won't assemble but I couldn't figure out how to fix these problems I've spent days with objdump, gdb, etc. and still can't fix this. I have figured out that the clang compiler can't cast anything so I can't figure out how to print something to the screen. I have no idea what the gnu assembler error is.entry.s: Assembler messages:
entry.s: Error: can't open entry.o for reading: No such file or directory
main.c:4:9: warning: incompatible integer to pointer conversion assigning to
'char *' from 'int';
vidmem=0xB8000;
^~~~~~~~
1 warning generated.
ld: warning: cannot find entry symbol Start; defaulting to 0000000001000000
Here's my linker script
Code: Select all
ENTRY("Start") #We start running the code at the Start function
TARGET(elf32-i386) #We are writing our code for the i386 and above processor family and the binary is in a elf 32 file format
SECTIONS
{
#We're starting our code at the address 0x1000000
. = 0x1000000;
#We're aligning our code to the next page
.text ALIGN(0x1000) :{
*(.text)
}
.data ALIGN(0x1000) :{
*(.data)
}
.rodata ALIGN(0x1000) :{
*(.rodata)
}
.bss ALIGN(0x1000) :{
*(.COMMON)
*(.bss)
}
}
Here's my entry.s file which is loaded from grub/other bootloader
Code: Select all
.global Start #Make this readable from the linker
.extern main #Find the main functions
#Multiboot Header Information
.align 4
.set MAGIC, 0x1BADB002
.set FLAGS, 3
.set CHECKSUM, -(MAGIC + FLAGS)
#This is the first executed code
Start:
cli
mov $(StackEnd + StackSize), %esp #Setup the stack
cmp $0x2BADB002, %eax
jne end
push %ebx #Pass the multiboot address pointer
call main #Call the main function
#This halts the system
end:
cli
hlt
.set StackSize, 0x1000 #The stack is going to be 4096 bytes
.comm StackEnd, StackSize #Reserve 4096 bytes for the stack
Code: Select all
void main(int Multiboot)
{
char *vidmem;
vidmem=0xB8000; //Video memory is at the address 0xB8000
*vidmem='a'; //Print A to the scree
vidmem++;
*vidmem=0xF0; //White on black
}
Code: Select all
assemble="as" #We're using the GNU Assembler
x86_options="-c" #We're
compile="clang"
clang_options="-ffreestanding -I../Include -nostdinc -c"
link="ld"
ld_options="-A i386 -T link.ld -o kernel.bin *.o"
mount_location="/media/floppy1"
echo "[Starting...]"
echo "Making OS virtual floppy image"
cp boot/image/os++.img Build
cd Core
echo "Creating kernel binary"
#Assemble code to x86
$assemble $x86_options entry.s entry.o
#Compile code to x86 elf format
$compile $clang_options main.c
#Link to x86 elf format
$link $ld_options
cd ..
echo "Copying object files"
cp Core/*.o Build/object
rm Core/*.o
echo "Copying build to build directory"
cp Core/kernel.bin Build
rm Core/kernel.bin
echo "Creating temporary mounting folder"
sudo mkdir /media/floppy1
echo "Mounting OS virtual floppy image"
sudo mount -o loop Build/os++.img $mount_location
echo "Copying build files to OS virtual floppy image"
cp Build/kernel.bin /media/floppy1
echo "Unmounting OS virtual floppy image"
cd Build
umount /media/floppy1
cd ..
echo "Removing Mounting Folder"
sudo rm -r /media/floppy1
echo "[Done]"
Jackson