/** @file console.h
* @brief Function prototypes for the console driver.
*
* This contains the prototypes for the console
* driver and eventually any macros, constants,
* or global variables you will need.
*
* @author Harry Q. Bovik (hqbovik)
* @author Fred Hacker (fhacker)
* @bug No known bugs.
*/#ifndef _MY_CONSOLE_H
#define _MY_CONSOLE_H
#include<video_defines.h>/** @brief Prints character ch at the current location
* of the cursor.
*
* If the character is a newline ('\n'), the cursor should
* be moved to the next line (scrolling if necessary). If
* the character is a carriage return ('\r'), the cursor
* should be immediately reset to the beginning of the current
* line, causing any future output to overwrite any existing
* output on the line. If backsapce ('\b') is encountered,
* the previous character should be erased (write a space
* over it and move the cursor back one column). It is up
* to you how you want to handle a backspace occurring at the
* beginning of a line.
*
* @param ch the character to print
* @return The input character
*/intputbyte(charch);/** @brief Prints the string s, starting at the current
* location of the cursor.
*
* If the string is longer than the current line, the
* string should fill up the current line and then
* continue on the next line. If the string exceeds
* available space on the entire console, the screen
* should scroll up one line, and then the string should
* continue on the new line. If '\n', '\r', and '\b' are
* encountered within the string, they should be handled
* as per putbyte. If len is not a positive integer or s
* is null, the function has no effect.
*
* @param s The string to be printed.
* @param len The length of the string s.
* @return Void.
*/voidputbytes(constchar*s,intlen);/** @brief Changes the foreground and background color
* of future characters printed on the console.
*
* If the color code is invalid, the function has no effect.
*
* @param color The new color code.
* @return Void.
*/voidset_term_color(intcolor);/** @brief Writes the current foreground and background
* color of characters printed on the console
* into the argument color.
* @param color The address to which the current color
* information will be written.
* @return Void.
*/voidget_term_color(int*color);/** @brief Sets the position of the cursor to the
* position (row, col).
*
* Subsequent calls to putbytes should cause the console
* output to begin at the new position. If the cursor is
* currently hidden, a call to set_cursor() must not show
* the cursor.
*
* @param row The new row for the cursor.
* @param col The new column for the cursor.
* @return Void.
*/voidset_cursor(introw,intcol);/** @brief Writes the current position of the cursor
* into the arguments row and col.
* @param row The address to which the current cursor
* row will be written.
* @param col The address to which the current cursor
* column will be written.
* @return Void.
*/voidget_cursor(int*row,int*col);/** @brief Hides the cursor.
*
* Subsequent calls to putbytes must not cause the
* cursor to show again.
*
* @return Void.
*/voidhide_cursor();/** @brief Shows the cursor.
*
* If the cursor is already shown, the function has no effect.
*
* @return Void.
*/voidshow_cursor();/** @brief Clears the entire console.
* @return Void.
*/voidclear_console();/** @brief Prints character ch with the specified color
* at position (row, col).
*
* If any argument is invalid, the function has no effect.
*
* @param row The row in which to display the character.
* @param col The column in which to display the character.
* @param ch The character to display.
* @param color The color to use to display the character.
* @return Void.
*/voiddraw_char(introw,intcol,intch,intcolor);/** @brief Returns the character displayed at position (row, col).
* @param row Row of the character.
* @param col Column of the character.
* @return The character at (row, col).
*/charget_char(introw,intcol);#endif /* _MY_CONSOLE_H */
/** @file console.c
* @brief A console driver.
*
* These empty function definitions are provided
* so that stdio will build without complaining.
* You will need to fill these functions in. This
* is the implementation of the console driver.
* Important details about its implementation
* should go in these comments.
*
* @author Harry Q. Bovik (hqbovik)
* @author Fred Hacker (fhacker)
* @bug No know bugs.
*/#include<console.h>intputbyte(charch){returnch;}voidputbytes(constchar*s,intlen){}voidset_term_color(intcolor){}voidget_term_color(int*color){}voidset_cursor(introw,intcol){}voidget_cursor(int*row,int*col){}voidhide_cursor(){}voidshow_cursor(){}voidclear_console(){}voiddraw_char(introw,intcol,intch,intcolor){}
/** @file kernel.c
* @brief An initial kernel.c
*
* This file contains the kernel's
* main() function.
*
* You should add your own comments to
* replace this one.
*
* This is where you will eventually setup
* your game board and have it run.
*
* @author Harry Q. Bovik (hqbovik)
* @author Fred Hacker (fhacker)
* @bug No known bugs.
*//* -- Includes -- *//* libc includes. */#include<stdio.h> /* for lprintf_kern() *//* multiboot header file */#include<multiboot.h> /* for boot_info *//* memory includes. */#include<lmm.public.h> /* for lmm_remove_free() *//* x86 specific includes */#include<x86/seg.h> /* for install_user_segs() */#include<x86/pic.h> /* for pic_init() */#include<x86/base_irq.h> /* for base_irq_master/slave *//*
* state for kernel memory allocation.
*/externlmm_tmalloc_lmm;/*
* Info about system gathered by the boot loader
*/externstructmultiboot_infoboot_info;/** @brief Kernel entrypoint.
*
* This is the entrypoint for your kernel.
* You will use this to test and debug your
* drivers and it will eventually hold the
* code for your game. Right now, it is
* A tight while loop.
*
* @return Should not return
*/intmain(){/*
* Tell the kernel memory allocator which memory it can't use.
* It already knows not to touch kernel image.
*/lmm_remove_free(&malloc_lmm,(void*)USER_MEM_START,USER_MEM_SIZE);lmm_remove_free(&malloc_lmm,(void*)0,0x100000);/*
* Install interrupt handlers here.
*//*
* initialize the PIC so that IRQs and
* exception handlers don't overlap in the IDT.
*/pic_init(BASE_IRQ_MASTER_BASE,BASE_IRQ_SLAVE_BASE);lprintf_kern("Hello from a brand new kernel!");while(1);return0;}
enum
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/// @brief Mathematical error code
enumclassMathErrorCode:std::uint32_t{/// Bit 0 (value 0x00 or 0) not set => Means no error
E_OK=0x00,/// bit 0 (value 0x01 or 1) means that an error of any type happened
E_ERROR=0x01,/// bit 1 (value 0x02 or 2) Overflow error
E_OVERFLOW=0x02,/// bit 2 (value 0x04 or 4) Undeflow error
E_UNDERFLOW=0x04,/// bit 3 (value 0x08 or 8) Not a number
E_NAN=0x08,/// bit 4 (value 0x10 or 16) Root, series or algorithm result doesn't converge.
E_CONVERGENCE=0x10,/// bit 5 (value 0x20 or 16) Maximum iterations reached
E_MAX_ITER=0x20};
/** @brief C++ implementation of Fotran BLAS daxypy
Computes the equation ys[i] <- xs[i] * alpha + beta
@note Function with C-linkage.
@param[in] n Array size. Size of xs and ys
@param[in] xs Input array xs
@param[in, out] ys Output array ys
@param[in] alpha Linear coefficient
@return Void
*/extern"C"autodaxpy(size_tn,doubleconst*xs,double*ys,doublealpha,doublebeta)->void;nitialguess/// @param eps Tolerance for stopping criteria.
/// @return Equation result as a float point type T.
///
/// @details
/// Solves non-linear equation using Newton method. This function needs two
/// functions, the function to be solved @p fun and its derivate @p dfun
///
/// @note The function f(x) must be continues and differentiable.
/// @warning Throws NonCoverge exception when the root is not found.
///
/// @see NewtonSolver
/// @see https://en.wikipedia.org/wiki/Newton%27s_method
///
/// @par Example:
/// @code
/// // Solve f(x) = x^2 - 25.0 , df(x) = 2x around x0 = 10.0
/// auto fun = [](double x){ return x * x - 25.0 };
/// auto dfun = [](double x){ return 2 * x; }
///
/// double root = GenericNewtonsolver(fun, dfun, 10.0, 0.001);
/// std::cout << "Root = " << root << std::endl;
/// @endcode
///
template<typenameT>autoGenericNewtonSolver(MathFuncGen<T>fun,MathFuncGen<T>dfun,Tx0,Teps)->T;}// --- End of Namespace MathUtils::Solvers ----//