31.01.2013 Views

using the bootstrap loader

using the bootstrap loader

using the bootstrap loader

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

WRITING A CUSTOM THIRD-STAGE DRIVER<br />

6.2 WHAT A THIRD-STAGE DEVICE DRIVER MUST CONTAIN<br />

6-2<br />

The third stage device driver, like <strong>the</strong> first stage, must contain a device initialization and a<br />

device read procedure. For <strong>the</strong> most part, <strong>the</strong>se procedures are similar to <strong>the</strong>ir first-stage<br />

counterparts. However, two differences exist.<br />

• Both procedures must be in <strong>the</strong> same code segment.<br />

• You must also create a PUBLIC symbol that contains a pointer to <strong>the</strong> device driver<br />

data segment. The third stage needs this information so it can create a descriptor for<br />

<strong>the</strong> data segment, enabling <strong>the</strong> driver to access <strong>the</strong> segment in protected mode.<br />

When developing code for your third stage driver, you must remember that <strong>the</strong> second<br />

stage always loads <strong>the</strong> third stage, including <strong>the</strong> drivers you write. The only type of code<br />

that <strong>the</strong> second stage can load is code that uses <strong>the</strong> 8086 object module format (OMF-86).<br />

Therefore, you must use 8086 tools (ASM86, PL/M-86, LINK86, etc.) to develop <strong>the</strong> thirdstage<br />

device initialization and read procedures. (<br />

Even though you use 8086 tools to develop your driver code, <strong>the</strong> resulting initialization and<br />

read procedures must be able to run in protected mode. One ramification of running in<br />

protected mode is that all long pointers produced by PL/M-86 (or by any o<strong>the</strong>r means)<br />

that were correct in real mode cause an ILLEGAL SELECTOR exception in protected<br />

mode. Therefore, if you must use long pointers, your device initialization and read<br />

procedure must determine if <strong>the</strong> processor is in protected mode. If protected mode is<br />

active, <strong>the</strong> procedure must replace all <strong>the</strong> selector portions of long pointers with a new<br />

selector that is valid in protected mode.<br />

You can determine <strong>the</strong> processor mode by <strong>using</strong> <strong>the</strong> following assembly code:<br />

DB OFH,OlH,OE3H ;Opcode for <strong>the</strong> ASM286 instruction<br />

;SMSW BX. You must use<br />

;DB OFH,OlH,OE3H because SMSW is an<br />

;ASM286 instruction unrecognized by<br />

;ASM86.<br />

AND BX, OlH ;Examine lowest bit of MSW to see if<br />

; CPU is running in PVAM.<br />

JZ REAL ;No, not running in PVAM .<br />

. code to override ;Yes, running in PVAM.<br />

selectors of<br />

. long pointers ;<br />

Bootstrap Loader<br />

i<br />

\,

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!