我目前正在操作系统上,我的问题是关于从MakeFile创建的mykernel.iso。我的发行版是Kali Linux,我遇到的问题与引导有关。
在我的目录中,我有Makefile
,kernel.cpp
,kernel.o
,linker.d
,loader.o
,loader.s
,types.h
,mykernel.o
,mykernel.iso
。当我使用VirtualBox引导mykernel.iso时,出现错误
(也mykernel.iso应该是4 mb,我的是340 kb)
以下是代码:
GCCPARAMS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore
ASPARAMS = --32
LDPARAMS = -melf_i386
objects = loader.o kernel.o
%.o: %.cpp
gcc $(GCCPARAMS) -c -o $@ $<
%.o: %.s
as $(ASPARAMS) -o $@ $<
mykernel.bin: linker.ld $(objects)
ld $(LDPARAMS) -T $< -o $@ $(objects)
mykernel.iso: mykernel.bin
mkdir iso
mkdir iso/boot
mkdir iso/boot/grub
cp mykernel.bin iso/boot/mykernel.bin
echo 'set timeout=0' > iso/boot/grub/grub.cfg
echo 'set default=0' >> iso/boot/grub/grub.cfg
echo '' >> iso/boot/grub/grub.cfg
echo 'menuentry "My Operating System" {' >> iso/boot/grub/grub.cfg
echo ' multiboot /boot/mykernel.bin' >> iso/boot/grub/grub.cfg
echo ' boot' >> iso/boot/grub/grub.cfg
echo '}' >> iso/boot/grub/grub.cfg
grub-mkrescue --output=mykernel.iso iso
rm -rf iso
run: mykernel.iso
(killall VirtualBox && sleep 1) || true
VirtualBox --startvm 'My Operating System' &
install: mykernel.bin
sudo cp $< /boot/mykernel.bin
kernel.cpp:
#include "types.h"
void printf(char* str)
{
static uint16_t* VideoMemory = (uint16_t*)0xb8000;
for(int i = 0; str[i] != '\0'; ++i)
VideoMemory[i] = (VideoMemory[i] & 0xFF00) | str[i];
}
typedef void (*constructor)();
extern "C" constructor start_ctors;
extern "C" constructor end_ctors;
extern "C" void callConstructors()
{
for(constructor* i = &start_ctors; i != &end_ctors; i++)
(*i)();
}
extern "C" void kernelMain(const void* multiboot_structure, uint32_t /*multiboot_magic*/)
{
printf("Welcome To My Operating System");
while(1);
}
有什么建议吗?
最佳答案
看起来您在Kali Distro上。切换到Ubuntu并应用
sudo apt-get install xorriso
应该像一个有魅力的儿子一样工作。