Fixed errors in ARM linker. Converted all files to Unix format.

This commit is contained in:
L. Bradley LaBoon 2013-12-06 14:20:46 -05:00
parent 74035befbf
commit bf60ad29f4
8 changed files with 386 additions and 386 deletions

View File

@ -1,34 +1,34 @@
# Build environment # Build environment
PREFIX ?= /home/brad/brados/brados-gcc PREFIX ?= /home/brad/brados/brados-gcc
ARCH ?= i586-elf ARCH ?= i586-elf
GNU ?= $(PREFIX)/$(ARCH)/bin/$(ARCH) GNU ?= $(PREFIX)/$(ARCH)/bin/$(ARCH)
# Source files # Source files
SOURCES_ASM := arch/$(ARCH)/boot.s SOURCES_ASM := arch/$(ARCH)/boot.s
SOURCES_C := driver/video/vga.c kernel/brados.c lib/string.c SOURCES_C := driver/video/vga.c kernel/brados.c lib/string.c
# Object files # Object files
OBJS := $(patsubst %.s,%.o,$(SOURCES_ASM)) OBJS := $(patsubst %.s,%.o,$(SOURCES_ASM))
OBJS += $(patsubst %.c,%.o,$(SOURCES_C)) OBJS += $(patsubst %.c,%.o,$(SOURCES_C))
# Build flags # Build flags
CFLAGS = -std=gnu99 -ffreestanding -Iinclude/ -O2 -Wall -Wextra CFLAGS = -std=gnu99 -ffreestanding -Iinclude/ -O2 -Wall -Wextra
LDFLAGS = -ffreestanding -O2 -nostdlib -lgcc LDFLAGS = -ffreestanding -O2 -nostdlib -lgcc
# Build rules # Build rules
all: brados.bin all: brados.bin
.PHONY: all clean .PHONY: all clean
brados.bin: $(OBJS) arch/$(ARCH)/linker.ld brados.bin: $(OBJS) arch/$(ARCH)/linker.ld
$(GNU)-gcc -T arch/$(ARCH)/linker.ld -o $@ $(LDFLAGS) $(OBJS) $(GNU)-gcc -T arch/$(ARCH)/linker.ld -o $@ $(LDFLAGS) $(OBJS)
clean: clean:
rm -f $(OBJS) brados.bin rm -f $(OBJS) brados.bin
# C # C
%.o: %.c Makefile %.o: %.c Makefile
$(GNU)-gcc -c $< -o $@ $(CFLAGS) $(GNU)-gcc -c $< -o $@ $(CFLAGS)
# Assembly # Assembly
%.o: %.s Makefile %.o: %.s Makefile
$(GNU)-as $< -o $@ $(GNU)-as $< -o $@

View File

@ -1,33 +1,33 @@
.section ".text.boot" .section ".text.boot"
.globl Start .globl Start
Start: Start:
// Setup the stack // Setup the stack
mov sp, #0x8000 mov sp, #0x8000
// Clear out bss // Clear out bss
ldr r4, =_bss_start ldr r4, =_bss_start
ldr r9, =_bss_end ldr r9, =_bss_end
mov r5, #0 mov r5, #0
mov r6, #0 mov r6, #0
mov r7, #0 mov r7, #0
mov r8, #0 mov r8, #0
b 2f b 2f
1: 1:
// Store multiple at r4 // Store multiple at r4
stmia r4!, {r5-r8} stmia r4!, {r5-r8}
2: 2:
// If we are still below bss_end, loop // If we are still below bss_end, loop
cmp r4, r9 cmp r4, r9
blo 1b blo 1b
// Call brados_main // Call brados_main
ldr r3, =brados_main ldr r3, =brados_main
blx r3 blx r3
halt: halt:
// Halt // Halt
wfe wfe
b halt b halt

View File

@ -1,42 +1,42 @@
ENTRY(Start) ENTRY(Start)
SECTIONS SECTIONS
{ {
/* Starts at LOADER_ADDR */ /* Starts at LOADER_ADDR */
. = 0x8000 . = 0x8000;
_start = .; _start = .;
_text_start = .; _text_start = .;
.text: .text :
{ {
KEEP(*(.text.boot)) KEEP(*(.text.boot))
*(.text) *(.text)
} }
. = ALIGN(4096); . = ALIGN(4096);
_text_end = .; _text_end = .;
_rodata_start = .; _rodata_start = .;
.rodata: .rodata :
{ {
*(.rodata) *(.rodata)
} }
. = ALIGN(4096) . = ALIGN(4096);
_rodata_end = .; _rodata_end = .;
_data_start = .; _data_start = .;
.data: .data :
{ {
*(.data) *(.data)
} }
. = ALIGN(4096); . = ALIGN(4096);
_data_end = .; _data_end = .;
_bss_start = .; _bss_start = .;
.bss: .bss :
{ {
bss = .; bss = .;
*(.bss) *(.bss)
} }
. = ALIGN(4096) . = ALIGN(4096);
_bss_end = .; _bss_end = .;
_end = .; _end = .;
} }

View File

@ -1,40 +1,40 @@
# Declare constants for creating a multiboot header # Declare constants for creating a multiboot header
.set ALIGN, 1<<0 .set ALIGN, 1<<0
.set MEMINFO, 1<<1 .set MEMINFO, 1<<1
.set FLAGS, ALIGN | MEMINFO .set FLAGS, ALIGN | MEMINFO
.set MAGIC, 0x1BADB002 .set MAGIC, 0x1BADB002
.set CHECKSUM, -(MAGIC + FLAGS) .set CHECKSUM, -(MAGIC + FLAGS)
# Declare multiboot header # Declare multiboot header
.section .multiboot .section .multiboot
.align 4 .align 4
.long MAGIC .long MAGIC
.long FLAGS .long FLAGS
.long CHECKSUM .long CHECKSUM
# Create a 16 KiB stack # Create a 16 KiB stack
.section .bootstrap_stack .section .bootstrap_stack
stack_bottom: stack_bottom:
.skip 16384 .skip 16384
stack_top: stack_top:
# Kernel entry point # Kernel entry point
.section .text .section .text
.global _start .global _start
.type _start, @function .type _start, @function
_start: _start:
# We are now in kernel mode! # We are now in kernel mode!
# Setup the stack # Setup the stack
movl $stack_top, %esp movl $stack_top, %esp
# Call the main kernel function # Call the main kernel function
call brados_main call brados_main
# In case the function returns, enter an endless loop # In case the function returns, enter an endless loop
cli cli
hlt hlt
.Lhang: .Lhang:
jmp .Lhang jmp .Lhang
# Set the size of the _start symbol for debugging # Set the size of the _start symbol for debugging
.size _start, . - _start .size _start, . - _start

View File

@ -1,38 +1,38 @@
/* Kernel entry point */ /* Kernel entry point */
ENTRY(_start) ENTRY(_start)
/* Define the locations of the object file sections */ /* Define the locations of the object file sections */
SECTIONS SECTIONS
{ {
/* Sections begin at 1 MiB */ /* Sections begin at 1 MiB */
. = 1M; . = 1M;
/* The multiboot header needs to come first, followed by program code */ /* The multiboot header needs to come first, followed by program code */
.text BLOCK(4K) : ALIGN(4K) .text BLOCK(4K) : ALIGN(4K)
{ {
*(.multiboot) *(.multiboot)
*(.text) *(.text)
} }
/* Read-only data */ /* Read-only data */
.rodata BLOCK(4K) : ALIGN(4K) .rodata BLOCK(4K) : ALIGN(4K)
{ {
*(.rodata) *(.rodata)
} }
/* Initialized read-write data */ /* Initialized read-write data */
.data BLOCK(4K) : ALIGN(4K) .data BLOCK(4K) : ALIGN(4K)
{ {
*(.data) *(.data)
} }
/* Uninitialized read-write data and stack */ /* Uninitialized read-write data and stack */
.bss BLOCK(4K) : ALIGN(4K) .bss BLOCK(4K) : ALIGN(4K)
{ {
*(COMMON) *(COMMON)
*(.bss) *(.bss)
*(.bootstrap_stack) *(.bootstrap_stack)
} }
/* Add other sections here */ /* Add other sections here */
} }

View File

@ -1,91 +1,91 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <brados/string.h> #include <brados/string.h>
#include <video/vga.h> #include <video/vga.h>
// Create a VGA color // Create a VGA color
uint8_t make_color(enum vga_color fg, enum vga_color bg) uint8_t make_color(enum vga_color fg, enum vga_color bg)
{ {
return fg | bg << 4; return fg | bg << 4;
} }
// Create a VGA character // Create a VGA character
uint16_t make_vgaEntry(char c, uint8_t color) uint16_t make_vgaEntry(char c, uint8_t color)
{ {
uint16_t c16 = c; uint16_t c16 = c;
uint16_t color16 = color; uint16_t color16 = color;
return c16 | color16 << 8; return c16 | color16 << 8;
} }
// Initialize a VGA term // Initialize a VGA term
void term_init(struct vgastate *state) void term_init(struct vgastate *state)
{ {
state->term_row = state->term_col = 0; state->term_row = state->term_col = 0;
state->term_color = make_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK); state->term_color = make_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK);
state->term_buf = (uint16_t *) VGA_BUF; state->term_buf = (uint16_t *) VGA_BUF;
for (size_t y = 0; y < VGA_HEIGHT; y++) { for (size_t y = 0; y < VGA_HEIGHT; y++) {
for (size_t x = 0; x < VGA_WIDTH; x++) { for (size_t x = 0; x < VGA_WIDTH; x++) {
const size_t index = y * VGA_WIDTH + x; const size_t index = y * VGA_WIDTH + x;
state->term_buf[index] = make_vgaEntry(' ', state->term_color); state->term_buf[index] = make_vgaEntry(' ', state->term_color);
} }
} }
} }
// Write a character to a VGA term // Write a character to a VGA term
void term_putChar(struct vgastate *state, char c) void term_putChar(struct vgastate *state, char c)
{ {
if (c == '\n') if (c == '\n')
state->term_col = VGA_WIDTH - 1; state->term_col = VGA_WIDTH - 1;
else else
term_putEntryAt(state, c, state->term_color, state->term_col, state->term_row); term_putEntryAt(state, c, state->term_color, state->term_col, state->term_row);
if (++state->term_col == VGA_WIDTH) { if (++state->term_col == VGA_WIDTH) {
state->term_col = 0; state->term_col = 0;
if (++state->term_row == VGA_HEIGHT) { if (++state->term_row == VGA_HEIGHT) {
state->term_row--; state->term_row--;
term_scroll(state); term_scroll(state);
} }
} }
} }
// Place a character in a VGA term's buffer // Place a character in a VGA term's buffer
void term_putEntryAt(struct vgastate *state, char c, uint8_t color, size_t x, size_t y) void term_putEntryAt(struct vgastate *state, char c, uint8_t color, size_t x, size_t y)
{ {
const size_t index = y * VGA_WIDTH + x; const size_t index = y * VGA_WIDTH + x;
state->term_buf[index] = make_vgaEntry(c, color); state->term_buf[index] = make_vgaEntry(c, color);
} }
// Scroll the term down 1 line // Scroll the term down 1 line
void term_scroll(struct vgastate *state) void term_scroll(struct vgastate *state)
{ {
// Move each row up // Move each row up
for (size_t y = 1; y < VGA_HEIGHT; y++) { for (size_t y = 1; y < VGA_HEIGHT; y++) {
for (size_t x = 0; x < VGA_WIDTH; x++) { for (size_t x = 0; x < VGA_WIDTH; x++) {
const size_t index = y * VGA_WIDTH + x; const size_t index = y * VGA_WIDTH + x;
const size_t indexBelow = (y - 1) * VGA_WIDTH + x; const size_t indexBelow = (y - 1) * VGA_WIDTH + x;
state->term_buf[indexBelow] = state->term_buf[index]; state->term_buf[indexBelow] = state->term_buf[index];
} }
} }
// Clear the last line // Clear the last line
for (size_t x = 0; x < VGA_WIDTH; x++) { for (size_t x = 0; x < VGA_WIDTH; x++) {
const size_t index = (VGA_HEIGHT - 1) * VGA_WIDTH + x; const size_t index = (VGA_HEIGHT - 1) * VGA_WIDTH + x;
state->term_buf[index] = ' '; state->term_buf[index] = ' ';
} }
} }
// Set VGA term color // Set VGA term color
void term_setColor(struct vgastate *state, uint8_t color) void term_setColor(struct vgastate *state, uint8_t color)
{ {
state->term_color = color; state->term_color = color;
} }
// Write a string to a VGA term // Write a string to a VGA term
void term_writeStr(struct vgastate *state, const char *data) void term_writeStr(struct vgastate *state, const char *data)
{ {
size_t dataLen = strlen(data); size_t dataLen = strlen(data);
for (size_t i = 0; i < dataLen; i++) for (size_t i = 0; i < dataLen; i++)
term_putChar(state, data[i]); term_putChar(state, data[i]);
} }

View File

@ -1,64 +1,64 @@
#ifndef __brados_video_vga_h__ #ifndef __brados_video_vga_h__
#define __brados_video_vga_h__ #define __brados_video_vga_h__
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#define VGA_BUF 0xB8000 #define VGA_BUF 0xB8000
#define VGA_WIDTH 80 #define VGA_WIDTH 80
#define VGA_HEIGHT 24 #define VGA_HEIGHT 24
// VGA State // VGA State
struct vgastate { struct vgastate {
size_t term_row, term_col; size_t term_row, term_col;
uint8_t term_color; uint8_t term_color;
uint16_t *term_buf; uint16_t *term_buf;
}; };
// Color constants // Color constants
enum vga_color enum vga_color
{ {
VGA_COLOR_BLACK = 0, VGA_COLOR_BLACK = 0,
VGA_COLOR_BLUE = 1, VGA_COLOR_BLUE = 1,
VGA_COLOR_GREEN = 2, VGA_COLOR_GREEN = 2,
VGA_COLOR_CYAN = 3, VGA_COLOR_CYAN = 3,
VGA_COLOR_RED = 4, VGA_COLOR_RED = 4,
VGA_COLOR_MAGENTA = 5, VGA_COLOR_MAGENTA = 5,
VGA_COLOR_BROWN = 6, VGA_COLOR_BROWN = 6,
VGA_COLOR_LIGHT_GREY = 7, VGA_COLOR_LIGHT_GREY = 7,
VGA_COLOR_DARK_GREY = 8, VGA_COLOR_DARK_GREY = 8,
VGA_COLOR_LIGHT_BLUE = 9, VGA_COLOR_LIGHT_BLUE = 9,
VGA_COLOR_LIGHT_GREEN = 10, VGA_COLOR_LIGHT_GREEN = 10,
VGA_COLOR_LIGHT_CYAN = 11, VGA_COLOR_LIGHT_CYAN = 11,
VGA_COLOR_LIGHT_RED = 12, VGA_COLOR_LIGHT_RED = 12,
VGA_COLOR_LIGHT_MAGENTA = 13, VGA_COLOR_LIGHT_MAGENTA = 13,
VGA_COLOR_LIGHT_BROWN = 14, VGA_COLOR_LIGHT_BROWN = 14,
VGA_COLOR_WHITE = 15 VGA_COLOR_WHITE = 15
}; };
// Create a VGA color // Create a VGA color
uint8_t make_color(enum vga_color fg, enum vga_color bg); uint8_t make_color(enum vga_color fg, enum vga_color bg);
// Create a VGA character // Create a VGA character
uint16_t make_vgaEntry(char c, uint8_t color); uint16_t make_vgaEntry(char c, uint8_t color);
// Initialize a VGA term // Initialize a VGA term
void term_init(struct vgastate *state); void term_init(struct vgastate *state);
// Write a character to a VGA term // Write a character to a VGA term
void term_putChar(struct vgastate *state, char c); void term_putChar(struct vgastate *state, char c);
// Place a character in a VGA term's buffer // Place a character in a VGA term's buffer
void term_putEntryAt(struct vgastate *state, char c, uint8_t color, size_t x, size_t y); void term_putEntryAt(struct vgastate *state, char c, uint8_t color, size_t x, size_t y);
// Scroll the term down 1 line // Scroll the term down 1 line
void term_scroll(struct vgastate *state); void term_scroll(struct vgastate *state);
// Set VGA term color // Set VGA term color
void term_setColor(struct vgastate *state, uint8_t color); void term_setColor(struct vgastate *state, uint8_t color);
// Write a string to a VGA term // Write a string to a VGA term
void term_writeStr(struct vgastate *state, const char *data); void term_writeStr(struct vgastate *state, const char *data);
#endif #endif

View File

@ -1,44 +1,44 @@
#include <stddef.h> #include <stddef.h>
#include <brados/string.h> #include <brados/string.h>
#include <video/vga.h> #include <video/vga.h>
// Make sure we are using the right compiler // Make sure we are using the right compiler
#if defined(__linux__) #if defined(__linux__)
#error "You are using the wrong compiler." #error "You are using the wrong compiler."
#endif #endif
// Test various VGA functionality // Test various VGA functionality
void vgaTests(struct vgastate *term) void vgaTests(struct vgastate *term)
{ {
// Test line wrapping // Test line wrapping
term_writeStr(term, "Welcome to the desert of the real. I thought what I'd do was I'd pretend I was one of those deaf mutes.\n\n"); term_writeStr(term, "Welcome to the desert of the real. I thought what I'd do was I'd pretend I was one of those deaf mutes.\n\n");
// Test colors // Test colors
term_setColor(term, make_color(VGA_COLOR_BLACK, VGA_COLOR_WHITE)); term_setColor(term, make_color(VGA_COLOR_BLACK, VGA_COLOR_WHITE));
term_writeStr(term, "This text should be inverse.\n"); term_writeStr(term, "This text should be inverse.\n");
term_setColor(term, make_color(VGA_COLOR_LIGHT_BLUE, VGA_COLOR_GREEN)); term_setColor(term, make_color(VGA_COLOR_LIGHT_BLUE, VGA_COLOR_GREEN));
term_writeStr(term, "This text should be colorful.\n\n"); term_writeStr(term, "This text should be colorful.\n\n");
// Test scrolling // Test scrolling
term_setColor(term, make_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK)); term_setColor(term, make_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK));
for (size_t i = 0; i < 20; i++) { for (size_t i = 0; i < 20; i++) {
term_writeStr(term, "Printing some lines.\n"); term_writeStr(term, "Printing some lines.\n");
for (volatile size_t j = 0; j < 100000000; j++); for (volatile size_t j = 0; j < 100000000; j++);
} }
} }
// Main kernel function // Main kernel function
void brados_main() void brados_main()
{ {
struct vgastate term; struct vgastate term;
term_init(&term); term_init(&term);
// Welcome message // Welcome message
term_writeStr(&term, "Welcome to BRaDOS!\n"); term_writeStr(&term, "Welcome to BRaDOS!\n");
term_writeStr(&term, "written by L. Bradley LaBoon\n\n"); term_writeStr(&term, "written by L. Bradley LaBoon\n\n");
vgaTests(&term); vgaTests(&term);
term_writeStr(&term, "Done."); term_writeStr(&term, "Done.");
} }