1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2024-11-20 11:16:10 -05:00

Compile with -nostdinc

This commit is contained in:
Braiden Vasco 2017-11-01 10:08:09 +00:00
parent 78d8d84912
commit a02eda4c85
9 changed files with 90 additions and 100 deletions

View file

@ -23,7 +23,7 @@ kernel: $(OBJS)
grub-file --is-x86-multiboot2 $@
%.c.o: %.c
$(CC) -c $< -o $@ -std=gnu99 -ffreestanding -fno-builtin -fno-stack-protector -Wall -Wextra -I$(I)
$(CC) -c $< -o $@ -std=gnu99 -ffreestanding -nostdinc -fno-builtin -fno-stack-protector -Wall -Wextra -I$(I)
%.s.o: %.s
$(AS) $< -o $@

View file

@ -2,29 +2,29 @@
#include "util.h"
#include <stdbool.h>
static const unsigned int VGA_WIDTH = 80;
static const unsigned int VGA_HEIGHT = 25;
static const size_t VGA_WIDTH = 80;
static const size_t VGA_HEIGHT = 25;
static unsigned int console_row;
static unsigned int console_column;
static size_t console_row;
static size_t console_column;
static uint8_t console_color;
static uint16_t* console_buffer;
static unsigned char console_color;
static uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg);
static uint16_t vga_entry(unsigned char uc, uint8_t color);
static void console_putentryat(char c, uint8_t color, size_t x, size_t y);
static unsigned short *console_buffer;
static unsigned char vga_entry_color(enum vga_color fg, enum vga_color bg);
static unsigned short vga_entry(unsigned char uc, unsigned char color);
static void console_putentryat(char c, unsigned char color, unsigned int x, unsigned int y);
void console_initialize() {
console_row = 0;
console_column = 0;
console_color = vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK);
console_buffer = (uint16_t*)0xB8000;
console_buffer = (unsigned short*)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;
for (unsigned int y = 0; y < VGA_HEIGHT; y++) {
for (unsigned int x = 0; x < VGA_WIDTH; x++) {
const unsigned int index = y * VGA_WIDTH + x;
console_buffer[index] = vga_entry(' ', console_color);
}
}
@ -63,25 +63,25 @@ void console_puts(const char *const s)
console_putc('\n');
}
void console_setcolor(const uint8_t color) {
void console_setcolor(const unsigned char color) {
console_color = color;
}
void console_write(const char *const data, const size_t size) {
for (size_t i = 0; i < size; i++) {
void console_write(const char *const data, const unsigned int size) {
for (unsigned int i = 0; i < size; i++) {
console_putc(data[i]);
}
}
uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg) {
unsigned char vga_entry_color(enum vga_color fg, enum vga_color bg) {
return fg | bg << 4;
}
uint16_t vga_entry(unsigned char uc, uint8_t color) {
return (uint16_t) uc | (uint16_t) color << 8;
unsigned short vga_entry(unsigned char uc, unsigned char color) {
return (unsigned short) uc | (unsigned short) color << 8;
}
void console_putentryat(char c, uint8_t color, size_t x, size_t y) {
const size_t index = y * VGA_WIDTH + x;
void console_putentryat(char c, unsigned char color, unsigned int x, unsigned int y) {
const unsigned int index = y * VGA_WIDTH + x;
console_buffer[index] = vga_entry(c, color);
}

View file

@ -1,9 +1,6 @@
#ifndef TAILIX_KERNEL_INCLUDED_CONSOLE
#define TAILIX_KERNEL_INCLUDED_CONSOLE 1
#include <stdint.h>
#include <stddef.h>
// Hardware text mode color constants.
enum vga_color {
VGA_COLOR_BLACK = 0,
@ -29,7 +26,7 @@ void console_initialize();
void console_print(const char *s);
void console_putc(char c);
void console_puts(const char *s);
void console_setcolor(uint8_t color);
void console_write(const char *data, size_t size);
void console_setcolor(unsigned char color);
void console_write(const char *data, unsigned int size);
#endif

View file

@ -6,9 +6,9 @@ static struct GdtPointer gdt_pointer;
static struct GdtEntry gdt_entries[5];
static void gdt_set_gate(int32_t num, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran);
static void gdt_set_gate(int num, unsigned int base, unsigned int limit, unsigned char access, unsigned char gran);
void gdt_flush(uint32_t pointer);
void gdt_flush(unsigned int pointer);
void gdt_initialize()
{
@ -23,12 +23,12 @@ void gdt_initialize()
logger_info("Load GDT.");
gdt_pointer.limit = sizeof(struct GdtEntry) * 5 - 1;
gdt_pointer.base = (uint32_t)&gdt_entries;
gdt_pointer.base = (unsigned int)&gdt_entries;
gdt_flush((uint32_t)&gdt_pointer);
gdt_flush((unsigned int)&gdt_pointer);
}
void gdt_set_gate(int32_t num, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran)
void gdt_set_gate(int num, unsigned int base, unsigned int limit, unsigned char access, unsigned char gran)
{
gdt_entries[num].base_low = (base & 0xFFFF);
gdt_entries[num].base_middle = (base >> 16) & 0xFF;

View file

@ -1,21 +1,19 @@
#ifndef TAILIX_KERNEL_INCLUDED_GDT
#define TAILIX_KERNEL_INCLUDED_GDT 1
#include <stdint.h>
struct GdtPointer {
uint16_t limit;
uint32_t base;
unsigned short limit;
unsigned int base;
}
__attribute__((packed));
struct GdtEntry {
uint16_t limit_low;
uint16_t base_low;
uint8_t base_middle;
uint8_t access;
uint8_t granularity;
uint8_t base_high;
unsigned short limit_low;
unsigned short base_low;
unsigned char base_middle;
unsigned char access;
unsigned char granularity;
unsigned char base_high;
}
__attribute__((packed));

View file

@ -6,9 +6,9 @@ static struct IdtPointer idt_pointer;
static struct IdtEntry idt_entries[256];
static void idt_set_gate(uint8_t num, uint32_t base, uint16_t sel, uint8_t flags);
static void idt_set_gate(unsigned char num, unsigned int base, unsigned short sel, unsigned char flags);
void idt_flush(uint32_t pointer);
void idt_flush(unsigned int pointer);
void isr0();
void isr1();
@ -47,52 +47,52 @@ void idt_initialize()
{
logger_info("Setup IDT.");
for (uint8_t *p = (uint8_t*)idt_entries; p < (uint8_t*)&idt_entries[256]; ++p) {
for (unsigned char *p = (unsigned char*)idt_entries; p < (unsigned char*)&idt_entries[256]; ++p) {
*p = 0;
}
idt_set_gate(0, (uint32_t)isr0, 0x08, 0x8E);
idt_set_gate(1, (uint32_t)isr1, 0x08, 0x8E);
idt_set_gate(2, (uint32_t)isr2, 0x08, 0x8E);
idt_set_gate(3, (uint32_t)isr3, 0x08, 0x8E);
idt_set_gate(4, (uint32_t)isr4, 0x08, 0x8E);
idt_set_gate(5, (uint32_t)isr5, 0x08, 0x8E);
idt_set_gate(6, (uint32_t)isr6, 0x08, 0x8E);
idt_set_gate(7, (uint32_t)isr7, 0x08, 0x8E);
idt_set_gate(8, (uint32_t)isr8, 0x08, 0x8E);
idt_set_gate(9, (uint32_t)isr9, 0x08, 0x8E);
idt_set_gate(10, (uint32_t)isr10, 0x08, 0x8E);
idt_set_gate(11, (uint32_t)isr11, 0x08, 0x8E);
idt_set_gate(12, (uint32_t)isr12, 0x08, 0x8E);
idt_set_gate(13, (uint32_t)isr13, 0x08, 0x8E);
idt_set_gate(14, (uint32_t)isr14, 0x08, 0x8E);
idt_set_gate(15, (uint32_t)isr15, 0x08, 0x8E);
idt_set_gate(16, (uint32_t)isr16, 0x08, 0x8E);
idt_set_gate(17, (uint32_t)isr17, 0x08, 0x8E);
idt_set_gate(18, (uint32_t)isr18, 0x08, 0x8E);
idt_set_gate(19, (uint32_t)isr19, 0x08, 0x8E);
idt_set_gate(20, (uint32_t)isr20, 0x08, 0x8E);
idt_set_gate(21, (uint32_t)isr21, 0x08, 0x8E);
idt_set_gate(22, (uint32_t)isr22, 0x08, 0x8E);
idt_set_gate(23, (uint32_t)isr23, 0x08, 0x8E);
idt_set_gate(24, (uint32_t)isr24, 0x08, 0x8E);
idt_set_gate(25, (uint32_t)isr25, 0x08, 0x8E);
idt_set_gate(26, (uint32_t)isr26, 0x08, 0x8E);
idt_set_gate(27, (uint32_t)isr27, 0x08, 0x8E);
idt_set_gate(28, (uint32_t)isr28, 0x08, 0x8E);
idt_set_gate(29, (uint32_t)isr29, 0x08, 0x8E);
idt_set_gate(30, (uint32_t)isr30, 0x08, 0x8E);
idt_set_gate(31, (uint32_t)isr31, 0x08, 0x8E);
idt_set_gate(0, (unsigned int)isr0, 0x08, 0x8E);
idt_set_gate(1, (unsigned int)isr1, 0x08, 0x8E);
idt_set_gate(2, (unsigned int)isr2, 0x08, 0x8E);
idt_set_gate(3, (unsigned int)isr3, 0x08, 0x8E);
idt_set_gate(4, (unsigned int)isr4, 0x08, 0x8E);
idt_set_gate(5, (unsigned int)isr5, 0x08, 0x8E);
idt_set_gate(6, (unsigned int)isr6, 0x08, 0x8E);
idt_set_gate(7, (unsigned int)isr7, 0x08, 0x8E);
idt_set_gate(8, (unsigned int)isr8, 0x08, 0x8E);
idt_set_gate(9, (unsigned int)isr9, 0x08, 0x8E);
idt_set_gate(10, (unsigned int)isr10, 0x08, 0x8E);
idt_set_gate(11, (unsigned int)isr11, 0x08, 0x8E);
idt_set_gate(12, (unsigned int)isr12, 0x08, 0x8E);
idt_set_gate(13, (unsigned int)isr13, 0x08, 0x8E);
idt_set_gate(14, (unsigned int)isr14, 0x08, 0x8E);
idt_set_gate(15, (unsigned int)isr15, 0x08, 0x8E);
idt_set_gate(16, (unsigned int)isr16, 0x08, 0x8E);
idt_set_gate(17, (unsigned int)isr17, 0x08, 0x8E);
idt_set_gate(18, (unsigned int)isr18, 0x08, 0x8E);
idt_set_gate(19, (unsigned int)isr19, 0x08, 0x8E);
idt_set_gate(20, (unsigned int)isr20, 0x08, 0x8E);
idt_set_gate(21, (unsigned int)isr21, 0x08, 0x8E);
idt_set_gate(22, (unsigned int)isr22, 0x08, 0x8E);
idt_set_gate(23, (unsigned int)isr23, 0x08, 0x8E);
idt_set_gate(24, (unsigned int)isr24, 0x08, 0x8E);
idt_set_gate(25, (unsigned int)isr25, 0x08, 0x8E);
idt_set_gate(26, (unsigned int)isr26, 0x08, 0x8E);
idt_set_gate(27, (unsigned int)isr27, 0x08, 0x8E);
idt_set_gate(28, (unsigned int)isr28, 0x08, 0x8E);
idt_set_gate(29, (unsigned int)isr29, 0x08, 0x8E);
idt_set_gate(30, (unsigned int)isr30, 0x08, 0x8E);
idt_set_gate(31, (unsigned int)isr31, 0x08, 0x8E);
logger_info("Load IDT.");
idt_pointer.limit = sizeof(struct IdtEntry) * 256 - 1;
idt_pointer.base = (uint32_t)&idt_entries;
idt_pointer.base = (unsigned int)&idt_entries;
idt_flush((uint32_t)&idt_pointer);
idt_flush((unsigned int)&idt_pointer);
}
void idt_set_gate(uint8_t num, uint32_t base, uint16_t sel, uint8_t flags)
void idt_set_gate(unsigned char num, unsigned int base, unsigned short sel, unsigned char flags)
{
idt_entries[num].base_lo = base & 0xFFFF;
idt_entries[num].base_hi = (base >> 16) & 0xFFFF;

View file

@ -1,20 +1,18 @@
#ifndef TAILIX_KERNEL_INCLUDED_IDT
#define TAILIX_KERNEL_INCLUDED_IDT 1
#include <stdint.h>
struct IdtPointer {
uint16_t limit;
uint32_t base;
unsigned short limit;
unsigned int base;
}
__attribute__((packed));
struct IdtEntry {
uint16_t base_lo;
uint16_t sel;
uint8_t always0;
uint8_t flags;
uint16_t base_hi;
unsigned short base_lo;
unsigned short sel;
unsigned char always0;
unsigned char flags;
unsigned short base_hi;
}
__attribute__((packed));

View file

@ -4,7 +4,7 @@
#include "gdt.h"
#include "idt.h"
void main(uint32_t multiboot_magic)
void main(unsigned int multiboot_magic)
{
logger_initialize();

View file

@ -1,20 +1,17 @@
#ifndef TAILIX_KERNEL_INCLUDED_UTIL
#define TAILIX_KERNEL_INCLUDED_UTIL 1
#include <stdint.h>
#include <stddef.h>
static inline unsigned int strlen(const char *s);
static inline size_t strlen(const char *s);
size_t strlen(const char *const s)
unsigned int strlen(const char *const s)
{
size_t len = 0;
unsigned int result = 0;
while (s[len]) {
len++;
while (s[result]) {
++result;
}
return len;
return result;
}
#endif