-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrew Sweeney
committed
Oct 25, 2012
1 parent
2a51b94
commit 98edb24
Showing
61 changed files
with
2,499 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
ifeq ($(strip $(V)),) | ||
E= @echo | ||
Q= @ | ||
else | ||
E = @\# | ||
Q = | ||
endif | ||
|
||
CC := gcc -m32 | ||
LD := ld -m elf_i386 | ||
AS := as --32 | ||
|
||
CFLAGS := -g3 -Werror -ffreestanding -nostdlib -mno-red-zone | ||
LDFLAGS := -nostdlib -fno-builtin -nostartfiles -nostdinc -nodefaultlibs | ||
|
||
KERNEL := kernel.img | ||
|
||
WARNINGS += -Wall | ||
WARNINGS += -Wcast-align | ||
WARNINGS += -Wformat=2 | ||
WARNINGS += -Winit-self | ||
WARNINGS += -Wmissing-declarations | ||
WARNINGS += -Wmissing-prototypes | ||
WARNINGS += -Wnested-externs | ||
WARNINGS += -Wno-system-headers | ||
WARNINGS += -Wold-style-definition | ||
WARNINGS += -Wredundant-decls | ||
WARNINGS += -Wsign-compare | ||
WARNINGS += -Wstrict-prototypes | ||
WARNINGS += -Wundef | ||
WARNINGS += -Wvolatile-register-var | ||
WARNINGS += -Wwrite-strings | ||
|
||
CFLAGS += $(WARNINGS) | ||
|
||
OBJS += kernel.o | ||
OBJS += gdt.o | ||
OBJS += isr.o | ||
OBJS += idt.o | ||
OBJS += mm.o | ||
OBJS += vm.o | ||
OBJS += vga.o | ||
OBJS += timer.o | ||
OBJS += printk.o | ||
OBJS += kbd.o | ||
OBJS += string.o | ||
OBJS += serial.o | ||
OBJS += ports.o | ||
OBJS += vtxprintf.o | ||
OBJS += boot_log.o | ||
|
||
all: $(KERNEL) | ||
$(E) "--[ Kernel Built" | ||
|
||
DEPS :=$(patsubst %.o, %.d, $(OBJS)) | ||
|
||
$(KERNEL): $(DEPS) $(OBJS) loader.o | ||
$(E) " LINK " $@ | ||
$(Q) $(LD) -T linker.ld loader.o $(OBJS) -o $@ | ||
|
||
loader.o: | ||
$(E) " AS " $@ | ||
$(Q) $(AS) -o loader.o loader.s gdt.s interrupt.s | ||
|
||
$(DEPS): | ||
|
||
%.d: %.c | ||
$(Q) $(CC) -M -MT $(patsubst %.d, %.o, $@) $(CFLAGS) $(LDFLAGS) $< -o $@ | ||
|
||
$(OBJS): | ||
|
||
%.o: %.c | ||
$(E) " CC " $@ | ||
$(Q) $(CC) -c $(CFLAGS) $(LDFLAGS) $< -o $@ | ||
|
||
|
||
floppy: $(KERNEL) | ||
|
||
clean: | ||
$(Q) rm -f $(DEPS) $(OBJS) loader.o $(KERNEL) | ||
$(E) "--[ Clean" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,23 @@ | ||
tinyboot | ||
======== | ||
|
||
tinyboot | ||
This is a tiny 32 bit kernel that was designed for learning purposes. The | ||
main goal in writing this was to create some boiler plate code required | ||
to get [Composite OS](http://composite.seas.gwu.edu/) to boot nativly. | ||
|
||
|
||
credit | ||
====== | ||
|
||
* http://www.jamesmolloy.co.uk/tutorial_html/index.html | ||
* http://www.kernel.org/ | ||
* http://www.minix3.org/ | ||
* http://wiki.osdev.org/ | ||
* http://www.seas.gwu.edu/~gparmer/composite | ||
* https://github.com/gparmer/Composite | ||
|
||
|
||
license | ||
====== | ||
This code is licensed under the GPL version 2.0: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
boot: floppy | ||
floppya: 1_44="floppy.img", status=inserted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "string.h" | ||
#include "serial.h" | ||
#include "boot_log.h" | ||
#include "printk.h" | ||
|
||
char boot_buffer[1024] = { '\0' }; | ||
|
||
static const char * boot_log_msgs[] = { | ||
[BOOT_OK] = "\033[1;32m OK ", | ||
[BOOT_WARN] = "\033[1;33m WARN ", | ||
[BOOT_ERROR] = "\033[1;31mERROR!", | ||
}; | ||
|
||
static const char *last_message = NULL; | ||
|
||
void | ||
boot_log(const char *s) | ||
{ | ||
last_message = s; | ||
|
||
sprintf(boot_buffer, "\033[0m%s\033[1000C\033[8D[ \033[1;34m....\033[0m ]", s); | ||
serial__puts(boot_buffer); | ||
} | ||
|
||
void | ||
boot_log_finish(enum boot_log_level l) | ||
{ | ||
if (last_message == NULL) | ||
return; | ||
|
||
sprintf(boot_buffer, "\033[1000D\033[0m%s\033[1000C\033[8D[%s\033[0m]\n", last_message, boot_log_msgs[l]); | ||
serial__puts(boot_buffer); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef _BOOT_LOG_H_ | ||
#define _BOOT_LOG_H_ | ||
|
||
enum boot_log_level { | ||
BOOT_OK, | ||
BOOT_WARN, | ||
BOOT_ERROR, | ||
}; | ||
|
||
|
||
void boot_log(const char *s); | ||
void boot_log_finish(enum boot_log_level l); | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef __I386_DIV64 | ||
#define __I386_DIV64 | ||
|
||
/* | ||
* do_div() is NOT a C function. It wants to return | ||
* two values (the quotient and the remainder), but | ||
* since that doesn't work very well in C, what it | ||
* does is: | ||
* | ||
* - modifies the 64-bit dividend _in_place_ | ||
* - returns the 32-bit remainder | ||
* | ||
* This ends up being the most efficient "calling | ||
* convention" on x86. | ||
*/ | ||
#define do_div(n,base) ({ \ | ||
unsigned long __upper, __low, __high, __mod, __base; \ | ||
__base = (base); \ | ||
asm("":"=a" (__low), "=d" (__high):"A" (n)); \ | ||
__upper = __high; \ | ||
if (__high) { \ | ||
__upper = __high % (__base); \ | ||
__high = __high / (__base); \ | ||
} \ | ||
asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (__base), "0" (__low), "1" (__upper)); \ | ||
asm("":"=A" (n):"a" (__low),"d" (__high)); \ | ||
__mod; \ | ||
}) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "types.h" | ||
#include "gdt.h" | ||
|
||
struct gdt_entry { | ||
uint16_t limit_low; // Lower 16 bits of the limit | ||
uint16_t base_low; // Lower 16 bits of the base | ||
uint8_t base_middle; // Next 8 bits of the base | ||
uint8_t access; // Access flags to determine ring | ||
uint8_t granularity; | ||
uint8_t base_high; // Last 8 bits of the base | ||
} __attribute__((packed)); | ||
|
||
struct gdt_ptr { | ||
uint16_t limit; // Upper 16 bits of all selecor limits | ||
uint32_t base; // Address of the first gdt entry | ||
} __attribute__((packed)); | ||
|
||
|
||
extern void gdt_flush(uint32_t); | ||
|
||
#define NUM_GDT_ENTRIES 5 | ||
|
||
static struct gdt_entry gdt_entries[NUM_GDT_ENTRIES]; | ||
struct gdt_ptr gdt_ptr; | ||
|
||
static void | ||
gdt_set_gate(int32_t num, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran) { | ||
|
||
/* setup the base address */ | ||
gdt_entries[num].base_low = (base & 0xFFFF); | ||
gdt_entries[num].base_middle = (base >> 16) & 0xFF; | ||
gdt_entries[num].base_high = (base >> 24) & 0xFF; | ||
|
||
/* Set up the limits */ | ||
gdt_entries[num].limit_low = (limit & 0xFFFF); | ||
gdt_entries[num].granularity = (limit >> 16) & 0x0F; | ||
|
||
/* Set granularity */ | ||
gdt_entries[num].granularity |= (gran & 0xF0); | ||
|
||
/* Assign access flags */ | ||
gdt_entries[num].access = access; | ||
} | ||
|
||
void | ||
gdt__init(void) | ||
{ | ||
gdt_ptr.limit = (sizeof(struct gdt_entry) * NUM_GDT_ENTRIES) - 1; | ||
gdt_ptr.base = (uintptr_t)&gdt_entries; | ||
|
||
/* NULL */ | ||
gdt_set_gate(0, 0, 0, 0, 0); | ||
|
||
/* Code Segemnt */ | ||
gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); | ||
|
||
/* Data Segemnt */ | ||
gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); | ||
|
||
/* User mode code */ | ||
gdt_set_gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); | ||
|
||
/* User mode data */ | ||
gdt_set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); | ||
|
||
gdt_flush((uintptr_t)&gdt_ptr); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef _GDT_H_ | ||
#define _GDT_H_ | ||
|
||
void gdt__init(void); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.global gdt_flush | ||
gdt_flush: | ||
# Load the GDT | ||
mov 4(%esp), %eax | ||
lgdt (%eax) | ||
mov $0x10, %ax | ||
mov %ax, %ds | ||
mov %ax, %es | ||
mov %ax, %fs | ||
mov %ax, %gs | ||
mov %ax, %ss | ||
ljmp $0x08,$(flush) | ||
flush: | ||
ret | ||
|
||
.global idt_flush | ||
idt_flush: | ||
mov 4(%esp), %eax | ||
lidt (%eax) | ||
ret | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.