changeset 11:26b76ada8c13

add README.txt. This file contain TODO and how to way boot cbc_os.
author Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
date Thu, 30 Aug 2012 21:31:23 +0900
parents 50e4b9ca4867
children b045d733207e
files Makefile README.txt bootstrap.S
diffstat 3 files changed, 77 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Mon Aug 27 23:45:31 2012 +0900
+++ b/Makefile	Thu Aug 30 21:31:23 2012 +0900
@@ -1,10 +1,9 @@
-HOME		= /Users/TaikiTAIRA
+HOME		= /Users/taira
 prefix		= $(HOME)/cross/COMMON_INSTALL/bin
 CBC			= $(prefix)/elf-cbc-gcc-4.6.0
 LD			= $(prefix)/x86_64-elf-ld
 
-CBCFLAGS	= -m32 \
-			  -ffreestanding \
+CBCFLAGS	= -ffreestanding \
 			  -fno-common \
 			  -fno-builtin \
 			  -fomit-frame-pointer \
@@ -14,10 +13,10 @@
 			  -c \
 			  -o
 
-LDFLAGS		= -m elf_i386 \
+LDFLAGS		= -m elf_x86_64 \
 			  -nostdlib \
 			  -Ttext 0x100000 \
-			  --oformat elf32-i386 \
+			  --oformat elf64-x86-64 \
 			  -o 
 
 TARGET=cbc_os.elf
@@ -25,14 +24,16 @@
 all: $(TARGET)
 
 kernel.o: kernel.cbc 
-	$(CBC) $(CBCFLAGS) $@ $^ 
+	$(CBC) -m64 $(CBCFLAGS) $@ $^ 
 
 bootstrap.o: bootstrap.S 
-	$(CBC) $(CBCFLAGS) $@  $^
+	$(CBC) -m64 $(CBCFLAGS) $@ $^
 
-$(TARGET): bootstrap.o kernel.o
+head32.o: head32.S
+	$(CBC) -m64 $(CBCFLAGS) $@ $^ 
+
+$(TARGET): bootstrap.o kernel.o head32.o
 	$(LD) $(LDFLAGS) $@ $^
 
-
 clean:
 	rm -rf *.o *.elf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.txt	Thu Aug 30 21:31:23 2012 +0900
@@ -0,0 +1,54 @@
+TODO
+grub2 から OS を起動するための multiboot header magic が認識されていないので、認識されて起動できるようにする。
+
+
+【環境】
+//binutils
+configure --target=x86_64-elf --enable-64-bit-bfd
+
+//newlib
+コンパイルして cbc-gcc のディレクトリにシンボリックリンクを貼る
+
+
+//cbc-gcc
+configure --target=x86_64-elf --disabble-bootstrap --enable-languages=c \
+--enable-checking=tree,rtl,assert,types --disable-nls --with-newlib --without-headers --disable-libssp --disable-libquadmath
+
+
+【コンパイル】
+//64bit
+gcc -m64 \
+    --ffreestanding -fno-common \
+    -fomit-frame-pointer \
+    -g \
+    -Wall \
+    -O2 \
+
+//32bit
+gcc -m32
+    あとは 64bit と同じ
+
+ld -m elf_x86_64 \
+    -nostdlib \
+    -Ttext 0x100000 \
+    --oformat elf64-x86-64 or --oformat elf32-i386
+
+【実行】
+fd.img をgrub2 の乗っている VM に接続
+grub2 の OS 選択画面で C を押す
+
+bash like. tab 補完きく
+コマンド実行画面で
+
+>ls
+接続されている記憶媒体の表示
+
+>set root=(記憶媒体,ファイルシステム)
+    ex: set root=(fd0,msdos1)
+
+>multiboot2 /cbc_os.elf
+boot 前の下準備。OS のロード。
+
+>boot
+boot する。
+
--- a/bootstrap.S	Mon Aug 27 23:45:31 2012 +0900
+++ b/bootstrap.S	Thu Aug 30 21:31:23 2012 +0900
@@ -3,36 +3,17 @@
  * Change mode to 64bit mode and go to CbC kernel.
  */
 
-#include "multiboot2.h"
-#include "boot_header.h"
-
 .file "bootstrap.S"
 
-.text
 .code32
-.globl _start
 
-_start:
-    jmp move_longmode
-    /* Align 64 bit boundly. */
-    .align 8
-multiboot_header:
-    .long MULTIBOOT2_HEADER_MAGIC
-    .long MULTIBOOT_ARCHITECTURE_I386
-    .long multiboot_header_end - multiboot_header
-    .long -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + (multiboot_header_end - multiboot_header))
-    .short MULTIBOOT_HEADER_TAG_END
-    .short 0
-    .long 8
-multiboot_header_end:
-
+#include "boot_header.h"
 
 /*
  * Prepare for entering 64bit-mode.
  */
 
 move_longmode:
-
     /* load new GDT */
     leal gdt(%ebp), %eax
     movl %eax, gdt+2(%ebp)
@@ -96,17 +77,26 @@
     rdmsr
     btsl $EFER_LME, %eax 
     wrmsr
+    
+    pushl $(12*8)
+    leal start_kernel(%ebp), %eax
+    pushl %eax
 
+    /* activating Long Mode */
+    movl %eax, %cr0
     
     jmp start_kernel
 
 
-/* jump to kernel.
+/* 
+ * jump to kernel.
  * push ebx and eax send argument to kernel.
  */
+.code64
+
 start_kernel:
-    pushl %ebx
-    pushl %eax
+    pushq %rbx
+    pushq %rax
     call kmain 
 
 .data