Functioning IA32 EFI loader
This commit is contained in:
parent
fbf7ccd234
commit
e55fb284ba
9
Makefile
9
Makefile
@ -184,7 +184,7 @@ endif
|
||||
|
||||
image.iso: cdrom/ramdisk.img cdrom/boot/boot.sys cdrom/kernel cdrom/netinit ${MODULES}
|
||||
xorriso -as mkisofs -R -J -c boot/bootcat \
|
||||
-b boot/boot.sys -no-emul-boot -boot-load-size 20 \
|
||||
-b boot/boot.sys -no-emul-boot -boot-load-size 24 \
|
||||
${EFI_XORRISO} \
|
||||
-o image.iso cdrom
|
||||
|
||||
@ -198,10 +198,10 @@ cdrom/boot/efi.img: boot/boot32.efi
|
||||
-mmd -i $@ '/EFI/BOOT'
|
||||
mcopy -i $@ boot/boot32.efi '::/EFI/BOOT/BOOTIA32.EFI'
|
||||
|
||||
EFI_CFLAGS=-fno-stack-protector -fpic -DEFI_FUNCTION_WRAPPER -m32 -ffreestanding -fshort-wchar -I /usr/include/efi -I /usr/include/efi/ia32 -mno-red-zone
|
||||
EFI_CFLAGS=-fno-stack-protector -fpic -DEFI_FUNCTION_WRAPPER -m32 -DEFI_PLATFORM -ffreestanding -fshort-wchar -I /usr/include/efi -I /usr/include/efi/ia32 -mno-red-zone
|
||||
EFI_SECTIONS=-j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .reloc
|
||||
|
||||
boot/efi.so: boot/efi.c boot/jmp.o
|
||||
boot/efi.so: boot/cstuff.c boot/*.h
|
||||
$(CC) ${EFI_CFLAGS} -c -o boot/efi.o $<
|
||||
$(LD) boot/efi.o /usr/lib32/crt0-efi-ia32.o -nostdlib -znocombreloc -T /usr/lib32/elf_ia32_efi.lds -shared -Bsymbolic -L /usr/lib32 -lefi -lgnuefi -o boot/efi.so
|
||||
|
||||
@ -217,9 +217,6 @@ boot/cstuff.o: boot/cstuff.c boot/*.h
|
||||
boot/boot.o: boot/boot.s
|
||||
yasm -f elf -o $@ $<
|
||||
|
||||
boot/jmp.o: boot/jmp.s
|
||||
yasm -f elf -o $@ $<
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f base/lib/*.so
|
||||
|
10
boot/boot.s
10
boot/boot.s
@ -131,13 +131,3 @@ mmap_ent db 0, 0
|
||||
global lower_mem
|
||||
lower_mem db 0, 0
|
||||
|
||||
[bits 32]
|
||||
global jump_to_main
|
||||
jump_to_main:
|
||||
extern _eax
|
||||
extern _ebx
|
||||
extern _xmain
|
||||
mov eax, [_eax]
|
||||
mov ebx, [_ebx]
|
||||
jmp [_xmain]
|
||||
|
||||
|
@ -1,6 +1,11 @@
|
||||
//#define __DEBUG__
|
||||
#ifdef EFI_PLATFORM
|
||||
# include <efi.h>
|
||||
# include <efilib.h>
|
||||
EFI_HANDLE ImageHandleIn;
|
||||
#else
|
||||
# include "types.h"
|
||||
#endif
|
||||
|
||||
#include "types.h"
|
||||
#include "ata.h"
|
||||
#include "text.h"
|
||||
#include "util.h"
|
||||
@ -75,57 +80,65 @@ static char * boot_mode_names[] = {
|
||||
/* More bootloader implementation that depends on the module config */
|
||||
#include "moremultiboot.h"
|
||||
|
||||
#ifdef EFI_PLATFORM
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
|
||||
{
|
||||
InitializeLib(ImageHandle, SystemTable);
|
||||
ST = SystemTable;
|
||||
ImageHandleIn = ImageHandle;
|
||||
#else
|
||||
int kmain() {
|
||||
|
||||
/* Boot options - configurable values */
|
||||
#endif
|
||||
|
||||
BOOT_OPTION(_debug, 0, "Debug output",
|
||||
"Enable debug output in the bootloader and enable the",
|
||||
"serial debug log in the operating system itself.");
|
||||
"Enable debug output in the bootloader and enable the",
|
||||
"serial debug log in the operating system itself.");
|
||||
|
||||
BOOT_OPTION(_legacy_ata, 0, "Legacy ATA driver",
|
||||
"Enable the legacy ATA driver, which does not support",
|
||||
"ATAPI or use DMA. May be necessary in some virtual machines.");
|
||||
"Enable the legacy ATA driver, which does not support",
|
||||
"ATAPI or use DMA. May be necessary in some virtual machines.");
|
||||
|
||||
BOOT_OPTION(_normal_ata, 1, "DMA ATA driver",
|
||||
"Enable the normal, DMA-capable ATA driver. This is the default.",
|
||||
NULL);
|
||||
"Enable the normal, DMA-capable ATA driver. This is the default.",
|
||||
NULL);
|
||||
|
||||
BOOT_OPTION(_debug_shell, 1, "Debug shell",
|
||||
"Enable the kernel debug shell. This can be accessed using",
|
||||
"the `kdebug` application.");
|
||||
"Enable the kernel debug shell. This can be accessed using",
|
||||
"the `kdebug` application.");
|
||||
|
||||
BOOT_OPTION(_video, 1, "Video modules",
|
||||
"Enable the video modules. These are needed to modeset",
|
||||
"and provide a framebuffer for the UI.");
|
||||
"Enable the video modules. These are needed to modeset",
|
||||
"and provide a framebuffer for the UI.");
|
||||
|
||||
BOOT_OPTION(_vbox, 1, "VirtualBox Guest Additions",
|
||||
"Enable integration with VirtualBox, including",
|
||||
"automatic mode setting and absolute mouse pointer.");
|
||||
"Enable integration with VirtualBox, including",
|
||||
"automatic mode setting and absolute mouse pointer.");
|
||||
|
||||
BOOT_OPTION(_vmware, 1, "VMWare mouse driver",
|
||||
"Enable the VMware / QEMU absolute mouse pointer.",
|
||||
NULL);
|
||||
"Enable the VMware / QEMU absolute mouse pointer.",
|
||||
NULL);
|
||||
|
||||
BOOT_OPTION(_sound, 1, "Audio drivers",
|
||||
"Enable the audio subsystem and AC'97 drivers.",
|
||||
NULL);
|
||||
"Enable the audio subsystem and AC'97 drivers.",
|
||||
NULL);
|
||||
|
||||
BOOT_OPTION(_net, 1, "Network drivers",
|
||||
"Enable the IPv4 network subsystem and various",
|
||||
"network interface drivers.");
|
||||
"Enable the IPv4 network subsystem and various",
|
||||
"network interface drivers.");
|
||||
|
||||
BOOT_OPTION(_migrate, 1, "Writable root",
|
||||
"Migrates the ramdisk from ext2 to an in-memory",
|
||||
"temporary filesystem at boot.");
|
||||
"Migrates the ramdisk from ext2 to an in-memory",
|
||||
"temporary filesystem at boot.");
|
||||
|
||||
BOOT_OPTION(_serialshell, 0, "Debug on serial",
|
||||
"Start a kernel debug shell on the first",
|
||||
"serial port.");
|
||||
"Start a kernel debug shell on the first",
|
||||
"serial port.");
|
||||
|
||||
BOOT_OPTION(_netinit, 0, "Netinit",
|
||||
"Downloads a userspace filesystem from a remote",
|
||||
"server and extracts it at boot.");
|
||||
"Downloads a userspace filesystem from a remote",
|
||||
"server and extracts it at boot.");
|
||||
|
||||
/* Loop over rendering the menu */
|
||||
show_menu();
|
||||
@ -156,6 +169,7 @@ int kmain() {
|
||||
|
||||
if (_debug) {
|
||||
strcat(cmdline, DEBUG_LOG_CMDLINE);
|
||||
txt_debug = 1;
|
||||
}
|
||||
|
||||
if (_serialshell) {
|
||||
@ -204,4 +218,7 @@ int kmain() {
|
||||
}
|
||||
|
||||
boot();
|
||||
|
||||
while (1) {}
|
||||
return 0;
|
||||
}
|
||||
|
212
boot/efi.c
212
boot/efi.c
@ -1,212 +0,0 @@
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
|
||||
#include "ata.h"
|
||||
#include "text.h"
|
||||
#include "util.h"
|
||||
#include "atapi_imp.h"
|
||||
#include "iso9660.h"
|
||||
#include "elf.h"
|
||||
#include "multiboot.h"
|
||||
#include "kbd.h"
|
||||
#include "options.h"
|
||||
|
||||
/* Basic text strings */
|
||||
#define VERSION_TEXT "ToaruOS-NIH Bootloader v1.3"
|
||||
#define HELP_TEXT "Press <Enter> or select a menu option with \030/\031/\032/\033."
|
||||
#define COPYRIGHT_TEXT "ToaruOS is free software under the NCSA license."
|
||||
#define LINK_TEXT "https://toaruos.org - https://gitlab.com/toaruos"
|
||||
|
||||
/* Boot command line strings */
|
||||
#define DEFAULT_ROOT_CMDLINE "root=/dev/ram0,nocache "
|
||||
#define DEFAULT_GRAPHICAL_CMDLINE "start=live-session "
|
||||
#define DEFAULT_SINGLE_CMDLINE "start=terminal "
|
||||
#define DEFAULT_TEXT_CMDLINE "start=--vga "
|
||||
#define DEFAULT_VID_CMDLINE "vid=auto,1440,900 "
|
||||
#define DEFAULT_NETINIT_CMDLINE "init=/dev/ram0 _"
|
||||
#define MIGRATE_CMDLINE "start=--migrate _"
|
||||
#define DEBUG_LOG_CMDLINE "logtoserial=3 "
|
||||
#define DEBUG_SERIAL_CMDLINE "kdebug "
|
||||
|
||||
char * module_dir = "MOD";
|
||||
char * kernel_path = "KERNEL.";
|
||||
char * ramdisk_path = "RAMDISK.IMG";
|
||||
|
||||
/* Where to dump kernel data while loading */
|
||||
#define KERNEL_LOAD_START 0x300000
|
||||
|
||||
/* Module file names - need to be ordered. */
|
||||
static char * modules[] = {
|
||||
"ZERO.KO", // 0
|
||||
"RANDOM.KO", // 1
|
||||
"SERIAL.KO", // 2
|
||||
"DEBUG_SH.KO", // 3
|
||||
"PROCFS.KO", // 4
|
||||
"TMPFS.KO", // 5
|
||||
"ATA.KO", // 6
|
||||
"EXT2.KO", // 7
|
||||
"ISO9660.KO", // 8
|
||||
"PS2KBD.KO", // 9
|
||||
"PS2MOUSE.KO", // 10
|
||||
"LFBVIDEO.KO", // 11
|
||||
"VBOXGUES.KO", // 12
|
||||
"VMWARE.KO", // 13
|
||||
"VIDSET.KO", // 14
|
||||
"PACKETFS.KO", // 15
|
||||
"SND.KO", // 16
|
||||
"AC97.KO", // 17
|
||||
"NET.KO", // 18
|
||||
"PCNET.KO", // 19
|
||||
"RTL.KO", // 20
|
||||
"E1000.KO", // 21
|
||||
"PCSPKR.KO", // 22
|
||||
0
|
||||
};
|
||||
|
||||
/* Names of the available boot modes. */
|
||||
static char * boot_mode_names[] = {
|
||||
"Normal Boot",
|
||||
"VGA Text Mode",
|
||||
"Single-User Graphical Terminal",
|
||||
};
|
||||
|
||||
/* More bootloader implementation that depends on the module config */
|
||||
#include "moremultiboot.h"
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
|
||||
{
|
||||
InitializeLib(ImageHandle, SystemTable);
|
||||
Print(L"Hello, world!\n");
|
||||
BOOT_OPTION(_debug, 0, "Debug output",
|
||||
"Enable debug output in the bootloader and enable the",
|
||||
"serial debug log in the operating system itself.");
|
||||
|
||||
BOOT_OPTION(_legacy_ata, 0, "Legacy ATA driver",
|
||||
"Enable the legacy ATA driver, which does not support",
|
||||
"ATAPI or use DMA. May be necessary in some virtual machines.");
|
||||
|
||||
BOOT_OPTION(_normal_ata, 1, "DMA ATA driver",
|
||||
"Enable the normal, DMA-capable ATA driver. This is the default.",
|
||||
NULL);
|
||||
|
||||
BOOT_OPTION(_debug_shell, 1, "Debug shell",
|
||||
"Enable the kernel debug shell. This can be accessed using",
|
||||
"the `kdebug` application.");
|
||||
|
||||
BOOT_OPTION(_video, 1, "Video modules",
|
||||
"Enable the video modules. These are needed to modeset",
|
||||
"and provide a framebuffer for the UI.");
|
||||
|
||||
BOOT_OPTION(_vbox, 1, "VirtualBox Guest Additions",
|
||||
"Enable integration with VirtualBox, including",
|
||||
"automatic mode setting and absolute mouse pointer.");
|
||||
|
||||
BOOT_OPTION(_vmware, 1, "VMWare mouse driver",
|
||||
"Enable the VMware / QEMU absolute mouse pointer.",
|
||||
NULL);
|
||||
|
||||
BOOT_OPTION(_sound, 1, "Audio drivers",
|
||||
"Enable the audio subsystem and AC'97 drivers.",
|
||||
NULL);
|
||||
|
||||
BOOT_OPTION(_net, 1, "Network drivers",
|
||||
"Enable the IPv4 network subsystem and various",
|
||||
"network interface drivers.");
|
||||
|
||||
BOOT_OPTION(_migrate, 1, "Writable root",
|
||||
"Migrates the ramdisk from ext2 to an in-memory",
|
||||
"temporary filesystem at boot.");
|
||||
|
||||
BOOT_OPTION(_serialshell, 0, "Debug on serial",
|
||||
"Start a kernel debug shell on the first",
|
||||
"serial port.");
|
||||
|
||||
BOOT_OPTION(_netinit, 0, "Netinit",
|
||||
"Downloads a userspace filesystem from a remote",
|
||||
"server and extracts it at boot.");
|
||||
|
||||
Print(L"Boot options loaded.\n");
|
||||
|
||||
/* Loop over rendering the menu */
|
||||
show_menu();
|
||||
|
||||
/* Build our command line. */
|
||||
if (_netinit) {
|
||||
strcat(cmdline, DEFAULT_NETINIT_CMDLINE);
|
||||
ramdisk_path = "NETINIT.";
|
||||
} else {
|
||||
strcat(cmdline, DEFAULT_ROOT_CMDLINE);
|
||||
|
||||
if (_migrate) {
|
||||
strcat(cmdline, MIGRATE_CMDLINE);
|
||||
}
|
||||
}
|
||||
|
||||
if (boot_mode == 0) {
|
||||
strcat(cmdline, DEFAULT_GRAPHICAL_CMDLINE);
|
||||
strcat(cmdline, DEFAULT_VID_CMDLINE);
|
||||
} else if (boot_mode == 1) {
|
||||
strcat(cmdline, DEFAULT_TEXT_CMDLINE);
|
||||
} else if (boot_mode == 2) {
|
||||
strcat(cmdline, DEFAULT_SINGLE_CMDLINE);
|
||||
strcat(cmdline, DEFAULT_VID_CMDLINE);
|
||||
}
|
||||
|
||||
if (_debug) {
|
||||
strcat(cmdline, DEBUG_LOG_CMDLINE);
|
||||
}
|
||||
|
||||
if (_serialshell) {
|
||||
strcat(cmdline, DEBUG_SERIAL_CMDLINE);
|
||||
}
|
||||
|
||||
/* Configure modules */
|
||||
if (!_normal_ata) {
|
||||
modules[6] = "NONE";
|
||||
}
|
||||
|
||||
if (_legacy_ata) {
|
||||
modules[6] = "ATAOLD.KO";
|
||||
}
|
||||
|
||||
if (!_debug_shell) {
|
||||
modules[3] = "NONE";
|
||||
modules[14] = "NONE";
|
||||
}
|
||||
|
||||
if (!_video) {
|
||||
modules[11] = "NONE";
|
||||
modules[12] = "NONE";
|
||||
modules[13] = "NONE";
|
||||
modules[14] = "NONE";
|
||||
}
|
||||
|
||||
if (!_vmware) {
|
||||
modules[13] = "NONE";
|
||||
}
|
||||
|
||||
if (!_vbox) {
|
||||
modules[12] = "NONE";
|
||||
}
|
||||
|
||||
if (!_sound) {
|
||||
modules[16] = "NONE";
|
||||
modules[17] = "NONE";
|
||||
}
|
||||
|
||||
if (!_net) {
|
||||
modules[18] = "NONE";
|
||||
modules[19] = "NONE";
|
||||
modules[20] = "NONE";
|
||||
modules[21] = "NONE";
|
||||
}
|
||||
|
||||
boot();
|
||||
|
||||
while (1) {
|
||||
|
||||
}
|
||||
return EFI_SUCCESS;
|
||||
}
|
10
boot/jmp.s
10
boot/jmp.s
@ -1,10 +0,0 @@
|
||||
[bits 32]
|
||||
global jump_to_main
|
||||
jump_to_main:
|
||||
extern _eax
|
||||
extern _ebx
|
||||
extern _xmain
|
||||
mov eax, [_eax]
|
||||
mov ebx, [_ebx]
|
||||
jmp [_xmain]
|
||||
|
45
boot/kbd.h
45
boot/kbd.h
@ -1,4 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#define KBD_SCAN_DOWN 0x50
|
||||
#define KBD_SCAN_UP 0x48
|
||||
#define KBD_SCAN_LEFT 0x4B
|
||||
#define KBD_SCAN_RIGHT 0x4D
|
||||
#define KBD_SCAN_ENTER 0x1C
|
||||
#define KBD_SCAN_1 2
|
||||
#define KBD_SCAN_9 10
|
||||
|
||||
#ifdef EFI_PLATFORM
|
||||
|
||||
static int read_scancode(void) {
|
||||
EFI_INPUT_KEY Key;
|
||||
unsigned long int index;
|
||||
uefi_call_wrapper(ST->BootServices->WaitForEvent, 3, 1, &ST->ConIn->WaitForKey, &index);
|
||||
uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, ST->ConIn, &Key);
|
||||
switch (Key.ScanCode) {
|
||||
case 0:
|
||||
switch (Key.UnicodeChar) {
|
||||
case L'\r':
|
||||
return KBD_SCAN_ENTER;
|
||||
case L'1':
|
||||
case L'2':
|
||||
case L'3':
|
||||
case L'4':
|
||||
case L'5':
|
||||
case L'6':
|
||||
case L'7':
|
||||
case L'8':
|
||||
case L'9':
|
||||
return Key.UnicodeChar - L'1' + KBD_SCAN_1;
|
||||
default:
|
||||
return 0xFF;
|
||||
}
|
||||
break;
|
||||
case 0x01: return KBD_SCAN_UP;
|
||||
case 0x02: return KBD_SCAN_DOWN;
|
||||
case 0x03: return KBD_SCAN_RIGHT;
|
||||
case 0x04: return KBD_SCAN_LEFT;
|
||||
default:
|
||||
return 0xFF;
|
||||
}
|
||||
}
|
||||
#else
|
||||
static int read_scancode(void) {
|
||||
while (!(inportb(0x64) & 1));
|
||||
int out;
|
||||
@ -7,3 +51,4 @@ static int read_scancode(void) {
|
||||
}
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
@ -33,8 +33,6 @@ static struct multiboot multiboot_header = {
|
||||
static long ramdisk_off = 1;
|
||||
static long ramdisk_len = 1;
|
||||
|
||||
extern void jump_to_main(void);
|
||||
|
||||
int _eax = 1;
|
||||
int _ebx = 1;
|
||||
int _xmain = 1;
|
||||
@ -49,6 +47,10 @@ struct mmap_entry {
|
||||
extern unsigned short mmap_ent;
|
||||
extern unsigned short lower_mem;
|
||||
|
||||
char * final_offset = NULL;
|
||||
|
||||
extern char make_it_happen_capn[];
|
||||
|
||||
static void move_kernel(void) {
|
||||
clear();
|
||||
print("Relocating kernel...\n");
|
||||
@ -75,6 +77,10 @@ static void move_kernel(void) {
|
||||
print(" ");
|
||||
print_hex(phdr->p_filesz);
|
||||
print("\n");
|
||||
#ifdef EFI_PLATFORM
|
||||
EFI_PHYSICAL_ADDRESS addr = phdr->p_vaddr;
|
||||
uefi_call_wrapper(ST->BootServices->AllocatePages, 3, AllocateAddress, 0x80000000, phdr->p_memsz / 4096 + 1, &addr);
|
||||
#endif
|
||||
memcpy((uint8_t*)phdr->p_vaddr, (uint8_t*)KERNEL_LOAD_START + phdr->p_offset, phdr->p_filesz);
|
||||
long r = phdr->p_filesz;
|
||||
while (r < phdr->p_memsz) {
|
||||
@ -85,6 +91,33 @@ static void move_kernel(void) {
|
||||
}
|
||||
|
||||
print("Setting up memory map...\n");
|
||||
#ifdef EFI_PLATFORM
|
||||
mboot_memmap_t * mmap = (void*)KERNEL_LOAD_START;
|
||||
multiboot_header.mmap_addr = (uintptr_t)mmap;
|
||||
mmap->size = 0;
|
||||
mmap->base_addr = 0;
|
||||
mmap->length = 0;
|
||||
mmap->type = 0;
|
||||
|
||||
multiboot_header.mem_lower = 1024;
|
||||
multiboot_header.mem_upper = 1024 * 512;
|
||||
|
||||
memcpy(final_offset, cmdline, 1024);
|
||||
multiboot_header.cmdline = (uintptr_t)final_offset;
|
||||
final_offset += 1024;
|
||||
while ((uintptr_t)final_offset & 0x3ff) final_offset++;
|
||||
|
||||
multiboot_header.mods_addr = (uintptr_t)final_offset;
|
||||
memcpy(final_offset, &modules_mboot, sizeof(modules_mboot));
|
||||
final_offset += sizeof(modules_mboot);
|
||||
while ((uintptr_t)final_offset & 0x3ff) final_offset++;
|
||||
|
||||
memcpy(final_offset, &multiboot_header, sizeof(multiboot_header));
|
||||
_ebx = (uintptr_t)final_offset;
|
||||
|
||||
|
||||
print("Jumping to main, good luck.\n");
|
||||
#else
|
||||
print_hex(mmap_ent);
|
||||
print("\n");
|
||||
memset((void*)KERNEL_LOAD_START, 0x00, 1024);
|
||||
@ -118,12 +151,40 @@ static void move_kernel(void) {
|
||||
|
||||
multiboot_header.mem_upper = upper_mem / 1024;
|
||||
|
||||
int foo;
|
||||
//__asm__ __volatile__("jmp %1" : "=a"(foo) : "a" (MULTIBOOT_EAX_MAGIC), "b"((unsigned int)multiboot_header), "r"((unsigned int)entry));
|
||||
_eax = MULTIBOOT_EAX_MAGIC;
|
||||
_ebx = (unsigned int)&multiboot_header;
|
||||
#endif
|
||||
|
||||
_eax = MULTIBOOT_EAX_MAGIC;
|
||||
_xmain = entry;
|
||||
jump_to_main();
|
||||
|
||||
#ifdef EFI_PLATFORM
|
||||
print_("\nExiting boot services and jumping to ");
|
||||
print_hex_(entry);
|
||||
print_(" with mboot_mag=");
|
||||
print_hex_(_eax);
|
||||
print_(" and mboot_ptr=");
|
||||
print_hex_(_ebx);
|
||||
print_("...\n");
|
||||
|
||||
if (1) {
|
||||
EFI_STATUS e;
|
||||
UINTN mapSize = 0, mapKey, descriptorSize;
|
||||
UINT32 descriptorVersion;
|
||||
uefi_call_wrapper(ST->BootServices->GetMemoryMap, 5, &mapSize, NULL, &mapKey, &descriptorSize, NULL);
|
||||
e = uefi_call_wrapper(ST->BootServices->ExitBootServices, 2, ImageHandleIn, mapKey);
|
||||
|
||||
if (e != EFI_SUCCESS) {
|
||||
print_("Exit services failed. \n");
|
||||
print_hex_(e);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"mov %1,%%eax \n"
|
||||
"mov %2,%%ebx \n"
|
||||
"jmp *%0" : : "g"(_xmain), "g"(_eax), "g"(_ebx) : "eax", "ebx"
|
||||
);
|
||||
}
|
||||
|
||||
static void do_it(struct ata_device * _device) {
|
||||
@ -153,6 +214,12 @@ done:
|
||||
print_hex(dir_entry->extent_length_LSB); print("\n");
|
||||
long offset = 0;
|
||||
for (int i = dir_entry->extent_start_LSB; i < dir_entry->extent_start_LSB + dir_entry->extent_length_LSB / 2048 + 1; ++i, offset += 2048) {
|
||||
|
||||
#ifdef EFI_PLATFORM
|
||||
EFI_PHYSICAL_ADDRESS addr = KERNEL_LOAD_START + offset;
|
||||
uefi_call_wrapper(ST->BootServices->AllocatePages, 3, AllocateAddress, 0x80000000, 1, &addr);
|
||||
#endif
|
||||
|
||||
ata_device_read_sector_atapi(device, i, (uint8_t *)KERNEL_LOAD_START + offset);
|
||||
}
|
||||
restore_root();
|
||||
@ -172,6 +239,10 @@ done:
|
||||
modules_mboot[j].mod_start = KERNEL_LOAD_START + offset;
|
||||
modules_mboot[j].mod_end = KERNEL_LOAD_START + offset + dir_entry->extent_length_LSB;
|
||||
for (int i = dir_entry->extent_start_LSB; i < dir_entry->extent_start_LSB + dir_entry->extent_length_LSB / 2048 + 1; ++i, offset += 2048) {
|
||||
#ifdef EFI_PLATFORM
|
||||
EFI_PHYSICAL_ADDRESS addr = KERNEL_LOAD_START + offset;
|
||||
uefi_call_wrapper(ST->BootServices->AllocatePages, 3, AllocateAddress, 0x80000000, 1, &addr);
|
||||
#endif
|
||||
ata_device_read_sector_atapi(device, i, (uint8_t *)KERNEL_LOAD_START + offset);
|
||||
}
|
||||
j++;
|
||||
@ -182,7 +253,7 @@ done:
|
||||
print("Done.\n");
|
||||
restore_root();
|
||||
if (navigate(ramdisk_path)) {
|
||||
clear_();
|
||||
//clear_();
|
||||
ramdisk_off = KERNEL_LOAD_START + offset;
|
||||
ramdisk_len = dir_entry->extent_length_LSB;
|
||||
modules_mboot[multiboot_header.mods_count-1].mod_start = ramdisk_off;
|
||||
@ -190,6 +261,11 @@ done:
|
||||
|
||||
print_("Loading ramdisk");
|
||||
|
||||
#ifdef EFI_PLATFORM
|
||||
EFI_PHYSICAL_ADDRESS addr = KERNEL_LOAD_START + offset;
|
||||
uefi_call_wrapper(ST->BootServices->AllocatePages, 3, AllocateAddress, 0x80000000, ramdisk_len / 4096 + 1, &addr);
|
||||
#endif
|
||||
|
||||
int i = dir_entry->extent_start_LSB;
|
||||
int sectors = dir_entry->extent_length_LSB / 2048 + 1;
|
||||
#define SECTORS 65536
|
||||
@ -204,9 +280,11 @@ done:
|
||||
if (sectors > 0) {
|
||||
print_("!");
|
||||
ata_device_read_sectors_atapi(device, i, (uint8_t *)KERNEL_LOAD_START + offset, sectors);
|
||||
offset += 2048;
|
||||
offset += 2048 * sectors;
|
||||
}
|
||||
attr = 0x07;
|
||||
|
||||
final_offset = (uint8_t *)KERNEL_LOAD_START + offset;
|
||||
set_attr(0x07);
|
||||
print("Done.\n");
|
||||
move_kernel();
|
||||
}
|
||||
@ -240,7 +318,6 @@ void swap_bytes(void * in, int count) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef EFI_FUNCTION_WRAPPER
|
||||
void show_menu(void) {
|
||||
|
||||
#if 1
|
||||
@ -308,6 +385,7 @@ void show_menu(void) {
|
||||
}
|
||||
sel_max += BASE_SEL + 1;
|
||||
|
||||
#ifndef EFI_PLATFORM
|
||||
outportb(0x3D4, 14);
|
||||
outportb(0x3D5, 0xFF);
|
||||
outportb(0x3D4, 15);
|
||||
@ -318,19 +396,19 @@ void show_menu(void) {
|
||||
char b = inportb(0x3C1);
|
||||
b &= ~8;
|
||||
outportb(0x3c0, b);
|
||||
#endif
|
||||
|
||||
clear_();
|
||||
|
||||
do {
|
||||
x = 0;
|
||||
y = 0;
|
||||
attr = 0x1f;
|
||||
move_cursor(0,0);
|
||||
set_attr(0x1f);
|
||||
print_banner(VERSION_TEXT);
|
||||
attr = 0x07;
|
||||
set_attr(0x07);
|
||||
print_("\n");
|
||||
|
||||
for (int i = 0; i < BASE_SEL+1; ++i) {
|
||||
attr = sel == i ? 0x70 : 0x07;
|
||||
set_attr(sel == i ? 0x70 : 0x07);
|
||||
print_(" ");
|
||||
char tmp[] = {'0' + (i + 1), '.', ' ', '\0'};
|
||||
print_(tmp);
|
||||
@ -339,15 +417,15 @@ void show_menu(void) {
|
||||
}
|
||||
|
||||
// put a gap
|
||||
attr = 0x07;
|
||||
set_attr(0x07);
|
||||
print_("\n");
|
||||
|
||||
for (int i = 0; i < sel_max - BASE_SEL - 1; ++i) {
|
||||
toggle(BASE_SEL + 1 + i, *boot_options[i].value, boot_options[i].title);
|
||||
}
|
||||
|
||||
attr = 0x07;
|
||||
y = 17;
|
||||
set_attr(0x07);
|
||||
move_cursor(x,17);
|
||||
print_("\n");
|
||||
print_banner(HELP_TEXT);
|
||||
print_("\n");
|
||||
@ -431,13 +509,3 @@ static void boot(void) {
|
||||
|
||||
while (1);
|
||||
}
|
||||
#else
|
||||
|
||||
void show_menu(void) {
|
||||
Print(L"lol menu goes here\n");
|
||||
}
|
||||
|
||||
static void boot(void) {
|
||||
Print(L"Boop.\n");
|
||||
}
|
||||
#endif
|
||||
|
@ -2,7 +2,7 @@ static int sel_max = 0;
|
||||
static int sel = 0;
|
||||
|
||||
void toggle(int ndx, int value, char *str) {
|
||||
attr = sel == ndx ? 0x70 : 0x07;
|
||||
set_attr(sel == ndx ? 0x70 : 0x07);
|
||||
if (value) {
|
||||
print_(" [X] ");
|
||||
} else {
|
||||
|
42
boot/text.h
42
boot/text.h
@ -1,13 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
static int _debug = 0;
|
||||
static int txt_debug = 0;
|
||||
|
||||
unsigned short * textmemptr = (unsigned short *)0xB8000;
|
||||
static void placech(unsigned char c, int x, int y, int attr) {
|
||||
#ifdef EFI_PLATFORM
|
||||
unsigned short ch;
|
||||
switch (c) {
|
||||
case '\030':
|
||||
ch = L'↑';
|
||||
break;
|
||||
case '\031':
|
||||
ch = L'↓';
|
||||
break;
|
||||
case '\032':
|
||||
ch = L'←';
|
||||
break;
|
||||
case '\033':
|
||||
ch = L'→';
|
||||
break;
|
||||
default:
|
||||
ch = c;
|
||||
break;
|
||||
}
|
||||
uint16_t string[] = {ch, 0};
|
||||
uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, attr);
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, x, y);
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, string);
|
||||
#else
|
||||
unsigned short *where;
|
||||
unsigned att = attr << 8;
|
||||
where = textmemptr + (y * 80 + x);
|
||||
*where = c | att;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int x = 0;
|
||||
@ -39,6 +64,15 @@ static void print_(char * str) {
|
||||
}
|
||||
}
|
||||
|
||||
static void move_cursor(int _x, int _y) {
|
||||
x = _x;
|
||||
y = _y;
|
||||
}
|
||||
|
||||
static void set_attr(int _attr) {
|
||||
attr = _attr;
|
||||
}
|
||||
|
||||
static void print_banner(char * str) {
|
||||
if (!str) {
|
||||
for (int i = 0; i < 80; ++i) {
|
||||
@ -83,7 +117,7 @@ static void clear_() {
|
||||
}
|
||||
}
|
||||
|
||||
#define print(s) do {if (_debug) {print_(s);}} while(0)
|
||||
#define clear() do {if (_debug) {clear_();}} while(0)
|
||||
#define print_hex(d) do {if (_debug) {print_hex_(d);}} while(0)
|
||||
#define print(s) do {if (txt_debug) {print_(s);}} while(0)
|
||||
#define clear() do {if (txt_debug) {clear_();}} while(0)
|
||||
#define print_hex(d) do {if (txt_debug) {print_hex_(d);}} while(0)
|
||||
|
||||
|
@ -96,11 +96,11 @@ int kmain(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) {
|
||||
isrs_install(); /* Interrupt service requests */
|
||||
irq_install(); /* Hardware interrupt requests */
|
||||
|
||||
uintptr_t last_mod = (uintptr_t)&end;
|
||||
if (mboot_ptr->flags & MULTIBOOT_FLAG_MODS) {
|
||||
debug_print(NOTICE, "There %s %d module%s starting at 0x%x.", mboot_ptr->mods_count == 1 ? "is" : "are", mboot_ptr->mods_count, mboot_ptr->mods_count == 1 ? "" : "s", mboot_ptr->mods_addr);
|
||||
debug_print(NOTICE, "Current kernel heap start point would be 0x%x.", &end);
|
||||
if (mboot_ptr->mods_count > 0) {
|
||||
uintptr_t last_mod = (uintptr_t)&end;
|
||||
uint32_t i;
|
||||
mboot_mods = (mboot_mod_t *)mboot_ptr->mods_addr;
|
||||
mboot_mods_count = mboot_ptr->mods_count;
|
||||
@ -111,6 +111,7 @@ int kmain(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) {
|
||||
if ((uintptr_t)mod + sizeof(mboot_mod_t) > last_mod) {
|
||||
/* Just in case some silly person put this *behind* the modules... */
|
||||
last_mod = (uintptr_t)mod + sizeof(mboot_mod_t);
|
||||
debug_print(NOTICE, "moving forward to 0x%x", last_mod);
|
||||
}
|
||||
debug_print(NOTICE, "Module %d is at 0x%x:0x%x", i, module_start, module_end);
|
||||
if (last_mod < module_end) {
|
||||
@ -118,9 +119,12 @@ int kmain(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) {
|
||||
}
|
||||
}
|
||||
debug_print(NOTICE, "Moving kernel heap start to 0x%x", last_mod);
|
||||
kmalloc_startat(last_mod);
|
||||
}
|
||||
}
|
||||
if ((uintptr_t)mboot_ptr > last_mod) {
|
||||
last_mod = (uintptr_t)mboot_ptr + sizeof(struct multiboot);
|
||||
}
|
||||
kmalloc_startat(last_mod);
|
||||
|
||||
if (mboot_ptr->flags & MULTIBOOT_FLAG_MEM) {
|
||||
paging_install(mboot_ptr->mem_upper + mboot_ptr->mem_lower);
|
||||
|
Loading…
Reference in New Issue
Block a user