pxe load OS, then enter long mode?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
zbear
Posts: 2
Joined: Wed May 06, 2009 2:49 pm

pxe load OS, then enter long mode?

Post by zbear »

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.

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
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: pxe load OS, then enter long mode?

Post by pcmattman »

Does the floppy image work without booting it via PXE?
zbear
Posts: 2
Joined: Wed May 06, 2009 2:49 pm

Re: pxe load OS, then enter long mode?

Post by zbear »

my xeon box doesn't have a physical floppy drive.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: pxe load OS, then enter long mode?

Post by xenos »

Different question: Can you boot something else (i.e. a x86_64 simulator like Bochs (with x86_64 support compiled in), QEMU, AMD SimNow!, or a different machine) with your floppy image, without PXE?
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Post Reply