pxe load OS, then enter long mode?
Posted: Thu May 07, 2009 1:21 am
Hi All,
I'd like to pxe boot my OS. I'm using PXELinux with memdisk feature. The memdisk is a floppy image, with grub to load my kernel. My kernel goes from protected 32bit mode [where grub left off] and attempts to enter long 64bit mode. However, I'm encountering machine reset when I enable paging in cr0.
I'm testing on a Intel x86_64 xeon box.
so, is this network booting scenario possible? In other words, can I pxe download a memdisk, then use the grub embedded in this 'ram disk' to load my kernel and enter long mode? Everything seems ok, until I attempt to enter long mode by enabling paging.
thanks
zbear
here's my code, which is a combination of various tutorials found on these forums.
my OS is built as a flat binary, hence I turned on the kludge.
I'd like to pxe boot my OS. I'm using PXELinux with memdisk feature. The memdisk is a floppy image, with grub to load my kernel. My kernel goes from protected 32bit mode [where grub left off] and attempts to enter long 64bit mode. However, I'm encountering machine reset when I enable paging in cr0.
I'm testing on a Intel x86_64 xeon box.
so, is this network booting scenario possible? In other words, can I pxe download a memdisk, then use the grub embedded in this 'ram disk' to load my kernel and enter long mode? Everything seems ok, until I attempt to enter long mode by enabling paging.
thanks
zbear
here's my code, which is a combination of various tutorials found on these forums.
my OS is built as a flat binary, hence I turned on the kludge.
Code: Select all
[BITS 32] ; All instructions should be 32-bit.
MBOOT_PAGE_ALIGN equ 1<<0 ; Load kernel and modules on a page boundary
MBOOT_MEM_INFO equ 1<<1 ; Provide your kernel with memory info
MBOOT_HEADER_MAGIC equ 0x1BADB002 ; Multiboot Magic value
MBOOT_AOUT_KLUDGE equ 1 << 16
MBOOT_HEADER_FLAGS equ MBOOT_PAGE_ALIGN | MBOOT_MEM_INFO |MBOOT_AOUT_KLUDGE
MBOOT_CHECKSUM equ -(MBOOT_HEADER_MAGIC + MBOOT_HEADER_FLAGS)
section .text
align 4
[GLOBAL mboot] ; Make 'mboot' accessible from C.
[EXTERN code] ; Start of the '.text' section.
[EXTERN bss] ; Start of the .bss section.
[EXTERN end] ; End of the last loadable section.
mboot:
dd MBOOT_HEADER_MAGIC ; GRUB will search for this value on each
; 4-byte boundary in your kernel file
dd MBOOT_HEADER_FLAGS ; How GRUB should load your file / settings
dd MBOOT_CHECKSUM ; To ensure that the above values are correct
dd mboot ; Location of this descriptor
dd code ; Start of kernel '.text' (code) section.
dd bss ; End of kernel '.data' section.
dd end ; End of kernel.
dd start ; Kernel entry point (initial EIP).
[GLOBAL start] ; Kernel entry point.
[EXTERN main_z] ; This is the entry point of our C code
start:
cli ; disable interrupt
;----------------- build page
;enable PAE, support for long mode paging
mov eax, cr4
bts eax, 5
mov cr4, eax
mov ecx, 2048
mov edx, 0x9C000 ;Flush the memory
.ZeroMemoryLoop:
mov dword [edx], 0
add edx, 4
loop .ZeroMemoryLoop
mov dword [0x9C000], 0x9D003 ;Set 0-4mb page table
mov ecx, 1024 ;1024 entries in a page table
mov edx, 0x9D000 ;Page table address
mov eax, 11b ;Physical Page Address
.GenTable:
mov dword [edx], eax
add edx, 4 ;Increment to next page table entry
add eax, 0x1000 ;Increment to next physical page
loop .GenTable
; load cr3 with pml4
mov eax, 0x9C000
mov cr3, eax
;call do_cr3
mov ecx, 0c0000080h ; EFER MSR num
rdmsr ; read RFER
bts eax, 8 ; set lme =1
bts eax, 0 ; set lme =1
wrmsr ; write RFER
lgdt [gdt.pointer]
;enable paging to activate long mode
mov eax, cr0 ; read cro
bts eax, 31 ; set pe = 1
mov cr0, eax ; write cr0 <------------ machine check here!!!!
mov esp, _sys_stack ; set up the stack
jmp gdt.code:startLongMode
. . . doesn't even reach rest of the code