Add ability to generate internal API documentation using Doxygen.

This commit is contained in:
Martin Whitaker 2022-02-19 16:17:40 +00:00
parent d09c5ed7b4
commit 76adad2fe6
45 changed files with 2967 additions and 232 deletions

2
.gitignore vendored
View File

@ -18,3 +18,5 @@ memtest_shared.bin
# Directories # Directories
grub-iso grub-iso
html
latex

View File

@ -1,27 +1,29 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef BADRAM_H #ifndef BADRAM_H
#define BADRAM_H #define BADRAM_H
/* /**
* Support for generating patterns for the Linux kernel BadRAM extension. * \file
* *
* Copyright (C) 2020 Martin Whitaker. * Provides functions for generating patterns for the Linux kernel BadRAM extension.
*
* Copyright (C) 2020-2022 Martin Whitaker.
*/ */
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
/* /**
* Initialises the pattern array. * Initialises the pattern array.
*/ */
void badram_init(void); void badram_init(void);
/* /**
* Inserts a single faulty address into the pattern array. Returns * Inserts a single faulty address into the pattern array. Returns
* true iff the array was changed. * true iff the array was changed.
*/ */
bool badram_insert(uintptr_t addr); bool badram_insert(uintptr_t addr);
/* /**
* Displays the pattern array in the scrollable display region in the * Displays the pattern array in the scrollable display region in the
* format used by the Linux kernel. * format used by the Linux kernel.
*/ */

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef CONFIG_H #ifndef CONFIG_H
#define CONFIG_H #define CONFIG_H
/* /**
* \file
*
* Provides the configuration settings and pop-up menu. * Provides the configuration settings and pop-up menu.
* *
* Copyright (C) 2020-2022 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef DISPLAY_H #ifndef DISPLAY_H
#define DISPLAY_H #define DISPLAY_H
/* /**
* \file
*
* Provides (macro) functions that implement the UI display. * Provides (macro) functions that implement the UI display.
* All knowledge about the display layout is encapsulated here. * All knowledge about the display layout is encapsulated here.
* *

View File

@ -1,10 +1,12 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef ERROR_H #ifndef ERROR_H
#define ERROR_H #define ERROR_H
/* /**
* \file
*
* Provides functions that can be called by the memory tests to report errors. * Provides functions that can be called by the memory tests to report errors.
* *
* Copyright (C) 2020-2021 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
#include <stdbool.h> #include <stdbool.h>
@ -12,34 +14,34 @@
#include "test.h" #include "test.h"
/* /**
* The number of errors recorded during the current run. * The number of errors recorded during the current run.
*/ */
extern uint64_t error_count; extern uint64_t error_count;
/* /**
* Initialises the error records. * Initialises the error records.
*/ */
void error_init(void); void error_init(void);
/* /**
* Adds an address error to the error reports. * Adds an address error to the error reports.
*/ */
void addr_error(testword_t *addr1, testword_t *addr2, testword_t good, testword_t bad); void addr_error(testword_t *addr1, testword_t *addr2, testword_t good, testword_t bad);
/* /**
* Adds a data error to the error reports. * Adds a data error to the error reports.
*/ */
void data_error(testword_t *addr, testword_t good, testword_t bad, bool use_for_badram); void data_error(testword_t *addr, testword_t good, testword_t bad, bool use_for_badram);
#if REPORT_PARITY_ERRORS #if REPORT_PARITY_ERRORS
/* /**
* Adds a parity error to the error reports. * Adds a parity error to the error reports.
*/ */
void parity_error(void); void parity_error(void);
#endif #endif
/* /**
* Refreshes the error display after the error mode is changed. * Refreshes the error display after the error mode is changed.
*/ */
void error_update(void); void error_update(void);

View File

@ -1,15 +1,17 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef INTERRUPT_H #ifndef INTERRUPT_H
#define INTERRUPT_H #define INTERRUPT_H
/* /**
* \file
*
* Provides the interrupt handler. * Provides the interrupt handler.
* *
* Copyright (C) 2020 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
struct trap_regs; struct trap_regs;
/* /**
* Handles an interrupt. * Handles an interrupt.
*/ */
void interrupt(struct trap_regs *trap_regs); void interrupt(struct trap_regs *trap_regs);

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef TEST_H #ifndef TEST_H
#define TEST_H #define TEST_H
/* /**
* \file
*
* Provides types and variables used when performing the memory tests. * Provides types and variables used when performing the memory tests.
* *
* Copyright (C) 2020-2022 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
@ -16,7 +18,7 @@
#include "barrier.h" #include "barrier.h"
#include "spinlock.h" #include "spinlock.h"
/* /**
* A mapping from a CPU core number to the index number of the memory chunk * A mapping from a CPU core number to the index number of the memory chunk
* it operates on when performing a memory test in parallel across all the * it operates on when performing a memory test in parallel across all the
* enabled cores. * enabled cores.
@ -29,22 +31,22 @@ extern uint8_t chunk_index[MAX_CPUS];
*/ */
extern int num_active_cpus; extern int num_active_cpus;
/* /**
* The current master CPU core. * The current master CPU core.
*/ */
extern int master_cpu; extern int master_cpu;
/* /**
* A barrier used when running tests. * A barrier used when running tests.
*/ */
extern barrier_t *run_barrier; extern barrier_t *run_barrier;
/* /**
* A mutex used when reporting errors or printing trace information. * A mutex used when reporting errors or printing trace information.
*/ */
extern spinlock_t *error_mutex; extern spinlock_t *error_mutex;
/* /**
* The word width (in bits) used for memory testing. * The word width (in bits) used for memory testing.
*/ */
#ifdef __x86_64__ #ifdef __x86_64__
@ -53,17 +55,17 @@ extern spinlock_t *error_mutex;
#define TESTWORD_WIDTH 32 #define TESTWORD_WIDTH 32
#endif #endif
/* /**
* The number of hex digits needed to display a memory test word. * The number of hex digits needed to display a memory test word.
*/ */
#define TESTWORD_DIGITS (TESTWORD_WIDTH / 4) #define TESTWORD_DIGITS (TESTWORD_WIDTH / 4)
/* /**
* The word type used for memory testing. * The word type used for memory testing.
*/ */
typedef uintptr_t testword_t; typedef uintptr_t testword_t;
/* /**
* A virtual memory segment descriptor. * A virtual memory segment descriptor.
*/ */
typedef struct { typedef struct {
@ -72,35 +74,35 @@ typedef struct {
testword_t *end; testword_t *end;
} vm_map_t; } vm_map_t;
/* /**
* The list of memory segments currently mapped into virtual memory. * The list of memory segments currently mapped into virtual memory.
*/ */
extern vm_map_t vm_map[MAX_MEM_SEGMENTS]; extern vm_map_t vm_map[MAX_MEM_SEGMENTS];
/* /**
* The number of memory segments currently mapped into virtual memory. * The number of memory segments currently mapped into virtual memory.
*/ */
extern int vm_map_size; extern int vm_map_size;
/* /**
* The number of completed test passes. * The number of completed test passes.
*/ */
extern int pass_num; extern int pass_num;
/* /**
* The current test number. * The current test number.
*/ */
extern int test_num; extern int test_num;
/* /**
* A flag indicating that testing should be restarted due to a configuration * A flag indicating that testing should be restarted due to a configuration
* change. * change.
*/ */
extern bool restart; extern bool restart;
/* /**
* A flag indicating that the current test should be aborted. * A flag indicating that the current test should be aborted.
*/ */
extern bool bail; extern bool bail;
/* /**
* The base address of the block of memory currently being tested. * The base address of the block of memory currently being tested.
*/ */
extern uintptr_t test_addr[MAX_CPUS]; extern uintptr_t test_addr[MAX_CPUS];

View File

@ -1,9 +1,11 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef BOOT_H #ifndef BOOT_H
#define BOOT_H #define BOOT_H
/* /**
* Definitions used in the boot code. Also defines exported symbols needed * \file
* in the main code. *
* Provides definitions used in the boot code. Also defines exported symbols
* needed in the main code.
* *
* Copyright (C) 2020-2022 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */

View File

@ -1,13 +1,15 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef BOOTPARAMS_H #ifndef BOOTPARAMS_H
#define BOOTPARAMS_H #define BOOTPARAMS_H
/* /**
* \file
*
* Provides definitions for the boot params structure passed to us by * Provides definitions for the boot params structure passed to us by
* intermediate bootloaders when using the Linux boot protocol. This matches * intermediate bootloaders when using the Linux boot protocol. This matches
* the Linux boot_params struct, although we only define the fields we are * the Linux boot_params struct, although we only define the fields we are
* interested in. * interested in.
* *
* Copyright (C) 2020-2021 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
#include <stdint.h> #include <stdint.h>

View File

@ -1,11 +1,13 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef EFI_H #ifndef EFI_H
#define EFI_H #define EFI_H
/* /**
* \file
*
* Provides definitions for accessing the UEFI boot services and configuration * Provides definitions for accessing the UEFI boot services and configuration
* tables. * tables.
* *
* Copyright (C) 2020 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
#include <stdint.h> #include <stdint.h>
@ -16,7 +18,7 @@
#define NATIVE_MSB 0x80000000 #define NATIVE_MSB 0x80000000
#endif #endif
/* /**
* EFI_STATUS values. * EFI_STATUS values.
*/ */
#define EFI_SUCCESS 0 #define EFI_SUCCESS 0
@ -27,17 +29,17 @@
#define EFI_NOT_FOUND (NATIVE_MSB | 14) #define EFI_NOT_FOUND (NATIVE_MSB | 14)
#define EFI_ABORTED (NATIVE_MSB | 21) #define EFI_ABORTED (NATIVE_MSB | 21)
/* /**
* EFI_LOCATE_SEARCH_TYPE values. * EFI_LOCATE_SEARCH_TYPE values.
*/ */
#define EFI_LOCATE_BY_PROTOCOL 2 #define EFI_LOCATE_BY_PROTOCOL 2
/* /**
* EFI_ALLOCATE_TYPE values. * EFI_ALLOCATE_TYPE values.
*/ */
#define EFI_ALLOCATE_ADDRESS 2 #define EFI_ALLOCATE_ADDRESS 2
/* /**
* EFI_MEMORY_TYPE values. * EFI_MEMORY_TYPE values.
*/ */
#define EFI_LOADER_CODE 1 #define EFI_LOADER_CODE 1
@ -47,7 +49,7 @@
#define EFI_CONVENTIONAL_MEMORY 7 #define EFI_CONVENTIONAL_MEMORY 7
#define EFI_ACPI_RECLAIM_MEMORY 9 #define EFI_ACPI_RECLAIM_MEMORY 9
/* /**
* EFI_GRAPHICS_PIXEL_FORMAT values. * EFI_GRAPHICS_PIXEL_FORMAT values.
*/ */
#define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0 #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0

2574
doc/Doxyfile Normal file

File diff suppressed because it is too large Load Diff

76
doc/README_DEVEL.md Normal file
View File

@ -0,0 +1,76 @@
# Developer's Guide
This is the developer's guide to the PCMemTest source code. The user's guide
can be found in the README.md file in the top level directory.
## Code Organisation
The source code is divided into the following categories, each contained in a
subdirectory of the same name:
* app
The main application and framework for running the memory tests.
* boot
The code that transitions from the BIOS or bootloader entry point to the
start of the main application.
* lib
The subset of the C standard library that is used by PCMemTest plus other
hardware-independent low-level support functions.
* system
Low-level support functions that interface to the hardware.
* tests
The individual memory tests.
The boot code is mostly written in AT&T syntax x86 assembly language. The
remaining code is written in C.
Each category is further subdivided into multiple source files, splitting the
code into small units of closely related functionality. For the C code, the
API for each unit is defined in a header (`.h`) file and the implementation
(if required) is found in the correspondingly named source (`.c`) file.
## Code Documentation
Doxygen can be used to automatically generate HTML documentation for the API
for each code unit from the comments in the C header files. To regenerate the
documentation, change directory into the `doc` subdirectory and run `doxygen`.
## Coding Conventions
### C Code
Macro names and enumeration values are written in upper case separated by
underscores. All other identifiers are written in lower case separated by
underscores. Both excessive length and excessive abbreviation are avoided.
Line length is normally limited to 120 characters.
Indentation is 4 spaces. No hard tab characters are used.
Opening braces for function bodies are put on a new line. Other opening braces
are put on the same line as the construct that introduces them.
The C11 dialect is used. In particular, variable declarations and statements
are interspersed and loop variables are declared within the `for` loop
construct.
### Assembly Code
Labels are written in lower case separated by underscores. Op-codes and
register names are written in lower case.
Line length is normally limited to 120 characters.
Indentation is 8 spaces using hard tab characters.
The C preprocessor is used for defining constant values and expressions.
Macro names are written in upper case separated by underscores.

View File

@ -1,15 +1,17 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef BARRIER_H #ifndef BARRIER_H
#define BARRIER_H #define BARRIER_H
/* /**
* \file
*
* Provides a barrier synchronisation primitive. * Provides a barrier synchronisation primitive.
* *
* Copyright (C) 2020 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
#include "spinlock.h" #include "spinlock.h"
/* /**
* A barrier object. * A barrier object.
*/ */
typedef struct typedef struct
@ -21,12 +23,12 @@ typedef struct
spinlock_t st2; spinlock_t st2;
} barrier_t; } barrier_t;
/* /**
* Initialises the barrier to block the specified number of threads. * Initialises the barrier to block the specified number of threads.
*/ */
void barrier_init(barrier_t *barrier, int num_threads); void barrier_init(barrier_t *barrier, int num_threads);
/* /**
* Waits for all threads to arrive at the barrier. * Waits for all threads to arrive at the barrier.
*/ */
void barrier_wait(barrier_t *barrier); void barrier_wait(barrier_t *barrier);

View File

@ -1,25 +1,27 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef CTYPE_H #ifndef CTYPE_H
#define CTYPE_H #define CTYPE_H
/* /**
* \file
*
* Provides a subset of the functions normally provided by <ctype.h>. * Provides a subset of the functions normally provided by <ctype.h>.
* *
* Copyright (C) 2020 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
/* /**
* If c is a lower-case letter, returns its upper-case equivalent, otherwise * If c is a lower-case letter, returns its upper-case equivalent, otherwise
* returns c. Assumes c is an ASCII character. * returns c. Assumes c is an ASCII character.
*/ */
int toupper(int c); int toupper(int c);
/* /**
* Returns 1 if c is a decimal digit, otherwise returns 0. Assumes c is an * Returns 1 if c is a decimal digit, otherwise returns 0. Assumes c is an
* ASCII character. * ASCII character.
*/ */
int isdigit(int c); int isdigit(int c);
/* /**
* Returns 1 if c is a hexadecimal digit, otherwise returns 0. Assumes c is an * Returns 1 if c is a hexadecimal digit, otherwise returns 0. Assumes c is an
* ASCII character. * ASCII character.
*/ */

View File

@ -1,28 +1,30 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef PRINT_H #ifndef PRINT_H
#define PRINT_H #define PRINT_H
/* /**
* \file
*
* Provides functions to print strings and formatted values to the screen. * Provides functions to print strings and formatted values to the screen.
* *
* Copyright (C) 2020 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
/* /**
* Prints a single character on screen at location (row,col) and returns col+1. * Prints a single character on screen at location (row,col) and returns col+1.
*/ */
int printc(int row, int col, char c); int printc(int row, int col, char c);
/* /**
* Prints a string on screen starting at location (row,col) and returns the * Prints a string on screen starting at location (row,col) and returns the
* next column after the string. * next column after the string.
*/ */
int prints(int row, int col, const char *str); int prints(int row, int col, const char *str);
/* /**
* Prints a signed decimal number on screen starting at location (row,col) in * Prints a signed decimal number on screen starting at location (row,col) in
* a field of at least length characters, optionally padding the number with * a field of at least length characters, optionally padding the number with
* leading zeros, and optionally left-justifying instead of right-justifying * leading zeros, and optionally left-justifying instead of right-justifying
@ -30,7 +32,7 @@ int prints(int row, int col, const char *str);
*/ */
int printi(int row, int col, int value, int length, bool pad, bool left); int printi(int row, int col, int value, int length, bool pad, bool left);
/* /**
* Prints an unsigned decimal number on screen starting at location (row,col) * Prints an unsigned decimal number on screen starting at location (row,col)
* in a field of at least length characters, optionally padding the number with * in a field of at least length characters, optionally padding the number with
* leading zeros, and optionally left-justifying instead of right-justifying in * leading zeros, and optionally left-justifying instead of right-justifying in
@ -38,7 +40,7 @@ int printi(int row, int col, int value, int length, bool pad, bool left);
*/ */
int printu(int row, int col, uintptr_t value, int length, bool pad, bool left); int printu(int row, int col, uintptr_t value, int length, bool pad, bool left);
/* /**
* Prints an unsigned hexadecimal number on screen starting at location (row,col) * Prints an unsigned hexadecimal number on screen starting at location (row,col)
* in a field of at least length characters, optionally padding the number with * in a field of at least length characters, optionally padding the number with
* leading zeros, and optionally left-justifying instead of right-justifying in * leading zeros, and optionally left-justifying instead of right-justifying in
@ -46,7 +48,7 @@ int printu(int row, int col, uintptr_t value, int length, bool pad, bool left);
*/ */
int printx(int row, int col, uintptr_t value, int length, bool pad, bool left); int printx(int row, int col, uintptr_t value, int length, bool pad, bool left);
/* /**
* Prints a K<unit> value on screen starting at location (row,col) in a field of * Prints a K<unit> value on screen starting at location (row,col) in a field of
* at least length characters, optionally padding the number with leading zeros, * at least length characters, optionally padding the number with leading zeros,
* and optionally left-justifying instead of right-justifying in the field. The * and optionally left-justifying instead of right-justifying in the field. The
@ -55,7 +57,7 @@ int printx(int row, int col, uintptr_t value, int length, bool pad, bool left);
*/ */
int printk(int row, int col, uintptr_t value, int length, bool pad, bool left); int printk(int row, int col, uintptr_t value, int length, bool pad, bool left);
/* /**
* Emulates the standard printf function. Printing starts at location (row,col). * Emulates the standard printf function. Printing starts at location (row,col).
* *
* The conversion flags supported are: * The conversion flags supported are:
@ -77,7 +79,7 @@ int printk(int row, int col, uintptr_t value, int length, bool pad, bool left);
*/ */
int printf(int row, int col, const char *fmt, ...); int printf(int row, int col, const char *fmt, ...);
/* /**
* The alternate form of printf. * The alternate form of printf.
*/ */
int vprintf(int row, int col, const char *fmt, va_list args); int vprintf(int row, int col, const char *fmt, va_list args);

View File

@ -1,15 +1,17 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef READ_H #ifndef READ_H
#define READ_H #define READ_H
/* /**
* \file
*
* Provides a function to read a numeric value. * Provides a function to read a numeric value.
* *
* Copyright (C) 2020 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
#include <stdint.h> #include <stdint.h>
/* /**
* Returns an unsigned numeric value entered on the keyboard. Echoes the * Returns an unsigned numeric value entered on the keyboard. Echoes the
* input to the display field located at (row,col), limiting it to field_width * input to the display field located at (row,col), limiting it to field_width
* characters. If the entered value is prefixed by "0x", assumes base 16, * characters. If the entered value is prefixed by "0x", assumes base 16,

View File

@ -1,20 +1,22 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef SPINLOCK_H #ifndef SPINLOCK_H
#define SPINLOCK_H #define SPINLOCK_H
/* /**
* \file
*
* Provides a lightweight mutex synchronisation primitive. * Provides a lightweight mutex synchronisation primitive.
* *
* Copyright (C) 2020 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
#include <stdbool.h> #include <stdbool.h>
/* /**
* A mutex object. Use spin_unlock() to initialise prior to first use. * A mutex object. Use spin_unlock() to initialise prior to first use.
*/ */
typedef volatile bool spinlock_t; typedef volatile bool spinlock_t;
/* /**
* Spins until the mutex is unlocked. * Spins until the mutex is unlocked.
*/ */
static inline void spin_wait(spinlock_t *lock) static inline void spin_wait(spinlock_t *lock)
@ -26,7 +28,7 @@ static inline void spin_wait(spinlock_t *lock)
} }
} }
/* /**
* Spins until the mutex is unlocked, then locks the mutex. * Spins until the mutex is unlocked, then locks the mutex.
*/ */
static inline void spin_lock(spinlock_t *lock) static inline void spin_lock(spinlock_t *lock)
@ -41,7 +43,7 @@ static inline void spin_lock(spinlock_t *lock)
} }
} }
/* /**
* Unlocks the mutex. * Unlocks the mutex.
*/ */
static inline void spin_unlock(spinlock_t *lock) static inline void spin_unlock(spinlock_t *lock)

View File

@ -1,15 +1,17 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef STRING_H #ifndef STRING_H
#define STRING_H #define STRING_H
/* /**
* \file
*
* Provides a subset of the functions normally provided by <string.h>. * Provides a subset of the functions normally provided by <string.h>.
* *
* Copyright (C) 2020 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
#include <stddef.h> #include <stddef.h>
/* /**
* Compares the first n bytes of the memory areas pointed to by s1 and s2 * Compares the first n bytes of the memory areas pointed to by s1 and s2
* and returns 0 if all bytes are the same or the numerical difference * and returns 0 if all bytes are the same or the numerical difference
* between the first mismatching byte in s1 (interpreted as an unsigned * between the first mismatching byte in s1 (interpreted as an unsigned
@ -17,32 +19,32 @@
*/ */
int memcmp(const void *s1, const void *s2, size_t n); int memcmp(const void *s1, const void *s2, size_t n);
/* /**
* Copies n bytes from the memory area pointed to by src to the memory area * Copies n bytes from the memory area pointed to by src to the memory area
* pointed to by dest and returns a pointer to dest. The memory areas must * pointed to by dest and returns a pointer to dest. The memory areas must
* not overlap. * not overlap.
*/ */
void *memcpy(void *dst, const void *src, size_t n); void *memcpy(void *dst, const void *src, size_t n);
/* /**
* Copies n bytes from the memory area pointed to by src to the memory area * Copies n bytes from the memory area pointed to by src to the memory area
* pointed to by dest and returns a pointer to dest. The memory areas may * pointed to by dest and returns a pointer to dest. The memory areas may
* overlap. * overlap.
*/ */
void *memmove(void *dest, const void *src, size_t n); void *memmove(void *dest, const void *src, size_t n);
/* /**
* Fills the first n bytes of the memory area pointed to by s with the byte * Fills the first n bytes of the memory area pointed to by s with the byte
* value c. * value c.
*/ */
void *memset(void *s, int c, size_t n); void *memset(void *s, int c, size_t n);
/* /**
* Returns the string length, excluding the terminating null character. * Returns the string length, excluding the terminating null character.
*/ */
size_t strlen(const char *s); size_t strlen(const char *s);
/* /**
* Compares at most the first n characters in the strings s1 and s2 and * Compares at most the first n characters in the strings s1 and s2 and
* returns 0 if all characters are the same or the numerical difference * returns 0 if all characters are the same or the numerical difference
* between the first mismatching character in s1 (interpreted as a signed * between the first mismatching character in s1 (interpreted as a signed
@ -50,7 +52,7 @@ size_t strlen(const char *s);
*/ */
int strncmp(const char *s1, const char *s2, size_t n); int strncmp(const char *s1, const char *s2, size_t n);
/* /**
* Finds the first occurrence of the substring needle in the string haystack * Finds the first occurrence of the substring needle in the string haystack
* and returns a pointer to the beginning of the located substring, or NULL * and returns a pointer to the beginning of the located substring, or NULL
* if the substring is not found. * if the substring is not found.

View File

@ -1,18 +1,20 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef UNISTD_H #ifndef UNISTD_H
#define UNISTD_H #define UNISTD_H
/* /**
* \file
*
* Provides a subset of the functions normally provided by <unistd.h>. * Provides a subset of the functions normally provided by <unistd.h>.
* *
* Copyright (C) 2020 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
/* /**
* Sleeps for at least usec microseconds. * Sleeps for at least usec microseconds.
*/ */
void usleep(unsigned int usec); void usleep(unsigned int usec);
/* /**
* Sleeps for at least sec seconds. * Sleeps for at least sec seconds.
*/ */
void sleep(unsigned int sec); void sleep(unsigned int sec);

View File

@ -1,13 +1,15 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef CACHE_H #ifndef CACHE_H
#define CACHE_H #define CACHE_H
/* /**
* \file
*
* Provides functions to enable, disable, and flush the CPU caches. * Provides functions to enable, disable, and flush the CPU caches.
* *
* Copyright (C) 2020-2021 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
/* /**
* Disable the CPU caches. * Disable the CPU caches.
*/ */
static inline void cache_off(void) static inline void cache_off(void)
@ -35,7 +37,7 @@ static inline void cache_off(void)
#endif #endif
} }
/* /**
* Enable the CPU caches. * Enable the CPU caches.
*/ */
static inline void cache_on(void) static inline void cache_on(void)
@ -61,7 +63,7 @@ static inline void cache_on(void)
#endif #endif
} }
/* /**
* Flush the CPU caches. * Flush the CPU caches.
*/ */
static inline void cache_flush(void) static inline void cache_flush(void)

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef CPUID_H #ifndef CPUID_H
#define CPUID_H #define CPUID_H
/* /**
* \file
*
* Provides access to the CPUID information. * Provides access to the CPUID information.
* *
* Copyright (C) 2020-2022 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
@ -12,7 +14,7 @@
#include <stdint.h> #include <stdint.h>
/* /**
* Structures that hold the collected CPUID information. * Structures that hold the collected CPUID information.
*/ */
@ -172,17 +174,17 @@ typedef union {
}; };
} cpuid4_ecx_t; } cpuid4_ecx_t;
/* /**
* The CPUID information collected by cpuid_init(); * The CPUID information collected by cpuid_init();
*/ */
extern cpuid_info_t cpuid_info; extern cpuid_info_t cpuid_info;
/* /**
* Reads the CPUID information and stores it in cpuid_info. * Reads the CPUID information and stores it in cpuid_info.
*/ */
void cpuid_init(void); void cpuid_init(void);
/* /**
* Executes the cpuid instruction. * Executes the cpuid instruction.
*/ */
static inline void cpuid(uint32_t op, uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) static inline void cpuid(uint32_t op, uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)

View File

@ -1,51 +1,53 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef CPUINFO_H #ifndef CPUINFO_H
#define CPUINFO_H #define CPUINFO_H
/* /**
* \file
*
* Provides information about the CPU type, clock speed and cache sizes. * Provides information about the CPU type, clock speed and cache sizes.
* *
* Copyright (C) 2020 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
/* /**
* A string identifying the CPU make and model. * A string identifying the CPU make and model.
*/ */
extern const char *cpu_model; extern const char *cpu_model;
/* /**
* A number identifying the integrated memory controller type. * A number identifying the integrated memory controller type.
*/ */
extern uint32_t imc_type; extern uint32_t imc_type;
/* /**
* The size of the L1 cache in KB. * The size of the L1 cache in KB.
*/ */
extern int l1_cache; extern int l1_cache;
/* /**
* The size of the L2 cache in KB. * The size of the L2 cache in KB.
*/ */
extern int l2_cache; extern int l2_cache;
/* /**
* The size of the L3 cache in KB. * The size of the L3 cache in KB.
*/ */
extern int l3_cache; extern int l3_cache;
/* /**
* A flag indicating that we can't read the core temperature on this CPU. * A flag indicating that we can't read the core temperature on this CPU.
*/ */
extern bool no_temperature; extern bool no_temperature;
/* /**
* The TSC clock speed in kHz. Assumed to be the nominal CPU clock speed. * The TSC clock speed in kHz. Assumed to be the nominal CPU clock speed.
*/ */
extern uint32_t clks_per_msec; extern uint32_t clks_per_msec;
/* /**
* Determines the CPU info and stores it in the exported variables. * Determines the CPU info and stores it in the exported variables.
*/ */
void cpuinfo_init(void); void cpuinfo_init(void);

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef EHCI_H #ifndef EHCI_H
#define EHCI_H #define EHCI_H
/* /**
* \file
*
* Provides support for USB keyboards connected via an EHCI controller. * Provides support for USB keyboards connected via an EHCI controller.
* *
* Copyright (C) 2021-2022 Martin Whitaker. * Copyright (C) 2021-2022 Martin Whitaker.
@ -11,7 +13,7 @@
#include "usbhcd.h" #include "usbhcd.h"
/* /**
* Initialises the EHCI device identified by bus, dev, func, and base_addr, * Initialises the EHCI device identified by bus, dev, func, and base_addr,
* scans all the attached USB devices, and configures any HID USB keyboard * scans all the attached USB devices, and configures any HID USB keyboard
* devices it finds to generate periodic interrupt transfers that report key * devices it finds to generate periodic interrupt transfers that report key

View File

@ -1,22 +1,24 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef FONT_H #ifndef FONT_H
#define FONT_H #define FONT_H
/* /**
* \file
*
* Provides the font used for framebuffer display. * Provides the font used for framebuffer display.
* *
* Copyright (C) 2020 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
#include <stdint.h> #include <stdint.h>
/* /**
* Font size definitions. * Font size definitions.
*/ */
#define FONT_WIDTH 8 #define FONT_WIDTH 8
#define FONT_HEIGHT 16 #define FONT_HEIGHT 16
#define FONT_CHARS 256 #define FONT_CHARS 256
/* /**
* The font data. * The font data.
*/ */
extern const uint8_t font_data[FONT_CHARS][FONT_HEIGHT]; extern const uint8_t font_data[FONT_CHARS][FONT_HEIGHT];

View File

@ -1,23 +1,25 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef HWCTRL_H #ifndef HWCTRL_H
#define HWCTRL_H #define HWCTRL_H
/* /**
* \file
*
* Provides miscellaneous hardware control functions. * Provides miscellaneous hardware control functions.
* *
* Copyright (C) 2020 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
/* /**
* Reboots the machine. * Reboots the machine.
*/ */
void reboot(void); void reboot(void);
/* /**
* Turns off the floppy motor. * Turns off the floppy motor.
*/ */
void floppy_off(); void floppy_off();
/* /**
* Disables the screen cursor. * Disables the screen cursor.
*/ */
void cursor_off(); void cursor_off();

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef IO_H #ifndef IO_H
#define IO_H #define IO_H
/* /**
* \file
*
* Provides macro definitions for the x86 IO instructions * Provides macro definitions for the x86 IO instructions
* inb/inw/inl/outb/outw/outl and the "string versions" of the same * inb/inw/inl/outb/outw/outl and the "string versions" of the same
* (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing" * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
@ -78,7 +80,7 @@ __OUTS(b)
__OUTS(w) __OUTS(w)
__OUTS(l) __OUTS(l)
/* /**
* Note that due to the way __builtin_constant_p() works, you * Note that due to the way __builtin_constant_p() works, you
* - can't use it inside a inline function (it will never be true) * - can't use it inside a inline function (it will never be true)
* - you don't have to worry about side effects within the __builtin.. * - you don't have to worry about side effects within the __builtin..

View File

@ -1,22 +1,23 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef KEYBOARD_H #ifndef KEYBOARD_H
#define KEYBOARD_H #define KEYBOARD_H
/**
#include <stdbool.h> * \file
*
/*
* Provides the keyboard interface. It converts incoming key codes to * Provides the keyboard interface. It converts incoming key codes to
* ASCII characters. * ASCII characters.
* *
* Copyright (C) 2020-2021 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
/* #include <stdbool.h>
/**
* The Escape character. * The Escape character.
*/ */
#define ESC 27 #define ESC 27
/* /**
* A set of supported keyboard types. * A set of supported keyboard types.
*/ */
typedef enum { typedef enum {
@ -25,17 +26,17 @@ typedef enum {
KT_USB = 2 KT_USB = 2
} keyboard_types_t; } keyboard_types_t;
/* /**
* The set of enabled keyboard types * The set of enabled keyboard types
*/ */
extern keyboard_types_t keyboard_types; extern keyboard_types_t keyboard_types;
/* /**
* Initialises the keyboard interface. * Initialises the keyboard interface.
*/ */
void keyboard_init(bool pause_at_end); void keyboard_init(bool pause_at_end);
/* /**
* Checks if a key has been pressed and returns the primary ASCII character * Checks if a key has been pressed and returns the primary ASCII character
* corresponding to that key if so, otherwise returns the null character. * corresponding to that key if so, otherwise returns the null character.
* F1 to F10 are mapped to the corresponding decimal digit (F10 -> 0). All * F1 to F10 are mapped to the corresponding decimal digit (F10 -> 0). All

View File

@ -1,17 +1,19 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef MEMRW32_H #ifndef MEMRW32_H
#define MEMRW32_H #define MEMRW32_H
/* /**
* \file
*
* Provides some 32-bit memory access functions. These stop the compiler * Provides some 32-bit memory access functions. These stop the compiler
* optimizing accesses which need to be ordered and atomic. Mostly used * optimizing accesses which need to be ordered and atomic. Mostly used
* for accessing memory-mapped hardware registers. * for accessing memory-mapped hardware registers.
* *
* Copyright (C) 2021 Martin Whitaker. * Copyright (C) 2021-2022 Martin Whitaker.
*/ */
#include <stdint.h> #include <stdint.h>
/* /**
* Reads and returns the value stored in the 32-bit memory location pointed * Reads and returns the value stored in the 32-bit memory location pointed
* to by ptr. * to by ptr.
*/ */
@ -27,7 +29,7 @@ static inline uint32_t read32(const volatile uint32_t *ptr)
return val; return val;
} }
/* /**
* Writes val to the 32-bit memory location pointed to by ptr. * Writes val to the 32-bit memory location pointed to by ptr.
*/ */
static inline void write32(const volatile uint32_t *ptr, uint32_t val) static inline void write32(const volatile uint32_t *ptr, uint32_t val)
@ -41,7 +43,7 @@ static inline void write32(const volatile uint32_t *ptr, uint32_t val)
); );
} }
/* /**
* Writes val to the 32-bit memory location pointed to by ptr. Reads it * Writes val to the 32-bit memory location pointed to by ptr. Reads it
* back (and discards it) to ensure the write is complete. * back (and discards it) to ensure the write is complete.
*/ */

View File

@ -1,17 +1,19 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef MEMRW64_H #ifndef MEMRW64_H
#define MEMRW64_H #define MEMRW64_H
/* /**
* \file
*
* Provides some 64-bit memory access functions. These stop the compiler * Provides some 64-bit memory access functions. These stop the compiler
* optimizing accesses which need to be ordered and atomic. Mostly used * optimizing accesses which need to be ordered and atomic. Mostly used
* for accessing memory-mapped hardware registers. * for accessing memory-mapped hardware registers.
* *
* Copyright (C) 2021 Martin Whitaker. * Copyright (C) 2021-2022 Martin Whitaker.
*/ */
#include <stdint.h> #include <stdint.h>
/* /**
* Reads and returns the value stored in the 64-bit memory location pointed * Reads and returns the value stored in the 64-bit memory location pointed
* to by ptr. * to by ptr.
*/ */
@ -27,7 +29,7 @@ static inline uint64_t read64(const volatile uint64_t *ptr)
return val; return val;
} }
/* /**
* Writes val to the 64-bit memory location pointed to by ptr. * Writes val to the 64-bit memory location pointed to by ptr.
*/ */
static inline void write64(const volatile uint64_t *ptr, uint64_t val) static inline void write64(const volatile uint64_t *ptr, uint64_t val)
@ -41,7 +43,7 @@ static inline void write64(const volatile uint64_t *ptr, uint64_t val)
); );
} }
/* /**
* Writes val to the 64-bit memory location pointed to by ptr. Reads it * Writes val to the 64-bit memory location pointed to by ptr. Reads it
* back (and discards it) to ensure the write is complete. * back (and discards it) to ensure the write is complete.
*/ */

View File

@ -1,10 +1,12 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef MEMSIZE_H #ifndef MEMSIZE_H
#define MEMSIZE_H #define MEMSIZE_H
/* /**
* \file
*
* Provides some convenient constants and constant constructors. * Provides some convenient constants and constant constructors.
* *
* Copyright (C) 2020 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
#include <stddef.h> #include <stddef.h>

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef MSR_H #ifndef MSR_H
#define MSR_H #define MSR_H
/* /**
* \file
*
* Provides access to the CPU machine-specific registers. * Provides access to the CPU machine-specific registers.
* *
* Copyright (C) 2020-2022 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef OHCI_H #ifndef OHCI_H
#define OHCI_H #define OHCI_H
/* /**
* \file
*
* Provides support for USB keyboards connected via an OHCI controller. * Provides support for USB keyboards connected via an OHCI controller.
* *
* Copyright (C) 2021-2022 Martin Whitaker. * Copyright (C) 2021-2022 Martin Whitaker.
@ -11,7 +13,7 @@
#include "usbhcd.h" #include "usbhcd.h"
/* /**
* Initialises the OHCI device found at base_addr, scans all the attached USB * Initialises the OHCI device found at base_addr, scans all the attached USB
* devices, and configures any HID USB keyboard devices it finds to generate * devices, and configures any HID USB keyboard devices it finds to generate
* periodic interrupt transfers that report key presses. Initialises hcd and * periodic interrupt transfers that report key presses. Initialises hcd and

View File

@ -1,10 +1,12 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef PCI_H #ifndef PCI_H
#define PCI_H #define PCI_H
/* /**
* \file
*
* Provides functions to perform PCI configuration space reads and writes. * Provides functions to perform PCI configuration space reads and writes.
* *
* Copyright (C) 2020-2021 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
#include <stdint.h> #include <stdint.h>
@ -13,44 +15,44 @@
#define PCI_MAX_DEV 32 #define PCI_MAX_DEV 32
#define PCI_MAX_FUNC 8 #define PCI_MAX_FUNC 8
/* /**
* Initialises the PCI access support. * Initialises the PCI access support.
*/ */
void pci_init(void); void pci_init(void);
/* /**
* Returns an 8 bit value read from the specified bus+device+function+register * Returns an 8 bit value read from the specified bus+device+function+register
* address in the PCI configuration address space. * address in the PCI configuration address space.
*/ */
uint8_t pci_config_read8(int bus, int dev, int func, int reg); uint8_t pci_config_read8(int bus, int dev, int func, int reg);
/* /**
* Returns a 16 bit value read from the specified bus+device+function+register * Returns a 16 bit value read from the specified bus+device+function+register
* address in the PCI configuration address space. The address must be 16-bit * address in the PCI configuration address space. The address must be 16-bit
* aligned. * aligned.
*/ */
uint16_t pci_config_read16(int bus, int dev, int func, int reg); uint16_t pci_config_read16(int bus, int dev, int func, int reg);
/* /**
* Returns a 32 bit value read from the specified bus+device+function+register * Returns a 32 bit value read from the specified bus+device+function+register
* address in the PCI configuration address space. The address must be 32-bit * address in the PCI configuration address space. The address must be 32-bit
* aligned. * aligned.
*/ */
uint32_t pci_config_read32(int bus, int dev, int func, int reg); uint32_t pci_config_read32(int bus, int dev, int func, int reg);
/* /**
* Writes an 8 bit value to the specified bus+device+function+register address * Writes an 8 bit value to the specified bus+device+function+register address
* in the PCI configuration address space. * in the PCI configuration address space.
*/ */
void pci_config_write8(int bus, int dev, int func, int reg, uint8_t value); void pci_config_write8(int bus, int dev, int func, int reg, uint8_t value);
/* /**
* Writes a 16 bit value to the specified bus+device+function+register address * Writes a 16 bit value to the specified bus+device+function+register address
* in the PCI configuration address space. The address must be 16-bit aligned. * in the PCI configuration address space. The address must be 16-bit aligned.
*/ */
void pci_config_write16(int bus, int dev, int func, int reg, uint16_t value); void pci_config_write16(int bus, int dev, int func, int reg, uint16_t value);
/* /**
* Writes a 32 bit value to the specified bus+device+function+register address * Writes a 32 bit value to the specified bus+device+function+register address
* in the PCI configuration address space. The address must be 32-bit aligned. * in the PCI configuration address space. The address must be 32-bit aligned.
*/ */

View File

@ -1,10 +1,12 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef PMEM_H #ifndef PMEM_H
#define PMEM_H #define PMEM_H
/* /**
* \file
*
* Provides a description of the system physical memory map. * Provides a description of the system physical memory map.
* *
* Copyright (C) 2020 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
#include <stddef.h> #include <stddef.h>

View File

@ -1,22 +1,24 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef SCREEN_H #ifndef SCREEN_H
#define SCREEN_H #define SCREEN_H
/* /**
* \file
*
* Provides the display interface. It provides an 80x25 VGA-compatible text * Provides the display interface. It provides an 80x25 VGA-compatible text
* display. * display.
* *
* Copyright (C) 2020 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
#include <stdint.h> #include <stdint.h>
/* /**
* Screen size definitions. The screen size cannot be changed. * Screen size definitions. The screen size cannot be changed.
*/ */
#define SCREEN_WIDTH 80 #define SCREEN_WIDTH 80
#define SCREEN_HEIGHT 25 #define SCREEN_HEIGHT 25
/* /**
* Colours that can be used for the foreground or background. * Colours that can be used for the foreground or background.
*/ */
typedef enum { typedef enum {
@ -30,58 +32,58 @@ typedef enum {
WHITE = 7 WHITE = 7
} screen_colour_t; } screen_colour_t;
/* /**
* Modifier that can be added to any foreground colour. * Modifier that can be added to any foreground colour.
* Has no effect on background colours. * Has no effect on background colours.
*/ */
#define BOLD 8 #define BOLD 8
/* /**
* Initialise the display interface. * Initialise the display interface.
*/ */
void screen_init(void); void screen_init(void);
/* /**
* Set the foreground colour used for subsequent drawing operations. * Set the foreground colour used for subsequent drawing operations.
*/ */
void set_foreground_colour(screen_colour_t colour); void set_foreground_colour(screen_colour_t colour);
/* /**
* Set the background colour used for subsequent drawing operations. * Set the background colour used for subsequent drawing operations.
*/ */
void set_background_colour(screen_colour_t colour); void set_background_colour(screen_colour_t colour);
/* /**
* Clear the whole screen, using the current background colour. * Clear the whole screen, using the current background colour.
*/ */
void clear_screen(void); void clear_screen(void);
/* /**
* Clear the specified region of the screen, using the current background * Clear the specified region of the screen, using the current background
* colour. * colour.
*/ */
void clear_screen_region(int start_row, int start_col, int end_row, int end_col); void clear_screen_region(int start_row, int start_col, int end_row, int end_col);
/* /**
* Move the contents of the specified region of the screen up one row, * Move the contents of the specified region of the screen up one row,
* discarding the top row, and clearing the bottom row, using the current * discarding the top row, and clearing the bottom row, using the current
* background colour. * background colour.
*/ */
void scroll_screen_region(int start_row, int start_col, int end_row, int end_col); void scroll_screen_region(int start_row, int start_col, int end_row, int end_col);
/* /**
* Copy the contents of the specified region of the screen into the supplied * Copy the contents of the specified region of the screen into the supplied
* buffer. * buffer.
*/ */
void save_screen_region(int start_row, int start_col, int end_row, int end_col, uint16_t buffer[]); void save_screen_region(int start_row, int start_col, int end_row, int end_col, uint16_t buffer[]);
/* /**
* Restore the specified region of the screen from the supplied buffer. * Restore the specified region of the screen from the supplied buffer.
* This restores both text and colours. * This restores both text and colours.
*/ */
void restore_screen_region(int start_row, int start_col, int end_row, int end_col, const uint16_t buffer[]); void restore_screen_region(int start_row, int start_col, int end_row, int end_col, const uint16_t buffer[]);
/* /**
* Write the supplied character to the specified screen location, using the * Write the supplied character to the specified screen location, using the
* current foreground colour. Has no effect if the location is outside the * current foreground colour. Has no effect if the location is outside the
* screen. * screen.

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef _SMP_H_ #ifndef _SMP_H_
#define _SMP_H_ #define _SMP_H_
/* /**
* \file
*
* Provides support for multi-threaded operation. * Provides support for multi-threaded operation.
* *
* Copyright (C) 2020-2022 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
@ -15,12 +17,12 @@
#include "barrier.h" #include "barrier.h"
#include "spinlock.h" #include "spinlock.h"
/* /**
* The maximum number of CPU cores that can be used. * The maximum number of CPU cores that can be used.
*/ */
#define MAX_CPUS (1 + MAX_APS) #define MAX_CPUS (1 + MAX_APS)
/* /**
* The current state of a CPU core. * The current state of a CPU core.
*/ */
typedef enum __attribute__ ((packed)) { typedef enum __attribute__ ((packed)) {
@ -30,49 +32,49 @@ typedef enum __attribute__ ((packed)) {
CPU_STATE_HALTED = 3 CPU_STATE_HALTED = 3
} cpu_state_t; } cpu_state_t;
/* /**
* The number of available CPU cores. Initially this is 1, but may increase * The number of available CPU cores. Initially this is 1, but may increase
* after calling smp_init(). * after calling smp_init().
*/ */
extern int num_available_cpus; extern int num_available_cpus;
/* /**
* The search step that located the ACPI RSDP (for debug). * The search step that located the ACPI RSDP (for debug).
*/ */
extern const char *rsdp_source; extern const char *rsdp_source;
/* /**
* The address of the ACPI RSDP (for debug). * The address of the ACPI RSDP (for debug).
*/ */
extern uintptr_t rsdp_addr; extern uintptr_t rsdp_addr;
/* /**
* Initialises the SMP state and detects the number of available CPU cores. * Initialises the SMP state and detects the number of available CPU cores.
*/ */
void smp_init(bool smp_enable); void smp_init(bool smp_enable);
/* /**
* Starts the APs listed as enabled in cpu_state. Returns 0 on success * Starts the APs listed as enabled in cpu_state. Returns 0 on success
* or the index number of the lowest-numbered AP that failed to start. * or the index number of the lowest-numbered AP that failed to start.
*/ */
int smp_start(cpu_state_t cpu_state[MAX_CPUS]); int smp_start(cpu_state_t cpu_state[MAX_CPUS]);
/* /**
* Sends a non-maskable interrupt to the CPU core whose ordinal number * Sends a non-maskable interrupt to the CPU core whose ordinal number
* is cpu_num. * is cpu_num.
*/ */
bool smp_send_nmi(int cpu_num); bool smp_send_nmi(int cpu_num);
/* /**
* Returns the ordinal number of the calling CPU core. * Returns the ordinal number of the calling CPU core.
*/ */
int smp_my_cpu_num(void); int smp_my_cpu_num(void);
/* /**
* Allocates and initialises a barrier object in pinned memory. * Allocates and initialises a barrier object in pinned memory.
*/ */
barrier_t *smp_alloc_barrier(int num_threads); barrier_t *smp_alloc_barrier(int num_threads);
/* /**
* Allocates and initialises a spinlock object in pinned memory. * Allocates and initialises a spinlock object in pinned memory.
*/ */
spinlock_t *smp_alloc_mutex(); spinlock_t *smp_alloc_mutex();

View File

@ -1,13 +1,15 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef TEMPERATURE_H #ifndef TEMPERATURE_H
#define TEMPERATURE_H #define TEMPERATURE_H
/* /**
* \file
*
* Provides a function to read the CPU core temperature. * Provides a function to read the CPU core temperature.
* *
* Copyright (C) 2020 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
/* /**
* Returns the current temperature of the CPU. Returns 0 if * Returns the current temperature of the CPU. Returns 0 if
* the temperature cannot be read. * the temperature cannot be read.
*/ */

View File

@ -1,10 +1,12 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef TSC_H #ifndef TSC_H
#define TSC_H #define TSC_H
/* /**
* \file
*
* Provides access to the CPU timestamp counter. * Provides access to the CPU timestamp counter.
* *
* Copyright (C) 2020 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
#include <stdint.h> #include <stdint.h>
@ -22,7 +24,7 @@
: "edx" \ : "edx" \
) )
/* /**
* Reads and returns the timestamp counter value. * Reads and returns the timestamp counter value.
*/ */
static inline uint64_t get_tsc(void) static inline uint64_t get_tsc(void)

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef USB_H #ifndef USB_H
#define USB_H #define USB_H
/* /**
* \file
*
* Provides definitions of various values and data structures defined by the * Provides definitions of various values and data structures defined by the
* USB specifications. * USB specifications.
* *

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef USBHCD_H #ifndef USBHCD_H
#define USBHCD_H #define USBHCD_H
/* /**
* \file
*
* Provides the base USB host controller driver for USB keyboard support. * Provides the base USB host controller driver for USB keyboard support.
* *
* This is an object-oriented design. The hcd_methods_t structure defines * This is an object-oriented design. The hcd_methods_t structure defines
@ -25,13 +27,13 @@
#include "usb.h" #include "usb.h"
/* /**
* The size of the data transfer buffer in a host controller driver workspace. * The size of the data transfer buffer in a host controller driver workspace.
* This aligns the start of the driver private data to a 1024 byte boundary. * This aligns the start of the driver private data to a 1024 byte boundary.
*/ */
#define HCD_DATA_BUFFER_SIZE (1024 - sizeof(size_t)) #define HCD_DATA_BUFFER_SIZE (1024 - sizeof(size_t))
/* /**
* A USB device speed (used internally by the various HCI drivers). * A USB device speed (used internally by the various HCI drivers).
*/ */
typedef enum __attribute__ ((packed)) { typedef enum __attribute__ ((packed)) {
@ -41,7 +43,7 @@ typedef enum __attribute__ ((packed)) {
USB_SPEED_HIGH = 3 USB_SPEED_HIGH = 3
} usb_speed_t; } usb_speed_t;
/* /**
* A USB endpoint descriptor (used internally by the various HCI drivers). * A USB endpoint descriptor (used internally by the various HCI drivers).
*/ */
typedef struct __attribute__ ((packed)) { typedef struct __attribute__ ((packed)) {
@ -55,7 +57,7 @@ typedef struct __attribute__ ((packed)) {
uint8_t reserved; uint8_t reserved;
} usb_ep_t; } usb_ep_t;
/* /**
* A USB hub descriptor (used internally by the various HCI drivers). * A USB hub descriptor (used internally by the various HCI drivers).
*/ */
typedef struct __attribute__ ((packed)) { typedef struct __attribute__ ((packed)) {
@ -67,12 +69,12 @@ typedef struct __attribute__ ((packed)) {
uint8_t power_up_delay; uint8_t power_up_delay;
} usb_hub_t; } usb_hub_t;
/* /**
* A USB host controller driver object reference. * A USB host controller driver object reference.
*/ */
typedef const struct usb_hcd_s *usb_hcd_r; typedef const struct usb_hcd_s *usb_hcd_r;
/* /**
* A USB host controller driver method table. * A USB host controller driver method table.
*/ */
typedef struct { typedef struct {
@ -87,7 +89,7 @@ typedef struct {
uint8_t (*get_keycode) (usb_hcd_r); uint8_t (*get_keycode) (usb_hcd_r);
} hcd_methods_t; } hcd_methods_t;
/* /**
* A USB host controller driver workspace. This is extended by each HCI driver * A USB host controller driver workspace. This is extended by each HCI driver
* to append its private data. * to append its private data.
*/ */
@ -96,7 +98,7 @@ typedef struct __attribute__((packed)) {
size_t data_length; size_t data_length;
} hcd_workspace_t; } hcd_workspace_t;
/* /**
* A USB host controller driver object. * A USB host controller driver object.
*/ */
typedef struct usb_hcd_s { typedef struct usb_hcd_s {
@ -104,7 +106,7 @@ typedef struct usb_hcd_s {
hcd_workspace_t *ws; hcd_workspace_t *ws;
} usb_hcd_t; } usb_hcd_t;
/* /**
* A set of USB device initialisation options. * A set of USB device initialisation options.
*/ */
typedef enum { typedef enum {
@ -112,14 +114,14 @@ typedef enum {
USB_EXTRA_RESET = 1 USB_EXTRA_RESET = 1
} usb_init_options_t; } usb_init_options_t;
/* /**
* The selected USB device initialisation options. * The selected USB device initialisation options.
* *
* Used internally by the various HCI drivers. * Used internally by the various HCI drivers.
*/ */
extern usb_init_options_t usb_init_options; extern usb_init_options_t usb_init_options;
/* /**
* Constructs a USB setup packet in buffer using the provided values. * Constructs a USB setup packet in buffer using the provided values.
* *
* Used internally by the various HCI drivers. * Used internally by the various HCI drivers.
@ -152,7 +154,7 @@ static inline int default_max_packet_size(usb_speed_t device_speed)
} }
} }
/* /**
* Returns true if size is a valid value for the maximum packet size for a * Returns true if size is a valid value for the maximum packet size for a
* USB device running at the given speed. * USB device running at the given speed.
* *
@ -163,7 +165,7 @@ static inline bool valid_usb_max_packet_size(int size, usb_speed_t speed)
return (size == 8) || ((speed != USB_SPEED_LOW) && (size == 16 || size == 32 || size == 64)); return (size == 8) || ((speed != USB_SPEED_LOW) && (size == 16 || size == 32 || size == 64));
} }
/* /**
* Returns true if buffer appears to contain a valid USB device descriptor. * Returns true if buffer appears to contain a valid USB device descriptor.
* *
* Used internally by the various HCI drivers. * Used internally by the various HCI drivers.
@ -175,7 +177,7 @@ static inline bool valid_usb_device_descriptor(const uint8_t *buffer)
return desc->length == sizeof(usb_device_desc_t) && desc->type == USB_DESC_DEVICE; return desc->length == sizeof(usb_device_desc_t) && desc->type == USB_DESC_DEVICE;
} }
/* /**
* Returns true if buffer appears to contain a valid USB configuration * Returns true if buffer appears to contain a valid USB configuration
* descriptor. * descriptor.
* *
@ -188,7 +190,7 @@ static inline bool valid_usb_config_descriptor(const uint8_t *buffer)
return desc->length == sizeof(usb_config_desc_t) && desc->type == USB_DESC_CONFIGURATION; return desc->length == sizeof(usb_config_desc_t) && desc->type == USB_DESC_CONFIGURATION;
} }
/* /**
* Returns the USB route to the device attached to the hub port specified by * Returns the USB route to the device attached to the hub port specified by
* hub and port_num. The top 8 bits of the returned value contain the root * hub and port_num. The top 8 bits of the returned value contain the root
* port number and the bottom 20 bits contain the USB3 route string. * port number and the bottom 20 bits contain the USB3 route string.
@ -197,7 +199,7 @@ static inline bool valid_usb_config_descriptor(const uint8_t *buffer)
*/ */
uint32_t usb_route(const usb_hub_t *hub, int port_num); uint32_t usb_route(const usb_hub_t *hub, int port_num);
/* /**
* Waits for all the bits set in bit_mask to be cleared in the register pointed * Waits for all the bits set in bit_mask to be cleared in the register pointed
* to by reg or for max_time microseconds to elapse. * to by reg or for max_time microseconds to elapse.
* *
@ -205,7 +207,7 @@ uint32_t usb_route(const usb_hub_t *hub, int port_num);
*/ */
bool wait_until_clr(const volatile uint32_t *reg, uint32_t bit_mask, int max_time); bool wait_until_clr(const volatile uint32_t *reg, uint32_t bit_mask, int max_time);
/* /**
* Waits for all the bits set in bit_mask to also be set in the register pointed * Waits for all the bits set in bit_mask to also be set in the register pointed
* to by reg or for max_time microseconds to elapse. * to by reg or for max_time microseconds to elapse.
* *
@ -213,7 +215,7 @@ bool wait_until_clr(const volatile uint32_t *reg, uint32_t bit_mask, int max_tim
*/ */
bool wait_until_set(const volatile uint32_t *reg, uint32_t bit_mask, int max_time); bool wait_until_set(const volatile uint32_t *reg, uint32_t bit_mask, int max_time);
/* /**
* Displays an informational message, scrolling the screen if necessary. * Displays an informational message, scrolling the screen if necessary.
* Takes the same arguments as the printf function. * Takes the same arguments as the printf function.
* *
@ -221,14 +223,14 @@ bool wait_until_set(const volatile uint32_t *reg, uint32_t bit_mask, int max_tim
*/ */
void print_usb_info(const char *fmt, ...); void print_usb_info(const char *fmt, ...);
/* /**
* Resets the specified USB hub port. * Resets the specified USB hub port.
* *
* Used internally by the various HCI drivers. * Used internally by the various HCI drivers.
*/ */
bool reset_usb_hub_port(const usb_hcd_t *hcd, const usb_hub_t *hub, int port_num); bool reset_usb_hub_port(const usb_hcd_t *hcd, const usb_hub_t *hub, int port_num);
/* /**
* Sets the device address for the device attached to the specified hub port * Sets the device address for the device attached to the specified hub port
* (thus moving the device to Address state), fills in the descriptor for the * (thus moving the device to Address state), fills in the descriptor for the
* device's default control endpoint (ep0), and leaves the device descriptor * device's default control endpoint (ep0), and leaves the device descriptor
@ -240,7 +242,7 @@ bool reset_usb_hub_port(const usb_hcd_t *hcd, const usb_hub_t *hub, int port_num
bool assign_usb_address(const usb_hcd_t *hcd, const usb_hub_t *hub, int port_num, bool assign_usb_address(const usb_hcd_t *hcd, const usb_hub_t *hub, int port_num,
usb_speed_t device_speed, int device_id, usb_ep_t *ep0); usb_speed_t device_speed, int device_id, usb_ep_t *ep0);
/* /**
* Scans the specified USB device to detect whether it has any HID keyboards * Scans the specified USB device to detect whether it has any HID keyboards
* attached to it (directly or indirectly). If so, the keyboard device(s) * attached to it (directly or indirectly). If so, the keyboard device(s)
* are initialised and configured, as are any intermediate USB hubs, and the * are initialised and configured, as are any intermediate USB hubs, and the
@ -254,7 +256,7 @@ bool find_attached_usb_keyboards(const usb_hcd_t *hcd, const usb_hub_t *hub, int
usb_speed_t device_speed, int device_id, int *num_devices, usb_speed_t device_speed, int device_id, int *num_devices,
usb_ep_t keyboards[], int max_keyboards, int *num_keyboards); usb_ep_t keyboards[], int max_keyboards, int *num_keyboards);
/* /**
* Scans the attached USB devices and initialises all HID keyboard devices * Scans the attached USB devices and initialises all HID keyboard devices
* it finds (subject to implementation limits on the number of devices). * it finds (subject to implementation limits on the number of devices).
* Records the information needed to subsequently poll those devices for * Records the information needed to subsequently poll those devices for
@ -264,7 +266,7 @@ bool find_attached_usb_keyboards(const usb_hcd_t *hcd, const usb_hub_t *hub, int
*/ */
void find_usb_keyboards(bool pause_at_end); void find_usb_keyboards(bool pause_at_end);
/* /**
* Polls the keyboards discovered by find_usb_keyboards. Consumes and returns * Polls the keyboards discovered by find_usb_keyboards. Consumes and returns
* the HID key code for the first key press it detects. Returns zero if no key * the HID key code for the first key press it detects. Returns zero if no key
* has been pressed. * has been pressed.

View File

@ -1,11 +1,13 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef VMEM_H #ifndef VMEM_H
#define VMEM_H #define VMEM_H
/* /**
* \file
*
* Provides functions to handle physical memory page mapping into virtual * Provides functions to handle physical memory page mapping into virtual
* memory. * memory.
* *
* Copyright (C) 2020-2021 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.
*/ */
#include <stdbool.h> #include <stdbool.h>

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef XHCI_H #ifndef XHCI_H
#define XHCI_H #define XHCI_H
/* /**
* \file
*
* Provides support for USB keyboards connected via an XHCI controller. * Provides support for USB keyboards connected via an XHCI controller.
* *
* Copyright (C) 2021-2022 Martin Whitaker. * Copyright (C) 2021-2022 Martin Whitaker.
@ -11,7 +13,7 @@
#include "usbhcd.h" #include "usbhcd.h"
/* /**
* Initialises the XHCI device found at base_addr, scans all the attached USB * Initialises the XHCI device found at base_addr, scans all the attached USB
* devices, and configures any HID USB keyboard devices it finds to generate * devices, and configures any HID USB keyboard devices it finds to generate
* periodic interrupt transfers that report key presses. Initialises hcd and * periodic interrupt transfers that report key presses. Initialises hcd and

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef TEST_FUNCS_H #ifndef TEST_FUNCS_H
#define TEST_FUNCS_H #define TEST_FUNCS_H
/* /**
* \file
*
* Provides the prototypes for the basic test functions used to implement * Provides the prototypes for the basic test functions used to implement
* the tests. * the tests.
* *

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef TEST_HELPER_H #ifndef TEST_HELPER_H
#define TEST_HELPER_H #define TEST_HELPER_H
/* /**
* \file
*
* Provides some common definitions and helper functions for the memory * Provides some common definitions and helper functions for the memory
* tests. * tests.
* *
@ -13,7 +15,7 @@
#include "test.h" #include "test.h"
/* /**
* Test word atomic read and write functions. * Test word atomic read and write functions.
*/ */
#ifdef __x86_64__ #ifdef __x86_64__
@ -26,24 +28,24 @@
#define write_word write32 #define write_word write32
#endif #endif
/* /**
* A wrapper for guiding branch prediction. * A wrapper for guiding branch prediction.
*/ */
#define unlikely(x) __builtin_expect(!!(x), 0) #define unlikely(x) __builtin_expect(!!(x), 0)
/* /**
* The block size processed between each update of the progress bars and * The block size processed between each update of the progress bars and
* spinners. This also affects how quickly the program will respond to the * spinners. This also affects how quickly the program will respond to the
* keyboard. * keyboard.
*/ */
#define SPIN_SIZE (1 << 27) // in testwords #define SPIN_SIZE (1 << 27) // in testwords
/* /**
* A macro to perform test bailout when requested. * A macro to perform test bailout when requested.
*/ */
#define BAILOUT if (bail) return ticks #define BAILOUT if (bail) return ticks
/* /**
* Returns value rounded down to the nearest multiple of align_size. * Returns value rounded down to the nearest multiple of align_size.
*/ */
static inline uintptr_t round_down(uintptr_t value, size_t align_size) static inline uintptr_t round_down(uintptr_t value, size_t align_size)
@ -51,7 +53,7 @@ static inline uintptr_t round_down(uintptr_t value, size_t align_size)
return value & ~(align_size - 1); return value & ~(align_size - 1);
} }
/* /**
* Returns value rounded up to the nearest multiple of align_size. * Returns value rounded up to the nearest multiple of align_size.
*/ */
static inline uintptr_t round_up(uintptr_t value, size_t align_size) static inline uintptr_t round_up(uintptr_t value, size_t align_size)
@ -59,26 +61,26 @@ static inline uintptr_t round_up(uintptr_t value, size_t align_size)
return (value + (align_size - 1)) & ~(align_size - 1); return (value + (align_size - 1)) & ~(align_size - 1);
} }
/* /**
* Seeds the psuedo-random number generator for my_cpu. * Seeds the psuedo-random number generator for my_cpu.
*/ */
void random_seed(int my_cpu, uint64_t seed); void random_seed(int my_cpu, uint64_t seed);
/* /**
* Returns a psuedo-random number for my_cpu. The sequence of numbers returned * Returns a psuedo-random number for my_cpu. The sequence of numbers returned
* is repeatable for a given starting seed. The sequence repeats after 2^64 - 1 * is repeatable for a given starting seed. The sequence repeats after 2^64 - 1
* numbers. Within that period, no number is repeated. * numbers. Within that period, no number is repeated.
*/ */
testword_t random(int my_cpu); testword_t random(int my_cpu);
/* /**
* Calculates the start and end word address for the chunk of segment that is * Calculates the start and end word address for the chunk of segment that is
* to be tested by my_cpu. The chunk start will be aligned to a multiple of * to be tested by my_cpu. The chunk start will be aligned to a multiple of
* chunk_align. * chunk_align.
*/ */
void calculate_chunk(testword_t **start, testword_t **end, int my_cpu, int segment, size_t chunk_align); void calculate_chunk(testword_t **start, testword_t **end, int my_cpu, int segment, size_t chunk_align);
/* /**
* Flushes the CPU caches. If SMP is enabled, synchronises the threads before * Flushes the CPU caches. If SMP is enabled, synchronises the threads before
* and after issuing the cache flush instruction. * and after issuing the cache flush instruction.
*/ */

View File

@ -1,7 +1,9 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#ifndef TESTS_H #ifndef TESTS_H
#define TESTS_H #define TESTS_H
/* /**
* \file
*
* Provides support for identifying and running the memory tests. * Provides support for identifying and running the memory tests.
* *
* Copyright (C) 2020-2022 Martin Whitaker. * Copyright (C) 2020-2022 Martin Whitaker.