Style: Converting spaces to tabs
This commit is contained in:
parent
e472492ee3
commit
5ec345e59f
4 changed files with 185 additions and 185 deletions
70
src/serial.c
70
src/serial.c
|
@ -2,48 +2,48 @@
|
||||||
#define PORT 0x3f8 // COM1
|
#define PORT 0x3f8 // COM1
|
||||||
|
|
||||||
static inline void outb(unsigned short port, unsigned char val) {
|
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) {
|
static inline unsigned char inb(unsigned short port) {
|
||||||
unsigned char ret;
|
unsigned char ret;
|
||||||
asm volatile("inb %1, %0" : "=a"(ret) : "Nd"(port) : "memory");
|
asm volatile("inb %1, %0" : "=a"(ret) : "Nd"(port) : "memory");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int serial_init() {
|
int serial_init() {
|
||||||
outb(PORT + 1, 0x00); // Disable all interrupts
|
outb(PORT + 1, 0x00); // Disable all interrupts
|
||||||
outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
|
outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
|
||||||
outb(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud
|
outb(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud
|
||||||
outb(PORT + 1, 0x00); // (hi byte)
|
outb(PORT + 1, 0x00); // (hi byte)
|
||||||
outb(PORT + 3, 0x03); // 8 bits, no parity, one stop bit
|
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 + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold
|
||||||
outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
|
outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
|
||||||
outb(PORT + 4, 0x1E); // Set in loopback mode, test the serial chip
|
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
|
outb(PORT + 0, 0xAE); // Test serial chip (send byte 0xAE and check if serial
|
||||||
// returns same byte)
|
// returns same byte)
|
||||||
|
|
||||||
// Check if serial is faulty (i.e: not same byte as sent)
|
// Check if serial is faulty (i.e: not same byte as sent)
|
||||||
if (inb(PORT + 0) != 0xAE) {
|
if (inb(PORT + 0) != 0xAE) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If serial is not faulty set it in normal operation mode
|
// If serial is not faulty set it in normal operation mode
|
||||||
// (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled)
|
// (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled)
|
||||||
outb(PORT + 4, 0x0F);
|
outb(PORT + 4, 0x0F);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static int serial_is_transmit_empty() { return inb(PORT + 5) & 0x20; }
|
static int serial_is_transmit_empty() { return inb(PORT + 5) & 0x20; }
|
||||||
|
|
||||||
static void serial_write_char(char chr) {
|
static void serial_write_char(char chr) {
|
||||||
while (serial_is_transmit_empty() == 0);
|
while (serial_is_transmit_empty() == 0);
|
||||||
outb(PORT, chr);
|
outb(PORT, chr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void serial_write_string(const char* text) {
|
void serial_write_string(const char* text) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(text[i]) {
|
while(text[i]) {
|
||||||
serial_write_char(text[i]);
|
serial_write_char(text[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
format elf
|
format elf
|
||||||
use32
|
use32
|
||||||
|
|
||||||
MULTIBOOT_PAGE_ALIGN equ (1 shl 0)
|
MULTIBOOT_PAGE_ALIGN equ (1 shl 0)
|
||||||
MULTIBOOT_MEMORY_INFO equ (1 shl 1)
|
MULTIBOOT_MEMORY_INFO equ (1 shl 1)
|
||||||
MULTIBOOT_VIDEO_REQUEST equ (1 shl 2)
|
MULTIBOOT_VIDEO_REQUEST equ (1 shl 2)
|
||||||
MULTIBOOT_AOUT_KLUDGE equ (1 shl 16)
|
MULTIBOOT_AOUT_KLUDGE equ (1 shl 16)
|
||||||
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
|
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
|
||||||
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN or MULTIBOOT_MEMORY_INFO or MULTIBOOT_VIDEO_REQUEST
|
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_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
|
||||||
|
|
||||||
.multiboot: align 4
|
.multiboot: align 4
|
||||||
dd MULTIBOOT_HEADER_MAGIC
|
dd MULTIBOOT_HEADER_MAGIC
|
||||||
dd MULTIBOOT_HEADER_FLAGS
|
dd MULTIBOOT_HEADER_FLAGS
|
||||||
dd MULTIBOOT_CHECKSUM
|
dd MULTIBOOT_CHECKSUM
|
||||||
dd 0 ; header address
|
dd 0 ; header address
|
||||||
dd 0 ; load address
|
dd 0 ; load address
|
||||||
dd 0 ; load end address
|
dd 0 ; load end address
|
||||||
dd 0 ; bss end address
|
dd 0 ; bss end address
|
||||||
dd 0 ; entry address
|
dd 0 ; entry address
|
||||||
dd 0 ; video mode_type (0:fb, 1:txt) (set flags[2]!)
|
dd 0 ; video mode_type (0:fb, 1:txt) (set flags[2]!)
|
||||||
dd 1024 ; video width
|
dd 1024 ; video width
|
||||||
dd 768 ; video height
|
dd 768 ; video height
|
||||||
dd 32 ; video depth
|
dd 32 ; video depth
|
||||||
|
|
||||||
section '.bss' writable align 16
|
section '.bss' writable align 16
|
||||||
stack_bottom:
|
stack_bottom:
|
||||||
|
|
118
src/vga.c
118
src/vga.c
|
@ -11,87 +11,87 @@ unsigned char bgcolor;
|
||||||
unsigned short blank;
|
unsigned short blank;
|
||||||
|
|
||||||
static unsigned char vga_entry_color(enum vga_color fg, enum vga_color bg) {
|
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() {
|
unsigned short vga_blank_entry() {
|
||||||
return vga_entry_color(fgcolor, bgcolor) << 8;
|
return vga_entry_color(fgcolor, bgcolor) << 8;
|
||||||
}
|
}
|
||||||
void draw_cursor(void) {
|
void draw_cursor(void) {
|
||||||
*((unsigned char *)VGA_MEM_ADDR + cursor_loc * 2) = CURSOR_CHR;
|
*((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+1 + cursor_loc * 2) = vga_entry_color(fgcolor, bgcolor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vga_set_color(enum vga_color fg, enum vga_color bg) {
|
void vga_set_color(enum vga_color fg, enum vga_color bg) {
|
||||||
fgcolor = fg;
|
fgcolor = fg;
|
||||||
bgcolor = bg;
|
bgcolor = bg;
|
||||||
}
|
}
|
||||||
void vga_init(enum vga_color fg, enum vga_color bg) {
|
void vga_init(enum vga_color fg, enum vga_color bg) {
|
||||||
vga_set_color(fg, bg);
|
vga_set_color(fg, bg);
|
||||||
blank = vga_blank_entry();
|
blank = vga_blank_entry();
|
||||||
cls();
|
cls();
|
||||||
}
|
}
|
||||||
void cls(void) {
|
void cls(void) {
|
||||||
int i;
|
int i;
|
||||||
for (i=0; i<VGA_HEIGHT*VGA_WIDTH;i++) {
|
for (i=0; i<VGA_HEIGHT*VGA_WIDTH;i++) {
|
||||||
*((unsigned short *) VGA_MEM_ADDR+i) = blank;
|
*((unsigned short *) VGA_MEM_ADDR+i) = blank;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void scroll(void) {
|
void scroll(void) {
|
||||||
int y;
|
int y;
|
||||||
int x;
|
int x;
|
||||||
*((unsigned short *) VGA_MEM_ADDR+cursor_loc) = blank;
|
*((unsigned short *) VGA_MEM_ADDR+cursor_loc) = blank;
|
||||||
for (y=0;y<VGA_HEIGHT;y++) {
|
for (y=0;y<VGA_HEIGHT;y++) {
|
||||||
for (x = 0;x<VGA_WIDTH;x++) {
|
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);
|
*((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++) {
|
for (x=0;x<VGA_WIDTH;x++) {
|
||||||
*((unsigned short *) VGA_MEM_ADDR+CURSOR_HOME+x) = blank;
|
*((unsigned short *) VGA_MEM_ADDR+CURSOR_HOME+x) = blank;
|
||||||
}
|
}
|
||||||
cursor_loc = CURSOR_HOME;
|
cursor_loc = CURSOR_HOME;
|
||||||
draw_cursor();
|
draw_cursor();
|
||||||
}
|
}
|
||||||
void putchar(unsigned char chr) {
|
void putchar(unsigned char chr) {
|
||||||
if (chr == '\n') {
|
if (chr == '\n') {
|
||||||
scroll();
|
scroll();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*((unsigned char *) VGA_MEM_ADDR+cursor_loc * 2) = chr;
|
*((unsigned char *) VGA_MEM_ADDR+cursor_loc * 2) = chr;
|
||||||
*((unsigned char *) VGA_MEM_ADDR+1+cursor_loc * 2) = vga_entry_color(fgcolor, bgcolor);
|
*((unsigned char *) VGA_MEM_ADDR+1+cursor_loc * 2) = vga_entry_color(fgcolor, bgcolor);
|
||||||
cursor_loc++;
|
cursor_loc++;
|
||||||
if (cursor_loc >= VGA_HEIGHT*VGA_WIDTH) {
|
if (cursor_loc >= VGA_HEIGHT*VGA_WIDTH) {
|
||||||
scroll();
|
scroll();
|
||||||
}
|
}
|
||||||
draw_cursor();
|
draw_cursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void vga_write(const char* text) {
|
void vga_write(const char* text) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(text[i]) {
|
while(text[i]) {
|
||||||
putchar(text[i]);
|
putchar(text[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void vga_write_color( const char* text, enum vga_color fg, enum vga_color bg) {
|
void vga_write_color( const char* text, enum vga_color fg, enum vga_color bg) {
|
||||||
unsigned char prevfg = fgcolor;
|
unsigned char prevfg = fgcolor;
|
||||||
unsigned char prevbg = bgcolor;
|
unsigned char prevbg = bgcolor;
|
||||||
vga_set_color(fg, bg);
|
vga_set_color(fg, bg);
|
||||||
vga_write(text);
|
vga_write(text);
|
||||||
fgcolor = prevfg;
|
fgcolor = prevfg;
|
||||||
bgcolor = prevbg;
|
bgcolor = prevbg;
|
||||||
}
|
}
|
||||||
void vga_write_line(const char* text) {
|
void vga_write_line(const char* text) {
|
||||||
if (cursor_loc != CURSOR_HOME) {
|
if (cursor_loc != CURSOR_HOME) {
|
||||||
scroll();
|
scroll();
|
||||||
}
|
}
|
||||||
vga_write(text);
|
vga_write(text);
|
||||||
scroll();
|
scroll();
|
||||||
}
|
}
|
||||||
void vga_write_line_color(const char* text, enum vga_color fg, enum vga_color bg) {
|
void vga_write_line_color(const char* text, enum vga_color fg, enum vga_color bg) {
|
||||||
unsigned char prevfg = fgcolor;
|
unsigned char prevfg = fgcolor;
|
||||||
unsigned char prevbg = bgcolor;
|
unsigned char prevbg = bgcolor;
|
||||||
vga_set_color(fg, bg);
|
vga_set_color(fg, bg);
|
||||||
vga_write_line(text);
|
vga_write_line(text);
|
||||||
fgcolor = prevfg;
|
fgcolor = prevfg;
|
||||||
bgcolor = prevbg;
|
bgcolor = prevbg;
|
||||||
}
|
}
|
||||||
|
|
148
src/xtoa.c
148
src/xtoa.c
|
@ -1,100 +1,100 @@
|
||||||
#include "xtoa.h"
|
#include "xtoa.h"
|
||||||
char* itoa(int value, int base) {
|
char* itoa(int value, int base) {
|
||||||
char* result;
|
char* result;
|
||||||
|
|
||||||
// check that the base if valid
|
// check that the base if valid
|
||||||
if (base < 2 || base > 36) { *result = '\0'; return result; }
|
if (base < 2 || base > 36) { *result = '\0'; return result; }
|
||||||
|
|
||||||
char* ptr = result, *ptr1 = result, tmp_char;
|
char* ptr = result, *ptr1 = result, tmp_char;
|
||||||
int tmp_value;
|
int tmp_value;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
tmp_value = value;
|
tmp_value = value;
|
||||||
value /= base;
|
value /= base;
|
||||||
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
|
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
|
||||||
} while ( value );
|
} while ( value );
|
||||||
|
|
||||||
// Apply negative sign
|
// Apply negative sign
|
||||||
if (tmp_value < 0) *ptr++ = '-';
|
if (tmp_value < 0) *ptr++ = '-';
|
||||||
*ptr-- = '\0';
|
*ptr-- = '\0';
|
||||||
while(ptr1 < ptr) {
|
while(ptr1 < ptr) {
|
||||||
tmp_char = *ptr;
|
tmp_char = *ptr;
|
||||||
*ptr--= *ptr1;
|
*ptr--= *ptr1;
|
||||||
*ptr1++ = tmp_char;
|
*ptr1++ = tmp_char;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
char* uitoa(unsigned int value, int base) {
|
char* uitoa(unsigned int value, int base) {
|
||||||
char* result;
|
char* result;
|
||||||
|
|
||||||
// check that the base if valid
|
// check that the base if valid
|
||||||
if (base < 2 || base > 36) { *result = '\0'; return result; }
|
if (base < 2 || base > 36) { *result = '\0'; return result; }
|
||||||
|
|
||||||
char* ptr = result, *ptr1 = result, tmp_char;
|
char* ptr = result, *ptr1 = result, tmp_char;
|
||||||
int tmp_value;
|
int tmp_value;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
tmp_value = value;
|
tmp_value = value;
|
||||||
value /= base;
|
value /= base;
|
||||||
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
|
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
|
||||||
} while ( value );
|
} while ( value );
|
||||||
|
|
||||||
|
|
||||||
*ptr-- = '\0';
|
*ptr-- = '\0';
|
||||||
while(ptr1 < ptr) {
|
while(ptr1 < ptr) {
|
||||||
tmp_char = *ptr;
|
tmp_char = *ptr;
|
||||||
*ptr--= *ptr1;
|
*ptr--= *ptr1;
|
||||||
*ptr1++ = tmp_char;
|
*ptr1++ = tmp_char;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
char* ltoa(long value, int base) {
|
char* ltoa(long value, int base) {
|
||||||
char* result;
|
char* result;
|
||||||
|
|
||||||
// check that the base if valid
|
// check that the base if valid
|
||||||
if (base < 2 || base > 36) { *result = '\0'; return result; }
|
if (base < 2 || base > 36) { *result = '\0'; return result; }
|
||||||
|
|
||||||
char* ptr = result, *ptr1 = result, tmp_char;
|
char* ptr = result, *ptr1 = result, tmp_char;
|
||||||
int tmp_value;
|
int tmp_value;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
tmp_value = value;
|
tmp_value = value;
|
||||||
value /= base;
|
value /= base;
|
||||||
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
|
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
|
||||||
} while ( value );
|
} while ( value );
|
||||||
|
|
||||||
// Apply negative sign
|
// Apply negative sign
|
||||||
if (tmp_value < 0) *ptr++ = '-';
|
if (tmp_value < 0) *ptr++ = '-';
|
||||||
*ptr-- = '\0';
|
*ptr-- = '\0';
|
||||||
while(ptr1 < ptr) {
|
while(ptr1 < ptr) {
|
||||||
tmp_char = *ptr;
|
tmp_char = *ptr;
|
||||||
*ptr--= *ptr1;
|
*ptr--= *ptr1;
|
||||||
*ptr1++ = tmp_char;
|
*ptr1++ = tmp_char;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
char* ultoa(unsigned long value, int base) {
|
char* ultoa(unsigned long value, int base) {
|
||||||
char* result;
|
char* result;
|
||||||
|
|
||||||
// check that the base if valid
|
// check that the base if valid
|
||||||
if (base < 2 || base > 36) { *result = '\0'; return result; }
|
if (base < 2 || base > 36) { *result = '\0'; return result; }
|
||||||
|
|
||||||
char* ptr = result, *ptr1 = result, tmp_char;
|
char* ptr = result, *ptr1 = result, tmp_char;
|
||||||
int tmp_value;
|
int tmp_value;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
tmp_value = value;
|
tmp_value = value;
|
||||||
value /= base;
|
value /= base;
|
||||||
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
|
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
|
||||||
} while ( value );
|
} while ( value );
|
||||||
|
|
||||||
// Apply negative sign
|
// Apply negative sign
|
||||||
//if (tmp_value < 0) *ptr++ = '-';
|
//if (tmp_value < 0) *ptr++ = '-';
|
||||||
*ptr-- = '\0';
|
*ptr-- = '\0';
|
||||||
while(ptr1 < ptr) {
|
while(ptr1 < ptr) {
|
||||||
tmp_char = *ptr;
|
tmp_char = *ptr;
|
||||||
*ptr--= *ptr1;
|
*ptr--= *ptr1;
|
||||||
*ptr1++ = tmp_char;
|
*ptr1++ = tmp_char;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue