Initial revision

This commit is contained in:
Ben Gras
2005-04-21 14:53:53 +00:00
commit 9865aeaa79
2264 changed files with 411685 additions and 0 deletions
+85
View File
@@ -0,0 +1,85 @@
# Makefile for lib/i86/misc.
CFLAGS = -O -D_MINIX -D_POSIX_SOURCE -Was-ncc
CC1 = $(CC) $(CFLAGS) -c
LIBRARY = ../../libc.a
all: $(LIBRARY)
OBJECTS = \
$(LIBRARY)(alloca.o) \
$(LIBRARY)(get_bp.o) \
$(LIBRARY)(getprocessor.o) \
$(LIBRARY)(hton86.o) \
$(LIBRARY)(io_inb.o) \
$(LIBRARY)(io_inl.o) \
$(LIBRARY)(io_insb.o) \
$(LIBRARY)(io_insl.o) \
$(LIBRARY)(io_insw.o) \
$(LIBRARY)(io_intr.o) \
$(LIBRARY)(io_inw.o) \
$(LIBRARY)(io_outb.o) \
$(LIBRARY)(io_outl.o) \
$(LIBRARY)(io_outsb.o) \
$(LIBRARY)(io_outsl.o) \
$(LIBRARY)(io_outsw.o) \
$(LIBRARY)(io_outw.o) \
$(LIBRARY)(oneC_sum.o) \
$(LIBRARY): $(OBJECTS)
aal cr $@ *.o
rm *.o
$(LIBRARY)(alloca.o): alloca.s
$(CC1) alloca.s
$(LIBRARY)(get_bp.o): get_bp.s
$(CC1) get_bp.s
$(LIBRARY)(getprocessor.o): getprocessor.s
$(CC1) getprocessor.s
$(LIBRARY)(hton86.o): hton86.s
$(CC1) hton86.s
$(LIBRARY)(io_inb.o): io_inb.s
$(CC1) io_inb.s
$(LIBRARY)(io_inl.o): io_inl.s
$(CC1) io_inl.s
$(LIBRARY)(io_insb.o): io_insb.s
$(CC1) io_insb.s
$(LIBRARY)(io_insl.o): io_insl.s
$(CC1) io_insl.s
$(LIBRARY)(io_insw.o): io_insw.s
$(CC1) io_insw.s
$(LIBRARY)(io_intr.o): io_intr.s
$(CC1) io_intr.s
$(LIBRARY)(io_inw.o): io_inw.s
$(CC1) io_inw.s
$(LIBRARY)(io_outb.o): io_outb.s
$(CC1) io_outb.s
$(LIBRARY)(io_outl.o): io_outl.s
$(CC1) io_outl.s
$(LIBRARY)(io_outsb.o): io_outsb.s
$(CC1) io_outsb.s
$(LIBRARY)(io_outsl.o): io_outsl.s
$(CC1) io_outsl.s
$(LIBRARY)(io_outsw.o): io_outsw.s
$(CC1) io_outsw.s
$(LIBRARY)(io_outw.o): io_outw.s
$(CC1) io_outw.s
$(LIBRARY)(oneC_sum.o): oneC_sum.s
$(CC1) oneC_sum.s
+23
View File
@@ -0,0 +1,23 @@
#
! alloca() - allocate space on the stack Author: Kees J. Bot
! 26 Jan 1994
#if __ACK__ /* BCC can't do alloca(), register saving is wrong. */
.text
.define _alloca
_alloca:
pop cx ! Return address
pop ax ! Bytes to allocate
add ax, #2*2+1 ! Add space for two saved register variables
andb al, #0xFE ! Align
mov bx, sp ! Keep current sp
sub sp, ax ! Lower stack
mov ax, sp ! Return value
push 2(bx) ! Push what is probably the saved si
push (bx) ! Saved di
! Now ACK can still do:
! pop di; pop si; mov sp, bp; pop bp; ret
push ax ! Dummy argument
jmp (cx)
#endif
+15
View File
@@ -0,0 +1,15 @@
! get_bp.s
!
! return BP in AX
!
! Created: Sep 7, 1992 by Philip Homburg
.sect .text; .sect .rom; .sect .data; .sect .bss
.sect .text
.define _get_bp
_get_bp:
mov ax, bp
ret
! $PchId: get_bp.ack.s,v 1.3 1996/02/23 08:27:48 philip Exp $
+92
View File
@@ -0,0 +1,92 @@
! getprocessor() - determine processor type Author: Kees J. Bot
! 26 Jan 1994
.text
o32 = 0x66 ! 32 bit operand size prefix
! int getprocessor(void);
! Return 86, 186, 286, 386, 486, 586, ...
.define _getprocessor
_getprocessor:
push bp
mov bp, sp
push sp ! see if pushed sp == sp
pop ax
cmp ax, sp
jz new_processor
mov cx, #0x0120 ! see if shifts are mod 32
shlb ch, cl ! zero tells if 86
mov ax, #86
jz got_processor
mov ax, #186
jmp got_processor
new_processor: ! see if high bits are set in saved IDT
sub sp, #6 ! space for IDT ptr
sidt -6(bp) ! save 3 word IDT ptr
cmpb -1(bp), #0xFF ! top byte of IDT ptr is always FF on 286
mov ax, #286
je got_processor
! 386, 486, 586
and sp, #0xFFFC ! Align stack to avoid AC fault (needed?)
mov cx, #0x0004 ! Try to flip the AC bit introduced on the 486
call flip
mov ax, #386 ! 386 if it didn't react to "flipping"
jz got_processor
mov cx, #0x0020 ! Try to flip the ID bit introduced on the 586
call flip
mov ax, #486 ! 486 if it didn't react
jz got_processor
.data1 o32
pushf
.data1 o32
pusha ! Save the world
.data1 o32
xor ax, ax
inc ax ! eax = 1
.data1 0x0F, 0xA2 ! CPUID instruction tells the processor type
andb ah, #0x0F ! Extract the family (5, 6, ...)
movb al, ah
movb ah, #100
mulb ah ! 500, 600, ...
add ax, #86 ! 586, 686, ...
mov bx, sp
mov 7*4(bx), ax ! Pass ax through
.data1 o32
popa
.data1 o32
popf
got_processor:
mov sp, bp
pop bp
ret
flip:
push bx ! Save bx and realign stack to multiple of 4
.data1 o32 ! About to operate on a 32 bit object
pushf ! Push eflags
pop ax
pop dx ! dx:ax = eflags
mov bx, dx ! Save original eflags (high word only)
xor dx, cx ! Flip the bit to test
push dx
push ax ! Push modified eflags value
.data1 o32
popf ! Load modified eflags register
.data1 o32
pushf
pop ax
pop dx ! Get it again
push bx
push ax
.data1 o32
popf ! Restore original eflags register
xor dx, bx ! See if the bit changed
test dx, cx
pop bx ! Restore bx
ret
+25
View File
@@ -0,0 +1,25 @@
! htonX(), ntohX() - Host to network byte order conversion
! Author: Kees J. Bot
! 7 Jan 1997
!
! This is a little endian 8086, so we swap bytes to/from the big endian network
! order. The normal <net/hton.h> macros are not used, they give lousy code.
.text
.define _htons, _ntohs
_htons:
_ntohs:
mov bx, sp
movb ah, 2(bx) ! Load bytes into ax in reverse order
movb al, 3(bx)
ret
.define _htonl, _ntohl
_htonl:
_ntohl:
mov bx, sp
movb dh, 2(bx) ! Load bytes into dx:ax in reverse order
movb dl, 3(bx)
movb ah, 4(bx)
movb al, 5(bx)
ret
+14
View File
@@ -0,0 +1,14 @@
! inb() - Input one byte Author: Kees J. Bot
! 18 Mar 1996
! unsigned inb(U16_t port);
.sect .text
.define _inb
_inb:
push bp
mov bp, sp
mov dx, 4(bp) ! port
inb dx ! read 1 byte
xorb ah, ah
pop bp
ret
+23
View File
@@ -0,0 +1,23 @@
! inl() - Input one dword Author: Kees J. Bot
! 18 Mar 1996
! unsigned inl(U16_t port);
o32 = 0x66
.sect .text
.define _inl
_inl:
push bp
mov bp, sp
pushf
cli ! eax is not interrupt safe
mov dx, 4(bp) ! port
.data1 o32
in dx ! read 1 dword
.data1 o32
push ax ! push eax
pop ax
pop dx ! dx:ax = eax
popf
pop bp
ret
+21
View File
@@ -0,0 +1,21 @@
! insb() - Input a byte array Author: Kees J. Bot
! 18 Mar 1996
! void insb(U16_t port, void *buf, size_t count);
.sect .text
.define _insb
_insb:
push bp
mov bp, sp
cld
push di
mov dx, 4(bp) ! port
mov di, 6(bp) ! buf
mov cx, 8(bp) ! byte count
jcxz 1f
0: inb dx ! input 1 byte
stosb ! write 1 byte
loop 0b ! many times
1: pop di
pop bp
ret
+22
View File
@@ -0,0 +1,22 @@
! insl() - Input a dword array Author: Kees J. Bot
! 18 Mar 1996
! void insl(U16_t port, void *buf, size_t count);
o32 = 0x66
.sect .text
.define _insl
_insl:
push bp
mov bp, sp
cld
push di
mov dx, 4(bp) ! port
mov di, 6(bp) ! buf
mov cx, 8(bp) ! byte count
shr cx, #2 ! dword count
.data1 o32
rep ins ! input many dwords
pop di
pop bp
ret
+19
View File
@@ -0,0 +1,19 @@
! insw() - Input a word array Author: Kees J. Bot
! 18 Mar 1996
! void insw(U16_t port, void *buf, size_t count);
.sect .text
.define _insw
_insw:
push bp
mov bp, sp
cld
push di
mov dx, 4(bp) ! port
mov di, 6(bp) ! buf
mov cx, 8(bp) ! byte count
shr cx, #1 ! word count
rep ins ! input many words
pop di
pop bp
ret
+16
View File
@@ -0,0 +1,16 @@
! intr_disable(), intr_enable - Disable/Enable hardware interrupts.
! Author: Kees J. Bot
! 18 Mar 1996
! void intr_disable(void);
! void intr_enable(void);
.sect .text
.define _intr_disable
_intr_disable:
cli
ret
.define _intr_enable
_intr_enable:
sti
ret
+13
View File
@@ -0,0 +1,13 @@
! inw() - Input one word Author: Kees J. Bot
! 18 Mar 1996
! unsigned inw(U16_t port);
.sect .text
.define _inw
_inw:
push bp
mov bp, sp
mov dx, 4(bp) ! port
in dx ! read 1 word
pop bp
ret
+14
View File
@@ -0,0 +1,14 @@
! outb() - Output one byte Author: Kees J. Bot
! 18 Mar 1996
! void outb(U16_t port, U8_t value);
.sect .text
.define _outb
_outb:
push bp
mov bp, sp
mov dx, 4(bp) ! port
mov ax, 4+2(bp) ! value
outb dx ! output 1 byte
pop bp
ret
+21
View File
@@ -0,0 +1,21 @@
! outl() - Output one dword Author: Kees J. Bot
! 18 Mar 1996
! void outl(U16_t port, u32_t value);
o32 = 0x66
.sect .text
.define _outl
_outl:
push bp
mov bp, sp
pushf
cli ! eax is not interrupt safe
mov dx, 4(bp) ! port
.data1 o32
mov ax, 4+2(bp) ! value
.data1 o32
out dx ! output 1 dword
popf
pop bp
ret
+21
View File
@@ -0,0 +1,21 @@
! outsb() - Output a byte array Author: Kees J. Bot
! 18 Mar 1996
! void outsb(U16_t port, void *buf, size_t count);
.sect .text
.define _outsb
_outsb:
push bp
mov bp, sp
cld
push si
mov dx, 4(bp) ! port
mov si, 6(bp) ! buf
mov cx, 8(bp) ! byte count
jcxz 1f
0: lodsb ! read 1 byte
outb dx ! output 1 byte
loop 0b ! many times
1: pop si
pop bp
ret
+22
View File
@@ -0,0 +1,22 @@
! outsl() - Output a dword array Author: Kees J. Bot
! 18 Mar 1996
! void outsl(U16_t port, void *buf, size_t count);
o32 = 0x66
.sect .text
.define _outsl
_outsl:
push bp
mov bp, sp
cld
push si
mov dx, 4(bp) ! port
mov si, 6(bp) ! buf
mov cx, 8(bp) ! byte count
shr cx, #2 ! dword count
.data1 o32
rep outs ! output many dwords
pop si
pop bp
ret
+19
View File
@@ -0,0 +1,19 @@
! outsw() - Output a word array Author: Kees J. Bot
! 18 Mar 1996
! void outsw(U16_t port, void *buf, size_t count);
.sect .text
.define _outsw
_outsw:
push bp
mov bp, sp
cld
push si
mov dx, 4(bp) ! port
mov si, 6(bp) ! buf
mov cx, 8(bp) ! byte count
shr cx, #1 ! word count
rep outs ! output many words
pop si
pop bp
ret
+14
View File
@@ -0,0 +1,14 @@
! outw() - Output one word Author: Kees J. Bot
! 18 Mar 1996
! void outw(U16_t port, U16_t value);
.sect .text
.define _outw
_outw:
push bp
mov bp, sp
mov dx, 4(bp) ! port
mov ax, 4+2(bp) ! value
out dx ! output 1 word
pop bp
ret
+68
View File
@@ -0,0 +1,68 @@
! oneC_sum() - One complement`s checksum Author: Kees J. Bot
! 23 May 1998
! See RFC 1071, "Computing the Internet checksum"
! See also the C version of this code.
.text
.define _oneC_sum
.align 4
_oneC_sum:
push bp
mov bp, sp
push si
push di
mov ax, 4(bp) ! Checksum of previous block
mov si, 6(bp) ! Data to compute checksum over
mov di, 8(bp) ! Number of bytes
xor dx, dx
xorb cl, cl
align: test si, #1 ! Is the data aligned?
jz aligned
test di, di
jz 0f
movb dh, (si) ! First unaligned byte in high half of
dec di ! the dx register, i.e. rotate 8 bits
0: inc si
movb cl, #8 ! Number of bits "rotated"
ror ax, cl ! Rotate the checksum likewise
aligned:add ax, dx ! Summate the unaligned byte
adc ax, #0 ! Add carry back in for one`s complement
jmp add6test
.align 4
add6: add ax, (si) ! Six times unrolled loop, see below
adc ax, 2(si)
adc ax, 4(si)
adc ax, 6(si)
adc ax, 8(si)
adc ax, 10(si)
adc ax, #0
add si, #12
add6test:
sub di, #12
jae add6
add di, #12
jmp add1test
.align 4
add1: add ax, (si) ! while ((di -= 2) >= 0)
adc ax, #0 ! ax += *si++;
add si, #2 ! di += 2;
add1test:
sub di, #2
jae add1
add di, #2
jz done ! Is there an extra byte?
movb dl, (si) ! Load extra byte in word
xorb dh, dh
add ax, dx ! Add in the last bits
adc ax, #0
done:
rol ax, cl ! Undo the rotation at the beginning
pop di
pop si
pop bp
ret