Download presentation
Presentation is loading. Please wait.
1
Project 2 Roadmap
2
Segmentation Review Intel docs, fig. 3-1 and 3-5
3
Spawn() Starts a user program in src/geekos/user.c triggered by SYS_SPAWN Read_Fully() read an executable file from disk into memory Parse_ELF_Executable() fill Exe_Format data structure; (Project 1) ignore the bogus program headers (size=0) Load_User_Program() will set up the memory image for the new process and create a User_Context with the loaded program Start_User_Thread() with the new User_Context
4
Load_User_Program() Prepares a new address space for the program and creates a User_Context in src/geekos/userseg.c allocate the memory image of the new process find highest virtual address: scan Exe_Format find args size: Get_Argument_Block_Size() this is not sizeof(Argument_Block) ! size = Round_Up_To_Page(highest virtual address) + DEFAULT_USER_STACK_SIZE + args size create the User_Context… Fill in remaining User_Context fields
5
Create_User_Context() Allocates space for a User_Context, fill in its fields. User_Context stores all the information needed to setup and run a user thread in src/geekos/userseg.c create an LDT for the process add a descriptor to the GDT that describes the location of the LDT create a selector that contains the location of the LDT descriptor within the GDT create descriptors for the code and data segments of the user program and add these descriptors to the LDT create selectors that contain the locations of the two descriptors within the LDT
6
LDT descriptor GDT struct Segment_Descriptor ldt[0] char * program int programSize int stackAddr ushort_t dsSelector ushort_t csSelector ushort_t ldtSelector struct Segment_Descriptor *ldtDescriptor struct Segment_Descriptor ldt[1] User_Context Selector Init_LDT_Descriptor() Initialize the LDT descriptor in GDT with the location of the LDT 3 Selector() Create selectors that contain the locations of the two descriptors within the LDT 6 Init_Code_Segment_Descriptor()/ Init_Data_Segment_Descriptor Initialize the descriptors in LDT as code/data descriptors 5 Selector() Create a selector that contains the location of the LDT descriptor within the GDT 4 Allocate_Segment_Descriptor() Allocate an LDT descriptor in the GDT for the process 2 Malloc() Create an User_Context structure; it will store all the information that will be needed to setup and run the user thread 1 1 34 5 5 6 2 Create_User_Context() 4 6 6
7
Start_User_Thread Create a thread, setup the stack to look as if it was interrupted, make it runnable. in src/geekos/kthread.c Create_Thread() call Setup_User_Thread() which will push values (specified in description) Look at Setup_Kernel_Thread() for similar code Make_Runnable_Atomic()
8
Command Line Arguments In Load_User_Program(), create an Argument_Block data structure and attach it to the process image. This data structure contains the argc and argv arguments that are passed to the main() function of the user program Get #of bytes and argc from Get_Argument_Block_Size() Call Format_Argument_Block() to build Argument_Block data structure in user memory fix argv up (make all user space pointers)
9
System Calls INT90 put args in registers on user side recover them on kernel side call Sys_xxx accordingly return result/error code Use g_CurrentThread to get info about current thread
10
Sys_Null Just add a print statement in syscall.c Your first test for user mode: spawn /c/null.exe
11
Sys_Exit simple call to Exit() but funs called from Exit() must clean up the thread Free_Segment_Descriptor Free userContext, memory space allocated for the program
12
Sys_PrintString Copy_From_User() the string Put_Buf()
13
Sys_GetKey Wait_For_Key() the shell takes care of the rest see libc/conio.c
14
Sys_SetAttr/Sys_GetCursor/Sys_PutCursor straightforward calls to name-similar kernel funs Sys_GetCursor() requires a Copy_To_User() !
15
Sys_Spawn Calls Spawn() Command needs a Copy_From_User() !
16
Sys_Wait Wait for specified PID Use Join()
17
Sys_GetPID just return current thread’s PID
18
Copy_From_User/Copy_To_User Caller allocates space ( dstInKernel ) Validate memory pointer is within bounds? convert If yes copy Make generic, not specific to strings Ensure proper ‘\0’ termination for SYS_PRINTSTRING and SYS_SPAWN
19
LDT descriptor GDT struct Segment_Descriptor ldt[0]... ushort_t dsSelector ushort_t csSelector ushort_t ldtSelector struct Segment_Descriptor *ldtDescriptor struct Segment_Descriptor ldt[1] User_Context ldtSelector...
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.