parent
d6b01a0ac5
commit
1b4d5fb6a4
@ -1 +1,5 @@
|
||||
.vscode/settings.json
|
||||
**/a.out
|
||||
mkramfs/ramfs.img
|
||||
mkramfs/mkramfs
|
||||
FAT/
|
||||
|
@ -0,0 +1,30 @@
|
||||
#include "elf.h"
|
||||
#include "text.h"
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
|
||||
void run(char *elfdata) {
|
||||
if (elfdata[EI_CLASS] == ELFCLASS32) {
|
||||
Elf32_Ehdr elf32header;
|
||||
CopyMem(&elf32header, elfdata, sizeof(elf32header));
|
||||
if (!IS_ELF(elf32header)) {
|
||||
print("This is not ELF file!");
|
||||
}
|
||||
if (elf32header.e_ident[EI_OSABI] != ELFOSABI_LINUX &&
|
||||
elf32header.e_ident[EI_OSABI] != ELFOSABI_NONE) {
|
||||
print("This ELF file is not valid OS ABI!");
|
||||
}
|
||||
if (elf32header.e_machine != EM_386 &&
|
||||
elf32header.e_machine != EM_486 &&
|
||||
elf32header.e_machine != EM_X86_64) {
|
||||
print("This ELF file is not for x86 or x86_64!");
|
||||
}
|
||||
if (elf32header.e_type == ET_REL) {
|
||||
} else if (elf32header.e_type == ET_EXEC) {
|
||||
} else if (elf32header.e_type == ET_DYN) {
|
||||
}
|
||||
|
||||
} else if (elfdata[EI_CLASS] == ELFCLASS64) {
|
||||
Elf64_Ehdr elf64header;
|
||||
CopyMem(&elf64header, elfdata, sizeof(elf64header));
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
#include <../BaseTools/Source/C/GenFw/elf_common.h>
|
||||
#include <../BaseTools/Source/C/GenFw/elf32.h>
|
||||
#include <../BaseTools/Source/C/GenFw/elf64.h>
|
@ -0,0 +1,40 @@
|
||||
char keycode_to_ascii[] = {
|
||||
0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^',
|
||||
0, 0, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '@', '[',
|
||||
'\n', 0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', ':', 0,
|
||||
0, ']', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 0, '*',
|
||||
0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.',
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, '\\', 0, 0, 0, 0, 0, 0, 0, 0, 0, '\\',
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0};
|
||||
|
||||
char keycode_to_ascii_shift[] = {
|
||||
0, 0, '!', '"', '#', '$', '%', '&', '\'', '(', ')', 0, '=', '~', 0,
|
||||
0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '`', '{', 0, 0,
|
||||
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', '*', 0, 0, '}', 'Z',
|
||||
'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-',
|
||||
'4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, '|', 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0};
|
@ -0,0 +1,5 @@
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Uefi.h>
|
||||
#include <Uefi/UefiSpec.h>
|
||||
|
||||
void VMemInit() { UINTN *PageTable = (UINTN *)AsmReadCr3(); }
|
@ -0,0 +1,8 @@
|
||||
CC := g++
|
||||
CFLAGS := -std=c++17
|
||||
|
||||
|
||||
mkramfs: main.cpp
|
||||
$(CC) $(CFLAGS) -o mkramfs main.cpp
|
||||
|
||||
clean: $(RM) mkramfs
|
@ -0,0 +1,37 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
typedef struct {
|
||||
int Start;
|
||||
int Size;
|
||||
char name[256];
|
||||
} FILE_DESC;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc == 1) {
|
||||
std::cout << "Usage:mkramfs <file1> <file2> ..." << std::endl;
|
||||
return -1;
|
||||
}
|
||||
FILE_DESC descriptor[256] = {0};
|
||||
std::ofstream ramfs("ramfs.img", std::ios::binary | std::ios::ate);
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (!std::filesystem::exists(std::filesystem::path(argv[i]))) {
|
||||
std::cout << "file does not exist! - " << argv[i] << std::endl;
|
||||
continue;
|
||||
}
|
||||
descriptor[i].Start = descriptor[i - 1].Start + descriptor[i - 1].Size;
|
||||
descriptor[i].Size =
|
||||
std::filesystem::file_size(std::filesystem::path(argv[i]));
|
||||
strncpy(descriptor[i].name,
|
||||
std::filesystem::path(argv[i]).filename().c_str(), 255);
|
||||
}
|
||||
ramfs.write(reinterpret_cast<char *>(descriptor), sizeof(descriptor));
|
||||
for (int i = 1; i < argc; i++) {
|
||||
std::ifstream file(argv[i], std::ios::binary);
|
||||
ramfs << file.rdbuf();
|
||||
file.close();
|
||||
}
|
||||
ramfs.close();
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
#include <IndustryStandard/Pci.h>
|
||||
#include <Uefi.h>
|
||||
#include <Uefi/UefiSpec.h>
|
||||
|
||||
typedef struct {
|
||||
BOOLEAN isUsing;
|
||||
BOOLEAN isIDE; // T:IDE F:AHCI
|
||||
UINT8 bus;
|
||||
UINT8 device;
|
||||
UINT8 function;
|
||||
} DiskController;
|
||||
|
||||
DiskController controllers[5];
|
||||
|
||||
void init_pci() {
|
||||
for (UINT8 bus = 0; bus < 256; bus++) {
|
||||
for (UINT8 device = 0; device < 32; device++) {
|
||||
for (UINT8 function = 0; function < 8; function++) {
|
||||
UINT32 ConfigData =
|
||||
PciCf8Read32(PCI_CF8_LIB_ADDRESS(bus, device, function, 0));
|
||||
if (ConfigData != 0xffffffff) {
|
||||
ConfigData = PciCf8Read32(
|
||||
PCI_CF8_LIB_ADDRESS(bus, device, function, 8));
|
||||
if ((ConfigData >> 16) == 0x0101) { // IDE Controller
|
||||
int n = 0;
|
||||
while (controllers[n].isUsing) {
|
||||
n++;
|
||||
}
|
||||
controllers[n].isUsing = TRUE;
|
||||
controllers[n].isIDE = TRUE;
|
||||
controllers[n].bus = bus;
|
||||
controllers[n].device = device;
|
||||
controllers[n].function = function;
|
||||
return;
|
||||
} else if ((ConfigData >> 8) ==
|
||||
0x010601) { // AHCI Controller
|
||||
int n = 0;
|
||||
while (controllers[n].isUsing) {
|
||||
n++;
|
||||
}
|
||||
controllers[n].isUsing = TRUE;
|
||||
controllers[n].isIDE = FALSE;
|
||||
controllers[n].bus = bus;
|
||||
controllers[n].device = device;
|
||||
controllers[n].function = function;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
#include "ramfs.h"
|
||||
|
||||
#include <Guid/FileInfo.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/PrintLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Uefi.h>
|
||||
|
||||
#include "text.h"
|
||||
RAMFS_DATA *data;
|
||||
void ramfsinit(
|
||||
EFI_SYSTEM_TABLE *SystemTable) { // must call before ExitBootServices
|
||||
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fsp;
|
||||
EFI_FILE_PROTOCOL *Root, *ramfs;
|
||||
EFI_FILE_INFO info;
|
||||
UINTN infosize = sizeof(info), datasize;
|
||||
|
||||
EFI_STATUS Status = SystemTable->BootServices->LocateProtocol(
|
||||
&gEfiSimpleFileSystemProtocolGuid, NULL, (VOID **)&fsp);
|
||||
if (EFI_ERROR(Status)) {
|
||||
Print(L"Error:Failed to locate EFI Simple FileSystem Protocol - %r",
|
||||
Status);
|
||||
return;
|
||||
}
|
||||
|
||||
fsp->OpenVolume(fsp, &Root);
|
||||
Status = Root->Open(Root, &ramfs, L"ramfs.img", EFI_FILE_MODE_READ, 0);
|
||||
if (EFI_ERROR(Status)) {
|
||||
Print(L"Error:Failed to open ramfs file - %r\n", Status);
|
||||
return;
|
||||
}
|
||||
ramfs->GetInfo(ramfs, &gEfiFileInfoGuid, &infosize, &info);
|
||||
Status = SystemTable->BootServices->AllocatePool(
|
||||
EfiLoaderData, info.FileSize, (void **)&data);
|
||||
if (EFI_ERROR(Status)) {
|
||||
Print(L"Error:Failed to allocate ramfs memory - %r\n", Status);
|
||||
return;
|
||||
}
|
||||
datasize = info.FileSize;
|
||||
ramfs->Read(ramfs, &datasize, data);
|
||||
}
|
||||
|
||||
void getfilesize(char *filename, UINTN *size) {
|
||||
int index;
|
||||
for (index = 0; index < 256; index++)
|
||||
if (!AsciiStrCmp(data->descriptor[index].name, filename)) break;
|
||||
*size = data->descriptor[index].Size;
|
||||
}
|
||||
|
||||
void readfile(char *filename, UINTN buffersize, void *buffer) {
|
||||
int index;
|
||||
for (index = 0; index < 256; index++)
|
||||
if (!AsciiStrCmp(data->descriptor[index].name, filename)) break;
|
||||
CopyMem(buffer, data->data + data->descriptor[index].Start, buffersize);
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
#include <Protocol/SimpleFileSystem.h>
|
||||
typedef struct {
|
||||
int Start;
|
||||
int Size;
|
||||
char name[256];
|
||||
} FILE_DESC;
|
||||
|
||||
typedef struct {
|
||||
FILE_DESC descriptor[256];
|
||||
char data[];
|
||||
} RAMFS_DATA;
|
||||
|
||||
void ramfsinit(EFI_SYSTEM_TABLE *SystemTable);
|
||||
void getfilesize(char *filename, UINTN *size);
|
||||
void readfile(char *filename, UINTN buffersize, void *buffer);
|
@ -0,0 +1,3 @@
|
||||
int main(){
|
||||
return 0;
|
||||
}
|
Loading…
Reference in new issue