All pastes #3251 Raw Edit

Maw

public text v1 · immutable
#3251 ·published 2004-12-21 17:45 UTC
rendered paste body
#
# MULTIBOOT FOR MOX 
#
# by maw
#define ASM
#include <mox/multiboot.h>
.text

.global start, _start
.extern cmain

start:
_start:
	jmp multiboot_entry
.align 4
multiboot_header:
     .long MULTIBOOT_HEADER_MAGIC
	.long MULTIBOOT_HEADER_FLAGS
	.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
#ifndef __ELF__
	.long   multiboot_header
	.long   _start
	.long   _edata
	.long   _end
	.long   multiboot_entry
#endif		
#
# Remove the old GDT, since grub dont give us one
# Setup the new GDT and load it
# Load the IDT, since GRUB doesnt give us any
# Make CS Use the new GDT
# Jump over to the C kernel
# If the C kernel ever returns, then just loop forever,
#	or maybe make a panic or something
#

multiboot_entry:
	#remove the old
	xor	%edi,%edi
	movl	$0x800+0x800,%ecx
	repz stos %al,%es:(%edi)
	
	
	#Setup the new
	movl	gdt,%esi
	movl	$0x0800,%edi
	movl	$0x20,%ecx
	repz movsb %ds:(%esi),%es:(%edi)
	
	#load both the GDT and the IDT
	lgdt	gdt_pointer
	lidt	idt_pointer
	
	#Setup the sergs
	mov	$0x8,%dx
	mov	%edx,%ds
	mov	%edx,%es
	mov	%edx,%fs
	mov	%edx,%gs
	mov	$0x18,%dx
	mov	%edx,%ss


	#we are going to give the C kernel this shi
	movl	$0x1000,%esp

	pushl	%ebx
	pushl	%eax

	#Use the new GDT
	#ajmp	$(0x10),$1f
	ljmp   $0x10,$1f
1:
	#jump to the C kernel
	call	cmain
	
	#loop forever
	1:jmp	1b
 .comm   stack, STACK_SIZE

.data
idt_pointer:
	.word	0x800
	.long	0x00000000
gdt_pointer:
	.word	0x800
	.long	0x00000800 #start where the IDT left

gdt:
	.long	0x00000000
	.long	0x00000000

	.long	0x0000ffff
	.long 	0x00cf9200

	.long	0x0000ffff
	.long	0x00cf9A00

	.long	0x0000ffff
	.long	0x00cb9200