From 5ec345e59f2a3e0539a73fbd93ada7f04dc3304d Mon Sep 17 00:00:00 2001 From: Jarkko Toivanen Date: Thu, 22 Jun 2023 02:28:33 +0300 Subject: [PATCH] Style: Converting spaces to tabs --- src/serial.c | 72 +++++++++++------------ src/start32.asm | 30 +++++----- src/vga.c | 118 ++++++++++++++++++------------------- src/xtoa.c | 150 ++++++++++++++++++++++++------------------------ 4 files changed, 185 insertions(+), 185 deletions(-) diff --git a/src/serial.c b/src/serial.c index e888af4..a9747cf 100644 --- a/src/serial.c +++ b/src/serial.c @@ -2,48 +2,48 @@ #define PORT 0x3f8 // COM1 static inline void outb(unsigned short port, unsigned char val) { - asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port) : "memory"); + asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port) : "memory"); } static inline unsigned char inb(unsigned short port) { - unsigned char ret; - asm volatile("inb %1, %0" : "=a"(ret) : "Nd"(port) : "memory"); - return ret; + unsigned char ret; + asm volatile("inb %1, %0" : "=a"(ret) : "Nd"(port) : "memory"); + return ret; } int serial_init() { - outb(PORT + 1, 0x00); // Disable all interrupts - outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor) - outb(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud - outb(PORT + 1, 0x00); // (hi byte) - outb(PORT + 3, 0x03); // 8 bits, no parity, one stop bit - outb(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold - outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set - outb(PORT + 4, 0x1E); // Set in loopback mode, test the serial chip - outb(PORT + 0, 0xAE); // Test serial chip (send byte 0xAE and check if serial - // returns same byte) + outb(PORT + 1, 0x00); // Disable all interrupts + outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor) + outb(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud + outb(PORT + 1, 0x00); // (hi byte) + outb(PORT + 3, 0x03); // 8 bits, no parity, one stop bit + outb(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold + outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set + outb(PORT + 4, 0x1E); // Set in loopback mode, test the serial chip + outb(PORT + 0, 0xAE); // Test serial chip (send byte 0xAE and check if serial + // returns same byte) - // Check if serial is faulty (i.e: not same byte as sent) - if (inb(PORT + 0) != 0xAE) { - return 1; - } + // Check if serial is faulty (i.e: not same byte as sent) + if (inb(PORT + 0) != 0xAE) { + return 1; + } - // If serial is not faulty set it in normal operation mode - // (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled) - outb(PORT + 4, 0x0F); - return 0; -} -static int serial_is_transmit_empty() { return inb(PORT + 5) & 0x20; } + // If serial is not faulty set it in normal operation mode + // (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled) + outb(PORT + 4, 0x0F); + return 0; + } + static int serial_is_transmit_empty() { return inb(PORT + 5) & 0x20; } -static void serial_write_char(char chr) { - while (serial_is_transmit_empty() == 0); - outb(PORT, chr); -} + static void serial_write_char(char chr) { + while (serial_is_transmit_empty() == 0); + outb(PORT, chr); + } + + void serial_write_string(const char* text) { + int i = 0; + while(text[i]) { + serial_write_char(text[i]); + i++; + } -void serial_write_string(const char* text) { - int i = 0; - while(text[i]) { - serial_write_char(text[i]); - i++; - } - -} + } diff --git a/src/start32.asm b/src/start32.asm index ce581d6..5344b47 100644 --- a/src/start32.asm +++ b/src/start32.asm @@ -1,27 +1,27 @@ format elf use32 -MULTIBOOT_PAGE_ALIGN equ (1 shl 0) -MULTIBOOT_MEMORY_INFO equ (1 shl 1) -MULTIBOOT_VIDEO_REQUEST equ (1 shl 2) -MULTIBOOT_AOUT_KLUDGE equ (1 shl 16) -MULTIBOOT_HEADER_MAGIC equ 0x1BADB002 -MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN or MULTIBOOT_MEMORY_INFO or MULTIBOOT_VIDEO_REQUEST +MULTIBOOT_PAGE_ALIGN equ (1 shl 0) +MULTIBOOT_MEMORY_INFO equ (1 shl 1) +MULTIBOOT_VIDEO_REQUEST equ (1 shl 2) +MULTIBOOT_AOUT_KLUDGE equ (1 shl 16) +MULTIBOOT_HEADER_MAGIC equ 0x1BADB002 +MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN or MULTIBOOT_MEMORY_INFO or MULTIBOOT_VIDEO_REQUEST MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) .multiboot: align 4 dd MULTIBOOT_HEADER_MAGIC dd MULTIBOOT_HEADER_FLAGS dd MULTIBOOT_CHECKSUM - dd 0 ; header address - dd 0 ; load address - dd 0 ; load end address - dd 0 ; bss end address - dd 0 ; entry address - dd 0 ; video mode_type (0:fb, 1:txt) (set flags[2]!) - dd 1024 ; video width - dd 768 ; video height - dd 32 ; video depth + dd 0 ; header address + dd 0 ; load address + dd 0 ; load end address + dd 0 ; bss end address + dd 0 ; entry address + dd 0 ; video mode_type (0:fb, 1:txt) (set flags[2]!) + dd 1024 ; video width + dd 768 ; video height + dd 32 ; video depth section '.bss' writable align 16 stack_bottom: diff --git a/src/vga.c b/src/vga.c index 9589d4f..bac204d 100644 --- a/src/vga.c +++ b/src/vga.c @@ -11,87 +11,87 @@ unsigned char bgcolor; unsigned short blank; static unsigned char vga_entry_color(enum vga_color fg, enum vga_color bg) { - return fg | bg << 4; + return fg | bg << 4; } unsigned short vga_blank_entry() { - return vga_entry_color(fgcolor, bgcolor) << 8; + return vga_entry_color(fgcolor, bgcolor) << 8; } void draw_cursor(void) { - *((unsigned char *)VGA_MEM_ADDR + cursor_loc * 2) = CURSOR_CHR; - *((unsigned char *)VGA_MEM_ADDR+1 + cursor_loc * 2) = vga_entry_color(fgcolor, bgcolor); + *((unsigned char *)VGA_MEM_ADDR + cursor_loc * 2) = CURSOR_CHR; + *((unsigned char *)VGA_MEM_ADDR+1 + cursor_loc * 2) = vga_entry_color(fgcolor, bgcolor); } void vga_set_color(enum vga_color fg, enum vga_color bg) { - fgcolor = fg; - bgcolor = bg; + fgcolor = fg; + bgcolor = bg; } void vga_init(enum vga_color fg, enum vga_color bg) { - vga_set_color(fg, bg); - blank = vga_blank_entry(); - cls(); + vga_set_color(fg, bg); + blank = vga_blank_entry(); + cls(); } void cls(void) { - int i; - for (i=0; i= VGA_HEIGHT*VGA_WIDTH) { - scroll(); - } - draw_cursor(); + if (chr == '\n') { + scroll(); + return; + } + *((unsigned char *) VGA_MEM_ADDR+cursor_loc * 2) = chr; + *((unsigned char *) VGA_MEM_ADDR+1+cursor_loc * 2) = vga_entry_color(fgcolor, bgcolor); + cursor_loc++; + if (cursor_loc >= VGA_HEIGHT*VGA_WIDTH) { + scroll(); + } + draw_cursor(); } void vga_write(const char* text) { - int i = 0; - while(text[i]) { - putchar(text[i]); - i++; - } + int i = 0; + while(text[i]) { + putchar(text[i]); + i++; + } } void vga_write_color( const char* text, enum vga_color fg, enum vga_color bg) { - unsigned char prevfg = fgcolor; - unsigned char prevbg = bgcolor; - vga_set_color(fg, bg); - vga_write(text); - fgcolor = prevfg; - bgcolor = prevbg; + unsigned char prevfg = fgcolor; + unsigned char prevbg = bgcolor; + vga_set_color(fg, bg); + vga_write(text); + fgcolor = prevfg; + bgcolor = prevbg; } void vga_write_line(const char* text) { - if (cursor_loc != CURSOR_HOME) { - scroll(); - } - vga_write(text); - scroll(); + if (cursor_loc != CURSOR_HOME) { + scroll(); + } + vga_write(text); + scroll(); } void vga_write_line_color(const char* text, enum vga_color fg, enum vga_color bg) { - unsigned char prevfg = fgcolor; - unsigned char prevbg = bgcolor; - vga_set_color(fg, bg); - vga_write_line(text); - fgcolor = prevfg; - bgcolor = prevbg; + unsigned char prevfg = fgcolor; + unsigned char prevbg = bgcolor; + vga_set_color(fg, bg); + vga_write_line(text); + fgcolor = prevfg; + bgcolor = prevbg; } diff --git a/src/xtoa.c b/src/xtoa.c index aaf7b69..68c9520 100644 --- a/src/xtoa.c +++ b/src/xtoa.c @@ -1,100 +1,100 @@ #include "xtoa.h" char* itoa(int value, int base) { - char* result; + char* result; - // check that the base if valid - if (base < 2 || base > 36) { *result = '\0'; return result; } + // check that the base if valid + if (base < 2 || base > 36) { *result = '\0'; return result; } - char* ptr = result, *ptr1 = result, tmp_char; - int tmp_value; + char* ptr = result, *ptr1 = result, tmp_char; + int tmp_value; - do { - tmp_value = value; - value /= base; - *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)]; - } while ( value ); - - // Apply negative sign - if (tmp_value < 0) *ptr++ = '-'; - *ptr-- = '\0'; - while(ptr1 < ptr) { - tmp_char = *ptr; - *ptr--= *ptr1; - *ptr1++ = tmp_char; - } - return result; + do { + tmp_value = value; + value /= base; + *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)]; + } while ( value ); + + // Apply negative sign + if (tmp_value < 0) *ptr++ = '-'; + *ptr-- = '\0'; + while(ptr1 < ptr) { + tmp_char = *ptr; + *ptr--= *ptr1; + *ptr1++ = tmp_char; + } + return result; } char* uitoa(unsigned int value, int base) { - char* result; + char* result; - // check that the base if valid - if (base < 2 || base > 36) { *result = '\0'; return result; } + // check that the base if valid + if (base < 2 || base > 36) { *result = '\0'; return result; } - char* ptr = result, *ptr1 = result, tmp_char; - int tmp_value; + char* ptr = result, *ptr1 = result, tmp_char; + int tmp_value; - do { - tmp_value = value; - value /= base; - *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)]; - } while ( value ); + do { + tmp_value = value; + value /= base; + *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)]; + } while ( value ); - *ptr-- = '\0'; - while(ptr1 < ptr) { - tmp_char = *ptr; - *ptr--= *ptr1; - *ptr1++ = tmp_char; - } - return result; + *ptr-- = '\0'; + while(ptr1 < ptr) { + tmp_char = *ptr; + *ptr--= *ptr1; + *ptr1++ = tmp_char; + } + return result; } char* ltoa(long value, int base) { - char* result; + char* result; - // check that the base if valid - if (base < 2 || base > 36) { *result = '\0'; return result; } + // check that the base if valid + if (base < 2 || base > 36) { *result = '\0'; return result; } - char* ptr = result, *ptr1 = result, tmp_char; - int tmp_value; + char* ptr = result, *ptr1 = result, tmp_char; + int tmp_value; - do { - tmp_value = value; - value /= base; - *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)]; - } while ( value ); + do { + tmp_value = value; + value /= base; + *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)]; + } while ( value ); - // Apply negative sign - if (tmp_value < 0) *ptr++ = '-'; - *ptr-- = '\0'; - while(ptr1 < ptr) { - tmp_char = *ptr; - *ptr--= *ptr1; - *ptr1++ = tmp_char; - } - return result; + // Apply negative sign + if (tmp_value < 0) *ptr++ = '-'; + *ptr-- = '\0'; + while(ptr1 < ptr) { + tmp_char = *ptr; + *ptr--= *ptr1; + *ptr1++ = tmp_char; + } + return result; } char* ultoa(unsigned long value, int base) { - char* result; + char* result; - // check that the base if valid - if (base < 2 || base > 36) { *result = '\0'; return result; } + // check that the base if valid + if (base < 2 || base > 36) { *result = '\0'; return result; } - char* ptr = result, *ptr1 = result, tmp_char; - int tmp_value; + char* ptr = result, *ptr1 = result, tmp_char; + int tmp_value; - do { - tmp_value = value; - value /= base; - *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)]; - } while ( value ); + do { + tmp_value = value; + value /= base; + *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)]; + } while ( value ); - // Apply negative sign - //if (tmp_value < 0) *ptr++ = '-'; - *ptr-- = '\0'; - while(ptr1 < ptr) { - tmp_char = *ptr; - *ptr--= *ptr1; - *ptr1++ = tmp_char; - } - return result; + // Apply negative sign + //if (tmp_value < 0) *ptr++ = '-'; + *ptr-- = '\0'; + while(ptr1 < ptr) { + tmp_char = *ptr; + *ptr--= *ptr1; + *ptr1++ = tmp_char; + } + return result; }