OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 8:53 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Help with Paging x86
PostPosted: Wed Feb 14, 2018 2:11 pm 
Offline
User avatar

Joined: Wed Aug 23, 2017 1:09 pm
Posts: 20
Okay, I can't seem to figure out how to implement paging in my OS and I've been given examples, but I still can't seem to figure it out. The only difference I could find, that was different than other people's methods of paging, is that usually they are using GRUB while I have my own bootloader. I wouldn't think that would make that much of a difference. Anyways I've been trying to figure it out for about 2 months now and I can't get it to work, so if someone could do it for me that would be greatly appreciated. Now, I still want to know how you implement it with my OS, so if you give it a go please leave comments everywhere so I can understand what's going on. The Github link to my already existing files is here. Again, would greatly appreciate the help. ;)

_________________
Gigaboy


Last edited by Gigaboy on Thu Feb 15, 2018 11:34 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Help with Paging x86
PostPosted: Wed Feb 14, 2018 2:50 pm 
Offline

Joined: Tue Apr 18, 2017 6:02 pm
Posts: 13
did you verify that you have set cr3 and the page directories to point at the PHYSICAL memory location (not the virtual adress location)
(my english is not very good but i hope you understand what i mean)

(or do you have problems with the data structure?)


Top
 Profile  
 
 Post subject: Re: Help with Paging x86
PostPosted: Wed Feb 14, 2018 2:55 pm 
Offline
User avatar

Joined: Wed Aug 23, 2017 1:09 pm
Posts: 20
SeeSoftware wrote:
did you verify that you have set cr3 and the page directories to point at the PHYSICAL memory location (not the virtual adress location)
(my english is not very good but i hope you understand what i mean)

(or do you have problems with the data structure?)


Yes, I can understand you fine. :) And I don't know what the problem is. It triple faults everytime I try to implement it.

_________________
Gigaboy


Top
 Profile  
 
 Post subject: Re: Help with Paging x86
PostPosted: Wed Feb 14, 2018 3:06 pm 
Offline

Joined: Tue Apr 18, 2017 6:02 pm
Posts: 13
Gigaboy wrote:
SeeSoftware wrote:
did you verify that you have set cr3 and the page directories to point at the PHYSICAL memory location (not the virtual adress location)
(my english is not very good but i hope you understand what i mean)

(or do you have problems with the data structure?)


Yes, I can understand you fine. :) And I don't know what the problem is. It triple faults everytime I try to implement it.


ok (if you are using a struct (for page entries/dirs) in C/C++) you have to make SURE that structure packing is 1 BYTE

GCC: struct __attribute__ ((packed)) {...}

MSVC: #pragma pack(push, 1)
struct { .... }
#pragma pack(pop)

2. make sure those Data structures (like a Array holding Entries etc...) are 4096 byte aligned

eg:

GCC: uint32_t MyStructure[1024] __attribute__ ((aligned (4096)));
MSVC: __declspec(align(4096)) uint32_t MyStructure[1024];

3. make sure you have enough stack space for those data structures (because i didnt i just had 1mib stack (and you need 4mib if you want to have 1024*1024 entries (whole table (4GIB) (4k paging))


Top
 Profile  
 
 Post subject: Re: Help with Paging x86
PostPosted: Thu Feb 15, 2018 11:48 am 
Offline
Member
Member

Joined: Mon Jan 03, 2011 6:58 pm
Posts: 283
you say you are triple faulting? Use bochs and it will tell you what faults are happening.

- Amy


Top
 Profile  
 
 Post subject: Re: Help with Paging x86
PostPosted: Thu Feb 15, 2018 1:57 pm 
Offline
User avatar

Joined: Wed Aug 23, 2017 1:09 pm
Posts: 20
tjmonk15 wrote:
you say you are triple faulting? Use bochs and it will tell you what faults are happening.

- Amy

When I use bochs the kernel won't start. It has a physical read error when I use bochs instead of qemu.
Code:
00000000000i[CPU0 ] CPU is in real mode (active)
00000000000i[CPU0 ] CS.mode = 16 bit
00000000000i[CPU0 ] SS.mode = 16 bit
00000000000i[CPU0 ] EFER   = 0x00000000
00000000000i[CPU0 ] | EAX=00000000  EBX=00000000  ECX=00000000  EDX=00000000
00000000000i[CPU0 ] | ESP=00000000  EBP=00000000  ESI=00000000  EDI=00000000
00000000000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf ZF af PF cf
00000000000i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00000000000i[CPU0 ] |  CS:0000( 0000| 0|  0) 00000000 00000000 0 0
00000000000i[CPU0 ] |  DS:0000( 0000| 0|  0) 00000000 00000000 0 0
00000000000i[CPU0 ] |  SS:0000( 0000| 0|  0) 00000000 00000000 0 0
00000000000i[CPU0 ] |  ES:0000( 0000| 0|  0) 00000000 00000000 0 0
00000000000i[CPU0 ] |  FS:0000( 0000| 0|  0) 00000000 00000000 0 0
00000000000i[CPU0 ] |  GS:0000( 0000| 0|  0) 00000000 00000000 0 0
00000000000i[CPU0 ] | EIP=00000000 (00000000)
00000000000i[CPU0 ] | CR0=0x00000000 CR2=0x00000000
00000000000i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
bx_dbg_read_linear: physical memory read error (phy=0x0000000000000000, lin=0x0000000000000000)
00000000000i[CTRL ] quit_sim called with exit code 1

_________________
Gigaboy


Top
 Profile  
 
 Post subject: Re: Help with Paging x86
PostPosted: Thu Feb 15, 2018 9:53 pm 
Offline
Member
Member

Joined: Mon Jan 03, 2011 6:58 pm
Posts: 283
Gigaboy wrote:
tjmonk15 wrote:
you say you are triple faulting? Use bochs and it will tell you what faults are happening.

- Amy

When I use bochs the kernel won't start. It has a physical read error when I use bochs instead of qemu.


Sounds like you have other problems that may be related to what you are dealing with. With that error, I would hazard a guess that you are assuming the contents of a register when you shouldn't.

- Amy

P.S. You might wanna get your code up to github, and others might take a look.


Top
 Profile  
 
 Post subject: Re: Help with Paging x86
PostPosted: Thu Feb 15, 2018 11:32 pm 
Offline
User avatar

Joined: Wed Aug 23, 2017 1:09 pm
Posts: 20
tjmonk15 wrote:
You might wanna get your code up to github, and others might take a look.

This is my Github link. Also, why would Qemu not tell me about the physical read error? (just curious)

_________________
Gigaboy


Top
 Profile  
 
 Post subject: Re: Help with Paging x86
PostPosted: Thu Feb 15, 2018 11:44 pm 
Offline
Member
Member

Joined: Mon Jan 03, 2011 6:58 pm
Posts: 283
You are assuming the contents of all the segment registers (CS, DS, etc.)

- Amy


Top
 Profile  
 
 Post subject: Re: Help with Paging x86
PostPosted: Fri Feb 16, 2018 7:26 am 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 692
I don't see any paging code in your github repository. I only see a simple switch to Protected mode. As it is when I run this code it seems to run in QMEU and Bochs. Are you compiling this under Windows? (ie. MinGW or Cygwin)? I'll assume you aren't on Windows, but I just want to make sure.

PS: You should really use a cross compiler.


Top
 Profile  
 
 Post subject: Re: Help with Paging x86
PostPosted: Fri Feb 16, 2018 9:31 am 
Offline
User avatar

Joined: Wed Aug 23, 2017 1:09 pm
Posts: 20
MichaelPetch wrote:
I don't see any paging code in your github repository. I only see a simple switch to Protected mode. As it is when I run this code it seems to run in QMEU and Bochs. Are you compiling this under Windows? (ie. MinGW or Cygwin)? I'll assume you aren't on Windows, but I just want to make sure.

PS: You should really use a cross compiler.


I deleted the paging C and header files because they weren't working.

I'm running on Ubuntu 16.04.

I'm not using a cross compiler because I didn't know I should have used one when I started this project and I haven't gotten around to changing the compilers yet. (That is one of the things on my todo list though.)

_________________
Gigaboy


Top
 Profile  
 
 Post subject: Re: Help with Paging x86
PostPosted: Fri Feb 16, 2018 11:17 am 
Offline
Member
Member
User avatar

Joined: Tue Mar 06, 2007 11:17 am
Posts: 1225
I made an x86 32-bit paging table in NASM assembly, static and identity mapped, for being able to easily see the basic full structure of paging:
http://sourceforge.net/projects/x86-32-paging/files/static_identity_mapped_paging_tables.asm

You should first make a kernel with some usable functions and some way to run programs, at least make a kernel image with already-running programs just to test, and then try to add paging for being able to test if it works.

I think that next year I will spend the whole year trying to add a memory manager capable of working with or without paging, with or without Ring 0-3 memory protection (all Ring 0 or ringed), after completing my minimally functional C compiler, compile/assemble it to my OS, and add a little bit of file system support.

That should let me make enough tests on my kernel core, compiler and the memory management code to add, so as to let me get going by being able to use open source programs compiled under my own OS as I add more capabilities.

I had initially just a very basic kernel with text console that could load raw binary files with a provisional executable/import header, from floppy. But as you can see, from there we can advance as much as we like if we are careful enough to include a compiler and toolchain that we fully understand, to extend it under our own OS, for being able to freely try to run our own code or third-party one, open source, and maybe later, binary-only files from Win32, DOS, Linux...

_________________
Live PC 1: Image Live PC 2: Image

YouTube:
http://youtube.com/@AltComp126/streams
http://youtube.com/@proyectos/streams

http://master.dl.sourceforge.net/projec ... 7z?viasf=1


Top
 Profile  
 
 Post subject: Re: Help with Paging x86
PostPosted: Fri Feb 16, 2018 2:39 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 692
What is the point of showing us your github project that doesn't include the code that doesn't work? That doesn't help us. If you were to add back your paging code that doesn't work then maybe we can look at it and tell you why. As it stands the github code seems to work so it isn't useful to us to help you with your real problem.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 182 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group