From 57f911a4372ec937a679177a0ce50e37c40563c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 21 Mar 2005 17:54:13 +0000 Subject: [PATCH] Moved kernel/apps to tests/kernel/boot_floppy, removed boot_floppy stuff from kernel/Jamfile. Actually kernel/apps is still there as Subversion doesn't let me commit it -- I'll remove that later. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@11940 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/Jamfile | 218 ------ src/tests/kernel/boot_floppy/Jamfile | 39 + .../kernel/boot_floppy/cache_control.cpp | 58 ++ src/tests/kernel/boot_floppy/cpuinfo/Jamfile | 20 + .../kernel/boot_floppy/cpuinfo/cpuinfo.h | 105 +++ .../kernel/boot_floppy/cpuinfo/flag_arrays.c | 178 +++++ src/tests/kernel/boot_floppy/cpuinfo/main.c | 663 ++++++++++++++++ src/tests/kernel/boot_floppy/echo/Jamfile | 3 + src/tests/kernel/boot_floppy/echo/main.c | 79 ++ src/tests/kernel/boot_floppy/envtest/Jamfile | 3 + src/tests/kernel/boot_floppy/envtest/main.c | 66 ++ src/tests/kernel/boot_floppy/exec_test.c | 52 ++ src/tests/kernel/boot_floppy/false_main.c | 13 + src/tests/kernel/boot_floppy/fibo_main.c | 72 ++ src/tests/kernel/boot_floppy/filetest/Jamfile | 3 + src/tests/kernel/boot_floppy/filetest/main.c | 52 ++ src/tests/kernel/boot_floppy/fork_test.c | 33 + src/tests/kernel/boot_floppy/fortune/Jamfile | 7 + src/tests/kernel/boot_floppy/fortune/fortunes | 9 + src/tests/kernel/boot_floppy/fortune/main.c | 80 ++ src/tests/kernel/boot_floppy/hostname/Jamfile | 3 + src/tests/kernel/boot_floppy/hostname/main.c | 42 + src/tests/kernel/boot_floppy/init.c | 52 ++ src/tests/kernel/boot_floppy/ls/Jamfile | 8 + src/tests/kernel/boot_floppy/ls/main.c | 163 ++++ src/tests/kernel/boot_floppy/monitor_test.c | 44 ++ src/tests/kernel/boot_floppy/on_exit_thread.c | 43 + src/tests/kernel/boot_floppy/pipe_test.c | 97 +++ src/tests/kernel/boot_floppy/ps/Jamfile | 3 + src/tests/kernel/boot_floppy/ps/main.c | 72 ++ src/tests/kernel/boot_floppy/select_test.c | 48 ++ src/tests/kernel/boot_floppy/shell/Jamfile | 12 + src/tests/kernel/boot_floppy/shell/args.c | 80 ++ src/tests/kernel/boot_floppy/shell/args.h | 10 + src/tests/kernel/boot_floppy/shell/commands.c | 238 ++++++ src/tests/kernel/boot_floppy/shell/commands.h | 22 + .../kernel/boot_floppy/shell/file_utils.c | 129 +++ .../kernel/boot_floppy/shell/file_utils.h | 10 + src/tests/kernel/boot_floppy/shell/main.c | 117 +++ src/tests/kernel/boot_floppy/shell/parse.c | 583 ++++++++++++++ src/tests/kernel/boot_floppy/shell/parse.h | 22 + src/tests/kernel/boot_floppy/shell/script.c | 124 +++ src/tests/kernel/boot_floppy/shell/script.h | 27 + .../kernel/boot_floppy/shell/shell_defs.h | 71 ++ .../kernel/boot_floppy/shell/shell_history.c | 69 ++ .../kernel/boot_floppy/shell/shell_history.h | 16 + .../kernel/boot_floppy/shell/shell_vars.c | 372 +++++++++ .../kernel/boot_floppy/shell/shell_vars.h | 45 ++ .../kernel/boot_floppy/shell/statements.c | 741 ++++++++++++++++++ .../kernel/boot_floppy/shell/statements.h | 18 + src/tests/kernel/boot_floppy/sig_test.c | 122 +++ .../kernel/boot_floppy/sockettest/Jamfile | 3 + .../kernel/boot_floppy/sockettest/main.c | 57 ++ src/tests/kernel/boot_floppy/symlink/Jamfile | 3 + src/tests/kernel/boot_floppy/symlink/main.c | 22 + src/tests/kernel/boot_floppy/testapp/Jamfile | 3 + src/tests/kernel/boot_floppy/testapp/main.c | 521 ++++++++++++ .../kernel/boot_floppy/testdigit/Jamfile | 3 + src/tests/kernel/boot_floppy/testdigit/main.c | 47 ++ src/tests/kernel/boot_floppy/tests/Jamfile | 45 ++ .../kernel/boot_floppy/tests/fops_test.c | 69 ++ .../kernel/boot_floppy/tests/random_test.c | 43 + .../kernel/boot_floppy/tests/thread_test.c | 136 ++++ src/tests/kernel/boot_floppy/tls_test.c | 97 +++ src/tests/kernel/boot_floppy/true_main.c | 13 + src/tests/kernel/boot_floppy/uname/Jamfile | 3 + src/tests/kernel/boot_floppy/uname/main.c | 188 +++++ 67 files changed, 6191 insertions(+), 218 deletions(-) create mode 100644 src/tests/kernel/boot_floppy/Jamfile create mode 100644 src/tests/kernel/boot_floppy/cache_control.cpp create mode 100644 src/tests/kernel/boot_floppy/cpuinfo/Jamfile create mode 100644 src/tests/kernel/boot_floppy/cpuinfo/cpuinfo.h create mode 100644 src/tests/kernel/boot_floppy/cpuinfo/flag_arrays.c create mode 100644 src/tests/kernel/boot_floppy/cpuinfo/main.c create mode 100644 src/tests/kernel/boot_floppy/echo/Jamfile create mode 100644 src/tests/kernel/boot_floppy/echo/main.c create mode 100644 src/tests/kernel/boot_floppy/envtest/Jamfile create mode 100644 src/tests/kernel/boot_floppy/envtest/main.c create mode 100644 src/tests/kernel/boot_floppy/exec_test.c create mode 100644 src/tests/kernel/boot_floppy/false_main.c create mode 100644 src/tests/kernel/boot_floppy/fibo_main.c create mode 100644 src/tests/kernel/boot_floppy/filetest/Jamfile create mode 100644 src/tests/kernel/boot_floppy/filetest/main.c create mode 100644 src/tests/kernel/boot_floppy/fork_test.c create mode 100644 src/tests/kernel/boot_floppy/fortune/Jamfile create mode 100644 src/tests/kernel/boot_floppy/fortune/fortunes create mode 100644 src/tests/kernel/boot_floppy/fortune/main.c create mode 100644 src/tests/kernel/boot_floppy/hostname/Jamfile create mode 100644 src/tests/kernel/boot_floppy/hostname/main.c create mode 100644 src/tests/kernel/boot_floppy/init.c create mode 100644 src/tests/kernel/boot_floppy/ls/Jamfile create mode 100644 src/tests/kernel/boot_floppy/ls/main.c create mode 100644 src/tests/kernel/boot_floppy/monitor_test.c create mode 100644 src/tests/kernel/boot_floppy/on_exit_thread.c create mode 100644 src/tests/kernel/boot_floppy/pipe_test.c create mode 100644 src/tests/kernel/boot_floppy/ps/Jamfile create mode 100644 src/tests/kernel/boot_floppy/ps/main.c create mode 100644 src/tests/kernel/boot_floppy/select_test.c create mode 100644 src/tests/kernel/boot_floppy/shell/Jamfile create mode 100644 src/tests/kernel/boot_floppy/shell/args.c create mode 100644 src/tests/kernel/boot_floppy/shell/args.h create mode 100644 src/tests/kernel/boot_floppy/shell/commands.c create mode 100644 src/tests/kernel/boot_floppy/shell/commands.h create mode 100644 src/tests/kernel/boot_floppy/shell/file_utils.c create mode 100644 src/tests/kernel/boot_floppy/shell/file_utils.h create mode 100644 src/tests/kernel/boot_floppy/shell/main.c create mode 100644 src/tests/kernel/boot_floppy/shell/parse.c create mode 100644 src/tests/kernel/boot_floppy/shell/parse.h create mode 100644 src/tests/kernel/boot_floppy/shell/script.c create mode 100644 src/tests/kernel/boot_floppy/shell/script.h create mode 100644 src/tests/kernel/boot_floppy/shell/shell_defs.h create mode 100644 src/tests/kernel/boot_floppy/shell/shell_history.c create mode 100644 src/tests/kernel/boot_floppy/shell/shell_history.h create mode 100644 src/tests/kernel/boot_floppy/shell/shell_vars.c create mode 100644 src/tests/kernel/boot_floppy/shell/shell_vars.h create mode 100644 src/tests/kernel/boot_floppy/shell/statements.c create mode 100644 src/tests/kernel/boot_floppy/shell/statements.h create mode 100644 src/tests/kernel/boot_floppy/sig_test.c create mode 100644 src/tests/kernel/boot_floppy/sockettest/Jamfile create mode 100644 src/tests/kernel/boot_floppy/sockettest/main.c create mode 100644 src/tests/kernel/boot_floppy/symlink/Jamfile create mode 100644 src/tests/kernel/boot_floppy/symlink/main.c create mode 100644 src/tests/kernel/boot_floppy/testapp/Jamfile create mode 100644 src/tests/kernel/boot_floppy/testapp/main.c create mode 100644 src/tests/kernel/boot_floppy/testdigit/Jamfile create mode 100644 src/tests/kernel/boot_floppy/testdigit/main.c create mode 100644 src/tests/kernel/boot_floppy/tests/Jamfile create mode 100644 src/tests/kernel/boot_floppy/tests/fops_test.c create mode 100644 src/tests/kernel/boot_floppy/tests/random_test.c create mode 100644 src/tests/kernel/boot_floppy/tests/thread_test.c create mode 100644 src/tests/kernel/boot_floppy/tls_test.c create mode 100644 src/tests/kernel/boot_floppy/true_main.c create mode 100644 src/tests/kernel/boot_floppy/uname/Jamfile create mode 100644 src/tests/kernel/boot_floppy/uname/main.c diff --git a/src/kernel/Jamfile b/src/kernel/Jamfile index aaa8d9e828..305a656ae7 100644 --- a/src/kernel/Jamfile +++ b/src/kernel/Jamfile @@ -174,231 +174,13 @@ KernelLd libglue2.o : # libglue2.o is used for executables : no_gcc ; -KernelLd init : - libglue2.o - <$(SOURCE_GRIST)!apps>init.o - libroot.so - : $(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld - : - : - : beos/bin/init - ; - -KernelLd kernel_false : - libglue2.o - <$(SOURCE_GRIST)!apps>false_main.o - libroot.so - : $(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld - : - : - : beos/bin/false - ; - -KernelLd kernel_true : - libglue2.o - <$(SOURCE_GRIST)!apps>true_main.o - libroot.so - : $(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld - : - : - : beos/bin/true - ; - -KernelLd fibo : - libglue2.o - <$(SOURCE_GRIST)!apps>fibo_main.o - libroot.so - : $(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld - : - : - : beos/bin/fibo - ; - -KernelLd sig_test : - libglue2.o - <$(SOURCE_GRIST)!apps>sig_test.o - libroot.so - : $(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld - : - : - : beos/bin/sig_test - ; - -KernelLd monitor_test : - libglue2.o - <$(SOURCE_GRIST)!apps>monitor_test.o - libroot.so - : $(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld - : - : - : beos/bin/monitor_test - ; - -KernelLd kernel_fortune : - libglue2.o - <$(SOURCE_GRIST)!apps!fortune>main.o - libroot.so - : $(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld - : - : - : beos/bin/fortune - ; - -KernelConfigSection beos/etc/fortunes : data : $(SUBDIR)/apps/fortune/fortunes ; - -KernelLd kernel_ls : - libglue2.o - <$(SOURCE_GRIST)!apps!ls>main.o - libroot.so - : $(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld - : - : - : beos/bin/ls - ; - -KernelLd symlink : - libglue2.o - <$(SOURCE_GRIST)!apps!symlink>main.o - libroot.so - : $(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld - : - : - : beos/bin/symlink - ; - -KernelLd consoled : - libglue2.o - <$(SOURCE_GRIST)!apps!consoled>consoled.o - libroot.so - : $(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld - : - : - : beos/bin/consoled - ; - -# Note: shell is a built in target, thus we need the grist. -KernelLd obos_shell : - libglue2.o - <$(SOURCE_GRIST)!apps!shell>main.o - <$(SOURCE_GRIST)!apps!shell>args.o - <$(SOURCE_GRIST)!apps!shell>commands.o - <$(SOURCE_GRIST)!apps!shell>file_utils.o - <$(SOURCE_GRIST)!apps!shell>parse.o - <$(SOURCE_GRIST)!apps!shell>script.o - <$(SOURCE_GRIST)!apps!shell>shell_vars.o - <$(SOURCE_GRIST)!apps!shell>statements.o - <$(SOURCE_GRIST)!apps!shell>shell_history.o - libroot.so - : $(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld - : - : - : beos/bin/sh - ; - -KernelLd testapp : - libglue2.o - <$(SOURCE_GRIST)!apps!testapp>main.o - libroot.so - : $(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld - : - : - : beos/bin/testapp - ; - -KernelLd tls_test : - libglue2.o - <$(SOURCE_GRIST)!apps>tls_test.o - libroot.so - : $(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld - : - : - : beos/bin/tls_test - ; - -KernelLd pipe_test : - libglue2.o - <$(SOURCE_GRIST)!apps>pipe_test.o - libroot.so - : $(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld - : - : - : beos/bin/pipe_test - ; - -KernelLd fork_test : - libglue2.o - <$(SOURCE_GRIST)!apps>fork_test.o - libroot.so - : $(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld - : - : - : beos/bin/fork_test - ; - -KernelConfigSection drivers/dev/tty - : elf32 - : $(OBOS_TOP)/distro/$(OBOS_ARCH).R1/beos/system/add-ons/kernel/drivers/dev/tty - ; - -KernelConfigSection drivers/dev/console - : elf32 - : $(OBOS_TOP)/distro/$(OBOS_ARCH).R1/beos/system/add-ons/kernel/drivers/dev/console - ; - -KernelConfigSection addons/kernel/console/vga_text - : elf32 - : $(OBOS_TOP)/distro/$(OBOS_ARCH).R1/beos/system/add-ons/kernel/console/vga_text - ; - -KernelLd kernel_ps : - libglue2.o - <$(SOURCE_GRIST)!apps!ps>main.o - libroot.so - : $(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld - : - : - : beos/bin/ps - ; - -KernelLd kernel_echo : - libglue2.o - <$(SOURCE_GRIST)!apps!echo>main.o - libroot.so - : $(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld - : - : - : beos/bin/echo - ; - -KernelLd kernel_uname : - libglue2.o - <$(SOURCE_GRIST)!apps!uname>main.o - libroot.so - : $(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld - : - : - : beos/bin/uname - ; WriteKernelConfig $(OBOS_KERNEL_CONFIG) ; - BuildKernel $(OBOS_KERNEL) : $(OBOS_KERNEL_CONFIG) ; -KernelFloppyImage $(OBOS_FLOPPY) : $(OBOS_KERNEL) : $(SUBDIR)/boot/arch/$(OBOS_ARCH)/bootblock.bin ; - Depends kernel.so : kernel ; # kernel.so will be rebuilt with the kernel -Depends $(OBOS_FLOPPY) : tty ; -Depends $(OBOS_FLOPPY) : console ; -Depends $(OBOS_FLOPPY) : vga_text ; - -Depends boot_floppy : $(OBOS_FLOPPY) ; -NotFile boot_floppy ; -Depends bootfloppy : $(OBOS_FLOPPY) ; -NotFile bootfloppy ; - -SubInclude OBOS_TOP src kernel apps ; SubInclude OBOS_TOP src kernel boot ; SubInclude OBOS_TOP src kernel core ; SubInclude OBOS_TOP src kernel glue ; diff --git a/src/tests/kernel/boot_floppy/Jamfile b/src/tests/kernel/boot_floppy/Jamfile new file mode 100644 index 0000000000..aaf64c0e83 --- /dev/null +++ b/src/tests/kernel/boot_floppy/Jamfile @@ -0,0 +1,39 @@ +SubDir OBOS_TOP src kernel apps ; + +KernelObjects + exec_test.c + false_main.c + fibo_main.c + fork_test.c + init.c + monitor_test.c + pipe_test.c + true_main.c + sig_test.c + select_test.c + tls_test.c + on_exit_thread.c + ; + +UsePrivateHeaders kernel ; +# UsePrivateHeaders [ FDirName kernel arch ] ; +UsePrivateHeaders [ FDirName kernel arch $(OBOS_ARCH) ] ; +UsePrivateHeaders [ FDirName kernel boot platform $(OBOS_BOOT_PLATFORM) ] ; + +if $(OBOS_ARCH) = x86 { + SubInclude OBOS_TOP src kernel apps cpuinfo ; +} + +SubInclude OBOS_TOP src kernel apps echo ; +SubInclude OBOS_TOP src kernel apps filetest ; +SubInclude OBOS_TOP src kernel apps fortune ; +SubInclude OBOS_TOP src kernel apps hostname ; +SubInclude OBOS_TOP src kernel apps ls ; +SubInclude OBOS_TOP src kernel apps symlink ; +SubInclude OBOS_TOP src kernel apps ps ; +SubInclude OBOS_TOP src kernel apps shell ; +SubInclude OBOS_TOP src kernel apps envtest ; +#SubInclude OBOS_TOP src kernel apps sockettest ; +SubInclude OBOS_TOP src kernel apps testapp ; +SubInclude OBOS_TOP src kernel apps tests ; +SubInclude OBOS_TOP src kernel apps uname ; diff --git a/src/tests/kernel/boot_floppy/cache_control.cpp b/src/tests/kernel/boot_floppy/cache_control.cpp new file mode 100644 index 0000000000..a9118c9160 --- /dev/null +++ b/src/tests/kernel/boot_floppy/cache_control.cpp @@ -0,0 +1,58 @@ +/* + * Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include + +#include + +#include +#include + + +extern const char *__progname; + + +void +usage() +{ + fprintf(stderr, "usage: %s [clear | unset | set ]\n", __progname); + exit(0); +} + + +int +main(int argc, char **argv) +{ + uint32 version = 0; + status_t status = _kern_generic_syscall(CACHE_SYSCALLS, B_SYSCALL_INFO, &version, sizeof(version)); + if (status != B_OK) { + fprintf(stderr, "%s: The cache syscalls are not available on this system.\n", __progname); + return 1; + } + + if (argc < 2) + usage(); + + if (!strcmp(argv[1], "clear")) { + status = _kern_generic_syscall(CACHE_SYSCALLS, CACHE_CLEAR, NULL, 0); + if (status != B_OK) + fprintf(stderr, "%s: clearing the cache failed: %s\n", __progname, strerror(status)); + } else if (!strcmp(argv[1], "unset")) { + status = _kern_generic_syscall(CACHE_SYSCALLS, CACHE_SET_MODULE, NULL, 0); + if (status != B_OK) + fprintf(stderr, "%s: unsetting the cache module failed: %s\n", __progname, strerror(status)); + } else if (!strcmp(argv[1], "set") && argc > 2) { + status = _kern_generic_syscall(CACHE_SYSCALLS, CACHE_SET_MODULE, argv[2], strlen(argv[2])); + if (status != B_OK) + fprintf(stderr, "%s: setting the module failed: %s\n", __progname, strerror(status)); + } else + usage(); + + return 0; +} + diff --git a/src/tests/kernel/boot_floppy/cpuinfo/Jamfile b/src/tests/kernel/boot_floppy/cpuinfo/Jamfile new file mode 100644 index 0000000000..7f32bc0e8c --- /dev/null +++ b/src/tests/kernel/boot_floppy/cpuinfo/Jamfile @@ -0,0 +1,20 @@ +SubDir OBOS_TOP src kernel apps cpuinfo ; + +KernelObjects + <$(SOURCE_GRIST)>main.c + : + -fpic + ; + +KernelLd cpuinfo : + libglue2.o + <$(SOURCE_GRIST)>main.o + libroot.so + : + $(OBOS_TOP)/src/kernel/ldscripts/$(OBOS_ARCH)/app.ld + : + : + : + bin/cpuinfo + ; + diff --git a/src/tests/kernel/boot_floppy/cpuinfo/cpuinfo.h b/src/tests/kernel/boot_floppy/cpuinfo/cpuinfo.h new file mode 100644 index 0000000000..7691cc6baa --- /dev/null +++ b/src/tests/kernel/boot_floppy/cpuinfo/cpuinfo.h @@ -0,0 +1,105 @@ + +// cache-type codes +enum cache_types { + Unused, + Inst_TLB, + Data_TLB, + L1_Inst_Cache, + L1_Data_Cache, + L2_Cache, + L3_Cache, + No_L2_Or_L3, + Trace_Cache +}; + + +// an entry in the TLB/Cache table +typedef struct { + uint8 descriptor; + uint8 cache_type; + char text[70]; +} tlbc_info; + + +// +// the global TLB/Cache table +// technical reference: +// "Intel Processor Identification and the CPUID instruction" +// (ftp://ftp.intel.com/docs/24161821.pdf) +// Page 18 + +static tlbc_info +Intel_TLB_Cache_Table[] = { + {0x0, 0, ""}, + {0x1, Inst_TLB, "4KB pages, 4-way set associative, 32 entries"}, + {0x2, Inst_TLB, "4MB pages, fully associative, 2 entries"}, + {0x50, Inst_TLB, "4KB, 2MB or 4MB pages, fully associative, 64 entries"}, + {0x51, Inst_TLB, "4KB, 2MB or 4MB pages, fully associative, 128 entries"}, + {0x52, Inst_TLB, "4KB, 2MB or 4MB pages, fully associative, 256 entries"}, + + {0x3, Data_TLB, "4KB pages, 4-way set associative, 64 entries"}, + {0x4, Data_TLB, "4MB pages, 4-way set associative, 8 entries"}, + {0x5b, Data_TLB, "4KB or 4MB pages, fully associative, 64 entries"}, + {0x5c, Data_TLB, "4KB or 4MB pages, fully associative, 128 entries"}, + {0x5d, Data_TLB, "4KB or 4MB pages, fully associative, 256 entries"}, + + {0x6, L1_Inst_Cache, "8KB pages, 4-way set associative, 32 byte line size"}, + {0x8, L1_Inst_Cache, "16KB pages, 4-way set associative, 32 byte line size"}, + + {0xa, L1_Data_Cache, "8KB pages, 2-way set associative, 32 byte line size"}, + {0xc, L1_Data_Cache, "16KB pages, 4-way set associative, 32 byte line size"}, + {0x66, L1_Data_Cache, "8KB pages, 4-way set associative, 64 byte line size"}, + {0x67, L1_Data_Cache, "16KB pages, 4-way set associative, 64 byte line size"}, + {0x68, L1_Data_Cache, "32KB pages, 4-way set associative, 64 byte line size"}, + + {0x39, L2_Cache, "128KB pages, 4-way set associative, sectored, 64 byte line size"}, + {0x3c, L2_Cache, "256KB pages, 4-way set associative, sectored, 64 byte line size"}, + {0x41, L2_Cache, "128KB pages, 4-way set associative, 32 byte line size"}, + {0x42, L2_Cache, "256KB pages, 4-way set associative, 32 byte line size"}, + {0x43, L2_Cache, "512KB pages, 4-way set associative, 32 byte line size"}, + {0x44, L2_Cache, "1MB pages, 4-way set associative, 32 byte line size"}, + {0x45, L2_Cache, "2MB pages, 4-way set associative, 32 byte line size"}, + {0x79, L2_Cache, "128KB pages, 8-way set associative, sectored, 64 byte line size"}, + {0x7a, L2_Cache, "256KB pages, 8-way set associative, sectored, 64 byte line size"}, + {0x7b, L2_Cache, "512KB pages, 8-way set associative, sectored, 64 byte line size"}, + {0x7c, L2_Cache, "1MB pages, 8-way set associative, sectored, 64 byte line size"}, + {0x82, L2_Cache, "256KB pages, 8-way set associative, 32 byte line size"}, + {0x83, L2_Cache, "512KB pages, 8-way set associative, 32 byte line size"}, + {0x84, L2_Cache, "1MB pages, 8-way set associative, 32 byte line size"}, + {0x85, L2_Cache, "2MB pages, 8-way set associative, 32 byte line size"}, + + {0x40, No_L2_Or_L3, "No 2nd-level cache, or if 2nd-level cache exists, no 3rd-level cache\n"}, + + {0x22, L3_Cache, "512KB pages, 4-way set associative, sectored, 64 byte line size"}, + {0x23, L3_Cache, "1MB pages, 8-way set associative, sectored, 64 byte line size"}, + {0x25, L3_Cache, "2MB pages, 8-way set associative, sectored, 64 byte line size"}, + {0x29, L3_Cache, "4MB pages, 8-way set associative, sectored, 64 byte line size"}, + + {0x70, Trace_Cache, "Trace cache: 12K-uops, 8-way set associative\n"}, + {0x71, Trace_Cache, "Trace cache: 16K-uops, 8-way set associative\n"}, + {0x72, Trace_Cache, "Trace cache: 32K-uops, 8-way set associative\n"}, +}; + + + + +void AMD_identify (cpuid_info *); +void AMD_features (cpuid_info *); +void AMD_TLB_cache (cpuid_info *); +void Cyrix_identify (cpuid_info *); +void Cyrix_features (cpuid_info *); +void Cyrix_TLB_cache (cpuid_info *); +void Intel_identify (cpuid_info *); +void Intel_features (cpuid_info *); +void Intel_TLB_cache (cpuid_info *); + +const char *Intel_brand_string (int, int); +void dump_regs (cpuid_info *, const char *, uint32, uint32); +char getoption (char *); +void insert (int *, int, int); +void opt_identify (cpuid_info *, int); +void opt_features (cpuid_info *, int); +void opt_TLB_cache (cpuid_info *, int); +void opt_dump_calls (cpuid_info *, uint32); +void print_regs (cpuid_info *); +void usage (void); diff --git a/src/tests/kernel/boot_floppy/cpuinfo/flag_arrays.c b/src/tests/kernel/boot_floppy/cpuinfo/flag_arrays.c new file mode 100644 index 0000000000..ff37c632a0 --- /dev/null +++ b/src/tests/kernel/boot_floppy/cpuinfo/flag_arrays.c @@ -0,0 +1,178 @@ + +static char *Intel_feature_flags[32] = { + "FPU Floating Point Unit", + "VME Virtual 8086 Mode Enhancements", + "DE Debugging Extensions", + "PSE Page Size Extensions", + "TSC Time Stamp Counter", + "MSR Model Specific Registers", + "PAE Physical Address Extension", + "MCE Machine Check Exception", + "CX8 COMPXCHG8B Instruction", + "APIC On-chip Advanced Programmable Interrupt Controller", + "10 Reserved", + "SEP Fast System Call", + "MTRR Memory Type Range Registers", + "PGE PTE Global Flag", + "MCA Machine Check Architecture", + "CMOV Conditional Move and Compare Instructions", + "FGPAT Page Attribute Table", + "PSE-36 36-bit Page Size Extension", + "PN Processor Serial Number present and enabled", + "CLFSH CFLUSH instruction", + "20 reserved", + "DS Debug store", + "ACPI Thermal Monitor and Clock Ctrl", + "MMX MMX instruction set", + "FXSR Fast FP/MMX Streaming SIMD Extensions save/restore", + "SSE Streaming SIMD Extensions instruction set", + "SSE2 SSE2 extensions", + "SS Self Snoop", + "HT Hyper Threading", + "TM Thermal monitor", + "30 reserved", + "31 reserved" +}; + +#if 0 +static char *AMD_feature_flags[32] = { + "Floating Point Unit", + "Virtual Mode Extensions", + "Debugging Extensions", + "Page Size Extensions", + "Time Stamp Counter (with RDTSC and CR4 disable bit)", + "Model Specific Registers with RDMSR & WRMSR", + "PAE - Page Address Extensions", + "Machine Check Exception", + "COMPXCHG8B Instruction", + "APIC", + "10 - Reserved", + "SYSCALL/SYSRET or SYSENTER/SYSEXIT instructions", + "MTRR - Memory Type Range Registers", + "Global paging extension", + "Machine Check Architecture", + "Conditional Move Instruction", + "PAT - Page Attribute Table", + "PSE-36 - Page Size Extensions", + "18 - reserved", + "19 - reserved", + "20 - reserved", + "21 - reserved", + "AMD MMX Instruction Extensions", + "MMX instructions", + "FXSAVE/FXRSTOR", + "25 - reserved", + "26 - reserved", + "27 - reserved", + "28 - reserved", + "29 - reserved", + "3DNow! Instruction Extensions", + "3DNow instructions" +}; + + +static char *Cyrix_standard_feature_flags_5[32] = { + "FPU Floating Point Unit", + "V86 Virtual Mode Extensions", + "Debug Extension", + "4MB Page Size", + "Time Stamp Counter", + "RDMSR/WRMSR (Model Specific Registers)", + "PAE", + "Machine Check Exception", + "COMPXCHG8B Instruction", + "APIC - On-chip Advanced Programmable Interrupt Controller", + "10 - Reserved", + "11 - Reserved", + "MTRR Memory Type Range Registers", + "13 - reserved", + "Machine Check", + "CMOV Conditional Move Instruction", + "16 - reserved", + "17 - reserved", + "18 - reserved", + "19 - reserved", + "20 - reserved", + "21 - reserved", + "22 - reserved", + "MMX instructions", + "24 - reserved", + "25 - reserved", + "26 - reserved", + "27 - reserved", + "28 - reserved", + "29 - reserved", + "30 - reserved" +}; + + +static char *Cyrix_standard_feature_flags_not5[32] = { + "FPU Floating Point Unit", + "V86 Virtual Mode Extensions", + "Debug Extension", + "4MB Page Size", + "Time Stamp Counter", + "RDMSR/WRMSR (Model Specific Registers)", + "PAE", + "Machine Check Exception", + "COMPXCHG8B Instruction", + "APIC - On-chip Advanced Programmable Interrupt Controller", + "10 - Reserved", + "11 - Reserved", + "MTRR Memory Type Range Registers", + "Global Paging Extension", + "Machine Check", + "CMOV Conditional Move Instruction", + "16 - reserved", + "17 - reserved", + "18 - reserved", + "19 - reserved", + "20 - reserved", + "21 - reserved", + "22 - reserved", + "MMX instructions", + "24 - reserved", + "25 - reserved", + "26 - reserved", + "27 - reserved", + "28 - reserved", + "29 - reserved", + "30 - reserved" +}; + + +static char *Cyrix_extended_feature_flags[32] = { + "FPU Floating Point Unit", + "V86 Virtual Mode Extensions", + "Debug Extension", + "Page Size Extensions", + "Time Stamp Counter", + "Cyrix MSR", + "PAE", + "MC Exception", + "COMPXCHG8B", + "APIC on chip", + "SYSCALL/SYSRET", + "11 - reserved", + "MTRR", + "Global bit", + "Machine Check", + "CMOV", + "FPU CMOV", + "17 - reserved", + "18 - reserved", + "19 - reserved", + "20 - reserved", + "21 - reserved", + "22 - reserved", + "MMX", + "Extended MMX", + "25 - reserved", + "26 - reserved", + "27 - reserved", + "28 - reserved", + "29 - reserved", + "30 - reserved", + "3DNow instructions" +}; +#endif diff --git a/src/tests/kernel/boot_floppy/cpuinfo/main.c b/src/tests/kernel/boot_floppy/cpuinfo/main.c new file mode 100644 index 0000000000..27cfac32a9 --- /dev/null +++ b/src/tests/kernel/boot_floppy/cpuinfo/main.c @@ -0,0 +1,663 @@ +#include +#include +#include +#include + +#include "cpuinfo.h" +#include "flag_arrays.c" + + + +extern char *__progname; +static cpuid_info CPU_Data; + + +void +usage() +{ + printf("usage: %s [-option]\n\n" + "Prints information about your CPU.\n" + " -i CPU identification\n" + " -f supported processor features\n" + " -t TLB and cache info\n" + " -d dump registers from CPUID calls\n", __progname); + + exit(0); +} + + +char +getoption(char *optstr) +{ + if ((optstr[0] != '-') + || (strlen(optstr) > 2) + || (strchr("iftd", optstr[1]) == NULL)) + // invalid option + usage(); + + return optstr[1]; +} + + +int +main(int argc, char *argv[]) +{ + // this program prints out everything you would ever want to know about + // your computer's processor, or your money back, in full (30 days, no hassle) + // + // technical reference: + // "Intel Processor Identification and the CPUID Instruction" + // (ftp://download.intel.com/design/Xeon/applnots/24161821.pdf) + + const char *no_support = "Sorry, your processor does not support this feature\n"; + + char option = 0; + int vendor_tag; + uint32 max_level; + cpuid_info *info = &CPU_Data; + + if (argc == 2) + option = getoption(argv[1]); + else + usage(); + + // get initial info (max_level and vendor_tag) + get_cpuid(info, 0, 0); + max_level = info->eax_0.max_eax; + vendor_tag = info->regs.ebx; + + switch (option) { + case 'i': + printf("CPU identification:\n\n"); + if (max_level < 1) + printf(no_support); + else + opt_identify(info, vendor_tag); + break; + + case 'f': + printf("Supported processor features:\n\n"); + if (max_level < 1) + printf(no_support); + else + opt_features(info, vendor_tag); + break; + + case 't': + printf("TLB and cache information:\n\n"); + if (max_level < 2) + printf(no_support); + else + opt_TLB_cache(info, vendor_tag); + break; + + case 'd': + printf("CPUID instruction call dump:\n\n"); + opt_dump_calls(info, max_level); + break; + } + + return 0; +} + + +void +opt_identify(cpuid_info *info, int vendor_tag) +{ + // gosh, these CPU manufacturers have really outdone + // themselves on creating cutesy vendorID strings, no? + // (that was sarcasm, btw...) + + char vendorID[12+1] = {0}; + + // the 'vendorid' field of the info struct is not null terminated, + // so it is copied into a properly terminated local string buffer + memcpy(vendorID, info->eax_0.vendor_id, 12); + printf("%12s '%s'\n", "Vendor ID:", vendorID); + + switch (vendor_tag) { + case 'uneG': // "GenuineIntel" + Intel_identify(info); + break; + + case 'htuA': // "AuthenticAMD" + AMD_identify(info); + break; + + case 'iryC': // "CyrixInstead" + Cyrix_identify(info); + break; + } +} + + +void +opt_features(cpuid_info *info, int vendor_tag) +{ + switch (vendor_tag) { + case 'uneG': // "GenuineIntel" + Intel_features(info); + break; + + case 'htuA': // "AuthenticAMD" + AMD_features(info); + break; + + case 'iryC': // "CyrixInstead" + Cyrix_features(info); + break; + } +} + + +void +opt_TLB_cache(cpuid_info *info, int vendor_tag) +{ + switch (vendor_tag) { + case 'uneG': // "GenuineIntel" + Intel_TLB_cache(info); + break; + + case 'htuA': // "AuthenticAMD" + AMD_TLB_cache(info); + break; + + case 'iryC': // "CyrixInstead" + Cyrix_TLB_cache(info); + break; + } +} + + + + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// Intel specs + +void +Intel_identify(cpuid_info *info) +{ + // the code for this function looks very boring and tedious + // (that's because it's very boring and tedious) + // but I think it's correct anyway (there's always that possibility!) + + int type, family, model, sig; + + get_cpuid(info, 1, 0); + type = info->eax_1.type; + family = info->eax_1.family; + model = info->eax_1.model; + + sig = info->regs.eax; + printf("%12s 0x%08X\n", "Signature:", sig); + + printf("%12s %2d '", "Type:", type); + if (type == 0) printf("Original OEM"); + else if (type == 1) printf("Overdrive"); + else if (type == 2) printf("Dual-capable"); + else if (type == 3) printf("Reserved"); + printf("'\n"); + + printf("%12s %2d '", "Family:", family); + if (family == 3) printf("i386"); + else if (family == 4) printf("i486"); + else if (family == 5) printf("Pentium"); + else if (family == 6) printf("Pentium Pro"); + else if (family == 15) printf("Pentium 4"); + printf("'\n"); + + if (family == 15) { + int efamily = (info->regs.eax >> 20) & 0xff; + printf("Extended family: %d\n", efamily); + } + + printf("%12s %2d '", "Model:", model); + switch (family) { + case 3: + break; + case 4: + if (model == 0) printf("DX"); + else if (model == 1) printf("DX"); + else if (model == 2) printf("SX"); + else if (model == 3) printf("487/DX2"); + else if (model == 4) printf("SL"); + else if (model == 5) printf("SX2"); + else if (model == 7) printf("write-back enhanced DX2"); + else if (model == 8) printf("DX4"); + break; + case 5: + if (model == 1) printf("60/66"); + else if (model == 2) printf("75-200"); + else if (model == 3) printf("for 486 system"); + else if (model == 4) printf("MMX"); + break; + case 6: + if (model == 1) printf("Pentium Pro"); + else if (model == 3) printf("Pentium II Model 3"); + else if (model == 5) printf("Pentium II Model 5/Xeon/Celeron"); + else if (model == 6) printf("Celeron"); + else if (model == 7) printf("Pentium III/Pentium III Xeon - external L2 cache"); + else if (model == 8) printf("Pentium III/Pentium III Xeon - internal L2 cache"); + break; + case 15: + break; + } + printf("'\n"); + + if (model == 15) { + int emodel = (info->regs.eax >> 16) & 0xf; + printf("Extended model: %d\n", emodel); + } + + printf("%12s 0x%08lX\n", "Features:", info->eax_1.features); + + { + int id = info->regs.ebx & 0xff; + printf("%12s %2d '%s'\n", "Brand ID:", id, Intel_brand_string(id, sig)); + } + + printf("%12s %2d\n", "Stepping:", info->eax_1.stepping); + printf("%12s %2d\n", "Reserved:", info->eax_1.reserved_0); + + get_cpuid(info, 0x80000000, 0); + if (info->regs.eax & 0x80000000) { + // extended feature/signature bits supported + if (info->regs.eax >= 0x80000004) { + uint32 i; + + printf("\nExtended brand string:\n'"); + for (i = 0x80000002; i <= 0x80000004; ++i) { + get_cpuid(info, i, 0); + print_regs(info); + } + printf("'\n"); + } + } +} + + +const char * +Intel_brand_string(int id, int processor_signature) +{ + int sig = processor_signature; + + switch (id) { + case 0x0: return "Unsupported"; + case 0x1: return "Intel(R) Celeron(R) processor"; + case 0x2: return "Intel(R) Pentium(R) III processor"; + case 0x3: return (sig == 0x6B1) ? "Intel(R) Celeron(R) processor" : "Intel(R) Pentium(R) III Xeon(TM) processor"; + case 0x4: return "Intel(R) Pentium(R) III processor"; + case 0x5: return ""; + case 0x6: return "Mobile Intel(R) Pentium(R) III Processor-M"; + case 0x7: return "Mobile Intel(R) Celeron(R) processor"; + case 0x8: return (sig >= 0xF13) ? "Intel(R) Genuine processor" : "Intel(R) Pentium(R) 4 processor"; + case 0x9: return "Intel(R) Pentium(R) 4 processor"; + case 0xA: return "Intel(R) Celeron(R) processor"; + case 0xB: return (sig < 0xF13) ? "Intel(R) Xeon(TM) processor MP" : "Intel(R) Xeon(TM) processor"; + case 0xC: return "Intel(R) Xeon(TM) processor MP"; + case 0xD: return ""; + case 0xE: return (sig < 0xF13) ? "Intel(R) Xeon(TM) processor" : "Mobile Intel(R) Pentium(R) 4 Processor-M"; + case 0xF: return "Mobile Intel(R) Celeron(R) processor"; + default: + return ""; + } +} + + +void +Intel_features(cpuid_info *info) +{ + // for each bit set in the features flag, print out the + // corresponding index in the flags array (too easy!) + + int i; + int fflags; + + get_cpuid(info, 1, 0); + fflags = info->eax_1.features; + + for (i = 0; i < 32; ++i) + if (fflags & (1< lo; --i) + a[i] = a[i-1]; + + // insert the new guy + a[lo] = elem; +} + + +void +Intel_TLB_cache(cpuid_info *info) +{ + // displays technical info for the CPU's various instruction and data pipeline caches + // and the TLBs (Translation Lookaside Buffers). + // + // The method for extracting and displaying this info might be less than obvious, + // so here's an explanation: + // + // The TLB/Cache info is stored in a global table. Each entry is uniquely identified + // by a descriptor byte. Additionally, each entry is catagorized according to the + // cache type. A textual string contains the information to display. + // + // To retrieve the CPUs capabilities, the pass loop repeatedly (maybe) calls + // get_cpuid() which fills the registers. Each register is a 4-byte datum, + // capable of holding up to 4 descriptor bytes. The descriptor bytes are extracted + // (thru shifting and masking) and then inserted into a slot array. The slot array + // stores indexes into the table. Since descriptor bytes are not indexes themselves, + // an index array is created and used to convert them. The slot array is filled so + // as to keep the indexes in sorted order -- this guarantees than all entries for + // a particular cache type will display together. + // + // After the pass loop is finished, the slot array contains the indexes of all the + // table entries that apply to the host processor. Displaying the info is merely a matter + // of spinning thru the slot array and printing the text. The output, however, is organized + // by the cache types -- this technique *only* works because the TLB/Cache table has been + // carefully arranged in that order. + + #define BIT_31_MASK (1 << 31) + + uint32 pass, matches; // counters + uint32 reg; // value of an individual register (eax, ebx, ecx, edx) + uint8 db; // descriptor byte + int indexOf[256] = {0}; // converts descriptor bytes to table indexes + int slot[256] = {0}; // indexes into the TLB/Cache table (for entries found) + + tlbc_info *tab = Intel_TLB_Cache_Table; + int tabsize = sizeof Intel_TLB_Cache_Table / sizeof(Intel_TLB_Cache_Table[0]); + + // fill the index conversion array + int i = 0; + int n = 0; + + while (n < tabsize) + indexOf[tab[n++].descriptor] = i++; + + // pass loop: insert relevant table indexes into the slot array + i = 0; + for (pass = 0; ; ++pass) { + get_cpuid(info, 2, 0); + + // low byte of eax register holds maximum iterations + reg = info->regs.eax; + if (pass >= (reg & 0xff)) + break; + + reg >>= 8; // skip low byte + for (; reg; reg >>= 8) + if ((db = (reg & 0xff))) + insert(slot, indexOf[db], i++); + + reg = info->regs.ebx; // ebx + if ((reg & BIT_31_MASK) == 0) + for (; reg; reg >>= 8) + if ((db = (reg & 0xff))) + insert(slot, indexOf[db], i++); + + reg = info->regs.ecx; // ecx + if ((reg & BIT_31_MASK) == 0) + for (; reg; reg >>= 8) + if ((db = (reg & 0xff))) + insert(slot, indexOf[db], i++); + + reg = info->regs.edx; // edx + if ((reg & BIT_31_MASK) == 0) + for (; reg; reg >>= 8) + if ((db = (reg & 0xff))) + insert(slot, indexOf[db], i++); + } + + // reset slot index for output loop + i = 0; + + // eeiuw! an icky macro (but it really does prevent much repetitive code) + #define display_matching_entries(type_name,type_code) \ + printf(type_name ":\n"); \ + matches = 0; \ + while (tab[n = slot[i]].cache_type == type_code) { \ + printf(" %s\n", tab[n].text); \ + ++matches; \ + ++i; \ + } \ + if (matches == 0) \ + printf(" None\n") + + // at long last... output the data + display_matching_entries("Instruction TLB", Inst_TLB); + display_matching_entries("Data TLB", Data_TLB); + display_matching_entries("L1 Instruction Cache", L1_Inst_Cache); + display_matching_entries("L1 Data Cache", L1_Data_Cache); + display_matching_entries("L2 Cache", L2_Cache); + + if (tab[slot[i]].cache_type == No_L2_Or_L3) + // no need to print the text on this one, just skip it + ++i; + + display_matching_entries("L3 Cache", L3_Cache); + display_matching_entries("Trace Cache", Trace_Cache); +} + + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// AMD specs + +// Brennan says: I'm just digging around and trying to find AMD documentation +// on product signatures and CPU types...not easy to find. This is a dirty hack +// until I can find proper docs... + +static const char * +AMD_brand_string(int family, int model, int processor_signature) +{ + int sig = processor_signature; + + switch (family) { + //K5 and K6 models + case 0x5: + if(model >= 0x0 && model <= 0x3) { + return "AMD K5"; + } + else if(model == 0x8){ + return "AMD K6-2"; + } + else if(model == 0x9) { + return "AMD K6-III"; + } + else { + return "AMD K6"; + } + //Athlon and Duron models, very general + case 0x6: + //Hack. I own one, so I know this is the processor signature! + if(sig == 1634) { + return "AMD Mobile Athlon"; + } + else if(model == 0x1 || model == 0x2 || model == 0x4) { + return "AMD Athlon"; + } + else if(model == 0x3 ||model == 0x7) { + return "AMD Duron"; + } + else if(model == 0x6){ + return "AMD Duron/AMD Athlon XP/AMD Athlon MP"; + } + case 0xf: + if(model == 0x5) { + return "AMD Athlon 64"; + } + if(model == 0x6) { + return "AMD Opteron"; + } + //This is the new 266FSB Duron model + else if(model == 0x8) { + return "AMD Duron (266 FSB)"; + } + default: + return "Unknown AMD Processor"; + } +} + + +void +AMD_identify(cpuid_info *info) +{ + int type, family, model, sig; + const char *id_string; + + get_cpuid(info, 1, 0); + type = info->eax_1.type; + family = info->eax_1.family; + model = info->eax_1.model; + sig = info->regs.eax; + + id_string = AMD_brand_string(family, model, sig); + + printf("%s, Model: %d\n", id_string, model); + printf("Family: %d\n", family); + printf("Signature: %d\n", sig); + +} + + +void +AMD_features(cpuid_info *info) +{ + printf("Sorry! Info about AMD CPU's not implemented yet :(\n"); +} + + +void +AMD_TLB_cache(cpuid_info *info) +{ + printf("Sorry! Info about AMD CPU's not implemented yet :(\n"); +} + + + + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// Cyrix specs + + +void +Cyrix_identify(cpuid_info *info) +{ + printf("Sorry! Info about Cyrix CPU's not implemented yet :(\n"); +} + + +void +Cyrix_features(cpuid_info *info) +{ + printf("Sorry! Info about Cyrix CPU's not implemented yet :(\n"); +} + + +void +Cyrix_TLB_cache(cpuid_info *info) +{ + printf("Sorry! Info about Cyrix CPU's not implemented yet :(\n"); +} + + + + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// dumps + + +void +opt_dump_calls(cpuid_info *info, uint32 max_level) +{ + // dumps the registers for standard (and if supported) extended + // calls to the CPUID instruction + + uint32 max_extended; + + dump_regs(info, "Standard Calls", 0, max_level); + + get_cpuid(info, 0x80000000, 0); + max_extended = info->regs.eax; + + if (max_extended == 0) + printf("\nNo extended calls available for this CPU\n"); + else + dump_regs(info, "Extended Calls", 0x80000000, max_extended); +} + + +void +dump_regs(cpuid_info *info, const char *heading, uint32 min_level, uint32 max_level) +{ + // gosh, it's so perty (in a text-based output kind of way) + + uint32 i; + + printf("%s (max eax level = %lx)\n", heading, max_level); + printf("----------------------------------------------\n"); + printf(" Input | Output\n"); + printf("----------------------------------------------\n"); + printf(" eax | eax ebx ecx edx\n"); + + for (i = min_level; i <= max_level; ++i) { + get_cpuid(info, i, 0); + printf("%08lx | %08lx %08lx %08lx %08lx\n", + i, + info->regs.eax, + info->regs.ebx, + info->regs.ecx, + info->regs.edx); + } + printf("\n"); +} + + +void +print_regs(cpuid_info *info) +{ + // this function either prints the contents of all the + // registers as a single character string, or it does + // something else entirely (you decide) + + int i; + char s[17] = {0}; + + for (i = 0; i < 4; ++i) + s[i] = info->regs.eax >> (8*i), + s[i+4] = info->regs.ebx >> (8*i), + s[i+8] = info->regs.ecx >> (8*i), + s[i+12] = info->regs.edx >> (8*i); + + printf("%s", s); +} + diff --git a/src/tests/kernel/boot_floppy/echo/Jamfile b/src/tests/kernel/boot_floppy/echo/Jamfile new file mode 100644 index 0000000000..8db262a729 --- /dev/null +++ b/src/tests/kernel/boot_floppy/echo/Jamfile @@ -0,0 +1,3 @@ +SubDir OBOS_TOP src kernel apps echo ; + +KernelObjects <$(SOURCE_GRIST)>main.c : -fpic -Wno-unused ; diff --git a/src/tests/kernel/boot_floppy/echo/main.c b/src/tests/kernel/boot_floppy/echo/main.c new file mode 100644 index 0000000000..257dbb953d --- /dev/null +++ b/src/tests/kernel/boot_floppy/echo/main.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + +#include +#include +#include + + +int +main(int argc , char *argv[]) +{ + int nflag; /* if not set, output a trailing newline. */ + + /* This utility may NOT do getopt(3) option parsing. */ + if (*++argv && !strcmp(*argv, "-n")) { + ++argv; + nflag = 1; + } else + nflag = 0; + + while (argv[0] != NULL) { + + /* + * If the next argument is NULL then this is this + * the last argument, therefore we need to check + * for a trailing \c. + */ + if (argv[1] == NULL) { + size_t len; + + len = strlen(argv[0]); + /* is there room for a '\c' and is there one? */ + if (len >= 2 && + argv[0][len - 2] == '\\' && + argv[0][len - 1] == 'c') { + /* chop it and set the no-newline flag. */ + argv[0][len - 2] = '\0'; + nflag = 1; + } + } + (void)printf("%s", argv[0]); + if (*++argv) + putchar(' '); + } + if (!nflag) + putchar('\n'); + return 0; +} diff --git a/src/tests/kernel/boot_floppy/envtest/Jamfile b/src/tests/kernel/boot_floppy/envtest/Jamfile new file mode 100644 index 0000000000..9221a98e85 --- /dev/null +++ b/src/tests/kernel/boot_floppy/envtest/Jamfile @@ -0,0 +1,3 @@ +SubDir OBOS_TOP src kernel apps envtest ; + +KernelObjects <$(SOURCE_GRIST)>main.c : -fpic -Wno-unused ; diff --git a/src/tests/kernel/boot_floppy/envtest/main.c b/src/tests/kernel/boot_floppy/envtest/main.c new file mode 100644 index 0000000000..9b15cc5556 --- /dev/null +++ b/src/tests/kernel/boot_floppy/envtest/main.c @@ -0,0 +1,66 @@ +/* +** Copyright 2003-2004, The Haiku Team. All rights reserved. +** Distributed under the terms of the Haiku License. +*/ + + +#include + +#include +#include +#include + + +int +main(int argc, char **argv) +{ + int i; + thread_id pid; + status_t rc; + char temp[16]; + char *var; + + printf("Setting some env vars...\n"); + + if (setenv("TEST", "This is a test!", 0)) { + printf("setenv() error\n"); + return -1; + } + if (setenv("HOME", "/boot", 1)) { + printf("setenv() error\n"); + return -1; + } + + printf("Getting VAR_1: "); + var = getenv("VAR_1"); + if (var) + printf("found set to: \"%s\"\n", var); + else + printf("not found\n"); + + printf("List of env variables set:\n"); + for (i = 0; environ[i]; i++) + printf("%s\n", environ[i]); + + if (argc > 1) { + char buffer[16]; + const char *_argv[] = { argv[0], buffer, NULL }; + int val = atoi(argv[1]) - 1; + + sprintf(temp, "VAR_%d", val); + if (setenv(temp, "dummy", 0)) { + printf("setenv() error\n"); + return -1; + } + + if (val > 0) { + printf("Spawning test (%d left)\n", val); + sprintf(buffer, "%d", val); + pid = load_image(2, _argv, (const char **)environ); + wait_for_thread(pid, &rc); + } + } + return 0; +} + + diff --git a/src/tests/kernel/boot_floppy/exec_test.c b/src/tests/kernel/boot_floppy/exec_test.c new file mode 100644 index 0000000000..ce1409342b --- /dev/null +++ b/src/tests/kernel/boot_floppy/exec_test.c @@ -0,0 +1,52 @@ +/* +** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the Haiku License. +*/ + + +#include + +#include +#include +#include +#include + + +static void +print_process_info(const char *text) +{ + puts(text); + + printf("\tsession_id = %ld\n", getsid(0)); + printf("\tgroup_id = %ld\n", getpgid(0)); + printf("\tprocess_id = %ld\n", getpid()); + printf("\tparent_id = %ld\n", getppid()); +} + + +int +main(int argc, char **argv) +{ + printf("exec_test: this is thread %ld\n", find_thread(NULL)); + + if (argc < 2) { + print_process_info("before exec():"); + puts("going to execl()..."); + + execl("/bin/exec_test", "/bin/exec_test", "argument 1", NULL); + printf("execl() returned: %s\n", strerror(errno)); + } else { + int i; + + print_process_info("after exec():"); + puts("got arguments:"); + for (i = 0; i < argc; i++) + printf("%d: \"%s\"\n", i, argv[i]); + + setsid(); + print_process_info("after setsid():"); + } + + return 0; +} + diff --git a/src/tests/kernel/boot_floppy/false_main.c b/src/tests/kernel/boot_floppy/false_main.c new file mode 100644 index 0000000000..9128fb0be9 --- /dev/null +++ b/src/tests/kernel/boot_floppy/false_main.c @@ -0,0 +1,13 @@ +/* +** Copyright 2002, Manuel J. Petit. All rights reserved. +** Contains portions of: +** +** /boot/bin/true, Copyright 2001 Travis K. Geiselbrecht +** +** Distributed under the terms of the NewOS License. +*/ +int main(void) +{ + return 1; +} + diff --git a/src/tests/kernel/boot_floppy/fibo_main.c b/src/tests/kernel/boot_floppy/fibo_main.c new file mode 100644 index 0000000000..2fd4a70113 --- /dev/null +++ b/src/tests/kernel/boot_floppy/fibo_main.c @@ -0,0 +1,72 @@ +/* +** Copyright 2002, Manuel J. Petit. All rights reserved. +** Distributed under the terms of the NewOS License. +*/ + + +#include + +#include +#include +#include + + +static void +usage(char const *app) +{ + printf("usage: %s [-s] ###\n", app); + exit(-1); +} + + +int +main(int argc, char *argv[]) +{ + int num = 0; + int silent = 0; + int result; + + switch (argc) { + case 2: + num = atoi(argv[1]); + break; + case 3: + if (strcmp(argv[1], "-s") == 0) { + num = atoi(argv[2]); + silent = 1; + } else { + usage(argv[0]); + } + break; + default: + usage(argv[0]); + break; + } + + if (num < 2) { + result = 1; + } else { + thread_id pid; + status_t retcode; + char buffer[64]; + const char *aaargv[] = { "/boot/bin/fibo", "-s", buffer, NULL }; + int aaargc = 3; + + sprintf(buffer, "%d", num-1); + pid = load_image(aaargc, aaargv, (const char **)environ); + wait_for_thread(pid, &retcode); + result = retcode; + + sprintf(buffer, "%d", num-2); + pid = load_image(aaargc, aaargv, (const char **)environ); + wait_for_thread(pid, &retcode); + result += retcode; + } + + if (silent) { + return result; + } else { + printf("%d\n", result); + return 0; + } +} diff --git a/src/tests/kernel/boot_floppy/filetest/Jamfile b/src/tests/kernel/boot_floppy/filetest/Jamfile new file mode 100644 index 0000000000..d01295c6b4 --- /dev/null +++ b/src/tests/kernel/boot_floppy/filetest/Jamfile @@ -0,0 +1,3 @@ +SubDir OBOS_TOP src kernel apps filetest ; + +KernelObjects <$(SOURCE_GRIST)>main.c : -fpic -Wno-unused ; diff --git a/src/tests/kernel/boot_floppy/filetest/main.c b/src/tests/kernel/boot_floppy/filetest/main.c new file mode 100644 index 0000000000..497a941514 --- /dev/null +++ b/src/tests/kernel/boot_floppy/filetest/main.c @@ -0,0 +1,52 @@ +/* +** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. +** Distributed under the terms of the NewOS License. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define FORTUNES "/boot/etc/fortunes" + +int main(int argc, char **argv) +{ + int rc = 0, fd[3]; + int cnt, i; + int on = 1; + + printf("File Test!!!\n"); + + for (i=0;i<3;i++) { + printf("%d : ", i + 1); + fd[i] = open(FORTUNES, O_RDONLY, 0); + printf("fd %d\n", fd[i]); + } + + printf("closing the 3 fd's\n"); + for (i=0;i<3;i++) { + close(fd[i]); + } + + printf("\nNow we have no open fd's so next socket should be 3\n"); + fd[0] = open(FORTUNES, O_RDONLY, 0); + printf("new fd %d\n", fd[0]); + + printf("Trying ioctl to set non-blocking: "); + rc = ioctl(fd[0], FIONBIO, &on, sizeof(on)); + if (rc == EINVAL) { + printf("OK\n"); + } else { + printf("failed\n"); + printf("error was %s\n", strerror(errno)); + } + + close(fd[0]); + + return 0; +} diff --git a/src/tests/kernel/boot_floppy/fork_test.c b/src/tests/kernel/boot_floppy/fork_test.c new file mode 100644 index 0000000000..4252cef5aa --- /dev/null +++ b/src/tests/kernel/boot_floppy/fork_test.c @@ -0,0 +1,33 @@ +/* +** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the Haiku License. +*/ + + +#include + +#include +#include +#include +#include +#include + + +int +main(int argc, char **argv) +{ + pid_t child = fork(); + + if (child == 0) { + printf("CHILD: we're the child!\n"); + snooze(500000); // .5 sec + printf("CHILD: exit!\n"); + } else if (child > 0) { + printf("PARENT: we're the parent, our child has pid %ld\n", child); + waitpid(-1, NULL, 0); + } else + fprintf(stderr, "fork() failed: %s\n", strerror(errno)); + + return 0; +} + diff --git a/src/tests/kernel/boot_floppy/fortune/Jamfile b/src/tests/kernel/boot_floppy/fortune/Jamfile new file mode 100644 index 0000000000..ca41fe0e4b --- /dev/null +++ b/src/tests/kernel/boot_floppy/fortune/Jamfile @@ -0,0 +1,7 @@ +SubDir OBOS_TOP src kernel apps fortune ; + +KernelObjects + <$(SOURCE_GRIST)>main.c + : + -fpic + ; diff --git a/src/tests/kernel/boot_floppy/fortune/fortunes b/src/tests/kernel/boot_floppy/fortune/fortunes new file mode 100644 index 0000000000..168166bd09 --- /dev/null +++ b/src/tests/kernel/boot_floppy/fortune/fortunes @@ -0,0 +1,9 @@ +#@# +Magic is real... unless declared integer. +#@# +System is up and running. +#@# +Open source thesis that thousand of eyes looking thu the code +increases software quality is completely wrong. The amount of +bugs per line of code is an universal constant. The bazaar +model only achieves a quick bug turnover. diff --git a/src/tests/kernel/boot_floppy/fortune/main.c b/src/tests/kernel/boot_floppy/fortune/main.c new file mode 100644 index 0000000000..64dd6ea9c8 --- /dev/null +++ b/src/tests/kernel/boot_floppy/fortune/main.c @@ -0,0 +1,80 @@ +/* +** Copyright 2002-2004, The OpenBeOS Team. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define FORTUNES "/etc/fortunes" + +int +main(void) +{ + int fd; + int rc; + char *buf; + unsigned i; + unsigned found; + struct stat stat; + + fd = open(FORTUNES, O_RDONLY, 0); + if (fd < 0) { + printf("Couldn't open %s: %s\n", FORTUNES, strerror(errno)); + return -1; + } + + rc = fstat(fd, &stat); + if (rc < 0) { + printf("stat() failed: %s\n", strerror(errno)); + return -1; + } + + buf = malloc(stat.st_size + 1); + rc = read(fd, buf, stat.st_size); + if (rc < 0) { + printf("Could not read from fortune file: %s\n", strerror(errno)); + return -1; + } + + buf[stat.st_size] = 0; + close(fd); + + found = 0; + for (i = 0; i < stat.st_size; i++) { + if (!strncmp(buf + i, "#@#", 3)) + found += 1; + } + + if (found > 0) + found = 1 + ((system_time() + 3) % found); + else { + printf("Out of cookies...\n"); + return -1; + } + + for (i = 0; i < stat.st_size; i++) { + if (!strncmp(buf + i, "#@#", 3)) + found -= 1; + + if (found == 0) { + unsigned j; + + for (j = i + 1; j < stat.st_size; j++) { + if (!strncmp(buf + j, "#@#", 3)) + buf[j] = 0; + } + + printf("%s\n", buf + i + 3); + break; + } + } + + return 0; +} diff --git a/src/tests/kernel/boot_floppy/hostname/Jamfile b/src/tests/kernel/boot_floppy/hostname/Jamfile new file mode 100644 index 0000000000..d9e516d0c1 --- /dev/null +++ b/src/tests/kernel/boot_floppy/hostname/Jamfile @@ -0,0 +1,3 @@ +SubDir OBOS_TOP src kernel apps hostname ; + +KernelObjects <$(SOURCE_GRIST)>main.c : -fpic -Wno-unused ; diff --git a/src/tests/kernel/boot_floppy/hostname/main.c b/src/tests/kernel/boot_floppy/hostname/main.c new file mode 100644 index 0000000000..2630de5369 --- /dev/null +++ b/src/tests/kernel/boot_floppy/hostname/main.c @@ -0,0 +1,42 @@ +/* naive implementation of hostname + * + * This mainly serves as a testbed for sysctl, part of the kernel + * just added. + */ + +#include +#include +#include +#include +#include + +#define MAXHOSTNAMELEN 256 + +int main(int argc, char *argv[]) +{ + char buffer[MAXHOSTNAMELEN]; + size_t buflen = MAXHOSTNAMELEN; + int mib[2]; + int rc = -1; + char *newname = NULL; + size_t newnamelen = 0; + + if (argc >= 2) { + newname = argv[1]; + newnamelen = strlen(newname); + } + + buffer[0] = '\0'; + mib[0] = CTL_KERN; + mib[1] = KERN_HOSTNAME; + + rc = sysctl(mib, 2, &buffer, &buflen, newname, newnamelen); + + if (rc == 0 && !newname) { + printf("%s\n", buffer); + } + + return 0; +} + + diff --git a/src/tests/kernel/boot_floppy/init.c b/src/tests/kernel/boot_floppy/init.c new file mode 100644 index 0000000000..c45125820a --- /dev/null +++ b/src/tests/kernel/boot_floppy/init.c @@ -0,0 +1,52 @@ +/* +** Copyright 2001, Travis Geiselbrecht. All rights reserved. +** Distributed under the terms of the NewOS License. +*/ + + +#include + +#include +#include +#include +#include + + +static void +setup_io(void) +{ + int i; + + for (i = 0; i< 256; i++) { + close(i); + } + + open("/dev/keyboard", O_RDONLY, 0); /* stdin */ + open("/dev/console", O_WRONLY, 0); /* stdout */ + open("/dev/console", O_WRONLY, 0); /* stderr */ +} + + +int +main(int argc, char **argv) +{ + setup_io(); + + printf("Welcome to Haiku!\r\n"); + + { + const char *args[] = {"consoled", NULL}; + thread_id thread; + + thread = load_image(1, args, (const char **)environ); + if (thread >= B_OK) { + status_t returnCode; + wait_for_thread(thread, &returnCode); + } else + printf("Failed to create a team for fortune.\n"); + } + + printf("init exiting\n"); + + return 0; +} diff --git a/src/tests/kernel/boot_floppy/ls/Jamfile b/src/tests/kernel/boot_floppy/ls/Jamfile new file mode 100644 index 0000000000..f5ddbae634 --- /dev/null +++ b/src/tests/kernel/boot_floppy/ls/Jamfile @@ -0,0 +1,8 @@ +SubDir OBOS_TOP src kernel apps ls ; + +KernelObjects + <$(SOURCE_GRIST)>main.c + : + -fpic -Wno-unused + ; + diff --git a/src/tests/kernel/boot_floppy/ls/main.c b/src/tests/kernel/boot_floppy/ls/main.c new file mode 100644 index 0000000000..6ccf71377c --- /dev/null +++ b/src/tests/kernel/boot_floppy/ls/main.c @@ -0,0 +1,163 @@ +/* +** Copyright 2002, Travis Geiselbrecht. All rights reserved. +** Distributed under the terms of the NewOS License. +*/ +#include +#include +#include +#include +#include +#include +#include + +extern char *__progname; + +void (*disp_func)(const char *, const char *, struct stat *) = NULL; +static int show_all = 0; + +mode_t perms [9] = { + S_IRUSR, + S_IWUSR, + S_IXUSR, + S_IRGRP, + S_IWGRP, + S_IXGRP, + S_IROTH, + S_IWOTH, + S_IXOTH +}; + + +static void +display_l(const char *path, const char *filename, struct stat *stat) +{ + char perm[11]; + uint32 i; + memset(perm, '-', 10); + perm[10] = '\0'; + + for (i = 0; i < sizeof(perms) / sizeof(mode_t); i++) { + if (stat->st_mode & perms[i]) { + switch(i % 3) { + case 0: + perm[i + 1] = 'r'; + break; + case 1: + perm[i+1] = 'w'; + break; + case 2: + perm[i+1] = 'x'; + } + } + } + if (S_ISDIR(stat->st_mode)) + perm[0] = 'd'; + else if (S_ISLNK(stat->st_mode)) + perm[0] = 'l'; + else if (S_ISCHR(stat->st_mode)) + perm[0] = 'c'; + + printf("%10s %12lld %s" ,perm ,stat->st_size ,filename); + + if (S_ISLNK(stat->st_mode)) { + char buffer[1024]; + if (readlink(path, buffer, sizeof(buffer)) < 0) + strcpy(buffer, "???"); + printf(" (-> %s)\n", buffer); + } else + putchar('\n'); +} + + +static void +display(const char *path, const char *filename, struct stat *stat) +{ + printf("%s\n", filename); +} + + +int +main(int argc, char *argv[]) +{ + int rc; + int rc2; + int count = 0; + struct stat st; + char *arg; + int ch; + uint64 totbytes = 0; + + disp_func = display; + + while ((ch = getopt(argc, argv, "al")) != -1) { + switch (ch) { + case 'a': + show_all = 1; + break; + case 'l': + disp_func = display_l; + break; + } + } + argc -= optind; + argv += optind; + + if (*argv == NULL) + arg = "."; + else + arg = *argv; + + rc = stat(arg, &st); + if (rc < 0) { + printf("%s: %s: %s\n", __progname, + arg, strerror(rc)); + goto err_ls; + } + + if (S_ISDIR(st.st_mode)) { + DIR *thedir = opendir(arg); + + if (!thedir) { + printf("ls: %s: %s\n", arg, strerror(errno)); + } else { + if (show_all) { + /* process the '.' entry */ + rc = stat(arg, &st); + if (rc == 0) { + (*disp_func)(arg, ".", &st); + totbytes += st.st_size; + } + } + + for(;;) { + char buf2[1024]; + struct dirent *de = readdir(thedir); + + if (!de) + break; + + memset(buf2, 0, sizeof(buf2)); + if (strcmp(arg, ".") != 0) { + strlcpy(buf2, arg, sizeof(buf2)); + strlcat(buf2, "/", sizeof(buf2)); + } + strlcat(buf2, de->d_name, sizeof(buf2)); + + rc2 = lstat(buf2, &st); + if (rc2 == 0) { + (*disp_func)(buf2, de->d_name, &st); + totbytes += st.st_size; + } + count++; + } + closedir(thedir); + } + + printf("%lld bytes in %d files\n", totbytes, count); + } else { + (*disp_func)(arg, arg, &st); + } + +err_ls: + return 0; +} diff --git a/src/tests/kernel/boot_floppy/monitor_test.c b/src/tests/kernel/boot_floppy/monitor_test.c new file mode 100644 index 0000000000..8e5f8bcfa2 --- /dev/null +++ b/src/tests/kernel/boot_floppy/monitor_test.c @@ -0,0 +1,44 @@ +/* tests node monitor functionality (very basic test!) */ + +/* +** Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the Haiku License. +*/ + + +#include +#include +#include + +#include +#include +#include + + +int +main(int argc, char **argv) +{ + struct stat st; + if (stat("/", &st) < 0) { + fprintf(stderr, "Could not stat root!\n"); + return -1; + } + + printf("watch file: device = %ld, node = %Ld\n", st.st_dev, st.st_ino); + + if (_kern_start_watching(st.st_dev, st.st_ino, B_WATCH_DIRECTORY, 1, 2) < B_OK) { + fprintf(stderr, "Could not start watching!\n"); + return -1; + } + + mkdir("/temp_test", 0755); + rmdir("/temp_test"); + + if (_kern_stop_watching(st.st_dev, st.st_ino, 0, 1, 2) < B_OK) { + fprintf(stderr, "Could not stop watching!\n"); + return -1; + } + + return 0; +} + diff --git a/src/tests/kernel/boot_floppy/on_exit_thread.c b/src/tests/kernel/boot_floppy/on_exit_thread.c new file mode 100644 index 0000000000..7ea9565512 --- /dev/null +++ b/src/tests/kernel/boot_floppy/on_exit_thread.c @@ -0,0 +1,43 @@ +#include +#include + + +static void +first(void *data) +{ + printf("first on_exit_thread(): %ld\n", (int32)data); +} + + +static void +second(void *data) +{ + printf("second on_exit_thread(): %ld\n", (int32)data); +} + + +static int32 +thread(void *data) +{ + puts("Nurse Stimpy for the rescue!"); + + on_exit_thread(first, (void *)11); + on_exit_thread(second, (void *)22); + + return 0; +} + + +int +main(int argc, char **argv) +{ + status_t status; + thread_id id; + + on_exit_thread(first, (void *)666); + id = spawn_thread(thread, "mythread", B_NORMAL_PRIORITY, (void *)42); + resume_thread(id); + + wait_for_thread(id, &status); + return 0; +} diff --git a/src/tests/kernel/boot_floppy/pipe_test.c b/src/tests/kernel/boot_floppy/pipe_test.c new file mode 100644 index 0000000000..5947e59662 --- /dev/null +++ b/src/tests/kernel/boot_floppy/pipe_test.c @@ -0,0 +1,97 @@ +/* tests basic pipes functionality */ + +/* +** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + + +#include + +#include +#include +#include + + +static int32 +reader_func(void *data) +{ + char buffer[1024]; + int input = (int)data; + int bytes; + + while ((bytes = read(input, buffer, sizeof(buffer) - 1)) > 0) { + buffer[bytes] = '\0'; + // null-terminate, just in case + printf("reader: (%d) %s\n", bytes, buffer); + + if (buffer[0] == '2') { + puts("reader: wait a second and let the writer lead (the pipe has to be buffered)"); + snooze(1000000); + } + if (strstr(buffer, "QUIT")) + break; + } + puts("reader quits"); + + return 0; +} + + +static int32 +writer_func(void *data) +{ + int output = (int)data; + int i; + + const char *strings[] = { + "1. If you read this ", + "2. the pipe implementation ", + "3. seems to work ", + "4. at least a bit ", + "5. QUIT", + NULL}; + + for (i = 0; strings[i] != NULL; i++) { + snooze(100000); + // make sure the reader is waiting for us... + // (needed by the current pipefs implementation :) + + printf("writer: (%ld)\n", write(output, strings[i], strlen(strings[i]))); + } + puts("writer quits"); + + return 0; +} + + +int +main(int argc, char **argv) +{ + thread_id reader, writer; + int stream[2]; + status_t returnCode; + + if (pipe(stream) < 0) { + fprintf(stderr, "pipe creation failed!\n"); + return -1; + } + + reader = spawn_thread(reader_func, "Reader" , B_NORMAL_PRIORITY, (void *)stream[0]); + resume_thread(reader); + + writer = spawn_thread(writer_func, "Writer" , B_NORMAL_PRIORITY, (void *)stream[1]); + resume_thread(writer); + + puts("reader & writer started."); + + // wait until they quit + wait_for_thread(reader, &returnCode); + wait_for_thread(writer, &returnCode); + + close(stream[0]); + close(stream[1]); + + return 0; +} + diff --git a/src/tests/kernel/boot_floppy/ps/Jamfile b/src/tests/kernel/boot_floppy/ps/Jamfile new file mode 100644 index 0000000000..263838b2af --- /dev/null +++ b/src/tests/kernel/boot_floppy/ps/Jamfile @@ -0,0 +1,3 @@ +SubDir OBOS_TOP src kernel apps ps ; + +KernelObjects <$(SOURCE_GRIST)>main.c ; diff --git a/src/tests/kernel/boot_floppy/ps/main.c b/src/tests/kernel/boot_floppy/ps/main.c new file mode 100644 index 0000000000..393bd83c21 --- /dev/null +++ b/src/tests/kernel/boot_floppy/ps/main.c @@ -0,0 +1,72 @@ +/* + * PS command + * Rewritten for OpenBeOS by Angelo Mottola, Aug 2002. + */ + +#include +#include +#include +#include +#include +#include + + +const char *state(thread_state state); + + +const char *state(thread_state state) +{ + switch (state) { + case B_THREAD_RUNNING: + return "run"; + case B_THREAD_READY: + return "rdy"; + case B_THREAD_SUSPENDED: + return "sus"; + case B_THREAD_WAITING: + return "sem"; + case B_THREAD_ASLEEP: + return "zzz"; + case B_THREAD_RECEIVING: + return "msg"; + default: + return "???"; + } +} + + +int main(int argc, char **argv) +{ + int32 thread_num; + int32 team_num = 0; + thread_info thread; + team_info team; + sem_info sem; + char sem_name[B_OS_NAME_LENGTH * 2]; + char buffer[B_OS_NAME_LENGTH]; + + printf("\n thread name state prio user kernel semaphore\n"); + printf("-----------------------------------------------------------------------\n"); + + while (get_next_team_info(&team_num, &team) == B_OK) { + printf("%s (team %ld) (uid %d) (gid %d)\n", + team.args, team.team, team.uid, team.gid); + thread_num = 0; + while (get_next_thread_info(team.team, &thread_num, &thread) == B_OK) { + sem_name[0] = '\0'; + if (thread.state == B_THREAD_WAITING) { + if (get_sem_info(thread.sem, &sem) == B_OK) { + strcpy(sem_name, sem.name); + sprintf(buffer, "(%ld)", sem.sem); + strcat(sem_name, buffer); + } + } + printf(" %6ld %20s %s %3ld %7d %7d %s\n", + thread.thread, thread.name, state(thread.state), thread.priority, + (int)thread.user_time, (int)thread.kernel_time, sem_name); + } + } + printf("\n"); + + return 0; +} diff --git a/src/tests/kernel/boot_floppy/select_test.c b/src/tests/kernel/boot_floppy/select_test.c new file mode 100644 index 0000000000..91588a5e03 --- /dev/null +++ b/src/tests/kernel/boot_floppy/select_test.c @@ -0,0 +1,48 @@ +/* tests basic select() and poll() functionality */ + +/* +** Copyright 2002, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + + +#include +#include + +#include +#include +#include +#include + +#define FILE_NAME "/boot" + +int +main(int argc, char **argv) +{ + fd_set readSet; + struct pollfd pollfd; + int count; + int file = open(FILE_NAME, O_RDONLY); + if (file < 0) { + fprintf(stderr, "Could not open \"%s\": %s\n", FILE_NAME, strerror(file)); + return -1; + } + + FD_ZERO(&readSet); + FD_SET(file, &readSet); + + puts("selecting..."); + count = select(file + 1, &readSet, NULL, NULL, NULL); + printf("\tselect returned: %d (read set = %ld)\n", count, FD_ISSET(file, &readSet)); + + pollfd.fd = file; + pollfd.events = POLLOUT | POLLERR; + + puts("polling..."); + count = poll(&pollfd, 1, -1); + printf("\tpoll returned: %d (revents = 0x%x)\n", count, pollfd.revents); + + close(file); + return 0; +} + diff --git a/src/tests/kernel/boot_floppy/shell/Jamfile b/src/tests/kernel/boot_floppy/shell/Jamfile new file mode 100644 index 0000000000..d7f4ec4aeb --- /dev/null +++ b/src/tests/kernel/boot_floppy/shell/Jamfile @@ -0,0 +1,12 @@ +SubDir OBOS_TOP src kernel apps shell ; + +KernelObjects <$(SOURCE_GRIST)>main.c + <$(SOURCE_GRIST)>args.c + <$(SOURCE_GRIST)>commands.c + <$(SOURCE_GRIST)>file_utils.c + <$(SOURCE_GRIST)>parse.c + <$(SOURCE_GRIST)>script.c + <$(SOURCE_GRIST)>shell_vars.c + <$(SOURCE_GRIST)>statements.c + <$(SOURCE_GRIST)>shell_history.c + : -fpic ; diff --git a/src/tests/kernel/boot_floppy/shell/args.c b/src/tests/kernel/boot_floppy/shell/args.c new file mode 100644 index 0000000000..31fc81181c --- /dev/null +++ b/src/tests/kernel/boot_floppy/shell/args.c @@ -0,0 +1,80 @@ +//#include +#include +#include +#include +#include +#include + +#include "args.h" +#include "shell_defs.h" +#include "shell_vars.h" + +bool af_exit_after_script; +char *af_script_file_name; +char *gCommandToExecute = NULL; + +static const char *kUsage = +"Usage: shell [ -s ] [ -c ] [