Category : Assembly Language Source Code
Archive   : PROTEC.ZIP
Filename : EN.DOC

Output of file : EN.DOC contained in archive : PROTEC.ZIP

EN.EXE is a fun and games program that illustrates how to enter protected
mode, type 19 lines in protected mode using a KISS mini-keyboard decoder,
offers 12 each HELP choices via the F1 through F12 keys, and most importantly
allows the user to near instantly go to REAL MODE's EDMOD.OBJ program via the
Ctrl key.

º This modified program uses a KISS mini- º
º keyboard decode routine. º
º º
º Enter beginning next line down º
º backspace erases & moves back a byte º
º arrow keys PgUp PgDn Home are active º
º Alt+C or c cls all inside rectangle º
º Alt+keypad 3 digits for 0-255 ASCII º
º F2 displays all pages EN.DOC º
º F3 segments size and addresses º
º F4 EDMOD.OBJ typical page º
º F5 speed up/slow down keyboard º
º F6 Print Screen subroutine º
º F7 Pentium protected exceptionsº
º F8 display all CS DS ES FS GS º
º F9 set FS/GS seg to 0000h-F000hº
º F10 diz control-debug-flag regs º
º F11 shift F1 thru shift F12 menuº
º F12 Interrupt Descriptor Table º
º Ctrl go Edmod - Del ret protectedº
º Please read EN.DOC in C:\PROTECT º

EDMOD.OBJ is an `olde` (circa 1977 though frequently updated) program that
allows the user to edit/modify any/all ram memory in real mode, plus displays
the disassembled instruction on the lower left bottom of the video display (you MUST know where the instruction begins to disassemble it correctly).

You may switch back to PROTECTED MODE near instantly while in EDMOD.OBJ by
pressing the Del key. Please write down these directions.

You may switch to the DOS> prompt any time in either program by pressing the
Esc key.

EN.ASM, the source code file for EN.EXE is rather well commented and should
explain the fundamentals of what is going on after the STRUCT and MACRO files
are executed.

Use the enclosed EDLIN.COM to read all of them. It is an updated version that
will read and write 33% larger files in DOS 4.0, DOS 5.0 and DOS 6.0 than the
standard versions.

The STRUCT and MACRO1 through MACRO4 explanations follow:

STRUCT: defines the structure of the descriptions (descp) + page tables + old
IP and CS values.

MACRO1: defines the stack in the Task State Segment (TSS), + CR3 in TSS +
general registers in TSS + segment registers in TSS + plus CALL FAR & JMP FAR.
(note: EN.EXE does NOT switch tasks so the TSS is not used, but is included
for general info).

MACRO2: steps 0, 1, 2, 3, 4 which defines the General Descriptor Table (GDT),
Interrupt Descriptor Table (IDT), limits, + initializes the segment base
address for each segment decriptor.

MACRO3: step 5 defines all of the DS segment including messages, mini-keyboard
decoder and Help pages.

MACRO4: steps 6, 7, 8 defines pivilege level 0, 1, 2 stack segments, + set up
task state segment, + define a dummy segment to define old real mode segment
registers, + CR0 register value.

Code Segment - Step 8A:

Most all Intel 80386, 80486 and Pentium microprocessor programs are
initialized in real mode. Since this demo program illustrates how to switch
back and forth between real mode and protected mode, it must tell the real
mode program, EDMOD.OBJ that is loaded high to segment 9000h:8000h its code
segment so that EDMOD.OBJ knows where to return. The st_art lines do just
that by stuffing its code segment down into low memory at 0000h:0300h plus
telling EDMOD.OBJ it is a .EXE program rather than .COM program by loading an
'E' into 0000:0382h.

Step 8B - save or restore `typed.dat` from C:\PROTECT:

This is a simple routine that allows the user to save or restore the second
welcome page that is displayed only ONCE on program initialization. If you
save it as a blank page via Alt + C then the shift F2 key, it will display a
blank page after the first welcome page is displayed the next time you run
EN.EXE. Alternately, you may type in anything you wish and save it via the
shift F2 key and it will be displayed after the first welcome page when you
run EN.EXE the next time.

Steps 9, 10 and 11:

Initialize the interrupt descriptor table, get the general descriptor table
(GDT) and interrupt descriptor table (IDT) limits & linear address, and set
the linear base address for each corressponding descriptor.

Step 12 - switch to protected mode:

Clear interrupts, load global descriptor table (GDT) and limit into global
descriptor table register (GDTR), load interrupt descriptor table (IDT) and
limit into interrupt descriptor table register (IDTR), and set register CR0 to
protected mode enable. Then, a far jump to enter_prot flushes the instruction
queue and the program is in protected mode.

Step 13 - set LDTR, SS, SP, DS, ES, FS, GS:

The local descriptor table register (LDTR) is not used in this program so it
is set to a null value and segment register SS, stack pointer, segment
registers DS, ES, FS and GS set to new protected mode values.

Steps 14 - 14A display message and keyboard input decode in protected mode:

Since protected mode does not allow the use of real mode interrupts, every
familiar function/interrupt that you are accustomed to in real mode that you
wish to use must be created. Step 14A after label bb0 calls kybd1 in
approximately line 510 where all the protected mode keyboard input functions
are executed (approximately lines 510 through line 2027).

Rather than reinvent the wheel by rewriting every interrupt function desired,
EN.EXE does some fancy footwork when a number of functions are desired. What
it does is to near instantly exit protected mode, perform the function in real
mode, and then near instantly return to protected mode doing exactly what is
was doing when it departed.

Shift F11 will display HELP 11, the SHIFT + F1 thru F5 functions. Shift + F5
is an interesting option. When pressed, it displays a VGA graphics page we
use in one of our IBM touchscreen information system programs. In this case
it is one of the 4 Welcome pages used in our Ford Scientific Research Center
program. Any key pressed after displaying the page will near instantly return
you to protected mode.

Exit protected mode - go to EDMOD.OBJ in real mode - return to protected mod:

In protected mode the Ctrl (control) key is used to switch to EDMOD.OBJ in
real mode. Here is the sequence after the Ctrl key is pressed (line numbers
are approximate).

line 608: senses the Ctrl key (al,29) and jumps go_edmod in line 1909.
line 1909: sets bp,3 - calls stor_video - and jumps to ky9b in line 701.
line 701: displays 'Now in real mode' and jumps to bb4 in line 261.
line 261: is part of Step 15. Steps 15 to 22 are exit protected mode.
line 365: senses bp,3 so jumps to ed_mod in line 389.
line 389: on up first checks 9000h:8000h for e9h = jmp byte.
if NOT there it loads EDMOD.OBJ to 9000h:8000h and jmps 9000h:8001h
if there it immediately jmps 9000h;8011h.

Now we are in EDMOD in real mode. Press F7 to read EDMOD.DOC. The F1 key
displays an index of the help options.

º F1 key: EDMOD.OBJ - HELP º
º EDIT MODE (green) º
º Esc key DOS> prompt or Windows º
º Shift F1 ret ur pgm if 0000:0300 set º
º F6 key display any directory º
º D key decimal to hex converter º
º H key hex to decimal converter º
º S key global search ASCII/hex º
º F8 key using the KISS disassembler º
º F9 key zeros out entire segment º
º F10 key zeros out displayed page º
º note: will not zero BIOS or EDMOD º
º MODIFY MODE (yellow) º
º ASCII key modifies mem beneath cursor º
º F2 key toggles back to EDIT MODE º
º F3 key input hex beneath cursor º
º keypad directions keys active º
º MODIFY MODE (red) if in BIOS or EDMOD º
º press F7 to display EDMOD.DOC º

Since we came from protected mode, NOT all of EDMOD's 'save the newcomer from
fouling up the program' functions are available. Yes, you can edit/modify
most all of memory including EN.EXE's DS and CS segments which will prevent
you returning to it, plus the BIOS areas in segment 0000h and maybe segment
1000h which will lockup the program. If you do, about the worst that can
happen is that you will have to restart with a cold boot. To the best of our
knowledge it will not harm any variety of computer.

EDMOD is also a fun & games program. It is NOT a replacement for debug or a
first class disassembler, though if you know where an instruction begins, the
keypad + key will probably disassemble it correctly. The Pentium disassembler
function is about 66% complete and should be finished by Christmas 1993.
A typical EDMOD page is illustrated below.

Edit/Modify 1024K Mem and Kiss Disassembler copyright 1977-1993 REAL
(c) R. Richardson 0123456789ABCDEF Pentium alpha 1.0 MODE
BEGIN º 0000000000000000000000000000000000000000000000000000000000000 º DSseg
0000 º 0000000000000000000000000000000000000000000000000000000000000 º 8000
º 0000000000000000000000000000000000000000000000000000000000000 º
MEMORY º 0000000000000000000 do not use mouse if 0000000000000000000 º CSseg
0000 º 0000000000000000000 from protected mode 0000000000000000000 º 9000
º 0000000000000000000000000000000000000000000000000000000000000 º
VALUE º 0000000000000000000 each page displays 0000000000000000000 º ESseg
0000 º 0000000000000000000 1024 bytes of memory 0000000000000000000 º B800
º 0000000000000000000 in ASCII & extended 0000000000000000000 º
EDIT º 0000000000000000000 ASCII 0000000000000000000 º SSseg
MODE º 0000000000000000000000000000000000000000000000000000000000000 º 9000
º 0000000000000000000 zero values are 0000000000000000000 º
DISAS- º 0000000000000000000 displayed as ASCII 0 0000000000000000000 º SP
SEMBLY º 0000000000000000000000000000000000000000000000000000000000000 º FCF6
º 0000000000000000000000000000000000000000000000000000000000000 º
HEX º 0000000000000000000000000000000000000000000000000000000000000 º END
º : Up 1024 bytes º : Move cursor º
ADD º : Down 1024 bytes º : <- ^ v -> º F1
[Bx+Si]º : Toggle modify mode º : Change Seg 0 - F º Help
AL º : Hex modify º : Disassemble Memoryº

Exit EDMOD.OBJ and return to ENE.EXE in protected mode:

In either EDMOD's edit or modify mode, pressing the Del (delete) key will
return you to protected mode with everything exactly the same as you left it.
This commences the following sequence:

EDMOD tests 0000:0300h for zero. If so it beeps (nothing there, so ignore).
If not zero it saves ENE.EXE's code segment and then tests 0000:0382h for 'E'
denoting an .EXE file. If so it then jumps far to ENE.EXE's code segment plus
20H which is located in the 15 each nops at line 39 and is part of Step 8A.

It then continues through Steps 9, 10, 11, 12, 13 and 14 re-entering protected
mode. Since hold_video is not zero it calls rstor_video and uses sav_line and
savdi to restore the cursor to its previous position. Everything now is as it
was before.

Pressing the Esc key in EDMOD will return you to the DOS> prompt. Pressing
the Esc key in protected mode will return to real mode and give you the choice

Press N to go to the DOS> prompt
Press Y to go to EDMOD
Press enter to return to protected mode


The little program, GOEDMOD.COM in C:\PROTECT will load EDMOD.OBJ to
9000h:8000h from the DOS> command line and then jump far to it. GOEDMOD.COM
may be on any drive in any subdirectory as long as EDMOD.OBJ is in the same one.

Previous loading of EDMOD.OBJ has no effect since upon return to the DOS>
prompt, DOS 6.0's COMMAND.COM reloads itself into the 9000h:8000h region. The
portion of DOS 6.0's COMMAND.COM that is loaded to 9000h:8000h is at its
offset 21,804.


EN.EXE is strictly a demo of how to enter protected mode, exit protected mode,
re-enter protected mode, and go to and from EDMOD in real mode. Since it uses
'para public use16' one cannot use the 80386, 80486 or Pentium's fabulous
ability of addressing up to 4 gigabytes of space with a single fell swoop.
Unfortunately the 'use16' and most all the protected mode initialization
routines limit segments to 64k.

Most programmers will admit that using the LIM (Lotus-Intel-Microsoft) 4.0
extended memory 64k page swapping scheme to use a single segment of extended
memory at a time is downtown crudesville, yet it has worked for years and is
used in countless successful programs.

As an obvious matter of fact, getting into and out of protected mode is not
exactly simplicity itself.....yet when one becomes accustomed to the new rules
of the protected mode game, it is not all that difficult.

HUGE.EXE and HUGE.ASM will shortly introduce the 'para public use32' version
of EN.EXE and EN.ASM in protected mode that will be able to address huge seg-
ments of memory far larger than 1024k. Many of the protected mode initial-
ization routines are being rewritten to accomodate the huge segmentation.

Special thanks go to 'i386/i486 Advanced Programming' author, Shirley Her with
Nexgen Microsystems in Silicon Valley (San Jose), California for all her aid,
guidance and superior programming skills that made ENE.EXE possible. Those
who were of assistance to Shirley Her while writing the book include:

Sen-Cuo Ro - coauthor 'i386/i486 Advanced Programming' - Nexgen Taiwan
Rajvir Singh - Automata Publishing
Avatar Saini - Intel
Jay Sethuram - Intel
Hal Broome - Sun Microsystems
Steve Thomas - Intergraph
Deepak Verma - VLSI Technology


Press the Alt key and then the far right on the keyboard keypad's number
desired THREE times; i.e., to display 1, press 0 then 0 then 1. To display 2,
press 0 then 0 then 2. THREE numbers must always be pressed.

- end -

  3 Responses to “Category : Assembly Language Source Code
Archive   : PROTEC.ZIP
Filename : EN.DOC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: