[Ques] Dynamic Linking & Loading
Posted: Thu Jan 18, 2007 1:50 am
I just wanted to know how does Operating Systems load executable files in the memory and transfer control to them and when finished get back the control?
The Place to Start for Operating System Developers
http://f.osdev.org/
The whole thing is about jumping far to another location |which changes the CS register|. Loading a file into the memory isn't complicated, but you have to write file system and disk io code. For example, most people (like me) write a boot loader code to load their kernels and stuff into the memory.Snake wrote:I just wanted to know how does Operating Systems load executable files in the memory and transfer control to them and when finished get back the control?
Most commercial OSs use paging and multi tasking. They create a new address space for the process, load the executable image and set up the page tables for the new process. After that, they create a new task and call itIs this the way many commercial OS manages the child processes
Code: Select all
push es
mov ax,0x0050
mov es,ax
mov bx,0
mov bx,llBuff ; the address of the location to load to
mov ax,40 ; sector to read from
call readsect ; read it
push ds ; save data segment
call word 0x0050:0x0000 ; jumps to the place we just loaded it to
pop ds ; restore data segment
pop es
Code: Select all
; ES:BX = Locationto load to, AX = Sector
readsect:
mov si,[bsTrackSect]
div si ; divide logical sect by track size
inc dl ; sector # begins at 1
mov [bsReserv],dl ; sector to read
xor dx,dx ; logical track left in ax
div word [bsHeadCnt] ; leaves head in dl, cyl in ax
mov dh, [bsBootDrv] ;
xchg dl,dh ; head to dh, drive to dl
mov cx,ax ; cyl to cx
xchg cl,ch ; low 8 bits of cyl to ch, hi 2 bits
shl cl,6 ; shifted to bits 6 and 7
or cl, byte [bsReserv] ; or with sector number
mov al,1 ; number of sectors
mov ah,2 ; use read function of int 0x13
int 0x13 ; read sector
jc rsfail ; display error message
jmp readcomplete ; skip error handler
rsfail: ; error handler, print msg
mov si,llReadFail
call putstr
readcomplete:
ret ; return to caller