summaryrefslogtreecommitdiffstats
path: root/src/arch
diff options
context:
space:
mode:
authorMichael Brown2016-03-17 15:29:18 +0100
committerMichael Brown2016-03-17 15:32:00 +0100
commitdbc9e591a5e958b0b849fc1669902f38043b0422 (patch)
tree70da06624e620bc07475dac54bcac71c5c8a5ab8 /src/arch
parent[xen] Use generic test_and_clear_bit() function (diff)
downloadipxe-dbc9e591a5e958b0b849fc1669902f38043b0422.tar.gz
ipxe-dbc9e591a5e958b0b849fc1669902f38043b0422.tar.xz
ipxe-dbc9e591a5e958b0b849fc1669902f38043b0422.zip
[test] Move i386-specific tests to arch/i386/tests
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/arch')
-rw-r--r--src/arch/i386/Makefile1
-rw-r--r--src/arch/i386/tests/comboot/shuffle-simple.asm40
-rw-r--r--src/arch/i386/tests/comboot/version.asm136
-rw-r--r--src/arch/i386/tests/gdbstub_test.S54
-rwxr-xr-xsrc/arch/i386/tests/gdbstub_test.gdb116
5 files changed, 347 insertions, 0 deletions
diff --git a/src/arch/i386/Makefile b/src/arch/i386/Makefile
index 89393d06..a5298604 100644
--- a/src/arch/i386/Makefile
+++ b/src/arch/i386/Makefile
@@ -84,6 +84,7 @@ endif
#
SRCDIRS += arch/i386/core
SRCDIRS += arch/i386/image
+SRCDIRS += arch/i386/tests
SRCDIRS += arch/i386/interface/syslinux
# Include common x86 Makefile
diff --git a/src/arch/i386/tests/comboot/shuffle-simple.asm b/src/arch/i386/tests/comboot/shuffle-simple.asm
new file mode 100644
index 00000000..8ede8d09
--- /dev/null
+++ b/src/arch/i386/tests/comboot/shuffle-simple.asm
@@ -0,0 +1,40 @@
+ bits 16
+ org 100h
+
+ jmp start
+
+shuffle_start:
+ push 0xB800
+ pop es
+ mov cx, 80*24*2
+ mov ax, 'AA'
+ xor di, di
+ rep stosw
+.lbl: jmp .lbl
+shuffle_end:
+ nop
+shuffle_len equ (shuffle_end - shuffle_start + 1)
+
+start:
+ ; calculate physical address of shuffled part
+ xor eax, eax
+ push ds
+ pop ax
+ shl eax, 4
+ add ax, shuffle_start
+ mov dword [source], eax
+
+ mov ax, 0012h
+ mov di, shuffle_descriptors
+ mov cx, num_shuffle_descriptors
+ mov ebp, 0x7c00
+ int 22h
+ int3
+
+shuffle_descriptors:
+ dd 0x7C00
+source: dd 0
+ dd shuffle_len
+
+num_shuffle_descriptors equ 1
+
diff --git a/src/arch/i386/tests/comboot/version.asm b/src/arch/i386/tests/comboot/version.asm
new file mode 100644
index 00000000..01140423
--- /dev/null
+++ b/src/arch/i386/tests/comboot/version.asm
@@ -0,0 +1,136 @@
+ bits 16
+ org 100h
+
+_start:
+ ; first check for SYSLINUX
+ mov ah, 30h
+ int 21h
+
+ cmp eax, 59530000h
+ jne .not_syslinux
+ cmp ebx, 4c530000h
+ jne .not_syslinux
+ cmp ecx, 4e490000h
+ jne .not_syslinux
+ cmp edx, 58550000h
+ jne .not_syslinux
+
+ ; now get syslinux version
+ mov ax, 0001h
+ int 22h
+
+ push cx
+ push dx
+ push di
+ push si
+ push es
+
+ ; print version string
+ mov dx, str_version
+ mov ah, 09h
+ int 21h
+
+ pop es
+ pop bx
+ push es
+ mov ax, 0002h
+ int 22h
+
+ ; print copyright string
+ mov dx, str_copyright
+ mov ah, 09h
+ int 21h
+
+ pop es
+ pop bx
+ mov ax, 0002h
+ int 22h
+
+ ; print syslinux derivative id
+ mov dx, str_derivative
+ mov ah, 09h
+ int 21h
+
+ pop ax
+ call print_hex_byte
+
+ ; print version number
+ mov dx, str_version_num
+ mov ah, 09h
+ int 21h
+
+ pop cx
+ push cx
+ mov ax, cx
+ and ax, 0FFh
+ call print_dec_word
+
+ mov dl, '.'
+ mov ah, 02h
+ int 21h
+
+ pop cx
+ mov ax, cx
+ shr ax, 8
+ call print_dec_word
+
+ ret
+
+
+.not_syslinux:
+ mov dx, str_not_syslinux
+ mov ah, 09h
+ int 21h
+ ret
+
+; input: al = byte to print in hex
+print_hex_byte:
+ push ax
+ shr al, 4
+ call print_hex_nybble
+ pop ax
+ call print_hex_nybble
+ ret
+
+; input: bottom half of al = nybble to print in hex
+print_hex_nybble:
+ push ax
+ mov bl, al
+ and bx, 1111b
+ mov dl, [str_hex + bx]
+ mov ah, 02h
+ int 21h
+ pop ax
+ ret
+
+str_hex: db "01234567890abcdef"
+
+; input: ax = word to print
+print_dec_word:
+ mov cx, 10
+ mov word [.count], 0
+.loop:
+ xor dx, dx
+ div cx
+ inc word [.count]
+ push dx
+ test ax, ax
+ jnz .loop
+
+.print:
+ pop dx
+ add dx, '0'
+ mov ah, 02h
+ int 21h
+ dec word [.count]
+ jnz .print
+
+ ret
+
+.count: dw 0
+
+str_not_syslinux: db "Not SYSLINUX or derivative (running on DOS?)$"
+str_version: db "Version: $"
+str_copyright: db 10, "Copyright: $"
+str_derivative: db 10, "Derivative ID: 0x$"
+str_version_num: db 10, "Version number: $"
diff --git a/src/arch/i386/tests/gdbstub_test.S b/src/arch/i386/tests/gdbstub_test.S
new file mode 100644
index 00000000..739b0527
--- /dev/null
+++ b/src/arch/i386/tests/gdbstub_test.S
@@ -0,0 +1,54 @@
+ .arch i386
+
+ .section ".data", "aw", @progbits
+watch_me:
+ .long 0xfeedbeef
+
+ .section ".text", "ax", @progbits
+ .code32
+gdbstub_test:
+ /* 1. Read registers test */
+ movl $0xea010203, %eax
+ movl $0xeb040506, %ebx
+ movl $0xec070809, %ecx
+ movl $0xed0a0b0c, %edx
+ movl $0x510d0e0f, %esi
+ movl $0xd1102030, %edi
+ int $3
+
+ /* 2. Write registers test */
+ int $3
+
+ /* 3. Read memory test */
+ subl $8, %esp
+ movl $0x11223344, 4(%esp)
+ movw $0x5566, 2(%esp)
+ movb $0x77, (%esp)
+ int $3
+
+ /* 4. Write memory test */
+ int $3
+ addl $8, %esp
+
+ /* 5. Step test */
+ int $3
+ nop
+
+ /* 6. Access watch test */
+ movl $0x600d0000, %ecx
+ movl watch_me, %eax
+ movl $0xbad00000, %ecx
+ int $3
+ movl $0x600d0001, %ecx
+ movl %eax, watch_me
+ movl $0xbad00001, %ecx
+ int $3
+
+ /* 7. Write watch test */
+ movl $0x600d0002, %ecx
+ movl %eax, watch_me
+ movl $0xbad00002, %ecx
+ int $3
+
+1:
+ jmp 1b
diff --git a/src/arch/i386/tests/gdbstub_test.gdb b/src/arch/i386/tests/gdbstub_test.gdb
new file mode 100755
index 00000000..bcfa07da
--- /dev/null
+++ b/src/arch/i386/tests/gdbstub_test.gdb
@@ -0,0 +1,116 @@
+#!/usr/bin/gdb -x
+# Test suite for GDB remote debugging
+# Run:
+# make bin/ipxe.hd.tmp
+# make
+# gdb
+# (gdb) target remote :TCPPORT
+# OR
+# (gdb) target remote udp:IP:UDPPORT
+# (gdb) source tests/gdbstub_test.gdb
+
+define ipxe_load_symbols
+ file bin/ipxe.hd.tmp
+end
+
+define ipxe_assert
+ if $arg0 != $arg1
+ echo FAIL $arg2\n
+ else
+ echo PASS $arg2\n
+ end
+end
+
+define ipxe_start_tests
+ jump gdbstub_test
+end
+
+define ipxe_test_regs_read
+ ipxe_assert $eax 0xea010203 "ipxe_test_regs_read eax"
+ ipxe_assert $ebx 0xeb040506 "ipxe_test_regs_read ebx"
+ ipxe_assert $ecx 0xec070809 "ipxe_test_regs_read ecx"
+ ipxe_assert $edx 0xed0a0b0c "ipxe_test_regs_read edx"
+ ipxe_assert $esi 0x510d0e0f "ipxe_test_regs_read esi"
+ ipxe_assert $edi 0xd1102030 "ipxe_test_regs_read edi"
+end
+
+define ipxe_test_regs_write
+ set $eax = 0xea112233
+ set $ebx = 0xeb445566
+ set $ecx = 0xec778899
+ set $edx = 0xedaabbcc
+ set $esi = 0x51ddeeff
+ set $edi = 0xd1010203
+ c
+ ipxe_assert $eax 0xea112233 "ipxe_test_regs_write eax"
+ ipxe_assert $ebx 0xeb445566 "ipxe_test_regs_write ebx"
+ ipxe_assert $ecx 0xec778899 "ipxe_test_regs_write ecx"
+ ipxe_assert $edx 0xedaabbcc "ipxe_test_regs_write edx"
+ ipxe_assert $esi 0x51ddeeff "ipxe_test_regs_write esi"
+ ipxe_assert $edi 0xd1010203 "ipxe_test_regs_write edi"
+
+ # This assumes segment selectors are always 0x10 or 0x8 (for code).
+ ipxe_assert $cs 0x08 "ipxe_test_regs_write cs"
+ ipxe_assert $ds 0x10 "ipxe_test_regs_write ds"
+end
+
+define ipxe_test_mem_read
+ c
+ ipxe_assert ({int}($esp+4)) 0x11223344 "ipxe_test_mem_read int"
+ ipxe_assert ({short}($esp+2)) 0x5566 "ipxe_test_mem_read short"
+ ipxe_assert ({char}($esp)) 0x77 "ipxe_test_mem_read char"
+end
+
+define ipxe_test_mem_write
+ set ({int}($esp+4)) = 0xaabbccdd
+ set ({short}($esp+2)) = 0xeeff
+ set ({char}($esp)) = 0x99
+ c
+ ipxe_assert ({int}($esp+4)) 0xaabbccdd "ipxe_test_mem_write int"
+ ipxe_assert ({short}($esp+2)) (short)0xeeff "ipxe_test_mem_write short"
+ ipxe_assert ({char}($esp)) (char)0x99 "ipxe_test_mem_write char"
+end
+
+define ipxe_test_step
+ c
+ si
+ ipxe_assert ({char}($eip-1)) (char)0x90 "ipxe_test_step" # nop = 0x90
+end
+
+define ipxe_test_awatch
+ awatch watch_me
+
+ c
+ ipxe_assert $ecx 0x600d0000 "ipxe_test_awatch read"
+ if $ecx == 0x600d0000
+ c
+ end
+
+ c
+ ipxe_assert $ecx 0x600d0001 "ipxe_test_awatch write"
+ if $ecx == 0x600d0001
+ c
+ end
+
+ delete
+end
+
+define ipxe_test_watch
+ watch watch_me
+ c
+ ipxe_assert $ecx 0x600d0002 "ipxe_test_watch"
+ if $ecx == 0x600d0002
+ c
+ end
+ delete
+end
+
+ipxe_load_symbols
+ipxe_start_tests
+ipxe_test_regs_read
+ipxe_test_regs_write
+ipxe_test_mem_read
+ipxe_test_mem_write
+ipxe_test_step
+ipxe_test_awatch
+ipxe_test_watch