Page 1 of 1

GRUB Error 13, can't statically link either

Posted: Thu Jul 20, 2023 4:32 am
by milkcool
Hello everyone! I'm new to os development also new to this forum. I've tried everything I could find online, but couldn't succeed.
When I'm compiling, linking and booting my OS GRUB gives me the error 13. I am trying to follow this tutorial https://hasinisama.medium.com/building- ... 6425adb084 (this is the 2nd part), but I'm trying to include standard C libraries as well as trying to make the system 64 bit.
kernel/main.c: https://pastebin.com/ceQjSGnJ
loader.s: https://pastebin.com/PUYi48Ve
Makefile: https://pastebin.com/GyHjPDmd
link.ld: https://pastebin.com/2qxCebER
What am I doing wrong? Thanks in advance :)

Re: GRUB Error 13, can't statically link either

Posted: Thu Jul 20, 2023 8:37 pm
by Octocontrabass
milkcool wrote:What am I doing wrong?
  • Following a tutorial
  • Trying to include standard C libraries
  • Not switching to 64-bit mode
Most tutorials focused on or around OS development have mistakes. Usually the author is a beginner like you, documenting their process as they go, including their mistakes that they haven't noticed yet. Most tutorial authors give up before they reach the point where they could go back and correct their mistakes.

Standard C libraries depend on an OS. You're trying to include standard C libraries designed to run on Linux. Your OS is not compatible with Linux (for now), so the Linux C libraries won't work. You can use freestanding C headers; those don't depend on an OS.

Multiboot says the CPU starts in 32-bit mode. You have to switch the CPU into 64-bit mode before you can run 64-bit code. Switching to 64-bit mode is not exactly simple; you need to set up a GDT and some page tables, and mess with a handful of control registers. If you really want to write a 64-bit OS, you might have an easier time if you use a bootloader that can handle switching to 64-bit mode (such as Limine). You'll still need to set up a GDT and some page tables eventually, but then you can put it off until you're more familiar with x86.

Re: GRUB Error 13, can't statically link either

Posted: Fri Jul 21, 2023 1:32 am
by davmac314
You cannot use a system C library, designed to work in programs running in user space under a particular kernel, in your own kernel which does not run under that kernel.