flat assembler
Message board for the users of flat assembler.

Index > OS Construction > can't enable paging :-(

Author
Thread Post new topic Reply to topic
othername



Joined: 08 Apr 2005
Posts: 26
Location: Lithuania
othername 04 May 2005, 20:53
Hi all!
Have a problem. This small kernel booted from Grub. Grub enebles Pmode, and doesn't initiate global and local descriptor tables, so i have to do it by myself. Everything goes fine, till i want to enable paging (after cr0, 31 is set). I think it's a problem in PDE and PTE while iam setting them up. Can help? Thank you.

compile
nasm -f elf kernel.asm
ld -Ttext 0x100000 kernel.o

Code:
bits 32
global _start, _stack, adress, _stack
section .text
_start:
        jmp start
        align 4
;************* multiboot_header for GRUB bootloader*************
multiboot_header:
        dd 0x1BADB002           ; multiboot magic number
        dd 0x00000003           ; flags
        dd - ( 0x1BADB002 + 0x00000003)
        dd multiboot_header
        dd _start
        dd 0x0
        dd 0x0
        dd start
start:
        mov     esp, _stack+1024*16     
        pushl
        popl
        
        mov     dword [GDTR+2], GDT
        lgdt    [GDTR]
        mov     ax,0x10                     ; 10000b -- data_des descriptor
        mov     ds,ax
        mov     es,ax
        mov     [es:0xb8000], word 0x0531     ; write 1
        jmp pm_entry    

GDT:    times 8 db 0                    ; NULL descriptor
                                        
        code_des db 0xff, 0xff, 0x00, 0x00, 0x00, 10011010b, 11001111b, 0x00 
        data_des db 0xff, 0xff, 0x00, 0x00, 0x00, 10010010b, 11001111b, 0x00 
        gdt_size equ $-GDT

GDTR    dw      gdt_size - 1            
        dd      0x0

pm_entry:    
        
        
        mov     [es:0xb8002], word 0x0532                       ; write 2

;********** Enable paging at 1Mb-8192bytes (0xFE000) ***********
;Locations: ****** 1Mb == our program
;******************* 1Mb - 8192 == Page Directory Entry *****************
;******************* 1Mb - 4096 ==Page Table Entry **********************       

        mov     edi,0x000FE000                            ; 1M - 8192
        mov     eax,0x000FF007                           ;  1M - 4096, 7- flags
        mov     ecx,1024
        rep     stosd                                         ; All directory fill with 0x000FF007
                                                                      ; points to first page descr at 0x000FF000
        mov     edi,0x000FF000
        mov     eax,0x00000007
        mov     ecx,1024
L_1:
        stosd
        add     eax,0x00001000
        loop    L_1                                            ; Map 4MB of our memory 
;**************************************************
        mov     [es:0xb8008], word 0x0533


        mov     eax,0x000FE000          ; cr3 == 1Mb-8192 (PDE adress)
        mov     cr3,eax
        
        mov     eax,cr0                   
        or      eax,0x80000000
        mov     cr0,eax                 ; Enable paging  set bit 31 in cr0

        mov     [es:0x000b8008], word 0x0534
here:   jmp     here
_stack:
    

Sorry its not a fasm, forgot to correct code.

_________________
Sorry for my bad English Sad
Post 04 May 2005, 20:53
View user's profile Send private message Reply with quote
thomasantony



Joined: 18 Aug 2004
Posts: 8
Location: Kerala, India
thomasantony 07 May 2005, 04:12
Hi,
You should point CR3 to the start of your page directory and not start of your program

Thomas
Post 07 May 2005, 04:12
View user's profile Send private message Visit poster's website Reply with quote
othername



Joined: 08 Apr 2005
Posts: 26
Location: Lithuania
othername 07 May 2005, 09:20
Page directory entry ---- 0x00FE000
Page table entry --------- 0x00FF000
My program starts ------ 0x0100000

This is what i do:
mov eax,0x000FE000
mov cr3,eax

this points to Page Directory Entry, look at source.

_________________
Sorry for my bad English Sad
Post 07 May 2005, 09:20
View user's profile Send private message Reply with quote
CodeWorld



Joined: 15 Nov 2003
Posts: 69
CodeWorld 07 May 2005, 09:55
You map only part of mem? I think some interrupt handler may not mapped in necessary addresses, and their selectors (ID) after creating new gdt would not be correct too. #PF or #GP. Insert "CLI" and test it.

ps: sorry for my english, too =)

_________________
Image
FASM & RUS OSDEV at WWW.SYSBIN.COM (EN: ww2.sysbin.com)
Post 07 May 2005, 09:55
View user's profile Send private message Visit poster's website Reply with quote
othername



Joined: 08 Apr 2005
Posts: 26
Location: Lithuania
othername 07 May 2005, 11:32
Yes, i map just first 4Mb of mem. I tried with CLI, didn't work.
Now i changed to:
Page directory entry ---- 0x00001000 PDE
Page table entry --------- 0x00002000 PTE
My program starts ------ 0x00100000

and now it works, i think that was a broblem of overwriting my code with page tables,
but iam stil confused why it could be.

_________________
Sorry for my bad English Sad
Post 07 May 2005, 11:32
View user's profile Send private message Reply with quote
CodeWorld



Joined: 15 Nov 2003
Posts: 69
CodeWorld 07 May 2005, 11:52
Quote:
iam stil confused why it could be

Maybe. But where? =) What if 0x00FE000 mem used by some device?

_________________
Image
FASM & RUS OSDEV at WWW.SYSBIN.COM (EN: ww2.sysbin.com)
Post 07 May 2005, 11:52
View user's profile Send private message Visit poster's website Reply with quote
othername



Joined: 08 Apr 2005
Posts: 26
Location: Lithuania
othername 07 May 2005, 17:32
Don't know. I havo no info about how memory looks at boot time, i think it would be easier
to do everything above 1Mb.

_________________
Sorry for my bad English Sad
Post 07 May 2005, 17:32
View user's profile Send private message Reply with quote
CodeWorld



Joined: 15 Nov 2003
Posts: 69
CodeWorld 07 May 2005, 17:43
ACPI and SMI above 1 mb. Because i dont think that it is overwriting. Where? =)

_________________
Image
FASM & RUS OSDEV at WWW.SYSBIN.COM (EN: ww2.sysbin.com)
Post 07 May 2005, 17:43
View user's profile Send private message Visit poster's website Reply with quote
othername



Joined: 08 Apr 2005
Posts: 26
Location: Lithuania
othername 07 May 2005, 18:31
I know anything about ACPI and SMI.
Post 07 May 2005, 18:31
View user's profile Send private message Reply with quote
CodeWorld



Joined: 15 Nov 2003
Posts: 69
CodeWorld 07 May 2005, 18:35
ok. i mean trouble is not in hardware. but where then? ^)

_________________
Image
FASM & RUS OSDEV at WWW.SYSBIN.COM (EN: ww2.sysbin.com)
Post 07 May 2005, 18:35
View user's profile Send private message Visit poster's website Reply with quote
othername



Joined: 08 Apr 2005
Posts: 26
Location: Lithuania
othername 07 May 2005, 19:04
I don't know.

Iam not sure about the following sentence, but if it's true then it's that "overwriting" :

If i do at link time -Ttext 0x100000, it means that _start is located at this position,
then elf header is propably 0x100000-some_bytes
(am i right?)
Post 07 May 2005, 19:04
View user's profile Send private message Reply with quote
CodeWorld



Joined: 15 Nov 2003
Posts: 69
CodeWorld 07 May 2005, 19:10
I think it is true. Tell me about your os =) What plans do you have?

_________________
Image
FASM & RUS OSDEV at WWW.SYSBIN.COM (EN: ww2.sysbin.com)
Post 07 May 2005, 19:10
View user's profile Send private message Visit poster's website Reply with quote
othername



Joined: 08 Apr 2005
Posts: 26
Location: Lithuania
othername 07 May 2005, 21:29
I started to write just for experimenting PM, and wanted to know more about how kernel works. I think i would not go far with this my "OS". I am to lazy to read much, and i have lack of knowledge, i can tell that i haven't write'n any serious program. I think i'll try to write just MINIMAL kernel, and iam not convinced that i'll succeed.









S prazdnikom, Rusak!! Wink

_________________
Sorry for my bad English Sad
Post 07 May 2005, 21:29
View user's profile Send private message Reply with quote
CodeWorld



Joined: 15 Nov 2003
Posts: 69
CodeWorld 08 May 2005, 04:32
Quote:
I think i'll try to write just MINIMAL kernel, and iam not convinced that i'll succeed.

Clear, you whant microkernel? What will be in it? Mem manager, process manager, ipc... and?

Quote:
S prazdnikom, Rusak!!

Thanks!

ps: do yous speak russian? =)

_________________
Image
FASM & RUS OSDEV at WWW.SYSBIN.COM (EN: ww2.sysbin.com)
Post 08 May 2005, 04:32
View user's profile Send private message Visit poster's website Reply with quote
Mota



Joined: 29 Dec 2004
Posts: 22
Mota 08 May 2005, 08:03
0xF0000 to 0x0xFFFFF is used by the BIOS, so it is an overwriting error.
About the elf header, maybe grub only loads the text, data, and sets the bss segment, but doesn't load the whole file together. I dunno cos I dont use GRUB, i just make my own bootsectors to avoid any complication.
Post 08 May 2005, 08:03
View user's profile Send private message Reply with quote
othername



Joined: 08 Apr 2005
Posts: 26
Location: Lithuania
othername 08 May 2005, 11:28
Mota: havo more info about what memory uses BIOS?

CodeWorld: Now iam thinking to read about memory management, what will be more, don't know, i didn't think much about that. I don't think that i will write my own working kernel or OS. But everything could be.








Yes: i speak russian, lithuanian, english.

_________________
Sorry for my bad English Sad
Post 08 May 2005, 11:28
View user's profile Send private message Reply with quote
CodeWorld



Joined: 15 Nov 2003
Posts: 69
CodeWorld 10 May 2005, 09:34
Ты получил письмо? А то я те намылил и чё то ответа нет =(

_________________
Image
FASM & RUS OSDEV at WWW.SYSBIN.COM (EN: ww2.sysbin.com)
Post 10 May 2005, 09:34
View user's profile Send private message Visit poster's website Reply with quote
othername



Joined: 08 Apr 2005
Posts: 26
Location: Lithuania
othername 10 May 2005, 10:28
уже есть

_________________
Sorry for my bad English Sad
Post 10 May 2005, 10:28
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.