Add: TAR init ramdisk via GRUB2 module
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
# BlankOS
|
# BlankOS
|
||||||
|
|
||||||
Rewritten monolithic, ring 0, lower-half, singletasking kernel for the x86 processor architecture, using GRUB 2 as bootloader. Emulation was tested on QEMU using Arch Linux 6.9.7-arch1-1, and on real hardware (UEFI and BIOS).
|
Rewritten megalithic, ring 0, lower-half, singletasking kernel for the x86 processor architecture (using 32-bit protected mode), with GRUB 2 as bootloader. Emulation was tested on QEMU using Arch Linux 6.9.7-arch1-1, and on real hardware (UEFI and BIOS).
|
||||||
The long-term goal of this OS is to be capable of running user programs and having its own complete kernel C library so that users can write their own C programs and expand the system!
|
The long-term goal of this OS is to be capable of running user programs and having its own complete kernel C library so that users can write their own C programs and expand the system!
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@@ -65,7 +65,7 @@ Two other documents are available to help you understand the project better. One
|
|||||||
- [X] Kernel-space utilities (shell, simple programs)
|
- [X] Kernel-space utilities (shell, simple programs)
|
||||||
- [ ] Filesystem (FAT32 or VFS ramdisk)
|
- [ ] Filesystem (FAT32 or VFS ramdisk)
|
||||||
- [ ] Changing the default VGA font
|
- [ ] Changing the default VGA font
|
||||||
- [ ] Dynamic memory allocator (get memmap from GRUB?)
|
- [X] Dynamic memory allocator (get memmap from GRUB?)
|
||||||
- [ ] Paging/Page Frame Allocation
|
- [ ] Paging/Page Frame Allocation
|
||||||
- [ ] TCP/IP Network stack
|
- [ ] TCP/IP Network stack
|
||||||
- [ ] Getting to Ring-3 (userspace)
|
- [ ] Getting to Ring-3 (userspace)
|
||||||
|
|||||||
1
grub.cfg
1
grub.cfg
@@ -2,5 +2,6 @@ menuentry "Blank OS" {
|
|||||||
insmod all_video
|
insmod all_video
|
||||||
set gfxpayload=1024x768x32
|
set gfxpayload=1024x768x32
|
||||||
multiboot2 /boot/kernel.elf
|
multiboot2 /boot/kernel.elf
|
||||||
|
module2 /boot/initrd.tar
|
||||||
boot
|
boot
|
||||||
}
|
}
|
||||||
|
|||||||
6
makefile
6
makefile
@@ -49,12 +49,16 @@ toolchain:
|
|||||||
wget $(TOOLCHAIN_SRC)
|
wget $(TOOLCHAIN_SRC)
|
||||||
tar xf $(TOOLCHAIN_FILE)
|
tar xf $(TOOLCHAIN_FILE)
|
||||||
|
|
||||||
iso: kernel.elf
|
iso: kernel.elf initrd
|
||||||
mkdir -p iso/boot/grub
|
mkdir -p iso/boot/grub
|
||||||
cp kernel.elf iso/boot/kernel.elf
|
cp kernel.elf iso/boot/kernel.elf
|
||||||
cp grub.cfg iso/boot/grub/grub.cfg
|
cp grub.cfg iso/boot/grub/grub.cfg
|
||||||
grub-mkrescue iso -o blankos.iso
|
grub-mkrescue iso -o blankos.iso
|
||||||
|
|
||||||
|
initrd:
|
||||||
|
tar -cf $(OBJ_DIR)/initrd.tar -C $(SRC_DIR)/initrd .
|
||||||
|
cp $(OBJ_DIR)/initrd.tar iso/boot
|
||||||
|
|
||||||
run: iso
|
run: iso
|
||||||
qemu-system-i386 -drive file=blankos.iso,format=raw
|
qemu-system-i386 -drive file=blankos.iso,format=raw
|
||||||
|
|
||||||
|
|||||||
1
src/initrd/hello.txt
Normal file
1
src/initrd/hello.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
hello, ramdisk world!
|
||||||
@@ -19,6 +19,7 @@ void kmain(multiboot2_info *mb_info)
|
|||||||
{
|
{
|
||||||
multiboot2_tag_framebuffer *fb_info = NULL;
|
multiboot2_tag_framebuffer *fb_info = NULL;
|
||||||
struct multiboot_tag_mmap *mmap_tag = NULL;
|
struct multiboot_tag_mmap *mmap_tag = NULL;
|
||||||
|
struct multiboot_tag_module *initrd_module = NULL;
|
||||||
|
|
||||||
uint8_t *tags = mb_info->tags;
|
uint8_t *tags = mb_info->tags;
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -32,6 +33,9 @@ void kmain(multiboot2_info *mb_info)
|
|||||||
if (tag_type == MULTIBOOT_TAG_TYPE_MMAP) {
|
if (tag_type == MULTIBOOT_TAG_TYPE_MMAP) {
|
||||||
mmap_tag = (struct multiboot_tag_mmap*) tags;
|
mmap_tag = (struct multiboot_tag_mmap*) tags;
|
||||||
}
|
}
|
||||||
|
if (tag_type == MULTIBOOT_TAG_TYPE_MODULE) {
|
||||||
|
initrd_module = (struct multiboot_tag_module*) tags;
|
||||||
|
}
|
||||||
|
|
||||||
tags += ((tag_size + 7) & ~7);
|
tags += ((tag_size + 7) & ~7);
|
||||||
}
|
}
|
||||||
@@ -42,7 +46,7 @@ void kmain(multiboot2_info *mb_info)
|
|||||||
serial_printf(3, "Framebuffer Pitch: %u", fb_info->framebuffer_pitch);
|
serial_printf(3, "Framebuffer Pitch: %u", fb_info->framebuffer_pitch);
|
||||||
serial_printf(3, "Framebuffer BPP: %u", fb_info->framebuffer_bpp);
|
serial_printf(3, "Framebuffer BPP: %u", fb_info->framebuffer_bpp);
|
||||||
|
|
||||||
if (fb_info) {
|
if (fb_info) { // fb setup
|
||||||
framebuffer = (uint32_t *)(uintptr_t) fb_info->framebuffer_addr;
|
framebuffer = (uint32_t *)(uintptr_t) fb_info->framebuffer_addr;
|
||||||
|
|
||||||
uint32_t width = fb_info->framebuffer_width;
|
uint32_t width = fb_info->framebuffer_width;
|
||||||
@@ -60,7 +64,7 @@ void kmain(multiboot2_info *mb_info)
|
|||||||
printf("[kernel] framebuffer discovered at 0x%x\n", fb_info->framebuffer_addr);
|
printf("[kernel] framebuffer discovered at 0x%x\n", fb_info->framebuffer_addr);
|
||||||
printf("[kernel] fb0: width=%u, height=%u, pitch=%u, bpp=%u\n", fb_info->framebuffer_width, fb_info->framebuffer_height, fb_info->framebuffer_pitch, fb_info->framebuffer_bpp);
|
printf("[kernel] fb0: width=%u, height=%u, pitch=%u, bpp=%u\n", fb_info->framebuffer_width, fb_info->framebuffer_height, fb_info->framebuffer_pitch, fb_info->framebuffer_bpp);
|
||||||
|
|
||||||
if (mmap_tag)
|
if (mmap_tag) // memmap debug print
|
||||||
{
|
{
|
||||||
printf("[kernel] found memory map tag by multiboot2\n");
|
printf("[kernel] found memory map tag by multiboot2\n");
|
||||||
struct multiboot_mmap_entry *mmap = mmap_tag->entries;
|
struct multiboot_mmap_entry *mmap = mmap_tag->entries;
|
||||||
@@ -84,6 +88,16 @@ void kmain(multiboot2_info *mb_info)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (initrd_module) {
|
||||||
|
uint32_t initrd_start = initrd_module->mod_start;
|
||||||
|
uint32_t initrd_end = initrd_module->mod_end;
|
||||||
|
uint32_t initrd_size = initrd_end - initrd_start;
|
||||||
|
|
||||||
|
printf("[kernel] TAR initrd module found at 0x%x, size=%u bytes\n", initrd_start, initrd_size);
|
||||||
|
} else {
|
||||||
|
puts("[kernel] TAR initrd module not found\n");
|
||||||
|
}
|
||||||
|
|
||||||
init_serial();
|
init_serial();
|
||||||
gdt_install();
|
gdt_install();
|
||||||
idt_install();
|
idt_install();
|
||||||
@@ -94,7 +108,8 @@ void kmain(multiboot2_info *mb_info)
|
|||||||
init_alloc();
|
init_alloc();
|
||||||
void* ptr1 = malloc(256);
|
void* ptr1 = malloc(256);
|
||||||
void* ptr2 = malloc(512);
|
void* ptr2 = malloc(512);
|
||||||
free(ptr2);
|
printf("[debug] malloc test ptr1=0x%x, ptr2=0x%x\n", ptr1, ptr2);
|
||||||
|
free(ptr1); free(ptr2);
|
||||||
|
|
||||||
timer_install();
|
timer_install();
|
||||||
keyboard_install();
|
keyboard_install();
|
||||||
|
|||||||
Reference in New Issue
Block a user