Style: Converting spaces to tabs

This commit is contained in:
Jarkko Toivanen 2023-06-22 02:28:33 +03:00
parent e472492ee3
commit 5ec345e59f
Signed by: jt
GPG key ID: 9151B109B73ECAD5
4 changed files with 185 additions and 185 deletions

View file

@ -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++;
}
}
}

View file

@ -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:

118
src/vga.c
View file

@ -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;i++) {
*((unsigned short *) VGA_MEM_ADDR+i) = blank;
}
int i;
for (i=0; i<VGA_HEIGHT*VGA_WIDTH;i++) {
*((unsigned short *) VGA_MEM_ADDR+i) = blank;
}
}
void scroll(void) {
int y;
int x;
*((unsigned short *) VGA_MEM_ADDR+cursor_loc) = blank;
for (y=0;y<VGA_HEIGHT;y++) {
for (x = 0;x<VGA_WIDTH;x++) {
*((unsigned short *) VGA_MEM_ADDR+y*VGA_WIDTH+x) = *((unsigned short *) VGA_MEM_ADDR+(y+1)*VGA_WIDTH+x);
}
}
for (x=0;x<VGA_WIDTH;x++) {
*((unsigned short *) VGA_MEM_ADDR+CURSOR_HOME+x) = blank;
}
cursor_loc = CURSOR_HOME;
draw_cursor();
int y;
int x;
*((unsigned short *) VGA_MEM_ADDR+cursor_loc) = blank;
for (y=0;y<VGA_HEIGHT;y++) {
for (x = 0;x<VGA_WIDTH;x++) {
*((unsigned short *) VGA_MEM_ADDR+y*VGA_WIDTH+x) = *((unsigned short *) VGA_MEM_ADDR+(y+1)*VGA_WIDTH+x);
}
}
for (x=0;x<VGA_WIDTH;x++) {
*((unsigned short *) VGA_MEM_ADDR+CURSOR_HOME+x) = blank;
}
cursor_loc = CURSOR_HOME;
draw_cursor();
}
void putchar(unsigned char chr) {
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();
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;
}

View file

@ -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 );
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* 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;
}