DEPS = kernel
OUTPUT = corax
PHONY = $(DEPS) clean qemu
-LAYOUT = $(shell setxkbmap -query | sed -nE 's/^layout:.*?([a-z]{2})$/\1/p')
+#LAYOUT = $(shell setxkbmap -query | sed -nE 's/^layout:.*?([a-z]{2})$/\1/p')
-foo:
- $(eval setxkbmap -query | sed -nE 's/^layout:.*?([a-z]{2})$/\1/p')
+#foo:
+# $(eval setxkbmap -query | sed -nE 's/^layout:.*?([a-z]{2})$/\1/p')
all: $(OUTPUT)
qemu:
- qemu-system-x86_64 -k ja -kernel $(OUTPUT) -m 512
+ qemu-system-i386 -k ja -kernel $(OUTPUT) -m 128 -display gtk
$(OUTPUT): $(DEPS)
mv kernel/corax $(OUTPUT)
#define CONFIG_KERNEL_STACK_SIZE 4096
#define CONFIG_USER_STACK_SIZE 4096
-#define CONFIG_APIC 1
+#define CONFIG_APIC 0
#define CONFIG_SMP 0
#define CONFIG_SMP_CPUS 1
cli
movl $_cpu, %esp
addl $STACK0_TOP, %esp
+ movl %esp, %ebp
pushl %eax
pushl %ebx
call corax
* 0x200 = IF
* 0x400 = DF
* 0x800 = OF
- * 0x1000 =
+ * 0x1000 =
*/
#endif /* __DEFS_H */
call dbg_printf
/* TODO: initialise timer */
-/* call _i8259_getmask */
+#if 0
+ call _i8259_getmask
+#endif
xorl %eax, %eax
- movw $0xfffd, %ax
+
+ /* 0x0001 = timer, 0x0002 = kbd */
+ /* 0xfffd = mask all but kbd, 0xfffc = all but (timer | kbd) */
+ movw $0xfffc, %ax
movl %eax, (%esp)
call _i8259_setmask
addl $4, %esp
- sti
ret
.global _i8259_getmask
.extern _kernel_cr3
.extern pg_init
.extern dbg_printf
+.extern dbg_panic
.extern _i8259_init
.extern _apic_init
.long _int_entry23
#endif /* CONFIG_APIC */
+_dbg_regs_str:
+ .ascii "EAX = %08x EBX = %08x\n"
+ .ascii "ECX = %08x EDX = %08x\n"
+ .ascii "ESI = %08x EDI = %08x\n"
+ .asciz "ESP = %08x EBP = %08x\n"
+
.section .text
+.globl _print_regs
+
+_print_regs:
+ pushl %ebp
+ pushl %esp
+ pushl %edi
+ pushl %esi
+ pushl %edx
+ pushl %ecx
+ pushl %ebx
+ pushl %eax
+ pushl $_dbg_regs_str
+ call dbg_printf
+ addl $36, %esp
+ ret
+
arch_init:
+ call _print_regs
+
subl $24, %esp
movl $_mem_start, %eax
addl $4, %eax
movl %eax, (_mem_start)
+
/*
movl $_cpu, %eax
addl $GDT_OFFSET, %eax
shll $3, %eax
movl %eax, 8(%esp)
call memset
-*/
+ */
+
movl $_cpu, %eax
addl $GDT_OFFSET, %eax
movl $0, (%eax)
/* remap i8259 interrupts */
movb $0x11, %al
outb %al, $PIC1_COMM
- outb %al, $PIC2_COMM
- movb $PIC1_VECTOR0, %al
+ movb $PIC1_VECTOR0, %al
outb %al, $PIC1_DATA
- movb $PIC2_VECTOR0, %al
- outb %al, $PIC2_DATA
movb $0x04, %al
outb %al, $PIC1_DATA
- movb $0x02, %al
- outb %al, $PIC2_DATA
movb $0x01, %al
outb %al, $PIC1_DATA
+
+ movb $0x11, %al
+ outb %al, $PIC2_COMM
+ movb $PIC2_VECTOR0, %al
+ outb %al, $PIC2_DATA
+ movb $0x02, %al
+ outb %al, $PIC2_DATA
+ movb $0x01, %al
outb %al, $PIC2_DATA
+
+ movl $128, %esi
+0: subl $1, %esi
xorl %eax, %eax
+ cmp %esi, 0
+ jnz 0b
+
outb %al, $PIC1_DATA
outb %al, $PIC2_DATA
addl $8, (%esp)
addl $1, %esi
jmp 0b
- 1:
+1:
/*
_idt_fill:
0:
#endif /* CONFIG_APIC */
call _i8259_init
- 1:
+1:
popl %ebx
orl %eax, %ebx
movl 12(%esp), %eax
addl $16, %esp
-*/
+ */
+
+ sti
+
+ call _print_regs
- sti
ret
/*
if(ctx.intn == INT_KEYBOARD) {
extern struct cpu _cpu[CONFIG_SMP_CPUS];
- dbg_printf("Rebooting...\n");
-
+ dbg_printf("Keyboard interrupt\n");
+#if 0
/* hacky reboot: clear IDT entries for
* #DF and #GP, then cause a #GP */
_cpu[CPU_ID].cpu_idt[EXC_DOUBLEFAULT].sd_low = 0;
/* this is such a retarded thing to do, I don't see how this
* could not cause a triple fault */
asm volatile("ljmp $0x30, $0xfee00020"); /* LEEROY JENKINS!!! */
+#endif
} else if(ctx.intn != INT_TIMER) {
dbg_printf("Interrupt %u occurred\n", ctx.intn);
}
while((u32_t)mmap < (info->mmap_addr + info->mmap_length)) {
u32_t attrs;
u64_t addr;
-/*
- dbg_printf("Region: 0x%016llx - 0x%016llx [%u]\n", mmap->addr, mmap->addr + mmap->len, mmap->type);
-*/
+#if 1
+ dbg_printf("Region: 0x%016llx - 0x%016llx [%u]\n",
+ mmap->addr, mmap->addr + mmap->len, mmap->type);
+#endif
attrs = PAGE_ATTR_SIZE | PAGE_ATTR_WRITABLE | PAGE_ATTR_PRESENT;
/* disable caching on reserved memory areas */
pd = (page_table_t*)cr3;
- for(addr = mmap->addr & ~(PAGE_SIZE_LARGE - 1); addr < (mmap->addr + mmap->len); addr += PAGE_SIZE_LARGE) {
+ for(addr = mmap->addr & ~(PAGE_SIZE_LARGE - 1);
+ addr < (mmap->addr + mmap->len);
+ addr += PAGE_SIZE_LARGE) {
pd->pt_entries[addr >> 22] = (u32_t)addr | attrs;
}
*/
_kernel_cr3 = (u32_t)cr3;
- dbg_printf("Enabling %s paging\n", _str_pg_mode[_pg_flags & 0x3]);
+ dbg_printf("Enabling %s paging\n", _str_pg_mode[_pg_flags & PG_MODE_MASK]);
return((void*)(cr3 | _pg_flags));
}
*/
#define __ASSEMBLY_SOURCE
-
+
#include <config.h>
#include "defs.h"
+#define CPU_SIZE (TSS_OFFSET + TSS_SIZE + 4)
+#define CUR_TASK (TSS_OFFSET + TSS_SIZE)
.extern _cpu
.global _task_prepare
u32_t p;
/*
- volatile register u64_t sysenter, sysexit;
void *ptr;
for(ptr = (void*)0xd0000; ptr < (void*)0xffffd; ptr++) {
/* void *ptr;*/
arch_init(mb_info);
+
+ dbg_panic("fooooo", "baaaaar", __LINE__, "foobar");
+
/*
u64_t capabilities = cpu_get_capabilities();
dbg_printf("CPUID.01h = 0x%016llx\n", capabilities);
dbg_printf("This is cpu%u\n", cpu_get_id());
}
*/
+#if 0
+ {
+ volatile register u64_t sysenter, sysexit;
-/*
- sysenter = cpu_timestamp();
- asm volatile("int $0xCC");
- sysexit = cpu_timestamp();
-
- dbg_printf("Syscall took %llu cycles\n", sysexit - sysenter);
-*/
+ sysenter = cpu_timestamp();
+ asm volatile("int $0xCC");
+ sysexit = cpu_timestamp();
+ dbg_printf("Syscall took %llu cycles\n", sysexit - sysenter);
+ }
+#endif
/*
cpu_debug();
*/
}
}
*/
-
dbg_printf("Switching pstate\n");
+
+ asm volatile("int $0xcc");
+ asm volatile("int $0xcc");
+ /*
p = cpu_set_pstate(1);
dbg_printf("Entered P-state %u. (0x%x)\n", p & 0xffff, p);
- dbg_printf("Initialisation complete. Nothing to do.\n");
-
+ dbg_printf("Initialisation complete. Nothing to do.\n"); */
+/*
struct task tsk;
_task_prepare(&tsk, (u32_t)_idle, (u32_t)&_stack + sizeof(_stack));
_task_switch(&tsk);
-
+*/
while(1) {
asm volatile("hlt");
}