Added time RTC library

This commit is contained in:
Cetica Marco 2021-01-02 17:49:15 +01:00
parent 5880c473fc
commit 21f017f13c
29 changed files with 157 additions and 67 deletions

View File

@ -1,7 +1,7 @@
LD = i686-elf-ld
LFLAGS = -melf_i386 -nostdlib -O2 -T link.ld
all: prepare cpu kernel_code drivers libc shell mem link iso
all: prepare cpu kernel_code drivers libc userspace mem link iso
prepare:
mkdir -p obj/
@ -24,9 +24,9 @@ libc:
make -C kernel/libc
cp kernel/libc/*.o obj/
shell:
make -C kernel/shell
cp kernel/shell/*.o obj/
userspace:
make -C kernel/userspace
cp kernel/userspace/*.o obj/
mem:
make -C kernel/mem

View File

@ -1,7 +1,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; iceOS Kernel ;
; vulcanOS Kernel ;
; Developed by Marco 'icebit' Cetica ;
; (c) 2019 ;
; (c) 2019-2021 ;
; Released under GPLv3 ;
; https://github.com/ice-bit/iceOS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -1,7 +1,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; iceOS Kernel ;
; vulcanOS Kernel ;
; Developed by Marco 'icebit' Cetica ;
; (c) 2019 ;
; (c) 2019-2021 ;
; Released under GPLv3 ;
; https://github.com/ice-bit/iceOS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -1,7 +1,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; iceOS Kernel ;
; vulcanOS Kernel ;
; Developed by Marco 'icebit' Cetica ;
; (c) 2019 ;
; (c) 2019-2021 ;
; Released under GPLv3 ;
; https://github.com/ice-bit/iceOS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -1,7 +1,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; iceOS Kernel ;
; vulcanOS Kernel ;
; Developed by Marco 'icebit' Cetica ;
; (c) 2019-2020 ;
; (c) 2019-2021 ;
; Released under GPLv3 ;
; https://github.com/ice-bit/iceOS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -1,7 +1,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; iceOS Kernel ;
; vulcanOS Kernel ;
; Developed by Marco 'icebit' Cetica ;
; (c) 2019 ;
; (c) 2019-2021 ;
; Released under GPLv3 ;
; https://github.com/ice-bit/iceOS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -1,7 +1,7 @@
/**************************************
* iceOS Kernel *
* VulcanOS Kernel *
* Developed by Marco 'icebit' Cetica *
* (c) 2019 *
* (c) 2019-2021 *
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/

View File

@ -1,7 +1,7 @@
/**************************************
* iceOS Kernel *
* VulcanOS Kernel *
* Developed by Marco 'icebit' Cetica *
* (c) 2019 *
* (c) 2019-2021 *
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/

View File

@ -1,7 +1,7 @@
/**************************************
* iceOS Kernel *
* VulcanOS Kernel *
* Developed by Marco 'icebit' Cetica *
* (c) 2019 *
* (c) 2019-2021 *
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/

View File

@ -1,3 +1,10 @@
/**************************************
* VulcanOS Kernel *
* Developed by Marco 'icebit' Cetica *
* (c) 2019-2021 *
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/
#ifndef INITRD_H
#define INITRD_H
/* Ramdisk is a file system that is loaded along with the kernel

View File

@ -1,7 +1,7 @@
/**************************************
* iceOS Kernel *
* VulcanOS Kernel *
* Developed by Marco 'icebit' Cetica *
* (c) 2019 *
* (c) 2019-2021 *
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/

View File

@ -17,7 +17,7 @@
#include "isr.h"
#include "ports.h"
#include "tty.h"
#include "../shell/shell.h"
#include "../userspace/shell.h"
#include "../libc/stdio.h"
static void keyboard_callback();

View File

@ -1,7 +1,7 @@
/**************************************
* iceOS Kernel *
* VulcanOS Kernel *
* Developed by Marco 'icebit' Cetica *
* (c) 2019 *
* (c) 2019-2021 *
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/

View File

@ -1,3 +1,10 @@
/**************************************
* VulcanOS Kernel *
* Developed by Marco 'icebit' Cetica *
* (c) 2019-2021 *
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/
#ifndef _PORTS_H
#define _PORTS_H

View File

@ -1,7 +1,7 @@
/**************************************
* iceOS Kernel *
* VulcanOS Kernel *
* Developed by Marco 'icebit' Cetica *
* (c) 2019 *
* (c) 2019-2021 *
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/

View File

@ -1,11 +1,10 @@
/**************************************
* iceOS Kernel *
* VulcanOS Kernel *
* Developed by Marco 'icebit' Cetica *
* (c) 2019 *
* (c) 2019-2021 *
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/
#ifndef _TTY_H_
#define _TTY_H_

View File

@ -1,7 +1,7 @@
/**************************************
* iceOS Kernel *
* VulcanOS Kernel *
* Developed by Marco 'icebit' Cetica *
* (c) 2019 *
* (c) 2019-2021 *
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/
@ -12,7 +12,7 @@
#include "drivers/keyboard.h"
#include "mem/paging.h"
#include "mem/kheap.h"
#include "shell/shell.h"
#include "userspace/shell.h"
#include "libc/stdio.h"
#include "libc/assert.h"

View File

@ -1,4 +1,4 @@
OBJS = stdio.o string.o assert.o
OBJS = stdio.o string.o assert.o time.o
CC = i686-elf-gcc # cross-compiler
CFLAGS = -m32 -fno-stack-protector -ffreestanding -Wall -Wextra -Werror -g -c

View File

@ -1,7 +1,7 @@
/**************************************
* iceOS Kernel *
* VulcanOS Kernel *
* Developed by Marco 'icebit' Cetica *
* (c) 2019 *
* (c) 2019-2021 *
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/

View File

@ -1,11 +1,10 @@
/**************************************
* iceOS Kernel *
* VulcanOS Kernel *
* Developed by Marco 'icebit' Cetica *
* (c) 2019 *
* (c) 2019-2021 *
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/
#ifndef _STDIO_H_
#define _STDIO_H_

View File

@ -1,11 +1,10 @@
/**************************************
* iceOS Kernel *
* VulcanOS Kernel *
* Developed by Marco 'icebit' Cetica *
* (c) 2019 *
* (c) 2019-2021 *
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/
#ifndef _STRING_H_
#define _STRING_H_

38
kernel/libc/time.c Normal file
View File

@ -0,0 +1,38 @@
#include "time.h"
#include "../drivers/ports.h"
// Check whether CMOS is updated or not
static uint8_t is_cmos_updated() {
outb(CMOS_ADDRESS, 0x0A);
return (inb(CMOS_DATA) & 0x80);
}
// Get CMOS register's status
static uint8_t reg_status(int32_t reg) {
outb(CMOS_ADDRESS, reg);
return inb(CMOS_DATA);
}
time_t cmos_reader() {
while(is_cmos_updated()); // Wait until the CMOS is being updated
time_t tm;
tm.second = BCD_CONVERTER(reg_status(TIME_R_SECOND));
tm.minute = BCD_CONVERTER(reg_status(TIME_R_MINUTE));
tm.hour = BCD_CONVERTER(reg_status(TIME_R_HOUR));
tm.day = BCD_CONVERTER(reg_status(TIME_R_DAY));
tm.month = BCD_CONVERTER(reg_status(TIME_R_MONTH));
tm.year = BCD_CONVERTER(reg_status(TIME_R_YEAR));
return tm;
}
uint32_t get_time(uint32_t field) {
while(is_cmos_updated()); // Wait the CMOS is being updated
return BCD_CONVERTER(reg_status(field));
}

42
kernel/libc/time.h Normal file
View File

@ -0,0 +1,42 @@
/**************************************
* VulcanOS Kernel *
* Developed by Marco 'icebit' Cetica *
* (c) 2019-2021 *
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/
/* Get time reading the RTC(real time clock) CMOS on the motherboard */
#ifndef TIME_H
#define TIME_H
#include <stdint.h>
// Define RTC field registers
#define TIME_R_YEAR 0x09
#define TIME_R_MONTH 0x08
#define TIME_R_DAY 0x07
#define TIME_R_HOUR 0x06
#define TIME_R_MINUTE 0x05
#define TIME_R_SECOND 0x04
//#define TIME_R_CENTURY 0x32
// Define RTC address
#define CMOS_ADDRESS 0x70
#define CMOS_DATA 0x71
// Convert BCD encoed values to binary
#define BCD_CONVERTER(n) ((n / 16) * 10 + (n & 0xF))
typedef struct {
uint8_t second;
uint8_t minute;
uint8_t hour;
uint8_t day;
uint8_t month;
uint8_t year;
} time_t;
time_t cmos_reader();
uint32_t get_time(uint32_t field);
#endif

View File

@ -1,12 +1,11 @@
/**************************************
* iceOS Kernel *
* VulcanOS Kernel *
* Developed by Marco 'icebit' Cetica *
* (c) 2019 *
* (c) 2019-2021 *
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/
/*** Heap implementation from James Molloy's tutorial:
http://www.jamesmolloy.co.uk/tutorial_html/7.-The%20Heap.html ***/

View File

@ -1,7 +1,7 @@
/**************************************
* iceOS Kernel *
* VulcanOS Kernel *
* Developed by Marco 'icebit' Cetica *
* (c) 2019 *
* (c) 2019-2021 *
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/

View File

@ -1,7 +1,7 @@
/**************************************
* iceOS Kernel *
* VulcanOS Kernel *
* Developed by Marco 'icebit' Cetica *
* (c) 2019 *
* (c) 2019-2021 *
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/

View File

@ -1,7 +1,7 @@
/**************************************
* iceOS Kernel *
* VulcanOS Kernel *
* Developed by Marco 'icebit' Cetica *
* (c) 2019 *
* (c) 2019-2021 *
* Released under GPLv3 *
* https://github.com/ice-bit/iceOS *
***************************************/