Compiling the kernel into a binary on mac

I followed these tutorials to make a simple kernel that I would then boot using GRUB. The compilation instructions did not work (ld could not find the -T option), and when I finally got the compiled file, it was in Macho format. What are the correct steps when building these files on a Mac.
Edit:
I compiled the code in an Ubuntu virtual machine, and so I have a kernel.bin file. Now, how can I make a boot image that launches the kernel?

+3
source share
3 answers

You will need to do something for this.

-, , nasm, gcc ld macho i386. -f macho nasm, -m32 gcc -arch i386 ld, x86_64 .

-, GRUB - ELF. - GRUB, , ​​macho multiboot.

, 16- FLAGS multiboot:

FLAGS 1<<16 | whateverelse

GRUB , , , .

GRUB . , 4 , GRUB ( ) :

  • header_addr: , ​​ . .text. (: .text )
  • load_addr: , GRUB . ,.text - , .text location
  • load_end_addr: GRUB . - stack+STACKSIZE.
  • bss_end_addr: BSS. , , load_end_addr .
  • entry_addr: . OS X start, loader.

:

global start           ; making entry point visible to linker
extern _kmain            ; kmain is defined elsewhere

; setting up the Multiboot header - see GRUB docs for details
MODULEALIGN equ  1<<0                   ; align loaded modules on page boundaries
MEMINFO     equ  1<<1                   ; provide memory map
MACHO       equ  1<<16
FLAGS       equ  MODULEALIGN | MEMINFO | MACHO  ; this is the Multiboot 'flag' field
MAGIC       equ  0x1BADB002           ; 'magic number' lets bootloader find the header
CHECKSUM    equ -(MAGIC + FLAGS)        ; checksum required

section .text
align 4
MultiBootHeader:
   dd MAGIC
   dd FLAGS
   dd CHECKSUM
   dd MultiBootHeader
   dd MultiBootHeader
   dd stack+STACKSIZE
   dd stack+STACKSIZE
   dd start

; reserve initial kernel stack space
STACKSIZE equ 0x4000                  ; that 16k.

start:
   mov esp, stack+STACKSIZE           ; set up the stack
   push eax                           ; pass Multiboot magic number
   push ebx                           ; pass Multiboot info structure

   call  _kmain                       ; call kernel proper

   cli
hang:
   hlt                                ; halt machine should kernel return
   jmp   hang

section .bss
align 4
stack:
   resb STACKSIZE                     ; reserve 16k stack on a doubleword boundary

, GRUB kernel 200+x, "multiboot-kludge" , . boot ​​macho, !

+4

Mac, Mac EFI (). - Sun VirtualBox Linux - , , , , ( HD, -).

+3

rEFIt, Windows Linux ( ) Mac.

Mac VM, , Q , VMWare Fusion.

0

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


All Articles