Loading and Linking

Module 10 and starting with Lecture slides 20

Loaders

Pseudo-code of a simple OS and loader:

operating system ver. 1.0
repeat:
p <- next program to run
loader(p)
jalr $0
beq $0, $0, repeat

loader ver. 1.0
for(i=0; i<codeLength; ++i){
	MEM[4i] = file[i];
}

Not necessarily starting at address 0x00.

operating system ver. 2.0
repeat:
p <-- choose program to run
$3 <-- loader(p)
jalr $3
beq $0, $0, repeat

Now loader returns a value compared to version 1. Is the starting address of the program that was just loaded. The OS then jumps to that address.

loader ver. 2.0
alpha <-- findFreeRAM(N)
for(i=0; i<codeLength; ++i){
mem[alpha+4i] = file[i];
$30 <-- alpha + N
return alpha to OS
}

N represents the amount of memory the loader decides to allocate to the program. This memory includes memory needed for the instructions in the program and memory for the stack and heap.

Difference between loader v1 and v2:

MERL Format

  • Header:
  • MIPS program:
  • Footer: contains relocation entries. Each relocation entry in the footer is made of two words. The first on is 1 indicating that this is a relocation entry. The next word is the address of a word that must be relocated.