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

@ -43,7 +43,8 @@
#include <stddef.h> #include <stddef.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C"
{
#endif #endif
#ifdef __GNUC__ #ifdef __GNUC__
@ -98,7 +99,6 @@ __attribute__((format(__printf__, (one_based_format_index), (first_arg))))
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
* *
@ -118,7 +118,6 @@ 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
* *
@ -139,7 +138,6 @@ 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
* *
@ -162,8 +160,6 @@ 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
* *

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__