Something's not ok with Pascal Bare Bones

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
User avatar
Synapse
Posts: 6
Joined: Tue Sep 08, 2015 6:53 pm

Something's not ok with Pascal Bare Bones

Post 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?
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Something's not ok with Pascal Bare Bones

Post by Roman »

GRUB pre-2 doesn't support ELF64.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
User avatar
Synapse
Posts: 6
Joined: Tue Sep 08, 2015 6:53 pm

Re: Something's not ok with Pascal Bare Bones

Post by Synapse »

Code: Select all

[major@localhost ~]$ grub-install -V
grub-install (GRUB) 2.02~beta2
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Something's not ok with Pascal Bare Bones

Post by Roman »

What architecture are you targeting?
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
User avatar
Synapse
Posts: 6
Joined: Tue Sep 08, 2015 6:53 pm

Re: Something's not ok with Pascal Bare Bones

Post by Synapse »

I want to run my OS on X86_64 processors.
User avatar
BASICFreak
Member
Member
Posts: 284
Joined: Fri Jan 16, 2009 8:34 pm
Location: Louisiana, USA

Re: Something's not ok with Pascal Bare Bones

Post 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)
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
Sortie wrote:
  • Don't play the role of an operating systems developer, be one.
  • Be truly afraid of undefined [behavior].
  • Your operating system should be itself, not fight what it is.
Kevin
Member
Member
Posts: 1074
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Something's not ok with Pascal Bare Bones

Post 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.
Developer of tyndur - community OS of Lowlevel (German)
User avatar
Nutterts
Member
Member
Posts: 159
Joined: Wed Aug 05, 2015 5:33 pm
Libera.chat IRC: Nutterts
Location: Drenthe, Netherlands

Re: Something's not ok with Pascal Bare Bones

Post 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.
"Always code as if the guy who ends up maintaining it will be a violent psychopath who knows where you live." - John F. Woods

Failed project: GoOS - https://github.com/nutterts/GoOS
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Something's not ok with Pascal Bare Bones

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply