mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-05-31 00:37:58 +00:00
CMOS clock
This commit is contained in:
parent
7c4d43fec3
commit
f3aea7e1bd
1
.vscode/c_boilerplates.code-snippets
vendored
1
.vscode/c_boilerplates.code-snippets
vendored
@ -1,6 +1,5 @@
|
||||
{
|
||||
"Fennix Kernel Header": {
|
||||
"scope": "c",
|
||||
"prefix": [
|
||||
"head",
|
||||
],
|
||||
|
1
.vscode/c_cpp_properties.json
vendored
1
.vscode/c_cpp_properties.json
vendored
@ -6,6 +6,7 @@
|
||||
"${workspaceFolder}/include/**"
|
||||
],
|
||||
"defines": [
|
||||
"__debug_vscode__",
|
||||
"KERNEL_NAME=\"Fennix\"",
|
||||
"KERNEL_VERSION=\"1.0\"",
|
||||
"GIT_COMMIT=\"0000000000000000000000000000000000000000\"",
|
||||
|
35
Kernel.cpp
35
Kernel.cpp
@ -1,10 +1,34 @@
|
||||
#include "kernel.h"
|
||||
|
||||
#include <display.hpp>
|
||||
#include <memory.hpp>
|
||||
#include <string.h>
|
||||
#include <printf.h>
|
||||
#include <time.hpp>
|
||||
#include <debug.h>
|
||||
|
||||
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)
|
||||
{
|
||||
@ -20,11 +44,12 @@ EXTERNC void kernel_entry(BootInfo *Info)
|
||||
bInfo = (BootInfo *)KernelAllocator.RequestPages(TO_PAGES(sizeof(BootInfo)));
|
||||
memcpy(bInfo, Info, sizeof(BootInfo));
|
||||
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)
|
||||
CPU::Halt();
|
||||
}
|
||||
|
||||
// TODO: Implement screen printing
|
||||
extern "C" void putchar(int a, int b)
|
||||
{
|
||||
}
|
||||
|
38
arch/Time.cpp
Normal file
38
arch/Time.cpp
Normal 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
11
core/README.md
Normal 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.
|
@ -43,7 +43,8 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
@ -98,7 +99,6 @@ __attribute__((format(__printf__, (one_based_format_index), (first_arg))))
|
||||
PRINTF_VISIBILITY
|
||||
void putchar(char c);
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
///@}
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
///@}
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
///@}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* printf/vprintf with user-specified output function
|
||||
*
|
||||
|
14
include/time.hpp
Normal file
14
include/time.hpp
Normal 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__
|
Loading…
x
Reference in New Issue
Block a user