Page 1 of 1

paging *aaarrrgggg*

Posted: Thu Jan 29, 2004 8:45 am
by guest
hi, i have a big problem. I CAN'T ENABLE PAGING!!!
My bootloader loads the kernel to the address 0x100,
after enable protection it jumps to it (address 0x1000).
in the start asm code it try to enable paging but bochs mean that there is a triple fault 14 (page fault). before this i had load my kernel at 0x300 and jumped to 0x3000 then bochs said oh triple fault 13. i think i map all 1:1 if it isn't say it, and say how to map addresses.

My enable_paging function:

Code: Select all

enable_paging:
   cli
   page_dir equ 0x9C000
   page_table equ 0x9D000
   
   xor eax, eax
   xor ebx, ebx
   mov ecx, 1024
loop1:
   or eax, 3
   mov [page_table + ebx], eax
   xor eax, 3
   add ebx, 32
   add eax, 4096
   loop loop1

   mov eax, page_table
   or eax, 3
   mov[page_dir + 0x00], eax

   xor eax, eax
   or eax, 2
   mov ebx, 32

   mov ecx, 1023
loop2:
   mov [page_dir + ebx], eax
   add ebx, 32
   loop loop2

   mov eax, page_dir
   mov cr3, eax

   mov eax, cr0
   or eax, 0x80000000
   mov cr0, eax            ; after this the cpu crashes

   ret
thats my linker script:

Code: Select all

/* Link.ld */
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
.text 0x100000 :
{
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}

.data :
{
__CTOR_LIST__ = .; LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) *(.ctors) LONG(0) __CTOR_END__ = .; 
__DTOR_LIST__ = .; LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2) *(.dtors) LONG(0) __DTOR_END__ = .; 

data = .; _data = .; __data = .;
*(.data)
. = ALIGN(4096);
}

.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}

end = .; _end = .; __end = .;
} 

Re:paging *aaarrrgggg*

Posted: Thu Jan 29, 2004 9:26 am
by Phil
I only looked at your paging code. I hate looking at linker stuff.

Assuming: your code loads where you want it and runs without setting up paging.

I see these bugs in your code:
1) In loop1 and loop2, "add ebx, 32" should be "add ebx,4" since each entry in the both tables are 4 bytes, not 32 bytes.

2) Just before loop2 you have "mov ebx,32" which should be "mov ebx,4" for the same reason.

Not a bug, but the line "xor eax, 3" in loop1 is not needed, and if you remove that line then the line "or eax,3" in loop1 could be move to just before loop1 and only executed once.


That is all I see.
Phil

Re:paging *aaarrrgggg*

Posted: Thu Jan 29, 2004 9:51 am
by frank
. i think i map all 1:1 if it isn't say it, and say how to map addresses.
With 1:1 mapping the physical address correspondends with the linear address.
So 0x1000 = 0x1000 after paging enabled.
If you don't use 1:1 Mapping the kernel could be not found or moved to 0x2000.. (that is, non-designed)

See the 1-last topic: http://www.mega-tokyo.com/forum/index.p ... eadid=5345

loop2:
mov [page_dir + ebx], eax
add ebx, 32
loop loop2
Seems like your code doesn't do that.

Re:paging *aaarrrgggg*

Posted: Thu Jan 29, 2004 1:37 pm
by Pype.Clicker
why adding 32 to ebx ?? 4 sounds far enough to me ...

Re:paging *aaarrrgggg*

Posted: Fri Jan 30, 2004 9:17 am
by guest
OK I changed a few things and it works:

Code: Select all

enable_paging:
   cli
   page_dir equ 0x9C000
   page_table equ 0x9D000
   
   xor eax, eax
   xor ebx, ebx
   mov ecx, 1024
   or eax, 3         ; change
loop1:               ; creates the page table entries
   mov [page_table + ebx], eax
   add ebx, 4         ; change
   add eax, 4096
   loop loop1

   mov eax, page_table
   or eax, 3         ; change the main error
   mov[page_dir + 0x00], eax   ; first page dir entry = first page table entry | 3

   xor eax, eax
   or eax, 2         ; change the main error too
   mov ebx, 4         ; change

   mov ecx, 1023
loop2:
   mov [page_dir + ebx], eax
   add ebx, 4
   loop loop2

   mov eax, page_dir
   mov cr3, eax

   mov eax, cr0
   or eax, 0x80000000
   mov cr0, eax

   ret
but I have another problem:

My kernel starts but when I try to use a this function the Kernel prints on the screen:

Code: Select all

void putstr(char* str)
{
    while(*str)
      putc(*str++);
}

use for example:

putstr("LALA");
the function putc works. str is != 0 but *str is == 0 why???

Re:paging *aaarrrgggg*

Posted: Sun Feb 01, 2004 2:57 pm
by Pype.Clicker
Was the same function working before you entered paging ? Are you sure the pointer you had to video memory is still valid ?

Re:paging *aaarrrgggg*

Posted: Mon Feb 02, 2004 8:35 am
by guest
Was the same function working before you entered paging ?
NO.
Are you sure the pointer you had to video memory is still valid ?
Yes

Re:paging *aaarrrgggg*

Posted: Mon Feb 02, 2004 3:05 pm
by Pype.Clicker
then i would say that the problem is either in your putstr function or, more likely, in the way you build your executable. strings tend to go either in the .text section (in which case you have nothing special to do) or in one of the .rodata* sections. Just check the string you'd like to output is present in your binary file ...

Re:paging *aaarrrgggg*

Posted: Tue Feb 03, 2004 8:37 am
by guest