From b01480d3617b3d524634fd3acca9b7b526db4f9d Mon Sep 17 00:00:00 2001 From: Jenny Curle Date: Mon, 1 Apr 2019 12:21:00 +0100 Subject: [PATCH] Initial update - fixed broken files, dependencies on outside libraries, \nThe system will now compile under 'make all', and no errors are thrown.\nThe system itself hasn't been tested, yet. Here goes... --- arch/i386/boot.s | 1 + arch/i386/crti.s | 3 +-- arch/i386/crtn.s | 2 +- arch/i386/linker.ld | 3 ++- arch/i386/make.config | 6 +++--- arch/i386/tty.c | 36 +++++++++++++++++++++++++++++++----- include/kernel/tty.h | 9 +++++---- include/kernel/utils.h | 5 +++++ include/{kernel => }/vga.h | 7 ++----- kernel/kernel.c | 11 ++++++----- kernel/utils.c | 8 ++++++++ makefile | 18 ++++++++++-------- 12 files changed, 75 insertions(+), 34 deletions(-) create mode 100755 include/kernel/utils.h rename include/{kernel => }/vga.h (72%) create mode 100755 kernel/utils.c diff --git a/arch/i386/boot.s b/arch/i386/boot.s index 7220deb..5504693 100755 --- a/arch/i386/boot.s +++ b/arch/i386/boot.s @@ -19,6 +19,7 @@ stack_top: .section .text .global _start .type _start, @function + _start: movl $stack_top, %esp diff --git a/arch/i386/crti.s b/arch/i386/crti.s index 25c5732..23c4507 100755 --- a/arch/i386/crti.s +++ b/arch/i386/crti.s @@ -1,6 +1,5 @@ .section .init .global _init - .type _init, @function _init: @@ -13,4 +12,4 @@ _init: _fini: push %ebp - movl %esp, %ebp \ No newline at end of file + movl %esp, %ebp diff --git a/arch/i386/crtn.s b/arch/i386/crtn.s index 38dd18e..430f1ce 100755 --- a/arch/i386/crtn.s +++ b/arch/i386/crtn.s @@ -4,4 +4,4 @@ .section .fini popl %ebp - ret \ No newline at end of file + ret diff --git a/arch/i386/linker.ld b/arch/i386/linker.ld index 1def46f..6fe18ab 100755 --- a/arch/i386/linker.ld +++ b/arch/i386/linker.ld @@ -1,3 +1,4 @@ + ENTRY(_start) SECTIONS @@ -16,7 +17,7 @@ SECTIONS *(.rodata) } - .data BLOCK(4K : ALIGN(4K) + .data BLOCK(4K) : ALIGN(4K) { *(.data) } diff --git a/arch/i386/make.config b/arch/i386/make.config index 96463ac..44f0c86 100755 --- a/arch/i386/make.config +++ b/arch/i386/make.config @@ -3,6 +3,6 @@ KERNEL_ARCH_CPPFLAGS= KERNEL_ARCH_LDFLAGS= KERNEL_ARCH_LIBS= -KERNEL_ARCH_OBKS=\ -$(ARCHDIR)/boot.o\ -$(ARCHDIR)/tty.o\ \ No newline at end of file +KERNEL_ARCH_OBJS= \ +$(ARCHDIR)/boot.o \ +$(ARCHDIR)/tty.o \ No newline at end of file diff --git a/arch/i386/tty.c b/arch/i386/tty.c index df9989b..a1b5663 100755 --- a/arch/i386/tty.c +++ b/arch/i386/tty.c @@ -4,7 +4,7 @@ #include #include -#include "vga.h" +#include static const size_t TERM_WIDTH=80; static const size_t TERM_HEIGHT=25; @@ -14,10 +14,10 @@ static size_t terminal_column; static uint8_t current_color; static uint16_t* term_buffer; +static uint16_t* const vga_buffer = (uint16_t*) 0xB8000; void screen_initialize(void) { - static uint16_t* const vga_buffer = (uint16_t*) 0xB8000; terminal_row = 0; terminal_column = 0; current_color = vga_color_set(LIGHT_GREY, BLACK); @@ -35,7 +35,7 @@ void term_setcolor(enum vga_colors color) { current_color = color; } -void term_putentryat (unsigned char c, uint8_t color, size_t x, size_t y) { +void term_putentryat (char c, uint8_t color, size_t x, size_t y) { const size_t offset = y * TERM_WIDTH + x; term_buffer[offset] = vga_entry(c, color); } @@ -45,11 +45,13 @@ void term_putchar(char c) { term_putentryat(uc, current_color, terminal_column, terminal_row); if(++terminal_column == TERM_WIDTH) + { terminal_column = 0; if(++terminal_row == TERM_HEIGHT){ term_scroll(); terminal_row = 0; } + } } void term_write(const char* data, size_t size) { @@ -57,6 +59,30 @@ void term_write(const char* data, size_t size) { term_putchar(data[i]); } -void puts(const char* string) { - term_write(string + "\n", strlen(string)); +void puts(const char* string) { + term_write(string, strlen(string)); + term_putchar('\n'); +} + +void term_scroll() { + int current_pos = 160; //Start of the second line. + + unsigned char* term_buffer = (unsigned char*) vga_buffer; + + while (current_pos <= 4000) { + term_buffer[current_pos - 160 /*The character immediately below it*/] = vga_buffer[current_pos]; //Move each character up a line + term_buffer[current_pos - 159 /*The color of the character below*/] = vga_buffer[current_pos + 1]; //As well as its color + current_pos += 2; //Move to next char + } + + current_pos = 3840; //Start of the last line + int i; //Offset for framebuffer + //Wipe out the bottom line + for(i = 1920; i <= 2000; i++) { + term_buffer[current_pos] = 0; + current_pos += 2; + } + + i = 3840; + terminal_row = 24; //Prepare the screen to scroll } \ No newline at end of file diff --git a/include/kernel/tty.h b/include/kernel/tty.h index 121c20b..19881bb 100755 --- a/include/kernel/tty.h +++ b/include/kernel/tty.h @@ -1,14 +1,15 @@ -#ifndef _KERNEL_TTY_H -#define _KERNEL_TTY_H +#pragma once #include +#include +#include void term_setcolor(enum vga_colors); void screen_initialize(void); void term_putentryat(char, uint8_t, size_t, size_t); void term_putchar(char); -void term_write(char, size_t); -void puts(char); +void term_write(const char*, size_t); +void puts(const char*); void set_cursor(int, int); void term_scroll(void); void int_to_ascii(int, char*); diff --git a/include/kernel/utils.h b/include/kernel/utils.h new file mode 100755 index 0000000..eb23480 --- /dev/null +++ b/include/kernel/utils.h @@ -0,0 +1,5 @@ +#include + +/* A temporary file, to get the system compiling. */ + +size_t strlen(const char*); \ No newline at end of file diff --git a/include/kernel/vga.h b/include/vga.h similarity index 72% rename from include/kernel/vga.h rename to include/vga.h index 6f82f38..f69ba70 100755 --- a/include/kernel/vga.h +++ b/include/vga.h @@ -1,5 +1,4 @@ -#ifndef ARCH_I386_VGA_H -#define ARCH_I386_VGA_H +#pragma once #include @@ -23,12 +22,10 @@ enum vga_colors { WHITE = 15 }; -static inline uint8_t vga_color_set(enum vga_color fg, enum vga_color bg) { +static inline uint8_t vga_color_set(enum vga_colors fg, enum vga_colors bg) { return fg | bg << 4; } static inline uint16_t vga_entry(unsigned char uc, uint8_t color) { return (uint16_t) uc | (uint16_t) color << 8; } - -#endif \ No newline at end of file diff --git a/kernel/kernel.c b/kernel/kernel.c index 897096e..45470f0 100755 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,5 +1,6 @@ -#include -#include +//#include + +#include "kernel/tty.h" int kernel_main(void) { //Prepare the screen, and blank it out. @@ -7,11 +8,11 @@ int kernel_main(void) { //Print a copyright message. puts("(c)"); - set_screen_text_color(GREEN); + term_setcolor(GREEN); puts(" Project"); - set_screen_text_color(RED); + term_setcolor(RED); puts("RED"); - set_screen_text_color(WHITE); + term_setcolor(WHITE); puts(", 2019\n"); for(;;) {} diff --git a/kernel/utils.c b/kernel/utils.c new file mode 100755 index 0000000..739d608 --- /dev/null +++ b/kernel/utils.c @@ -0,0 +1,8 @@ +#include + +size_t strlen(const char* string) { + size_t size = 0; + while (string[size]) + size++; + return size; +} \ No newline at end of file diff --git a/makefile b/makefile index 8796645..efe639d 100755 --- a/makefile +++ b/makefile @@ -1,6 +1,6 @@ -DEFAULT_HOST!=../default-host.sh +DEFAULT_HOST:=i686-elf HOST?=DEFAULT_HOST -HOSTARCH!=../target_to_arch.sh $(HOST) +HOSTARCH:=i386 CFLAGS?= -O2 -g CPPFLAGS?= @@ -16,7 +16,7 @@ INCLUDEDIR?=$(PREFIX)/include CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra CPPFLAGS:=$(CPPFLAGS) -D__is_kernel -Iinclude LDFLAGS:=$(LDFLAGS) -LIBS:=$(LIBS) -nostdlib -lk -lgcc +LIBS:=$(LIBS) -nostdlib -lgcc ARCHDIR=arch/$(HOSTARCH) @@ -27,9 +27,10 @@ CPPFLAGS:=$(CPPFLAGS) $(KERNEL_ARCH_CPPFLAGS) LDFLAGS:=$(LDFLAGS) $(KERNEL_ARCH_LDFLAGS) LIBS:=$(LIBS) $(KERNEL_ARCH_LIBS) -KERNEL_OBJS=\ -$(KERNEL_ARCH_OBJS)\ -kernel/kernel.o +KERNEL_OBJS= \ +$(KERNEL_ARCH_OBJS) \ +kernel/utils.o \ +kernel/kernel.o OBJS=\ $(ARCHDIR)/crti.o \ @@ -59,13 +60,13 @@ $(ARCHDIR)/crtbegin.o $(ARCHDIR)/crtend.o: OBJ=`$(CC) $(CFLAGS) $(LDFLAGS) -print-file-name=$(@F)` && cp "$$OBJ" $@ .c.o: - $(CC) -MD -c $< -o $@ -std=gnull $(CFLAGS) $(CPPFLAGS) + $(CC) -MD -c $< -o $@ -std=gnu11 $(CFLAGS) $(CPPFLAGS) .s.o: $(CC) -MD -c $< -o $@ $(CFLAGS) $(CPPFLAGS) clean: rm -f red.kernel - rm -f $(OBJS) *.0 */*.o */*/*.o + rm -f $(OBJS) *.o */*.o */*/*.o rm -f $(OBJS:.o=.d) *.d */*.d */*/*.d install: install-headers install-kernel gen-iso @@ -92,3 +93,4 @@ gen-iso: iso -include $(OBJS:.o=.d) +