Now actually runs.
parent
1ba4954e58
commit
236f28e1c7
|
@ -0,0 +1,3 @@
|
||||||
|
file kernel.bin
|
||||||
|
target remote localhost:1234
|
||||||
|
set step-mode on
|
10
Makefile
10
Makefile
|
@ -19,7 +19,7 @@ CX:=$(ENV)/$(TARGET)-g++
|
||||||
AS:=nasm
|
AS:=nasm
|
||||||
LD:=$(ENV)/$(TARGET)-ld
|
LD:=$(ENV)/$(TARGET)-ld
|
||||||
|
|
||||||
CFLAGS:=-Wall -Wextra -Werror -nostdlib -nostartfiles -nodefaultlibs -std=c99
|
CFLAGS:=-Wall -Werror -nostdlib -nostartfiles -nodefaultlibs -std=c99 -g
|
||||||
CFLAGS+=-I ./include
|
CFLAGS+=-I ./include
|
||||||
LFLAGS:=-nostdlib -nostartfiles -nodefaultlibs
|
LFLAGS:=-nostdlib -nostartfiles -nodefaultlibs
|
||||||
|
|
||||||
|
@ -60,8 +60,14 @@ hdd.img: kernel.bin
|
||||||
@mcopy -i hdd_temp.img dst/syslinux.cfg ::syslinux.cfg
|
@mcopy -i hdd_temp.img dst/syslinux.cfg ::syslinux.cfg
|
||||||
@mv hdd_temp.img hdd.img
|
@mv hdd_temp.img hdd.img
|
||||||
|
|
||||||
emulate-nohdd: kernel.bin
|
emulate-nohdd-debug: kernel.bin
|
||||||
|
@echo "[i] Starting GDB..."
|
||||||
|
@gnome-terminal -x /bin/bash -c "gdb"
|
||||||
@echo "[i] Starting QEmu..."
|
@echo "[i] Starting QEmu..."
|
||||||
|
@qemu -kernel kernel.bin -S -gdb tcp::1234
|
||||||
|
|
||||||
|
emulate-nohdd: kernel.bin
|
||||||
|
@echo "[i] Starting QEMU..."
|
||||||
@qemu -kernel kernel.bin
|
@qemu -kernel kernel.bin
|
||||||
|
|
||||||
emulate: hdd.img
|
emulate: hdd.img
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#ifndef __PAGING_H__
|
#ifndef __PAGING_H__
|
||||||
#define __PAGING_H__
|
#define __PAGING_H__
|
||||||
|
|
||||||
void init_simple_paging(void);
|
void paging_init_simple(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,9 +15,11 @@ STACKSIZE equ 0x4000
|
||||||
; ############################## text segment #################################
|
; ############################## text segment #################################
|
||||||
; #############################################################################
|
; #############################################################################
|
||||||
|
|
||||||
section .text
|
section .setup
|
||||||
align 4
|
align 4
|
||||||
|
|
||||||
|
global g_before_gdt
|
||||||
|
|
||||||
; Multiboot header
|
; Multiboot header
|
||||||
MultiBootHeader:
|
MultiBootHeader:
|
||||||
dd MAGIC
|
dd MAGIC
|
||||||
|
@ -27,15 +29,18 @@ MultiBootHeader:
|
||||||
; Actual entry point
|
; Actual entry point
|
||||||
_start:
|
_start:
|
||||||
lgdt [falsegdt]
|
lgdt [falsegdt]
|
||||||
mov ax, 0x10
|
mov cx, 0x10
|
||||||
mov ds, ax
|
mov ds, cx
|
||||||
mov es, ax
|
mov es, cx
|
||||||
mov fs, ax
|
mov fs, cx
|
||||||
mov gs, ax
|
mov gs, cx
|
||||||
mov ss, ax
|
mov ss, cx
|
||||||
|
g_before_gdt:
|
||||||
jmp 0x08:higherhalf
|
jmp 0x08:higherhalf
|
||||||
|
|
||||||
|
section .text
|
||||||
|
align 4
|
||||||
|
|
||||||
higherhalf:
|
higherhalf:
|
||||||
mov esp, kstack + STACKSIZE
|
mov esp, kstack + STACKSIZE
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,9 @@
|
||||||
// Real kernel entry point, called from _start.asm
|
// Real kernel entry point, called from _start.asm
|
||||||
void kmain(void *mbd, u32 magic)
|
void kmain(void *mbd, u32 magic)
|
||||||
{
|
{
|
||||||
init_simple_paging();
|
kclear();
|
||||||
gdt_create_flat();
|
kprintf("[i] Welcome to Cucumber!\n\n");
|
||||||
|
kprintf("[i] Magic from bootloader: 0x%x.\n", magic);
|
||||||
|
|
||||||
if (magic != 0x2BADB002)
|
if (magic != 0x2BADB002)
|
||||||
{
|
{
|
||||||
|
@ -15,10 +16,7 @@ void kmain(void *mbd, u32 magic)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *szBootLoaderName = (char *)((u32 *)mbd)[16];
|
paging_init_simple();
|
||||||
|
gdt_create_flat();
|
||||||
kclear();
|
|
||||||
kprintf("[i] Booting via %s.\n", szBootLoaderName);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,9 +101,9 @@ void kscroll_up(void)
|
||||||
if (g_kstdio_cur_y >= 25)
|
if (g_kstdio_cur_y >= 25)
|
||||||
{
|
{
|
||||||
Temp = g_kstdio_cur_y - 25 + 1;
|
Temp = g_kstdio_cur_y - 25 + 1;
|
||||||
kmemcpy((void*)0xB8000, (void*)(0xB8000 - Temp * 80 * 2), (25 - Temp) * 80 * 2);
|
kmemcpy((void*)0xC00B8000, (void*)(0xC00B8000 - Temp * 80 * 2), (25 - Temp) * 80 * 2);
|
||||||
|
|
||||||
kmemsetw((void*)(0xB8000 + (25 - Temp) * 80), Blank, 80);
|
kmemsetw((void*)(0xC00B8000 + (25 - Temp) * 80), Blank, 80);
|
||||||
g_kstdio_cur_y = 25 - 1;
|
g_kstdio_cur_y = 25 - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,7 @@ void kdump(u8 *bData, u32 Length)
|
||||||
|
|
||||||
void kputch(s8 Character)
|
void kputch(s8 Character)
|
||||||
{
|
{
|
||||||
volatile u8 *VideoMemory = (u8 *)0xB8000;
|
volatile u8 *VideoMemory = (u8 *)0xC00B8000;
|
||||||
u16 Offset = (g_kstdio_cur_y * 80 + g_kstdio_cur_x) << 1;
|
u16 Offset = (g_kstdio_cur_y * 80 + g_kstdio_cur_x) << 1;
|
||||||
|
|
||||||
if (Character == '\n')
|
if (Character == '\n')
|
||||||
|
@ -207,7 +207,7 @@ void kprint(s8 *szString)
|
||||||
|
|
||||||
void kclear(void)
|
void kclear(void)
|
||||||
{
|
{
|
||||||
volatile u8 *VideoMemory = (u8 *)0xB8000;
|
volatile u8 *VideoMemory = (u8 *)0xC00B8000;
|
||||||
u32 Size = (80 * 25 ) << 1;
|
u32 Size = (80 * 25 ) << 1;
|
||||||
for (u32 i = 0; i < Size; i += 2)
|
for (u32 i = 0; i < Size; i += 2)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,24 +1,58 @@
|
||||||
#include "Tier0/paging.h"
|
#include "Tier0/paging.h"
|
||||||
|
#include "Tier0/kstdio.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
u32 g_kernel_page_directory[1024] __attribute__ ((aligned (4096)));
|
u32 g_kernel_page_directory[1024] __attribute__ ((aligned (4096)));
|
||||||
u32 g_low_page_table[1024] __attribute__ ((aligned (4096)));
|
u32 g_low_page_table[1024] __attribute__ ((aligned (4096)));
|
||||||
|
|
||||||
void init_simple_paging(void)
|
/*u8 paging_get_physical(u32 Virtual, u32 *Physical)
|
||||||
|
{
|
||||||
|
u16 Index =
|
||||||
|
|
||||||
|
u32 DirectoryEntry = g_kernel_page_directory[Index];
|
||||||
|
|
||||||
|
u8 TablePresent = DirectoryEntry & 0b1;
|
||||||
|
|
||||||
|
if (!TablePresent)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
u32 TableAddress = 0;
|
||||||
|
TableAddress |= (DirectoryEntry & 0xFFFFF000);
|
||||||
|
|
||||||
|
u32 Table = *((u32 *) &TableAddress);
|
||||||
|
|
||||||
|
u8 PagePresent = DirectoryEntry &
|
||||||
|
}*/
|
||||||
|
|
||||||
|
void paging_dump_directory(void)
|
||||||
|
{
|
||||||
|
for (u32 i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
kprintf("[i] Virtual 0x%X - 0x%X, Entry 0x%X.\n", i * 4096 * 1024, (i + 1) * 4096 * 1024, g_kernel_page_directory[i] & 0xFFFFF000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void paging_init_simple(void)
|
||||||
{
|
{
|
||||||
void *RealKernelPageDir = (u8 *)g_kernel_page_directory + 0x40000000;
|
void *RealKernelPageDir = (u8 *)g_kernel_page_directory + 0x40000000;
|
||||||
void *RealLowPageTable = (u8 *)g_low_page_table + 0x40000000;
|
void *RealLowPageTable = (u8 *)g_low_page_table + 0x40000000;
|
||||||
|
|
||||||
for (u16 i = 0; i < 1024; i++)
|
for (u16 i = 0; i < 1024; i++)
|
||||||
{
|
{
|
||||||
g_kernel_page_directory[i] = (i * 4096) | 0x03;
|
g_low_page_table[i] = (i * 4096) | 0x03;
|
||||||
g_low_page_table[i] = 0;
|
g_kernel_page_directory[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kprintf("[i] Page Directory Physical: 0x%X, Virtual: 0x%X.\n", RealKernelPageDir, g_kernel_page_directory);
|
||||||
|
kprintf("[i] Low Page Table Physical: 0x%X, Virtual: 0x%X.\n", RealLowPageTable, g_low_page_table);
|
||||||
|
|
||||||
g_kernel_page_directory[0] = (u32)RealLowPageTable | 0x03;
|
g_kernel_page_directory[0] = (u32)RealLowPageTable | 0x03;
|
||||||
g_kernel_page_directory[768] = (u32)RealLowPageTable | 0x03;
|
g_kernel_page_directory[768] = (u32)RealLowPageTable | 0x03;
|
||||||
|
|
||||||
|
paging_dump_directory();
|
||||||
|
|
||||||
__asm__ volatile ( "mov %0, %%eax\n"
|
|
||||||
|
__asm volatile ( "mov %0, %%eax\n"
|
||||||
"mov %%eax, %%cr3\n"
|
"mov %%eax, %%cr3\n"
|
||||||
"mov %%cr0, %%eax\n"
|
"mov %%cr0, %%eax\n"
|
||||||
"orl $0x80000000, %%eax\n"
|
"orl $0x80000000, %%eax\n"
|
||||||
|
|
|
@ -1,31 +1,48 @@
|
||||||
OUTPUT_FORMAT("elf32-i386")
|
OUTPUT_FORMAT("elf32-i386")
|
||||||
ENTRY(_start)
|
ENTRY(_start)
|
||||||
|
|
||||||
|
Offset = 0x00100000;
|
||||||
|
LMA = 0x00000000;
|
||||||
|
VMA = 0xC0000000;
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
. = 0x100000;
|
. = Offset;
|
||||||
.setup :
|
|
||||||
|
g_setup_gdt_ptr = g_gdt_ptr - VMA;
|
||||||
|
g_setup_gdt_entries = g_gdt_entries - VMA;
|
||||||
|
|
||||||
|
.setup LMA + Offset : AT(LMA + Offset)
|
||||||
{
|
{
|
||||||
*(.setup)
|
*(.setup)
|
||||||
|
. = ALIGN(0x1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
. += 0xC0000000;
|
. += VMA;
|
||||||
|
|
||||||
.text : AT(ADDR(.text) - 0xC0000000)
|
.text : AT(g_section_code)
|
||||||
{
|
{
|
||||||
|
g_section_code = . - VMA;
|
||||||
*(.text)
|
*(.text)
|
||||||
|
. = ALIGN(0x1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
.data ALIGN (4096) : AT(ADDR(.data) - 0xC0000000)
|
.data : AT(g_section_data)
|
||||||
{
|
{
|
||||||
|
g_section_data = . - VMA;
|
||||||
*(.data)
|
*(.data)
|
||||||
*(.rodata*)
|
*(.rodata*)
|
||||||
|
. = ALIGN(0x1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
.bss ALIGN (4096) : AT(ADDR(.bss) - 0xC0000000)
|
.bss : AT(g_section_bss)
|
||||||
{
|
{
|
||||||
|
g_section_bss = . - VMA;
|
||||||
*(COMMON*)
|
*(COMMON*)
|
||||||
*(.bss*)
|
*(.bss*)
|
||||||
|
. = ALIGN(0x1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
. = ALIGN(0x1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue