Hello,every one.I'm going to create the first process in my kernel.
I have create several kernel processes in my OS,that means they run in ring 0.Because there are no privilege changes when interrupt occurs,this seems easy,and i have done that.
I want to create user process that run in ring 3, and i have nothing in mind what should i do.
Can anyone tell me what should i do to create such process or any code to read or books?
Thank you very much.
how to create the first user process?
- Combuster
- 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:
Re: how to create the first user process?
If you can make a kernel thread, the only thing it needs to do to land in userspace is to build a custom stackframe containing eip/cs/eflags/esp/ss and IRET to it. The intel manuals should help you out from there.
Re: how to create the first user process?
I hope that helps.
Re: how to create the first user process?
When you work on implementing user-space, I suggest:
1. If you have not handle exception yet, do it now (including #TS, #SS and #GP).
2. Tweak the syscall interface, if using interrupt, set user bits so that accessible from ring3
3. plan the address layout
4. you only need a few instructions to enter ring3, I'll leave you figure out the detail from the manual.
The next thing would be create user-space from executable file, you will need:
1. File system support (operate on physical device or ram drive), a minimum VFS layer would do fine.
2. Program loader, which extract the program into address space, do relocation, etc. Consult the ELF document(or executable format of your choice) for detail.
3. You're done here.
1. If you have not handle exception yet, do it now (including #TS, #SS and #GP).
2. Tweak the syscall interface, if using interrupt, set user bits so that accessible from ring3
3. plan the address layout
4. you only need a few instructions to enter ring3, I'll leave you figure out the detail from the manual.
The next thing would be create user-space from executable file, you will need:
1. File system support (operate on physical device or ram drive), a minimum VFS layer would do fine.
2. Program loader, which extract the program into address space, do relocation, etc. Consult the ELF document(or executable format of your choice) for detail.
3. You're done here.
-
- Posts: 1
- Joined: Wed Jul 25, 2012 5:32 pm
- Contact:
Re: how to create the first user process?
I’m still learning about Ubuntu. Far away to patch the kernel. Lol
Re: how to create the first user process?
Thank you.bluemoon wrote:When you work on implementing user-space, I suggest:
1. If you have not handle exception yet, do it now (including #TS, #SS and #GP).
2. Tweak the syscall interface, if using interrupt, set user bits so that accessible from ring3
3. plan the address layout
4. you only need a few instructions to enter ring3, I'll leave you figure out the detail from the manual.
The next thing would be create user-space from executable file, you will need:
1. File system support (operate on physical device or ram drive), a minimum VFS layer would do fine.
2. Program loader, which extract the program into address space, do relocation, etc. Consult the ELF document(or executable format of your choice) for detail.
3. You're done here.
1.I have implement interrupt mechanism, but just print which interrupt has happend.
2.i use 0x80 as the syscall vector, i just set the privilege as 3 and type trap gate, i wonder whether this can work.
3.i can not understand exactly.
4.i think the instructions are push several registers and iret.But several problems confuse me.
a.i use page,i wonder whether should i set LDT? i see some codes do that.but i think there is no need.
b.i want to use the kernel code as the first process's code.how to set the eip?
c.how to set a TSS.which part of TSS should i set? i just set ss0,sp0,can this work?
Thanks again.
Re: how to create the first user process?
thanks.Combuster wrote:If you can make a kernel thread, the only thing it needs to do to land in userspace is to build a custom stackframe containing eip/cs/eflags/esp/ss and IRET to it. The intel manuals should help you out from there.
Re: how to create the first user process?
It's better to plan the address space layout in early stage, basically you just slice the whole address space into zones, for example:ckzippo wrote: > 3. plan the address layout
3.i can not understand exactly.
3-4G Kernel
2-3G Global Resources, Drivers
0-2G Applications:
* 2G-32M ~ 2G: Process specific information, handle mappings
* 2G-64M ~ 2G-32M: Default stack
* 4M and Up: Application
LDT is optional, and it's generally not use for flat modelckzippo wrote:4.i think the instructions are push several registers and iret.But several problems confuse me.
a.i use page,i wonder whether should i set LDT? i see some codes do that.but i think there is no need.
1. Set DS/ES/FS/GS to data selector +3ckzippo wrote:b.i want to use the kernel code as the first process's code.how to set the eip?
2. push value of new SS(data selctor+3)
3. push application stack (new value of esp)
4. push new value of flags (e.g. 0x202 to enable interrupts)
5. push new value of CS (code selector +3)
6. push new value of EIP
7. IRETD
For 32-bit TSS, you only need to set SS0 and ESP0 (which refer to kernel stack, it can be different per each user thread, search kernel-stack per thread vs per core for more), and optionally IOPLckzippo wrote:c.how to set a TSS.which part of TSS should i set? i just set ss0,sp0,can this work?