feat(serial): add serial initialization and gitignore

Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
Julien CLEMENT 2021-07-12 19:46:04 +02:00
parent 95ef09da4b
commit 202fc190ac
5 changed files with 67 additions and 0 deletions

14
.gitignore vendored Normal file

@ -0,0 +1,14 @@
*.o
*.d
*.a
*.iso
iso/
k/k
roms/chichehunter/hunter
roms/chichepong/pong
roms/chichevaders/vaders
roms/perrodlauncher/perrod
roms/skate/skate
roms/yakanoid/yakanoid

@ -30,6 +30,7 @@ OBJS = \
libvga.o \
list.o \
memory.o \
serial.o
DEPS = $(OBJS:.o=.d)

2
k/k.c

@ -24,6 +24,7 @@
#include <k/kstd.h>
#include "multiboot.h"
#include "stdio.h"
void k_main(unsigned long magic, multiboot_info_t *info)
@ -34,6 +35,7 @@ void k_main(unsigned long magic, multiboot_info_t *info)
char star[4] = "|/-\\";
char *fb = (void *)0xb8000;
printf("bonjour\r\n");
for (unsigned i = 0; ; ) {
*fb = star[i++ % 4];
}

26
k/serial.c Normal file

@ -0,0 +1,26 @@
#include <stddef.h>
#include "serial.h"
#include "io.h"
void set_baud_rate(void)
{
u8 line_control_register = inb(COM1 + 3);
outb(COM1 + 3, DLAB | line_control_register);
outb(COM1, 3);
outb(COM1 + 1, 0);
outb(COM1 + 3, line_control_register);
}
void serial_init(void)
{
outb(COM1 + 3, NO_PARITY | EIGHT_BITS_LENGTH);
outb(COM1 + 2, FIFO | TRIGGER_LVL_14 | CLEAR_TRANSMIT_FIFO
| CLEAR_RECEIVE_FIFO);
outb(COM1 + 1, ENABLE_TRANSMITTER);
}
int write(const char *buf, size_t count)
{
return 0;
}

24
k/serial.h Normal file

@ -0,0 +1,24 @@
#ifndef SERIAL_H
#define SERIAL_H
#define COM1 0x3f8
#define COM2 0x2f8
#define COM3 0x3e8
#define COM4 0x2e8
#define ENABLE_TRANSMITTER (0x1 << 1)
#define FIFO 0x1
#define TRIGGER_LVL_14 (0x3 << 6)
#define CLEAR_TRANSMIT_FIFO (0x1 << 2)
#define CLEAR_RECEIVE_FIFO (0x1 << 1)
#define NO_PARITY 0x0
#define EIGHT_BITS_LENGTH 0x3
#define DLAB (0x1 << 7)
void serial_init(void);
int write(const char *buf, size_t count);
#endif /* SERIAL_H */