03 Boot
03 Boot
• For backward
compatibility, PC
boots in 16-bit mode
OS OS
• Bootloader copies OS
0x00100000 eip 0x00100000 image starting from
BIOS ROM BIOS ROM disk sector 1 to
0x000F0000 0x000F0000
0x100000 and transfers
control to it
VGA display
0x000C0000
VGA display
0x000C0000
• We need to tell gcc that
0x000A0000 0x000A0000
image will be loaded at
eip Bootloader
0x00007C00
Bootloader
0x00007C00
0x100000
Backward compatibility
push, pop
#include <stdio.h>
• p points to (0x5555 << 4) + 0x0005
int foo() { = 0x55555
char far *p =(char far *)0x55550005;
char far *q =(char far *)0x53332225; • q points to (0x5333 << 4) + 0x2225
*p = 80; = 0x55555
(*p)++;
printf("%d",*q);
return 0; • Multiple ways of referencing same
} address making them awkward to
control
Outputs 81
Segment registers in 32-bit
• 32-bit registers can point to 2^32 (=4GB) memory.
• “Protected mode”: extend segment registers for protection
… … … …
… … … …
• Segment descriptor:
• 32 bit base
• 20 bit limit
• If G=1,
granularity=4KB.
• Max memory
within 1 segment
= 2^20*2^12 =
4GB
Segmented memory model
• Stack cannot grow into code section
Multi-segment
model 23
esp
• Best protection
• Difficult to program
addl $1 (%ecx)
42
Does not add 1 to the ecx
value at top of the
stack!
Flat memory model
• Easier to program
• Used by xv6