diff --git a/kernel/Makefile b/kernel/Makefile index 01e3c1053b3aea084937954741da1ef48aeb41ab..59e0061dd6705c4154d551e4f02b84c3131612b9 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,8 +1,8 @@ GCC := gcc -CCFLAG := -mcpu=i386 -I../include -nostdinc -Wall -fomit-frame-pointer -c -LDFLAG := -Ttext 0x0 -s --oformat binary +CCFLAG := -I../include -nostdinc -Wall -fomit-frame-pointer -c +LDFLAG := -Ttext 0x0 -s --oformat binary -m elf_x86_64 INCDIR := ../include -OBJS := head.o +OBJS := head.o main.o system: $(OBJS) $(LD) $(LDFLAG) -e startup_32 -o $@ $^ @@ -10,6 +10,9 @@ system: $(OBJS) head.o : head.S $(GCC) -traditional -c -o $@ $< +main.o : main.c + $(GCC) $(CCFLAG) -o $@ $< + clean : rm *.o rm system diff --git a/kernel/head.S b/kernel/head.S index 80b4dcbacea943f59b0ff387e0719bf2517eb3ee..077f7c5eddb7b1aa7287a2d9de323d645620cc0b 100644 --- a/kernel/head.S +++ b/kernel/head.S @@ -1,6 +1,7 @@ .code32 .text -.globl startup_32 +.globl startup_32, idt, gdt, pg_dir, tmp_floppy_area +pg_dir: startup_32: movl $0x10, %eax movw %ax, %ds @@ -23,9 +24,16 @@ startup_32: movb $0x42, %al movw %ax, %gs:(%edi) - int $0x80 -loop: - jmp loop + xorl %eax, %eax +1: + incl %eax + movl %eax, 0x000000 + cmpl %eax, 0x100000 + je 1b + + + jmp after_page_tables + setup_idt: leal ignore_int, %edx @@ -47,6 +55,34 @@ setup_gdt: lgdt gdt_descr ret +.org 0x1000 +pg0: + +.org 0x2000 +pg1: + +.org 0x3000 +pg2: + +.org 0x4000 +pg3: + +.org 0x5000 + +tmp_floppy_area: +.fill 1024, 1, 0 + +after_page_tables: +/*we call jump to main at this*/ + pushl $0 + pushl $0 + pushl $0 + pushl $L6 + pushl $main + jmp setup_paging +L6: + jmp L6 + ignore_int: /* we do not have function _printk now, so trick it */ pushl %eax @@ -72,6 +108,34 @@ ignore_int: popl %eax iret +.align 4 +setup_paging: + movl $1024*5, %ecx + xorl %eax, %eax + xorl %edi, %edi + cld + rep + stosl + + movl $pg0 + 7, pg_dir + movl $pg1 + 7, pg_dir + 4 + movl $pg2 + 7, pg_dir + 8 + movl $pg3 + 7, pg_dir + 12 + movl $pg3 + 4092, %edi + movl $0xfff007, %eax + std +1: + stosl + subl $0x1000, %eax + jge 1b + xorl %eax, %eax + movl %eax, %cr3 + movl %cr0, %eax + orl $0x80000000, %eax + movl %eax, %cr0 + + ret + .align 4 .word 0 idt_descr: diff --git a/kernel/main.c b/kernel/main.c new file mode 100644 index 0000000000000000000000000000000000000000..2e4356f9bde6a0a425d8e5a99961a9b7c94d4b28 --- /dev/null +++ b/kernel/main.c @@ -0,0 +1,10 @@ +#define __LIBRARY__ + +void main(void) +{ + __asm__("int $0x80 \n\r"::); + __asm__ __volatile__( + "loop:\n\r" + "jmp loop" + ::); +}