Paging and writing text in PMODe

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
sheena9877
Posts: 16
Joined: Wed Jan 02, 2008 10:44 pm
Location: USA

Paging and writing text in PMODe

Post by sheena9877 »

Hello,
I'd cracking my head for couple days now on this code, but heading to nowhere.

First of all, I built my OS loader, here is the part of the paging of this
OS loader.

;OSLoader.asm

Code: Select all

 cli
 push ds
 push es
 ;FIRST CLEAR ALL ENTRIES IN PAGE DIRECTORY BY SETTING THEM TO ZERO
 xor ax, ax
 mov ds, ax
 mov es, ax
 cld
 xor edi, edi
 mov edi, 90000H          ;physical address of PAGE DIR in linear form
 mov ecx, 1024             ;Number of DWORDS to clear
 xor eax, eax                ;Make it 0
 ClearDir:
 mov es:[edi], eax        ;Set it to 0
 add edi, 4                    ;Next DWORD to set
  loop ClearDir              ;Loop until ecx==0
 
;NEXT FILL THE FIRST ENTRY OF PAGE DIRECTORY
;SO FIRST PAGE TABLE IS USE FOR IDENTITY MAPPING
;WE WILL USE AN ADDRESS JUST THE ADJACENT OF PAGE DIRECTORY
;LAST ADDRESS OCCUPIED BY PAGE DIRECTORY IS 90FFFH 
;REMEMBER THAT PAGE DIRECTORY IS 4096 BYTES LONG AND ZERO BASED
;SO THE PHYSICAL ADDRESS OF FIRST PAGE TABLE WILL BE 91000H
 xor eax, eax
 mov eax, 91000h  ;ADDRESS OF THE FIRST PAGE TABLE
 or  eax, 3
 xor edi, edi
 mov edi,90000H
 mov es:[edi], eax 
 
;SECOND PAGE TABLE IS USE FOR OS KERNEL
;MAP VIRTUAL ADDRESS 0C0000000H -> 0C03FFFFFH   (4mb)
TO PHYSICAL ADDRESS 00000000H -> 003FFFFFH (4MB)

 xor eax, eax
 mov eax, 92000h  ;physical base address of 2nd Page Table 
                            ;which is the content of entry in the PAGE DIRECTORY
 or  eax, 3             ;this content needs only 20 bits to the physical address
                            ;of PAGE TABLE, so the lowest 12 bits are set to
                            ;other setting by oring to 3
                  
 xor edi, edi
 ;now we will enter this PAGE TABLE address to entry 300th
 ;of PAGE DIRECTORY
 
 mov edi,90C00H   ;this is the 300th entry in PAGE DIRECTORY
                           ;we got this address by getting the highest ten bits
                           ;of the virtual address we gonna map to                
                           ;physical address                 
                           ;and add this to physical address of PAGE DIRECTORY
  mov dword ptr es:[edi], eax 
 

 
 
  
 
 ;ENTER THE ENTRIES TO FIRST PAGE TABLE
 ;FIRST PAGE TABLE IS FOR IDENTITY MAPPING
 xor edi, edi 
 mov edi, 91000H         ;physical addres of 1st PAGE TABLE
 mov eax, 00000000H   ;content of first entry of this PAGE TABLE
                                  ;which points to physical base address
                                  ;of PAGE FRAME
 or  eax, 3                   ;set this PAGE TABLE as Present, Supervisor, 
                                  ;Writable
 mov ecx, 1024            ;Number of locations left to map
 
LoopCreateTable:
 mov es:[edi], eax        ;Set it to next phys.
 add edi, 4                   ;Next DWORD to set
 add eax, 1000H          ;Next page to map to
 loop LoopCreateTable   ;Loop until ecx==0 (also "dec ecx")
 
 ;SECOND PAGE TABLE FOR  OS KERNEL
 ;SINCE WE WANT TO MAP THE 
 ;PHYSICAL ADDRESS 000000H TO VIRTUAL ADDRESS 0C0000000H
 ;WE WILL ENTER THE ADDRESS 000000H TO THE FIRST ENTRY OF 
 ;THE SECOND PAGE TABLE 
 xor edi, edi
 mov edi, 92000H         ;Location of page table 
 xor eax, eax
 mov eax, 00000000h    ;first 4 mb to 0C0000000h ->0C03FFFFFh
 or  eax, 3
 mov ecx, 1024            ;Amount left to set
 LoopCreateTable2:
 mov es:[edi], eax        ;Set it to next phys.
 add edi, 4                   ;Next DWORD to set
 add eax, 1000H            ;Next page to map into
 loop LoopCreateTable2  ;Loop until ecx==0 (also "dec ecx")
 
 
 pop es
 pop ds
 sti
 		
 xor  edx, edx  
 mov dl, [BOOTD]              ;OS can find bootdrive in DL on entry
   ;****************
      
; SWITCH TO FULL PROTECTED MODE
	
    LIDT FWORD PTR  DS:IDTptr
 	
    LGDT FWORD PTR  DS:GDTptr
   
       
    MOV EAX,CR0
    OR AL,1
    MOV CR0,EAX
    JMP $+2      ; Flush the instruction queue.
    NOP
    NOP
;already in 16-BIT PROTECTED MODE
    MOV BX,10H
    MOV DS,BX
    MOV ES,BX
    MOV FS,BX
    MOV GS,BX
    MOV SS,BX
;********************************************************
   ;enable paging here	
    xor eax, eax
    mov eax, 90000H         ;Get location page directory
    mov cr3, eax               ;Put it in CR3
 
    mov eax, CR0             ;Get CR0
    or eax,  80000000H      ;Or it with 'enable paging' bit
    mov cr0, eax                ;Enable paging!!!!!!!
 	
 	
 	
 	
;we need to jmp to identity table
    jmp  $+2   ; Flush the instruction queue.
    nop
    nop 
    mov eax,  0C0300000H
     mov esp, eax             ;Set stack
;########################################################################
;**** REMOVE IDENTITY MAPPING
;ENTER THE ENTRIES TO PAGE TABLE
 ;FIRST PAGE TABLE IS FOR IDENTITY MAPPING
 	XOR EDI, EDI
 	;physical addres of 1st PAGE TABLE
 	mov edi, 0C0091000h
 	mov eax, 00000000H        ;content of first entry of this PAGE TABLE
                         ;which points to physical base address
                         ;of PAGE FRAME
 	
 	mov ecx, 1024              ;Number of locations left to map
 
LoopCreateTable3:
 	mov es:[edi], eax           ;Set it to next phys.
 	add edi, 4                      ;Next DWORD to set
 	add eax, 1000H              ;Next page to map to
 	loop LoopCreateTable3    ;Loop until ecx==0 (also "dec ecx") 
 

;We jump to Kernel
    DB 66H
    DB 67H
    DB 0EAH             ;for jmp instruction
    DD 0C0010000H  ;starting address of Kernel code in virtual memory
    DW 0008H           ;descriptor

;Here is the kernel loaded by OS loader into 10000h (1meg)
;KERNEL.ASM
.DATA
msg db   'F i n a l l y   i n   p r o t e c t e d   m o d e ! '
.CODE
.VIRTUAL 0C0010000H

.START
;just print the message
lea esi, msg
mov edi, 0C00B8000H + 488
mov ecx,52
cld
rep movsb
cli
hlt
When I run this on real PC and Bosch, they both reset

What am I doing wrong here?
Please help.
Sheena
Last edited by sheena9877 on Wed Feb 20, 2008 12:36 pm, edited 4 times in total.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Hi,

Several things:

(1) Don't title your post in capitals, it looks ugly and gets our backs up.
(2) Please use [ code ] tags around your code so that it appears in a fixed-width font that is easy to read.
(3) Please provide more information on your problem, ideally how you have attempted to debug it, where the problem seems to be occurring, under what circumstances etc. Please don't expect us to sift through a brain dump to work out exactly what line of code is wrong - that is *your* job.

Thanks,

James
sheena9877
Posts: 16
Joined: Wed Jan 02, 2008 10:44 pm
Location: USA

Post by sheena9877 »

James,
Ok I use Bosch, but I don't know to interpret it
here is it

00000000000i[ ] Bochs x86 Emulator 2.3
00000000000i[ ] Build from CVS snapshot on August 27, 2006
00000000000i[ ] System configuration
00000000000i[ ] processors: 1 (cores=1, HT threads=1)
00000000000i[ ] A20 line support: yes
00000000000i[ ] APIC support: yes
00000000000i[ ] CPU configuration
00000000000i[ ] level: 6
00000000000i[ ] paging support: yes, tlb enabled: yes
00000000000i[ ] SMP support: no
00000000000i[ ] FPU support: yes
00000000000i[ ] MMX support: yes
00000000000i[ ] SSE support: 1
00000000000i[ ] v8086 mode support: yes
00000000000i[ ] VME support: yes
00000000000i[ ] 3dnow! support: no
00000000000i[ ] PAE support: yes
00000000000i[ ] PGE support: yes
00000000000i[ ] PSE support: yes
00000000000i[ ] x86-64 support: no
00000000000i[ ] SEP support: yes
00000000000i[ ] Optimization configuration
00000000000i[ ] Guest2HostTLB support: yes
00000000000i[ ] RepeatSpeedups support: yes
00000000000i[ ] Icache support: yes
00000000000i[ ] Host Asm support: yes
00000000000i[ ] Fast function calls: yes
00000000000i[ ] Devices configuration
00000000000i[ ] NE2000 support: yes
00000000000i[ ] PCI support: yes
00000000000i[ ] SB16 support: yes
00000000000i[ ] USB support: yes
00000000000i[ ] VGA extension support: vbe cirrus
00000000000i[MEM0 ] allocated memory at 00C80020. after alignment, vector=00C81000
00000000000i[MEM0 ] 128.00MB
00000000000i[MEM0 ] rom at 0xf0000/65536 ('E:\Bochs-2.3/BIOS-bochs-latest')
00000000000i[MEM0 ] rom at 0xc0000/38400 ('E:\Bochs-2.3/VGABIOS-lgpl-latest')
00000000000i[APIC?] set APIC ID to 0
00000000000i[APIC0] 80686
00000000000i[APIC0] local apic in CPU apicid=00 initializing
00000000000i[IOAP ] initializing I/O APIC
00000000000i[IOAP ] set APIC ID to 1
00000000000i[MEM0 ] Register memory access handlers: fec00000-fec00fff
00000000000i[CMOS ] Using local time for initial clock
00000000000i[CMOS ] Setting initial clock to: Tue Feb 19 13:01:13 2008 (time0=1203444073)
00000000000i[DMA ] channel 4 used by cascade
00000000000i[DMA ] channel 2 used by Floppy Drive
00000000000i[FDD ] fd0: 'a:' ro=0, h=2,t=80,spt=18
00000000000i[PCI ] 440FX Host bridge present at device 0, function 0
00000000000i[PCI ] PIIX3 PCI-to-ISA bridge present at device 1, function 0
00000000000i[MEM0 ] Register memory access handlers: 000a0000-000bffff
00000000000i[WGUI ] Number of Mouse Buttons = 3
00000000000i[WGUI ] IME disabled
00000000000i[MEM0 ] Register memory access handlers: e0000000-e07fffff
00000000000i[CLVGA] VBE Bochs Display Extension Enabled
00000000000i[CLVGA] interval=300000
00000000000i[ ] init_mem of 'harddrv' plugin device by virtual method
00000000000i[ ] init_mem of 'keyboard' plugin device by virtual method
00000000000i[ ] init_mem of 'serial' plugin device by virtual method
00000000000i[ ] init_mem of 'parallel' plugin device by virtual method
00000000000i[ ] init_mem of 'extfpuirq' plugin device by virtual method
00000000000i[ ] init_mem of 'gameport' plugin device by virtual method
00000000000i[ ] init_mem of 'speaker' plugin device by virtual method
00000000000i[ ] init_mem of 'pci_ide' plugin device by virtual method
00000000000i[ ] init_dev of 'harddrv' plugin device by virtual method
00000000000i[HD ] Using boot sequence floppy, none, none
00000000000i[HD ] Floppy boot signature check is enabled
00000000000i[ ] init_dev of 'keyboard' plugin device by virtual method
00000000000i[KBD ] will paste characters every 1000 keyboard ticks
00000000000i[ ] init_dev of 'serial' plugin device by virtual method
00000000000i[SER ] com1 at 0x03f8 irq 4
00000000000i[ ] init_dev of 'parallel' plugin device by virtual method
00000000000i[PAR ] parallel port 1 at 0x0378 irq 7
00000000000i[ ] init_dev of 'extfpuirq' plugin device by virtual method
00000000000i[ ] init_dev of 'gameport' plugin device by virtual method
00000000000i[ ] init_dev of 'speaker' plugin device by virtual method
00000000000i[ ] init_dev of 'pci_ide' plugin device by virtual method
00000000000i[PCI ] PIIX3 PCI IDE controller present at device 1, function 1
00000000000i[ ] register state of 'harddrv' plugin device by virtual method
00000000000i[ ] register state of 'keyboard' plugin device by virtual method
00000000000i[ ] register state of 'serial' plugin device by virtual method
00000000000i[ ] register state of 'parallel' plugin device by virtual method
00000000000i[ ] register state of 'extfpuirq' plugin device by virtual method
00000000000i[ ] register state of 'gameport' plugin device by virtual method
00000000000i[ ] register state of 'speaker' plugin device by virtual method
00000000000i[ ] register state of 'pci_ide' plugin device by virtual method
00000000000i[SYS ] bx_pc_system_c::Reset(HARDWARE) called
00000000000i[APIC0] local apic in CPU 0 initializing
00000000000i[ ] reset of 'harddrv' plugin device by virtual method
00000000000i[ ] reset of 'keyboard' plugin device by virtual method
00000000000i[ ] reset of 'serial' plugin device by virtual method
00000000000i[ ] reset of 'parallel' plugin device by virtual method
00000000000i[ ] reset of 'extfpuirq' plugin device by virtual method
00000000000i[ ] reset of 'gameport' plugin device by virtual method
00000000000i[ ] reset of 'speaker' plugin device by virtual method
00000000000i[ ] reset of 'pci_ide' plugin device by virtual method
00000003740i[BIOS ] $Revision: 1.166 $ $Date: 2006/08/11 17:34:12 $
00000320071i[KBD ] reset-disable command received
00000325683i[PIDE ] new BM-DMA address: 0xc000
00000449902i[VBIOS] VGABios $Id: vgabios.c,v 1.66 2006/07/10 07:47:51 vruppert Exp $

00000449973i[CLVGA] VBE known Display Interface b0c0
00000450005i[CLVGA] VBE known Display Interface b0c4
00000452930i[VBIOS] VBE Bios $Id: vbe.c,v 1.58 2006/08/19 09:39:43 vruppert Exp $
00003000000i[WGUI ] dimension update x=720 y=400 fontheight=16 fontwidth=9 bpp=8
00046562126i[CPU0 ] protected mode
00046562126i[CPU0 ] CS.d_b = 16 bit
00046562126i[CPU0 ] SS.d_b = 32 bit
00046562126i[CPU0 ] | EAX=00400000 EBX=00000010 ECX=00000000 EDX=00000000
00046562126i[CPU0 ] | ESP=c0300000 EBP=00000000 ESI=00090c00 EDI=c0092000
00046562126i[CPU0 ] | IOPL=3 ID vip vif ac vm RF NT of df if tf sf zf af PF cf
00046562126i[CPU0 ] | SEG selector base limit G D
00046562126i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00046562126i[CPU0 ] | CS:1000( 1e00| 0| 0) 00010000 0000ffff 0 0
00046562126i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00046562126i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00046562126i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 000fffff 1 1
00046562126i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00046562126i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00046562126i[CPU0 ] | EIP=000016d6 (000016d6)
00046562126i[CPU0 ] | CR0=0x80000011 CR1=0 CR2=0x00100040
00046562126i[CPU0 ] | CR3=0x00090000 CR4=0x00000000
00046562126i[CPU0 ] >> jmp far 0008:c0010000 : 6667EA000001C00800
00046562126e[CPU0 ] exception(): 3rd (14) exception with no resolution, shutdown status is 00h, resetting
00046562126i[SYS ] bx_pc_system_c::Reset(SOFTWARE) called
00046562126i[APIC0] local apic in CPU 0 initializing
00046565866i[BIOS ] $Revision: 1.166 $ $Date: 2006/08/11 17:34:12 $
00046882539i[KBD ] reset-disable command received
00047012408i[VBIOS]
VGABios $Id: vgabios.c,v 1.66 2006/07/10 07:47:51 vruppert Exp $

00047012479i[CLVGA] VBE known Display Interface b0c0
00047012511i[CLVGA] VBE known Display Interface b0c4
00047015436i[VBIOS] VBE Bios $Id: vbe.c,v 1.58 2006/08/19 09:39:43 vruppert Exp $
00054810000p[WGUI ] >>PANIC<< Window closed, exiting!
00054810000i[SYS ] Last time is 1203444078
00054810000i[CPU0 ] real mode
00054810000i[CPU0 ] CS.d_b = 16 bit
00054810000i[CPU0 ] SS.d_b = 16 bit
00054810000i[CPU0 ] | EAX=00000024 EBX=00000004 ECX=00000200 EDX=00000000
00054810000i[CPU0 ] | ESP=00004fba EBP=00004fba ESI=000003f6 EDI=00000200
00054810000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df IF tf sf ZF af PF cf
00054810000i[CPU0 ] | SEG selector base limit G D
00054810000i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00054810000i[CPU0 ] | CS:f000( 1e00| 0| 0) 000f0000 0000ffff 0 0
00054810000i[CPU0 ] | DS:0060( 0000| 0| 0) 00000600 0000ffff 0 0
00054810000i[CPU0 ] | SS:0060( 0000| 0| 0) 00000600 0000ffff 0 0
00054810000i[CPU0 ] | ES:1000( 0000| 0| 0) 00010000 0000ffff 0 0
00054810000i[CPU0 ] | FS:0000( 0000| 0| 0) 00000000 0000ffff 0 0
00054810000i[CPU0 ] | GS:0000( 0000| 0| 0) 00000000 0000ffff 0 0
00054810000i[CPU0 ] | EIP=000005a5 (000005a5)
00054810000i[CPU0 ] | CR0=0x00000010 CR1=0 CR2=0x00000000
00054810000i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00054810000i[CPU0 ] >> pop bp : 5D
00054810000i[ ] restoring default signal behavior
00054810000i[CTRL ] quit_sim called with exit code 1

Thank you.
Last edited by sheena9877 on Tue Feb 19, 2008 1:58 pm, edited 1 time in total.
sheena9877
Posts: 16
Joined: Wed Jan 02, 2008 10:44 pm
Location: USA

Post by sheena9877 »

Hello,
BTW, my OSLoader and Kernel works when I remove the paging code in the OSLoader.

Here is the kernel code when no paging.

Code: Select all

	lea esi, msg                 ; -> "Finally in protected mode
 	mov     edi,0B8000h +488 ; (80 * 3 + 4) * 2  ; row 3, column 4
	mov ecx,52
	cld
	rep movsb
                cli
                hlt

Thanks,
Sheena
Last edited by sheena9877 on Tue Feb 19, 2008 1:52 pm, edited 1 time in total.
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:

Post by Combuster »

You're in limbo between real and protected mode when you enable paging, and you crash when you try to reload CS. Given the paging mess that you do, you should check that the GDT is still valid by the time you reach the jump into kernel space.

edit: The crash is caused by a page fault
edit2: as said before, use tags
"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 ]
User avatar
Jef
Member
Member
Posts: 112
Joined: Tue Jan 08, 2008 7:25 am
Location: Greece
Contact:

Post by Jef »

Go step-by-step.
Make a simple paging. Make one page directory and make all table entries present and read/write.
Also put at all entries to be identical virtual = physical address.

All processes (kernel, drivers, etc) will have one page table, and everyone can see and write to all memory.

If this works, change/recode your memory manager to change the "present" and "write" bits only at pages that allocated.

Don't forget pages that belong to VGA (Of Screen Memory, Line Frame Buffer), OS stack, Memory Manager itself (bit maps), BIOS areas, and other standards that are not allocated by the Memory Manager.
Keep coding...
...the sky is the limit

AsteriOS project: http://www.mindfields.gr/main/index.php ... &Itemid=27
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Post by jal »

sheena9877 wrote:Ok I use Bosch
Bosch is a machine and tool factorer, the emulator is called Bochs (as in 'box').


JAL
sheena9877
Posts: 16
Joined: Wed Jan 02, 2008 10:44 pm
Location: USA

Post by sheena9877 »

already solved the problem by yours truly. yeaaaahaaa
BY THE TIME YOU FINISH YOUR OS, OS IS ALREADY OBSOLETE
User avatar
codemastersnake
Member
Member
Posts: 148
Joined: Sun Nov 07, 2004 12:00 am
Contact:

Post by codemastersnake »

I think sheena is a gurl
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

...which doesn't matter really, but it's good manners to tell how you fixed it, so others who find this thread via Google or forum search might benefit from your findings.
Every good solution is obvious once you've found it.
User avatar
codemastersnake
Member
Member
Posts: 148
Joined: Sun Nov 07, 2004 12:00 am
Contact:

Post by codemastersnake »

Ok I politely Apologize! But I was really excited to see a gurl in OS Development. There are really very few of them.
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:

Post by Combuster »

OT: We have this on the wall in the printer room (translated)::cry:
We regret that this year that there were no enrolments from women in computer science. Hence this poster is pink.
- The CS Department
p.s. 'girl' is written with an i
"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 ]
User avatar
codemastersnake
Member
Member
Posts: 148
Joined: Sun Nov 07, 2004 12:00 am
Contact:

Post by codemastersnake »

I know it's written with an 'i' in it i.e. 'Girl'. But I like to write it as Gurl :D
sheena9877
Posts: 16
Joined: Wed Jan 02, 2008 10:44 pm
Location: USA

Post by sheena9877 »

Hi,
Yes, I am a female.

I solved the problem by relocating this code

Code: Select all

;already in 16-BIT PROTECTED MODE
    MOV BX,10H
    MOV DS,BX
    MOV ES,BX
    MOV FS,BX
    MOV GS,BX
    MOV SS,BX 
 
after this code

Code: Select all

;**** REMOVE IDENTITY MAPPING

 ;FIRST PAGE TABLE IS FOR IDENTITY MAPPING
    XOR EDI, EDI
    ;physical addres of 1st PAGE TABLE
    mov edi, 0C0091000h       ;virtual address of Page Table for Identity mapping
    mov eax, 00000000H        ;zero them
    
    mov ecx, 1024              ;Number of locations left to map
 
LoopCreateTable3:
    mov es:[edi], eax           ;Set it to next phys.
    add edi, 4                      ;Next DWORD to set
    add eax, 1000H              ;Next page to map to
    loop LoopCreateTable3    ;Loop until ecx==0 (also "dec ecx") 

I detected that this line caused the triple fault if I did not relocate the above code

Code: Select all

  mov es:[edi], eax           ;Set it to next phys.


Now my paging is working. The first 4mb of physical memory is mapped to
virtual memory 0C0000000H. I can print text in PMODE.
But I have one doubt on my unmapping of Identity paging. It seems it does not work, because these two code always works.
First Code in Kernel.asm. This is ok, I expect this to work.

Code: Select all

lea esi, msg
mov edi, 0C00B8000H + 488
mov ecx,52
cld
rep movsb
cli
hlt 
This second code should not work because I already did the unmapping of the Identity page.

Code: Select all

lea esi, msg
mov edi, 0B8000H + 488
mov ecx,52
cld
rep movsb
cli
hlt 
my final code for unmapping the Identity page is this,
I added the following in the above unmapping code.

Code: Select all

xor ax, ax
mov ds, ax
mov es, ax
;invlpg virtua_address
equivalent of invlpg from NASM in  32-bit code
 db 0fh
 db 01h
 db 3dh
;0C0091000h
 db 00h
 db 10h
 db 09h
 db 0c9h
I have tried many variations of invlpg but they don't work.

Thanks
Sheena
BY THE TIME YOU FINISH YOUR OS, OS IS ALREADY OBSOLETE
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

sheena9877 wrote:Hi,
Now my paging is working. The first 4mb of physical memory is mapped to
virtual memory 0C0000000H. I can print text in PMODE.
But I have one doubt on my unmapping of Identity paging. It seems it does not work, because these two code always works.
First Code in Kernel.asm. This is ok, I expect this to work.

Code: Select all

lea esi, msg
mov edi, 0C00B8000H + 488
mov ecx,52
cld
rep movsb
cli
hlt 
This second code should not work because I already did the unmapping of the Identity page.

Code: Select all

lea esi, msg
mov edi, 0B8000H + 488
mov ecx,52
cld
rep movsb
cli
hlt 
my final code for unmapping the Identity page is this,
I added the following in the above unmapping code.

Code: Select all

xor ax, ax
mov ds, ax
mov es, ax
;invlpg virtua_address
equivalent of invlpg from NASM in  32-bit code
 db 0fh
 db 01h
 db 3dh
;0C0091000h
 db 00h
 db 10h
 db 09h
 db 0c9h
I have tried many variations of invlpg but they don't work.

Thanks
Sheena
It's the my same problem.
Try to do:
invlpg [0]

Or maybe you can try to flush the entire cache, but it's a waste of time to invalidate the entire cache when you want to invalidate only a page directory.
Post Reply