Professional Documents
Culture Documents
Introduction to 80386
Digital Systems
eg. Computer
Sub Systems
eg. Processor, IC’s
R. V. Bidwe, PICT,Pune. 16
R. V. Bidwe, PICT,Pune. 17
Evolution of Computers
• This led to
microcomputers-
computers on a desk.
– Artificial Intelligence
– Voice Recognition
– Parallel Processing
8080 1974 8 16 64 KB
1M
8086/88 1978 16/8 20
1M
80186/188 1982 16/8 20
16M:Clock speed is
80286 1983 16 24
high
DX (1986:not
DX:4G (275,000
compatibility) DX:32+132 pin 32
80386 transistor)
SX (1988: mostly used, SX:16+100 pin 24
SX:16MB
Not Co-Processor)
Memory Size: 4G
80486 32 32
+16K cache
R. V. Bidwe, PICT, Pune. 50
80286 vs 80386 vs 80486
R. V. Bidwe, PICT,Pune. 53
• Pipelining:-8086 uses two stage of pipelining.
First is Fetch Stage and the second is Execute
Stage.
– Fetch stage that prefetch upto 6 bytes of
instructions stores them in the queue.
– Execute stage that executes these instructions.
R. V. Bidwe, PICT,Pune. 54
• Operates in two modes:-8086 operates in two
modes:
– Minimum Mode: A system with only one
microprocessor.
– Maximum Mode: A system with multiprocessor.
R. V. Bidwe, PICT,Pune. 55
• Multiplication And Division:-8086 has a
powerful instruction set. So that it supports
Multiply and Divide operation.
R. V. Bidwe, PICT,Pune. 56
Architecture of 8086
2. DS = 3333 H
• The base address of the data segment is 33330 H.
• Effective address of memory is given by 33330H +
0020H = 33350H.
3. SS = 2526 H
• The base address of the stack segment is 25260 H.
• Effective address of memory is given by 25260H +
1100H = 26360H.
R. V. Bidwe, PICT, Pune. 80
Section .text
Exit:
Global Main Add:
---
---
Main: ----
----
---
---
---
;Menu ---
ret
1. ADD
2. Sub Sub:
3. Mul ---
----
4. DIV
---
5. Exit ---
ret
;If choice=1
Call Add Mul:
---
;If choice=2 ----
Call Sub ---
---
ret
R. V. Bidwe, PICT, Pune. 81
New in 80386
• Data bus = 32bit, all registers (except Segment) of
32 bit and Eflags is also of 32 bit.
• Address Bus = 32 bit. (4 GB Memory)
• Enhanced Memory Management Unit.
• Supports Virtual addressing.
• Faster execution of arithmetic operations.
• Works in :-
1. Real Mode (8086)
2. Protected Mode
3. Virtual 8086 Mode
• Additional Interrupts in IVT.
R. V. Bidwe, PICT, Pune. 82
FEATURES
• Manufactured using Intel’s complementary High-
performance Metal-oxide-semiconductor 3 process.
• 8 General Purpose Registers of 32-bit .
• 32-bit Address and Data Bus.
• Supports 8 bit,16 bit,32 bit data.
• Prefetch Queue of 16B.
• Very Large address space i.e VM of 64 TB and PM of
4GB.
• Supports Segmentation and Paging.
R. V. Bidwe, PICT, Pune. 83
• 4 levels of Protection.
• Uses 3-stage Pipelines.
• Supports Multitasking with Protection.
• On chip cache memory for TLB.
• Pipelined Instruction Execution.
• Memory Management unit.
• High speed numeric support via 80287 and 80387
coprocessor.
• It can operate in Real , Protected and Virtual 8086
mode.
• The data buffers interface the internal data bus with the
system bus.
• Byte (8-bit)
• Word (16-bit)
• Double word (32-bit)
• Quadword (64-bit)
• Ten bytes (80-bit)
24-Aug-18 Prof. R. V. Bidwe, PICT, Pune. 125
2. Data Types
1. Definition directives
• db (define byte)
• dw (define word)
• dd (define double word)
• dq (define quad word)
• dt (define ten bytes)
2. Declaration directives
• resb (reserve byte)
• resw (reserve word)
• resd (reserve double word)
• resq (reserve quad word)
24-Aug-18 Prof. R. V. Bidwe, PICT, Pune. 126
3. Memory addressing directives
• byte
• word
• dword
• qword
10000009 h 12 10000009 h FE
10000008 h 34 10000008 h CD
10000007 h 56 10000007 h 5C
10000006 h 78 10000006 h A9
10000005 h A9 10000005 h 78
10000004 h 5C 10000004 h 56
10000003 h CD 10000003 h 34
10000002 h FE 10000002 h 12
10000001 h 10000001 h
10000000 h 10000000 h
Qnumber
24-Aug-18 dq 12345678A95CCDFE
Prof. R. V.hBidwe, PICT, Pune. 129
Memory addressing Memory location Data
1000000A h
section .data 10000009 h 98
num: dq 9828919849096878h 10000008 h 28
section .bss
10000007 h 91
name: resb 8
10000006 h 98
Memory addressing: 10000005 h 49
mov al, byte[num] ; al = 78 10000004 h
mov ax , word [num] ; ax = 6878
09
10000003 h 68
mov eax , dword [num] ; eax = 49096878
mov rax , qword [num] 10000002 h 78
; rax = 9828919849096878 10000001 h
10000000 h
• Multiplication Instructions
• Division Instructions
• The ZF flag is set if the entire word is zero (no set bits are
found); ZF is cleared if a one-bit is found. If no set bit is
found, the value of the destination register is undefined.
• Software-Generated Interrupts
• LEAVE
JMP far
CALL far
RET far
LDS
LES
LFS
LGS
LSS
• No-Operation Instruction
• Translate Instruction
EFLAGS = 00000002 H
IP = 0000FFF0 H
CS selector = 0000 H
DS selector = 0000 H
ES selector = 0000 H
SS selector = 0000 H
FS selector = 0000 H
GS selector = 0000 H
IDTR:
Base =0
Limit = 03FF H
• GND:
• System Registers
• Control Registers
• Debug Registers
• Test Registers
R. V. Bidwe, PICT, Pune. 27
Flag Registers
PE (Protection Enable):
Is set to select the Protected Mode of
operation for the 80386.It may also cleared to
reenter the real mode.
BS:
If set the debug interrupt was caused by the TF
bit in the flag register.
BD:
If set the debug interrupt was caused by an
attempt to read the debug register with the GD
bit set.
The GD bit protects access to the debug registers.
R. V. Bidwe, PICT, Pune. 42
B3-B0:
Indicate which of the 4 debug breakpoints
addresses caused the debug interrupt.
LEN:
Defines the size of access at the breakpoint
address as 00(byte), 01(word), 10(Currently Not
Used) or 11 (double word).
RW:
Selects the cause of action that that enabled
breakpoint address as 00 (instruction
access),01(data write), 10(Currently Not Used),
11(data read n write).
R. V. Bidwe, PICT, Pune. 43
• The low-order eight bits of DR7 (L0 - L3 and G0 - G3)
selectively enable the four address breakpoint conditions.
There are two levels of enabling: the local (L0 through L3)
and global (G0 through G3) levels.
• The local enable bits are automatically reset by the
processor at every task switch to avoid unwanted
breakpoint conditions in the new task. The global enable
bits are not reset by a task switch; therefore, they can be
used for conditions that are global to all tasks.
S (Segment Descriptor) :
When set, indicate that the segment is a
system segment. When clear, the segment is a
code or data segment.
19
Type field
E (Executable):
Executable selects a stack segment (E=0) or a
code segment (E=1) .E also defines the function
of the next two bits.
X (Expansion):
If E=0,then X indicates the direction of expansion
for the data segment . If X=0,the segment expand
upward , as in a data segment.
The B bit controls the size of the stack pointer register. If B=1,
ESP will be used to point stack. And If B=0, SP will be used to
point stack.
R. V. Bidwe, PICT, Pune. 34
Page Translation
– Demand Paging
– Swapping
– Virtual Memory / Virtualization
2. Allocating Memory
i. IN ── Input
ii. OUT ── Output
iii. INS ── Input String
iv. OUTS ── Output String
6. Interrupt control:
i. CLI ── Clear Interrupt-Enable Flag
ii. STI ── Set Interrupt-Enable Flag
iii. LIDT ── Load IDT Register
iv. SIDT ── Store IDT Register
8. TLB testing:
i. MOV ── Move to and from test registers
9. System Control:
i. SMSW ── Set MSW
ii. LMSW ── Load MSW
iii. HLT ── Halt Processor
iv. MOV ── Move to and from control registers
R. V. Bidwe, PICT, Pune. 65
UNIT 4
Protection
Why Protection?
• The purpose of the protection features of the
80386 is to help detect and identify bugs
(Unauthorized accesses).
1. Type checking
2. Limit checking
3. Restriction of addressable domain
4. Restriction of procedure entry points
5. Restriction of instruction set
• And also, the DPL and RPL must equal the CPL.
3. ESP is pushed.
● Call gates
● Trap gates
● Interrupt gates
● Task gates
2. Type checking.
GP = General
protection fault
TS = Invalid TSS
SF = Stack fault
Validity tests of a
selector checks
whether selector
referring to the
proper
Table or not (eg.,
the LDT selector
refers to the GDT).
R. V. Bidwe, PICT, Pune. 21
Task Linking
• The back-link field of the TSS and the NT (nested
task) bit of the flag work together allow the
80386 to automatically return to a task that
CALLed another task or was interrupted by
another task.
● A V86 Monitor.
● Operating-system services.
1. Interrupts
– Maskable interrupts, which are signalled via the INTR
pin.
– Nonmaskable interrupts, which are signalled via the
NMI (Non-Maskable Interrupt) pin.
2. Exceptions
– Processor detected. These are further classified as
Faults, Traps and Aborts.
– Programmed. The instructions INT 0, INT 3, INT n, and
BOUND can trigger exceptions. These instructions are
often called "Software Interrupts", but the processor
handles them as exceptions.
R. V. Bidwe, PICT, Pune. 3
Identifying Interrupts
• Each different type of interrupt or exception
have given a unique identification number.
MOV SS, AX
MOV ESP, StackTop
– Task gates
– Interrupt gates
– Trap gates
Description
SGDT/SIDT copies the contents of the descriptor table register the six bytes of memory
indicated by the operand. The LIMIT field of the register is assigned to the first word at
the effective address. If the operand-size attribute is 32 bits, the next three bytes are
assigned the BASE field of the register, and the fourth byte is written with zero. The last
byte is undefined. Otherwise, if the operand-size attribute is 16 bits, the next four bytes
are assigned the 32-bit BASE field of the register.
SGDT and SIDT are used only in operating system software; they are not used in
application programs.
Description
SLDT stores the Local Descriptor Table Register (LDTR) in the two-byte register or
memory location indicated by the effective address operand. This register is a selector
that points into the Global Descriptor Table.
SLDT is used only in operating system software. It is not used in application programs.
Description
SMSW stores the machine status word (part of CR0) in the two-byte register or memory
location indicated by the effective address operand.
Description
The LGDT and LIDT instructions load a linear base address and limit value from a six-
byte data operand in memory into the GDTR or IDTR, respectively. If a 16-bit operand is
used with LGDT or LIDT, the register is loaded with a 16-bit limit and a 24-bit base, and
the high-order eight bits of the six-byte data operand are not used. If a 32-bit operand is
used, a 16-bit limit and a 32-bit base is loaded; the high-order eight bits of the six-byte
operand are used as high-order base address bits.
The SGDT and SIDT instructions always store into all 48 bits of the six-byte data
operand. With the 80286, the upper eight bits are undefined after SGDT or SIDT is
executed. With the 80386, the upper eight bits are written with the high-order eight
address bits, for both a 16-bit operand and a 32-bit operand. If LGDT or LIDT is used
with a 16-bit operand to load the register stored by SGDT or SIDT, the upper eight bits
are stored as zeros.
LGDT and LIDT appear in operating system software; they are not used in application
programs. They are the only instructions that directly load a linear address (i.e., not a
segment relative address) in 80386 Protected Mode.
Description
LLDT loads the Local Descriptor Table register (LDTR). The word operand (memory or
register) to LLDT should contain a selector to the Global Descriptor Table (GDT). The
GDT entry should be a Local Descriptor Table. If so, then the LDTR is loaded from the
entry. The descriptor registers DS, ES, SS, FS, GS, and CS are not affected. The LDT
field in the task state segment does not change.
The selector operand can be 0; if so, the LDTR is marked invalid. All descriptor
references (except by the LAR, VERR, VERW or LSL instructions) cause a #GP fault.
Description
LMSW loads the machine status word (part of CR0) from the source operand. This
instruction can be used to switch to Protected Mode; if so, it must be followed by an
intrasegment jump to flush the instruction queue. LMSW will not switch back to Real
Address Mode.
LMSW is used only in operating system software. It is not used in application programs.
Description Loads the source operand into the segment selector field of the task register.
Description Stores the segment selector field of the task register to operand.