style: clang-format on all files

This commit is contained in:
0x35c 2024-09-18 22:30:11 +02:00
parent 083468240d
commit 9b3a6cb5a4
15 changed files with 104 additions and 111 deletions

9
.clang-format Normal file
View File

@ -0,0 +1,9 @@
BasedOnStyle: LLVM
IndentWidth: 8
UseTab: AlignWithSpaces
BreakBeforeBraces: Linux
AllowShortIfStatementsOnASingleLine: Never
AllowShortFunctionsOnASingleLine: Empty
IndentCaseLabels: false
ColumnLimit: 80
AlignConsecutiveMacros: true

View File

@ -3,16 +3,16 @@
#include <stdarg.h> #include <stdarg.h>
enum print_level { enum print_level {
KERN_EMERG, KERN_EMERG,
KERN_ALERT, KERN_ALERT,
KERN_CRIT, KERN_CRIT,
KERN_ERR, KERN_ERR,
KERN_WARNING, KERN_WARNING,
KERN_NOTICE, KERN_NOTICE,
KERN_INFO, KERN_INFO,
KERN_DEBUG, KERN_DEBUG,
KERN_DEFAULT, KERN_DEFAULT,
KERN_CONT KERN_CONT
}; };
int kprintf(int level, const char *restrict format, ...); int kprintf(int level, const char *restrict format, ...);

View File

@ -2,32 +2,29 @@
#include <stdint.h> #include <stdint.h>
#define SECOND_REGISTER 0x00 #define SECOND_REGISTER 0x00
#define MINUTE_REGISTER 0x02 #define MINUTE_REGISTER 0x02
#define HOUR_REGISTER 0x04 #define HOUR_REGISTER 0x04
#define DAY_OF_THE_WEEK_REGISTER 0x06 #define DAY_OF_THE_WEEK_REGISTER 0x06
#define DAY_OF_THE_MONTH_REGISTER 0x07 #define DAY_OF_THE_MONTH_REGISTER 0x07
#define MONTH_REGISTER 0x08 #define MONTH_REGISTER 0x08
#define YEAR_REGISTER 0x09 #define YEAR_REGISTER 0x09
#define CENTURY_REGISTER 0x32 #define CENTURY_REGISTER 0x32
#define REGISTER_A 0x0A #define REGISTER_A 0x0A
#define REGISTER_B 0x0B #define REGISTER_B 0x0B
enum { enum { CMOS_ADDRESS = 0x70, CMOS_DATA = 0x71 };
CMOS_ADDRESS = 0x70,
CMOS_DATA = 0x71
};
struct rtc_date { struct rtc_date {
uint8_t second; uint8_t second;
uint8_t minute; uint8_t minute;
uint8_t hour; uint8_t hour;
uint8_t index_of_the_day; uint8_t index_of_the_day;
uint8_t day; uint8_t day;
uint8_t month; uint8_t month;
uint32_t year; uint32_t year;
}; };
struct rtc_date get_date(void); struct rtc_date get_date(void);

View File

@ -53,7 +53,7 @@ typedef enum {
ECHO, ECHO,
COLOR, COLOR,
MERDELLA, MERDELLA,
DATE, DATE,
ERROR ERROR
} CMD_TOK; } CMD_TOK;

View File

@ -1,4 +1,4 @@
int isdigit(int c) int isdigit(int c)
{ {
return '9' >= c && c >= '0'; return '9' >= c && c >= '0';
} }

View File

@ -1,4 +1,4 @@
int isprint(int c) int isprint(int c)
{ {
return (32 <= c && c < 127); return (32 <= c && c < 127);
} }

View File

@ -2,5 +2,5 @@
int atoi(const char *str) int atoi(const char *str)
{ {
return atoll(str); return atoll(str);
} }

View File

@ -2,5 +2,5 @@
long atol(const char *str) long atol(const char *str)
{ {
return atoll(str); return atoll(str);
} }

View File

@ -2,12 +2,12 @@
long long atoll(const char *str) long long atoll(const char *str)
{ {
const char *start = str; const char *start = str;
long long ret = 0; long long ret = 0;
while (*start != '\0') { while (*start != '\0') {
if (isdigit(*str)) if (isdigit(*str))
ret = ret * 10 + *str - '0'; ret = ret * 10 + *str - '0';
} }
return ret; return ret;
} }

View File

@ -2,12 +2,13 @@
int memcmp(const void *s1, const void *s2, size_t n) int memcmp(const void *s1, const void *s2, size_t n)
{ {
const char *str1 = s1; const char *str1 = s1;
const char *str2 = s2; const char *str2 = s2;
size_t i; size_t i;
if (n == 0) if (n == 0)
return 0; return 0;
for (i = 0; str1[i] == str2[i] && i < n - 1; i++); for (i = 0; str1[i] == str2[i] && i < n - 1; i++)
return str1[i] - str2[i]; ;
return str1[i] - str2[i];
} }

View File

@ -2,10 +2,9 @@
char *strchr(const char *str, int c) char *strchr(const char *str, int c)
{ {
char *start = (char *) str; char *start = (char *)str;
while (*start) while (*start) {
{
if (*start == c) if (*start == c)
return start; return start;
start++; start++;

View File

@ -1,6 +1,6 @@
#include <stddef.h> #include <stddef.h>
size_t strlen(const char *str) size_t strlen(const char *str)
{ {
const char *start = str; const char *start = str;

View File

@ -4,12 +4,11 @@
char *strstr(const char *haystack, const char *needle) char *strstr(const char *haystack, const char *needle)
{ {
char *start = (char *) haystack; char *start = (char *)haystack;
size_t len; size_t len;
len = strlen(needle); len = strlen(needle);
while (*start != '\0') while (*start != '\0') {
{
if (strncmp(start, needle, len) == 0) if (strncmp(start, needle, len) == 0)
return start; return start;
start++; start++;

View File

@ -6,53 +6,53 @@
static uint16_t raw_read_register(uint16_t cmos_register) static uint16_t raw_read_register(uint16_t cmos_register)
{ {
//selecting the register // selecting the register
outb(CMOS_ADDRESS, cmos_register); outb(CMOS_ADDRESS, cmos_register);
//read value of the selectect register // read value of the selectect register
return inb(CMOS_DATA); return inb(CMOS_DATA);
} }
static uint8_t update_is_in_progress(void) static uint8_t update_is_in_progress(void)
{ {
return raw_read_register(REGISTER_A) & 0x80; return raw_read_register(REGISTER_A) & 0x80;
} }
static uint16_t read_register(uint16_t cmos_register) static uint16_t read_register(uint16_t cmos_register)
{ {
while (update_is_in_progress()) while (update_is_in_progress())
kprintf(0, "%d\n", update_is_in_progress()); kprintf(0, "%d\n", update_is_in_progress());
return raw_read_register(cmos_register); return raw_read_register(cmos_register);
} }
uint8_t bcd_mode_to_bin(uint8_t value) uint8_t bcd_mode_to_bin(uint8_t value)
{ {
return (value & 0x0F) + ((value/ 16) * 10); return (value & 0x0F) + ((value / 16) * 10);
} }
struct rtc_date get_date(void) struct rtc_date get_date(void)
{ {
struct rtc_date rv; struct rtc_date rv;
uint8_t century; uint8_t century;
rv.second = read_register(SECOND_REGISTER); rv.second = read_register(SECOND_REGISTER);
rv.minute = read_register(MINUTE_REGISTER); rv.minute = read_register(MINUTE_REGISTER);
rv.hour = read_register(HOUR_REGISTER); rv.hour = read_register(HOUR_REGISTER);
rv.day = read_register(DAY_OF_THE_MONTH_REGISTER); rv.day = read_register(DAY_OF_THE_MONTH_REGISTER);
rv.index_of_the_day = read_register(DAY_OF_THE_WEEK_REGISTER) - 1; rv.index_of_the_day = read_register(DAY_OF_THE_WEEK_REGISTER) - 1;
rv.month = read_register(MONTH_REGISTER) - 1; rv.month = read_register(MONTH_REGISTER) - 1;
rv.year += read_register(YEAR_REGISTER); rv.year += read_register(YEAR_REGISTER);
century = read_register(CENTURY_REGISTER); century = read_register(CENTURY_REGISTER);
if (!(read_register(REGISTER_B) & 0x04)) { if (!(read_register(REGISTER_B) & 0x04)) {
rv.second = bcd_mode_to_bin(rv.second); rv.second = bcd_mode_to_bin(rv.second);
rv.minute = bcd_mode_to_bin(rv.minute); rv.minute = bcd_mode_to_bin(rv.minute);
rv.hour = bcd_mode_to_bin(rv.hour); rv.hour = bcd_mode_to_bin(rv.hour);
rv.day = bcd_mode_to_bin(rv.day); rv.day = bcd_mode_to_bin(rv.day);
rv.index_of_the_day = bcd_mode_to_bin(rv.index_of_the_day); rv.index_of_the_day = bcd_mode_to_bin(rv.index_of_the_day);
rv.month = bcd_mode_to_bin(rv.month); rv.month = bcd_mode_to_bin(rv.month);
rv.year = bcd_mode_to_bin(rv.year); rv.year = bcd_mode_to_bin(rv.year);
century = bcd_mode_to_bin(century); century = bcd_mode_to_bin(century);
} }
rv.year += century * 100 - 98; // -108 = bozo offset rv.year += century * 100 - 98; // -108 = bozo offset
return rv; return rv;
} }

View File

@ -1,30 +1,18 @@
#include "kprintf.h" #include "kprintf.h"
#include "rtc.h" #include "rtc.h"
void date() void date(void)
{ {
static const char *months[12] = { static const char *months[12] = {"January", "February", "March",
"January", "April", "May", "June",
"February", "July", "August", "September",
"March", "October", "November", "December"};
"April", static const char *week_days[] = {"Sunday", "Monday", "Tuesday",
"May", "Wednesday", "Thursday", "Friday",
"June", "Saturday"};
"July", struct rtc_date date = get_date();
"August",
"September",
"October",
"November",
"December" };
static const char * week_days[] = {
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday" };
struct rtc_date date = get_date();
kprintf(0, "%s. %d %s. %d %d:%d:%d\n", week_days[date.index_of_the_day], date.day, months[date.month], date.year, date.hour, date.minute, date.second); kprintf(0, "%s. %d %s. %d %d:%d:%d\n", week_days[date.index_of_the_day],
} date.day, months[date.month], date.year, date.hour, date.minute,
date.second);
}