鱼C论坛

 找回密码
 立即注册
查看: 1595|回复: 6

有点迷茫

[复制链接]
发表于 2022-10-19 12:26:23 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
就是说现在刚刚加入大学,对于计算机这一方面不是很熟悉
如果想要玩懂电脑,完好电脑,需要学习什么
现在正在学习计算机基础
就想问一下还有没有其他意见
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-10-19 12:34:38 | 显示全部楼层
C/C++
汇编语言
数据结构与算法
编译原理
操作系统
单片机
。。。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2022-10-19 15:24:28 | 显示全部楼层
我不明白你是要玩电脑还是学电脑知识?如果是玩,天天打游戏。如果是学,要全通恐怕有点难,有硬件,有软件,要看你专业是什么?把专业学好,精通一门(精通,不是略懂!!!),其他的应该都容易上手。仅供参考。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-10-19 17:06:18 | 显示全部楼层
chentyping 发表于 2022-10-19 15:24
我不明白你是要玩电脑还是学电脑知识?如果是玩,天天打游戏。如果是学,要全通恐怕有点难,有硬件,有软件 ...

c语言现在学着学着感觉没什么用,就是输出几个简单的代码
用相对复杂的方式去编译一个简单的但东西,在我目前看来有点没用,
之后会有什么用处,凭借输出几个字符或者许多个字符
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-10-20 13:02:39 | 显示全部楼层
0unique0 发表于 2022-10-19 17:06
c语言现在学着学着感觉没什么用,就是输出几个简单的代码
用相对复杂的方式去编译一个简单的但东西,在 ...

一门语言能够活下来,有它的生存之道。对后来学的人,c语言或许感觉很没有用,但它仍然没有被淘汰。哪怕c++出现,它仍然有市场。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-10-28 16:14:35 | 显示全部楼层
0unique0 发表于 2022-10-19 17:06
c语言现在学着学着感觉没什么用,就是输出几个简单的代码
用相对复杂的方式去编译一个简单的但东西,在 ...

玩底层你不用C语言你用什么?汇编语言?
还是算了吧,对于现在的我都是极力的避免使用汇编语言,因为汇编语言太难驾驭了,真的
看看下面这个代码怎么样?最近在研究smbios
这些底层的东西就得用C语言
虽然说也可以用C++,不过使用C++的意义不大
主要是这些底层的代码还没有复杂到要使用C++的程度
#include <efi.h>
#include <libsmbios.h>

#define print_variable(SystemTable, base, value) \
    kputs(SystemTable, L"" #value ": "); print_##base(SystemTable, value); kputc(SystemTable, L'\n')

void swap(CHAR16 *a, CHAR16 *b) {
    CHAR16 temp = *a;
    *a = *b;
    *b = temp;
}

CHAR16 kgetc(EFI_SYSTEM_TABLE *SystemTable) {
    EFI_INPUT_KEY key;
    SystemTable->BootServices->WaitForEvent(1, &SystemTable->ConIn->WaitForKey, NULL);
    SystemTable->ConIn->ReadKeyStroke(SystemTable->ConIn, &key);
    if(key.UnicodeChar == '\r') key.UnicodeChar = '\n';
    return key.UnicodeChar;
}

void kputc(EFI_SYSTEM_TABLE *SystemTable, CHAR16 c) {
    if(c == L'\n') kputc(SystemTable, L'\r');
    CHAR16 str[2] = {c, '\0'};
    SystemTable->ConOut->OutputString(SystemTable->ConOut, str);
}

void kputs(EFI_SYSTEM_TABLE *SystemTable, const CHAR16 *str) {
    for(UINTN i = 0; str[i]; ++i) {
        kputc(SystemTable, str[i]);
    }
}

void number(CHAR16 *buff, UINTN value, UINTN base) {
    static const CHAR16 table[16] = L"0123456789abcdef";
    if(base > 16) base = 16;
    CHAR16 *p = buff;
    do {
        *p++ = table[value % base];
        value /= base;
    } while(value);
    *p = L'\0';
    UINTN count = p - buff;
    for(UINTN i = 0; i < count / 2; ++i) {
        swap(&buff[i], &buff[count - i - 1]);
    }
}

void print_dec(EFI_SYSTEM_TABLE *SystemTable, UINTN value) {
    CHAR16 buff[128]; number(buff, value, 10); kputs(SystemTable, buff);
}

void print_hex(EFI_SYSTEM_TABLE *SystemTable, UINTN value) {
    CHAR16 buff[128]; number(buff, value, 16); kputs(SystemTable, buff);
}

/*
typedef struct {
    UINT32  Data1;
    UINT16  Data2;
    UINT16  Data3;
    UINT8   Data4[8];
} EFI_GUID;
*/
BOOLEAN compare_guid(const EFI_GUID *a, const EFI_GUID *b) {
    if(a->Data1 != b->Data1) return FALSE;
    if(a->Data2 != b->Data2) return FALSE;
    if(a->Data3 != b->Data3) return FALSE;
    for(UINTN i = 0; i < 8; ++i) {
        if(a->Data4[i] != b->Data4[i]) return FALSE;
    }
    return TRUE;
}

void print_guid(EFI_SYSTEM_TABLE *SystemTable, const EFI_GUID *guid) {
    const UINT8 *base = (const UINT8 *)guid;
    kputc(SystemTable, L'{');
    BOOLEAN flag = FALSE;
    for(UINTN i = 0; i < 16; ++i) {
        if(flag) kputs(SystemTable, L", ");
        flag = TRUE;
        print_hex(SystemTable, base[i]);
    }
    kputc(SystemTable, L'}');
}

UINT8 *print_smbios_string(EFI_SYSTEM_TABLE *SystemTable, UINT8 *str) {
    if(!*str) ++str;
    for(UINTN i = 1; ; ++i) {
        if(!*str) break;
        print_dec(SystemTable, i);
        kputs(SystemTable, L": ");
        while(*str) kputc(SystemTable, *str++);
        kputc(SystemTable, L'\n');
        ++str;
    }
    return str + 1;
}

void print_smbios_header(EFI_SYSTEM_TABLE *SystemTable, const SMBIOS_HEADER *hdr) {
    print_variable(SystemTable, hex, hdr->Type);
    print_variable(SystemTable, hex, hdr->Length);
    print_variable(SystemTable, hex, *(UINT16 *)&hdr->Handle);
}

void *bios_information(EFI_SYSTEM_TABLE *SystemTable, void *base) {
    SMBIOS_TYPE0 *st0 = base;
    kputc(SystemTable, L'\n');
    print_smbios_header(SystemTable, &st0->Hdr);
    print_variable(SystemTable, hex, st0->Vendor);
    print_variable(SystemTable, hex, st0->BiosVersion);
    print_variable(SystemTable, hex, *(UINT16 *)&st0->BiosSegment);
    print_variable(SystemTable, hex, st0->BiosReleaseDate);
    print_variable(SystemTable, hex, st0->BiosSize);
    print_variable(SystemTable, hex, st0->BiosCharacteristics[0]);
    print_variable(SystemTable, hex, st0->BiosCharacteristics[1]);
    print_variable(SystemTable, hex, st0->BiosCharacteristics[2]);
    print_variable(SystemTable, hex, st0->BiosCharacteristics[3]);
    print_variable(SystemTable, hex, st0->BiosCharacteristics[4]);
    print_variable(SystemTable, hex, st0->BiosCharacteristics[5]);
    print_variable(SystemTable, hex, st0->BiosCharacteristics[6]);
    print_variable(SystemTable, hex, st0->BiosCharacteristics[7]);
    return print_smbios_string(SystemTable, base + st0->Hdr.Length);
}

void *system_information(EFI_SYSTEM_TABLE *SystemTable, void *base) {
    SMBIOS_TYPE1 *st1 = base;
    kputc(SystemTable, L'\n');
    print_smbios_header(SystemTable, &st1->Hdr);
    print_variable(SystemTable, hex, st1->Manufacturer);
    print_variable(SystemTable, hex, st1->ProductName);
    print_variable(SystemTable, hex, st1->Version);
    print_variable(SystemTable, hex, st1->SerialNumber);
    print_guid(SystemTable, &st1->Uuid); kputc(SystemTable, L'\n');
    print_variable(SystemTable, hex, st1->WakeUpType);
    return print_smbios_string(SystemTable, base + st1->Hdr.Length);
}

void *baseboard_information(EFI_SYSTEM_TABLE *SystemTable, void *base) {
    SMBIOS_TYPE2 *st2 = base;
    kputc(SystemTable, L'\n');
    print_smbios_header(SystemTable, &st2->Hdr);
    print_variable(SystemTable, hex, st2->Manufacturer);
    print_variable(SystemTable, hex, st2->ProductName);
    print_variable(SystemTable, hex, st2->Version);
    print_variable(SystemTable, hex, st2->SerialNumber);
    return print_smbios_string(SystemTable, base + st2->Hdr.Length);
}

void *system_enclosure(EFI_SYSTEM_TABLE *SystemTable, void *base) {
    SMBIOS_TYPE3 *st3 = base;
    kputc(SystemTable, L'\n');
    print_smbios_header(SystemTable, &st3->Hdr);
    print_variable(SystemTable, hex, st3->Manufacturer);
    print_variable(SystemTable, hex, st3->Type);
    print_variable(SystemTable, hex, st3->Version);
    print_variable(SystemTable, hex, st3->SerialNumber);
    print_variable(SystemTable, hex, st3->AssetTag);
    print_variable(SystemTable, hex, st3->BootupState);
    print_variable(SystemTable, hex, st3->PowerSupplyState);
    print_variable(SystemTable, hex, st3->ThermalState);
    print_variable(SystemTable, hex, st3->SecurityStatus);
    print_variable(SystemTable, hex, *(UINT32 *)&st3->OemDefined);
    return print_smbios_string(SystemTable, base + st3->Hdr.Length);
}

void *processor_information(EFI_SYSTEM_TABLE *SystemTable, void *base) {
    SMBIOS_TYPE4 *st4 = base;
    kputc(SystemTable, L'\n');
    print_smbios_header(SystemTable, &st4->Hdr);
    print_variable(SystemTable, hex, st4->Socket);
    print_variable(SystemTable, hex, st4->ProcessorType);
    print_variable(SystemTable, hex, st4->ProcessorFamily);
    print_variable(SystemTable, hex, st4->ProcessorId[0]);
    print_variable(SystemTable, hex, st4->ProcessorId[1]);
    print_variable(SystemTable, hex, st4->ProcessorId[2]);
    print_variable(SystemTable, hex, st4->ProcessorId[3]);
    print_variable(SystemTable, hex, st4->ProcessorId[4]);
    print_variable(SystemTable, hex, st4->ProcessorId[5]);
    print_variable(SystemTable, hex, st4->ProcessorId[6]);
    print_variable(SystemTable, hex, st4->ProcessorId[7]);
    print_variable(SystemTable, hex, st4->ProcessorVersion);
    print_variable(SystemTable, hex, st4->Voltage);
    print_variable(SystemTable, hex, *(UINT16 *)&st4->ExternalClock);
    print_variable(SystemTable, hex, *(UINT16 *)&st4->MaxSpeed);
    print_variable(SystemTable, hex, *(UINT16 *)&st4->CurrentSpeed);
    print_variable(SystemTable, hex, st4->Status);
    print_variable(SystemTable, hex, st4->ProcessorUpgrade);
    print_variable(SystemTable, hex, *(UINT16 *)&st4->L1CacheHandle);
    print_variable(SystemTable, hex, *(UINT16 *)&st4->L2CacheHandle);
    print_variable(SystemTable, hex, *(UINT16 *)&st4->L3CacheHandle);
    return print_smbios_string(SystemTable, base + st4->Hdr.Length);
}

void *unknown_type(EFI_SYSTEM_TABLE *SystemTable, void *base) {
    SMBIOS_HEADER *hdr = base;
    kputc(SystemTable, L'\n');
    print_smbios_header(SystemTable, hdr);
    return print_smbios_string(SystemTable, base + hdr->Length);
}

void info_eps(EFI_SYSTEM_TABLE *SystemTable) {
    EFI_GUID smbios_guid = SMBIOS_TABLE_GUID;
    EFI_GUID smbios3_guid = SMBIOS3_TABLE_GUID;
    EFI_GUID mps_guid = MPS_TABLE_GUID;
    EFI_GUID acpi_guid = ACPI_TABLE_GUID;
    EFI_GUID acpi20_guid = ACPI_20_TABLE_GUID;
    EFI_GUID sal_system_guid = SAL_SYSTEM_TABLE_GUID;
    EFI_GUID dtb_guid = EFI_DTB_TABLE_GUID;
    SMBIOS_STRUCTURE_TABLE *smbios_header = NULL;
    for(UINTN i = 0; i < SystemTable->NumberOfTableEntries; ++i) {
        if(compare_guid(&SystemTable->ConfigurationTable[i].VendorGuid, &smbios_guid)) {
            kputs(SystemTable, L"SMBIOS_TABLE_GUID: ");
            smbios_header = SystemTable->ConfigurationTable[i].VendorTable;
        }
        if(compare_guid(&SystemTable->ConfigurationTable[i].VendorGuid, &smbios3_guid)) kputs(SystemTable, L"SMBIOS3_TABLE_GUID: ");
        if(compare_guid(&SystemTable->ConfigurationTable[i].VendorGuid, &mps_guid)) kputs(SystemTable, L"MPS_TABLE_GUID: ");
        if(compare_guid(&SystemTable->ConfigurationTable[i].VendorGuid, &acpi_guid)) kputs(SystemTable, L"ACPI_TABLE_GUID: ");
        if(compare_guid(&SystemTable->ConfigurationTable[i].VendorGuid, &acpi20_guid)) kputs(SystemTable, L"ACPI_20_TABLE_GUID: ");
        if(compare_guid(&SystemTable->ConfigurationTable[i].VendorGuid, &sal_system_guid)) kputs(SystemTable, L"SAL_SYSTEM_TABLE_GUID: ");
        if(compare_guid(&SystemTable->ConfigurationTable[i].VendorGuid, &dtb_guid)) kputs(SystemTable, L"EFI_DTB_TABLE_GUID: ");
        print_guid(SystemTable, &SystemTable->ConfigurationTable[i].VendorGuid); kputc(SystemTable, L'\n');
    }
    if(!smbios_header) return;
    kputs(SystemTable, L"AnchorString: "");
    kputc(SystemTable, smbios_header->AnchorString[0]);
    kputc(SystemTable, smbios_header->AnchorString[1]);
    kputc(SystemTable, smbios_header->AnchorString[2]);
    kputc(SystemTable, smbios_header->AnchorString[3]);
    kputs(SystemTable, L""\n");
    print_variable(SystemTable, hex, smbios_header->EntryPointStructureChecksum);
    print_variable(SystemTable, hex, smbios_header->EntryPointLength);
    print_variable(SystemTable, hex, smbios_header->MajorVersion);
    print_variable(SystemTable, hex, smbios_header->MinorVersion);
    print_variable(SystemTable, hex, smbios_header->MaxStructureSize);
    print_variable(SystemTable, hex, smbios_header->EntryPointRevision);
    print_variable(SystemTable, hex, smbios_header->IntermediateChecksum);
    print_variable(SystemTable, hex, smbios_header->TableLength);
    print_variable(SystemTable, hex, smbios_header->TableAddress);
    print_variable(SystemTable, hex, smbios_header->NumberOfSmbiosStructures);
    print_variable(SystemTable, hex, smbios_header->SmbiosBcdRevision);
    kputs(SystemTable, L"IntermediateAnchorString: "");
    kputc(SystemTable, smbios_header->IntermediateAnchorString[0]);
    kputc(SystemTable, smbios_header->IntermediateAnchorString[1]);
    kputc(SystemTable, smbios_header->IntermediateAnchorString[2]);
    kputc(SystemTable, smbios_header->IntermediateAnchorString[3]);
    kputc(SystemTable, smbios_header->IntermediateAnchorString[4]);
    kputs(SystemTable, L""\n");
    print_variable(SystemTable, hex, smbios_header->FormattedArea[0]);
    print_variable(SystemTable, hex, smbios_header->FormattedArea[1]);
    print_variable(SystemTable, hex, smbios_header->FormattedArea[2]);
    print_variable(SystemTable, hex, smbios_header->FormattedArea[3]);
    print_variable(SystemTable, hex, smbios_header->FormattedArea[4]);
    UINT8 *next = (UINT8 *)(UINT64)smbios_header->TableAddress;
    for(UINTN i = 0; i < smbios_header->NumberOfSmbiosStructures; ++i) {
        switch(*next) {
            case 0: next = bios_information(SystemTable, next); break;
            case 1: next = system_information(SystemTable, next); break;
            case 2: next = baseboard_information(SystemTable, next); break;
            case 3: next = system_enclosure(SystemTable, next); break;
            case 4: next = processor_information(SystemTable, next); break;
            default: next = unknown_type(SystemTable, next);
        }
        kgetc(SystemTable);
    }
}

EFI_STATUS EFIAPI efi_main(EFI_HANDLE *ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
    info_eps(SystemTable);
    kgetc(SystemTable);
    return EFI_SUCCESS;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-11-24 14:00:12 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-12-22 09:20

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表