diff --git a/arch/i386/i386_main.c b/arch/i386/i386_main.c new file mode 100644 index 0000000..621f859 --- /dev/null +++ b/arch/i386/i386_main.c @@ -0,0 +1,30 @@ +#include + +void main(); + +void i386_main(void) +{ + extern uint32_t magic; + + /* Uncomment the following if you want to be able to access the multiboot header */ + /* extern void *mbd; */ + + if ( magic != 0x2BADB002 ) + { + /* Something went not according to specs. Print an error */ + /* message and halt, but do *not* rely on the multiboot */ + /* data structure. */ + } + + /* You could either use multiboot.h */ + /* (http://www.gnu.org/software/grub/manual/multiboot/multiboot.html#multiboot_002eh) */ + /* or do your offsets yourself. The following is merely an example. */ + //char * boot_loader_name =(char*) ((long*)mbd)[16]; + + /* Print a letter to screen to see everything is working: */ + unsigned char *videoram = (unsigned char *)0xB8000; + videoram[0] = 65; /* character 'A' */ + videoram[1] = 0x07; /* light grey (7) on black (0). */ + + main(); +} diff --git a/arch/i386/include/arch/types.h b/arch/i386/include/arch/types.h new file mode 100644 index 0000000..b8b7c51 --- /dev/null +++ b/arch/i386/include/arch/types.h @@ -0,0 +1,23 @@ +/* + Copyright (C) 2012, Aaron Lindsay + + This file is part of Aedrix. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +#define arch_uint_ptr uint32 diff --git a/arch/i386/kernel.ld b/arch/i386/kernel.ld new file mode 100644 index 0000000..095a4a2 --- /dev/null +++ b/arch/i386/kernel.ld @@ -0,0 +1,18 @@ +ENTRY (start) + +SECTIONS +{ + . = 0x00100000; + .text ALIGN (0x1000) : { *(.text*) *(.rodata*) } + .init : { + early_initcalls_start = .; + *(.earlyinitcalls*) + early_initcalls_end = .; + initcalls_start = .; + *(.driversubsysinitcalls*) + *(.deviceinitcalls*) + initcalls_end = .; + } + .data ALIGN (0x1000) : { *(.data*) } + .bss : { *(.bss*) *(COMMON*) } +} diff --git a/arch/i386/kernel.mk b/arch/i386/kernel.mk new file mode 100644 index 0000000..c72a14d --- /dev/null +++ b/arch/i386/kernel.mk @@ -0,0 +1,32 @@ +DIRNAME := arch/i386 +SUBDIRS := kernel + +include $(BASEDIR)/header.mk + +# Architecture-specific definitions +CROSS_COMPILE ?= +ARCH_KCFLAGS = -m32 +ARCH_KLDFLAGS = -melf_i386 + +all: aedrix-boot.img + +HD_IMAGE_SIZE := $(shell echo $$((4*1024*1024))) +HD_NUM_BLOCKS := $(shell echo $$(($(HD_IMAGE_SIZE)/4096))) +KERNEL_ARGS := +aedrix-boot.img: aedrix-kernel.elf + @echo ' BUILD aedrix-boot.img' + $(V)dd if=/dev/zero of="$@" bs=4k count=$(HD_NUM_BLOCKS) 2>/dev/null + $(V)mkfs.vfat "$@" 1>/dev/null + $(V)syslinux "$@" + $(V)mcopy -i "$@" /usr/lib/syslinux/mboot.c32 ::mboot.c32 + $(V)mcopy -i "$@" aedrix-kernel.elf ::kernel.bin + $(V)mcopy -i "$@" arch/i386/syslinux.cfg ::syslinux.cfg + +OBJS_$(d) := $(d)/start.o \ + $(d)/i386_main.o + +KOBJS += $(OBJS_$(d)) + +include $(BASEDIR)/footer.mk + +ARCH_QEMU_CMD = qemu-system-i386 -m 1024 diff --git a/arch/i386/kernel/kernel.mk b/arch/i386/kernel/kernel.mk new file mode 100644 index 0000000..71b6419 --- /dev/null +++ b/arch/i386/kernel/kernel.mk @@ -0,0 +1,10 @@ +DIRNAME := kernel +SUBDIRS := + +include $(BASEDIR)/header.mk + +OBJS_$(d) := $(d)/mmu.o + +KOBJS += $(OBJS_$(d)) + +include $(BASEDIR)/footer.mk diff --git a/arch/i386/kernel/mmu.c b/arch/i386/kernel/mmu.c new file mode 100644 index 0000000..e91a3f7 --- /dev/null +++ b/arch/i386/kernel/mmu.c @@ -0,0 +1,30 @@ +/* + Copyright (C) 2012, Aaron Lindsay + + This file is part of Aedrix. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include + +void mmu_reinit() { +} +void declare_memory_region(void *lower, void *upper) { + (void)lower; + (void)upper; +} diff --git a/arch/i386/start.S b/arch/i386/start.S new file mode 100644 index 0000000..4f13569 --- /dev/null +++ b/arch/i386/start.S @@ -0,0 +1,56 @@ +/* + Copyright (C) 2012, Aaron Lindsay + + This file is part of Aedrix. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +.global start /* making entry point visible to linker */ + +/* setting up the Multiboot header - see GRUB docs for details */ +.set ALIGN, 1<<0 /* align loaded modules on page boundaries */ +.set MEMINFO, 1<<1 /* provide memory map */ +.set FLAGS, ALIGN | MEMINFO /* this is the Multiboot 'flag' field */ +.set MAGIC, 0x1BADB002 /* 'magic number' lets bootloader find the header */ +.set CHECKSUM, -(MAGIC + FLAGS) /* checksum required */ + +.align 4 +.long MAGIC +.long FLAGS +.long CHECKSUM + +/* reserve initial kernel stack space */ +.set STACKSIZE, 0x4000 /* that is, 16k. */ +.align 32 +.lcomm stack, STACKSIZE /* reserve 16k stack on a doubleword boundary */ +.comm mbd, 4 /* we will use this in i386_main */ +.comm magic, 4 /* we will use this in i386_main */ + +start: + movl $(stack + STACKSIZE), %esp /* set up the stack */ + movl %eax, magic /* Multiboot magic number */ + movl %ebx, mbd /* Multiboot data structure */ + + call i386_main /* call kernel proper */ + + cli +hang: + hlt /* halt machine should kernel return */ + jmp hang + +.globl atags_ptr +atags_ptr: + .word 0 diff --git a/arch/i386/syslinux.cfg b/arch/i386/syslinux.cfg new file mode 100644 index 0000000..e788891 --- /dev/null +++ b/arch/i386/syslinux.cfg @@ -0,0 +1,2 @@ +TIMEOUT 1 +DEFAULT mboot.c32 kernel.bin ''