Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

Commit

Permalink
Cleanup, prep for upstream merge
Browse files Browse the repository at this point in the history
  • Loading branch information
klange committed May 30, 2021
1 parent bb61177 commit b871a54
Show file tree
Hide file tree
Showing 19 changed files with 143 additions and 147 deletions.
Binary file modified apps/terminal-font.h
Binary file not shown.
1 change: 0 additions & 1 deletion base/usr/include/kernel/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ static inline uint32_t pci_box_device(int bus, int slot, int func) {
uint32_t pci_read_field(uint32_t device, int field, int size);
void pci_write_field(uint32_t device, int field, int size, uint32_t value);
uint16_t pci_find_type(uint32_t dev);
void pci_scan_hit(pci_func_t f, uint32_t dev, void * extra);
void pci_scan_func(pci_func_t f, int type, int bus, int slot, int func, void * extra);
void pci_scan_slot(pci_func_t f, int type, int bus, int slot, void * extra);
void pci_scan_bus(pci_func_t f, int type, int bus, void * extra);
Expand Down
1 change: 0 additions & 1 deletion base/usr/include/kernel/symboltable.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ typedef struct {
char name[];
} kernel_symbol_t;

extern void (* symbol_find(const char * name))(void);

6 changes: 5 additions & 1 deletion kernel/arch/x86_64/cmos.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
* @file kernel/arch/x86_64/cmos.c
* @author K. Lange
* @brief Real-time clock.
*
* Provides access to the CMOS RTC for initial boot time and
* calibrates the TSC to use as a general timing source. IRQ 0
* handler is also in here because it updates the wall clock time
* and triggers timeout-based wakeups.
*/

#include <kernel/printf.h>
#include <kernel/string.h>
#include <kernel/process.h>
Expand Down
15 changes: 9 additions & 6 deletions kernel/arch/x86_64/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ extern char end[];

extern void gdt_install(void);
extern void idt_install(void);
extern void pic_initialize(void);
extern void pit_initialize(void);
extern void acpi_initialize(void);
extern void smp_initialize(void);
extern void portio_initialize(void);
extern void ps2hid_install(void);
extern void serial_initialize(void);
Expand Down Expand Up @@ -62,9 +63,9 @@ static void multiboot_initialize(struct multiboot * mboot) {
memCount = (uintptr_t)mboot->mem_upper * 0x400 + 0x100000;
}

/* Check mmap if available */
#if 0
/* The multiboot 0.6.96 spec actually says the upper_memory is at most
/**
* FIXME:
* The multiboot 0.6.96 spec actually says the upper_memory is at most
* the address of the first hole, minus 1MiB, so in theory there should
* not be any unavailable memory between 1MiB and mem_upper... that
* also technically means there might be even higher memory above that
Expand All @@ -75,6 +76,7 @@ static void multiboot_initialize(struct multiboot * mboot) {
* mem_upper is probably the total available physical RAM. That's probably
* good enough for 1GiB~4GiB cases...
*/
#if 0
printf("mem_upper = %#zx\n", mboot->mem_upper);
if (mboot->flags & MULTIBOOT_FLAG_MMAP) {
mboot_memmap_t * mmap = (void *)(uintptr_t)mboot->mmap_addr;
Expand Down Expand Up @@ -228,7 +230,7 @@ const char * arch_get_loader(void) {
}

/**
* x86-64: The GS register, which is set by a pair of MSRs, tracks kernel stack.
* x86-64: The GS register, which is set by a pair of MSRs, tracks per-CPU kernel state.
*/
void arch_set_core_base(uintptr_t base) {
asm volatile ("wrmsr" : : "c"(0xc0000101), "d"((uint32_t)(base >> 32)), "a"((uint32_t)(base & 0xFFFFFFFF)));
Expand Down Expand Up @@ -267,6 +269,7 @@ int kmain(struct multiboot * mboot, uint32_t mboot_mag, void* esp) {
gdt_install();
idt_install();
fpu_initialize();
pic_initialize();

/* Early generic stuff */
generic_startup();
Expand All @@ -281,7 +284,7 @@ int kmain(struct multiboot * mboot, uint32_t mboot_mag, void* esp) {
framebuffer_initialize();
fbterm_initialize();

acpi_initialize();
smp_initialize();

/* Decompress and mount all initial ramdisks. */
mount_multiboot_ramdisks(mboot);
Expand Down
40 changes: 6 additions & 34 deletions kernel/arch/x86_64/timer.c → kernel/arch/x86_64/pic.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @file kernel/arch/x86_64/pic.c
* @brief Legacy PIC support.
*/
#include <kernel/printf.h>
#include <kernel/process.h>
#include <kernel/arch/x86_64/ports.h>
Expand Down Expand Up @@ -54,39 +58,7 @@ void irq_ack(size_t irq_no) {
outportb(PIC1_COMMAND, PIC_EOI);
}


/* Programmable interval timer */
#define PIT_A 0x40
#define PIT_B 0x41
#define PIT_C 0x42
#define PIT_CONTROL 0x43

#define PIT_MASK 0xFF
#define PIT_SCALE 1193180
#define PIT_SET 0x34

#define TIMER_IRQ 0

#define RESYNC_TIME 1

static void pit_set_timer_phase(long hz) {
long divisor = PIT_SCALE / hz;
outportb(PIT_CONTROL, PIT_SET);
outportb(PIT_A, divisor & PIT_MASK);
outportb(PIT_A, (divisor >> 8) & PIT_MASK);
}

extern int cmos_time_stuff(struct regs *r);

void pit_initialize(void) {
void pic_initialize(void) {
irq_remap();

irq_install_handler(TIMER_IRQ, cmos_time_stuff, "pit timer");

/* ELCR? */
uint8_t val = inportb(0x4D1);
outportb(0x4D1, val | (1 << (10-8)) | (1 << (11-8)));

/* Enable PIT */
pit_set_timer_phase(100); /* 1000 Hz */
}

39 changes: 39 additions & 0 deletions kernel/arch/x86_64/pit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <kernel/printf.h>
#include <kernel/process.h>
#include <kernel/arch/x86_64/ports.h>
#include <kernel/arch/x86_64/irq.h>
#include <kernel/arch/x86_64/regs.h>

/* Programmable interval timer */
#define PIT_A 0x40
#define PIT_B 0x41
#define PIT_C 0x42
#define PIT_CONTROL 0x43

#define PIT_MASK 0xFF
#define PIT_SCALE 1193180
#define PIT_SET 0x34

#define TIMER_IRQ 0

#define RESYNC_TIME 1

static void pit_set_timer_phase(long hz) {
long divisor = PIT_SCALE / hz;
outportb(PIT_CONTROL, PIT_SET);
outportb(PIT_A, divisor & PIT_MASK);
outportb(PIT_A, (divisor >> 8) & PIT_MASK);
}

extern int cmos_time_stuff(struct regs *r);

void pit_initialize(void) {
irq_install_handler(TIMER_IRQ, cmos_time_stuff, "pit timer");

/* ELCR? */
uint8_t val = inportb(0x4D1);
outportb(0x4D1, val | (1 << (10-8)) | (1 << (11-8)));

/* Enable PIT */
pit_set_timer_phase(100); /* 1000 Hz */
}
4 changes: 4 additions & 0 deletions kernel/arch/x86_64/ports.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @file kernel/arch/x86_64/ports.c
* @brief Port I/O methods for x86-64.
*/
#include <kernel/types.h>

unsigned short inports(unsigned short _port) {
Expand Down
6 changes: 2 additions & 4 deletions kernel/arch/x86_64/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@
* Attaches serial ports to TTY interfaces. Serial input processing
* happens in a kernel tasklet so that blocking is handled smoothly.
*
* FIXME This needs to be adapted to an irq chaining API when one
* is built for Misaka.
*
* @copyright
* This file is part of ToaruOS and is released under the terms
* of the NCSA / University of Illinois License - see LICENSE.md
* Copyright (C) 2014-2021 K. Lange
*/

#include <kernel/string.h>
#include <kernel/types.h>
#include <kernel/vfs.h>
Expand Down Expand Up @@ -90,6 +86,8 @@ static void process_serial(void * argp) {
pty = *pty_for_port(port);
tty_input_process(pty, ch);
next = serial_rcvd(port);
/* TODO: Can we handle more than one character here
* before yielding? Would that be helpful? */
if (next) switch_task(1);
} while (next);
}
Expand Down
18 changes: 12 additions & 6 deletions kernel/arch/x86_64/acpi.c → kernel/arch/x86_64/smp.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @file kernel/arch/x86_64/smp.c
* @brief Multi-processor Support for x86-64.
*
* Locates and bootstraps APs using ACPI MADT tables.
*/
#include <stdint.h>
#include <kernel/string.h>
#include <kernel/process.h>
Expand Down Expand Up @@ -106,7 +112,7 @@ void ap_main(void) {
uint32_t ebx, _unused;
cpuid(0x1,_unused,ebx,_unused,_unused);
if (this_core->lapic_id != (int)(ebx >> 24)) {
printf("acpi: lapic id does not match\n");
printf("smp: lapic id does not match\n");
}

/* Load the IDT */
Expand Down Expand Up @@ -178,8 +184,8 @@ void lapic_send_ipi(int i, uint32_t val) {
do { asm volatile ("pause" : : : "memory"); } while (lapic_read(0x300) & (1 << 12));
}

void acpi_initialize(void) {
/* ACPI */
void smp_initialize(void) {
/* Locate ACPI tables */
uintptr_t scan;
int good = 0;
for (scan = 0x000E0000; scan < 0x00100000; scan += 16) {
Expand All @@ -199,7 +205,7 @@ void acpi_initialize(void) {
load_processor_info();

if (!good) {
printf("acpi: No RSD PTR found\n");
printf("smp: No RSD PTR found\n");
return;
}

Expand All @@ -210,7 +216,7 @@ void acpi_initialize(void) {
check += *tmp;
}
if (check != 0) {
printf("acpi: Bad checksum on RSDP\n");
printf("smp: Bad checksum on RSDP\n");
return; /* bad checksum */
}

Expand All @@ -236,7 +242,7 @@ void acpi_initialize(void) {
processor_local_data[cores].lapic_id = entry[3];
cores++;
if (cores == 33) {
printf("acpi: too many cores\n");
printf("smp: too many cores\n");
arch_fatal();
}
}
Expand Down
4 changes: 4 additions & 0 deletions kernel/arch/x86_64/user.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @file kernel/arch/x86_64/user.c
* @brief Various assembly snippets for jumping to usermode and back.
*/
#include <stdint.h>
#include <kernel/process.h>
#include <kernel/string.h>
Expand Down
16 changes: 0 additions & 16 deletions kernel/arch/x86_64/vbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,23 +257,10 @@ uint64_t write_rectpipe(fs_node_t *node, uint64_t offset, uint64_t size, uint8_t

if (count > 254) count = 254; /* enforce maximum */

#if 0
fprintf(&vb, "Writing %d rectangles\n", count);
#endif

buffer += sizeof(uint32_t);

for (unsigned int i = 0; i < count; ++i) {
memcpy(&vbox_visibleregion->rect[i], buffer, sizeof(struct vbox_rtrect));
#if 0
fprintf(&vb, "Rectangle %d is [%d,%d,%d,%d]\n",
i,
vbox_visibleregion->rect[i].xLeft,
vbox_visibleregion->rect[i].yTop,
vbox_visibleregion->rect[i].xRight,
vbox_visibleregion->rect[i].yBottom);
#endif

buffer += sizeof(struct vbox_rtrect);
}

Expand All @@ -293,12 +280,9 @@ void vbox_initialize(void) {
pci_scan(vbox_scan_pci, -1, &vbox_device);

if (vbox_device) {
//fprintf(&vb, "VirtualBox host detected, switching log to VirtualBox.\n");

if (!args_present("novboxdebug")) {
vbox_set_log();
}
//fprintf(&vb, "HELLO WORLD\n");

uintptr_t t = pci_read_field(vbox_device, PCI_BAR0, 4);
if (t > 0) {
Expand Down
8 changes: 2 additions & 6 deletions kernel/misc/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ hashmap_t * kernel_args_map = NULL;
* so the caller should check whether it is correctly set.
*/
int args_present(const char * karg) {
if (!kernel_args_map) return 0; /* derp */

if (!kernel_args_map) return 0;
return hashmap_has(kernel_args_map, karg);
}

/**
* @brief Return the value associated with an argument provided to the kernel.
*/
char * args_value(const char * karg) {
if (!kernel_args_map) return 0; /* derp */

if (!kernel_args_map) return 0;
return hashmap_get(kernel_args_map, karg);
}

Expand All @@ -54,7 +52,6 @@ void args_parse(const char * _arg) {
int argc = tokenize(arg, " ", argv);

/* New let's parse the tokens into the arguments list so we can index by key */

if (!kernel_args_map) {
kernel_args_map = hashmap_create(10);
}
Expand Down Expand Up @@ -84,6 +81,5 @@ void args_parse(const char * _arg) {
}

free(arg);

}

2 changes: 1 addition & 1 deletion kernel/misc/fbterm.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern uint32_t lfb_resolution_s;
extern size_t lfb_memsize;

/* Bitmap font details */
#include "../terminal-font.h"
#include "../../apps/terminal-font.h"
#define char_height 20
#define char_width 9

Expand Down
17 changes: 16 additions & 1 deletion kernel/misc/gzip.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/**
* @file kernel/misc/gzip.c
* @brief Gzip/DEFLATE decompression.
*
* Provides decompression for ramdisks.
* Based on the same approach to DEFLATE decompression as libraries
* like "tinf", this is a slow-but-simple implementation of Huffman
* decoding. The kernel version operates directly on two pointers,
* @c gzip_inputPtr and @c gzip_outputPtr. For a more robust API,
* see the userspace version.
*
* @copyright
* This file is part of ToaruOS and is released under the terms
* of the NCSA / University of Illinois License - see LICENSE.md
* Copyright (C) 2020-2021 K. Lange
*/
#include <stdint.h>
#include <stddef.h>

Expand All @@ -17,7 +33,6 @@ static inline void _write(unsigned int sym) {
*gzip_outputPtr++ = sym;
}


/**
* Decoded Huffman table
*/
Expand Down
Loading

0 comments on commit b871a54

Please sign in to comment.