Mercurial > hg > Members > taiki > original_os
changeset 19:f8ef856d6691
two new test directory
author | Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 09 Oct 2012 17:35:53 +0900 |
parents | 9e2112e2c596 |
children | 4205fb316c14 |
files | Kernel/bootstrap.S Kernel_withGRUB2/Makefile Kernel_withGRUB2/Makefile.def Kernel_withGRUB2/boot/Makefile Kernel_withGRUB2/boot/bootstrap.S Kernel_withGRUB2/boot/head64.S head64test/Makefile head64test/head64.S head64test/ipl.S head64test/ipl.ld ipltest/Makefile ipltest/fd.img ipltest/ipl.S ipltest/ipl.ld ipltest/out.bin |
diffstat | 15 files changed, 368 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/Kernel/bootstrap.S Mon Oct 01 19:01:39 2012 +0900 +++ b/Kernel/bootstrap.S Tue Oct 09 17:35:53 2012 +0900 @@ -1,12 +1,47 @@ .code16 .text -.globl start +.globl _start .org 0 -start: - jmp $0x07c0, $start +_start: + jmp boot + nop + +os_name: .ascii "CbCOS" +n_bytes_per_sect: .word 0x0200 +n_sect_per_clstr: .byte 0x01 +n_rsvd_sect: .word 0x0001 +n_fats: .byte 0x02 +n_root_dir_ents: .word 0x00e0 +n_total_sectors: .word 0x0b40 +b_media: .byte 0xf0 +n_sect_per_fat: .word 0x0009 +n_sect_per_track: .word 0x0012 +n_heads: .word 0x0002 +n_hidden: .long 0x00000000 +n_total_sect32: .long 0x00000000 +n_boot_drive: .byte 0x00 +resvd_byte: .byte 0x00 +ext_boot_sig: .byte 0x29 +n_os_sectors: .word 0x0080 +resvs_word: .word 0x3f51 +vol_name: .ascii "rich" +fat_type: .ascii "FAT12 " + +boot: + cli + mov $0x9000, %ax + mov %ax, %ss + mov $0x8000, %ax + mov %ax, %es + xor %di, %di + + + + + mov %cs, %ax mov %ax, %ds
--- a/Kernel_withGRUB2/Makefile Mon Oct 01 19:01:39 2012 +0900 +++ b/Kernel_withGRUB2/Makefile Tue Oct 09 17:35:53 2012 +0900 @@ -1,21 +1,18 @@ include ./Makefile.def + TARGET=cbc_os.elf all: $(TARGET) -bootstrap: - $(CBC) $(BOOTCBCFLAGS) boot/bootstrap.o boot/bootstrap.S - $(LD) $(LDFLAGS32) bootstrap.elf boot/bootstrap.o +$(TARGET): $(KERNEL_OBJ) $(BOOT_OBJ) + $(LD) $(LDFLAGS) $@ $^ +$(BOOT_OBJ): $(BOOT_SRCS) + $(CBC) $(BITFLAG) $(CBCFLAGS) $@ $^ $(KERNEL_OBJ): $(KERNEL_SRCS) $(CBC) $(BITFLAG) $(CBCFLAGS) $@ $^ -$(BOOT_OBJ): $(BOOT_SRCS) - $(CBC) $(BITFLAG) $(CBCFLAGS) $@ $^ - -$(TARGET): $(KERNEL_OBJ) $(BOOT_OBJ) - $(LD) $(LDFLAGS) $@ $^ clean: rm -rf **/*.o *.elf
--- a/Kernel_withGRUB2/Makefile.def Mon Oct 01 19:01:39 2012 +0900 +++ b/Kernel_withGRUB2/Makefile.def Tue Oct 09 17:35:53 2012 +0900 @@ -28,7 +28,7 @@ LDFLAGS64 = -melf_x86_64 \ -nostdlib \ - -Ttext 0x200000 \ + -Ttext 0x100000 \ --oformat elf64-x86-64 \ -o @@ -46,7 +46,9 @@ BOOT_SRCS = $(BOOT_DIR)/head64.S BOOT_OBJ = $(BOOT_DIR)/head64.o +BOOTSTRAP_SRCS = $(BOOT_DIR)/bootstrap.S +BOOTSTRAP_OBJ = $(BOOT_DIR)/bootstrap.o + KERNEL_DIR = kernel KERNEL_SRCS = $(KERNEL_DIR)/kernel.cbc KERNEL_OBJ = $(KERNEL_DIR)/kernel.o -
--- a/Kernel_withGRUB2/boot/Makefile Mon Oct 01 19:01:39 2012 +0900 +++ b/Kernel_withGRUB2/boot/Makefile Tue Oct 09 17:35:53 2012 +0900 @@ -7,4 +7,3 @@ $(LD) $(LDFLAGS32) $(TARGET) bootstrap.o bootstrap.o: bootstrap.S $(CBC) $(BOOTCBCFLAGS) bootstrap.o bootstrap.S -
--- a/Kernel_withGRUB2/boot/bootstrap.S Mon Oct 01 19:01:39 2012 +0900 +++ b/Kernel_withGRUB2/boot/bootstrap.S Tue Oct 09 17:35:53 2012 +0900 @@ -27,12 +27,8 @@ * Prepare for entering 64bit-mode. */ -.globl _start -_start: - jmp move_longmode - -move_longmode: +bootstrap: /* load new GDT */ leal gdt(%ebp), %eax movl %eax, gdt+2(%ebp) @@ -99,14 +95,13 @@ pushl $(12*8) /* leal start_kernel(%ebp), %eax */ - movl $0x200, %eax + movl $0x150000, %eax pushl %eax /* activating Long Mode */ movl %eax, %cr0 - - ljmpl *$0x200000 + lret /* * jump to kernel.
--- a/Kernel_withGRUB2/boot/head64.S Mon Oct 01 19:01:39 2012 +0900 +++ b/Kernel_withGRUB2/boot/head64.S Tue Oct 09 17:35:53 2012 +0900 @@ -3,10 +3,11 @@ * push ebx and eax send argument to kernel. */ -#include "bootstrap.S" +.org 150000 + .code64 -start_k: +start_kernel: pushq %rbx pushq %rax call kmain
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/head64test/Makefile Tue Oct 09 17:35:53 2012 +0900 @@ -0,0 +1,19 @@ +HOME = /Users/taira +prefix = $(HOME)/cross/COMMON_INSTALL/bin +CBC = $(prefix)/elf-cbc-gcc-4.6.0 +LD = $(prefix)/x86_64-elf-ld +OBJCOPY = $(prefix)/x86_64-elf-objcopy +AS = $(prefix)/x86_64-elf-as + +TARGET = out.bin + +all:$(TARGET) + +ipl.o:ipl.S + $(AS) ipl.S -o ipl.o + +$(TARGET):ipl.o ipl.ld + $(LD) --oformat binary -T ipl.ld ipl.o -o $(TARGET) + +clean: + rm -f *.o $(TARGET) out.elf
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/head64test/head64.S Tue Oct 09 17:35:53 2012 +0900 @@ -0,0 +1,144 @@ +.globl bootstart +.code16 + +bootstart: + + movb $0xff, %al + outb %al, $0x21 + movb $0xff, %al + outb %al, $0xa1 + cli + +/* open A20 */ +1: inb $0x64, %al + testb $2, %al + jnz 1b + movb $0xd1, %al + outb %al, $0x64 +1: inb $0x64, %al + testb $2, %al + jnz 1b + movb $0xdf, %al + outb %al, $0x60 + + lidt idt32ptr + lgdt gdt32ptr + + movl %cr0, %eax + andl $0x7fffffff + orl $0x00000001, %eax + movl %eax, %cr0 + + ljmp $24, $entry32 + + .align 16 + +idt32ptr: + .word 0 + .long 0 + + .align 16 + +gdt32ptr: + .word 4*8-1 + .long gdt + + .align 16 + +gdt64ptr: + .word 4*8-1 + .long gdt,0 + + .align 16 +gdt: + .word 0,0,0,0 + .word 0xffff,0x0000,0x9a00,0x00af /* 8: r-x D=0 L=1 */ + .word 0xffff,0x0000,0x9200,0x00cf /* 16: data rw- */ + .word 0xffff,0x0000,0x9a00,0x00af /* 24: code r-x D=1 L=0 */ + .align 16 + +/* 32bit protected mode */ + +entry32: + .code32 + movw $16, %ax + movw %ax, %ds + movw %ax, %es + movw %ax, %fs + movw %ax, %gs + movw %ax, %ss + movl $0x01fe8ff0, %esp + + /* enable PAE */ + movl $0x00000020, %eax + movl %eax, %cr4 + + /* create 64bit page table */ + movl $0x01fe9000, %ebx + movl %ebx, %edi + xorl %eax, %eax + movl $(512*8*6/4), %ecx + rep stosl + + /* level 4 page map */ + leal 0x1007(%ebx), %eax + movl %eax, (%ebx) + + /* page directory pointers */ + leal 0x1000(%ebx), %edi + leal 0x2007(%ebx), %eax + movl $4, %ecx +1: movl %eax, (%edi) + addl $8, %edi + addl $0x1000, %eax + loop 1b + + /* page directories */ + leal 0x2000(%ebx), %edi + movl $0x183, %eax + movl $(512*4), %ecx +1: movl %eax, %(%edi) + addl $8, %edi + addl $0x00200000, %eax + loop 1b + + /* set page table base register */ + movl %ebx, %cr3 + + /* enable long mode */ + movl $0xc0000080, %ecx + rdmsr + btsl $8, %eax + wrmsr + + /* activate page translation and long mode */ + movl $0x80000001, %eax + movl %eax, %cr0 + + /* load code 64 descriptor */ + pushl $8 + pushl $entry64 + lret + +entry64: + .code64 + + /* clear screen */ + movl $0xb8000, %edi + movw %0x0f20, %ax + movl $80 * 25, %ecx + rep stosw + + /* draw 4 characters with them attributes */ + movl $0xb8000, %edi + movq fourchars(%rip), %r8 + movq %r8, (%rdi) + + /* work down. loop forever. */ +2: hlt + jmp 2b + + .align 8 + +fourchars: + .quad 0x0f330e320d310c30
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/head64test/ipl.S Tue Oct 09 17:35:53 2012 +0900 @@ -0,0 +1,65 @@ +.code16 +.globl start + +start: + jmp boot + +name: .ascii "TESTOS" +sect_size: .word 0x0200 +clust_size: .byte 0x01 +rsvd_sects: .word 1 +fat_cont: .byte 2 +root_ents: .word 244 +total_sect: .word 2880 +media_type: .byte 0xf0 +fat_size: .word 9 +trk_size: .word 18 +head_cont: .word 2 +hidd_sect: .long 0 +huge_sect: .long 2880 +boot_dev: .byte 0 +reserved: .byte 0 +signature: .byte 0x28 +vol_ID: .long 0xffffffff +vol_label: .ascii "DISK " +fat_name: .ascii "FAT12 " + .ascii "IPL 110105" + .skip 18,0 + +boot: + cli + movw $0, %ax + movw %ax, %ds + movw %ax, %ss + movw %ax, %es + movw %ax, %ss + movw $0x7c00, %sp + movw $msg, %si + +seta20_a: + inb $0x64, %al + testb $0x2, %al + jnz seta20_a + + +seta20_b: + +loop: + movb 0(%si), %al + add $0x01, %si + cmpb $0x00, %al + je fin + movb $0x0e, %ah + movw $0x0015, %bx + int $0x10 + jmp loop + +fin: + hlt + jmp fin + +msg: .ascii "xxx Making OS is very difficult xxx" + .byte 0 + +.org 510 +.byte 0x55,0xaa
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/head64test/ipl.ld Tue Oct 09 17:35:53 2012 +0900 @@ -0,0 +1,6 @@ +OUTPUT_FORMAT(binary) + +SECTIONS { + . = 0x7c00; + .text : { *(.text) } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ipltest/Makefile Tue Oct 09 17:35:53 2012 +0900 @@ -0,0 +1,19 @@ +HOME = /Users/taira +prefix = $(HOME)/cross/COMMON_INSTALL/bin +CBC = $(prefix)/elf-cbc-gcc-4.6.0 +LD = $(prefix)/x86_64-elf-ld +OBJCOPY = $(prefix)/x86_64-elf-objcopy +AS = $(prefix)/x86_64-elf-as + +TARGET = out.bin + +all:$(TARGET) + +ipl.o:ipl.S + $(AS) ipl.S -o ipl.o + +$(TARGET):ipl.o ipl.ld + $(LD) --oformat binary -T ipl.ld ipl.o -o $(TARGET) + +clean: + rm -f *.o $(TARGET) out.elf
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ipltest/ipl.S Tue Oct 09 17:35:53 2012 +0900 @@ -0,0 +1,56 @@ +.code16 +.globl start + +start: + jmp boot + +name: .ascii "TESTOS" +sect_size: .word 512 +clust_size: .byte 1 +rsvd_sects: .word 1 +fat_cont: .byte 2 +root_ents: .word 244 +total_sect: .word 2880 +media_type: .byte 0xf0 +fat_size: .word 9 +trk_size: .word 18 +head_cont: .word 2 +hidd_sect: .long 0 +huge_sect: .long 2880 +boot_dev: .byte 0 +reserved: .byte 0 +signature: .byte 0x28 +vol_ID: .long 0xffffffff +vol_label: .ascii "DISK " +fat_name: .ascii "FAT12 " + .ascii "IPL 110105" + .skip 18,0 + +boot: + cli + movw $0, %ax + movw %ax, %ss + movw $0x7c00, %sp + movw %ax, %ds + movw %ax, %es + movw $msg, %si + +loop: + movb 0(%si), %al + add $0x01, %si + cmpb $0x00, %al + je fin + movb $0x0e, %ah + movw $0x0015, %bx + int $0x10 + jmp loop + +fin: + hlt + jmp fin + +msg: .ascii "xxx Making OS is very difficult xxx" + .byte 0 + +.org 510 +.byte 0x55,0xaa