diff options
Diffstat (limited to 'kernel/init')
| -rw-r--r-- | kernel/init/Makefile | 20 | ||||
| -rw-r--r-- | kernel/init/entry.asm | 23 | ||||
| -rw-r--r-- | kernel/init/main.c | 67 |
3 files changed, 110 insertions, 0 deletions
diff --git a/kernel/init/Makefile b/kernel/init/Makefile new file mode 100644 index 0000000..815dc69 --- /dev/null +++ b/kernel/init/Makefile @@ -0,0 +1,20 @@ +CC= gcc +CFLAGS= -Wall -imacros ../defines -I../inc +OBJS= main.o entry.o +RM= /bin/rm +NASM= nasm +NASMFLAGS= -f elf + +.SUFFIXES: .c .asm .o + +all: $(OBJS) + +.c.o: + $(CC) $(CFLAGS) -c $< + +.asm.o: + $(NASM) $(NASMFLAGS) -o $*.o $< + +clean: + $(RM) -f $(OBJS) *~ #*# .#* + diff --git a/kernel/init/entry.asm b/kernel/init/entry.asm new file mode 100644 index 0000000..afb0434 --- /dev/null +++ b/kernel/init/entry.asm @@ -0,0 +1,23 @@ +[BITS 32] + +EXTERN KernelEntry +GLOBAL StartOfKernelImage +GLOBAL IdleLoop + +;;; +;;; I put "entry.o" first in line at the linker so I am sure this function +;;; gets put first in the kernel image. This is good because: +;;; +;;; 1. We know there is valid code at 0x00010000 when we jump here +;;; 2. We can use the address of this function as the start of image +;;; 3. We don't have to make sure main (or KernelEntry or whatever) +;;; is always the first function in main.c +;;; +StartOfKernelImage: + jmp KernelEntry + ret + +IdleLoop: + sti + hlt + jmp IdleLoop diff --git a/kernel/init/main.c b/kernel/init/main.c new file mode 100644 index 0000000..22fd14a --- /dev/null +++ b/kernel/init/main.c @@ -0,0 +1,67 @@ +//+---------------------------------------------------------------------------- +// +// File: main.c +// +// Module: +// +// Synopsis: +// +// Created: sgasch 4 Jul 2003 +// +//+---------------------------------------------------------------------------- + +#include "kernel.h" +#include "hal.h" +#include "rtl.h" + +extern char __bss_start; +extern char end; + +void +ZeroBSS(void) +{ + BYTE *pBssStart, *pBssEnd; + + pBssStart = &__bss_start; + pBssEnd = &end; + + // Fill .bss section with zero + RtlSetMemory((void *)pBssStart, '\0', (pBssEnd - pBssStart)); +} + +void +_assert(CHAR *szFunction, CHAR *szFile, ULONG uLine) +{ + HalVideoSetCursorPosition(0, 0); + HalVideoPrint("ASSERTION in %s at %s line %u.\n", + szFunction, szFile, uLine); + while(1) + { + ; + } +} + +// +// Entry point of the kernel. Not called main because I don't care to +// listen to gcc's warnings about argc and argv anymore. +// +int +KernelEntry(BIOS_HARDWARE_BLOCK *phw) +{ + ZeroBSS(); + + HalVideoInitialize(phw); + HalInitializeInterrupts(); + + HalVideoPrint("Interrupts initialized.\n"); + + hang: + HalReadTimestampCounter(); + HalVideoPrint("Timestamp Counter: %u%u\n", + ((g_ullTimeStampCounter >> 32) & 0xffffffff), + (g_ullTimeStampCounter & 0xffffffff)); + goto hang; + + return(-1); +} + |
