User:Imate900/32-bit assembler bare bones: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
Content deleted Content added
Combuster (talk | contribs)
Restored page from RSS feed. DO NOT DELETE MEANINGFUL CONTENT WITHOUT DISCUSSION
 
Combuster (talk | contribs)
Fixed markup going amiss
Line 5: Line 5:
== GRUB ==
== GRUB ==
All we need is something like this (GNU as):
All we need is something like this (GNU as):
<pre>
.global loader # making entry point visible to linker
.global loader # making entry point visible to linker


Line 22: Line 23:
# Write the kernel here
# Write the kernel here
jmp _start
jmp _start
</pre>


Link with:
Link with:
as -o kernel.o kernel.s
<tt>as -o kernel.o kernel.s</tt>
ld --oformat binary -o kernel.bin kernel.o
<tt>ld --oformat binary -o kernel.bin kernel.o</tt>


For NASM:
For NASM:
<pre>
global loader ; making entry point visible to linker
global loader ; making entry point visible to linker


Line 45: Line 48:
; Write the kernel here
; Write the kernel here
jmp _start
jmp _start

</pre>


Link with:
Link with:
nasm -f bin kernel.asm
<tt>nasm -f bin kernel.asm</tt>


Make sure you have a GRUB entry...
Make sure you have a GRUB entry...
title Assembler Barebones
title Assembler Barebones
kernel (hd0,0)/boot/kernel.bin
kernel (hd0,0)/boot/kernel.bin


Now, reboot, and enjoy!
Now, reboot, and enjoy!

== Raw (No GRUB) ==
Go crazy (you must convert into AT&T syntax if not using NASM)...
_start:
cli
; It might be a Good Idea(tm) to dump your GDT at the end and load it here
;lgdt [my_gdtr]
mov eax, cr0
or al, 1
mov cr0, eax
; Write your kernel here.
jmp $


[[Category:Bare bones tutorials]]
[[Category:Bare bones tutorials]]

Revision as of 16:49, 20 April 2009

Difficulty level

Medium
Kernel Designs
Models
Other Concepts

This tutorial will teach you how to make a 32-bit assembler kernel.

GRUB

All we need is something like this (GNU as):

.global loader # making entry point visible to linker

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

.align 4
.long MAGIC
.long FLAGS
.long CHECKSUM

_start:
# Write the kernel here
jmp _start

Link with: as -o kernel.o kernel.s ld --oformat binary -o kernel.bin kernel.o

For NASM:

global loader ; making entry point visible to linker

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

mboot:
dd MAGIC
dd FLAGS
dd CHECKSUM

_start:
; Write the kernel here
jmp _start

Link with: nasm -f bin kernel.asm

Make sure you have a GRUB entry...

title Assembler Barebones
kernel (hd0,0)/boot/kernel.bin

Now, reboot, and enjoy!