Skip to content

Latest commit

 

History

History
72 lines (55 loc) · 1.48 KB

File metadata and controls

72 lines (55 loc) · 1.48 KB

Code: Main.c that is executed after EntryPoint.S

#include "Types.h"

void kPrintString(int iX, int iY, const char *pcString);

// This function must be the first function defined. Otherwise, other function
// will be located at 0x10200
void Main(void) {
	kPrintString(0, 3, "C Language Kernel Started~!!!");

	while (1);
}

// Looks familiar, right? :D
// you can find assembly version in Bootloader.asm and EntryPoint.s
void kPrintString(int iX, int iY, const char *pcString) {
	CHARACTER *pstScreen = (CHARACTER *) 0xB8000;
    int i;

    pstScreen += iY * 80 + iX;

    for (i = 0; pcString[i] != 0; i++) {
    	pstScreen[i].bCharacter = pcString[i];
    }
}
// Types.h header file
// Because we still access to video memory address, a structure
// for printing text is defined

#ifndef __Types_H__
#define __Types_H__

#define BYTE unsigned char
#define WORD unsigned short
#define DWORD unsigned int
#define QWORD unsigned long
#define BOOL unsigned char

#define TRUE 1
#define FALSE 0
#define NULL 0

#pragma pack(push, 1)

typedef struct kChractorStruct {
    BYTE bCharacter;
    BYTE bAttribute;
} CHARACTER;

#pragma pack(pop)
#endif
    ;; Part of EntryPoint.C 
    ;; Let EntryPoint execute code written in C

    push (SWITCHSUCCESSMESSAGE - $$ + 0x10000)
    push 2
    push 0
    call PRINTMESSAGE
    add esp, 12 ; 4 bytes (Protected Mode) * 3

    ; In EntryPoint.s, replace jmp $
    ; jump to code which is written in C language
    jmp dword 0x08:0x10200