Import QEMU upstream snapshot d2e570c

Upstream: https://gitlab.com/qemu-project/qemu.git

Upstream-Commit: d2e570cc0f97b936902a5b1b86b73c0f5998b475
This commit is contained in:
2026-08-31 02:15:30 +02:00
commit cf256aa081
11315 changed files with 3598369 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
CC=gcc
CCFLAGS=-m32 -Wall -Wextra -Werror -fno-stack-protector -nostdinc -fno-builtin
ASFLAGS=-m32
LD=ld
LDFLAGS_ELF=-melf_i386 -T link.ld
LDFLAGS_BIN=-melf_i386 -T link.ld --oformat=binary
LIBS=$(shell $(CC) $(CCFLAGS) -print-libgcc-file-name)
AOUT_KLUDGE_BIN=$(foreach x,$(shell seq 1 9),aout_kludge_$x.bin)
all: mmap.elf modules.elf $(AOUT_KLUDGE_BIN)
mmap.elf: start.o mmap.o libc.o link.ld
$(LD) $(LDFLAGS_ELF) -o $@ $^ $(LIBS)
modules.elf: start.o modules.o libc.o link.ld
$(LD) $(LDFLAGS_ELF) -o $@ $^ $(LIBS)
aout_kludge_%.bin: aout_kludge_%.o link.ld
$(LD) $(LDFLAGS_BIN) -o $@ $^ $(LIBS)
.PRECIOUS: aout_kludge_%.o
aout_kludge_%.o: aout_kludge.S
$(CC) $(ASFLAGS) -DSCENARIO=$* -c -o $@ $^
%.o: %.c
$(CC) $(CCFLAGS) -c -o $@ $^
%.o: %.S
$(CC) $(ASFLAGS) -c -o $@ $^
+138
View File
@@ -0,0 +1,138 @@
/*
* Copyright (c) 2018 Kevin Wolf <kwolf@redhat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
.section multiboot
#define MB_MAGIC 0x1badb002
#define MB_FLAGS 0x10000
#define MB_CHECKSUM -(MB_MAGIC + MB_FLAGS)
.align 4
.int MB_MAGIC
.int MB_FLAGS
.int MB_CHECKSUM
#define LAST_BYTE_VALUE 0xa5
/*
* Order of fields in the a.out kludge header fields:
*
* header_addr
* load_addr
* load_end_addr
* bss_end_addr
* entry_addr
*/
#if SCENARIO == 1
/* Well-behaved kernel file with explicit bss_end */
.int 0x100000
.int 0x100000
.int data_end
.int data_end
.int _start
#elif SCENARIO == 2
/* Well-behaved kernel file with default bss_end */
.int 0x100000
.int 0x100000
.int data_end
.int 0
.int _start
#elif SCENARIO == 3
/* Well-behaved kernel file with default load_end */
.int 0x100000
.int 0x100000
.int 0
.int 0
.int _start
#elif SCENARIO == 4
/* Well-behaved kernel file with load_end < data_end and bss > data_end */
#undef LAST_BYTE_VALUE
#define LAST_BYTE_VALUE 0
.int 0x100000
.int 0x100000
.int code_end
.int 0x140000
.int _start
#elif SCENARIO == 5
/* header < load */
.int 0x10000
.int 0x100000
.int data_end
.int data_end
.int _start
#elif SCENARIO == 6
/* load_end < load */
.int 0x100000
.int 0x100000
.int 0x10000
.int data_end
.int _start
#elif SCENARIO == 7
/* header much larger than in reality with default load_end */
.int 0x80000000
.int 0x100000
.int 0
.int data_end
.int _start
#elif SCENARIO == 8
/* bss_end < load_end - load (regression test for CVE-2018-7550) */
.int 0x100000
.int 0x100000
.int data_end
.int code_end
.int _start
#elif SCENARIO == 9
/* Default load_end_addr, load_addr + kernel_file_size > UINT32_MAX */
.int 0xfffff000
.int 0xfffff000
.int 0
.int 0xfffff001
.int _start
#else
#error Invalid SCENARIO
#endif
.section .text
.global _start
_start:
xor %eax, %eax
cmpb $LAST_BYTE_VALUE, last_byte
je passed
or $0x1, %eax
passed:
/* Test device exit */
outl %eax, $0xf4
cli
hlt
jmp .
code_end:
#if SCENARIO != 8
.space 8192
#endif
last_byte:
.byte 0xa5
data_end:
+42
View File
@@ -0,0 +1,42 @@
=== Running test case: aout_kludge_1.bin ===
=== Running test case: aout_kludge_2.bin ===
=== Running test case: aout_kludge_3.bin ===
=== Running test case: aout_kludge_4.bin ===
=== Running test case: aout_kludge_5.bin ===
qemu-system-x86_64: invalid load_addr address
=== Running test case: aout_kludge_6.bin ===
qemu-system-x86_64: invalid load_end_addr address
=== Running test case: aout_kludge_7.bin ===
qemu-system-x86_64: invalid header_addr address
=== Running test case: aout_kludge_8.bin ===
qemu-system-x86_64: invalid bss_end_addr address
=== Running test case: aout_kludge_9.bin ===
qemu-system-x86_64: kernel does not fit in address space
+151
View File
@@ -0,0 +1,151 @@
/*
* Copyright (c) 2013 Kevin Wolf <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "libc.h"
void* memcpy(void *dest, const void *src, int n)
{
char *d = dest;
const char *s = src;
while (n--) {
*d++ = *s++;
}
return dest;
}
static void print_char(char c)
{
outb(0xe9, c);
}
static void print_str(char *s)
{
while (*s) {
print_char(*s++);
}
}
static void print_num(uint64_t value, int base)
{
char digits[] = "0123456789abcdef";
char buf[32] = { 0 };
int i = sizeof(buf) - 2;
do {
buf[i--] = digits[value % base];
value /= base;
} while (value);
print_str(&buf[i + 1]);
}
void printf(const char *fmt, ...)
{
va_list ap;
uint64_t val;
char *str;
int base;
int has_long;
int alt_form;
va_start(ap, fmt);
for (; *fmt; fmt++) {
if (*fmt != '%') {
print_char(*fmt);
continue;
}
fmt++;
if (*fmt == '#') {
fmt++;
alt_form = 1;
} else {
alt_form = 0;
}
if (*fmt == 'l') {
fmt++;
if (*fmt == 'l') {
fmt++;
has_long = 2;
} else {
has_long = 1;
}
} else {
has_long = 0;
}
switch (*fmt) {
case 'x':
case 'p':
base = 16;
goto convert_number;
case 'd':
case 'i':
case 'u':
base = 10;
goto convert_number;
case 'o':
base = 8;
goto convert_number;
convert_number:
switch (has_long) {
case 0:
val = va_arg(ap, unsigned int);
break;
case 1:
val = va_arg(ap, unsigned long);
break;
case 2:
val = va_arg(ap, unsigned long long);
break;
}
if (alt_form && base == 16) {
print_str("0x");
}
print_num(val, base);
break;
case 's':
str = va_arg(ap, char*);
print_str(str);
break;
case '%':
print_char(*fmt);
break;
default:
print_char('%');
print_char(*fmt);
break;
}
}
va_end(ap);
}
+62
View File
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2013 Kevin Wolf <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef LIBC_H
#define LIBC_H
/* Integer types */
typedef unsigned long long uint64_t;
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
typedef signed long long int64_t;
typedef signed int int32_t;
typedef signed short int16_t;
typedef signed char int8_t;
typedef uint32_t uintptr_t;
/* stdarg.h */
typedef __builtin_va_list va_list;
#define va_start(ap, X) __builtin_va_start(ap, X)
#define va_arg(ap, type) __builtin_va_arg(ap, type)
#define va_end(ap) __builtin_va_end(ap)
/* Port I/O functions */
static inline void outb(uint16_t port, uint8_t data)
{
asm volatile ("outb %0, %1" : : "a" (data), "Nd" (port));
}
/* Misc functions */
void printf(const char *fmt, ...);
void* memcpy(void *dest, const void *src, int n);
#endif
+19
View File
@@ -0,0 +1,19 @@
ENTRY(_start)
SECTIONS
{
. = 0x100000;
.text : AT(ADDR(.text)) {
*(multiboot)
*(.text)
}
.data ALIGN(4096) : AT(ADDR(.data)) {
*(.data)
}
.rodata ALIGN(4096) : AT(ADDR(.rodata)) {
*(.rodata)
}
.bss ALIGN(4096) : {
*(.bss)
}
}
+56
View File
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2013 Kevin Wolf <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "libc.h"
#include "multiboot.h"
int test_main(uint32_t magic, struct mb_info *mbi)
{
uintptr_t entry_addr;
struct mb_mmap_entry *entry;
(void) magic;
printf("Lower memory: %dk\n", mbi->mem_lower);
printf("Upper memory: %dk\n", mbi->mem_upper);
printf("\ne820 memory map:\n");
for (entry_addr = mbi->mmap_addr;
entry_addr < mbi->mmap_addr + mbi->mmap_length;
entry_addr += entry->size + 4)
{
entry = (struct mb_mmap_entry*) entry_addr;
printf("%#llx - %#llx: type %d [entry size: %d]\n",
entry->base_addr,
entry->base_addr + entry->length,
entry->type,
entry->size);
}
printf("\nmmap start: %#x\n", mbi->mmap_addr);
printf("mmap end: %#x\n", mbi->mmap_addr + mbi->mmap_length);
printf("real mmap end: %#x\n", entry_addr);
return 0;
}
+92
View File
@@ -0,0 +1,92 @@
=== Running test case: mmap.elf ===
Lower memory: 639k
Upper memory: 129920k
e820 memory map:
0x0 - 0x9fc00: type 1 [entry size: 20]
0x9fc00 - 0xa0000: type 2 [entry size: 20]
0xf0000 - 0x100000: type 2 [entry size: 20]
0x100000 - 0x7fe0000: type 1 [entry size: 20]
0x7fe0000 - 0x8000000: type 2 [entry size: 20]
0xfffc0000 - 0x100000000: type 2 [entry size: 20]
mmap start: 0x9000
mmap end: 0x9090
real mmap end: 0x9090
=== Running test case: mmap.elf -m 1.1M ===
Lower memory: 639k
Upper memory: 104k
e820 memory map:
0x0 - 0x9fc00: type 1 [entry size: 20]
0x9fc00 - 0xa0000: type 2 [entry size: 20]
0xf0000 - 0x100000: type 2 [entry size: 20]
0x100000 - 0x11a000: type 1 [entry size: 20]
0xfffc0000 - 0x100000000: type 2 [entry size: 20]
mmap start: 0x9000
mmap end: 0x9078
real mmap end: 0x9078
=== Running test case: mmap.elf -m 2G ===
Lower memory: 639k
Upper memory: 2096000k
e820 memory map:
0x0 - 0x9fc00: type 1 [entry size: 20]
0x9fc00 - 0xa0000: type 2 [entry size: 20]
0xf0000 - 0x100000: type 2 [entry size: 20]
0x100000 - 0x7ffe0000: type 1 [entry size: 20]
0x7ffe0000 - 0x80000000: type 2 [entry size: 20]
0xfffc0000 - 0x100000000: type 2 [entry size: 20]
mmap start: 0x9000
mmap end: 0x9090
real mmap end: 0x9090
=== Running test case: mmap.elf -m 4G ===
Lower memory: 639k
Upper memory: 3144576k
e820 memory map:
0x0 - 0x9fc00: type 1 [entry size: 20]
0x9fc00 - 0xa0000: type 2 [entry size: 20]
0xf0000 - 0x100000: type 2 [entry size: 20]
0x100000 - 0xbffe0000: type 1 [entry size: 20]
0xbffe0000 - 0xc0000000: type 2 [entry size: 20]
0xfffc0000 - 0x100000000: type 2 [entry size: 20]
0x100000000 - 0x140000000: type 1 [entry size: 20]
mmap start: 0x9000
mmap end: 0x90a8
real mmap end: 0x90a8
=== Running test case: mmap.elf -m 8G ===
Lower memory: 639k
Upper memory: 3144576k
e820 memory map:
0x0 - 0x9fc00: type 1 [entry size: 20]
0x9fc00 - 0xa0000: type 2 [entry size: 20]
0xf0000 - 0x100000: type 2 [entry size: 20]
0x100000 - 0xbffe0000: type 1 [entry size: 20]
0xbffe0000 - 0xc0000000: type 2 [entry size: 20]
0xfffc0000 - 0x100000000: type 2 [entry size: 20]
0x100000000 - 0x240000000: type 1 [entry size: 20]
mmap start: 0x9000
mmap end: 0x90a8
real mmap end: 0x90a8
+1
View File
@@ -0,0 +1 @@
This is a test file that is used as a multiboot module.
+55
View File
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2015 Kevin Wolf <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "libc.h"
#include "multiboot.h"
int test_main(uint32_t magic, struct mb_info *mbi)
{
struct mb_module *mod;
unsigned int i;
(void) magic;
printf("Module list with %d entries at %x\n",
mbi->mods_count, mbi->mods_addr);
for (i = 0, mod = (struct mb_module*) mbi->mods_addr;
i < mbi->mods_count;
i++, mod++)
{
char buf[1024];
unsigned int size = mod->mod_end - mod->mod_start;
printf("[%p] Module: %x - %x (%d bytes) '%s'\n",
mod, mod->mod_start, mod->mod_end, size, mod->string);
/* Print test file, but remove the newline at the end */
if (size < sizeof(buf)) {
memcpy(buf, (void*) mod->mod_start, size);
buf[size - 1] = '\0';
printf(" Content: '%s'\n", buf);
}
}
return 0;
}
+38
View File
@@ -0,0 +1,38 @@
=== Running test case: modules.elf ===
Module list with 0 entries at 102000
=== Running test case: modules.elf -initrd module.txt ===
Module list with 1 entries at 102000
[102000] Module: 103000 - 103038 (56 bytes) 'module.txt'
Content: 'This is a test file that is used as a multiboot module.'
=== Running test case: modules.elf -initrd module.txt argument ===
Module list with 1 entries at 102000
[102000] Module: 103000 - 103038 (56 bytes) 'module.txt argument'
Content: 'This is a test file that is used as a multiboot module.'
=== Running test case: modules.elf -initrd module.txt argument,,with,,commas ===
Module list with 1 entries at 102000
[102000] Module: 103000 - 103038 (56 bytes) 'module.txt argument,with,commas'
Content: 'This is a test file that is used as a multiboot module.'
=== Running test case: modules.elf -initrd module.txt,module.txt argument,module.txt ===
Module list with 3 entries at 102000
[102000] Module: 103000 - 103038 (56 bytes) 'module.txt'
Content: 'This is a test file that is used as a multiboot module.'
[102010] Module: 104000 - 104038 (56 bytes) 'module.txt argument'
Content: 'This is a test file that is used as a multiboot module.'
[102020] Module: 105000 - 105038 (56 bytes) 'module.txt'
Content: 'This is a test file that is used as a multiboot module.'
+66
View File
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2013 Kevin Wolf <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MULTIBOOT_H
#define MULTIBOOT_H
#include "libc.h"
struct mb_info {
uint32_t flags;
uint32_t mem_lower;
uint32_t mem_upper;
uint32_t boot_device;
uint32_t cmdline;
uint32_t mods_count;
uint32_t mods_addr;
char syms[16];
uint32_t mmap_length;
uint32_t mmap_addr;
uint32_t drives_length;
uint32_t drives_addr;
uint32_t config_table;
uint32_t boot_loader_name;
uint32_t apm_table;
uint32_t vbe_control_info;
uint32_t vbe_mode_info;
uint16_t vbe_mode;
uint16_t vbe_interface_seg;
uint16_t vbe_interface_off;
uint16_t vbe_interface_len;
} __attribute__((packed));
struct mb_module {
uint32_t mod_start;
uint32_t mod_end;
uint32_t string;
uint32_t reserved;
} __attribute__((packed));
struct mb_mmap_entry {
uint32_t size;
uint64_t base_addr;
uint64_t length;
uint32_t type;
} __attribute__((packed));
#endif
+94
View File
@@ -0,0 +1,94 @@
#!/usr/bin/env bash
# Copyright (c) 2013 Kevin Wolf <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
QEMU=${QEMU:-"../../qemu-system-x86_64"}
run_qemu() {
local kernel=$1
shift
printf %b "\n\n=== Running test case: $kernel $* ===\n\n" >> test.log
$QEMU \
-kernel $kernel \
-display none \
-device isa-debugcon,chardev=stdio \
-chardev file,path=test.out,id=stdio \
-device isa-debug-exit,iobase=0xf4,iosize=0x4 \
"$@" >> test.log 2>&1
ret=$?
cat test.out >> test.log
debugexit=$((ret & 0x1))
ret=$((ret >> 1))
if [ $debugexit != 1 ]; then
printf %b "\e[31m ?? \e[0m $kernel $* (no debugexit used, exit code $ret)\n"
pass=0
elif [ $ret != 0 ]; then
printf %b "\e[31mFAIL\e[0m $kernel $* (exit code $ret)\n"
pass=0
fi
}
mmap() {
run_qemu mmap.elf
run_qemu mmap.elf -m 1.1M
run_qemu mmap.elf -m 2G
run_qemu mmap.elf -m 4G
run_qemu mmap.elf -m 8G
}
modules() {
run_qemu modules.elf
run_qemu modules.elf -initrd module.txt
run_qemu modules.elf -initrd "module.txt argument"
run_qemu modules.elf -initrd "module.txt argument,,with,,commas"
run_qemu modules.elf -initrd "module.txt,module.txt argument,module.txt"
}
aout_kludge() {
for i in $(seq 1 9); do
run_qemu aout_kludge_$i.bin
done
}
make all
for t in mmap modules aout_kludge; do
echo > test.log
pass=1
$t
if ! diff $t.out test.log > /dev/null 2>&1; then
printf %b "\e[31mFAIL\e[0m $t (output difference)\n"
diff -u $t.out test.log
pass=0
fi
if [ $pass == 1 ]; then
printf %b "\e[32mPASS\e[0m $t\n"
fi
done
+51
View File
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2013 Kevin Wolf <kwolf@redhat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
.section multiboot
#define MB_MAGIC 0x1badb002
#define MB_FLAGS 0x0
#define MB_CHECKSUM -(MB_MAGIC + MB_FLAGS)
.align 4
.int MB_MAGIC
.int MB_FLAGS
.int MB_CHECKSUM
.section .text
.global _start
_start:
mov $stack, %esp
push %ebx
push %eax
call test_main
/* Test device exit */
outl %eax, $0xf4
cli
hlt
jmp .
.section bss
.space 8192
stack: