From 16a384cfb161f6a3dbcd69fc3b788b6dbc229669 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Fri, 23 Apr 1999 16:35:11 +0000 Subject: New BSP from Tony R. Ambardar from the University of British Columbia. The BSP is for: Yes, this is the "entry model" of a series of boards from Technologic Systems. Costs <$200 I believe. They have a WWW page at www.t-systems.com. I am letting them know about the availability of this BSP too. --- c/src/lib/libbsp/i386/ts_386ex/tools/Makefile.in | 26 + c/src/lib/libbsp/i386/ts_386ex/tools/README | 68 +++ c/src/lib/libbsp/i386/ts_386ex/tools/coff2bin | 23 + .../libbsp/i386/ts_386ex/tools/dos_sup/loader.com | Bin 0 -> 934 bytes .../ts_386ex/tools/dos_sup/loader_hybrid_com.asm | 575 +++++++++++++++++++++ .../libbsp/i386/ts_386ex/tools/dos_sup/ts1325.inc | 48 ++ .../i386/ts_386ex/tools/ts_1325_ada/Makefile | 41 ++ .../ts_386ex/tools/ts_1325_ada/Makefile.ts_386ex | 41 ++ .../i386/ts_386ex/tools/ts_1325_ada/i386_ports.adb | 29 ++ .../i386/ts_386ex/tools/ts_1325_ada/i386_ports.ads | 47 ++ .../libbsp/i386/ts_386ex/tools/ts_1325_ada/init.c | 86 +++ .../ts_386ex/tools/ts_1325_ada/ts1325-button.adb | 22 + .../ts_386ex/tools/ts_1325_ada/ts1325-button.ads | 22 + .../i386/ts_386ex/tools/ts_1325_ada/ts1325-led.adb | 46 ++ .../i386/ts_386ex/tools/ts_1325_ada/ts1325-led.ads | 26 + .../ts_386ex/tools/ts_1325_ada/ts1325-parallel.adb | 13 + .../ts_386ex/tools/ts_1325_ada/ts1325-parallel.ads | 21 + .../i386/ts_386ex/tools/ts_1325_ada/ts1325.ads | 2 + .../ts_386ex/tools/ts_1325_ada/ts1325_test.adb | 115 +++++ 19 files changed, 1251 insertions(+) create mode 100644 c/src/lib/libbsp/i386/ts_386ex/tools/Makefile.in create mode 100644 c/src/lib/libbsp/i386/ts_386ex/tools/README create mode 100755 c/src/lib/libbsp/i386/ts_386ex/tools/coff2bin create mode 100644 c/src/lib/libbsp/i386/ts_386ex/tools/dos_sup/loader.com create mode 100644 c/src/lib/libbsp/i386/ts_386ex/tools/dos_sup/loader_hybrid_com.asm create mode 100644 c/src/lib/libbsp/i386/ts_386ex/tools/dos_sup/ts1325.inc create mode 100644 c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/Makefile create mode 100644 c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/Makefile.ts_386ex create mode 100644 c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/i386_ports.adb create mode 100644 c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/i386_ports.ads create mode 100644 c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/init.c create mode 100644 c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-button.adb create mode 100644 c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-button.ads create mode 100644 c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-led.adb create mode 100644 c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-led.ads create mode 100644 c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-parallel.adb create mode 100644 c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-parallel.ads create mode 100644 c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325.ads create mode 100644 c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325_test.adb (limited to 'c/src/lib/libbsp/i386/ts_386ex/tools') diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/Makefile.in b/c/src/lib/libbsp/i386/ts_386ex/tools/Makefile.in new file mode 100644 index 0000000000..a3963fc909 --- /dev/null +++ b/c/src/lib/libbsp/i386/ts_386ex/tools/Makefile.in @@ -0,0 +1,26 @@ +# +# $Id$ +# + +@SET_MAKE@ +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +top_builddir = ../../../../../../.. +subdir = c/src/lib/libbsp/i386/ts_386ex/timer + +INSTALL = @INSTALL@ + +RTEMS_ROOT = $(top_srcdir)/@RTEMS_TOPdir@ +PROJECT_ROOT = @PROJECT_ROOT@ + +VPATH = @srcdir@ + +include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).cfg +include $(RTEMS_ROOT)/make/leaf.cfg + +CLEAN_ADDITIONS += +CLOBBER_ADDITIONS += + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/README b/c/src/lib/libbsp/i386/ts_386ex/tools/README new file mode 100644 index 0000000000..97f54cc0f0 --- /dev/null +++ b/c/src/lib/libbsp/i386/ts_386ex/tools/README @@ -0,0 +1,68 @@ +This directory contains various support software for using RTEMS on +the TS-1325. Descriptions follow. + + +DOS Loader +========== + +The dos_sup directory contains a DOS-based loader (loader.com) for +RTEMS executables on the TS-1325. Fully commented source code is +included. + +Once an application has been compiled and the resulting COFF +executable converted to raw binary format and transferred to the +TS-1325, the DOS loader program must be used to load and execute +it. The loader is simply invoked as "loader filename", where the +filename cannot contain an explicit path. + +The loader will work with files stored either on the C: ram disk or +the A: flash disk. Since Zmodem transfers to the C: ram disk are much +faster than to the A: disk, most development work will be done using +the C: disk. Once completed, an application may copied to the +(non-volatile) A: disk. Additionally, one may add the line "loader +filename" to the AUTOEXEC.BAT file, allow ing the application to be +run automatically at boot time. + +Note that the DOS loader will abort and exit if it detects that the +push-button switch is pressed, thus allowing one to break out of a +patho logical "boot loop" situation. + + +coff2bin +======== + +The coff2bin script is just a convenient wrapper for the objcopy +command. It can convert a list of RTEMS-generated COFF files to raw +binary images that can be loaded on the TS-1325. The converted files +are saved in the current directory with a ".bin" extension. + + +TS-1325 Ada95 Support +===================== + +The TS-1325 includes a few peripherals which are very useful for +embedded development: a push-button switch, an LED, and a parallel +port which may be used for digital I/O. Note that the pinout for the +parallel port is given in the TS-1325 manual. + +These devices are all supported by Ada packages allowing easy access; +they may be found in the ts_1325_ada directory. Doing a make command +here will build a program that tests and exercises all these support +packages. Plugging in some kind of parallel-port "loop-back" connector +would be useful during this test. + +Brief descriptions of the main packages are as follows: + +* ts1325-button: allows one to check or wait for a button press. + +* ts1325-led: allows safe reading and setting of the LED colour. + +* ts1325-parallel: used to read and write byte date to the parallel + port. + +* i386_ports: code to access the I/O address space, using Ada + inline assembly. + + +Tony Ambardar, 4/21/99 + diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/coff2bin b/c/src/lib/libbsp/i386/ts_386ex/tools/coff2bin new file mode 100755 index 0000000000..fbe5ed5ca3 --- /dev/null +++ b/c/src/lib/libbsp/i386/ts_386ex/tools/coff2bin @@ -0,0 +1,23 @@ +#!/bin/sh +# Just a Q&D prog to convert a bunch of RTEMS generated COFF files to raw +# binary images that can be loaded on the TS-1325. The converted files are +# saved in the current directory. +# +# Tony Ambardar + +OBJCOPY=/usr/local/rtems/bin/i386-rtems-objcopy + +if [ $# = 0 ] +then + echo "Description: Convert RTEMS coff files to raw binary files." + echo "Usage: coff2bin " + echo + exit 1 +fi + +for i in $* +do + OUTFILE=$(basename `echo $i | sed 's/\.[a-zA-Z0-9]*$//g'`.bin) + $OBJCOPY -O binary $i $OUTFILE +done + diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/dos_sup/loader.com b/c/src/lib/libbsp/i386/ts_386ex/tools/dos_sup/loader.com new file mode 100644 index 0000000000..945a7d2339 Binary files /dev/null and b/c/src/lib/libbsp/i386/ts_386ex/tools/dos_sup/loader.com differ diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/dos_sup/loader_hybrid_com.asm b/c/src/lib/libbsp/i386/ts_386ex/tools/dos_sup/loader_hybrid_com.asm new file mode 100644 index 0000000000..cd951ec8fd --- /dev/null +++ b/c/src/lib/libbsp/i386/ts_386ex/tools/dos_sup/loader_hybrid_com.asm @@ -0,0 +1,575 @@ +; loader_hybrid_com.asm +; +; This is a DOS command-line loader for RTEMS executables running on +; the Technologic Systems TS-1325 Embedded PC. +; +; It loads a DOS file given on the command line to the address `KernelBase', +; and then transfers control there. It uses DOS file I/O commands to read from +; the A: flash disk, and direct memory access to read from the C: ramdisk. +; +; Copying uses protected flat mode, so kernelbase could be above 1MB. +; It does not initialize protected mode before transferring control +; to the RTEMS executable image. +; +; Compile with: nasm -o loader.com loader_hybrid_com.asm +; +; Tony Ambardar (c) 1999 +; E.C.E. Department +; University of British Columbia + +%include "ts1325.inc" ; Some useful LED and button macros + +; IMPORTANT: [org xxx] MUST be the same as RelocAddr below. + +[org E000h] +[bits 16] + +; Only these three definitions may need to change + +KernelBase equ 08000h ; Where (32-bit) to locate and run RTEMS executable + +RelocSeg equ 9000h ; Segment to relocate code. +RelocAddr equ 0E000h ; Address to relocate code, same as "org" above + +; Next three used in GDT + +RelocBase equ RelocSeg*16 +Reloc15 equ RelocBase & 0FFFFh +Reloc23 equ RelocBase / 10000h + +Buffer equ RelocAddr+400h ; In same segment as RelocSeg +BuffSiz equ 200h ; Size of disk read + copy + +StackSeg equ RelocSeg +StackSiz equ 40h +StackAddr equ Buffer+BuffSiz+StackSiz + +; Used to jump to kernel in real mode + +KernelAddr equ KernelBase & 0FFFFh +KernelSeg equ (KernelBase - KernelAddr) / 16 + +; Used to load from the ramdisk + +Extended equ 100000h ; Start of extended memory / C: ramdisk +OffsetBPB equ 0Bh ; Start of BIOS param block in bootsector + +; Command-line parameters + +ParamLen equ 80h ; Byte length of command line params +ParamStr equ 82h ; Start of param string + +; The ORG address above means pre-relocation addresses are wrong. The +; following macro fixes these up. + +%define PRE_RELOC_ADDR(addr) (addr-CodeStart+100h) + +CodeStart: + +mov dx, PRE_RELOC_ADDR(Greet) +mov ah, 9h +int 21h + +mov ax, 0b021h ; Exit to DOS if push-button switch pressed +int 15h +and al, 01h ; Bit 0 == 0 if button pressed +jz ButtonExit + +xor cx, cx +mov cl, [ParamLen] ; See if there is a command line arg +jcxz NameError + +dec cx ; Nix leading space. Is this standard? +cmp cx, 12 ; Limit to 12 chars: e.g. ABCDEFGH.IJK +jg NameError + ; Damn. Should make sure of no ':' or '\' chars too. + +; Required by "relocated" [org] statement above + +mov di, PRE_RELOC_ADDR(FName) +mov si, ParamStr +repne +movsb ; Copy command line arg + +; Make sure no ':' in filename. This forces using the default dir. + +mov di, PRE_RELOC_ADDR(FName) +mov al, ':' +mov cx, 12 +repne +scasb +je NameError + +jmp Relocate + +ButtonExit: +mov dx, PRE_RELOC_ADDR(Button) +jmp short DosPrint + +NameError: +mov dx, PRE_RELOC_ADDR(FError) +jmp short DosPrint + +DosError: ; Only call this AFTER relocation +mov dx, RError + +DosPrint: +mov ah, 9h +int 21h + +DosExit: +mov ax, 04C00h ; DOS Function: Exit program +int 21h ; Call DOS. Terminate Program + +Relocate: ; Move this code down to RelocAddr + +cld +mov ax, RelocSeg +mov es, ax ; Set destination = RelocSeg:RelocAddr +mov di, RelocAddr +mov si, 100h ; Source is ds:0100h i.e. a COM file +mov cx, CodeEnd - CodeStart ; Size of all code + +repne +movsb + +; continue in copied code + +jmp RelocSeg:RelocAddr + (RelocStart - CodeStart) + +RelocStart: +cli +mov ax, StackSeg +mov ss, ax +mov sp, StackAddr +mov ax, cs +mov ds, ax +mov es, ax ; Setup segments and stack +sti + +mov ah, 19h +int 21h +mov [DDrive], al ; Save current default drive + +mov ax, 3d00h ; DOS Function: Open the file for reading +mov dx, FName ; Presume DS points at filename segment +int 21h +jc DosError + +GoodOpen: +mov [FHndl], ax ; Save file handle + +mov al, [DDrive] ; Check if loading from C: drive (ramdisk) +cmp al, 2 +je LoadRamdisk + +LoadDosdisk: + +; Here we are loading from A: drive. Use DOS calls to load the file into +; extended memory. Then copy from extended memory to `KernelBase'. This way +; we avoid overwriting DOS file I/O structures if reading directly into +; conventional (<640K) memory. + +mov edi, Extended ; Destination for code read @ 1 Meg + +ReadLoop: + +mov ah,3fh ; DOS Function: Read data from the file +mov bx, [FHndl] +mov dx, Buffer ; Address of data buffer +mov cx, BuffSiz ; Request BuffSiz bytes +int 21h +jc DosError + +GoodRead: + +cmp ax, cx ; EOF reached? AX = # bytes read +pushf + +add ax, 3 +shr ax, 2 ; Copy buffer by dwords, # = (ax + 3)/4 +movzx ecx, ax +mov esi, RelocBase + Buffer ; Source for copy, destination is in edi + +call CopyData32 ; Do protected-mode copy + +popf +je ReadLoop ; Still data left, so read next chunk + +mov esi, Extended ; Source for copy @ 1 Meg +mov ecx, edi ; Make count in dwords +sub ecx, esi +add ecx, 3 +shr ecx, 2 +mov edi, KernelBase ; Destination copy + +call CopyData32 ; Move code into conventional memory +jmp RunKernel + +LoadRamdisk: + +; Here we are loading from C: drive. Use protected mode to directly access +; the virtual disk sectors in extended memory and copy to `KernelBase'. +; This way we avoid using DOS file I/O calls, except for an `open' earlier +; which tells us the file exists. + +; Copy C: "bootsector" to buffer and save the BIOS parameter block + +mov esi, Extended +mov edi, RelocBase + Buffer ; Must be a 32-but address... +mov ecx, 80h +call CopyData32 + +mov si, Buffer + OffsetBPB +mov di, SavBPB +mov cx, EndBPB - SavBPB +repne +movsb + +; Calculate FAT, root dir, and data start addresses for the ramdisk + +xor eax, eax +mov ebx, eax +mov ecx, ebx + +mov ax, [ResSec] + +mov bl, [NumFAT] +imul bx, [SecFAT] + +mov cx, [NRoot] +shr cx, 4 ; 10h directory entries per sector + +add bx, ax +add cx, bx + +mov dx, [BpSect] +imul ax, dx +imul bx, dx +imul cx, dx + +add eax, Extended +add ebx, Extended +add ecx, Extended + +mov [BegFAT], eax +mov [BegRoot], ebx +mov [BegData], ecx + +; Convert the saved filename to format used in directory entry. Assume +; there's a `.' in it. Hopefully this won't haunt us later... + +mov di, FName ; Find the `.' +mov al, '.' +mov cx, 12 +repne +scasb + +mov bx, di ; di points to filename extension + +mov di, DirName +mov si, FName +mov cx, bx ; Make count +sub cx, si +dec cx +repne ; Copy initial part of filename +movsb + +mov di, bx ; Find the terminating zero +xor al,al +mov cx, 4 +repne +scasb + +mov cx, di ; Make count +sub cx, bx +dec cx +mov si, bx +mov di, DirName + 8 +repne ; Copy filename extension +movsb + +mov si, DirName ; Convert the stupid thing to upper case +mov di, si +mov cx, 11 + +Cvt2Upper: + +lodsb +cmp al, 'a' +jb NotLow +cmp al, 'z' +ja NotLow +xor al, 20h + +NotLow: + +stosb +loop Cvt2Upper + +; Now load in the root directory (temporarily) to find the first cluster +; of our file. Use KernelSeg:KernelAddr as temporary storage. + +mov esi, [BegRoot] +mov edi, KernelBase +xor ecx, ecx +mov cx, [NRoot] +shl cx, 3 ; Each root entry is 8 dwords +call CopyData32 + +mov dx, [NRoot] ; Max # of dir entries + +mov cx, KernelSeg ; Setup segment selector for comparison +mov es, cx +mov di, KernelAddr + +FindEntry: + +mov cx, 11 +mov si, DirName +push di +rep cmpsb +pop di +je GotEntry +add di, 20h ; Point to next dir entry +dec dx +jnz FindEntry + +int 3h ; Should never get here... + +GotEntry: + +mov eax, KernelBase ; Setup initial address for copy +mov [CurrDst], eax + +add di, 32 - 6 ; Load first cluster number +mov ax, [es:di] +mov cx, ds ; Fix `es' selector just in case +mov es, cx + +LoadKernel: + +call LoadCluster ; Load cluster `ax' to [CurrDst], update [CurrDst] + +call NextCluster ; Get next cluster number in ax + +cmp ax, 0FF8h ; Repeat until EOF +jb LoadKernel + +RunKernel: + +mov ax, KernelSeg ; Setup data segment and transfer control +mov ds, ax + +jmp KernelSeg:KernelAddr ; Huzzah!! + + +; Load cluster `ax' to [CurrDst], update [CurrDst] + +LoadCluster: + +push ax +sub ax, 2 ; Cluster numbers start at 2 +movzx eax, ax + +xor ecx, ecx ; Calculate bytes in a cluster +mov cl, [SpClst] +imul cx, [BpSect] + +imul eax, ecx +add eax, [BegData] ; Start of cluster + +shr ecx, 2 ; Cluster size in dwords +mov esi, eax ; Copy source +mov edi, [CurrDst] ; Copy destination +call CopyData32 + +mov [CurrDst], edi ; Update dest +pop ax ; Restore cluster number + +ret + +; Search FAT (FAT12 format) for next cluster in file after `ax'. + +NextCluster: + +movzx ecx, ax ; Calculate offset into FAT +shr ax, 1 +pushf +add cx, ax + +mov esi, [BegFAT] ; Copy word containing next cluster to buffer +add esi, ecx +mov edi, RelocBase + Buffer +xor ecx, ecx +inc ecx +call CopyData32 + +mov ax, [Buffer] ; Handle odd/even cluster numbers +popf +jnc EvenCluster +shr ax, 4 + +EvenCluster: + +and ax, 0FFFh +ret + +; Enable the A20 line for accesses to extended memory. + +EnableA20: + in al,92h + or al,2 + jmp short $+2 + jmp short $+2 + jmp short $+2 + out 92h,al + ret + +; The CopyData32 routine copies ecx dwords from esi to edi. Both esi +; and edi hold 32-bit values. CopyData32 runs in 32-bit protected mode. + +CopyData32: + cli + + call EnableA20 ; Put here in case file I/O screws with this + ; or with the GDTR + + lgdt [GDTStart] ; Initialize GDTR for 32-bit protected mode + + mov eax, cr0 + or al, 1 + mov cr0, eax ;go to real flat mode + +; LED_GRN +; PSW_WAIT + + jmp dword 8h : RelocBase+ProtJmp +[bits 32] +ProtJmp: +; LED_YEL +; PSW_WAIT + + mov ax, 10h + mov ds, ax + mov es, ax + mov ss, ax + + rep movsd ;copy the sector to where it should be + + mov ax, 20h + mov ds, ax + mov es, ax + mov ss, ax + +; LED_RED +; PSW_WAIT + + jmp 18h : RealJmp1 ;use code segment with 64K limit +[bits 16] +RealJmp1: +; LED_OFF +; PSW_WAIT + + mov eax, cr0 ;back to real segmented mode + and eax, 0fffffffeh + mov cr0, eax + + jmp RelocSeg : RealJmp2 +RealJmp2: +; LED_GRN +; PSW_WAIT + + mov ax, cs + mov es, ax + mov ds, ax + mov ss, ax + + sti +ret + +; Storage for a Dos 3+ BIOS Parameter Block (for the C: ramdisk) + +SavBPB: + +BpSect dw 0h ; Bytes per sector, always 512 +SpClst db 0h ; Sectors per cluster +ResSec dw 0h ; Num of reserved sectors +NumFAT db 0h ; Num of FATs +NRoot dw 0h ; Num of root directory entries +TotSec dw 0h ; Total sectors +Media db 0h ; Media descriptor byte +SecFAT dw 0h ; Sectors per FAT + +EndBPB: + +CurrDst dd 0h ; Current destination address for copying RTEMS exec + +; Important (32-bit) address for the C: ramdisk + +BegFAT dd 0h ; Start of the FAT +BegRoot dd 0h ; Start of root directory +BegData dd 0h ; Start of data clusters + +DDrive db 0h ; Default drive: 0h = A:, 2h = C: + +DirName times 11 db 32 ; Room for 8.3 directory entry name + +FName times 13 db 0 ; Room for a 12 character null-terminated string +FHndl dw 0000h + +Greet db "RTEMS DOS Loader (c) 1999 Tony R. Ambardar",13,10,"$" +Button db "Button pressed -- Aborting.",13,10,"$" +FError db "Missing or incorrect file name.",13,10,"$" +RError db "Error opening or reading file.",13,10,"$" + +; Global Descriptor Table used for protectd mode. +; Store the GDTR in the first null GDT entry + +GDTStart: + +dw GDTEnd - GDTStart - 1 +dd RelocBase + GDTStart +dw 0 + +; base=0h, limit=4Gb, present, code, exec/read, conform, 32-bit + +dw 0ffffh ;seg. lim. [15:0] +dw 0 ;base[15:0] +db 0 ;base[23:16] +db 9eh ;p=1,dpl=0,s=1 ; code: execute/read, conforming +db 0cfh ;c: gran=4K, D/B=1(32-bit) ; f: seg. lim. [19:16] +db 0 ;base[31:24] + +; base=0h, limit=4Gb, present, data, read/write exp. up, 32-bit SP + +dw 0ffffh ;seg. lim. [15:0] +dw 0 ;base[15:0] +db 0 ;base[23:16] +db 92h ;p=1,dpl=0,s=1 ; data: read/write expand-up +db 0cfh ;c: gran=4K, D/B=1(32-bit) ; f: seg. lim. [19:16] +db 0 ;base[31:24] + +; base=0h, limit=ffffh, present, code, exec/read, conform, 16-bit +; NOTE: this descriptor is used to change back to real mode. + +dw 0ffffh ;seg. lim. [15:0] +dw Reloc15 ;base[15:0] +db Reloc23 ;base[23:16] +db 9eh ;p=1,dpl=0,s=1 ; code: execute/read, conforming +db 000h ;4: gran=1 byte, D/B=0(16-bit) ; 0: seg. lim. [19:16] +db 0 ;base[31:24] + +; base=0h, limit=ffffh, present, data, read/write exp. up, 16-bit SP +; NOTE: this descriptor is used to change back to real mode. + +dw 0ffffh ;seg. lim. [15:0] +dw Reloc15 ;base[15:0] +db Reloc23 ;base[23:16] +db 92h ;p=1,dpl=0,s=1 ; data: read/write expand-up +db 000h ;0: gran=1 byte, D/B=0(16-bit) ; 0: seg. lim. [19:16] +db 0 ;base[31:24] + +GDTEnd: + +CodeEnd: ; end-of-code marker for copy diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/dos_sup/ts1325.inc b/c/src/lib/libbsp/i386/ts_386ex/tools/dos_sup/ts1325.inc new file mode 100644 index 0000000000..40ed3659ab --- /dev/null +++ b/c/src/lib/libbsp/i386/ts_386ex/tools/dos_sup/ts1325.inc @@ -0,0 +1,48 @@ +; Some nasm macros to turn on TS-1325 LEDs and wait for button presses. +; This should be '%include'ed in your nasm source file. +; +; Tony Ambardar + +P1LTC equ 0F862h +P1PIN equ 0F860h + +%macro LED_OFF 0 + mov dx, P1LTC + in al, dx + or al, 01000000b ; turn off red + and al, 11011111b ; turn off green + out dx, al +%endmacro + +%macro LED_GRN 0 + mov dx, P1LTC + in al, dx + or al, 01100000b ; turn off red, turn on green + out dx, al +%endmacro + +%macro LED_YEL 0 + mov dx, P1LTC + in al, dx + or al, 00100000b ; turn on green + and al, 10111111b ; turn on red + out dx, al +%endmacro + +%macro LED_RED 0 + mov dx, P1LTC + in al, dx + and al, 10011111b ; turn on red, turn off green + out dx, al +%endmacro + +%macro PSW_WAIT 0 + mov dx, P1PIN ; Get PSW state + mov ecx, 80000h +%%read in al, dx + test al, 00000001b ; is PSW asserted? + jnz %%read ; if not, we're done + dec ecx + jnz %%read +%endmacro + diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/Makefile b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/Makefile new file mode 100644 index 0000000000..1ce881e04e --- /dev/null +++ b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/Makefile @@ -0,0 +1,41 @@ +# +# Makefile for TS-1325 Utilities example +# + +MAIN=ts1325_test + +# Tool paths +tooldir=/usr/local/rtems +rtemsdir=${tooldir}/rtems/ts_386ex + +# Tool names +GCC=${tooldir}/bin/i386-rtems-gcc +GNATMAKE=${tooldir}/bin/i386-rtems-gnatmake +SIZE=${tooldir}/bin/i386-rtems-size +SIS=${tooldir}/bin/sis +GDB=${tooldir}/bin/sis-gdb + +CARGS=-B${rtemsdir}/lib/ -specs bsp_specs -qrtems \ +-msoft-float -mno-fp-ret-in-387 +#CARGS=-B/usr/local/rtems/tools/build-i386-rtems/ts_386ex/lib/ -specs bsp_specs -qrtems + +all: init.o + $(GNATMAKE) -O -gnata -gnatE -gnato $(MAIN) -g \ + -bargs -r \ + -cargs $(CARGS) \ + -largs $(CARGS) init.o + $(SIZE) $(MAIN) + + + +init.o: init.c + $(GCC) -O4 -g -Wall -ansi -fasm $(CARGS) -c init.c + +run: + $(SIS) $(MAIN) + +gdb: + $(GDB) $(MAIN) + +clean: + rm -f b_$(MAIN).c b_$(MAIN).o *.o *.ali $(MAIN) diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/Makefile.ts_386ex b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/Makefile.ts_386ex new file mode 100644 index 0000000000..1ce881e04e --- /dev/null +++ b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/Makefile.ts_386ex @@ -0,0 +1,41 @@ +# +# Makefile for TS-1325 Utilities example +# + +MAIN=ts1325_test + +# Tool paths +tooldir=/usr/local/rtems +rtemsdir=${tooldir}/rtems/ts_386ex + +# Tool names +GCC=${tooldir}/bin/i386-rtems-gcc +GNATMAKE=${tooldir}/bin/i386-rtems-gnatmake +SIZE=${tooldir}/bin/i386-rtems-size +SIS=${tooldir}/bin/sis +GDB=${tooldir}/bin/sis-gdb + +CARGS=-B${rtemsdir}/lib/ -specs bsp_specs -qrtems \ +-msoft-float -mno-fp-ret-in-387 +#CARGS=-B/usr/local/rtems/tools/build-i386-rtems/ts_386ex/lib/ -specs bsp_specs -qrtems + +all: init.o + $(GNATMAKE) -O -gnata -gnatE -gnato $(MAIN) -g \ + -bargs -r \ + -cargs $(CARGS) \ + -largs $(CARGS) init.o + $(SIZE) $(MAIN) + + + +init.o: init.c + $(GCC) -O4 -g -Wall -ansi -fasm $(CARGS) -c init.c + +run: + $(SIS) $(MAIN) + +gdb: + $(GDB) $(MAIN) + +clean: + rm -f b_$(MAIN).c b_$(MAIN).o *.o *.ali $(MAIN) diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/i386_ports.adb b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/i386_ports.adb new file mode 100644 index 0000000000..9705d069d8 --- /dev/null +++ b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/i386_ports.adb @@ -0,0 +1,29 @@ +with System.Machine_Code; +use System.Machine_Code; + +package body I386_Ports is + + procedure Outport (Addr: in Port_Address; Data: in Byte) is + begin + Asm ("movb %0, %%al;" & + "movw %1, %%dx;" & + "outb %%al, %%dx", + No_Output_Operands, + (Byte'Asm_Input ("g", Data), + Port_Address'Asm_Input ("g", Addr)), + Clobber => "al dx", + Volatile => True); + end Outport; + + procedure Inport (Addr: in Port_Address; Data: out Byte) is + begin + Asm ("movw %1, %%dx;" & + "inb %%dx, %%al;" & + "movb %%al, %0", + Byte'Asm_Output ("=g", Data), + Port_Address'Asm_Input ("g", Addr), + Clobber => "dx al", + Volatile => True); + end Inport; + +end I386_Ports; diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/i386_ports.ads b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/i386_ports.ads new file mode 100644 index 0000000000..c27ea646e7 --- /dev/null +++ b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/i386_ports.ads @@ -0,0 +1,47 @@ +with Interfaces; + +package I386_Ports is + + type Port_Address is new Interfaces.Unsigned_16; + + type Byte is new Interfaces.Unsigned_8; + + type Word is new Interfaces.Unsigned_16; + + type Long is new Interfaces.Unsigned_32; + + procedure Outport (Addr: in Port_Address; Data: in Byte); + + procedure Inport (Addr: in Port_Address; Data: out Byte); + + P1PIN: constant Port_Address; + P1LTC: constant Port_Address; + P1DIR: constant Port_Address; + + P2PIN: constant Port_Address; + P2LTC: constant Port_Address; + P2DIR: constant Port_Address; + + P3PIN: constant Port_Address; + P3LTC: constant Port_Address; + P3DIR: constant Port_Address; + +private + + pragma Inline (Outport, Inport); + + P1PIN: constant Port_Address := 16#F860#; + P1LTC: constant Port_Address := 16#F862#; + P1DIR: constant Port_Address := 16#F864#; + + P2PIN: constant Port_Address := 16#F868#; + P2LTC: constant Port_Address := 16#F86A#; + P2DIR: constant Port_Address := 16#F86C#; + + P3PIN: constant Port_Address := 16#F870#; + P3LTC: constant Port_Address := 16#F872#; + P3DIR: constant Port_Address := 16#F874#; + +end I386_Ports; + + diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/init.c b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/init.c new file mode 100644 index 0000000000..89e1652f3f --- /dev/null +++ b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/init.c @@ -0,0 +1,86 @@ +/* + * COPYRIGHT (c) 1989-1997. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be found in + * the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include + +#include +#include + +#ifdef GNAT_PID +#include +pid_t getpid() +{ + return GNAT_PID; +} +#endif + +/* + * By having the POSIX_Init thread create a second thread just + * to invoke gnat_main, we can override all default attributes + * of the "Ada environment task". Otherwise, we would be + * stuck with the defaults set by RTEMS. + */ + +void *start_gnat_main( void * argument ) +{ + extern int gnat_main ( int argc, char **argv, char **envp ); + + (void) gnat_main ( 0, 0, 0 ); + + exit( 0 ); + + return 0; +} + +void *POSIX_Init( void *argument ) +{ + pthread_t thread_id; + pthread_attr_t attr; + int status; + + status = pthread_attr_init( &attr ); + assert( !status ); + +#ifdef GNAT_MAIN_STACKSPACE + status = pthread_attr_setstacksize( &attr, GNAT_MAIN_STACKSPACE ); + assert( !status ); +#endif + + status = pthread_create( &thread_id, &attr, start_gnat_main, NULL ); + assert( !status ); + + pthread_exit( 0 ); + + return 0; +} + +/* configuration information */ + +#define CONFIGURE_SPTEST +#define CONFIGURE_GNAT_RTEMS + +#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER + +#define CONFIGURE_MICROSECONDS_PER_TICK RTEMS_MILLISECONDS_TO_MICROSECONDS(1) + +#define CONFIGURE_POSIX_INIT_THREAD_TABLE + +#define CONFIGURE_MAXIMUM_POSIX_THREADS 20 +#define CONFIGURE_MAXIMUM_POSIX_KEYS 20 +#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 30 +#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 20 + +#define CONFIGURE_INIT + +#include + diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-button.adb b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-button.adb new file mode 100644 index 0000000000..cc273b0b3f --- /dev/null +++ b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-button.adb @@ -0,0 +1,22 @@ +package body TS1325.Button is + + function Is_Button_Pressed return Boolean is + State: Byte; + begin + Inport (Button_Port, State); + return (State and Button_Mask) /= Button_Mask; + end Is_Button_Pressed; + + procedure Wait_For_Button_Press is + begin + Poll_Loop: + loop + if Is_Button_Pressed then + delay Minimum_Press_Time; + exit Poll_Loop when Is_Button_Pressed; + end if; + delay Poll_Interval; + end loop Poll_Loop; + end Wait_For_Button_Press; + +end TS1325.Button; diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-button.ads b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-button.ads new file mode 100644 index 0000000000..568710b32f --- /dev/null +++ b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-button.ads @@ -0,0 +1,22 @@ +with I386_Ports; +use I386_Ports; + +package TS1325.Button is + + function Is_Button_Pressed return Boolean; + + procedure Wait_For_Button_Press; + +private + + pragma Inline (Is_Button_Pressed, Wait_For_Button_Press); + + Poll_Interval: constant Duration := 0.3; + + Minimum_Press_Time: constant Duration := 0.3; + + Button_Mask: constant Byte := 2#0000_0001#; + + Button_Port: Port_Address renames P1PIN; + +end TS1325.Button; diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-led.adb b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-led.adb new file mode 100644 index 0000000000..1a213ac2ff --- /dev/null +++ b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-led.adb @@ -0,0 +1,46 @@ +package body TS1325.LED is + + protected body LED_State is + + function Get return LED_Colour is + State: Byte; + Red_On, Green_On: Boolean; + begin + Inport (LED_Port, State); + + Green_On := (State and Green_Bit) = Green_Bit; + Red_On := (State and Red_Bit) /= Red_Bit; + + if not (Green_On or Red_On) then + return Off; + elsif Green_On and not Red_On then + return Green; + elsif Green_On and Red_On then + return Yellow; + else + return Red; + end if; + end Get; + + procedure Set (Col: in LED_Colour) is + State: Byte; + begin + Inport (LED_Port, State); + + case Col is + when Off => + State := (State and not Green_Bit) or Red_Bit; + when Green => + State := State or Green_Bit or Red_Bit; + when Yellow => + State := (State or Green_Bit) and not Red_Bit; + when Red => + State := State and not (Green_Bit or Red_Bit); + end case; + + Outport (LED_Port, State); + end Set; + + end LED_State; + +end TS1325.LED; diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-led.ads b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-led.ads new file mode 100644 index 0000000000..6856bc4520 --- /dev/null +++ b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-led.ads @@ -0,0 +1,26 @@ +with I386_Ports; +use I386_Ports; + +package TS1325.LED is + + type LED_Colour is (Off, Green, Yellow, Red); + + protected LED_State is + + function Get return LED_Colour; + + procedure Set (Col: in LED_Colour); + + end LED_State; + +private + + Green_Bit: constant Byte := 2#0010_0000#; -- bit set = LED on + + Red_Bit: constant Byte := 2#0100_0000#; -- bit clear = LED on + + LED_Mask: constant Byte := 2#0110_0000#; + + LED_Port: Port_Address renames P1LTC; + +end TS1325.LED; diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-parallel.adb b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-parallel.adb new file mode 100644 index 0000000000..c0a76bcadf --- /dev/null +++ b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-parallel.adb @@ -0,0 +1,13 @@ +package body TS1325.Parallel is + + procedure Read_Parallel_Port (Data: out Byte) is + begin + Inport (Parallel_Port_In, Data); + end Read_Parallel_Port; + + procedure Write_Parallel_Port (Data: in Byte) is + begin + Outport (Parallel_Port_Out, Data); + end Write_Parallel_Port; + +end TS1325.Parallel; diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-parallel.ads b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-parallel.ads new file mode 100644 index 0000000000..b6b18d6b55 --- /dev/null +++ b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325-parallel.ads @@ -0,0 +1,21 @@ +with I386_Ports; +use I386_Ports; + +package TS1325.Parallel is + + procedure Read_Parallel_Port (Data: out Byte); + + procedure Write_Parallel_Port (Data: in Byte); + +private + + pragma Inline (Read_Parallel_Port, Write_Parallel_Port); + + -- These are non-standard IO locations, which is why they are here instead + -- of in the I386_Ports package. + + Parallel_Port_In: constant Port_Address := 16#75#; + + Parallel_Port_Out: constant Port_Address := 16#74#; + +end TS1325.Parallel; diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325.ads b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325.ads new file mode 100644 index 0000000000..5ef01b7449 --- /dev/null +++ b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325.ads @@ -0,0 +1,2 @@ +package TS1325 is +end TS1325; diff --git a/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325_test.adb b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325_test.adb new file mode 100644 index 0000000000..0cb621c880 --- /dev/null +++ b/c/src/lib/libbsp/i386/ts_386ex/tools/ts_1325_ada/ts1325_test.adb @@ -0,0 +1,115 @@ +-- +-- A test program that uses the TS1325 Button and LED packages. +-- + +with Text_IO; + +with I386_Ports; +use I386_Ports; + +with TS1325.LED; +use TS1325.LED; + +with TS1325.Button; +use TS1325.Button; + +with TS1325.Parallel; +use TS1325.Parallel; + +procedure Ts1325_Test is + + Test_Parallel_Interval: Duration := 1.0; + Read_Button_Interval: Duration := 1.0; + Read_LED_Interval: Duration := 1.0; + Set_LED_Interval: Duration := 0.2; + + task Test_Parallel is + entry Start; + end Test_Parallel; + + task body Test_Parallel is + W_Data, R_Data: I386_Ports.Byte := 0; + begin + accept Start; + + loop + W_Data := W_Data + 1; + Write_Parallel_Port (W_Data); + Read_Parallel_Port (R_Data); + Text_IO.Put_Line ("Parallel Port Loopback: Data Write = " & + I386_Ports.Byte'Image (W_Data) & + ", Data Read = " & + I386_Ports.Byte'Image (R_Data)); + delay Test_Parallel_Interval; + end loop; + end Test_Parallel; + + task Read_Button is + entry Start; + end Read_Button; + + task body Read_Button is + begin + accept Start; + + loop + if Is_Button_Pressed then + Text_IO.Put_Line ("Button is pressed."); + else + Text_IO.Put_Line ("Button is not pressed."); + end if; + delay Read_Button_Interval; + end loop; + end Read_Button; + + task Read_Colour is + entry Start; + end Read_Colour; + + task body Read_Colour is + begin + accept Start; + + loop + Text_IO.Put_Line ("Reading LED colour as " & + LED_Colour'Image (LED_State.Get)); + delay Read_LED_Interval; + end loop; + end Read_Colour; + + task Set_Colour is + entry Start; + end Set_Colour; + + task body Set_Colour is + Colour: LED_Colour := Off; + begin + accept Start; + + loop + LED_State.Set (Colour); + + if Colour = LED_Colour'Last then + Colour := LED_Colour'First; + else + Colour := LED_Colour'Succ (Colour); + end if; + + delay Set_LED_Interval; + end loop; + end Set_Colour; + +begin + Text_IO.Put_Line ("TS-1325 Utilities Test"); + Text_IO.Put_Line ("======================"); + Text_IO.New_Line; + Text_IO.Put_Line ("-=> Press the button to begin."); + Text_IO.New_Line; + + Wait_For_Button_Press; + + Set_Colour.Start; + Read_Colour.Start; + Read_Button.Start; + Test_Parallel.Start; +end Ts1325_Test; -- cgit v1.2.3