Added
This commit is contained in:
parent
e3aa2e3d59
commit
cc60122630
|
@ -1,7 +1,7 @@
|
|||
#include "type32.h"
|
||||
#include "grub.h"
|
||||
#include "kdef32.h"
|
||||
UINT32 HKA32 HkKernelEntry(multiboot_info_t* multibootInfo)
|
||||
uint32 HKA32 hk_main(multiboot_info_t* multibootInfo)
|
||||
{
|
||||
//setup new gdt
|
||||
//setup paging
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include "type32.h"
|
||||
|
||||
extern void HkWritePort(UINT16 port, UINT16 data);
|
||||
extern void HkReadPort(UINT16 port, UINT16 data);
|
||||
extern void hk_write_port(uint16 port, uint16 data);
|
||||
extern void hk_read_port(uint16 port, uint16 data);
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,15 @@
|
|||
#include "mem32.h"
|
||||
#include "type32.h"
|
||||
|
||||
int32 hk_set_gdt_descriptor(gdt_descriptor* pgdt_descriptor, uint32 base, uint32 limit, uint8 access, uint8 gran)
|
||||
{
|
||||
pgdt_descriptor->base_low = (base & 0xFFFF);
|
||||
pgdt_descriptor->base_middle = (base >> 16) & 0xFF;
|
||||
pgdt_descriptor->base_high = (base >> 24) & 0xFF;
|
||||
|
||||
pgdt_descriptor->limit_low = (limit & 0xFFFF);
|
||||
pgdt_descriptor->access = ((limit >> 16) & 0x0F);
|
||||
|
||||
pgdt_descriptor->granularity |= (gran & 0xF0);
|
||||
pgdt_descriptor->access = access;
|
||||
}
|
|
@ -7,13 +7,31 @@
|
|||
#pragma pack(1)
|
||||
typedef struct
|
||||
{
|
||||
UINT16 LimitLow;
|
||||
UINT16 BaseLow;
|
||||
UINT8 BaseMid;
|
||||
UINT8 AccessByte;
|
||||
UINT8 FlagLimitMid;
|
||||
UINT8 BaseHigh;
|
||||
} GDT_DESCRIPTOR;
|
||||
uint16 limit_low;
|
||||
uint16 base_low;
|
||||
uint8 base_middle;
|
||||
uint8 access;
|
||||
uint8 limit_mid_flag;
|
||||
uint8 base_high;
|
||||
} gdt_descriptor;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16 limit;
|
||||
uint32 base;
|
||||
} gdt_ptr;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
||||
} pde_32;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
||||
} pte_32;
|
||||
|
||||
|
||||
#pragma pop()
|
||||
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#ifndef _TYPE_H_
|
||||
#define _TYPE_H_
|
||||
typedef unsigned int UINT32;
|
||||
typedef unsigned short UINT16;
|
||||
typedef unsigned long long UINT64;
|
||||
typedef unsigned char UINT8;
|
||||
typedef int INT32;
|
||||
typedef short INT16;
|
||||
typedef long long INT64;
|
||||
typedef char INT8;
|
||||
typedef unsigned int uint32;
|
||||
typedef unsigned short uint16;
|
||||
typedef unsigned long long uint64;
|
||||
typedef unsigned char uint8;
|
||||
typedef int int32;
|
||||
typedef short int16;
|
||||
typedef long long int64;
|
||||
typedef char int8;
|
||||
#endif
|
|
@ -2,51 +2,51 @@
|
|||
#include "type32.h"
|
||||
#include "kdef32.h"
|
||||
|
||||
INT32 HKA32 HkSetBit32(void* dst,UINT32 bit)
|
||||
int32 HKA32 hk_set_bit(void* dst,uint32 bit)
|
||||
{
|
||||
if (dst == NULL)
|
||||
return -1;
|
||||
INT32 quo = bit/32;
|
||||
int32 quo = bit/32;
|
||||
bit = bit%32;
|
||||
INT32* cDst = (INT32*)dst + quo;
|
||||
*(INT32*)(cDst) |= 1 << bit;
|
||||
int32* cDst = (int32*)dst + quo;
|
||||
*(int32*)(cDst) |= 1 << bit;
|
||||
return 0;
|
||||
}
|
||||
|
||||
INT32 HKA32 HkClearBit32(void* dst, UINT32 bit)
|
||||
int32 HKA32 hk_clear_bit(void* dst, uint32 bit)
|
||||
{
|
||||
if (dst == NULL)
|
||||
return -1;
|
||||
INT32 quo = bit / 32;
|
||||
int32 quo = bit / 32;
|
||||
bit = bit % 32;
|
||||
INT32* cDst = (INT32*)dst + quo;
|
||||
*(INT32*)(cDst) &= ~(1 << bit);
|
||||
int32* cDst = (int32*)dst + quo;
|
||||
*(int32*)(cDst) &= ~(1 << bit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
INT32 HKA32 HkGetBit32(void* dst, UINT32 bit)
|
||||
int32 HKA32 hk_get_bit(void* dst, uint32 bit)
|
||||
{
|
||||
if (dst == NULL)
|
||||
return -1;
|
||||
INT32 quo = bit / 32;
|
||||
int32 quo = bit / 32;
|
||||
bit = bit % 32;
|
||||
INT32* cDst = (INT32*)dst + quo;
|
||||
return *(INT32*)(cDst) & (1 << bit);
|
||||
int32* cDst = (int32*)dst + quo;
|
||||
return *(int32*)(cDst) & (1 << bit);
|
||||
}
|
||||
|
||||
INT32 HKA32 HkToggleBit32(void* dst, UINT32 bit)
|
||||
int32 HKA32 hk_toggle_bit(void* dst, uint32 bit)
|
||||
{
|
||||
if (dst == NULL)
|
||||
return -1;
|
||||
INT32 quo = bit / 32;
|
||||
int32 quo = bit / 32;
|
||||
bit = bit % 32;
|
||||
INT32* cDst = (INT32*)dst + quo;
|
||||
*(INT32*)(cDst) |= 1 << bit;
|
||||
int32* cDst = (int32*)dst + quo;
|
||||
*(int32*)(cDst) |= 1 << bit;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
INT32 HKA32 HkMemcpy(void* src, void* dst, UINT32 size)
|
||||
int32 HKA32 hk_memcpy(void* src, void* dst, uint32 size)
|
||||
{
|
||||
if (src == NULL || dst == NULL)
|
||||
return -1;
|
||||
|
@ -57,7 +57,7 @@ INT32 HKA32 HkMemcpy(void* src, void* dst, UINT32 size)
|
|||
return 0;
|
||||
}
|
||||
|
||||
INT32 HKA32 HkMemmove(void* src, void* dst, UINT32 size)
|
||||
int32 HKA32 hk_memmove(void* src, void* dst, uint32 size)
|
||||
{
|
||||
if (src == NULL || dst == NULL)
|
||||
return -1;
|
||||
|
@ -65,11 +65,68 @@ INT32 HKA32 HkMemmove(void* src, void* dst, UINT32 size)
|
|||
char* cDst = (char*)dst;
|
||||
if (cSrc >= cDst)
|
||||
{
|
||||
return HkMemcpy(src,dst,size);
|
||||
return hk_memcpy(src,dst,size);
|
||||
}
|
||||
cSrc += size;
|
||||
cDst += size;
|
||||
while (size--)
|
||||
*(--cDst) = *(--cSrc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 HKA32 hk_print_string(char* str)
|
||||
{
|
||||
char* gs = (char*)(0xb8000);
|
||||
uint8 attr = 0x07;
|
||||
while (*(str) != 0)
|
||||
{
|
||||
*(gs) = *(str);
|
||||
str++;
|
||||
*(gs + 1) = attr;
|
||||
gs += 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 hk_print_int(int32 number)
|
||||
{
|
||||
char arr[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
int32 index = 10;
|
||||
int32 isNegative = 0;
|
||||
int32 div = 10;
|
||||
if (number < 0)
|
||||
{
|
||||
isNegative = 1;
|
||||
number *= -1;
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
int32 quo = number / div;
|
||||
int32 rmd = number%div;
|
||||
number = quo;
|
||||
arr[index] = '0' + rmd;
|
||||
index--;
|
||||
if (number == 0)
|
||||
break;
|
||||
}
|
||||
if (isNegative)
|
||||
{
|
||||
arr[index] = '-';
|
||||
}
|
||||
hk_print_string(&(arr[index]));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 HkUpdateCursor(int32 row, int32 col)
|
||||
{
|
||||
if (row < 0 || col < 0 || row > 25 || col > 80)
|
||||
return -1;
|
||||
uint16 position = (row * 80) + col;
|
||||
// cursor LOW port to vga INDEX register
|
||||
hk_write_port(0x3D4, 0x0F);
|
||||
hk_write_port(0x3D5, (uint8)(position & 0xFF));
|
||||
// cursor HIGH port to vga INDEX register
|
||||
hk_write_port(0x3D4, 0x0E);
|
||||
hk_write_port(0x3D5, (uint8)((position >> 8) & 0xFF));
|
||||
return 0;
|
||||
}
|
|
@ -3,10 +3,10 @@
|
|||
#include "io32.h"
|
||||
#include "kdef32.h"
|
||||
|
||||
INT32 HKA32 HkClearBit32(void* dst, UINT32 bit);
|
||||
INT32 HKA32 HkGetBit32(void* dst, UINT32 bit);
|
||||
INT32 HKA32 HkToggleBit32(void* dst, UINT32 bit);
|
||||
INT32 HKA32 HkMemcpy(void* src, void* dst, UINT32 size);
|
||||
INT32 HKA32 HkMemmove(void* src, void* dst, UINT32 size);
|
||||
int32 HKA32 hk_clear_bit(void* dst, uint32 bit);
|
||||
int32 HKA32 hk_get_bit(void* dst, uint32 bit);
|
||||
int32 HKA32 hk_toggle_bit(void* dst, uint32 bit);
|
||||
int32 HKA32 hk_memcpy(void* src, void* dst, uint32 size);
|
||||
int32 HKA32 hk_memmove(void* src, void* dst, uint32 size);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue