Mercurial > hg > Members > taiki > original_os
changeset 9:bd2f9ba6f5f8
add some file. I don't realize to add important file.
author | Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 22 Aug 2012 18:30:45 +0900 |
parents | 461b04687db5 |
children | 50e4b9ca4867 |
files | Makefile bootstrap.S kernel.cbc multiboot2.h |
diffstat | 4 files changed, 162 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Sat Aug 18 17:31:54 2012 +0900 +++ b/Makefile Wed Aug 22 18:30:45 2012 +0900 @@ -8,6 +8,7 @@ -fno-common \ -fno-builtin \ -fomit-frame-pointer \ + -g \ -Wall \ -O2 \ -c \ @@ -15,7 +16,7 @@ LDFLAGS = -m elf_i386 \ -nostdlib \ - -Ttext=0x100000 \ + -Ttext 0x100000 \ --oformat elf32-i386 \ -o
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bootstrap.S Wed Aug 22 18:30:45 2012 +0900 @@ -0,0 +1,97 @@ +/* + * This program is boot to kernel. + * Change mode to 64bit mode and go to CbC kernel. + */ + +#include "multiboot2.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: + + +/* + * Prepare for entering 64bit-mode. + */ + +move_longmode: + + /* load new GDT */ + leal gdt(%ebp), %eax + movl %eax, gdt+2(%ebp) + lgdt gdt(%ebp) + + /* + * PAE mode ON. + * Physical Address Extension + * You can use capacity of memory more than 4GiB on 32 bit CPU. + */ + + movl $0x00000020, %eax + movl %eax, %cr4 + + /* + * create 64bit page table + */ + + /* + * Initialize page tables to 0 + * 6144 = 512*8*6/4 + */ + + leal pgtable(%ebx), %edi + xorl %eax, %eax + movl $6144, %ecx + rep stosl + + /* Build Level 4 */ + leal pgtable + 0(%ebx), %edi + leal 0x1007(%edi), %eax + movl %eax, 0(%edi) + + + jmp start_kernel + +start_kernel: + pushl %ebx + pushl %eax + call kmain + +.data +gdt: + .word gdt_end - gdt + .long gdt + .word 0 + .quad 0x0000000000000000 /* NULL descriptor */ + .quad 0x00af9a000000ffff /* __KERNEL_CS */ + .quad 0x00cf92000000ffff /* __KERNEL_DS */ + .quad 0x0080890000000000 /* TS descriptor */ + .quad 0x0000000000000000 /* TS continued */ +gdt_end: + + +/* + * Space for page tables. + * a : section is allocatable. + * @nobits : section does not contain data. + */ +.section ".pgtable", "a", @nobits +.balign 4096 +pgtable: + .fill 6*4096, 1, 0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kernel.cbc Wed Aug 22 18:30:45 2012 +0900 @@ -0,0 +1,60 @@ +__code memory(int state); +__code kernel(int state); +void init(int state); + +__code put_to_vmem(unsigned char* str, unsigned short *video) +{ + char c; + if ((c=*(str++))!=0) { + *video++ = (0x0E << 8) | c; + goto put_to_vmem(str, video); + } else { + goto kernel(3); + } +} + + +__code putchar(int state) +{ + unsigned short *video = (unsigned short *)0xb8000; + unsigned char *str = (unsigned char *)"hello,world"; + + goto put_to_vmem(str, video); + + goto kernel(2); +} + +__code kernel(int state) +{ + switch(state) { + case 1: + goto putchar(3); + break; + case 2: + goto memory(state); + break; + } + goto kernel(state); +} + +__code memory(int state) +{ + if (state == 1) { + goto kernel(state); + } + init(state); +} + +void +init(int state) +{ + goto kernel(state); +} + +int +kmain(unsigned long magic, unsigned long addr) +{ + int state = 1; + init(state); + return 0; +}