Page 1 of 1
Help with Paging x86
Posted: Wed Feb 14, 2018 2:11 pm
by Gigaboy
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.
Re: Help with Paging x86
Posted: Wed Feb 14, 2018 2:50 pm
by SeeSoftware
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?)
Re: Help with Paging x86
Posted: Wed Feb 14, 2018 2:55 pm
by Gigaboy
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.
Re: Help with Paging x86
Posted: Wed Feb 14, 2018 3:06 pm
by SeeSoftware
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))
Re: Help with Paging x86
Posted: Thu Feb 15, 2018 11:48 am
by FallenAvatar
you say you are triple faulting? Use bochs and it will tell you what faults are happening.
- Amy
Re: Help with Paging x86
Posted: Thu Feb 15, 2018 1:57 pm
by Gigaboy
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: Select all
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
Re: Help with Paging x86
Posted: Thu Feb 15, 2018 9:53 pm
by FallenAvatar
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.
Re: Help with Paging x86
Posted: Thu Feb 15, 2018 11:32 pm
by Gigaboy
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)
Re: Help with Paging x86
Posted: Thu Feb 15, 2018 11:44 pm
by FallenAvatar
You are assuming the contents of all the segment registers (CS, DS, etc.)
- Amy
Re: Help with Paging x86
Posted: Fri Feb 16, 2018 7:26 am
by MichaelPetch
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.
Re: Help with Paging x86
Posted: Fri Feb 16, 2018 9:31 am
by Gigaboy
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.)
Re: Help with Paging x86
Posted: Fri Feb 16, 2018 11:17 am
by ~
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...
Re: Help with Paging x86
Posted: Fri Feb 16, 2018 2:39 pm
by MichaelPetch
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.