Commit 6875e259 authored by Oxynux's avatar Oxynux

preliminary support for uppercase (to cleanup)

Co-authored-by: tbillard's avatarcybernnal <tbillard@student.42.fr>
parent 9adfe80d
KERNEL = kfs_1
KERNEL_IMG = kfs_1.iso
KERNEL_DIR = kernel
LIBK_DIR = libk
LIBK = $(LIBK_DIR)/libk.a
CC = gcc
LD = ld
ASM = nasm
CCFLAGS = -O0 -ffreestanding -m32 -nostdlib -fno-stack-protector -Wall -Wextra -Werror
WFLAGS = # -Wall -Wextra -Werror
INCLUDES = -I . -I $(LIBK_DIR)
CCFLAGS = -O0 -ffreestanding -m32 -nostdlib -fno-stack-protector $(WFLAGS) $(INCLUDES)
LDFLAGS = -m elf_i386 -T
ASMFLAGS = -f elf32
CC_SRC = kmain.c \
keyboard.c
keyboard.c
LD_SRC = link.ld
ASM_SRC = kernel.s
GRUB_CFG = grub.cfg
CC_OBJ = $(CC_SRC:.c=.o)
ASM_OBJ = $(ASM_SRC:.s=.o)
all: $(KERNEL_IMG)
......@@ -29,7 +35,8 @@ $(KERNEL_IMG): $(KERNEL)
grub-mkrescue -o $@ $(KERNEL_DIR)
$(KERNEL): $(ASM_OBJ) $(CC_OBJ)
$(LD) $(LDFLAGS) $(LD_SRC) -o $@ $^
$(MAKE) -C $(LIBK_DIR)/
$(LD) $(LDFLAGS) $(LD_SRC) -o $@ $^ $(LIBK)
.c.o:
$(CC) $(CCFLAGS) -c $< -o $@
......@@ -40,11 +47,13 @@ $(KERNEL): $(ASM_OBJ) $(CC_OBJ)
clean:
rm -rf $(CC_OBJ)
rm -rf $(ASM_OBJ)
$(MAKE) -C $(LIBK_DIR)/ clean
fclean: clean
rm -rf $(KERNEL_DIR)
rm -rf $(KERNEL_IMG)
rm -rf $(KERNEL)
$(MAKE) -C $(LIBK_DIR)/ fclean
run: $(KERNEL_IMG)
qemu-system-i386 -cdrom $(KERNEL_IMG)
......
......@@ -26,7 +26,7 @@
#define BLUE 0x01
#define GREEN 0x02
#define CYAN 0x03
#define RED 0x04
#define RED 0x04
#define MAGENTA 0x05
#define BROWN 0x06
#define LIGHT_GREY 0x07
......@@ -35,11 +35,29 @@
#define LIGHT_GREEN 0x0a
#define LIGHT_CYAN 0x0b
#define LIGHT_RED 0x0c
#define LIGHT_MAGENTA 0x0d
#define LIGHT_MAGENTA 0x0d
#define LIGHT_BROWN 0x0e
#define WHITE 0x0f
char getchar();
int getchar(_Bool caps);
//void init_gdt(void);
//
//struct gdtr {
// uint16_t limite;
// uint32_t base;
//} __attribute__ ((packed));
//
//struct gdtdesc {
// uint16_t lim0_15;
// uint16_t base0_15;
// uint8_t base16_23;
// uint8_t acces;
// uint8_t lim16_19:4;
// uint8_t other:4;
// uint8_t base24_31;
//} __attribute__ ((packed));
#define GDTBASE 0x00000800
#endif
#include "include/kernel.h"
unsigned char kbdus[128] = {
0, // error
0, // esc
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
'-', '=',
253, // backspace
0, // tab
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']',
255, // enter
0, // left ctrl
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`',
0, // left shift
'\\', 'z', 'x', 'c', 'v', 'b', 'n',
'm', ',', '.', '/',
0, // right shift
'*',
0, // left alt
' ', // space
0, // caps-lock
200, 201, 202, 203, 204, 205, 206, 207, 208, 209, // f1->f10
0, // numlock
0, // scroll lock
0, // home
150, // up
0, // page up
'-',
151, // left
0, // keypad 5
152, // right
'+',
0, // end
153, // down
0, // page down
0, // insert
0, // del
0, // Alt-SysRq ?
0, // Fn?
0, // Cmd/Super?
0, // f11
0, // f12
0, // undefined
};
unsigned char kbdus[2][128] = {{
0, // error
0, // esc
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
'-', '=',
0, // tab
253, // backspace
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']',
255, // enter
0, // left ctrl
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`',
156, // left shift
'\\', 'z', 'x', 'c', 'v', 'b', 'n',
'm', ',', '.', '/',
157, // right SHIft
'*',
0, // left alt
' ', // space
155, // caps-lock
200, 201, 202, 203, 204, 205, 206, 207, 208, 209, // f1->f10
0, // numlock
0, // scroll lock
0, // home
150, // up
0, // page up
'-',
151, // left
0, // keypad 5
152, // right
'+',
0, // end
153, // down
0, // page down
0, // insert
0, // del
0, // Alt-SysRq ?
0, // Fn?
0, // Cmd/Super?
0, // f11
0, // f12
0, // undefined
},
{
0, // error
0, // esc
'!', '@', '#', '$', '%', '^', '&', '*', '(', ')',
'_', '+',
253, // backspace
0, // tab
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}',
255, // enter
0, // left ctrl
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '\"', '~',
156, // left shift
'|', 'Z', 'X', 'C', 'V', 'B', 'N',
'M', '<', '>', '?',
157, // right shift
'*',
0, // left alt
' ', // space
155, // caps-lock
200, 201, 202, 203, 204, 205, 206, 207, 208, 209, // f1->f10
0, // numlock
0, // scroll lock
0, // home
150, // up
0, // page up
'-',
151, // left
0, // keypad 5
152, // right
'+',
0, // end
153, // down
0, // page down
0, // insert
0, // del
0, // Alt-SysRq ?
0, // Fn?
0, // Cmd/Super?
0, // f11
0, // f12
0, // undefined
} };
/*
*
* outb: output byte in AL (here it's val and 0x0 in get_scancode())
* outb: output byte in AL (here it's val and 0x0 in _scancode())
* to I/O port address in DX (here it's port and 0x60 in get_scancode())
*
* a: constraint mean use the A register (in this case AL)
......@@ -107,7 +150,11 @@ static unsigned char get_scancode()
} while(1);
}
char getchar() {
return kbdus[get_scancode()];
int getchar(_Bool caps) {
int c = get_scancode();
if (c >= 128)
return (-kbdus[caps][c - 128]);
return kbdus[caps][c];
}
......@@ -3,7 +3,9 @@
*/
#include "include/kernel.h"
#include "libk.h"
_Bool caps = 0;
/*
*
......@@ -175,11 +177,11 @@ static inline void arrow_left(char **video)
*video -= 2;
}
static void kputchar(char c) {
void kputchar(int c) {
static char *video = (char*)VID_MEMORY;
static char color = WHITE;
switch ((unsigned char)c)
switch (c)
{
case 150:
arrow_up(&video);
......@@ -229,8 +231,19 @@ static void kputchar(char c) {
case 255:
enter(&video);
break;
case 155:
case 156:
case 157:
caps = !caps;
break;
case -156:
case -157:
caps = !caps;
break;
default:
*video++ = c;
if (c < 0)
break;
*video++ = (char)c;
*video++ = color;
break;
}
......@@ -240,10 +253,9 @@ static void kputchar(char c) {
}
static void basic_kbd() {
char c;
int c;
while (1) {
c = getchar();
c = getchar(caps);
if (c != 0)
kputchar(c);
}
......@@ -255,12 +267,14 @@ void kmain(void)
char *vidptr = (char*)VID_MEMORY; /* Videos memory begin here */
char c;
// init_gdt();
ft_clear_screen();
enable_cursor(0, 15);
ft_write_on_screen(str, vidptr);
while (1) {
c = getchar();
if (c != 0) {
c = getchar(0);
if (c != 0) {
ft_clear_screen();
basic_kbd();
}
......
CC = gcc
CFLAG = -O0 -ffreestanding -m32 -nostdlib -fno-stack-protector -Wall -Wextra -Werror
NAME = libk.a
SRC = memmove.c \
memcpy.c \
memcmp.c \
strlen.c \
memset.c
OBJ = $(SRC:.c=.o)
all: $(NAME)
$(NAME): $(OBJ)
@echo "Creating libk with an index..."
@ar rcs $@ $^
@echo "libk.a is ready !"
%.o: %.c
@echo Compiling $<
@$(CC) $(CFLAG) -I. -o $@ -c $<
clean:
@rm -rf $(OBJ)
fclean: clean
@rm -rf $(NAME)
re: fclean all
File added
//
// Created by oxynux on 2/17/19.
//
#ifndef KFS_LIBK_H
#define KFS_LIBK_H
#include <stddef.h>
int memcmp(const void *s1, const void *s2, size_t n);
void *memcpy(void *s1, const void *s2, size_t n);
void *memmove(void *s1, const void *s2, size_t n);
void *memset(void *b, int c, size_t len);
size_t strlen(const char *str);
#endif //KFS_LIBK_H
//
// Created by oxynux on 2/17/19.
//
#include "libk.h"
int memcmp(const void *s1, const void *s2, size_t n)
{
if (n != 0) {
const unsigned char *p1 = s1, *p2 = s2;
do {
if (*p1++ != *p2++)
return (*--p1 - *--p2);
} while (--n != 0);
}
return (0);
}
\ No newline at end of file
//
// Created by oxynux on 2/17/19.
//
#include "libk.h"
void *memcpy(void *s1, const void *s2, size_t n)
{
const char *f = s2;
char *t = s1;
while (n-- > 0)
*t++ = *f++;
return s1;
}
\ No newline at end of file
//
// Created by oxynux on 2/17/19.
//
#include "libk.h"
void *memmove(void *s1, const void *s2, size_t n)
{
const char *f = s2;
char *t = s1;
if (f < t) {
f += n;
t += n;
while (n-- > 0)
*--t = *--f;
} else
while (n-- > 0)
*t++ = *f++;
return s1;
}
\ No newline at end of file
//
// Created by oxynux on 2/17/19.
//
#include "libk.h"
void *memset(void *b, int c, size_t len)
{
unsigned char *p;
p = b;
while (len--)
*p++ = (unsigned char)c;
return (b);
}
//
// Created by oxynux on 2/17/19.
//
#include "libk.h"
size_t strlen(const char *str)
{
const char *s;
for (s = str; *s; ++s)
;
return (s - str);
}
\ No newline at end of file
......@@ -7,12 +7,12 @@
* Similarly, the data and bss sections are merged and placed at the then values of location-counter.
*/
OUTPUT_FORMAT(elf32-i386) /* Output format of our executablee*/
OUTPUT_FORMAT(elf32-i386) /* Output format of our executablee*/
ENTRY(start) /* Specify the entry point of our exexutable */
SECTIONS /* Layout of our executable */
SECTIONS /* Layout of our executable */
{
. = 0x100000; /* Kernel's code start at the adresses 0x100000 */
.text : { *(.text) } /* The asterisk (*) is a wildcard character that matches any file name */
. = 1M; /* Kernel's code start at 1M */
.text : { *(.text) } /* The asterisk (*) is a wildcard character that matches any file name */
.data : { *(.data) }
.bss : { *(.bss) }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment