有点迷茫
就是说现在刚刚加入大学,对于计算机这一方面不是很熟悉如果想要玩懂电脑,完好电脑,需要学习什么
现在正在学习计算机基础
就想问一下还有没有其他意见 C/C++
汇编语言
数据结构与算法
编译原理
操作系统
单片机
。。。
我不明白你是要玩电脑还是学电脑知识?如果是玩,天天打游戏。如果是学,要全通恐怕有点难,有硬件,有软件,要看你专业是什么?把专业学好,精通一门(精通,不是略懂!!!),其他的应该都容易上手。仅供参考。 chentyping 发表于 2022-10-19 15:24
我不明白你是要玩电脑还是学电脑知识?如果是玩,天天打游戏。如果是学,要全通恐怕有点难,有硬件,有软件 ...
c语言现在学着学着感觉没什么用,就是输出几个简单的代码
用相对复杂的方式去编译一个简单的但东西,在我目前看来有点没用,
之后会有什么用处,凭借输出几个字符或者许多个字符 0unique0 发表于 2022-10-19 17:06
c语言现在学着学着感觉没什么用,就是输出几个简单的代码
用相对复杂的方式去编译一个简单的但东西,在 ...
一门语言能够活下来,有它的生存之道。对后来学的人,c语言或许感觉很没有用,但它仍然没有被淘汰。哪怕c++出现,它仍然有市场。 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 = {c, '\0'};
SystemTable->ConOut->OutputString(SystemTable->ConOut, str);
}
void kputs(EFI_SYSTEM_TABLE *SystemTable, const CHAR16 *str) {
for(UINTN i = 0; str; ++i) {
kputc(SystemTable, str);
}
}
void number(CHAR16 *buff, UINTN value, UINTN base) {
static const CHAR16 table = L"0123456789abcdef";
if(base > 16) base = 16;
CHAR16 *p = buff;
do {
*p++ = table;
value /= base;
} while(value);
*p = L'\0';
UINTN count = p - buff;
for(UINTN i = 0; i < count / 2; ++i) {
swap(&buff, &buff);
}
}
void print_dec(EFI_SYSTEM_TABLE *SystemTable, UINTN value) {
CHAR16 buff; number(buff, value, 10); kputs(SystemTable, buff);
}
void print_hex(EFI_SYSTEM_TABLE *SystemTable, UINTN value) {
CHAR16 buff; number(buff, value, 16); kputs(SystemTable, buff);
}
/*
typedef struct {
UINT32Data1;
UINT16Data2;
UINT16Data3;
UINT8 Data4;
} 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 != b->Data4) 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);
}
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);
print_variable(SystemTable, hex, st0->BiosCharacteristics);
print_variable(SystemTable, hex, st0->BiosCharacteristics);
print_variable(SystemTable, hex, st0->BiosCharacteristics);
print_variable(SystemTable, hex, st0->BiosCharacteristics);
print_variable(SystemTable, hex, st0->BiosCharacteristics);
print_variable(SystemTable, hex, st0->BiosCharacteristics);
print_variable(SystemTable, hex, st0->BiosCharacteristics);
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);
print_variable(SystemTable, hex, st4->ProcessorId);
print_variable(SystemTable, hex, st4->ProcessorId);
print_variable(SystemTable, hex, st4->ProcessorId);
print_variable(SystemTable, hex, st4->ProcessorId);
print_variable(SystemTable, hex, st4->ProcessorId);
print_variable(SystemTable, hex, st4->ProcessorId);
print_variable(SystemTable, hex, st4->ProcessorId);
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.VendorGuid, &smbios_guid)) {
kputs(SystemTable, L"SMBIOS_TABLE_GUID: ");
smbios_header = SystemTable->ConfigurationTable.VendorTable;
}
if(compare_guid(&SystemTable->ConfigurationTable.VendorGuid, &smbios3_guid)) kputs(SystemTable, L"SMBIOS3_TABLE_GUID: ");
if(compare_guid(&SystemTable->ConfigurationTable.VendorGuid, &mps_guid)) kputs(SystemTable, L"MPS_TABLE_GUID: ");
if(compare_guid(&SystemTable->ConfigurationTable.VendorGuid, &acpi_guid)) kputs(SystemTable, L"ACPI_TABLE_GUID: ");
if(compare_guid(&SystemTable->ConfigurationTable.VendorGuid, &acpi20_guid)) kputs(SystemTable, L"ACPI_20_TABLE_GUID: ");
if(compare_guid(&SystemTable->ConfigurationTable.VendorGuid, &sal_system_guid)) kputs(SystemTable, L"SAL_SYSTEM_TABLE_GUID: ");
if(compare_guid(&SystemTable->ConfigurationTable.VendorGuid, &dtb_guid)) kputs(SystemTable, L"EFI_DTB_TABLE_GUID: ");
print_guid(SystemTable, &SystemTable->ConfigurationTable.VendorGuid); kputc(SystemTable, L'\n');
}
if(!smbios_header) return;
kputs(SystemTable, L"AnchorString: \"");
kputc(SystemTable, smbios_header->AnchorString);
kputc(SystemTable, smbios_header->AnchorString);
kputc(SystemTable, smbios_header->AnchorString);
kputc(SystemTable, smbios_header->AnchorString);
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);
kputc(SystemTable, smbios_header->IntermediateAnchorString);
kputc(SystemTable, smbios_header->IntermediateAnchorString);
kputc(SystemTable, smbios_header->IntermediateAnchorString);
kputc(SystemTable, smbios_header->IntermediateAnchorString);
kputs(SystemTable, L"\"\n");
print_variable(SystemTable, hex, smbios_header->FormattedArea);
print_variable(SystemTable, hex, smbios_header->FormattedArea);
print_variable(SystemTable, hex, smbios_header->FormattedArea);
print_variable(SystemTable, hex, smbios_header->FormattedArea);
print_variable(SystemTable, hex, smbios_header->FormattedArea);
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;
}
{:5_108:}
页:
[1]