Skip to content

Commit

Permalink
Fix boot issues, VGA Update
Browse files Browse the repository at this point in the history
- 8x8 VGA Font support
- ISO creation script in makefile
- Remove build artifacts from source tree
- kmain() updates
- parsing of multiboot "debug" cli argument
  • Loading branch information
primis committed Aug 1, 2022
1 parent e9bc9bd commit dd0e3e4
Show file tree
Hide file tree
Showing 40 changed files with 1,026 additions and 180 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- checkout
- run:
name: "Try Compilation"
command: "TARGET=x86 make link"
command: "make link"

# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
Expand Down
6 changes: 6 additions & 0 deletions .config
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ CONFIG_TTY_SERIAL_16550_UART=y
# IRQ Chips
#
CONFIG_IRQCHIP_8259=y
CONFIG_DISPLAY=y

#
# Display Drivers
#
CONFIG_DISPLAY_VGA=y
CONFIG_LIBC=y

#
Expand Down
20 changes: 18 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,25 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.3] - 2022-04-40
## [0.0.4] - 2022-07-30
### Added
- ipxe iso image
- Fancy VGA support (8x8 Font)
- iso creation in makefile
- kmain() Now displays system information
- `debug=y` parsing turns on kernel debugging messages

### Changed
- HAL: `get_num_processors()` now reports 1 as default
- Standardized naming of kernel (always kernel.mod now)
- VGA Console code cleanup
- IDT Triple fault fix

### Removed
- pre-compiled binaries and images from bin/ directory

## [0.0.3] - 2022-04-30
### Added
- ipxe iso image
- Kconfig files
- Modular Makefile system
- Qemu-specific shutdown driver
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.PHONY: all clean link

# Git revision number
GIT_REV != git rev-parse --short HEAD 2> /dev/null
GIT_REV != git rev-parse --short HEAD 2>/dev/null |tr '[:lower:]' '[:upper:]'
BUILD := build

# Documentation
Expand All @@ -21,6 +21,7 @@ INCLUDEDIR != find src -type d -name "include" -printf "-I%p "
include .config
TARGETL != echo $(CONFIG_TARGET) | tr '[:upper:]' '[:lower:]'
BUILD := build-$(TARGETL)
BIN := kernel.mod
include $(shell pwd)/scripts/target-$(TARGETL).mk

WARNINGS := -Wall -Wextra -Wno-unused-parameter
Expand Down Expand Up @@ -54,10 +55,11 @@ $(BUILD)/%.c.o: %.c Makefile | setup_builddir
link: $(OBJECTS)
@printf "\033[1mLINK\033[0m $@\n"
@$(CC) $(DEFS) $(WARNINGS) $(LDFLAGS) $(TARGET_LDFLAGS) \
-o bin/$(BIN) $(OBJECTS)
-o $(BUILD)/apollo/$(BIN) $(OBJECTS)

setup_builddir:
@mkdir -p $(BUILD)
@mkdir -p $(BUILD)/apollo
@cd $(BUILD) && mkdir -p `echo $(SRCDIR)`

clean:
Expand All @@ -78,3 +80,5 @@ html/%.html: docs/%.md
menuconfig:
@kconfig-mconf Kconfig

iso:
@cd $(BUILD) && ../scripts/isocreate.sh
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ This is a kernel project for x86 Hardware. Current compilation needs:
* GNU Make (Or Compatible)
* NASM, The Netwide Assembler
* GCC (cross compiler heavily suggested, such as i586-elf-gcc)
* grub-mkrescue (To generate a bootable ISO)

Optionally, for customizing builds, any application capable of reading Kconfig
files will work. If on debian based systems, the package `kconfig-frontends` is suggested.
files will work. If on debian based systems, the package `kconfig-frontends`
is suggested.

The kernel is written in X86-Assembly and ANSI-C. We are currently working
on making it as portable as possible.
Expand All @@ -32,21 +34,21 @@ removed without notice.

Running
=================================================
The best way to run latest is to use the ipxe images.
These should work on any VM/PC with a network card and
will load the latest kernel from kernel.primis.org
You can also load x86-sys.mod from any multiboot
compatible bootloader such as GRUB.
To run the kernel, any multiboot compatible bootloader will work.
An ISO is available in releases which is bootable as well.

Building
=================================================
Once all the pre-requisites software has been aquired,
you can build a kernel simply by typing `make`. The make
you can build a kernel simply by typing `make all`. The make
file defaults to x86 with most of the features set.
To customize features you can either directly edit the
`.config` file in the root directory of the project, or
you can run `make menuconfig` if you have `kconfig-frontends`
or it's equivilent package installed on your distro.
An ISO file can be generated by running `make iso` after
compilation has been completed. The iso will be placed inside
the build directory.

History:
=================================================
Expand Down
3 changes: 0 additions & 3 deletions bin/.gitattributes

This file was deleted.

17 changes: 0 additions & 17 deletions bin/boot.php

This file was deleted.

3 changes: 0 additions & 3 deletions bin/floppy.img

This file was deleted.

3 changes: 0 additions & 3 deletions bin/hosted-sys.mod

This file was deleted.

3 changes: 0 additions & 3 deletions bin/ipxe.dsk

This file was deleted.

Binary file removed bin/ipxe.iso
Binary file not shown.
3 changes: 0 additions & 3 deletions bin/test-hosted-sys.mod

This file was deleted.

3 changes: 0 additions & 3 deletions bin/test-x86-sys.mod

This file was deleted.

27 changes: 0 additions & 27 deletions bin/update-floppy.sh

This file was deleted.

3 changes: 0 additions & 3 deletions bin/x86-sys.mod

This file was deleted.

19 changes: 19 additions & 0 deletions scripts/isocreate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

set -e

mkdir -p isodir/boot/grub

cp apollo/kernel.mod isodir/boot/kernel.mod

cat > isodir/boot/grub/grub.cfg << EOF
menuentry "Apollo" {
multiboot /boot/kernel.mod
}
menuentry "Apollo Debugging" {
multiboot /boot/kernel.mod debug=y
}
EOF

grub-mkrescue -o apollo.iso isodir
1 change: 0 additions & 1 deletion scripts/target-hosted.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Hosted Makefile for doing testing on hosted systems

BIN := hosted-sys.mod
TARGET_DEFS := -DHOSTED=1

# That's it!
3 changes: 1 addition & 2 deletions scripts/target-x86.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ TARGET_LDFLAGS := -m32 -Tsrc/arch/x86/x86-link.ld -nostdlib -n
$(warning Using default GCC, please consider installing a cross compiler!)
endif

BIN := x86-sys.mod
AS := nasm
ASFLAGS := -felf -dGITREV="'$(GIT_REV)'"
TARGET_DEFS := -DX86=1 -m32 -masm=intel -ffreestanding -nostdlib
TARGET_DEFS := -DX86=1 -m32 -masm=intel -ffreestanding -nostdlib
TARGET_LDFLAGS ?= -m32 -Tsrc/arch/x86/x86-link.ld -nostdlib -lgcc -n

$(BUILD)/%.s.o: %.s | setup_builddir
Expand Down
2 changes: 1 addition & 1 deletion src/arch/x86/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

obj_$(CONFIG_X86_BASE) := start.s multiboot.s
obj_$(CONFIG_X86_BASE) += bringup.c ports.c
obj_$(CONFIG_X86_BASE) += idt.c irq.c ivt.s
obj_$(CONFIG_X86_BASE) += idt.c ivt.s irq.c
obj_$(CONFIG_X86_BASE) += gdt.c
obj_$(CONFIG_X86_BASE) += free_memory.c vmm.c
39 changes: 27 additions & 12 deletions src/arch/x86/free_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
#include <stdio.h>
extern multiboot_info_t mboot;

#define MBOOT_IS_MMAP_TYPE_RAM(x) (x == 1)
#define MBOOT_IS_MMAP_TYPE_RAM(x) (x == MULTIBOOT_MEMORY_AVAILABLE)
#define MBOOT_MEM (1<<0)
#define MBOOT_MMAP (1<<6)

static uint32_t total_megabytes;

static void remove_range(range_t *r, uint32_t start, uint32_t end)
{
// TODO: Stop assuming that a range exists which starts at 'start' and
Expand All @@ -25,13 +27,22 @@ static void remove_range(range_t *r, uint32_t start, uint32_t end)
}
}

static char* memtype[] = {
"Not Available",
"Available",
"Reserved",
"ACPI Reclaimable",
"NVS",
"Bad Ram"
};

static int free_memory()
{
extern uint32_t __start, __end; // Provided by linker

// Store ranges in easy format, instead of multiboot
range_t ranges[128], ranges_cpy[128];
uint32_t i;
uint32_t i = 0;
unsigned n = 0;
uint64_t extent = 0;
multiboot_memory_map_t *entry;
Expand All @@ -49,6 +60,12 @@ static int free_memory()
break;
}

// Check for a non-sensical MMAP Type, assume that they're RAM
if(entry->type > 5)
{
entry->type = MULTIBOOT_MEMORY_AVAILABLE;
}

// Is this ram? (Only ram is useful for us)
if (MBOOT_IS_MMAP_TYPE_RAM(entry->type)) {
// Make note of start and length of the range, then increment n.
Expand All @@ -60,26 +77,19 @@ static int free_memory()
extent = entry->addr + entry->len;
}
}
i++;
}

// __end is size of our kernel from ld, we add some flags to it.
uint32_t end = (((uint32_t)&__end) & ~get_page_mask()) + get_page_size();

total_megabytes = 0;
// Run over the ranges, one of them has our kernel in it and shouldn't be
// Marked as free (as our kernel would be overridden)
for (i = 0; i < n; i++)
{
remove_range(&ranges[i], (uint32_t)&__start, end);
uint32_t gigs = ((uint32_t)ranges[i].extent / 0x40000000);
uint32_t megs = ((uint32_t)ranges[i].extent / 0x100000);
uint32_t kilos = ((uint32_t)ranges[i].extent / 0x400);
if (gigs > 0) {
printf("\tFound %d GB at Address 0x%x\n", gigs, ranges[i].start);
} else if(megs > 0) {
printf("\tFound %d MB at Address 0x%x\n", megs, ranges[i].start);
} else {
printf("\tFound %d KB at Address 0x%x\n", kilos, ranges[i].start);
}
total_megabytes += megs;
}

// Copy the ranges to a backup, as init_physical_memory mutates them and
Expand All @@ -95,6 +105,11 @@ static int free_memory()
return 0;
}

uint32_t free_memory_get_megs()
{
return total_megabytes;
}

MODULE = {
.name = "x86/free_memory",
.required = NULL,
Expand Down
3 changes: 1 addition & 2 deletions src/arch/x86/gdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
* arch/x86/gdt.c - GDT & TSS
*/


#include <sys/hal.h>
#include <arch/x86/gdt.h>
#include <stdio.h>
#include <string.h>

#include "include/gdt.h"

static gdt_ptr_t gdt_ptr;
static gdt_entry_t entries[MAX_CORES+5];
Expand Down
Loading

0 comments on commit dd0e3e4

Please sign in to comment.