Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
df969e1
Datetime and puts
May 21, 2025
91b3363
Datetime and puts
May 21, 2025
02c19a7
puts only
May 21, 2025
98a4f96
foo
May 21, 2025
7aa6427
puts only
May 21, 2025
bd233a5
Makefile
May 21, 2025
e985642
printf.h
May 21, 2025
9ed8451
puts only
May 21, 2025
f9dd491
misc
May 21, 2025
ad4b0de
misc
May 21, 2025
fa0e8b8
Added optional arguments for puts and documentation
May 22, 2025
5194bfe
Added optional arguments for puts and documentation
May 22, 2025
b9df0d0
misc
May 22, 2025
3aa2390
Added documentation from printf branch
May 22, 2025
0927fc5
Added comments
May 22, 2025
387993f
Added doc/contents/datetime.tex for timekeeping documentation
May 22, 2025
2db4ab5
Main branch
May 22, 2025
25e88f0
merge test
May 22, 2025
f95ee56
Merge Fix
May 22, 2025
25e8b80
Merge Fix
May 22, 2025
35b0037
puts with options
May 22, 2025
408be44
puts with options
May 22, 2025
a706c3a
fix merge conflict issue
chrisdedman May 22, 2025
24afaeb
fix merge conflict issue
chrisdedman May 22, 2025
e7d9b70
fix merge conflict issue
chrisdedman May 22, 2025
7ee94be
Added TODO comment for case 'e' printf testing
chrisdedman May 22, 2025
9a481fb
Adding INFO + TODO comment for future implementation
chrisdedman May 23, 2025
6c73c09
renamed puts() to printf(), and kept original puts() available
chrisdedman May 23, 2025
2373b0e
adding printf function declaration to header file
chrisdedman May 23, 2025
23499e4
Change puts() to printf() from function testing
chrisdedman May 23, 2025
5e0b72c
Refactored printf
May 24, 2025
7715471
Refactored printf
May 24, 2025
6e96429
Refactored printf
May 24, 2025
0afb533
reverse change in the doc
chrisdedman May 24, 2025
9c92ab1
Reverse printf for puts for printing the banner
chrisdedman May 24, 2025
2fef6d9
Added TODO for invlaid format error handling
chrisdedman May 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ VPATH := $(SRC_DIRS)
all: clean kernel.bin qemu

# Assembly start.o goes to build/
$(OUT_DIR)start.o: kernel/start.S
$(OUT_DIR)start.o: kernel/start.s
@mkdir -p $(OUT_DIR)
$(AS) -c $< -o $@

Expand All @@ -53,4 +53,4 @@ qemu:
@echo "Press Ctrl-A then X to exit QEMU"
@qemu-system-arm -M versatilepb -nographic -kernel $(OUT_DIR)kernel.bin

.PHONY: all clean qemu
.PHONY: all clean qemu
4 changes: 2 additions & 2 deletions doc/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# esclude the /bin directory
# exclude the /bin directory
# This is the directory where the compiled files are stored
# It is not necessary to include it in the repository
/bin
/bin
60 changes: 60 additions & 0 deletions doc/contents/puts.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
\documentclass{article}
\usepackage{listings}
\usepackage{geometry}
\geometry{margin=1in}
\title{I/O API}
\date{}
\begin{document}

\maketitle

\section*{puts(char *s, ...)}
\subsection*{Description}
Sends a null-terminated format string over UART. If an incorrect datatype is given for a format specifier, \underline{the behavior is undefined}. If a format specifier is given without a matching argument, it is simply skipped when the string is outputted. The following format specifiers are supported:

\begin{itemize}
\item \textbf{\%c}: Expects a single character.
\item \textbf{\%s}: Expects a null-terminated string.
\item \textbf{\%d}: For 32-bit signed integers in the range \texttt{-2147483648} to \texttt{2147483647}.
\item \textbf{\%ld}: For 64-bit signed integers in the range \texttt{-9223372036854775808} to \texttt{9223372036854775807}, excluding the range specified above, for \textbf{\%d}.
\item \textbf{\%lu}: For 64-bit unsigned integers in the range \texttt{2147483648} to \texttt{18446744073709551615}.
\item \textbf{\%x} and \textbf{\%X}: For 32-bit unsigned integers in the range \texttt{0} to \texttt{2147483647}, where the case of \texttt{x} determines the case of the hexadecimal digits (\texttt{a-f} or \texttt{A-F}).
\item \textbf{\%lx} and \textbf{\%lX}: For 64-bit unsigned integers printed in hexadecimal format. Has the same range as \textbf{\%lu}. The case of \texttt{x} determines the case of the hexadecimal digits (\texttt{a-f} or \texttt{A-F}).
\item \textbf{\%\%}: Outputs a '\%'.
\end{itemize}

\begin{flushleft}
All the ranges specified above are inclusive. Also, note that integers in the range \texttt{-2147483648} to \texttt{2147483647} are passed as 32 bit integers and any integers not part of this range are passed as 64 bit integers \underline{by default}.
If desired, integers of this range can be cast as \texttt{long long} or \texttt{unsigned long long}
\newline
for use with the format specifiers prefixed by \textbf{l}(ell).
\end{flushleft}

\subsection*{Examples}
\begin{lstlisting}[language=C,showstringspaces=false]
// Printing long long integers
puts("%lu %ld %ld\n", 18446744073709551615, -9223372036854775808,
9223372036854775807);

// Printing 32-bit signed integers
puts("%d %d\n", 2147483647, -2147483648);

// Printing 32-bit unsigned integers
puts("%x %x %X %X\n", 2147483647, 1234, 2147483647, 1234);
// Output: 7fffffff 4d2 7FFFFFFF 4D2

// Printing unsigned long long integers in hex
puts("%lX %lx\n", 0x123456789ABCDEF0, 9223372036854775809);
// Output: 123456789ABCDEF0 8000000000000001

// Printing a character
puts("Name: %c\n", 'b');

// Printing a string
puts("Hello %s\n", "World");

// Printing a '%'
puts("100%%\n");
\end{lstlisting}

\end{document}
Binary file modified doc/figures/bootedKernel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/preamble/macros.tex
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@
}{%
\end{quote}\par\medskip
}
\makeatother
\makeatother
14 changes: 9 additions & 5 deletions include/printf.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#ifndef PRINTF_H
#define PRINTF_H

#include <stdarg.h>
#include <stddef.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif

void putc(char c);
void puts(const char *s);
char getc(void);
void getlines(char *restrict buffer, size_t length);
void putc(char c);
void puts(const char *s);
void printf(char *s, ...);
char getc(void);
void getlines(char *restrict buffer, size_t length);

#ifdef __cplusplus
}
Expand Down
41 changes: 25 additions & 16 deletions kernel/kernel.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdbool.h>
#include <stddef.h>

#include "printf.h"
#include "clear.h"
Expand All @@ -14,8 +15,7 @@ static const char *banner[] = {
"\r\n",
"Welcome to your own little Astra world!\r\n",
"Type away, explore, have fun.\r\n",
"\r\n"
};
"\r\n"};

// Initializes and prints the welcome banner.
static void init_message(void)
Expand All @@ -32,41 +32,50 @@ void kernel_main(void)
clear();

init_message();
puts("AstraKernel is running...\r\n");
puts("Press Ctrl-A and then X to exit QEMU.\r\n");
puts("\r\n");
printf("AstraKernel is running...\r\n");
printf("Press Ctrl-A and then X to exit QEMU.\r\n");
printf("\r\n");

char input_buffer[100];

bool is_running = true;
while (is_running)
{
input_buffer[0] = '\0'; // Clear the input buffer
puts("AstraKernel > ");
printf("AstraKernel > ");
getlines(input_buffer, sizeof(input_buffer));
puts("\r\n");

printf("\r\n");

switch (input_buffer[0])
{
case 'h': // Check for help command
puts("\nHelp: Press 'q' to exit, 'h' for help.\r\n");
printf("\nHelp:\n 'q' to exit\n 'h' for help\n 'c' to clear screen\n 't' to print current time\n 'd' to print current date\r\n");
break;
case 'e': // TODO: This is for testing purposes. Remove once not needed
printf("%ld %ld %ld\n", 0, -9223372036854775808, 9223372036854775807);
printf("%d %d\n", 2147483647, -2147483648);
printf("%x %lx %lX %X\n", 2147483647, 2147483649, 2147483648, 1234);
printf("%lX %x %lx\n", 0x123456789abcdef0, 1234, 9223372036854775809);
printf("Name: %c\n", 'b');
printf("Hello %s\n", "World");
printf("100%%\n");
break;
case 'q': // Check for exit command
puts("Exiting...\r\n");
printf("Exiting...\r\n");
is_running = false;
break;
case 'c': // Cjeck for clear screen command
case 'c': // Check for clear screen command
clear();
break;
case 't': // Check for time command
puts("Current time: 12:00 PM\r\n"); // TO-DO: Implement real time check
case 't': // Check for time command
printf("Current time: 12:00 PM\r\n"); // TO-DO: Implement real time check
break;
case 'd': // Check for date command
puts("Current date: 2023-10-01\r\n"); // TO-DO: Implement real date check
case 'd': // Check for date command
printf("Current date: 2023-10-01\r\n"); // TO-DO: Implement real date check
break;
default:
puts("Unknown command. Type 'h' for help.\r\n");
printf("Unknown command. Type 'h' for help.\r\n");
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions user/clear.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
// Clears the terminal screen and moves the cursor to the home position.
void clear(void)
{
puts("\x1B[2J");
puts("\x1B[H");
printf("\x1B[2J");
printf("\x1B[H");
}
Loading