All pastes #1389996 Raw Edit

Stuff

public text v1 · immutable
#1389996 ·published 2009-04-12 21:22 UTC
rendered paste body
/* real.S - real mode code */

#define ASM	1
#include <mem.h>

        .code16
	.data
gdt:
/* Allocate some bytes here, set them in protected mode code */
        .fill 1024, 8, 0

	.globl gdtdesc, _gdtdesc
gdtdesc:
_gdtdesc:
        .word 0
	.long gdt

idt:
        .fill 256, 8, 0

	.globl idtdesc, _idtdesc
idtdesc:
_idtdesc:
        .word 0
	.long idt

	.globl realidtdesc, _realidtdesc
realidtdesc:
_realidtdesc:
        .word 256
        .long 0

	.text
	.globl	enter_protmode, _enter_protmode
enter_protmode:
_enter_protmode:
	cli
        movl $idtdesc, %eax
	lidt (%eax)
        movl $gdtdesc, %eax
	lgdt (%eax)
        movl %cr0, %eax
	orl  $(CR0_PE),%eax
	movl %eax,%cr0
	movw $(SEG_KERN_UNUSED),%ax
	movw %ax,%gs
	movw %ax,%fs
	movw %ax,%es
        movw $(SEG_KERN_DATA),%ax
	movw %ax,%ds
        ljmpl $(SEG_KERN_CODE),$protmode_entry
     
	.code32
	.extern x86_init, _x86_init
	.globl protmode_entry, _protmode_entry
	.text
protmode_entry:
_protmode_entry:
 #sti
       jmpl x86_init
       nop