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...
This commit is contained in:
parent
26586447f5
commit
b01480d361
|
@ -19,6 +19,7 @@ stack_top:
|
|||
.section .text
|
||||
.global _start
|
||||
.type _start, @function
|
||||
|
||||
_start:
|
||||
movl $stack_top, %esp
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
.section .init
|
||||
.global _init
|
||||
|
||||
.type _init, @function
|
||||
|
||||
_init:
|
||||
|
@ -13,4 +12,4 @@ _init:
|
|||
|
||||
_fini:
|
||||
push %ebp
|
||||
movl %esp, %ebp
|
||||
movl %esp, %ebp
|
||||
|
|
|
@ -4,4 +4,4 @@
|
|||
|
||||
.section .fini
|
||||
popl %ebp
|
||||
ret
|
||||
ret
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
ENTRY(_start)
|
||||
|
||||
SECTIONS
|
||||
|
@ -16,7 +17,7 @@ SECTIONS
|
|||
*(.rodata)
|
||||
}
|
||||
|
||||
.data BLOCK(4K : ALIGN(4K)
|
||||
.data BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.data)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,6 @@ KERNEL_ARCH_CPPFLAGS=
|
|||
KERNEL_ARCH_LDFLAGS=
|
||||
KERNEL_ARCH_LIBS=
|
||||
|
||||
KERNEL_ARCH_OBKS=\
|
||||
$(ARCHDIR)/boot.o\
|
||||
$(ARCHDIR)/tty.o\
|
||||
KERNEL_ARCH_OBJS= \
|
||||
$(ARCHDIR)/boot.o \
|
||||
$(ARCHDIR)/tty.o
|
|
@ -4,7 +4,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include <kernel/tty.h>
|
||||
#include "vga.h"
|
||||
#include <kernel/utils.h>
|
||||
|
||||
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
|
||||
}
|
|
@ -1,14 +1,15 @@
|
|||
#ifndef _KERNEL_TTY_H
|
||||
#define _KERNEL_TTY_H
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <vga.h>
|
||||
|
||||
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*);
|
||||
|
|
5
include/kernel/utils.h
Executable file
5
include/kernel/utils.h
Executable file
|
@ -0,0 +1,5 @@
|
|||
#include <stddef.h>
|
||||
|
||||
/* A temporary file, to get the system compiling. */
|
||||
|
||||
size_t strlen(const char*);
|
|
@ -1,5 +1,4 @@
|
|||
#ifndef ARCH_I386_VGA_H
|
||||
#define ARCH_I386_VGA_H
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
@ -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
|
|
@ -1,5 +1,6 @@
|
|||
#include <stdio.h>
|
||||
#include <kernel/tty.h>
|
||||
//#include <stdio.h>
|
||||
|
||||
#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(;;) {}
|
||||
|
|
8
kernel/utils.c
Executable file
8
kernel/utils.c
Executable file
|
@ -0,0 +1,8 @@
|
|||
#include <stddef.h>
|
||||
|
||||
size_t strlen(const char* string) {
|
||||
size_t size = 0;
|
||||
while (string[size])
|
||||
size++;
|
||||
return size;
|
||||
}
|
18
makefile
18
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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user