feat: reformatted code

This commit is contained in:
2021-02-10 18:56:47 +01:00
parent 2b295db30a
commit 90ef4522ca
16 changed files with 47 additions and 38 deletions

View File

@@ -59,7 +59,8 @@ int init_timer(u32 freq) {
u32 divisor = 1193180 / freq; u32 divisor = 1193180 / freq;
u8 low = (u8) (divisor & 0xFF); u8 low = (u8) (divisor & 0xFF);
u8 high = (u8) ((divisor >> 8) & 0xFF); u8 high = (u8) ((divisor >> 8) & 0xFF);
port_byte_out(PORT_PIT_COMMAND, PIT_MODE_BIN | PIT_MODE_HARDWARE_SQUARE_WAVE_GENERATOR | PIT_ACCESS_MODE_LH | PIT_CHANNEL_0); port_byte_out(PORT_PIT_COMMAND,
PIT_MODE_BIN | PIT_MODE_HARDWARE_SQUARE_WAVE_GENERATOR | PIT_ACCESS_MODE_LH | PIT_CHANNEL_0);
port_byte_out(PORT_PIT_DATA_0, low); port_byte_out(PORT_PIT_DATA_0, low);
port_byte_out(PORT_PIT_DATA_0, high); port_byte_out(PORT_PIT_DATA_0, high);
return 0; return 0;

View File

@@ -8,7 +8,9 @@
#include <types.h> #include <types.h>
int init_timer(u32 freq); int init_timer(u32 freq);
void print_current_tick(); void print_current_tick();
void sleep(u32 milliseconds); void sleep(u32 milliseconds);
#endif //MY_KERNEL_TIMER_H #endif //MY_KERNEL_TIMER_H

View File

@@ -61,6 +61,7 @@ typedef struct pci_driver pci_driver;
typedef struct pci_device pci_device; typedef struct pci_device pci_device;
typedef u8 (*pci_driver_validate)(const pci_device *); typedef u8 (*pci_driver_validate)(const pci_device *);
typedef u8 (*pci_driver_initialize)(pci_device *); typedef u8 (*pci_driver_initialize)(pci_device *);
typedef struct pci_driver { typedef struct pci_driver {
@@ -152,4 +153,5 @@ void pci_config_write_word(u8 bus, u8 slot, u8 func, u8 offset, u16 value);
void pci_config_write_byte(u8 bus, u8 slot, u8 func, u8 offset, u8 value); void pci_config_write_byte(u8 bus, u8 slot, u8 func, u8 offset, u8 value);
void pci_init_bar(pci_device *device, u8 bar_index); void pci_init_bar(pci_device *device, u8 bar_index);
#endif //NEW_KERNEL_PCI_H #endif //NEW_KERNEL_PCI_H

View File

@@ -31,6 +31,7 @@ unsigned short port_word_in(unsigned short port) {
void port_word_out(unsigned short port, unsigned short data) { void port_word_out(unsigned short port, unsigned short data) {
__asm__("out %%ax, %%dx" : : "a" (data), "d" (port)); __asm__("out %%ax, %%dx" : : "a" (data), "d" (port));
} }
unsigned int port_double_word_in(unsigned int port) { unsigned int port_double_word_in(unsigned int port) {
unsigned int result; unsigned int result;
__asm__("in %%dx, %%eax" : "=a" (result) : "d" (port)); __asm__("in %%dx, %%eax" : "=a" (result) : "d" (port));

View File

@@ -61,4 +61,5 @@ void port_word_out_repeat(unsigned short port, unsigned short *data, int buffer_
void port_word_in_repeat(unsigned short port, unsigned short *data, int buffer_size); void port_word_in_repeat(unsigned short port, unsigned short *data, int buffer_size);
void port_double_word_in_repeat(unsigned short port, unsigned int *data, int buffer_size); void port_double_word_in_repeat(unsigned short port, unsigned int *data, int buffer_size);
#endif #endif

View File

@@ -36,8 +36,11 @@ typedef struct {
} cmd_handler; } cmd_handler;
void print(const char *arg); void print(const char *arg);
void ide(const char *arg); void ide(const char *arg);
void echo(const char *arg); void echo(const char *arg);
void help(const char *arg); void help(const char *arg);
cmd_handler cmd_handlers[] = { cmd_handler cmd_handlers[] = {

View File

@@ -32,12 +32,13 @@ int abs(int val) {
// next stolen form https://www.techiedelight.com/implement-itoa-function-in-c/ // next stolen form https://www.techiedelight.com/implement-itoa-function-in-c/
// inline function to swap two numbers // inline function to swap two numbers
void swap(char *x, char *y) { void swap(char *x, char *y) {
char t = *x; *x = *y; *y = t; char t = *x;
*x = *y;
*y = t;
} }
// function to reverse buffer[i..j] // function to reverse buffer[i..j]
char* reverse(char *buffer, int i, int j) char *reverse(char *buffer, int i, int j) {
{
while (i < j) while (i < j)
swap(&buffer[i++], &buffer[j--]); swap(&buffer[i++], &buffer[j--]);
@@ -45,8 +46,7 @@ char* reverse(char *buffer, int i, int j)
} }
// Iterative function to implement itoa() function in C // Iterative function to implement itoa() function in C
char* itoa(int value, char* buffer, int base) char *itoa(int value, char *buffer, int base) {
{
// invalid input // invalid input
if (base < 2 || base > 32) if (base < 2 || base > 32)
return buffer; return buffer;
@@ -55,8 +55,7 @@ char* itoa(int value, char* buffer, int base)
int n = abs(value); int n = abs(value);
int i = 0; int i = 0;
while (n) while (n) {
{
int r = n % base; int r = n % base;
if (r >= 10) if (r >= 10)