Initial commit
This commit is contained in:
.gitignoreLinker.ldMakefileMakefile.flags
driver/irq/pic
execformat/pe
extlib
graphics
interrupt
handler.asm.Shandler.chandlers.hinit.cinterrupt.hinterrupt_testcode.Sload_gdt.Smap_handler.Ssyscall.Ssyscall.htestcode.h
kernel
libc
READMEabs.c
main.cmain.hinclude
assert.hctype.herrno.hfloat.hinttypes.hiso646.hlimits.hlocale.h
memcmp.cstrncat.cstrncmp.cstrncpy.cpdclib
_PDCLIB_config.h_PDCLIB_defguard.h_PDCLIB_glue.h_PDCLIB_internal.h_PDCLIB_lib_ext1.h_PDCLIB_print.h_PDCLIB_tzcode.h
signal.hstdalign.hstdarg.hstdbool.hstddef.hstdint.hstdio.hstdlib.hstdnoreturn.hstring.hthreads.htime.hwctype.hmemory
liballoc_impl.cmemory.cmemory.hmemory.hppmemory_cpp.cpppaging_init.cpaging_internal.hpaging_map.cpaging_modeswitch.Spaging_physical.ctest_fillbits.ctest_take_bitfield.c
run.cmdruntime
calling_convention.Scalling_convention.hmemcpy.cmemcpy.hmemset_memmove.Spanic_assert.asm.Spanic_assert.hprintf.cprintf.hstdio.cstdio.hstring.ctest_memmove.ctest_utf8.cunicode.cunicode.h
util
vterm
51
kernel/kmain.c
Normal file
51
kernel/kmain.c
Normal file
@ -0,0 +1,51 @@
|
||||
|
||||
#include "../main.h"
|
||||
#include "kmain.h"
|
||||
|
||||
#include "../runtime/stdio.h"
|
||||
#include "../runtime/panic_assert.h"
|
||||
#include "../memory/memory.h"
|
||||
#include "../memory/paging_internal.h"
|
||||
#include "../interrupt/interrupt.h"
|
||||
#include "../interrupt/handlers.h"
|
||||
#include "../interrupt/syscall.h"
|
||||
#include "../driver/irq/pic/pic.h"
|
||||
#include "../driver/irq/pic/ps2/ps2.h"
|
||||
|
||||
#include "../execformat/pe/reloc.h"
|
||||
void execformat_pe_ReadSystemHeader(execformat_pe_PortableExecutable *pe);
|
||||
|
||||
static void tellRIP() {
|
||||
uint64_t a, b;
|
||||
asm volatile("leaq (%%rip), %0\n\tleaq runtime_InitPaging(%%rip), %1"
|
||||
: "=r"(a), "=r"(b));
|
||||
io_Printf("tellRIP(): Stack position: %llx, RIP=%llx, kMain_StackPosition:%llx(%llx), interrupt_Int128: %llx\n", &a, a, (uint64_t)&kMain_StackPosition, b, (uint64_t)interrupt_Int128);
|
||||
}
|
||||
|
||||
|
||||
SYSV_ABI void kMain() {
|
||||
io_WriteConsoleASCII("Yes! kMain survived!\n");
|
||||
|
||||
uint64_t a;
|
||||
asm volatile("leaq (%%rip), %0"
|
||||
: "=r"(a));
|
||||
io_Printf("Stack position: %llx, RIP=%llx, runtime_InitPaging:%llx, interrupt_Int128: %llx\n", &a, a, (uint64_t)runtime_InitPaging, (uint64_t)interrupt_Int128);
|
||||
|
||||
interrupt_Init();
|
||||
io_WriteConsoleASCII("Interrupts initialized\n");
|
||||
|
||||
Syscall(4, 1, 2, 3, 4, 5, 6);
|
||||
io_WriteConsoleASCII("Returning from Syscall()\n");
|
||||
|
||||
tellRIP();
|
||||
|
||||
irq_pic_Init();
|
||||
io_WriteConsoleASCII("PIC IRQ OK\n");
|
||||
irq_pic_ps2_Init();
|
||||
io_WriteConsoleASCII("PIC PS/2 OK\n");
|
||||
|
||||
for (;;) {
|
||||
asm volatile("hlt");
|
||||
io_WriteConsoleASCII("kMain: Interrupt hit\n");
|
||||
}
|
||||
}
|
28
kernel/kmain.h
Normal file
28
kernel/kmain.h
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "../main.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// set the position of the top of stack before calling kMain_Init()
|
||||
extern uint64_t kMain_StackPosition;
|
||||
extern char kMain_StackData[], kMain_StackData_End[];
|
||||
|
||||
|
||||
typedef SYSV_ABI void (*kMainType)();
|
||||
|
||||
// written in Assembly, this function deals with stack, registers, etc, and then calls kMain.
|
||||
//
|
||||
// remember setting kMain_StackPosition before calling kMain_Init()
|
||||
SYSV_ABI noreturn void kMain_Init();
|
||||
|
||||
// this is the real main function.
|
||||
// it should only be called by kMain_Init()
|
||||
SYSV_ABI void kMain();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
25
kernel/kmain.init.S
Normal file
25
kernel/kmain.init.S
Normal file
@ -0,0 +1,25 @@
|
||||
format elf64
|
||||
|
||||
extrn kMain
|
||||
|
||||
public kMain_StackPosition
|
||||
public kMain_Init
|
||||
|
||||
|
||||
section '.bss' writable
|
||||
kMain_StackPosition:
|
||||
rq 1
|
||||
|
||||
|
||||
section '.text' executable
|
||||
|
||||
; sysvx64call void kMain_Init()
|
||||
kMain_Init:
|
||||
mov rsp, [kMain_StackPosition]
|
||||
call kMain
|
||||
|
||||
.hlt:
|
||||
hlt
|
||||
jmp .hlt
|
||||
|
||||
|
Reference in New Issue
Block a user