setting up paging, physical address not available error

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
garob
Posts: 16
Joined: Wed Dec 30, 2009 3:26 am
Location: Melbourne, Australia

setting up paging, physical address not available error

Post by garob »

Hi, I'm setting up paging in my assembly bootstrap file but when I enable paging the bochs debugger comes up with a message like "(0).[98692884] ??? (physical address not available)" or "(0).[178217280] ??? (physical address not available)" and then resets. As these are different memory address it seems to be some sort of weird randomness.

Here is a portion of my asm file:

Code: Select all

;setup the PD and PTs
   
   ; as the page tables are allocated in the bss section they default
   ; to zero, I will change the entries that hold the 1st mb + the kernel
   
   xor bx, bx
   
   mov eax, kernel_end       ; eax now holds the size
   sub eax, VIRTUAL_OFFSET   ; of the kernel + 1st mb in memory
   shr eax, 12
   inc eax                      ; eax now holds the number of pages needed to store memory from 0 to the end of the kernel
   mov ecx, eax                 ; ecx now holds the number of pages needed to store memory from 0 to the end of the kernel
   mov ebx, _kernel_page_tables - VIRTUAL_OFFSET        ; move the address of the start of the page tables to ebx
   
   ; eax = page table entry to save at address
   ; ebx = page tables pointer(incrementing)
   ; ecx = number of pages(constant)
   ; edx = 
   ; in each loop 4096 will be added to eax
   
   ; initialise eax with pte for to map first address
   mov eax, 3   ; read/write and present
   
   ; loop through adding 4096 to each succesive page table entry, this
   ; works because all the page tables have been preallocated
   .l1:
      mov dword [ebx], eax
      add ebx, 4
      add eax, 4096
   loop .l1
   
   ; set the first few pde's to point to the kernel page table 1 and 2
   mov dword [_kernel_pd - VIRTUAL_OFFSET], _kernel_page_tables - VIRTUAL_OFFSET
   mov dword [_kernel_pd - VIRTUAL_OFFSET + 4], _kernel_page_tables - VIRTUAL_OFFSET + 4096
   
   
   ; enable paging
   mov eax, (_kernel_pd - VIRTUAL_OFFSET)
   mov cr3, eax
   
   mov ecx, cr0
   or ecx, 0x80000000
   mov cr0, ecx
   
   ;halt for debugging
   xchg bx, bx
   hlt
 
section .bss
align 4
stack:
   resb STACKSIZE                       ; reserve 16k stack on a doubleword boundary

align 0x1000
_kernel_pd:
   resb 0x1000
_kernel_page_tables:    ; I am creating 256 page tables here
   resb 0x100000   

Here is the complete debugger output for three runs:

Code: Select all

bx_dbg_read_linear: physical memory read error (phy=0x0000000100000000, lin=0x0000000100000000)
(0) Magic breakpoint
(0) Magic breakpoint
(0).[98692884] ??? (physical address not available)
(0).[98692884] ??? (physical address not available)
bx_dbg_read_linear: physical memory read error (phy=0x0000000100000000, lin=0x0000000100000000)
(0) Magic breakpoint
(0) Magic breakpoint
(0).[178217280] ??? (physical address not available)
(0).[178217280] ??? (physical address not available)
bx_dbg_read_linear: physical memory read error (phy=0x0000000100000000, lin=0x0000000100000000)
(0) Magic breakpoint
(0) Magic breakpoint
(0).[315778885] ??? (physical address not available)
bx_dbg_read_linear: physical memory read error (phy=0x0000000100000000, lin=0x0000000100000000)
Can someone give me some pointers as to why it does this please?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: setting up paging, physical address not available error

Post by gerryg400 »

Code: Select all

bx_dbg_read_linear: physical memory read error (phy=0x0000000100000000, lin=0x0000000100000000)
That physical address at the 4GB mark.
If a trainstation is where trains stop, what is a workstation ?
garob
Posts: 16
Joined: Wed Dec 30, 2009 3:26 am
Location: Melbourne, Australia

Re: setting up paging, physical address not available error

Post by garob »

Yeah but I don't think that is the problem as the debugger outputs that before bochs loads GRUB.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: setting up paging, physical address not available error

Post by Combuster »

virtual_offset undefined. No P/W/U bits set in the PD. Did you bother to check the output of "info tab"?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
garob
Posts: 16
Joined: Wed Dec 30, 2009 3:26 am
Location: Melbourne, Australia

Re: setting up paging, physical address not available error

Post by garob »

Thanks for the heads up Combuster, I fixed that up, but I didn't run properly. I discovered that though I had

Code: Select all

align 0x1000
my page directory and tables weren't page aligned. My linker script used to look like this

Code: Select all

ENTRY(loader)
OUTPUT_FORMAT(elf32-i386)
KERNEL_VMA = 0xC0100000;
KERNEL_LMA = 0x00100000;

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

   .text ALIGN (0x1000) : AT(ADDR(.text) - KERNEL_VMA + KERNEL_LMA) {
       *(.text)
       *(.rodata*)
   }

   .data ALIGN (0x1000) : AT(ADDR(.data) - KERNEL_VMA + KERNEL_LMA) {
       *(.data)
   }

   .bss ALIGN (0x1000) : AT(ADDR(.bss) - KERNEL_VMA + KERNEL_LMA) {
       _sbss = .;
      *(COMMON)
      *(.bss)
       _ebss = .;
   }
   kernel_end = .;
}
but after switching *(COMMON) and *(.bss) they lined up properly, *(COMMON) seemed to be taking up 16 bytes which made *(.bss) be not page aligned.

Oh sorry VIRTUAL_OFFSET is 0xC0000000
ecco
Posts: 19
Joined: Mon Nov 29, 2010 1:21 am
Location: Anchorage, AK

Re: setting up paging, physical address not available error

Post by ecco »

I ended up doing something like this to keep myself from reintroducing the problem

Code: Select all

section .kpd
align 0x1000
_kernel_pd:
   resb 0x1000
_kernel_page_tables:    ; I am creating 256 page tables here
   resb 0x100000   

Code: Select all

   .bss ALIGN (0x1000) : AT(ADDR(.bss) - KERNEL_VMA + KERNEL_LMA) {
       _sbss = .;
      *(kpd)
      *(COMMON)
      *(.bss)
       _ebss = .;
   }
Post Reply