📄 cstart.htm
字号:
mov bp,sp ;use bp to acess passed parameters
push ax
push bx
push cx
push dx
push ds
mov ax,[bp+10] ;get segment addr of inregs
mov ds,ax
mov si,[bp+8] ;copy .h.. into cpu registers
mov ax,[si] ;ds:si
mov bx,[si+2]
mov cx,[si+4]
mov dx,[si+6]
mov di,[si+10]
mov si,[si+8]
cmp word ptr [bp+6],0010h
je short int10
cmp word ptr [bp+6],0016h
je short int16
mov ax,-1
jmp short exit
int10: int 10h
jmp short exit
int16: int 16h
jmp short exit
exit: push ax
mov ax,[bp+14] ;save regs in program model
mov ds,ax
pop ax
mov si,[bp+12]
mov [si],ax
mov [si+2],bx
mov [si+4],cx
mov [si+6],dx
mov [si+8],si
mov [si+10],di
jnc short ex2
mov word ptr [si+12],0001h ; carry flag set
jmp short ex3
ex2: mov word ptr [si+12],0000h ; clear carry flag
ex3: pop ds ;restore registers
pop dx
pop cx
pop bx
pop ax
pop bp
ret
_int86 endp
; char inportb( int port );
_inportb proc far
push bp ;acess local vars inside functions
mov bp,sp ;use bp to acess passed parameters
push dx
mov dx,[bp+6] ; get port address
xor ax,ax ; clear ax
in al, dx ; read from port into al register
mov ah, 00h ; ensure high byte of ax is cleared
pop dx
pop bp
ret
_inportb endp
; void outportb( int port, char value );
_outportb proc far
push bp ;acess local vars inside functions
mov bp,sp ;use bp to acess passed parameters
push dx
mov dx,[bp+6] ;get port address
mov al, byte ptr [bp+8]
out dx, al
pop dx
pop bp
ret
_outportb endp
CODE ends
end
</PRE>
<P>
The C program looks like,
<PRE>
<A HREF="sw/turboc/test.c">/* test.c */</A>
#include "crom.h"
union REGS regs;
void clear()
{
regs.h.ah = 15; /* get video mode */
int86( 0x10, &regs, &regs );
regs.h.ah = 0; /* set video mode */
int86( 0x10, &regs, &regs );
regs.x.dx = 0; /* set cursor */
regs.h.ah = 2;
int86( 0x10, &regs, &regs );
}
void writechar( char ch )
{
regs.h.ah = 14; /* write tty */
regs.h.bh = 0;
regs.h.al = ch;
int86( 0x10, &regs, &regs );
}
char readkey()
{
regs.h.ah = 0;
int86( 0x16, &regs, &regs );
return regs.h.al;
}
main()
{
char ch;
clear();
for( ; ; )
{
ch = readkey();
writechar( ch );
}
}
</PRE>
The sequence of commands necessary to generate the .EXE file is,
<PRE>
tasm /mx tcstart
tasm /mx tclib
tcc -a- -c -f- -G- -K -B -ml -M -N- -O- -r- -v- -y- -Z- -S -O- test
tlink /m tcstart test tclib, test, test
</PRE>
The configuration file <A HREF="sw/turboc/test.cfg">TEST.CFG</A> has the
following format,
<PRE>
dup DATA CONST
class CODE = 0xf600
class STACK = 0x1000
class DATA = 0x2000
order DATA DATAEND BSS BSSEND
order CODE CODEEND CONST
rom CODE CONST
</PRE>
Finally, the memory image for storage in EPROM is generated using the
LOCATE utility as follows,
<PRE>
locate test
hexbin2 test.hex test.bin i f600
</PRE>
<P>
<HR>
<B>GENERATING ROMCODE (IBM-PC/XT, F600:0000) USING INTEL iC86</B><BR>
There are only a few small changes required for doing the same test
under the INTEL compiler. The header file <A HREF="sw/intel/crom.h>CROM.H
</A> remains the same, as is the source file <A HREF="sw/intel/test.c">
TEST.C</A>
<P>
The library code, stored in <A HREF="sw/intel/clib.asm">CLIB.ASM</A>, is
altered slightly by removing the leading underscores from the function
names.
<P>
The sequence of commands necessary to generate the EPROM image is,
<PRE>
asm86 c86f600.asm
asm86 c86clib.asm
ic86 test.c LARGE
link86 c86f600.obj,test.obj,c86clib.obj to test.lnk nobind
loc86 test.lnk order(classes(stack,data,code)) &
>> order(segments(STACK,TEST_DATA,CODE,TEST_CODE)) &
>> ad(sm(stack(10000h),test_data(20000h),(code(0f6000h)))
oh86 test to test.hex
</PRE>
<P>
<HR>
<B>DESIGNING TURNKEY PC SYSTEMS</B><BR>
A turnkey system automatically executes when power is applied, thus
when the PC is turned on it will execute the system software
application without user intervention.
<P>
Examples of these are
<UL>
<LI>environmental controllers
<LI>security systems
<LI>data loggers etc
</UL>
<P>
The PC provides a low cost entry into turnkey systems. By adding
a memory board and software in EPROM, it can quickly take the place
of a custom developed system.
<P>
The TWO basic methods are,
<UL>
<LI>a large RAM DISK with battery backup, and boot the software from disk
<LI>a memory board and software in EPROM
</UL>
<P>
<HR>
<B>RAM DISK/FLOPPY BOOT</B><BR>
This has the advantage of very large programs. Software is easily
upgraded by issuing a new disk. It requires little extra hardware or
development tools.
<P>
<HR>
<B>MEMORY BOARD</B><BR>
This is needed for high risk systems, and where the software program
is relatively small. Such systems do not require a floppy disk, thus
are unaffected by smoke and dust, as well as accidental damage.
<P>
The PC, upon power-on, executes routines in the ROM BIOS chip. The
design of the computer allows the execution of programs stored in
external EPROM, examples being those stored on EGA and XT hard
disk controller cards.
<P>
The memory region C0000 - EFFFF was reserved for this purpose. The
ROM BIOS routine, upon power on, checks each 2k block for a special
signature byte (AA, 55), and, if found, executes the program stored
there. In the case of the EGA card, this would patch the existing
int 10h vector into its own code space, then return to the ROM BIOS
routine. An embedded system would not return.
<P>
Lets look at the change required to implement a turnkey system out
of our existing rommable code demonstration program we developed
earlier, residing at F600:0000. We shall use the ic86 compiler
to do this.
<P>
Below are the changes required to the c86start.asm file
<PRE>
<A HREF="sw/intel/c86d000.asm">; c86d000.asm for Intel Compiler</A>
name c86d000
extrn main : far
STACK segment para stack 'STACK'
public top
db 1024 dup ('STACK')
top label word
STACK ends
CODE segment byte public 'CODE'
public entry
assume cs:CODE, SS:STACK
db 55h
db 0aah
db 40h ;length of eprom /512
jmp entry
start proc far
entry: cli
mov ax, STACK
mov ss, ax
mov ax, offset top
mov sp, ax
sti
push ds
mov ax, 0040h ; set warm boot flag
mov ds, ax
mov si, 0072h
mov word ptr [si], 1234h
pop ds
cli
mov al, 80h ; enable NMI
out 0A0h, al
mov al, 0bch ; enable 8259 PIC
out 21h, al
sti
call main
jmp entry
start endp
CODE ends
end
</PRE>
NOTE the extra code required to enable the NMI (used by the parity
system) and enable the default IRQ's on the 8259 PIC.
<P>
We shall use a standard PC Prototype board, which has had a 27256
Eprom socket wire wrapped as a 32k block beginning at 0D0000h. This
board cost $120 and only took 30 minutes to wire-wrap and configure
for use.
<P>
The command sequence to generate the HEX file is,
<PRE>
asm86 c86d000.asm
asm86 c86clib.asm
ic86 test.c LARGE
link86 c86d000.obj,test.obj,c86clib.obj to test.lnk nobind
loc86 test.lnk order(classes(stack,data,code)) &
>> order(segments(STACK,TEST_DATA,CODE,TEST_CODE)) &
>> ad(sm(stack(10000h),test_data(20000h),code(0d0000h)))
oh86 test to test.hex
</PRE>
The code is generated then stored into EPROM. The memory board is
configured to 0d0000h and installed with the EPROM into the target
PC/XT. When the PC is turned on, it executes the self tests of CPU,
ROM and RAM in the ROM BIOS before checking for external EPROMS.
It will then find ours, and execute the code stored there.
<P>
<HR>
<B>STRUCTURE OF THE PC/XT ROM BIOS ROUTINES</B><BR>
The following information was gleamed by reading the IBM technical
reference manual (BIOS listing), as well as running SOURCER on a PC
compatible. SOURCER is a ROM disassembler.
<UL>
<LI>test hardware, CPU, ROM, RAM
<LI>initialize 8237 DMA, 8253 timer, 8259 PIC
<LI>find out attached equipment by reading sw1 on motherboard
<LI>test video system and memory
<LI>check eproms C0000 to C7fffh in 2k chunks
<LI>initialize video system
<LI>print boot message
<LI>test RAM
<LI>check keyboard, send init byte, check response
<LI>check eproms C8000 - F6000h
<LI>set warm boot flag
<LI>enable PIC
<LI>reset FDC
<LI>reset printer port
<LI>enable NMI
<LI>call int 19h, boot from disk
<LI>if unsuccessful, call int 16h, read key, then int 18h F600:0000
</UL>
<P>
In a turnkey system running in external space C8000-F6000, extra code
in the startup file is necessary to enable the NMI and the PIC, as
well as reset the warm boot flag used by the CTRL_ALT_DEL routine.
<P>
<HR>
<B>PC/XT SOURCE ROUTINES TO INITIALIZE THE MOTHERBOARD</B><BR>
<PRE>
;SETUP 8237 DMA CONTROLLER
mov al, 0ffh ; dmsa count 64k channel 0
out 1, al ; lsb
out 1, al ; msb
mov al, 58h ; set dma mode ch0 ready, auto int
out 0bh, al
mov al, 0 ; enable dma
out 8, al
out 0Ah, al ; set chn0 for refresh of RAM
;SETUP 8253 TIMER COUNTER CHIP
mov ax, 1254h
out 43h, al
xchg ah, al
out 41h, al
mov cx, 3
mov al, 41h
lp2: out 0bh, al
inc al
loop lp2
;SETUP 8259 PRIORITY INTERRUPT CONTROLLER
mov al, 13h ; ICW1-Edge, Single ICW4
out 20h, al
mov al, 8 ; ICW2 - int type 8-F
out 21h, al
inc al
out 21h, al ; ICW4 - buffered 8086 mode
mov al, 0bch ; enable default IRQ's
out 21h, al
</PRE>
<P>
<HR>
<B>A POOR MANS TURNKEY SYSTEM</B><BR>
This involves using floppy disk boot. The source file is compiled to
generate an .EXE file which is placed on a formatted DOS diskette.
A file called CONFIG.SYS is created, which has the following line
added to it,
<PRE>
SHELL=TEST.EXE
</PRE>
When the PC/XT boots, the file will be run instead of command.com,
the standard command-line DOS interface program. The advantages of
this system are,
<UL>
<LI>uses standard DOS libraries of TC or MSC
<LI>no startup code is required
<LI>no need for eproms or memory boards
<LI>software upgrades involve shipping a disk
<LI>the PC can still be used as normal for other work
<LI>the software program can be quite large (400k-500k)
</UL>
<P>
The DOS consists of two files, IO.SYS and MSDOS.SYS, which are loaded
when the computer boots from disk. Using standard libraries simplifies
design and coding, as well as allowing complicated software to be
written (menus, database etc)
<P>
<HR>
© Copyright Brian Brown, 1989-1995. All rights reserved.<BR>
<A HREF="default.htm"><IMG SRC="images/menu.gif" ALT="menu"></A>
<A HREF="swparta.htm"><IMG SRC="images/previous.gif" ALT="prev"></A>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -