From bootsector to C ++ kernel

I decided to write a simple asm loader and C ++ kernel. I read a lot of tutorials, but I can not compile the assembly file as shown below:

[BITS 32]
[global start]
[extern _k_main]
start:
   call _k_main
   cli
   hlt

(I would like to call the k_main function from the c file)

Compile / compile / link errors:

nasm -f bin -o kernelstart.asm -o kernelstart.bin:
error: bin file cannot contain external references

okay, then I tried to create a .o file:

nasm -f aout -o kernelstart.asm -o kernelstart.o  (That right)
ld -i -e _main -Ttext 0x1000 kernel.o kernelstart.o main.o
error: File format not recognized

Someone give me a plz working example or say how to compile.: / (I look through the tutorials and helps 2 days ago, but can not find the correct answer)

+3
source share
1 answer

I have no direct answer to where your error comes from. However, I see a lot of errors, so I will write them here:

NASM

nasm -f aout -o kernelstart.asm -o kernelstart

Does it even work? It should be something like

nasm -f aout -o kernelstart kernelstart.asm

ld

ld -i -e _main -Ttext 0x1000 kernel.o kernelstart.o main.o

, , , , ld , MBR. , :

  • . MBR-, --oformat=binary . .
  • _main. , , , , start, , .
  • text, 0x1000. MBR BIOS, 0x7c00.
  • : , ​​ . , MBR 512 (, 510 , 2 ), . , .

, .

, OSDev. - " ​​" , MBR. .

+3

Source: https://habr.com/ru/post/1785251/


All Articles