flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > Paging woes. |
Author |
|
cod3b453 17 Aug 2013, 08:56
Sorry in my original post I didn't spot you swapped directions.
To map VA 0x0000000 to PA 0x0000A000 you'd need: Code: ; At 0x00001000 PageDirectory dd 0x00000003 ; PageTable0 at 0x00000000 ; At 0x00000000 PageTable0 PageEntry0 dd 0x0000A003 Note that your IDT is going to conflict with the PageTable0 at 0x00000000, so I'd move one of these somewhere else. |
|||
17 Aug 2013, 08:56 |
|
egos 17 Aug 2013, 10:57
I recommend to use recursive page dir mapping. I would write a tutorial but I have some problems with English.
Last edited by egos on 29 Aug 2013, 14:12; edited 1 time in total |
|||
17 Aug 2013, 10:57 |
|
Coty 17 Aug 2013, 17:49
@cod3b453: Thanks! As soon as I read your post everything fell into place! Only took me a few mins to get it working
@egos: What I think would be cool; would be to actually make tutorials in your native language. There are many nice tutorials in English as it is, granted some need some clarification... but it would be nice to see more things in more languages |
|||
17 Aug 2013, 17:49 |
|
Coty 28 Aug 2013, 18:05
Just for fun... Seems to work anyway
Code: use16 org 0x7C00 format binary as "img" ;=============================================================================; ; Clear screen of all prior crap... ; ;=============================================================================; push dx push 0xb800 pop es xor di, di mov ax, 0 mov cx, 80*25 rep stosw ;=============================================================================; ; Set up P-Mode... ; ;=============================================================================; cli lgdt [gdtr] mov eax, cr0 inc eax mov cr0, eax jmp 0x8:_PM ;-----------------------------------------------------------------------------; gdtr: dw GDT_end - GDT_start - 1 ; GDT size - 1 So that should be 23. dd GDT_start ; Were the GDT starts. GDT_start: dq 0x0000000000000000 ; Null descriptor. dw 0x03FF ; 4MB limmit 1023 (1024-1)*4096 = 4MB) dw 0x0000 ; Base adress = 0x0000 dw 0x9A00 ; code read/exec dw 0x00C0 ; granularity dw 0x03FF ; 4MB limmit 1023 ((1024-1)*4096=2MB) dw 0x0000 ; Base adress = 0x0000 dw 0x9200 ; code read/exec dw 0x00C0 ; granularity GDT_end: ;-----------------------------------------------------------------------------; use32 _PM: mov ax, 0x0010 ; Move the data segment into AX then mov ss, ax ; into SS, DS, ES, GS, and FS. mov ds, ax mov es, ax mov gs, ax mov fs, ax ;-----------------------------------------------------------------------------; ; Install our basic paging... ; This will map 4MB of "virtual" RAM corisponding to physical RAM. ; ; page_directory = 0x0000_9000 ; first_page_table = 0x0000_A000 ;-----------------------------------------------------------------------------; mov edi, 0x0009000 ; Paging starts at 0x9000 (at the PML4) mov cr3, edi ; place the location of PML4 into Cr3 push edi ; [!] put 0x00009000 on the stack. [!] ;''''''''''''''''''''''''''''''; ; Create the page directories. ; ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,; mov eax, 0x00000002 ; NOT present mov ecx, 1024 ; 1024 entries... This will point to our ; page table(s) push cx ; {!} put 1024 onto the stack. {!} rep stosd ; Clear all 1024 entries ;''''''''''''''''''''''''''''''; ; Create 1 page table, for 4MB ; ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,; pop cx ; {!} Get 1024 from the stack. {!} mov di, 0xA000 .loop: or al, 3 ; <<< eax stosd add eax, 4096 loop .loop ;''''''''''''''''''''''''''''''; ; Point page DIR to page table ; ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,; pop edi ; [!] Get 0x00009000 from the stack [!] mov eax, 0x0000A003 ; At location 0x0000_6000, ; Read/write bit = ture; ; Present bit = true; stosd mov eax, cr0 or eax, 0x80000000 ; Enable paging bit. mov cr0, eax ;-----------------------------------------------------------------------------; ; Put out dummy "spinner" app at 0x0000_1000 ;-----------------------------------------------------------------------------; mov edi, 0x00001000 mov esi, dummyApp mov ecx, 14 ; Copy 14 bytes. rep movsb ; do it ;-----------------------------------------------------------------------------; ; Re-map 0x0000 to 0x1000, just for giggles... ;-----------------------------------------------------------------------------; mov eax, [0xA000] ; Get 0x0000_0000 entry xchg eax, [0xA004] ; swap it with 0x0000_1000 mov [0xA000], eax ; put 0x0000_1000 into 0x0000_0000 entry ; thus fully swaping the entries... ;-----------------------------------------------------------------------------; ; Now goto 0x0000_0000 virtual, whitch is actually 0x0000_1000 physical! ;-----------------------------------------------------------------------------; jmp 0x00000000 ;=============================================================================; ; Data area. ; ;=============================================================================; dummyApp: file "spinner.bin" times 510 - ($-$$) db 0x00 dw 0xAA55 times 1024*8 - ($-$$) db 0x00 Code: use32 org 0x00000000 mov edi, 0xB8000 mov eax, ": ) " stosd jmp $ |
|||
28 Aug 2013, 18:05 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.