Page 1 of 1

Something's not ok with Pascal Bare Bones

Posted: Tue Sep 08, 2015 7:11 pm
by Synapse
I've successfully compiled and ran the Bare Bones tutorial, but as my favourite programming language is pascal, I tought I would continue with the pascal barebones.
I found some now-dead pascal operating systems scattered around the internet, wrote some ideas down, but currently I'm stuck, because I cannot link the compiled stuff listed in the Pascal Bare Bones wiki article.

Code: Select all

[major@localhost Build 2]$ ld --gc-sections -s -Tlinker.script -o kernel.obj stub.o kernel.o multiboot.o system.o console.o
ld: i386 architecture of input file `stub.o' is incompatible with i386:x86-64 output
[major@localhost Build 2]$ file stub.o
stub.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
[major@localhost Build 2]$ 
[major@localhost Build 2]$ which i386-elf-ld
/home/major/opt/cross/bin/i386-elf-ld
[major@localhost Build 2]$ i386-elf-ld --gc-sections -s -Tlinker.script -o kernel.obj stub.o kernel.o multiboot.o system.o console.o
kernel.o: file not recognized: File format not recognized
[major@localhost Build 2]$
[major@localhost Build 2]$ file kernel.o
kernel.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
[major@localhost Build 2]$ x86_64-elf-ld --gc-sections -s -Tlinker.script -o kernel.obj stub.o kernel.o multiboot.o system.o console.o
x86_64-elf-ld: i386 architecture of input file `stub.o' is incompatible with i386:x86-64 output
[major@localhost Build 2]$ 
 
Please advise me, what should I do. The files are created and compiled exactly as the Pascal Bare Bones tutorial said.

Thanks in advance!

EDIT: I found the solution to this problem, but I've found the next one. I have to use "nasm -f elf64" insted of "nasm -f elf" but for some reason when I boot the iso, grub loads successfully, but it says to my shiny new os that it is not multiboot compliant. Maybe GRUB cannot load the kernel.obj file as it is elf64 too?

Re: Something's not ok with Pascal Bare Bones

Posted: Wed Sep 09, 2015 12:23 am
by Roman
GRUB pre-2 doesn't support ELF64.

Re: Something's not ok with Pascal Bare Bones

Posted: Wed Sep 09, 2015 12:52 am
by Synapse

Code: Select all

[major@localhost ~]$ grub-install -V
grub-install (GRUB) 2.02~beta2

Re: Something's not ok with Pascal Bare Bones

Posted: Wed Sep 09, 2015 1:24 am
by Roman
What architecture are you targeting?

Re: Something's not ok with Pascal Bare Bones

Posted: Wed Sep 09, 2015 4:14 pm
by Synapse
I want to run my OS on X86_64 processors.

Re: Something's not ok with Pascal Bare Bones

Posted: Wed Sep 09, 2015 6:36 pm
by BASICFreak
You need to compile AND link to the SAME architecture.

Some of your files are i386 and some are i386:x86-64. Should be simple enough for you to figure out

ld: i386 architecture of input file `stub.o' is incompatible with i386:x86-64 output

To run x86_64 with grub, you will need a 32-bit loader stub - grub doesn't load x64.

http://wiki.osdev.org/Creating_a_64-bit ... our_kernel

Also multiboot has a special place it wants to be, make sure it is where it is supposed to be.

EDIT: Does Grub 2 really support x64? (I haven't tried - Even on my dev system I have Grub Legacy)

Re: Something's not ok with Pascal Bare Bones

Posted: Thu Sep 10, 2015 6:25 am
by Kevin
Synapse wrote:I want to run my OS on X86_64 processors.
That doesn't really answer the question as x86_64 processors are backwards compatible and run i386 OSes just fine. If you don't know what you want, you probably want i386 (Protected Mode) because it's a bit easier to start out. The native x86_64 mode (Long Mode) requires that you enable things like paging from the very beginning, while in PM you can enable it when you feel ready for it.

Re: Something's not ok with Pascal Bare Bones

Posted: Mon Sep 14, 2015 4:46 pm
by Nutterts
Synapse wrote:I've successfully compiled and ran the Bare Bones tutorial, but as my favorite programming language is pascal, I thought I would continue with the pascal barebones
It's for the D language but I found it very informative for a x86_64 bootstrap: http://wiki.osdev.org/D_barebone_with_ldc2

Imho in most cases you'll just want to write a 32bit kernel what the pascal barebone on the wiki will get your started with. There's simply much more information out there about how to do a 32bit kernel and fun stuff with it.

I'm also working on a 64bit one (although not in pascal even tho I love pascal) but I can't say it's been fun till now. There's allot of gotcha's. Things that might bite you later on like changing video modes.

Re: Something's not ok with Pascal Bare Bones

Posted: Tue Sep 15, 2015 2:14 am
by Combuster
Frequently asked questions wrote:Your build calls "gcc" and/or "ld". That's not how you should use a compiler. Sadly, this practice also breaks several tutorials in the wild.
Turned out we have another victim for that one.

I'm not a Pascal hero at all and I haven't tested my changes, but the tutorial should now be more explicit about not using the wrong versions of the tools to begin with.