...
 
Commits (2)
......@@ -2,10 +2,10 @@
//#define DEBUG
#include "alloc.h"
#include "errno.h"
#include "klibc.h"
#include "list.h"
#include "math.h"
#include "mem.h"
#include "vga.h"
#define IS_SELF_CONTAINED(desc) ((vaddr_t)((desc)->page) == (vaddr_t)(desc))
// Slab will contains object from sizeof(void *) to PAGE_SIZE/2 by pow2
......
#pragma once
#include "stack.h"
#include "vga.h"
#include "klibc.h"
#define assert(p) do { \
if (!(p)) { \
......
#include "klibc.h"
#include "serial.h"
#include "vga.h"
int memcmp(const void* aptr, const void* bptr, size_t size) {
const unsigned char* a = (const unsigned char*) aptr;
const unsigned char* b = (const unsigned char*) bptr;
for (size_t i = 0; i < size; i++) {
if (a[i] < b[i])
return -1;
else if (b[i] < a[i])
return 1;
}
return 0;
int memcmp(const void *aptr, const void *bptr, size_t size)
{
const unsigned char *a = (const unsigned char *)aptr;
const unsigned char *b = (const unsigned char *)bptr;
for (size_t i = 0; i < size; i++) {
if (a[i] < b[i])
return -1;
else if (b[i] < a[i])
return 1;
}
return 0;
}
void *memcpy(void *dst, const void *src, size_t n)
{
char *dstChar = dst;
const char *srcChar = src;
for (size_t i = 0; i < n; i++) {
*(dstChar++) = *(srcChar++);
}
return dst;
char *dstChar = dst;
const char *srcChar = src;
for (size_t i = 0; i < n; i++) {
*(dstChar++) = *(srcChar++);
}
return dst;
}
void *memset(void *src, int c, size_t n)
{
for (char *ptr = (char *)src; n > 0; n--, ptr++) {
*ptr = (char)c;
}
return src;
for (char *ptr = (char *)src; n > 0; n--, ptr++) {
*ptr = (char)c;
}
return src;
}
char * itoa( int value, char * str, int base )
char *itoa(int value, char *str, int base)
{
char * rc;
char * ptr;
char * low;
char *rc;
char *ptr;
char *low;
// Check for supported base.
if ( base < 2 || base > 36 )
{
if (base < 2 || base > 36) {
*str = '\0';
return str;
}
rc = ptr = str;
// Set '-' for negative decimals.
if ( value < 0 && base == 10 )
{
if (value < 0 && base == 10) {
*ptr++ = '-';
}
// Remember where the numbers start.
low = ptr;
// The actual conversion.
do
{
do {
// Modulo is negative for negative value. This trick makes abs() unnecessary.
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + value % base];
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"
[35 + value % base];
value /= base;
} while ( value );
} while (value);
// Terminating the string.
*ptr-- = '\0';
// Invert the numbers.
while ( low < ptr )
{
while (low < ptr) {
char tmp = *low;
*low++ = *ptr;
*ptr-- = tmp;
*low++ = *ptr;
*ptr-- = tmp;
}
return rc;
}
......@@ -99,3 +99,90 @@ int strcmp(char s1[], char s2[])
}
return s1[i] - s2[i];
}
void printf(const char *format, ...)
{
va_list ap;
va_start(ap, format);
vprintf(format, ap);
va_end(ap);
}
void puts(const char *str)
{
while (*str) {
putc(*(str++));
}
}
void putc(const char str){
VGAputc(str);
serialPutc(str);
}
void printInt(int integer)
{
char num[sizeof(int) * 3]; // int max is 2^(sizeof(int)*8) which is (2^3)^(sizeof(int)*8/3)
// = 8^(sizeof(int)*8/3) ~ 10^(sizeof(int)*8/3)
int i = 0, k = 0;
if (integer < 0) {
putc('-');
}
if (integer == 0) {
num[i++] = 0;
}
while (integer != 0) {
int digit = integer % 10;
num[i++] = (digit > 0) ? digit : -digit;
integer = integer / 10;
}
for (k = i - 1; k >= 0; k--) {
putc(num[k] + '0');
}
}
void vprintf(const char *format, va_list ap)
{
int i = 0;
while (format[i] != '\0') {
switch (format[i]) {
case '%':
switch (format[i + 1]) {
case 'i':
case 'd': {
int d = va_arg(ap, int);
printInt(d);
break;
}
case 'x': {
char val[sizeof(int) * 2];
int d = va_arg(ap, int);
itoa(d, val, 16);
puts(val);
break;
}
case 'c': {
int c = va_arg(ap, int);
putc((char)c);
break;
}
case 's': {
char *str = va_arg(ap, char *);
if (!str)
str = "[NULL STR]";
puts(str);
break;
}
case '%':
putc('%');
break;
}
i++;
break;
default:
putc(format[i]);
}
i++;
}
}
......@@ -16,3 +16,30 @@ char *itoa(int value, char *str, int base);
void reverse(char s[]);
int strlen(char s[]);
int strcmp(char s1[], char s2[]);
void puts(const char *str);
void putc(const char str);
void printInt(int integer);
void vprintf(const char *format, va_list ap);
void printf(const char *format, ...);
/*
* Dummy printk for disabled debugging statements to use whilst maintaining
* gcc's format checking.
*/
#define no_printf(fmt, ...) \
({ \
if (0) \
printf(fmt, ##__VA_ARGS__); \
0; \
})
#ifdef DEBUG
#define pr_devel(fmt, ...) \
printf(pr_fmt(fmt), ##__VA_ARGS__)
#else
#define pr_devel(fmt, ...) \
no_printf(pr_fmt(fmt), ##__VA_ARGS__)
#endif
#define pr_info(fmt, ...) \
printf(pr_fmt(fmt), ##__VA_ARGS__)
#include "mem.h"
#include "list.h"
#include "types.h"
#include "vga.h"
#include "klibc.h"
static struct mem_desc *page_desc = (struct mem_desc *)&__ld_kernel_end;
static struct mem_desc *free_page;
......
......@@ -3,7 +3,6 @@
#include "klibc.h"
#include "mem.h"
#include "stdarg.h"
#include "vga.h"
// In a Vaddr, 10 first bit (MSB) are the index in the Page Directory. A Page Directory Entry
// point to a Page Table. The 10 next bits are then an index in this Page Table. A Page Table
......
#include "stack.h"
#include "types.h"
#include "vga.h"
#include "klibc.h"
extern vaddr_t _stack_bottom;
extern vaddr_t _stack_top;
......
#include "keyboard.h"
#include "klibc.h"
#include "io.h"
#include "vga.h"
const char *scancode[128] = {
/* 0 */ 0,
......
#include "serial.h"
#include "io.h"
#include "irq.h"
#include "vga.h"
#define PORT 0x3f8 /* COM1 */
#define SERIAL_MAX_SPEED 115200
......@@ -40,7 +39,7 @@ int isTransmitEmpty()
return (inb(PORT + 5) & 0x20);
}
void serialWrite(char a)
void serialPutc(char a)
{
while (isTransmitEmpty() == 0)
;
......@@ -52,5 +51,5 @@ void serialDoIrq(struct interrupt_frame *level)
{
(void)level;
char c = inb(PORT);
serialWrite(c);
serialPutc(c);
}
......@@ -2,5 +2,5 @@
#include "irq.h"
void serialSetup(int speed);
void serialWrite(char a);
void serialPutc(char a);
void serialDoIrq(struct interrupt_frame *frame);
......@@ -34,28 +34,6 @@ void clearScreenLine(uint bgColor, uint line)
}
}
void printInt(int integer)
{
char num[sizeof(int) *
3]; // int max is 2^(sizeof(int)*8) which is (2^3)^(sizeof(int)*8/3) =
// 8^(sizeof(int)*8/3) ~ 10^(sizeof(int)*8/3)
int i = 0, k = 0;
if (integer < 0) {
printChar('-');
}
if (integer == 0) {
num[i++] = 0;
}
while (integer != 0) {
int digit = integer % 10;
num[i++] = (digit > 0) ? digit : -digit;
integer = integer / 10;
}
for (k = i - 1; k >= 0; k--) {
printChar(num[k] + '0');
}
}
void printIntDetails(int integer, uint color, uint bgColor, int startX, int startY)
{
char num[sizeof(int) *
......@@ -100,68 +78,9 @@ void vgaScrollUp(void)
}
}
void vprintf(const char *format, va_list ap)
{
int i = 0;
while (format[i] != '\0') {
switch (format[i]) {
case '%':
switch (format[i + 1]) {
case 'i':
case 'd': {
int d = va_arg(ap, int);
printInt(d);
break;
}
case 'x': {
char val[sizeof(int) * 2];
int d = va_arg(ap, int);
itoa(d, val, 16);
printString(val);
break;
}
case 'c': {
int c = va_arg(ap, int);
printChar((char)c);
break;
}
case 's': {
char *str = va_arg(ap, char *);
if (!str)
str = "[NULL STR]";
printString(str);
break;
}
case '%':
printChar('%');
break;
}
i++;
break;
default:
printChar(format[i]);
}
i++;
}
}
void printf(const char *format, ...)
{
va_list ap;
va_start(ap, format);
vprintf(format, ap);
va_end(ap);
}
void printString(const char *str)
{
while (*str) {
printChar(*(str++));
}
}
void printChar(const char str)
void VGAputc(const char str)
{
if (str == '\n') {
line++;
......
......@@ -21,40 +21,15 @@
#define pr_fmt(fmt) fmt
#endif
void vprintf(const char *format, va_list ap);
void printf(const char *format, ...);
int VGASetup(uint bgColor, uint color);
void VGAputc(const char str);
void clearScreen(uint bgColor);
void clearScreenLine(uint bgColor, uint line);
void printInt(int integer);
void printIntDetails(int integer, uint color, uint bgColor, int startX, int startY);
void printCharDetails(char str, uint color, uint bgColor, int startX, int startY);
void printStringDetails(const char *str, uint color, uint bgColor, int startX, int startY);
void printString(const char *str);
void printChar(const char str);
void vgaScrollUp(void);
void cursorEnable(uint8_t cursor_start, uint8_t cursor_end);
void cursorDisable(void);
void cursorMove(int x, int y);
/*
* Dummy printk for disabled debugging statements to use whilst maintaining
* gcc's format checking.
*/
#define no_printf(fmt, ...) \
({ \
if (0) \
printf(fmt, ##__VA_ARGS__); \
0; \
})
#ifdef DEBUG
#define pr_devel(fmt, ...) \
printf(pr_fmt(fmt), ##__VA_ARGS__)
#else
#define pr_devel(fmt, ...) \
no_printf(pr_fmt(fmt), ##__VA_ARGS__)
#endif
#define pr_info(fmt, ...) \
printf(pr_fmt(fmt), ##__VA_ARGS__)
......@@ -7,7 +7,6 @@
#include "paging.h"
#include "serial.h"
#include "stack.h"
#include "vga.h"
void testPhymem(void)
{
......@@ -222,11 +221,11 @@ void run_test(void)
{
testPaging();
printf("Testing Serial\n");
serialWrite('h');
serialWrite('e');
serialWrite('l');
serialWrite('l');
serialWrite('o');
serialPutc('h');
serialPutc('e');
serialPutc('l');
serialPutc('l');
serialPutc('o');
testAlloc();
printf("Testing backtrace\n");
test_backtrace();
......