Format files

This commit is contained in:
Jessica Creighton 2019-04-03 17:46:58 -04:00
parent bc6f94e353
commit 3fe2d7aa33
21 changed files with 1117 additions and 1125 deletions

10
.clang-format Normal file
View File

@ -0,0 +1,10 @@
---
DerivePointerAlignment: 'true'
SpaceBeforeParens: ControlStatements
UseTab: ForIndentation
IndentWidth: 2
TabWidth: 2
ColumnLimit: 120
BreakBeforeBraces: Attach
...

65
arch/i386/tty.c Executable file → Normal file
View File

@ -31,9 +31,7 @@ void screen_initialize(void) {
} }
} }
void term_setcolor(enum vga_colors color) { void term_setcolor(enum vga_colors color) { current_color = color; }
current_color = color;
}
void term_putentryat(char c, uint8_t color, size_t x, size_t y) { void term_putentryat(char c, uint8_t color, size_t x, size_t y) {
const size_t offset = y * TERM_WIDTH + x; const size_t offset = y * TERM_WIDTH + x;
@ -60,21 +58,18 @@ void term_putchar(char c) {
} }
break; break;
} }
} }
struct csi_sequence parse_csi(const char* data, size_t size) { struct csi_sequence parse_csi(const char* data, size_t size) {
enum State { PARAMETER, INTERMEDIATE, FINAL, INVALID }; enum State { PARAMETER, INTERMEDIATE, FINAL, INVALID };
enum State state = PARAMETER; enum State state = PARAMETER;
struct csi_sequence sequence = { struct csi_sequence sequence = {.parameter = NULL,
.parameter = NULL,
.parameter_len = 0, .parameter_len = 0,
.intermediate = NULL, .intermediate = NULL,
.intermediate_len = 0, .intermediate_len = 0,
.final = NULL, .final = NULL,
.valid = false .valid = false};
};
for (size_t j = 0; j < size; j++) { for (size_t j = 0; j < size; j++) {
uint8_t c = data[j]; uint8_t c = data[j];
@ -121,8 +116,7 @@ void term_write(const char* data, size_t size) {
handleControlSequence(sequence); handleControlSequence(sequence);
i += sequence.parameter_len + sequence.intermediate_len + 2; // Move past sequence i += sequence.parameter_len + sequence.intermediate_len + 2; // Move past sequence
} }
} } break;
break;
// Single shifts are not handled, so just print them and exit // Single shifts are not handled, so just print them and exit
case 'N': // SS2 - Single Shift Two case 'N': // SS2 - Single Shift Two
term_writes("Single Shift Two\n"); term_writes("Single Shift Two\n");
@ -161,9 +155,7 @@ void term_write(const char* data, size_t size) {
} }
} }
void term_writes(const char* data) { void term_writes(const char* data) { term_write(data, strlen(data)); }
term_write(data, strlen(data));
}
void puts(const char* string) { void puts(const char* string) {
term_write(string, strlen(string)); term_write(string, strlen(string));
@ -193,43 +185,53 @@ void handleControlSequence(struct csi_sequence sequence) {
} }
switch (*(sequence.final)) { switch (*(sequence.final)) {
case 'H': case 'f': // CUP - Cursor Position case 'H':
case 'f': // CUP - Cursor Position
// TODO: Check to see if we have 2 paramaters // TODO: Check to see if we have 2 paramaters
if (params[0]) params[0]--; if (params[0])
if (params[1]) params[1]--; params[0]--;
if (params[1])
params[1]--;
set_cursor(params[0], params[1]); set_cursor(params[0], params[1]);
break; break;
case 'A': // CUU - Cursor Up case 'A': // CUU - Cursor Up
if (!params[0]) params[0] = 1; if (!params[0])
params[0] = 1;
set_cursor(terminal_column, terminal_row - params[0]); set_cursor(terminal_column, terminal_row - params[0]);
break; break;
case 'B': // CUD - Cursor Down case 'B': // CUD - Cursor Down
if (!params[0]) params[0] = 1; if (!params[0])
params[0] = 1;
set_cursor(terminal_column, terminal_row + params[0]); set_cursor(terminal_column, terminal_row + params[0]);
break; break;
case 'C': // CUF - Cursor Forward case 'C': // CUF - Cursor Forward
if (!params[0]) params[0] = 1; if (!params[0])
params[0] = 1;
set_cursor(terminal_column + params[0], terminal_row); set_cursor(terminal_column + params[0], terminal_row);
break; break;
case 'D': // CUB - Cursor Back case 'D': // CUB - Cursor Back
if (!params[0]) params[0] = 1; if (!params[0])
params[0] = 1;
set_cursor(terminal_column - params[0], terminal_row); set_cursor(terminal_column - params[0], terminal_row);
break; break;
case 'E': // CNL - Cursor Next Line case 'E': // CNL - Cursor Next Line
if (!params[0]) params[0] = 1; if (!params[0])
params[0] = 1;
set_cursor(0, terminal_row + params[0]); set_cursor(0, terminal_row + params[0]);
break; break;
case 'F': // CPL - Cursor Previous Line case 'F': // CPL - Cursor Previous Line
if (!params[0]) params[0] = 1; if (!params[0])
params[0] = 1;
set_cursor(0, terminal_row - params[0]); set_cursor(0, terminal_row - params[0]);
break; break;
case 'G': // CHA - Cursor Horizontal Absolute case 'G': // CHA - Cursor Horizontal Absolute
if (params[0]) params[0]--; if (params[0])
params[0]--;
set_cursor(params[0], terminal_row); set_cursor(params[0], terminal_row);
break; break;
case 'J': // ED - Erase in Display case 'J': // ED - Erase in Display
//current cursor pos = y * width + x
{ {
// current cursor pos = y * width + x
int pos = terminal_row * 80 + terminal_column; int pos = terminal_row * 80 + terminal_column;
if (params[0] == 0) { // Clear from cursor to end of screen if (params[0] == 0) { // Clear from cursor to end of screen
for (; pos < (25 * 80); pos++) { for (; pos < (25 * 80); pos++) {
@ -245,8 +247,8 @@ void handleControlSequence(struct csi_sequence sequence) {
vga_buffer[0] = '\0'; vga_buffer[0] = '\0';
} }
} }
}
break; break;
}
case 'K': // EL - Erase in Line case 'K': // EL - Erase in Line
{ {
int pos = terminal_row * 80 + terminal_column; int pos = terminal_row * 80 + terminal_column;
@ -267,8 +269,8 @@ void handleControlSequence(struct csi_sequence sequence) {
vga_buffer[pos] = '\0'; vga_buffer[pos] = '\0';
} }
} }
}
break; break;
}
case 'S': // SU - Scroll Up case 'S': // SU - Scroll Up
term_scroll(true); term_scroll(true);
break; break;
@ -277,12 +279,9 @@ void handleControlSequence(struct csi_sequence sequence) {
break; break;
} }
} }
} }
bool isDigit(char c) { bool isDigit(char c) { return c >= '0' && c <= '9'; }
return c >= '0' && c <= '9';
}
void set_cursor(int n, int m) { void set_cursor(int n, int m) {
terminal_column = n; terminal_column = n;
@ -308,8 +307,10 @@ void term_scroll(bool down) {
} }
} else { } else {
while (current_pos <= 4000) { while (current_pos <= 4000) {
term_buffer[current_pos - 160 /*The character immediately below it*/] = vga_buffer[current_pos]; //Move each character up a line term_buffer[current_pos - 160 /*The character immediately below it*/] =
term_buffer[current_pos - 159 /*The color of the character below*/] = vga_buffer[current_pos + 1]; //As well as its color vga_buffer[current_pos]; // Move each character up a line
term_buffer[current_pos - 159 /*The color of the character below*/] =
vga_buffer[current_pos + 1]; // As well as its color
current_pos += 2; // Move to next char current_pos += 2; // Move to next char
} }
} }

9
include/arch/i386/vga.h Executable file → Normal file
View File

@ -3,7 +3,6 @@
#include <stdint.h> #include <stdint.h>
enum vga_colors { enum vga_colors {
BLACK = 0, BLACK = 0,
BLUE = 1, BLUE = 1,
@ -23,12 +22,8 @@ enum vga_colors {
WHITE = 15 WHITE = 15
}; };
static inline uint8_t vga_color_set(enum vga_colors fg, enum vga_colors bg) { static inline uint8_t vga_color_set(enum vga_colors fg, enum vga_colors bg) { return fg | bg << 4; }
return fg | bg << 4;
}
static inline uint16_t vga_entry(unsigned char uc, uint8_t color) { static inline uint16_t vga_entry(unsigned char uc, uint8_t color) { return (uint16_t)uc | (uint16_t)color << 8; }
return (uint16_t) uc | (uint16_t) color << 8;
}
#endif #endif

1
include/kernel/tty.h Executable file → Normal file
View File

@ -15,7 +15,6 @@ struct csi_sequence {
bool valid; bool valid;
}; };
void term_setcolor(enum vga_colors); void term_setcolor(enum vga_colors);
void screen_initialize(void); void screen_initialize(void);
void term_putentryat(char, uint8_t, size_t, size_t); void term_putentryat(char, uint8_t, size_t, size_t);

9
include/vga.h Executable file → Normal file
View File

@ -2,7 +2,6 @@
#include <stdint.h> #include <stdint.h>
enum vga_colors { enum vga_colors {
BLACK = 0, BLACK = 0,
BLUE = 1, BLUE = 1,
@ -22,10 +21,6 @@ enum vga_colors {
WHITE = 15 WHITE = 15
}; };
static inline uint8_t vga_color_set(enum vga_colors fg, enum vga_colors bg) { static inline uint8_t vga_color_set(enum vga_colors fg, enum vga_colors bg) { return fg | bg << 4; }
return fg | bg << 4;
}
static inline uint16_t vga_entry(unsigned char uc, uint8_t color) { static inline uint16_t vga_entry(unsigned char uc, uint8_t color) { return (uint16_t)uc | (uint16_t)color << 8; }
return (uint16_t) uc | (uint16_t) color << 8;
}

3
kernel/kernel.c Executable file → Normal file
View File

@ -15,6 +15,7 @@ int kernel_main(void) {
term_setcolor(WHITE); term_setcolor(WHITE);
term_writes(", 2019\n"); term_writes(", 2019\n");
for(;;) {} for (;;) {
}
return 0; return 0;
} }

10
kernel/syscalls.c Executable file → Normal file
View File

@ -1,10 +1,10 @@
/*#include <sys/stat.h> /*#include <sys/stat.h>
#include <sys/types.h>
#include <sys/fcntl.h>
#include <sys/times.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <stdio.h> #include <stdio.h>
#include <sys/errno.h>
#include <sys/fcntl.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/types.h>
//prototypes; these are the bare minimum for newlib to compile. //prototypes; these are the bare minimum for newlib to compile.

0
kernel/utils.c Executable file → Normal file
View File

17
libc/include/stdlib.h Executable file → Normal file
View File

@ -3,8 +3,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
__attribute__((__noreturn__)) __attribute__((__noreturn__)) void abort(void);
void abort(void);
/* /*
Default header file for malloc-2.8.x, written by Doug Lea Default header file for malloc-2.8.x, written by Doug Lea
@ -202,7 +201,6 @@ int mallopt(int, int);
#define M_GRANULARITY (-2) #define M_GRANULARITY (-2)
#define M_MMAP_THRESHOLD (-3) #define M_MMAP_THRESHOLD (-3)
/* /*
malloc_footprint(); malloc_footprint();
Returns the number of bytes obtained from the system. The total Returns the number of bytes obtained from the system. The total
@ -280,8 +278,7 @@ size_t malloc_set_footprint_limit(size_t bytes);
malloc_inspect_all is compiled only if MALLOC_INSPECT_ALL is defined. malloc_inspect_all is compiled only if MALLOC_INSPECT_ALL is defined.
*/ */
void malloc_inspect_all(void(*handler)(void*, void *, size_t, void*), void malloc_inspect_all(void (*handler)(void*, void*, size_t, void*), void* arg);
void* arg);
#if !NO_MALLINFO #if !NO_MALLINFO
/* /*
@ -577,10 +574,8 @@ void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size);
void* mspace_realloc(mspace msp, void* mem, size_t newsize); void* mspace_realloc(mspace msp, void* mem, size_t newsize);
void* mspace_realloc_in_place(mspace msp, void* mem, size_t newsize); void* mspace_realloc_in_place(mspace msp, void* mem, size_t newsize);
void* mspace_memalign(mspace msp, size_t alignment, size_t bytes); void* mspace_memalign(mspace msp, size_t alignment, size_t bytes);
void** mspace_independent_calloc(mspace msp, size_t n_elements, void** mspace_independent_calloc(mspace msp, size_t n_elements, size_t elem_size, void* chunks[]);
size_t elem_size, void* chunks[]); void** mspace_independent_comalloc(mspace msp, size_t n_elements, size_t sizes[], void* chunks[]);
void** mspace_independent_comalloc(mspace msp, size_t n_elements,
size_t sizes[], void* chunks[]);
size_t mspace_bulk_free(mspace msp, void**, size_t n_elements); size_t mspace_bulk_free(mspace msp, void**, size_t n_elements);
size_t mspace_usable_size(const void* mem); size_t mspace_usable_size(const void* mem);
void mspace_malloc_stats(mspace msp); void mspace_malloc_stats(mspace msp);
@ -589,9 +584,7 @@ size_t mspace_footprint(mspace msp);
size_t mspace_max_footprint(mspace msp); size_t mspace_max_footprint(mspace msp);
size_t mspace_footprint_limit(mspace msp); size_t mspace_footprint_limit(mspace msp);
size_t mspace_set_footprint_limit(mspace msp, size_t bytes); size_t mspace_set_footprint_limit(mspace msp, size_t bytes);
void mspace_inspect_all(mspace msp, void mspace_inspect_all(mspace msp, void (*handler)(void*, void*, size_t, void*), void* arg);
void(*handler)(void *, void *, size_t, void*),
void* arg);
#endif /* MSPACES */ #endif /* MSPACES */
#ifdef __cplusplus #ifdef __cplusplus

2
libc/include/string.h Executable file → Normal file
View File

@ -1,8 +1,8 @@
#ifndef _STRING_H #ifndef _STRING_H
#define _STRING_H 1 #define _STRING_H 1
#include <sys/cdefs.h>
#include <stddef.h> #include <stddef.h>
#include <sys/cdefs.h>
int memcmp(const void*, const void*, size_t); int memcmp(const void*, const void*, size_t);
void* memcpy(void* __restrict, const void* __restrict, size_t); void* memcpy(void* __restrict, const void* __restrict, size_t);

5
libc/stdio/printf.c Executable file → Normal file
View File

@ -1,6 +1,6 @@
#include <limits.h> #include <limits.h>
#include <stdbool.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -8,8 +8,7 @@ static bool print(const char* data, size_t length) {
const unsigned char* bytes = (const unsigned char*)data; const unsigned char* bytes = (const unsigned char*)data;
for (size_t i = 0; i < length; i++) for (size_t i = 0; i < length; i++)
if (putchar(bytes[i]) == EOF) if (putchar(bytes[i]) == EOF)
return false' return false' return true;
return true;
} }
int printf(const char* restrict format, ...) { int printf(const char* restrict format, ...) {

0
libc/stdio/putchar.c Executable file → Normal file
View File

6
libc/stdlib/abort.c Executable file → Normal file
View File

@ -1,8 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
__attribute__((__noreturn__)) __attribute__((__noreturn__)) void abort(void) {
void abort(void) {
#if defined(__is_libk) #if defined(__is_libk)
// TODO: Kernel panic. // TODO: Kernel panic.
@ -10,6 +9,7 @@ void abort(void) {
#else #else
printf("abort() called\n"); printf("abort() called\n");
#endif #endif
while(1) {} while (1) {
}
__builtin_unreachable(); __builtin_unreachable();
} }

0
libc/string/memcmp.c Executable file → Normal file
View File

0
libc/string/memmove.c Executable file → Normal file
View File

0
libc/string/memset.c Executable file → Normal file
View File

3
libc/string/strlen.c Executable file → Normal file
View File

@ -3,6 +3,5 @@
size_t strlen(const char* str) { size_t strlen(const char* str) {
size_t len = 0; size_t len = 0;
while (str[len]) while (str[len])
len++ len++ return len;
return len;
} }