User:Primis

From OSDev Wiki
Jump to: navigation, search

Initial Setup

In order to make our kernel work, we must be able to compile it, and link it. We have two different ways of building our code, the *NIX way with a Makefile, and the Windows way with a Batch file.

First is the Makefile:

# Makefile for our kernel
# This is designed for *NIX and Cygwin systems
# Use build.BAT for windows systems
# Requires GCC and NASM
# Based on JamesM's Kernel Tutorials

SOURCES=boot.o main.o

CFLAGS=-nostdlib -nostdinc -fno-builtin
LDFLAGS=-Tlink.ld
ASFLAGS=-felf

all: 
 $(SOURCES) link

clean: 
 -rm *.o kernel

link:  
 ld $(LDFLAGS) -o kernel $(SOURCES)

.s.o:  
 nasm $(ASFLAGS) $<

The basics are all quite simple, the only rule specifically changed is the assembler, which we've changed from GAS to NASM, The reason quite simply, Intel Syntax is more widely preferred over AT&T syntax in the x86 Assembly world.

// main.c -- Called from assembly, this is our main function.
int k_main() // We call this k_main() so we don't get main() warnings.
{
  return (0xDEADBEEF);
}
Personal tools
Namespaces
Variants
Actions
Navigation
About
Toolbox