From 2c9cde1e406b59ea52f04c22ed689d25417133af Mon Sep 17 00:00:00 2001 From: Aren Elchinyan Date: Sun, 29 Oct 2023 19:18:35 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8C=20cpubench?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.sh | 1 + configs/limine.cfg | 3 ++ modules/cpubench/build.sh | 6 ++++ modules/cpubench/main.c | 61 +++++++++++++++++++++++++++++++++++++++ pbuild.py | 3 +- 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 modules/cpubench/build.sh create mode 100644 modules/cpubench/main.c diff --git a/build.sh b/build.sh index 1d935da..fdd9283 100755 --- a/build.sh +++ b/build.sh @@ -4,5 +4,6 @@ dos2unix */*.sh cd helloworld/ && chmod +x build.sh && ./build.sh && cd .. cd music/ && chmod +x build.sh && ./build.sh && cd .. cd simd/ && chmod +x build.sh && ./build.sh && cd .. +cd cpubench/ && chmod +x build.sh && ./build.sh && cd .. cd .. python3 pbuild.py \ No newline at end of file diff --git a/configs/limine.cfg b/configs/limine.cfg index 2dbcb6c..eb4d68e 100644 --- a/configs/limine.cfg +++ b/configs/limine.cfg @@ -21,6 +21,9 @@ BACKGROUND_PATH=boot:///boot.tga MODULE_PATH=boot:///mod/simd.ko MODULE_CMDLINE=[MOD]simd.ko + MODULE_PATH=boot:///mod/cpubench.ko + MODULE_CMDLINE=[MOD]cpubench.ko + MODULE_PATH=boot:///mod/hello.ko MODULE_CMDLINE=[MOD]hello.ko diff --git a/modules/cpubench/build.sh b/modules/cpubench/build.sh new file mode 100644 index 0000000..915073f --- /dev/null +++ b/modules/cpubench/build.sh @@ -0,0 +1,6 @@ +#/bin/sh +echo "Название: CPUBENCH" +echo "Лицензия: Публичное достояние" +gcc -I../../modlib -O0 -finput-charset=UTF-8 -fexec-charset=cp1251 -c -fPIC -nostdlib main.c -o cpubench.o +gcc -Wl,--entry=init -fPIC -shared -nostdlib cpubench.o -o cpubench.ko +echo "Сборка завершена, файл: cpubench.ko" diff --git a/modules/cpubench/main.c b/modules/cpubench/main.c new file mode 100644 index 0000000..8354451 --- /dev/null +++ b/modules/cpubench/main.c @@ -0,0 +1,61 @@ +#include + +static char fxsave_region[512] __attribute__((aligned(16))); + +static inline void cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx, + uint32_t *ecx, uint32_t *edx) { + asm volatile("cpuid" + : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) + : "a"(leaf)); +} + +static void L1_cache_size( ) { + uint32_t eax, ebx, ecx, edx; + cpuid(0x80000006, &eax, &ebx, &ecx, &edx); + if ((edx & 0xFF) == 0) { + fb_printf("L1 кэш недоступен\n"); + return; + } + fb_printf( + "L1: Размер строки: %u B, Тип ассоциации: %u, Размер кэша: %u КБ\n", + ecx & 0xff, (ecx >> 12) & 0x07, (ecx >> 16) & 0xffff); +} + +static void L2_cache_size( ) { + uint32_t eax, ebx, ecx, edx; + cpuid(0x80000006, &eax, &ebx, &ecx, &edx); + if ((edx & 0xFF) == 0) { + fb_printf("L2 кэш недоступен\n"); + return; + } + fb_printf( + "L2: Размер строки: %u B, Тип ассоциации: %u, Размер кэша: %u КБ\n", + ecx & 0xff, (ecx >> 12) & 0x0F, (ecx >> 16) & 0xFFFF); +} + +static void L3_cache_size( ) { + uint32_t eax, ebx, ecx, edx; + cpuid(0x80000006, &eax, &ebx, &ecx, &edx); + if ((edx & 0xFF) == 0) { + fb_printf("L3 кэш недоступен\n"); + return; + } + fb_printf( + "L3: Размер строки: %u B, Тип ассоциации: %u, Размер кэша: %u КБ\n", + edx & 0xff, (edx >> 12) & 0x0F, (edx >> 16) & 0xFFFF); +} + +module_info_t init(env_t *env) { + init_env(env); + + L1_cache_size( ); + L2_cache_size( ); + L3_cache_size( ); + + return (module_info_t){ + .name = (char *)"CPUBENCH", + .message = (char *)"Дополнительная информация о процессоре", + .err_code = 0, + .func_count = 1 + }; +} \ No newline at end of file diff --git a/pbuild.py b/pbuild.py index adcb451..040da80 100644 --- a/pbuild.py +++ b/pbuild.py @@ -133,7 +133,7 @@ def create_hdd(IMAGE_NAME): os.system("mformat -i {}.hdd@@1M".format(IMAGE_NAME)) os.system("mmd -i {}.hdd@@1M ::/mod ::/EFI ::/EFI/BOOT ::/user".format(IMAGE_NAME)) os.system("mcopy -i {}.hdd@@1M kernel.elf configs/limine.cfg limine/limine-bios.sys ::/".format(IMAGE_NAME)) - os.system("mcopy -i {}.hdd@@1M modules/music/music.ko modules/simd/simd.ko modules/helloworld/hello.ko ::/mod".format(IMAGE_NAME)) + os.system("mcopy -i {}.hdd@@1M modules/music/music.ko modules/simd/simd.ko modules/cpubench/cpubench.ko modules/helloworld/hello.ko ::/mod".format(IMAGE_NAME)) os.system("mcopy -i {}.hdd@@1M limine/BOOTX64.EFI limine/BOOTIA32.EFI ::/EFI/BOOT".format(IMAGE_NAME)) os.system("mcopy -i {}.hdd@@1M boot.tga ::/".format(IMAGE_NAME)) os.system("./limine/limine bios-install {}.hdd".format(IMAGE_NAME)) @@ -150,6 +150,7 @@ def create_iso(IMAGE_NAME): os.system("cp -v modules/helloworld/hello.ko iso_root/mod/") os.system("cp -v modules/music/music.ko iso_root/mod/") os.system("cp -v modules/simd/simd.ko iso_root/mod/") + os.system("cp -v modules/cpubench/cpubench.ko iso_root/mod/") os.system("cp -v limine/BOOTX64.EFI iso_root/EFI/BOOT/") os.system("cp -v limine/BOOTIA32.EFI iso_root/EFI/BOOT/") os.system("xorriso -as mkisofs -b limine-bios-cd.bin -no-emul-boot -boot-load-size 4 -boot-info-table --efi-boot limine-uefi-cd.bin -efi-boot-part --efi-boot-image --protective-msdos-label iso_root -o {}.iso".format(IMAGE_NAME))