Browse Source

i386: Add new arch support! (woefully incomplete)

Aaron Lindsay 7 years ago
parent
commit
cee0ac7dda

+ 30 - 0
arch/i386/i386_main.c

@@ -0,0 +1,30 @@
1
+#include <stdint.h>
2
+
3
+void main();
4
+ 
5
+void i386_main(void)
6
+{
7
+   extern uint32_t magic;
8
+ 
9
+   /* Uncomment the following if you want to be able to access the multiboot header */
10
+   /* extern void *mbd; */
11
+ 
12
+   if ( magic != 0x2BADB002 )
13
+   {
14
+      /* Something went not according to specs. Print an error */
15
+      /* message and halt, but do *not* rely on the multiboot */
16
+      /* data structure. */
17
+   }
18
+ 
19
+   /* You could either use multiboot.h */
20
+   /* (http://www.gnu.org/software/grub/manual/multiboot/multiboot.html#multiboot_002eh) */
21
+   /* or do your offsets yourself. The following is merely an example. */ 
22
+   //char * boot_loader_name =(char*) ((long*)mbd)[16];
23
+ 
24
+   /* Print a letter to screen to see everything is working: */
25
+   unsigned char *videoram = (unsigned char *)0xB8000;
26
+   videoram[0] = 65; /* character 'A' */
27
+   videoram[1] = 0x07; /* light grey (7) on black (0). */
28
+
29
+   main();
30
+}

+ 23 - 0
arch/i386/include/arch/types.h

@@ -0,0 +1,23 @@
1
+/*
2
+    Copyright (C) 2012, Aaron Lindsay <aaron@aclindsay.com>
3
+
4
+    This file is part of Aedrix.
5
+
6
+    This program is free software; you can redistribute it and/or modify
7
+    it under the terms of the GNU General Public License as published by
8
+    the Free Software Foundation; either version 2 of the License, or
9
+    (at your option) any later version.
10
+
11
+    This program is distributed in the hope that it will be useful,
12
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+    GNU General Public License for more details.
15
+
16
+    You should have received a copy of the GNU General Public License along
17
+    with this program; if not, write to the Free Software Foundation, Inc.,
18
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
+ */
20
+
21
+#include <arch-generic/types.h>
22
+
23
+#define arch_uint_ptr uint32

+ 18 - 0
arch/i386/kernel.ld

@@ -0,0 +1,18 @@
1
+ENTRY (start)
2
+
3
+SECTIONS
4
+{
5
+	. = 0x00100000;
6
+	.text ALIGN (0x1000) : { *(.text*) *(.rodata*) }
7
+	.init : {
8
+		early_initcalls_start = .;
9
+		*(.earlyinitcalls*)
10
+		early_initcalls_end = .;
11
+		initcalls_start = .;
12
+		*(.driversubsysinitcalls*)
13
+		*(.deviceinitcalls*)
14
+		initcalls_end = .;
15
+	}
16
+	.data ALIGN (0x1000) : { *(.data*) }
17
+	.bss : { *(.bss*) *(COMMON*) }
18
+}

+ 32 - 0
arch/i386/kernel.mk

@@ -0,0 +1,32 @@
1
+DIRNAME := arch/i386
2
+SUBDIRS := kernel
3
+
4
+include $(BASEDIR)/header.mk
5
+
6
+# Architecture-specific definitions
7
+CROSS_COMPILE ?= 
8
+ARCH_KCFLAGS = -m32
9
+ARCH_KLDFLAGS = -melf_i386
10
+
11
+all: aedrix-boot.img
12
+
13
+HD_IMAGE_SIZE := $(shell echo $$((4*1024*1024)))
14
+HD_NUM_BLOCKS := $(shell echo $$(($(HD_IMAGE_SIZE)/4096)))
15
+KERNEL_ARGS := 
16
+aedrix-boot.img: aedrix-kernel.elf
17
+	@echo '  BUILD   aedrix-boot.img'
18
+	$(V)dd if=/dev/zero of="$@" bs=4k count=$(HD_NUM_BLOCKS) 2>/dev/null
19
+	$(V)mkfs.vfat "$@" 1>/dev/null
20
+	$(V)syslinux "$@"
21
+	$(V)mcopy -i "$@" /usr/lib/syslinux/mboot.c32 ::mboot.c32
22
+	$(V)mcopy -i "$@" aedrix-kernel.elf ::kernel.bin
23
+	$(V)mcopy -i "$@" arch/i386/syslinux.cfg ::syslinux.cfg
24
+
25
+OBJS_$(d) := $(d)/start.o \
26
+	$(d)/i386_main.o
27
+
28
+KOBJS += $(OBJS_$(d))
29
+
30
+include $(BASEDIR)/footer.mk
31
+
32
+ARCH_QEMU_CMD = qemu-system-i386 -m 1024

+ 10 - 0
arch/i386/kernel/kernel.mk

@@ -0,0 +1,10 @@
1
+DIRNAME := kernel
2
+SUBDIRS :=
3
+
4
+include $(BASEDIR)/header.mk
5
+
6
+OBJS_$(d) := $(d)/mmu.o
7
+
8
+KOBJS += $(OBJS_$(d))
9
+
10
+include $(BASEDIR)/footer.mk

+ 30 - 0
arch/i386/kernel/mmu.c

@@ -0,0 +1,30 @@
1
+/*
2
+    Copyright (C) 2012, Aaron Lindsay <aaron@aclindsay.com>
3
+
4
+    This file is part of Aedrix.
5
+
6
+    This program is free software; you can redistribute it and/or modify
7
+    it under the terms of the GNU General Public License as published by
8
+    the Free Software Foundation; either version 2 of the License, or
9
+    (at your option) any later version.
10
+
11
+    This program is distributed in the hope that it will be useful,
12
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+    GNU General Public License for more details.
15
+
16
+    You should have received a copy of the GNU General Public License along
17
+    with this program; if not, write to the Free Software Foundation, Inc.,
18
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
+ */
20
+
21
+#include <print.h>
22
+#include <types.h>
23
+#include <mm.h>
24
+
25
+void mmu_reinit() {
26
+}
27
+void declare_memory_region(void *lower, void *upper) {
28
+	(void)lower;
29
+	(void)upper;
30
+}

+ 56 - 0
arch/i386/start.S

@@ -0,0 +1,56 @@
1
+/*
2
+    Copyright (C) 2012, Aaron Lindsay <aaron@aclindsay.com>
3
+
4
+    This file is part of Aedrix.
5
+
6
+    This program is free software; you can redistribute it and/or modify
7
+    it under the terms of the GNU General Public License as published by
8
+    the Free Software Foundation; either version 2 of the License, or
9
+    (at your option) any later version.
10
+
11
+    This program is distributed in the hope that it will be useful,
12
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+    GNU General Public License for more details.
15
+
16
+    You should have received a copy of the GNU General Public License along
17
+    with this program; if not, write to the Free Software Foundation, Inc.,
18
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
+ */
20
+
21
+.global start /* making entry point visible to linker */
22
+
23
+/* setting up the Multiboot header - see GRUB docs for details */
24
+.set ALIGN,    1<<0                     /* align loaded modules on page boundaries */
25
+.set MEMINFO,  1<<1                     /* provide memory map */
26
+.set FLAGS,    ALIGN | MEMINFO          /* this is the Multiboot 'flag' field */
27
+.set MAGIC,    0x1BADB002               /* 'magic number' lets bootloader find the header */
28
+.set CHECKSUM, -(MAGIC + FLAGS)         /* checksum required */
29
+
30
+.align 4
31
+.long MAGIC
32
+.long FLAGS
33
+.long CHECKSUM
34
+
35
+/* reserve initial kernel stack space */
36
+.set STACKSIZE, 0x4000                  /* that is, 16k. */
37
+.align 32
38
+.lcomm stack, STACKSIZE                 /* reserve 16k stack on a doubleword boundary */
39
+.comm  mbd, 4                           /* we will use this in i386_main */
40
+.comm  magic, 4                         /* we will use this in i386_main */
41
+
42
+start:
43
+    movl  $(stack + STACKSIZE), %esp    /* set up the stack */
44
+    movl  %eax, magic                   /* Multiboot magic number */
45
+    movl  %ebx, mbd                     /* Multiboot data structure */
46
+
47
+    call  i386_main                     /* call kernel proper */
48
+
49
+    cli
50
+hang:
51
+    hlt                                 /* halt machine should kernel return */
52
+    jmp   hang
53
+
54
+.globl atags_ptr
55
+atags_ptr:
56
+	.word 0

+ 2 - 0
arch/i386/syslinux.cfg

@@ -0,0 +1,2 @@
1
+TIMEOUT 1
2
+DEFAULT mboot.c32 kernel.bin ''