Page 1 of 1

why it give error message " physical memory read error "

Posted: Sun Sep 14, 2014 9:25 pm
by hitlar
give error message when run this program
--------------------------------------------------------

Code: Select all

(0) [0x000000000010000c] 0008:0010000c (unk. ctxt): cmp eax, 0x2badb002       ; 3d02b0ad2b
<bochs:8> s
Next at t=77386328
(0) [0x0000000000100011] 0008:00100011 (unk. ctxt): jnz .+66 (0x00100055)     ; 7542
<bochs:9> 
Next at t=77386329
(0) [0x0000000000100013] 0008:00100013 (unk. ctxt): mov ecx, 0x00101000       ; b900101000
<bochs:10> 
Next at t=77386330
(0) [0x0000000000100018] 0008:00100018 (unk. ctxt): mov cr3, ecx              ; 0f22d9
<bochs:11> 
Next at t=77386331
(0) [0x000000000010001b] 0008:0010001b (unk. ctxt): mov ecx, cr4              ; 0f20e1
<bochs:12> 
Next at t=77386332
(0) [0x000000000010001e] 0008:0010001e (unk. ctxt): or ecx, 0x00000010        ; 83c910
<bochs:13> 
Next at t=77386333
(0) [0x0000000000100021] 0008:00100021 (unk. ctxt): mov cr4, ecx              ; 0f22e1
<bochs:14> 
Next at t=77386334
(0) [0x0000000000100024] 0008:00100024 (unk. ctxt): mov ecx, cr0              ; 0f20c1
<bochs:15> 
Next at t=77386335
(0) [0x0000000000100027] 0008:00100027 (unk. ctxt): or ecx, 0x80000000        ; 81c900000080
<bochs:16> 
Next at t=77386336
(0) [0x000000000010002d] 0008:0010002d (unk. ctxt): mov cr0, ecx              ; 0f22c1
<bochs:17> 
Next at t=77386337
bx_dbg_read_linear: physical memory read error (phy=0x0000008100100030, lin=0x00100030)

Code: Select all

boot.asm
-----------------
global _loader                          ; Make entry point visible to linker.
extern _main                            ; _main is defined elsewhere
extern _ebss
global kernel_pageTable
global identity_PageTable

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

KERNEL_VIRTUAL_BASE equ 0xC0000000                  ; 3GB
KERNEL_PAGE_NUMBER equ (KERNEL_VIRTUAL_BASE >> 22)  ; Page directory index of kernel's 4MB PTE.
IPT equ identity_PageTable - KERNEL_VIRTUAL_BASE

section .text
align 4
MultiBootHeader:
    dd MAGIC
    dd FLAGS
    dd CHECKSUM

; reserve initial kernel stack space -- that's 16k.
STACKSIZE equ 0x4000

; setting up entry point for linker
loader equ (_loader - 0xC0000000)
global _loader

_loader:
     mov ecx, (BootPageDirectory - KERNEL_VIRTUAL_BASE)
    mov cr3, ecx                                        ; Load Page Directory Base Register.

    mov ecx, cr4
    or ecx, 0x00000010                          ; Set PSE bit in CR4 to enable 4MB pages.
    mov cr4, ecx

    mov ecx, cr0
    or ecx, 0x80000000                          ; Set PG bit in CR0 to enable paging.
    mov cr0, ecx

    lea ecx, [StartInHigherHalf]
    jmp ecx                                                     ; NOTE: Must be absolute jump!

StartInHigherHalf:
     mov dword [BootPageDirectory], 0
    invlpg [0]


    mov esp, stack+STACKSIZE           ; set up the stack
    push eax                           ; pass Multiboot magic number
    push ebx

loop:
    hlt                          ; halt machine should kernel return
	jmp loop

section .data
align 0x1000
BootPageDirectory:
    dd IPT+0x83
    times (KERNEL_PAGE_NUMBER - 1) dd 0                 ; Pages before kernel space.
    ; This page directory entry defines a 4MB page containing the kernel.
    dd 0x00000083
    times (1024 - KERNEL_PAGE_NUMBER - 1) dd 0  ; Pages after the kernel image.

    align 4096
identity_PageTable:
	%assign i 0
	%rep 1024
	dd	i*0x1000+0x83
	%assign i i+1
	%endrep


section .bss
align 32
stack:
    resb STACKSIZE      ; reserve 16k stack on a quadword boundary

kernel.ld
------------------

ENTRY(_loader)
OUTPUT_FORMAT(elf32-i386)

SECTIONS {
   /* The kernel will live at 3GB + 1MB in the virtual
      address space, which will be mapped to 1MB in the
      physical address space. */
   . = 0xC0100000;

   .text : AT(ADDR(.text) - 0xC0000000) {
       *(.text)
       *(.rodata*)
   }

   .data ALIGN (0x1000) : AT(ADDR(.data) - 0xC0000000) {
       *(.data)
   }

   .bss : AT(ADDR(.bss) - 0xC0000000) {
       _sbss = .;
       *(COMMON)
       *(.bss)
       _ebss = .;
   }
}
compilation
---------------------------
nasm -g -felf boot.asm
boot.asm:109: warning: dword data exceeds bounds
ld -Tkernel.ld -o kernel boot.o kernel.o


mod edit: added code tags

Re: why it give error message " physical memory read error

Posted: Sun Sep 14, 2014 10:40 pm
by thepowersgang
First off - Forum rules, read them and understand them
1. Code tags
2. Descriptive title (it would have been nice if you had said 'Why does the bochs debugger print "physical read error"')

With that said, onwards to answering:

It's complaining because your page tables have mapped the current address to an invalid location (are you using PAE or IA-32e [long mode]), check your page tables are correctly formatted.

Re: why it give error message " physical memory read error

Posted: Sun Sep 14, 2014 10:48 pm
by KemyLand
Hi! Welcome to OsDev.org :P
Please use a cleaner syntax when posting code. You're copy-pasting ALL your code, without the {code}{/code} syntax (replace the { with [, } with ]). That makes it quite hard to read, and you SHOULDN'T paste all that code like this. You must have already done some debugging and (by thus) only post the relevant code. Also, you are showing ALL of Bochs debug output, and leaving us find the error line. Also, it'll be nice (necessary I would say) if you tell us you're using or not PAE, x86_64, and resume your paging setup steps, please. Please repair these problems and then repost. I'm sure we'll help you understand, if you help us understand. :wink:

Re: why it give error message " physical memory read error

Posted: Sun Sep 14, 2014 10:49 pm
by KemyLand
Describe us your paging setup. This is an obvious paging issue that Bochs tries to catch (thats why I don't like it). Also, read the rules please. :D

Re: why it give error message " physical memory read error

Posted: Sun Sep 14, 2014 10:54 pm
by KemyLand
Found a similar issue. See this topic.

Re: why it give error message " physical memory read error

Posted: Sun Sep 14, 2014 11:46 pm
by hitlar
i am using grub for boot IA-32 machine, boot.asm is the the first file where grub send the control at line loader, according to code first i want to set page directory with identity page, i feel above error given by setting identity page what's change in identity page address to remove the above error. i gave all the code bcz, understand to all code concept. after the code nothing i am setting.

Re: why it give error message " physical memory read error

Posted: Mon Sep 15, 2014 12:58 am
by Combuster

Code: Select all

0x0000008100100030
That's an address over 4GB. Since you only set the PSE bit (and not the PAE bit), the only possibility is that you hit the PSE36 support. Which basically means you set bits in what would otherwise be reserved areas.

Code: Select all

IPT equ identity_PageTable - KERNEL_VIRTUAL_BASE
(...)
BootPageDirectory:
dd IPT+0x83
identity_PageTable is 4K aligned, but certainly not 4M aligned, kernel_virtual_base is 4M aligned, which means that this line has bits set in the 12-22 region. These were originally reserved, but generate higher addresses on PSE36 enabled machines.

Either way, you have to fix addresses like these.

Re: why it give error message " physical memory read error

Posted: Mon Sep 15, 2014 1:12 am
by max
KemyLand, and you should please not double- or even triple-post, use the EDIT button. ;)