Hi,
I finally am starting to rewrite Kube in 32bits, but I have a question. In real mode I could jump to a newly loaded program by doing:
jmp 0x3000:0x0000
How do I do the same in Pmode?
My kernel is loaded to linear 0x10000 by the bootloader. There are no other defined segments, just a big 4gigs with both code and data. So could I just issue a jmp 0x30000:0x00000 in pmode? And if I did a call there could I just issue a retf to return back to my kernel?
Thanks, and yes I am a total pmode newbie.
pmode jump to code question
Hi,
In PMode, all segment selectors point to an entry in your GDT. I assume you have done the 'usual' of including one NULL segment, one Code segment and one Data segment.
You get the segment selector by the offset in to the GDT. As each entry is 8bytes long, that means, that if you have the setup described above, your CS should be 0x08. So, in this case, you would do:
I assume you want 0x300000 linear, as this is what your code sample would imply. In fact, if you are already in segment 0x08, you don't even need to far jump. Simply do the following:
You have already, of course, have done a far jump to 0x08:something to finalise going in to pmode, havent you?
Cheers,
Adam
In PMode, all segment selectors point to an entry in your GDT. I assume you have done the 'usual' of including one NULL segment, one Code segment and one Data segment.
You get the segment selector by the offset in to the GDT. As each entry is 8bytes long, that means, that if you have the setup described above, your CS should be 0x08. So, in this case, you would do:
Code: Select all
jmp 0x08:0x300000
Code: Select all
jmp 0x300000
Cheers,
Adam
- salil_bhagurkar
- Member
- Posts: 261
- Joined: Mon Feb 19, 2007 10:40 am
- Location: India
If u hav segs for 4 gigs then they probably have 'segment descriptors' as 0x08 and 0x10 -- 0x08 for code and 0x10 for data in the GDT(Global Descriptor Table) with the first entry in the gdt a null entry. So to jump to the newly loaded kernel you need to compute the actual physical memory address... e.g. In rmode if it is 0x3000:0x0000 That comes out to be 0x30000 . So to jump you use jmp 0x08:0x30000 (0x08 is the descriptor)
Or just replace jmp by call to issue a far call. Yes you can use retf.
Or just replace jmp by call to issue a far call. Yes you can use retf.
user programs or modules
Hi,
Hi, sorry, I meant to say that my kernel is already loaded and running in pmode, and I want to be able to jump to a user program that the kernel loads from disk.. thanks for your answers, they were what I was looking for.
Hi, sorry, I meant to say that my kernel is already loaded and running in pmode, and I want to be able to jump to a user program that the kernel loads from disk.. thanks for your answers, they were what I was looking for.
If your GDT descriptor are 0 based, you could run a simple program by loading test.bin to 0x400000 and in your kernel doing this
call 0x400000
; the program will return here
The test.bin example
NOTE: You would also need to enable A20 to load other 1mb.
call 0x400000
; the program will return here
The test.bin example
Code: Select all
use32 ; we want 32bit addressing
ORG 0x400000 ; where our program is loaded to
; put some more code here
ret ; return to kernel
Re: user programs or modules
Hi,
This will load CS, EIP, SS and ESP (and EFLAGS for IRETD) from the stack, and switch from CPL=0 to CPL=3 at the same time.
Cheers,
Brendan
If the user program is meant to run at CPL=3 (so that it can't trash the kernel for e.g.) then you can't jump to it's code from the kernel. Instead you need to "return" to it's code - i.e. push the relevant values on the kernel's stack, then either do "RETF" or "IRETD".kubeos wrote:Hi, sorry, I meant to say that my kernel is already loaded and running in pmode, and I want to be able to jump to a user program that the kernel loads from disk.. thanks for your answers, they were what I was looking for.
This will load CS, EIP, SS and ESP (and EFLAGS for IRETD) from the stack, and switch from CPL=0 to CPL=3 at the same time.
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.