Initial commit. Still a lot to do

This commit is contained in:
Ghostie 2022-03-03 00:47:41 +00:00
commit 5d355504bc
33 changed files with 3015 additions and 0 deletions

149
.clang-format Normal file
View File

@ -0,0 +1,149 @@
---
Language: Cpp
# BasedOnStyle: GNU
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveBitFields: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: All
AlwaysBreakAfterReturnType: AllDefinitions
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: true
IndentBraces: true
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: All
BreakBeforeBraces: GNU
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 79
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
- Regex: '.*'
Priority: 1
SortPriority: 0
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Always
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: c++03
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
...

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
*.o
*.bin
*~
\#*\#
.\#*
*.out

92
Makefile Normal file
View File

@ -0,0 +1,92 @@
CROSS_PATH=$(HOME)/opt/cross/bin
LD=$(CROSS_PATH)/i686-elf-ld
CC=$(CROSS_PATH)/i686-elf-gcc
ASM=nasm
ECHO=echo -e
QEMU=qemu-system-i386
GDB=gdb
CFLAGS=-g -ffreestanding -falign-jumps -falign-functions -falign-labels \
-falign-loops -fstrength-reduce -fomit-frame-pointer \
-finline-functions -Wno-unused-function -fno-builtin -Werror \
-Wno-unused-label -Wno-cpp -Wno-unused-parameter -nostdlib \
-nostartfiles -nodefaultlibs -Wall -O0
INCLUDES=-I.
NO_SECTORS=100
OBJS=build/kernel.asm.o build/kernel.o build/idt/idt.asm.o build/idt/idt.o \
build/mm/mem.o build/io/io.asm.o build/string/string.o
# VESA Driver
OBJS+=build/drivers/vesa/vesa.o build/drivers/vesa/terminal.o \
build/drivers/vesa/fonts/vga.o
all: build/boot/boot.bin build/kernel.out
@dd if=build/boot/boot.bin > kinl.bin
@dd if=build/kernel.out >> kinl.bin
@dd if=/dev/zero bs=512 count=$(NO_SECTORS) >> kinl.bin
build/kernel.out: $(OBJS)
@$(LD) -g -relocatable $(OBJS) -o build/kernelfull.o
@$(CC) $(CFLAGS) -T linker.ld -o $@ -ffreestanding -O0 -nostdlib \
build/kernelfull.o
build/boot/boot.bin: boot/bios.asm
@$(ECHO) "ASM\t\t"$<
@$(ASM) -f bin $< -o $@
build/kernel.asm.o: sys/kernel.asm
@$(ECHO) "ASM\t\t"$<
@$(ASM) -f elf -g $< -o $@
build/kernel.o: sys/kernel.c
@$(ECHO) "CC\t\t"$<
@$(CC) $(CFLAGS) $(INCLUDES) -std=gnu99 -c $< -o $@
build/idt/idt.asm.o: sys/idt/idt.asm
@$(ECHO) "ASM\t\t"$<
@$(ASM) -f elf -g $< -o $@
build/idt/idt.o: sys/idt/idt.c
@$(ECHO) "CC\t\t"$<
@$(CC) $(CFLAGS) $(INCLUDES) -std=gnu99 -c $< -o $@
build/mm/mem.o: sys/mm/mem.c
@$(ECHO) "CC\t\t"$<
@$(CC) $(CFLAGS) $(INCLUDES) -std=gnu99 -c $< -o $@
build/io/io.asm.o: sys/io/io.asm
@$(ECHO) "ASM\t\t"$<
@$(ASM) -f elf -g $< -o $@
build/string/string.o: sys/string/string.c
@$(ECHO) "CC\t\t"$<
@$(CC) $(CFLAGS) $(INCLUDES) -std=gnu99 -c $< -o $@
# VESA Driver
build/drivers/vesa/vesa.o: drivers/vesa/vesa.c
@$(ECHO) "CC\t\t"$<
@$(CC) $(CFLAGS) $(INCLUDES) -std=gnu99 -c $< -o $@
build/drivers/vesa/terminal.o: drivers/vesa/terminal.c
@$(ECHO) "CC\t\t"$<
@$(CC) $(CFLAGS) $(INCLUDES) -std=gnu99 -c $< -o $@
build/drivers/vesa/fonts/vga.o: drivers/vesa/fonts/vga.c
@$(ECHO) "CC\t\t"$<
@$(CC) $(CFLAGS) $(INCLUDES) -std=gnu99 -c $< -o $@
gdb: all
@$(GDB) -ex "set confirm off" \
-ex "add-symbol-file build/kernelfull.o 0x0100000" \
-ex "target remote | qemu-system-i386 -hda kinl.bin -S -gdb stdio"
run: all
@$(QEMU) -hda kinl.bin
clean:
@rm -Rf build/boot/boot.bin build/kernel.out \
build/kernelfull.o $(OBJS)

142
boot/bios.asm Normal file
View File

@ -0,0 +1,142 @@
ORG 0x7c00
BITS 16
CODE_SEG equ gdt_code - gdt_start
DATA_SEG equ gdt_data - gdt_start
_start:
jmp short start
nop
times 33 db 0
start:
jmp 0:step2
step2:
cli ; Disable interrupts
mov ax, 0x00
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 0x7c00
sti ; Enable interrupts
mov ax, 0x4F01
mov cx, 0x118
mov di, 0x500
int 0x10
mov ax, 0x4F02
mov bx, 0x118
int 0x10
.load_protected:
cli
lgdt [gdt_descriptor]
mov eax, cr0
or eax, 1
mov cr0, eax
jmp CODE_SEG:load32
;; GDT
gdt_start:
gdt_null:
dd 0x0
dd 0x0
;; offset 0x8
gdt_code: ; CS Should point to this
dw 0xffff ; Segment limit first 0-15 bits
dw 0 ; Base first 0-15 bits
db 0 ; Base 16-23 bits
db 0x9a ; Access bytes
db 11001111b ; High 4 bit flags and the low 4 bit flags
db 0 ; Base 24-31 bits
;; offset 0x10
gdt_data: ; DS, SS, ES, FS, GS
dw 0xffff ; Segment limit, first 0-15 bits
dw 0 ; Base first 0-15 bits
db 0 ; Base 16-23 bits
db 0x92 ; Access byte
db 11001111b ; High 4 bit flags and the low 4 bit flags
db 0 ; Base 24-31 bits
gdt_end:
gdt_descriptor:
dw gdt_end - gdt_start - 1
dd gdt_start
[BITS 32]
load32:
mov eax, 1
mov ecx, 100
mov edi, 0x0100000
call ata_lba_read
jmp CODE_SEG:0x0100000
ata_lba_read:
mov ebx, eax ; Backup the LBA
;; Send the highest 8 bits of the LBA to the hard disk controller
shr eax, 24
or eax, 0xE0
mov dx, 0x1F6
out dx, al
;; Finished sending the highest 8 bits of the LBA
;; Send the total sectors to read
mov eax, ecx
mov dx, 0x1F2
out dx, al
;; Finished sending the total sectors to read
;; Send more bits of the LBA
mov eax, ebx ; Restore the backup LBA
mov dx, 0x1F3
out dx, al
;; Finished sending more bits of the LBA
;; Send more bits of the LBA
mov dx, 0x1F4
mov eax, ebx ; Restore the backup LBA
shr eax, 8
out dx, al
;; Finished sending more bits of the LBA
;; Send upper 16 bits of the LBA
mov dx, 0x1F5
mov eax, ebx ; Restore the backup LBA
shr eax, 16
out dx, al
;; Finished sending upper 16 bits of the LBA
mov dx, 0x1F7
mov al, 0x20
out dx, al
;; Read all sectors into memory
.next_sector:
push ecx
;; Checking if we need to read
.try_again:
mov dx, 0x1F7
in al, dx
test al, 8
jz .try_again
;; We need to read 256 words at a time
mov ecx, 256
mov dx, 0x1F0
rep insw
pop ecx
loop .next_sector
;; End of reading sectors into memory
ret
times 510-($-$$) db 0
dw 0xAA55

0
build/.gitkeep Normal file
View File

0
build/boot/.gitkeep Normal file
View File

0
build/drivers/.gitkeep Normal file
View File

View File

View File

0
build/idt/.gitkeep Normal file
View File

0
build/io/.gitkeep Normal file
View File

0
build/mm/.gitkeep Normal file
View File

0
build/string/.gitkeep Normal file
View File

8
compile_flags.txt Normal file
View File

@ -0,0 +1,8 @@
-Wno-unused-function
-Wno-unused-label
-Wno-cpp
-Wno-unused-parameter
-nostdlib
-nodefaultlibs
-Wall
-I.

View File

@ -0,0 +1,9 @@
#ifndef __VESA_FONTS_H
#define __VESA_FONTS_H
#define FONT_VGA_WIDTH 12
#define FONT_VGA_HEIGHT 18
int font_vga (int index, int y);
#endif

2058
drivers/vesa/fonts/vga.c Normal file

File diff suppressed because it is too large Load Diff

71
drivers/vesa/terminal.c Normal file
View File

@ -0,0 +1,71 @@
#include "vesa.h"
#include "fonts/fonts.h"
#include <sys/kernel.h>
#include <sys/string/string.h>
#define TERMINAL_DEFAULT_FONT font_vga
u16 _row = 0;
u16 _col = 0;
static void
terminal_putchar (char c, u32 col)
{
if (c == '\n')
{
_row += 1;
_col = 0;
return;
}
vesa_putchar (TERMINAL_DEFAULT_FONT, FONT_VGA_WIDTH, FONT_VGA_HEIGHT, c,
_col * (FONT_VGA_WIDTH / 1.5), _row * FONT_VGA_HEIGHT, col);
_col += 1;
if (_col * (FONT_VGA_WIDTH / 1.5) >= vesa_get_width ())
{
_col = 0;
_row += 1;
}
}
void
terminal_print (const char *str)
{
int len = strlen (str);
for (int i = 0; i < len; i++)
{
terminal_putchar (str[i], vesa_make_colour (255, 255, 255));
}
}
void
terminal_print_ext (const char *str, u32 col)
{
int len = strlen (str);
for (int i = 0; i < len; i++)
{
terminal_putchar (str[i], col);
}
}
// This is a function that will write "* PENDING `task'" to the screen
void
terminal_print_pending (const char *task)
{
terminal_print_ext ("\n*", vesa_make_colour (255, 105, 147));
terminal_print_ext (" PENDING ", vesa_make_colour (255, 20, 147));
terminal_print (task);
}
// This is a function that will write "* DONE `task'" to the screen
void
terminal_print_done (const char *task)
{
terminal_print_ext ("\n*", vesa_make_colour (0, 255, 0));
terminal_print_ext (" DONE ", vesa_make_colour (34, 139, 34));
terminal_print (task);
}

105
drivers/vesa/vesa.c Normal file
View File

@ -0,0 +1,105 @@
#include "vesa.h"
struct vbe_info *info = (struct vbe_info *)VBE_INFO_ADDR;
u32
vesa_make_colour (u8 r, u8 g, u8 b)
{
return r << info->red_position | g << info->green_position
| b << info->blue_position;
}
void
vesa_putpixel (u16 x, u16 y, u32 col)
{
void *framebuffer = (void *)(unsigned long)info->framebuffer;
switch (info->bpp)
{
case 8:
{
u8 *pixel = framebuffer + info->pitch * y + x;
*pixel = col;
}
break;
case 15:
case 16:
{
u16 *pixel = framebuffer + info->pitch * y + 2 * x;
*pixel = col;
}
break;
case 24:
{
u32 *pixel = framebuffer + info->pitch * y + 3 * x;
*pixel = (col & 0xffffff) | (*pixel & 0xff000000);
}
break;
case 32:
{
u32 *pixel = framebuffer + info->pitch * y + 4 * x;
*pixel = col;
}
break;
}
}
void
vesa_cls (u32 col)
{
for (u16 y = 0; y < info->height; y++)
{
for (u16 x = 0; x < info->width; x++)
{
vesa_putpixel (x, y, col);
}
}
}
void
vesa_draw_rect (u16 x, u16 y, u16 w, u16 h, u32 col)
{
for (u16 j = y; j < (y + h); j++)
{
for (u16 i = x; i < (x + w); i++)
{
vesa_putpixel (i, j, col);
}
}
}
u16
vesa_get_width ()
{
return info->width;
}
u16
vesa_get_height ()
{
return info->height;
}
void
vesa_putchar (int (*font) (int, int), u8 font_width, u8 font_height, char c,
u16 x, u16 y, u32 col)
{
for (u8 j = 0; j < font_height; j++)
{
u32 row = (*font) ((i32)c, j);
i32 shift = font_width - 1;
i32 bit_val = 0;
for (u8 i = 0; i < font_width; i++)
{
bit_val = (row >> shift) & 1;
if (bit_val)
vesa_putpixel (x + i, y + j, col);
shift -= 1;
}
}
}

66
drivers/vesa/vesa.h Normal file
View File

@ -0,0 +1,66 @@
#ifndef __VESA_H
#define __VESA_H
#include <sys/kernel.h>
#define VBE_INFO_ADDR 0x500
struct vbe_info
{
u16 attributes;
u8 window_a;
u8 window_b;
u16 granularity;
u16 window_size;
u16 segment_a;
u16 segment_b;
u32 win_func_ptr;
u16 pitch;
u16 width;
u16 height;
u8 w_char;
u8 y_char;
u8 planes;
u8 bpp;
u8 banks;
u8 memory_model;
u8 bank_size;
u8 image_pages;
u8 reserved0;
u8 red_mask;
u8 red_position;
u8 green_mask;
u8 green_position;
u8 blue_mask;
u8 blue_position;
u8 reserved_mask;
u8 reserved_position;
u8 direct_colour_attributes;
u32 framebuffer;
u32 off_screen_mem_off;
u16 off_screen_mem_size;
u8 reserved1[206];
} __attribute__ ((packed));
u32 vesa_make_colour (u8 r, u8 g, u8 b);
void vesa_putpixel (u16 x, u16 y, u32 col);
void vesa_cls (u32 col);
void vesa_draw_rect (u16 x, u16 y, u16 w, u16 h, u32 col);
void vesa_putchar (int (*font) (int, int), u8 font_width, u8 font_height,
char c, u16 x, u16 y, u32 col);
// "terminal"
void terminal_print (const char *str);
void terminal_print_ext (const char *str, u32 col);
void terminal_print_pending (const char *task);
void terminal_print_done (const char *task);
u16 vesa_get_width ();
u16 vesa_get_height ();
#endif

31
linker.ld Normal file
View File

@ -0,0 +1,31 @@
ENTRY (_start)
OUTPUT_FORMAT(binary)
SECTIONS
{
. = 1M;
.text : ALIGN (4096)
{
*(.text)
}
.rodata : ALIGN (4096)
{
*(.rodata)
}
.data : ALIGN (4096)
{
*(.data)
}
.bss : ALIGN (4096)
{
*(COMMON)
*(.bss)
}
.asm :
{
*(.asm)
}
}

9
sys/config.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef __CONFIG_H
#define __CONFIG_H
#define KERNEL_CODE_SELECTOR 0x08
#define KERNEL_DATA_SELECTOR 0x10
#define KINL_TOTAL_INTERRUPTS 512
#endif

13
sys/idt/idt.asm Normal file
View File

@ -0,0 +1,13 @@
section .asm
global idt_load
idt_load:
push ebp
mov ebp, esp
mov ebx, [ebp + 8]
lidt [ebx]
pop ebp
ret

41
sys/idt/idt.c Normal file
View File

@ -0,0 +1,41 @@
#include "idt.h"
#include <sys/config.h>
#include <sys/mm/mem.h>
#include <drivers/vesa/vesa.h>
struct idt_desc idt_descriptors[KINL_TOTAL_INTERRUPTS];
struct idtr_desc idtr_descriptor;
extern void idt_load (void *ptr);
void
idt_zero ()
{
terminal_print ("Divide by zero error\n");
}
void
idt_set (int interrupt_no, void *address)
{
struct idt_desc *desc = &idt_descriptors[interrupt_no];
desc->offset_1 = (u32)address & 0x0000ffff;
desc->selector = KERNEL_CODE_SELECTOR;
desc->zero = 0x00;
desc->type_attribute = 0xee;
desc->offset_2 = (u32)address >> 16;
}
void
idt_init ()
{
memset (idt_descriptors, 0, sizeof (idt_descriptors));
idtr_descriptor.limit = sizeof (idt_descriptors) - 1;
idtr_descriptor.base = (u32)idt_descriptors;
idt_set (0, idt_zero);
// Load the interrupt descriptor table
idt_load (&idtr_descriptor);
}

24
sys/idt/idt.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef __IDT_H
#define __IDT_H
#include <sys/kernel.h>
struct idt_desc
{
u16 offset_1; // Offset bits 0 - 16
u16 selector; // Selector that's in our GDT
u8 zero;
u8 type_attribute; // Descriptor type attribute
u16 offset_2; // Offset bits 16-31
} __attribute__ ((packed));
struct idtr_desc
{
u16 limit; // Size of descriptor tabe
u32 base; // Base address of the start of the interrupt table
} __attribute__ ((packed));
void idt_init ();
void idt_set (int interrupt_no, void *address);
#endif

51
sys/io/io.asm Normal file
View File

@ -0,0 +1,51 @@
section .asm
global insb
global insw
global outb
global outw
insb:
push ebp
mov ebp, esp
xor eax, eax
mov edx, [ebp + 8]
in al, dx
pop ebp
ret
insw:
push ebp
mov ebp, esp
xor eax, eax
mov edx, [ebp + 8]
in ax, dx
pop ebp
ret
outb:
push ebp
mov ebp, esp
mov eax, [ebp + 12]
mov edx, [ebp + 8]
out dx, al
pop ebp
ret
outw:
push ebp
mov ebp, esp
mov eax, [ebp + 12]
mov edx, [ebp + 8]
out dx, ax
pop ebp
ret

12
sys/io/io.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef __IO_H
#define __IO_H
#include <sys/kernel.h>
u8 insb (u16 port);
u16 insw (u16 port);
void outb (u16 port, u8 val);
void outw (u16 port, u16 val);
#endif

29
sys/kernel.asm Normal file
View File

@ -0,0 +1,29 @@
[BITS 32]
extern kmain
global _start
CODE_SEG equ 0x08
DATA_SEG equ 0x10
_start:
mov ax, DATA_SEG
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov ebp, 0x00200000
mov esp, ebp
;; Enable A20 line
in al, 0x92
or al, 2
out 0x92, al
call kmain
jmp $
times 512-($-$$) db 0

17
sys/kernel.c Normal file
View File

@ -0,0 +1,17 @@
#include <sys/kernel.h>
#include <drivers/vesa/vesa.h>
#include <sys/idt/idt.h>
#include <sys/io/io.h>
void
kmain ()
{
terminal_print ("Welcome to the Kinl operating system!\n");
// Initialise the IDT
terminal_print_pending ("Initialise IDT");
idt_init ();
terminal_print_done ("Initialised IDT");
}

16
sys/kernel.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef __KERNEL_H
#define __KERNEL_H
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned long long u64;
typedef char i8;
typedef short i16;
typedef int i32;
typedef long long i64;
void kmain ();
#endif

14
sys/mm/mem.c Normal file
View File

@ -0,0 +1,14 @@
#include "mem.h"
void *
memset (void *ptr, int c, u32 size)
{
char *c_ptr = (char *)ptr;
for (u32 i = 0; i < size; i++)
{
c_ptr[i] = (char)c;
}
return ptr;
}

8
sys/mm/mem.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef __MEM_H_
#define __MEM_H
#include <sys/kernel.h>
void *memset (void *ptr, int c, u32 size);
#endif

36
sys/string/string.c Normal file
View File

@ -0,0 +1,36 @@
#include "string.h"
char
tolower (char s1)
{
if (s1 >= 65 && s1 <= 90)
s1 += 32;
return s1;
}
int
strlen (const char *str)
{
int i = 0;
while (*str != 0)
{
i++;
str += 1;
}
return i;
}
int
strnlen (const char *str, int max)
{
int i = 0;
for (int i = 0; i < max; i++)
{
if (str[i] == 0)
break;
}
return i;
}

8
sys/string/string.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef __STRING_H
#define __STRING_H
char tolower (char s1);
int strlen (const char *str);
int strnlen (const char *str, int max);
#endif