Commit 83b7c108 by malcolm

Style fixes

parent fca15660
......@@ -10,57 +10,51 @@ gdt_desc _gdt [MAX_GDT_DESC];
#define set_cs( cs ) asm volatile ( "ljmp %0, $1337f \n\t 1337: \n\t" :: "i"(cs) )
void gdt_install(){
struct{
uint16_t limit;
uint32_t base;
}__attribute__((packed)) gdtr;
gdtr.limit = gdt_limit;
gdtr.base = gdt_base;
asm volatile ("lgdt (%0)": :"r"(&gdtr));
//serial_writestring("gdt installed, now setting cs\n");
set_cs(8);
//serial_writestring("cs set, setting ds\n");
//asm volatile ("ljmp $0x8,$1f;
// 1:
asm volatile(" mov $0x10, %ax;\
mov %ax, %ds;\
mov %ax, %es;\
mov %ax, %fs;\
mov %ax, %gs;\
struct{
uint16_t limit;
uint32_t base;
}__attribute__((packed)) gdtr;
gdtr.limit = gdt_limit;
gdtr.base = gdt_base;
asm volatile ("lgdt (%0)": :"r"(&gdtr));
set_cs(8);
asm volatile("mov $0x10, %ax;\
mov %ax, %ds; \
mov %ax, %es; \
mov %ax, %fs; \
mov %ax, %gs; \
mov %ax, %ss;");
//serial_writestring("ds set, we done here. moving on to idt\n");
//terminal_writestring("");
strlen("");
strlen("");
}
void gdt_set_desc(uint32_t i, uint64_t base, uint64_t limit, uint8_t access, uint8_t gran){
if (i > MAX_GDT_DESC)
return;
memset ((void*)&_gdt[i], 0, sizeof (gdt_desc));
_gdt[i].low_base = (uint16_t)(base & 0xffff);
_gdt[i].mid_base = (uint8_t)((base >> 16) & 0xff);
_gdt[i].high_base = (uint8_t)((base >> 24) & 0xff);
_gdt[i].lim = (uint16_t)(limit & 0xffff);
_gdt[i].flags = access;
_gdt[i].gran = (uint8_t)((limit >> 16) & 0x0f);
_gdt[i].gran |= gran & 0xf0;
if (i > MAX_GDT_DESC)
return;
memset ((void*)&_gdt[i], 0, sizeof (gdt_desc));
_gdt[i].low_base = (uint16_t)(base & 0xffff);
_gdt[i].mid_base = (uint8_t)((base >> 16) & 0xff);
_gdt[i].high_base = (uint8_t)((base >> 24) & 0xff);
_gdt[i].lim = (uint16_t)(limit & 0xffff);
_gdt[i].flags = access;
_gdt[i].gran = (uint8_t)((limit >> 16) & 0x0f);
_gdt[i].gran |= gran & 0xf0;
}
gdt_desc* gdt_get_desc (int i) {
if (i > MAX_GDT_DESC)
return 0;
return &_gdt[i];
if (i > MAX_GDT_DESC)
return 0;
return &_gdt[i];
}
int gdt_init() {
gdt_limit = (sizeof (gdt_desc) * MAX_GDT_DESC)-1;
gdt_base = (uint32_t)&_gdt[0];
//null
gdt_set_desc(0, 0, 0, 0, 0);
//code
gdt_set_desc(1,0,0xffffffff, GDT_RW|GDT_EXE|GDT_CDT|GDT_MEM, GDT_GR_PG|GDT_GR_32|GDT_GR_HI);
//data
gdt_set_desc(2,0,0xffffffff, GDT_RW|GDT_CDT|GDT_MEM, GDT_GR_PG|GDT_GR_32|GDT_GR_HI);
//serial_writestring("gdt filled, now installing\n");
gdt_install();
return 0;
gdt_limit = (sizeof (gdt_desc) * MAX_GDT_DESC)-1;
gdt_base = (uint32_t)&_gdt[0];
//null
gdt_set_desc(0, 0, 0, 0, 0);
//code
gdt_set_desc(1,0,0xffffffff, GDT_RW|GDT_EXE|GDT_CDT|GDT_MEM, GDT_GR_PG|GDT_GR_32|GDT_GR_HI);
//data
gdt_set_desc(2,0,0xffffffff, GDT_RW|GDT_CDT|GDT_MEM, GDT_GR_PG|GDT_GR_32|GDT_GR_HI);
//serial_writestring("gdt filled, now installing\n");
gdt_install();
return 0;
}
......@@ -18,12 +18,12 @@
#define GDT_GR_PG 0x80
typedef struct{
uint16_t lim;
uint16_t low_base;
uint8_t mid_base;
uint8_t flags;
uint8_t gran;
uint8_t high_base;
uint16_t lim;
uint16_t low_base;
uint8_t mid_base;
uint8_t flags;
uint8_t gran;
uint8_t high_base;
} __attribute__((packed)) gdt_desc;
extern void gdt_set_desc(uint32_t i, uint64_t base, uint64_t limit, uint8_t access, uint8_t gran);
......
......@@ -8,61 +8,51 @@ uint32_t idt_base;
idt_desc _idt [MAX_IDT_INT];
void idt_install() {
struct{
uint16_t limit;
uint32_t base;
} __attribute__((packed)) idtr;
//char s[1];
//itoa(sizeof(idtr),s);
//serial_writestring(s);
idtr.limit = idt_limit;
idtr.base = idt_base;
char f[20];
itoa(idtr.limit,f);
//serial_writestring(f);
//serial_writestring("\n");
itoa(idtr.base,f);
//serial_writestring(f);
//serial_writestring("\n");
asm volatile ("lidt (%0)": :"r"(&idtr));
struct{
uint16_t limit;
uint32_t base;
} __attribute__((packed)) idtr;
idtr.limit = idt_limit;
idtr.base = idt_base;
char f[20];
asm volatile ("lidt (%0)": :"r"(&idtr));
}
static void default_handler () {
//DEBUG OUTPUT MAYBE?
serial_writestring("int caught\n");
//for(;;);
return;
//DEBUG OUTPUT MAYBE?
serial_writestring("int caught\n");
return;
}
idt_desc* get_ir (uint32_t i) {
if (i>MAX_IDT_INT)
return 0;
return &_idt[i];
if (i>MAX_IDT_INT)
return 0;
return &_idt[i];
}
int install_ir (uint32_t i, uint16_t flags, uint16_t code_sel, IRQ_HANDLER irq) {
if (i>MAX_IDT_INT)
return 0;
if (!irq)
if (i>MAX_IDT_INT)
return 0;
if (!irq)
return 0;
uint64_t uiBase = (uintptr_t)(&(*irq));
_idt[i].low_base = (uint16_t)(uiBase & 0xffff);
_idt[i].high_base = (uint16_t)((uiBase >> 16) & 0xffff);
_idt[i].reserved = 0;
_idt[i].flags = (uint8_t)(flags);
_idt[i].code_sel = code_sel;
return 0;
uint64_t uiBase = (uintptr_t)(&(*irq));
_idt[i].low_base = (uint16_t)(uiBase & 0xffff);
_idt[i].high_base = (uint16_t)((uiBase >> 16) & 0xffff);
_idt[i].reserved = 0;
_idt[i].flags = (uint8_t)(flags);
_idt[i].code_sel = code_sel;
return 0;
}
int idt_init (uint16_t code_sel) {
idt_limit = sizeof (idt_desc) * MAX_IDT_INT -1;
idt_base = (uint32_t)&_idt[0];
memset ((void*)&_idt[0], 0, sizeof (idt_desc) * MAX_IDT_INT-1);
for (int i=0; i<MAX_IDT_INT; i++)
install_ir (i, IDT_PR|IDT_32,code_sel,(IRQ_HANDLER)default_handler);
idt_install();
char f[20];
itoa((uintptr_t)&_idt,f);
//serial_writestring(f);
return 0;
idt_limit = sizeof (idt_desc) * MAX_IDT_INT -1;
idt_base = (uint32_t)&_idt[0];
memset ((void*)&_idt[0], 0, sizeof (idt_desc) * MAX_IDT_INT-1);
for (int i=0; i<MAX_IDT_INT; i++)
install_ir (i, IDT_PR|IDT_32,code_sel,(IRQ_HANDLER)default_handler);
idt_install();
char f[20];
itoa((uintptr_t)&_idt,f);
//serial_writestring(f);
return 0;
}
......@@ -15,11 +15,11 @@
typedef void (*IRQ_HANDLER)(void);
typedef struct {
uint16_t low_base;
uint16_t code_sel;
uint8_t reserved;
uint8_t flags;
uint16_t high_base;
uint16_t low_base;
uint16_t code_sel;
uint8_t reserved;
uint8_t flags;
uint16_t high_base;
}__attribute__((packed)) idt_desc;
extern idt_desc* get_ir (uint32_t i);
......
......@@ -13,14 +13,10 @@
extern "C" /* Use C linkage for kernel_main. */
#endif
void kernel_main() {
/* Initialize terminal and serial interfaces */
terminal_initialize();
/* Initialize terminal and serial interfaces */
terminal_initialize();
serial_init();
char b[2];
int a = strlen("");
itoa(a,b);
terminal_writestring(b);
gdt_init();
idt_init(0x8);
......
#include "string.h"
void *memset(void *s, int c, size_t n){
unsigned char* p=s;
while(n--)
*p++=(unsigned char) c;
return s;
unsigned char* p=s;
while(n--)
*p++=(unsigned char) c;
return s;
}
void itoa(int n, char s[])
{
int i, sign;
if ((sign = n) < 0) /* record sign */
n = -n; /* make n positive */
i = 0;
......@@ -24,8 +24,8 @@ void itoa(int n, char s[])
}
size_t strlen(const char* str) {
size_t ret = 0;
while ( str[ret] != 0 )
ret++;
return ret;
size_t ret = 0;
while ( str[ret] != 0 )
ret++;
return ret;
}
......@@ -7,13 +7,13 @@
#include "term.h"
uint8_t make_color(enum vga_color fg, enum vga_color bg) {
return fg | bg << 4;
return fg | bg << 4;
}
uint16_t make_vgaentry(char c, uint8_t color) {
uint16_t c16 = c;
uint16_t color16 = color;
return c16 | color16 << 8;
uint16_t c16 = c;
uint16_t color16 = color;
return c16 | color16 << 8;
}
static const size_t VGA_WIDTH = 80;
......@@ -25,39 +25,39 @@ uint8_t terminal_color;
uint16_t* terminal_buffer;
void terminal_initialize() {
terminal_row = 0;
terminal_column = 0;
terminal_color = make_color(COLOR_LIGHT_GREY, COLOR_BLACK);
terminal_buffer = (uint16_t*) 0xB8000;
for (size_t y = 0; y < VGA_HEIGHT; y++) {
for (size_t x = 0; x < VGA_WIDTH; x++) {
const size_t index = y * VGA_WIDTH + x;
terminal_buffer[index] = make_vgaentry(' ', terminal_color);
}
terminal_row = 0;
terminal_column = 0;
terminal_color = make_color(COLOR_LIGHT_GREY, COLOR_BLACK);
terminal_buffer = (uint16_t*) 0xB8000;
for (size_t y = 0; y < VGA_HEIGHT; y++) {
for (size_t x = 0; x < VGA_WIDTH; x++) {
const size_t index = y * VGA_WIDTH + x;
terminal_buffer[index] = make_vgaentry(' ', terminal_color);
}
}
}
void terminal_setcolor(uint8_t color) {
terminal_color = color;
terminal_color = color;
}
void terminal_putentryat(char c, uint8_t color, size_t x, size_t y) {
const size_t index = y * VGA_WIDTH + x;
terminal_buffer[index] = make_vgaentry(c, color);
const size_t index = y * VGA_WIDTH + x;
terminal_buffer[index] = make_vgaentry(c, color);
}
void terminal_putchar(char c) {
terminal_putentryat(c, terminal_color, terminal_column, terminal_row);
if (++terminal_column == VGA_WIDTH) {
terminal_column = 0;
if (++terminal_row == VGA_HEIGHT) {
terminal_row = 0;
}
terminal_putentryat(c, terminal_color, terminal_column, terminal_row);
if (++terminal_column == VGA_WIDTH) {
terminal_column = 0;
if (++terminal_row == VGA_HEIGHT) {
terminal_row = 0;
}
}
}
void terminal_writestring(const char* data) {
size_t datalen = strlen(data);
for (size_t i = 0; i < datalen; i++)
terminal_putchar(data[i]);
size_t datalen = strlen(data);
for (size_t i = 0; i < datalen; i++)
terminal_putchar(data[i]);
}
......@@ -9,22 +9,22 @@
#include "string.h"
/* Hardware text mode color constants. */
enum vga_color {
COLOR_BLACK = 0,
COLOR_BLUE = 1,
COLOR_GREEN = 2,
COLOR_CYAN = 3,
COLOR_RED = 4,
COLOR_MAGENTA = 5,
COLOR_BROWN = 6,
COLOR_LIGHT_GREY = 7,
COLOR_DARK_GREY = 8,
COLOR_LIGHT_BLUE = 9,
COLOR_LIGHT_GREEN = 10,
COLOR_LIGHT_CYAN = 11,
COLOR_LIGHT_RED = 12,
COLOR_LIGHT_MAGENTA = 13,
COLOR_LIGHT_BROWN = 14,
COLOR_WHITE = 15,
COLOR_BLACK = 0,
COLOR_BLUE = 1,
COLOR_GREEN = 2,
COLOR_CYAN = 3,
COLOR_RED = 4,
COLOR_MAGENTA = 5,
COLOR_BROWN = 6,
COLOR_LIGHT_GREY = 7,
COLOR_DARK_GREY = 8,
COLOR_LIGHT_BLUE = 9,
COLOR_LIGHT_GREEN = 10,
COLOR_LIGHT_CYAN = 11,
COLOR_LIGHT_RED = 12,
COLOR_LIGHT_MAGENTA = 13,
COLOR_LIGHT_BROWN = 14,
COLOR_WHITE = 15,
};
uint8_t make_color(enum vga_color fg, enum vga_color bg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment