CMOS clock

This commit is contained in:
Alex 2022-10-09 04:02:41 +03:00
parent 7c4d43fec3
commit f3aea7e1bd
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
7 changed files with 213 additions and 129 deletions

View File

@ -1,6 +1,5 @@
{ {
"Fennix Kernel Header": { "Fennix Kernel Header": {
"scope": "c",
"prefix": [ "prefix": [
"head", "head",
], ],

View File

@ -6,6 +6,7 @@
"${workspaceFolder}/include/**" "${workspaceFolder}/include/**"
], ],
"defines": [ "defines": [
"__debug_vscode__",
"KERNEL_NAME=\"Fennix\"", "KERNEL_NAME=\"Fennix\"",
"KERNEL_VERSION=\"1.0\"", "KERNEL_VERSION=\"1.0\"",
"GIT_COMMIT=\"0000000000000000000000000000000000000000\"", "GIT_COMMIT=\"0000000000000000000000000000000000000000\"",

View File

@ -1,10 +1,34 @@
#include "kernel.h" #include "kernel.h"
#include <display.hpp>
#include <memory.hpp> #include <memory.hpp>
#include <string.h> #include <string.h>
#include <printf.h>
#include <time.hpp>
#include <debug.h> #include <debug.h>
BootInfo *bInfo = nullptr; BootInfo *bInfo = nullptr;
Video::Display *Display = nullptr;
// For the Display class. Printing on first buffer.
extern "C" void putchar(char c) { Display->Print(c, 0); }
#ifdef __debug_vscode__
extern "C" int printf_(const char *format, ...);
extern "C" int vprintf_(const char *format, va_list arg);
#endif
void KPrint(const char *format, ...)
{
Time tm = ReadClock();
printf_("[%02ld:%02ld:%02ld] ", tm.Hour, tm.Minute, tm.Second);
va_list args;
va_start(args, format);
vprintf_(format, args);
va_end(args);
putchar('\n');
Display->SetBuffer(0);
}
EXTERNC void kernel_aarch64_entry(uint64_t dtb_ptr32, uint64_t x1, uint64_t x2, uint64_t x3) EXTERNC void kernel_aarch64_entry(uint64_t dtb_ptr32, uint64_t x1, uint64_t x2, uint64_t x3)
{ {
@ -20,11 +44,12 @@ EXTERNC void kernel_entry(BootInfo *Info)
bInfo = (BootInfo *)KernelAllocator.RequestPages(TO_PAGES(sizeof(BootInfo))); bInfo = (BootInfo *)KernelAllocator.RequestPages(TO_PAGES(sizeof(BootInfo)));
memcpy(bInfo, Info, sizeof(BootInfo)); memcpy(bInfo, Info, sizeof(BootInfo));
debug("BootInfo structure is at %p", bInfo); debug("BootInfo structure is at %p", bInfo);
Display = new Video::Display(bInfo->Framebuffer[0]);
printf_("%s - %s(%s)\n", KERNEL_NAME, KERNEL_VERSION, GIT_COMMIT_SHORT);
Display->SetBuffer(0);
for (size_t i = 0; i < 70; i++)
KPrint("Hello, World! (%ld)", i);
while (1) while (1)
CPU::Halt(); CPU::Halt();
} }
// TODO: Implement screen printing
extern "C" void putchar(int a, int b)
{
}

38
arch/Time.cpp Normal file
View File

@ -0,0 +1,38 @@
#include <time.hpp>
#include <io.h>
Time ReadClock()
{
Time tm;
#if defined(__amd64__) || defined(__i386__)
uint32_t t = 0;
outb(0x70, 0x00);
t = inb(0x71);
tm.Second = ((t & 0x0F) + ((t >> 4) * 10));
outb(0x70, 0x02);
t = inb(0x71);
tm.Minute = ((t & 0x0F) + ((t >> 4) * 10));
outb(0x70, 0x04);
t = inb(0x71);
tm.Hour = ((t & 0x0F) + ((t >> 4) * 10));
outb(0x70, 0x07);
t = inb(0x71);
tm.Day = ((t & 0x0F) + ((t >> 4) * 10));
outb(0x70, 0x08);
t = inb(0x71);
tm.Month = ((t & 0x0F) + ((t >> 4) * 10));
outb(0x70, 0x09);
t = inb(0x71);
tm.Year = ((t & 0x0F) + ((t >> 4) * 10));
tm.Counter = 0;
#elif defined(__aarch64__)
tm.Year = 0;
tm.Month = 0;
tm.Day = 0;
tm.Hour = 0;
tm.Minute = 0;
tm.Second = 0;
tm.Counter = 0;
#endif
return tm;
}

11
core/README.md Normal file
View File

@ -0,0 +1,11 @@
# Core components
This directory contains the core components of the project. These components are used by the kernel to provide the basic functionality of the operating system.
---
## 💾 Memory
Contains the memory management code.
It is responsible for allocating and freeing memory.
It also provides the `kmalloc`, `kcalloc`, `krealloc` and `kfree` functions that are used by the rest of the kernel.

View File

@ -39,20 +39,21 @@
#ifndef PRINTF_H_ #ifndef PRINTF_H_
#define PRINTF_H_ #define PRINTF_H_
# include <stdarg.h> #include <stdarg.h>
# include <stddef.h> #include <stddef.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C"
{
#endif #endif
#ifdef __GNUC__ #ifdef __GNUC__
# define ATTR_PRINTF(one_based_format_index, first_arg) \ #define ATTR_PRINTF(one_based_format_index, first_arg) \
__attribute__((format(__printf__, (one_based_format_index), (first_arg)))) __attribute__((format(__printf__, (one_based_format_index), (first_arg))))
# define ATTR_VPRINTF(one_based_format_index) ATTR_PRINTF((one_based_format_index), 0) #define ATTR_VPRINTF(one_based_format_index) ATTR_PRINTF((one_based_format_index), 0)
#else #else
# define ATTR_PRINTF((one_based_format_index), (first_arg)) #define ATTR_PRINTF((one_based_format_index), (first_arg))
# define ATTR_VPRINTF(one_based_format_index) #define ATTR_VPRINTF(one_based_format_index)
#endif #endif
#ifndef PRINTF_ALIAS_STANDARD_FUNCTION_NAMES #ifndef PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
@ -60,12 +61,12 @@ __attribute__((format(__printf__, (one_based_format_index), (first_arg))))
#endif #endif
#if PRINTF_ALIAS_STANDARD_FUNCTION_NAMES #if PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
# define printf_ printf #define printf_ printf
# define sprintf_ sprintf #define sprintf_ sprintf
# define vsprintf_ vsprintf #define vsprintf_ vsprintf
# define snprintf_ snprintf #define snprintf_ snprintf
# define vsnprintf_ vsnprintf #define vsnprintf_ vsnprintf
# define vprintf_ vprintf #define vprintf_ vprintf
#endif #endif
// If you want to include this implementation file directly rather than // If you want to include this implementation file directly rather than
@ -76,7 +77,7 @@ __attribute__((format(__printf__, (one_based_format_index), (first_arg))))
#define PRINTF_VISIBILITY #define PRINTF_VISIBILITY
#endif #endif
/** /**
* Prints/send a single character to some opaque output entity * Prints/send a single character to some opaque output entity
* *
* @note This function is not implemented by the library, only declared; you must provide an * @note This function is not implemented by the library, only declared; you must provide an
@ -95,11 +96,10 @@ __attribute__((format(__printf__, (one_based_format_index), (first_arg))))
* *
* @param c the single character to print * @param c the single character to print
*/ */
PRINTF_VISIBILITY PRINTF_VISIBILITY
void putchar(char c); void putchar(char c);
/**
/**
* An implementation of the C standard's printf/vprintf * An implementation of the C standard's printf/vprintf
* *
* @note you must implement a @ref putchar_ function for using this function - it invokes @ref putchar_ * @note you must implement a @ref putchar_ function for using this function - it invokes @ref putchar_
@ -112,14 +112,13 @@ void putchar(char c);
* @return The number of characters written into @p s, not counting the terminating null character * @return The number of characters written into @p s, not counting the terminating null character
*/ */
///@{ ///@{
PRINTF_VISIBILITY PRINTF_VISIBILITY
int printf_(const char* format, ...) ATTR_PRINTF(1, 2); int printf_(const char *format, ...) ATTR_PRINTF(1, 2);
PRINTF_VISIBILITY PRINTF_VISIBILITY
int vprintf_(const char* format, va_list arg) ATTR_VPRINTF(1); int vprintf_(const char *format, va_list arg) ATTR_VPRINTF(1);
///@} ///@}
/**
/**
* An implementation of the C standard's sprintf/vsprintf * An implementation of the C standard's sprintf/vsprintf
* *
* @note For security considerations (the potential for exceeding the buffer bounds), please consider using * @note For security considerations (the potential for exceeding the buffer bounds), please consider using
@ -132,15 +131,14 @@ int vprintf_(const char* format, va_list arg) ATTR_VPRINTF(1);
* @param arg Additional arguments to the function, one for each specifier in @p format * @param arg Additional arguments to the function, one for each specifier in @p format
* @return The number of characters written into @p s, not counting the terminating null character * @return The number of characters written into @p s, not counting the terminating null character
*/ */
///@{ ///@{
PRINTF_VISIBILITY PRINTF_VISIBILITY
int sprintf_(char* s, const char* format, ...) ATTR_PRINTF(2, 3); int sprintf_(char *s, const char *format, ...) ATTR_PRINTF(2, 3);
PRINTF_VISIBILITY PRINTF_VISIBILITY
int vsprintf_(char* s, const char* format, va_list arg) ATTR_VPRINTF(2); int vsprintf_(char *s, const char *format, va_list arg) ATTR_VPRINTF(2);
///@} ///@}
/**
/**
* An implementation of the C standard's snprintf/vsnprintf * An implementation of the C standard's snprintf/vsnprintf
* *
* @param s An array in which to store the formatted string. It must be large enough to fit either the * @param s An array in which to store the formatted string. It must be large enough to fit either the
@ -155,16 +153,14 @@ int vsprintf_(char* s, const char* format, va_list arg) ATTR_VPRINTF(2);
* null character. A value equal or larger than @p n indicates truncation. Only when the returned value * null character. A value equal or larger than @p n indicates truncation. Only when the returned value
* is non-negative and less than @p n, the null-terminated string has been fully and successfully printed. * is non-negative and less than @p n, the null-terminated string has been fully and successfully printed.
*/ */
///@{ ///@{
PRINTF_VISIBILITY PRINTF_VISIBILITY
int snprintf_(char* s, size_t count, const char* format, ...) ATTR_PRINTF(3, 4); int snprintf_(char *s, size_t count, const char *format, ...) ATTR_PRINTF(3, 4);
PRINTF_VISIBILITY PRINTF_VISIBILITY
int vsnprintf_(char* s, size_t count, const char* format, va_list arg) ATTR_VPRINTF(3); int vsnprintf_(char *s, size_t count, const char *format, va_list arg) ATTR_VPRINTF(3);
///@} ///@}
/**
/**
* printf/vprintf with user-specified output function * printf/vprintf with user-specified output function
* *
* An alternative to @ref printf_, in which the output function is specified dynamically * An alternative to @ref printf_, in which the output function is specified dynamically
@ -178,18 +174,18 @@ int vsnprintf_(char* s, size_t count, const char* format, va_list arg) ATTR_VPRI
* @return The number of characters for which the output f unction was invoked, not counting the terminating null character * @return The number of characters for which the output f unction was invoked, not counting the terminating null character
* *
*/ */
PRINTF_VISIBILITY PRINTF_VISIBILITY
int fctprintf(void (*out)(char c, void* extra_arg), void* extra_arg, const char* format, ...) ATTR_PRINTF(3, 4); int fctprintf(void (*out)(char c, void *extra_arg), void *extra_arg, const char *format, ...) ATTR_PRINTF(3, 4);
PRINTF_VISIBILITY PRINTF_VISIBILITY
int vfctprintf(void (*out)(char c, void* extra_arg), void* extra_arg, const char* format, va_list arg) ATTR_VPRINTF(3); int vfctprintf(void (*out)(char c, void *extra_arg), void *extra_arg, const char *format, va_list arg) ATTR_VPRINTF(3);
#if PRINTF_ALIAS_STANDARD_FUNCTION_NAMES #if PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
# undef printf_ #undef printf_
# undef sprintf_ #undef sprintf_
# undef vsprintf_ #undef vsprintf_
# undef snprintf_ #undef snprintf_
# undef vsnprintf_ #undef vsnprintf_
# undef vprintf_ #undef vprintf_
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

14
include/time.hpp Normal file
View File

@ -0,0 +1,14 @@
#ifndef __FENNIX_KERNEL_TIME_H__
#define __FENNIX_KERNEL_TIME_H__
#include <types.h>
struct Time
{
uint64_t Year, Month, Day, Hour, Minute, Second;
uint64_t Counter;
};
Time ReadClock();
#endif // !__FENNIX_KERNEL_TIME_H__