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 ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -19,4 +19,4 @@ gdt_flush:
mov ss, ax
jmp 0x08:.flush ; offset in the GDT of the code segment
.flush:
ret
ret

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 ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -11,4 +11,4 @@ section .text
idt_flush:
mov eax, [esp+4] ; Retrieve idt_ptr_t*
lidt [eax]
ret
ret

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 ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -18,4 +18,4 @@ outb:
inb:
mov dx, [esp + 4]
in al, dx
ret
ret

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 *
***************************************/
@ -81,4 +81,4 @@ void close_fs(fs_node_t *node);
struct dirent *readdir_fs(fs_node_t *node, uint32_t index);
fs_node_t *finddir_fs(fs_node_t *node, char *name);
#endif
#endif

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 *
***************************************/
@ -141,4 +141,4 @@ extern void irq13();
extern void irq14();
extern void irq15();
#endif
#endif

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
@ -26,4 +33,4 @@ static uint32_t initrd_read(fs_node_t *node, uint32_t offset, uint32_t size, uin
static struct dirent *initrd_readdir(fs_node_t *node, uint32_t index);
static fs_node_t *initrd_finddir(fs_node_t *node, uint8_t *name);
#endif
#endif

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();
@ -115,4 +115,4 @@ static void keyboard_callback() {
void init_keyboard() {
register_interrupt_handler(IRQ1, &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 *
***************************************/
@ -14,4 +14,4 @@
void init_keyboard();
#endif
#endif

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
@ -17,4 +24,4 @@ void outb(uint16_t port, uint16_t data);
uint8_t inb(uint16_t port);
#endif
#endif

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
@ -7,4 +7,4 @@ CFLAGS = -m32 -fno-stack-protector -ffreestanding -Wall -Wextra -Werror -g -c
all:${OBJS}
%.o: %.c
$(CC) $(CFLAGS) $< -o $@
$(CC) $(CFLAGS) $< -o $@

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 *
***************************************/
@ -18,4 +18,4 @@
extern void panic(const char *message, const char *file, uint32_t line);
extern void panic_assert(const char *file, uint32_t line, const char *desc);
#endif
#endif

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_
@ -17,4 +16,4 @@ int printf(const char *format, ...);
int printf_color(const char *format, uint8_t fg, uint8_t bg); // Only for string for now
void puts(const char *buf);
#endif
#endif

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 ***/
@ -68,4 +67,4 @@ uint32_t kmalloc_ap(uint32_t sz, uint32_t *phys);
uint32_t kmalloc(uint32_t sz);
void kfree(void *p);
#endif
#endif

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 *
***************************************/
@ -36,4 +36,4 @@ void insert_ordered_array(type_t item, ordered_array_t *array);
type_t lookup_ordered_array(uint32_t i, ordered_array_t *array);
void remove_ordered_array(uint32_t i, ordered_array_t *array);
#endif
#endif

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 *
***************************************/
@ -78,4 +78,4 @@ void alloc_frame(page_t *page, int32_t is_super, int32_t is_write);
// Page faults handler(ISR recorder)
void page_fault(registers_t regs);
#endif
#endif

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 *
***************************************/
@ -17,4 +17,4 @@ void helper();
void processCommand(uint8_t *cmd);
void iceos_ascii_logo();
#endif
#endif