OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 25, 2024 8:49 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Paging Wrong Problem
PostPosted: Sat Jan 21, 2017 8:32 am 
Offline
Member
Member

Joined: Sat Jan 21, 2017 7:35 am
Posts: 35
I am asking my first question, thus, this may be the wrong place.

I am developing a OS and am stuck, kind of, on virtual memory management aka Paging. I setup a page directory (1024 u32). I also have a array of 1024 page tables - u32[1024]1024] __aligned. I map each page table to a page directory 1 to 1. After enabling paging, I add a page for 0xb8000 and use that address to print to screen but nothing shows up. Why??????????????????????.

Code -

Code:
extern "C" void LoadDirectory(DirectoryEntry*);
extern "C" void EnablePaging(void);
extern "C" {
PageTable KernelMap[1024] __attribute__((aligned(4096)));
DirectoryEntry KernelDirectory[1024] __attribute__((aligned(4096)));
}

PagingBroker::PagingBroker() {
if(!pagingSetup){
int setupIndex = 0;
for( ; setupIndex < 1024; setupIndex++) {
KernelDirectory[setupIndex] = 0x2; // Supervisor, Read-Write, Not Present
}
pagingSetup = true;
}
}

/* Higher Half */
void PagingBroker::setupPaging() {
unsigned int pageIndex;

for(pageIndex = 0; pageIndex < 1024; pageIndex++) {
KernelMap[0][pageIndex] = (pageIndex * 0x1000) | 3;
}

for(pageIndex = 0; pageIndex < 1024; pageIndex++) {
KernelMap[1][pageIndex] = ((pageIndex + 1024) * 0x1000) | 3;
}


KernelDirectory[0] = ((DirectoryEntry) KernelMap[0]) | 3; // Identity Map First 4MB
KernelDirectory[1] = ((DirectoryEntry) KernelMap[1]) | 3; // 8MB


LoadDirectory(KernelDirectory);
EnablePaging();
}void PagingBroker::AddPage(unsigned long virtualAddress, unsigned long physicalAddress, unsigned int pflags) {
unsigned long pdIndex = virtualAddress >> 22;
unsigned long ptIndex = virtualAddress >> 12;

KernelDirectory[pdIndex] = ((DirectoryEntry) KernelDirectory[pdIndex]) | 3;

KernelMap[pdIndex][ptIndex] = physicalAddress | (pflags & 0xfff); // Present

FlushTLB(pdIndex);
}


In my Main() -
Code:
{
PagingBroker pb;
pb.setupPaging();
pb.AddPage((anything more than 8mb - 'xaddr'), 0xb8000, 3);
char *write = (char*) xaddr;
*write = 'd';
write[1] = 0x7;
}


-------------------------------

I am using GCC and NASM with a linker (ld).


Top
 Profile  
 
 Post subject: Re: Paging Wrong Problem
PostPosted: Sat Jan 21, 2017 8:56 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

My advice would be to use the "info tab" command in the debugger that's built into Bochs to determine how virtual addresses correspond to physical addresses, both before and after calling "pb.AddPage()". This should make it fairly obvious if the page isn't being added properly (and easy to see what actually happens).

Note that this won't just help with problem you think you have now, but will also help with problems you don't know you have now, and problems you will have in the future.. ;)


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: Paging Wrong Problem
PostPosted: Sat Jan 21, 2017 9:53 pm 
Offline
Member
Member

Joined: Sat Jan 21, 2017 7:35 am
Posts: 35
Can you also tell me how? Bochs doesn't seem to have a decent UI.


Top
 Profile  
 
 Post subject: Re: Paging Wrong Problem
PostPosted: Sat Jan 21, 2017 11:45 pm 
Offline
Member
Member

Joined: Sat Jan 21, 2017 7:35 am
Posts: 35
I tested it and the address was not mapped to 0xb8000. Can you help me in finding out the wrongness in the code?


Top
 Profile  
 
 Post subject: Re: Paging Wrong Problem
PostPosted: Sat Jan 21, 2017 11:48 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

SukantPal wrote:
Can you also tell me how? Bochs doesn't seem to have a decent UI.


You'll probably need to configure and compile Bochs yourself (to get full control over which of the many options are enabled/used). I'd also be tempted to suggest creating multiple different variations of Bochs (some with debugging and some without, some for different CPUs, etc).

For some instructions on setting up the GUI debugger, see this wiki page.


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: Paging Wrong Problem
PostPosted: Sun Jan 22, 2017 12:31 am 
Offline
Member
Member

Joined: Sat Jan 21, 2017 7:35 am
Posts: 35
Debugging Pages -

0x00000000-0x007fffff -> 0x0000000000000000-0x00000000007fffff
0xc0000000-0xc0000fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0001000-0xc0001fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0002000-0xc0002fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0003000-0xc0003fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0004000-0xc0004fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0005000-0xc0005fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0006000-0xc0006fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0007000-0xc0007fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0008000-0xc0008fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0009000-0xc0009fff -> 0x00000000f000e000-0x00000000f000efff
0xc000a000-0xc000afff -> 0x00000000f000e000-0x00000000f000efff
0xc000b000-0xc000bfff -> 0x00000000f000e000-0x00000000f000efff
0xc000c000-0xc000cfff -> 0x00000000f000e000-0x00000000f000efff
0xc000d000-0xc000dfff -> 0x00000000f000e000-0x00000000f000efff
0xc000e000-0xc000efff -> 0x00000000f000e000-0x00000000f000efff
0xc000f000-0xc000ffff -> 0x00000000f000e000-0x00000000f000efff
0xc0010000-0xc0010fff -> 0x00000000c0000000-0x00000000c0000fff
0xc0011000-0xc0011fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0012000-0xc0012fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0014000-0xc0015fff -> 0x00000000f000e000-0x00000000f000ffff
0xc0018000-0xc0018fff -> 0x00000000f0009000-0x00000000f0009fff
0xc001b000-0xc001bfff -> 0x00000000f000f000-0x00000000f000ffff
0xc001c000-0xc001cfff -> 0x00000000f000f000-0x00000000f000ffff
0xc001d000-0xc001dfff -> 0x00000000f000f000-0x00000000f000ffff
0xc001f000-0xc001ffff -> 0x00000000c0001000-0x00000000c0001fff
0xc0020000-0xc0020fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0021000-0xc0021fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0022000-0xc0022fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0023000-0xc0023fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0024000-0xc0024fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0025000-0xc0025fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0026000-0xc0026fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0027000-0xc0027fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0028000-0xc0028fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0029000-0xc0029fff -> 0x00000000f000f000-0x00000000f000ffff
0xc002a000-0xc002afff -> 0x00000000f000f000-0x00000000f000ffff
0xc002b000-0xc002bfff -> 0x00000000f000f000-0x00000000f000ffff
0xc002c000-0xc002cfff -> 0x00000000f000f000-0x00000000f000ffff
0xc002d000-0xc002dfff -> 0x00000000f000f000-0x00000000f000ffff
0xc002e000-0xc002efff -> 0x00000000f000f000-0x00000000f000ffff
0xc002f000-0xc002ffff -> 0x00000000f000f000-0x00000000f000ffff
0xc0030000-0xc0030fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0031000-0xc0031fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0032000-0xc0032fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0033000-0xc0033fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0034000-0xc0034fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0035000-0xc0035fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0036000-0xc0036fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0037000-0xc0037fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0038000-0xc0038fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0039000-0xc0039fff -> 0x00000000f000f000-0x00000000f000ffff
0xc003a000-0xc003afff -> 0x00000000f000f000-0x00000000f000ffff
0xc003b000-0xc003bfff -> 0x00000000f000f000-0x00000000f000ffff
0xc003c000-0xc003cfff -> 0x00000000f000f000-0x00000000f000ffff
0xc003d000-0xc003dfff -> 0x00000000f000f000-0x00000000f000ffff
0xc003e000-0xc003efff -> 0x00000000f000f000-0x00000000f000ffff
0xc003f000-0xc003ffff -> 0x00000000f000f000-0x00000000f000ffff
0xc0040000-0xc0040fff -> 0x00000000f000e000-0x00000000f000efff
0xc0041000-0xc0041fff -> 0x000000009fc00000-0x000000009fc00fff
0xc0042000-0xc0042fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0043000-0xc0043fff -> 0x00000000c0002000-0x00000000c0002fff
0xc0044000-0xc0044fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0045000-0xc0045fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0046000-0xc0046fff -> 0x000000009fc00000-0x000000009fc00fff
0xc0047000-0xc0047fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0048000-0xc0048fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0049000-0xc0049fff -> 0x00000000f000f000-0x00000000f000ffff
0xc004a000-0xc004afff -> 0x00000000f000f000-0x00000000f000ffff
0xc004b000-0xc004bfff -> 0x00000000f000f000-0x00000000f000ffff
0xc004c000-0xc004cfff -> 0x00000000f000f000-0x00000000f000ffff
0xc004d000-0xc004dfff -> 0x00000000f000f000-0x00000000f000ffff
0xc004e000-0xc004efff -> 0x00000000f000f000-0x00000000f000ffff
0xc004f000-0xc004ffff -> 0x00000000f000f000-0x00000000f000ffff
0xc0050000-0xc0050fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0051000-0xc0051fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0052000-0xc0052fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0053000-0xc0053fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0054000-0xc0054fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0055000-0xc0055fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0056000-0xc0056fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0057000-0xc0057fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0058000-0xc0058fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0059000-0xc0059fff -> 0x00000000f000f000-0x00000000f000ffff
0xc005a000-0xc005afff -> 0x00000000f000f000-0x00000000f000ffff
0xc005b000-0xc005bfff -> 0x00000000f000f000-0x00000000f000ffff
0xc005c000-0xc005cfff -> 0x00000000f000f000-0x00000000f000ffff
0xc005d000-0xc005dfff -> 0x00000000f000f000-0x00000000f000ffff
0xc005e000-0xc005efff -> 0x00000000f000f000-0x00000000f000ffff
0xc005f000-0xc005ffff -> 0x00000000f000f000-0x00000000f000ffff
0xc0068000-0xc0068fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0069000-0xc0069fff -> 0x00000000f000f000-0x00000000f000ffff
0xc006a000-0xc006afff -> 0x00000000f000f000-0x00000000f000ffff
0xc006b000-0xc006bfff -> 0x00000000f000f000-0x00000000f000ffff
0xc006c000-0xc006cfff -> 0x00000000f000f000-0x00000000f000ffff
0xc006d000-0xc006dfff -> 0x00000000f000f000-0x00000000f000ffff
0xc006e000-0xc006efff -> 0x00000000f000f000-0x00000000f000ffff
0xc006f000-0xc006ffff -> 0x00000000f000f000-0x00000000f000ffff
0xc0070000-0xc0070fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0072000-0xc0072fff -> 0x00000000f000e000-0x00000000f000efff
0xc0073000-0xc0073fff -> 0x00000000f000e000-0x00000000f000efff
0xc0074000-0xc0074fff -> 0x00000000f0009000-0x00000000f0009fff
0xc0075000-0xc0075fff -> 0x00000000f000e000-0x00000000f000efff
0xc0077000-0xc0078fff -> 0x00000000f000e000-0x00000000f000ffff
0xc007a000-0xc007afff -> 0x00000000f000f000-0x00000000f000ffff
0xc007b000-0xc007bfff -> 0x00000000f000f000-0x00000000f000ffff
0xc007c000-0xc007cfff -> 0x00000000f000f000-0x00000000f000ffff
0xc007d000-0xc007dfff -> 0x00000000f000f000-0x00000000f000ffff
0xc007e000-0xc007efff -> 0x00000000f000f000-0x00000000f000ffff
0xc007f000-0xc007ffff -> 0x00000000f000f000-0x00000000f000ffff
0xc0080000-0xc0080fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0081000-0xc0081fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0082000-0xc0082fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0083000-0xc0083fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0084000-0xc0084fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0085000-0xc0085fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0086000-0xc0086fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0087000-0xc0087fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0088000-0xc0088fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0089000-0xc0089fff -> 0x00000000f000f000-0x00000000f000ffff
0xc008a000-0xc008afff -> 0x00000000f000f000-0x00000000f000ffff
0xc008b000-0xc008bfff -> 0x00000000f000f000-0x00000000f000ffff
0xc008c000-0xc008cfff -> 0x00000000f000f000-0x00000000f000ffff
0xc008d000-0xc008dfff -> 0x00000000f000f000-0x00000000f000ffff
0xc008e000-0xc008efff -> 0x00000000f000f000-0x00000000f000ffff
0xc008f000-0xc008ffff -> 0x00000000f000f000-0x00000000f000ffff
0xc0090000-0xc0090fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0091000-0xc0091fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0092000-0xc0092fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0093000-0xc0093fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0094000-0xc0094fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0095000-0xc0095fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0096000-0xc0096fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0097000-0xc0097fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0098000-0xc0098fff -> 0x00000000f000f000-0x00000000f000ffff
0xc0099000-0xc0099fff -> 0x00000000f000f000-0x00000000f000ffff
0xc009a000-0xc009afff -> 0x00000000f000f000-0x00000000f000ffff
0xc009b000-0xc009bfff -> 0x00000000f000f000-0x00000000f000ffff
0xc009c000-0xc009cfff -> 0x00000000f000f000-0x00000000f000ffff
0xc009d000-0xc009dfff -> 0x00000000f000f000-0x00000000f000ffff
0xc009e000-0xc009efff -> 0x00000000f000f000-0x00000000f000ffff
0xc009f000-0xc009ffff -> 0x00000000f000f000-0x00000000f000ffff
0xc00a0000-0xc00a0fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00a1000-0xc00a1fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00a2000-0xc00a2fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00a3000-0xc00a3fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00a4000-0xc00a4fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00a5000-0xc00a5fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00a6000-0xc00a6fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00a7000-0xc00a7fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00a8000-0xc00a8fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00a9000-0xc00a9fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00aa000-0xc00aafff -> 0x00000000f000f000-0x00000000f000ffff
0xc00ab000-0xc00abfff -> 0x00000000f000f000-0x00000000f000ffff
0xc00ac000-0xc00acfff -> 0x00000000f000f000-0x00000000f000ffff
0xc00ad000-0xc00adfff -> 0x00000000f000f000-0x00000000f000ffff
0xc00ae000-0xc00aefff -> 0x00000000f000f000-0x00000000f000ffff
0xc00af000-0xc00affff -> 0x00000000f000f000-0x00000000f000ffff
0xc00b0000-0xc00b0fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00b1000-0xc00b1fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00b2000-0xc00b2fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00b3000-0xc00b3fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00b4000-0xc00b4fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00b5000-0xc00b5fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00b6000-0xc00b6fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00b7000-0xc00b7fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00b8000-0xc00b8fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00b9000-0xc00b9fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00ba000-0xc00bafff -> 0x00000000f000f000-0x00000000f000ffff
0xc00bb000-0xc00bbfff -> 0x00000000f000f000-0x00000000f000ffff
0xc00bc000-0xc00bcfff -> 0x00000000f000f000-0x00000000f000ffff
0xc00bd000-0xc00bdfff -> 0x00000000f000f000-0x00000000f000ffff
0xc00be000-0xc00befff -> 0x00000000f000f000-0x00000000f000ffff
0xc00bf000-0xc00bffff -> 0x00000000f000f000-0x00000000f000ffff
0xc00c0000-0xc00c0fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00c1000-0xc00c1fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00c2000-0xc00c2fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00c3000-0xc00c3fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00c4000-0xc00c4fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00c5000-0xc00c5fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00c6000-0xc00c6fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00c7000-0xc00c7fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00c8000-0xc00c8fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00c9000-0xc00c9fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00ca000-0xc00cafff -> 0x00000000f000f000-0x00000000f000ffff
0xc00cb000-0xc00cbfff -> 0x00000000f000f000-0x00000000f000ffff
0xc00cc000-0xc00ccfff -> 0x00000000f000f000-0x00000000f000ffff
0xc00cd000-0xc00cdfff -> 0x00000000f000f000-0x00000000f000ffff
0xc00ce000-0xc00cefff -> 0x00000000f000f000-0x00000000f000ffff
0xc00cf000-0xc00cffff -> 0x00000000f000f000-0x00000000f000ffff
0xc00d0000-0xc00d0fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00d1000-0xc00d1fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00d2000-0xc00d2fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00d3000-0xc00d3fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00d4000-0xc00d4fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00d5000-0xc00d5fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00d6000-0xc00d6fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00d7000-0xc00d7fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00d8000-0xc00d8fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00d9000-0xc00d9fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00da000-0xc00dafff -> 0x00000000f000f000-0x00000000f000ffff
0xc00db000-0xc00dbfff -> 0x00000000f000f000-0x00000000f000ffff
0xc00dc000-0xc00dcfff -> 0x00000000f000f000-0x00000000f000ffff
0xc00dd000-0xc00ddfff -> 0x00000000f000f000-0x00000000f000ffff
0xc00de000-0xc00defff -> 0x00000000f000f000-0x00000000f000ffff
0xc00df000-0xc00dffff -> 0x00000000f000f000-0x00000000f000ffff
0xc00e0000-0xc00e0fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00e1000-0xc00e1fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00e2000-0xc00e2fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00e3000-0xc00e3fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00e4000-0xc00e4fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00e5000-0xc00e5fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00e6000-0xc00e6fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00e7000-0xc00e7fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00e8000-0xc00e8fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00e9000-0xc00e9fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00ea000-0xc00eafff -> 0x00000000f000f000-0x00000000f000ffff
0xc00eb000-0xc00ebfff -> 0x00000000f000f000-0x00000000f000ffff
0xc00ec000-0xc00ecfff -> 0x00000000f000f000-0x00000000f000ffff
0xc00ed000-0xc00edfff -> 0x00000000f000f000-0x00000000f000ffff
0xc00ee000-0xc00eefff -> 0x00000000f000f000-0x00000000f000ffff
0xc00ef000-0xc00effff -> 0x00000000f000f000-0x00000000f000ffff
0xc00f0000-0xc00f0fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00f1000-0xc00f1fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00f2000-0xc00f2fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00f3000-0xc00f3fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00f4000-0xc00f4fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00f5000-0xc00f5fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00f6000-0xc00f6fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00f7000-0xc00f7fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00f8000-0xc00f8fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00f9000-0xc00f9fff -> 0x00000000f000f000-0x00000000f000ffff
0xc00fa000-0xc00fafff -> 0x00000000f000f000-0x00000000f000ffff
0xc00fb000-0xc00fbfff -> 0x00000000f000f000-0x00000000f000ffff
0xc00fc000-0xc00fcfff -> 0x00000000f000f000-0x00000000f000ffff
0xc00fd000-0xc00fdfff -> 0x00000000f000f000-0x00000000f000ffff
0xc00fe000-0xc00fefff -> 0x00000000f000f000-0x00000000f000ffff
0xc00ff000-0xc00fffff -> 0x00000000f000f000-0x00000000f000ffff
0xc0118000-0xc0118fff -> 0x00000000d4000000-0x00000000d4000fff
0xc0119000-0xc0119fff -> 0x00000000fa000000-0x00000000fa000fff
0xc011a000-0xc011afff -> 0x0000000000000000-0x0000000000000fff
0xc011b000-0xc011bfff -> 0x00000000000bd000-0x00000000000bdfff
0xc0122000-0xc0122fff -> 0x0000000000085000-0x0000000000085fff
0xc014a000-0xc014afff -> 0x0000000000000000-0x0000000000000fff
0xc0150000-0xc0150fff -> 0x0000000000000000-0x0000000000000fff
0xc0156000-0xc0156fff -> 0x0000000000000000-0x0000000000000fff
0xc015c000-0xc015cfff -> 0x0000000000000000-0x0000000000000fff
0xc0162000-0xc0162fff -> 0x0000000000000000-0x0000000000000fff
0xc0168000-0xc0168fff -> 0x0000000000000000-0x0000000000000fff
0xc016b000-0xc016bfff -> 0x0000000000000000-0x0000000000000fff
0xc01ca000-0xc01cafff -> 0x0000000000000000-0x0000000000000fff
0xc01cc000-0xc01ccfff -> 0x000000001fcbf000-0x000000001fcbffff
0xc01cf000-0xc01cffff -> 0x0000000000000000-0x0000000000000fff
0xc01d2000-0xc01d2fff -> 0x0000000000000000-0x0000000000000fff
0xc01d3000-0xc01d3fff -> 0x0000000000000000-0x0000000000000fff


Top
 Profile  
 
 Post subject: Re: Paging Wrong Problem
PostPosted: Sun Jan 22, 2017 12:32 am 
Offline
Member
Member

Joined: Sat Jan 21, 2017 7:35 am
Posts: 35
Can someone tell me why isn't 0xc00b8000 not being mapped to 0xb8000


Top
 Profile  
 
 Post subject: Re: Paging Wrong Problem
PostPosted: Sun Jan 22, 2017 2:47 am 
Online
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4597
Location: Chichester, UK
I can't tell you the answer to your problem (mainly because I am not prepared to wade through badly formatted code to do your debugging for you) but let me offer you some advice. (This is all my opinion, which I realize others may disagree with - but forums are there for people to give their opinions, aren't they?).

1. If you must post code then use "code" tags to ensure that it is formatted legibly.

2. But, you really shouldn't need to post any appreciable amount of code in a forum post. It makes for illegibility, and my initial reaction is to ignore the post. If you want people to review your code point them to an on-line repository such as github.

3. If you are not using version control, such as git, stop everything now, learn how to use a version control system, and use it.

4. Your problem appears to be a fairly trivial one; the page tables are not being set up correctly. If your debugging skills aren't up to discovering why, stop everything now and practice debugging. You will run into much more difficult problems in the future.

5. (Controversial point - purists look away.) Whilst there is nothing wrong with writing your OS in C++, I would recommend that you consider practising your paging code in C, or even assembler, first. Both are "closer to the metal" and it may be easier to spot silly errors or misunderstandings. When you are sure that you understand what is happening, then write the C++ version.

6. Try very, very hard to solve the problem yourself before posting here. You really don't want to get the reputation of asking others to solve every problem for you. And you will learn more, and gain more satisfaction, that way. Only ask in the forums as the final resort. The current problem is one that should be well within your ability to solve.

Some concrete advice on debugging your current problem:

1. Use your debugger to inspect the page tables in memory. Compare what they contain with what you expect them to contain.

2. If possible, use print statements to print the value of important variables at key points. Difficult in this case as you (eventually) can't address video memory.

3. Single-step through the code in the debugger of your choice, inspecting register and memory values at each stage. This should make it very easy to track down the error. (Many would recommend that you work through the code with pencil and paper, but I prefer to use all available tools.)

I hope that you take all of this in the spirit that it is intended. I'm hoping that my suggestions will help you to learn better and get more satisfaction from your hobby.


Top
 Profile  
 
 Post subject: Re: Paging Wrong Problem
PostPosted: Sun Jan 22, 2017 3:13 am 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
Fully agree with what iansjack said, with one small addition:

iansjack wrote:
2. If possible, use print statements to print the value of important variables at key points. Difficult in this case as you (eventually) can't address video memory.


bochs contains a debug output port (0xe8 iirc), write debug routines to output text to this port and redirect kernel prints there, you will then see debug output in bochs log.

_________________
Learn to read.


Top
 Profile  
 
 Post subject: Re: Paging Wrong Problem
PostPosted: Sun Jan 22, 2017 3:15 am 
Online
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4597
Location: Chichester, UK
Thanks for that clarification. I'm not familiar with Bochs as I prefer qemu/gdb or SimNow as my debugging tools of choice.


Top
 Profile  
 
 Post subject: Re: Paging Wrong Problem
PostPosted: Sun Jan 22, 2017 7:02 am 
Offline
Member
Member

Joined: Sat Nov 10, 2012 1:16 pm
Posts: 62
SukantPal wrote:
Can someone tell me why isn't 0xc00b8000 not being mapped to 0xb8000
Because, well...

0xc00b8000-0xc00b8fff -> 0x00000000f000f000-0x00000000f000ffff

Straight from your dump post labeled "Debugging Pages".

The first two possibilities that come to mind are incorrectly sized page table entries (are you sure PAE is enabled?) and loading your page table entries in an order that's, um, guaranteed to stomp on correct values with incorrect ones.

EDIT: The third one that comes to mind is that you're calling methods on an uninitialized variable. #-o Based on what you've posted of main(), your code shouldn't even compile (or, at the very least, should be spewing warnings up the ying-yang at compile time).


Top
 Profile  
 
 Post subject: Re: Paging Wrong Problem
PostPosted: Sun Jan 22, 2017 9:04 am 
Offline
Member
Member
User avatar

Joined: Thu Mar 27, 2014 3:57 am
Posts: 568
Location: Moscow, Russia
Are you sure "ptIndex = virtualAddress >> 12" is what you want?

_________________
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay


Top
 Profile  
 
 Post subject: Re: Paging Wrong Problem
PostPosted: Fri Jan 27, 2017 4:34 am 
Offline
Member
Member

Joined: Sat Jan 21, 2017 7:35 am
Posts: 35
I still don't get it -

Code:
   unsigned long freeFrame = frameAllocator -> getFrame();
   KernelDirectory[100] = ((uint32_t) heapTableI) | 3; // 4kb aligned table
   FlushTLB(100);

   heapTableI[0] = freeFrame | 3;

   uint32_t *t = (uint32_t*) (100 << 22);
   *t = 12; // Page Fault Why??
   
   kernelDebugger -> debugInt(*t); // PageFautl
   kernelDebugger -> debugLine("ovv");


Interesting to note, a page fault occurs in qemu. But in bochs, *t always stays 0. debugInt(*t) gives 0.


Top
 Profile  
 
 Post subject: Re: Paging Wrong Problem
PostPosted: Fri Jan 27, 2017 5:52 am 
Offline
Member
Member

Joined: Sat Jan 21, 2017 7:35 am
Posts: 35
I'm so happy I solved the problem and will share it with you. The kernel as told was higher half mapped to 3GB + 1MB. To get linear address, I had to subtract 0xc0000000 from the page table address.

Code:
KernelDirectory[n] = ((uint32_t) heapTable - 0xc0000000) | 3;


I found out the problem by getting the frame no. of the page table. It was much more than 256 (loading address) + 14 (size of kernel) blocks. Then I tested this and horray fixed the problem!!!!

Thank you for all your advice!!! It was very important for me on the first post. If there is a way to make this post [SOLVED], please tell me.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot], nullplan, SemrushBot [Bot] and 223 guests


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 post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group