-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmain.h
112 lines (80 loc) · 3.42 KB
/
main.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*****************************************
NanoShell Operating System
(C) 2021 iProgramInCpp
NanoShell Main module header file
******************************************/
#ifndef _MAIN_H
#define _MAIN_H
#include<stddef.h>
#include<stdarg.h>
#include<stdint.h>
#include<stdbool.h>
//#define EXPERIMENTAL
//#define EXPERIMENTAL_RSDPTR
#define EXPERIMENTAL_VMWARE
typedef char byte;
typedef char BYTE;
typedef unsigned uint;
#define USE_SSE_FXSAVE
#define PATH_MAX (260)
extern void KeTaskDone();
#define asm __asm__ volatile
#define hlt asm("hlt")
/*
void KeDisableInterruptsD(const char * file, int line);
void KeEnableInterruptsD(const char * file, int line);
#define cli KeDisableInterruptsD(__FILE__, __LINE__) //asm("cli")
#define sti KeEnableInterruptsD (__FILE__, __LINE__) //asm("sti")
*/
void KeDisableInterrupts();
void KeEnableInterrupts();
#define cli KeDisableInterrupts() //asm("cli")
#define sti KeEnableInterrupts () //asm("sti")
#define VersionNumber 102
#define VersionString "V1.02"
#define UNUSED __attribute__((unused))
#define KERNEL_MEM_START 0xC0000000
//note: needs to be used for arrays only (So no pointers, otherwise that will be UB)
#define ARRAY_COUNT(array) (sizeof(array)/sizeof(*array))
#define STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
#define UNUSED __attribute__((unused))
#define ALWAYS_INLINE __attribute__((always_inline))
#define NO_RETURN __attribute__((noreturn))
//SAI = Static and Always Inlined
#define SAI static ALWAYS_INLINE inline
// The function that gets called when an assertion fails.
bool OnAssertionFail (const char *pStr, const char *pFile, const char *pFunc, int nLine);
#define ASSERT(condition) ((condition) || OnAssertionFail(#condition, __FILE__, __FUNCTION__, __LINE__))
extern void WritePort(unsigned short port, unsigned char data);
extern unsigned char ReadPort(unsigned short port);
extern void WritePortW(unsigned short port, unsigned short data);
extern unsigned short ReadPortW(unsigned short port);
extern void WritePortL(unsigned short port, unsigned int data);
extern unsigned int ReadPortL(unsigned int port);
// Stops the system immediately.
__attribute__((noreturn))
void KeStopSystem();
void KePrintSystemVersion();
// Gets the contents of the EFLAGS register.
uint32_t KeGetEFlags(void);
// Checks if interrupts are disabled right now.
bool KeCheckInterruptsDisabled(void);
// Asserts if interrupts are disabled.
void KeVerifyInterruptsDisabledD(const char * file, int line);
#define KeVerifyInterruptsDisabled KeVerifyInterruptsDisabledD(__FILE__, __LINE__)
// Asserts if interrupts are enabled.
void KeVerifyInterruptsEnabledD(const char * file, int line);
#define KeVerifyInterruptsEnabled KeVerifyInterruptsEnabledD(__FILE__, __LINE__)
void StopwatchStart();
int StopwatchEnd();
// LogMsg - Log a message to the current console. Must have interrupts enabled.
void LogMsg (const char* fmt, ...);
void LogMsgNoCr (const char* fmt, ...);
// LogMsg - Log a message to the screen. Can have interrupts disabled.
void ILogMsg (const char* fmt, ...);
void ILogMsgNoCr (const char* fmt, ...);
// SLogMsg - Log a message to the debug console (0xE9 port). Can have interrupts disabled.
void SLogMsg (const char* fmt, ...);
void SLogMsgNoCr (const char* fmt, ...);
STATIC_ASSERT(sizeof(long) == sizeof(uintptr_t), "Size of long and uintptr_t must match");
#endif//_MAIN_H