Move assembly code for x86 64 IO to io.S
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
.global serial_outb
|
||||
serial_outb:
|
||||
.global io_outb
|
||||
io_outb:
|
||||
mov %di, %dx
|
||||
mov %sil, %al
|
||||
out %al, %dx
|
||||
ret
|
||||
|
||||
.global serial_inb
|
||||
serial_inb:
|
||||
.global io_inb
|
||||
io_inb:
|
||||
mov %di, %dx
|
||||
in %dx, %al
|
||||
movzx %al, %rax
|
7
kernel/hal/x86_64/io.h
Normal file
7
kernel/hal/x86_64/io.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef HAL_IO_H_
|
||||
#define HAL_IO_H_
|
||||
|
||||
extern uint8_t io_inb(uint16_t port);
|
||||
extern void io_outb(uint16_t port, uint8_t value);
|
||||
|
||||
#endif // HAL_IO_H_
|
@ -1,46 +1,44 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "io.h"
|
||||
|
||||
#define SERIAL_PORT 0x3f8
|
||||
|
||||
extern uint8_t serial_inb(uint16_t port);
|
||||
extern void serial_outb(uint16_t port, uint8_t value);
|
||||
|
||||
static int serial_received(void) {
|
||||
return serial_inb(SERIAL_PORT + 5) & 1;
|
||||
return io_inb(SERIAL_PORT + 5) & 1;
|
||||
}
|
||||
|
||||
static uint8_t serial_read(void) {
|
||||
while (serial_received() == 0);
|
||||
return serial_inb(SERIAL_PORT);
|
||||
return io_inb(SERIAL_PORT);
|
||||
}
|
||||
|
||||
static int serial_trans_empty(void) {
|
||||
return serial_inb(SERIAL_PORT + 5) & 0x20;
|
||||
return io_inb(SERIAL_PORT + 5) & 0x20;
|
||||
}
|
||||
|
||||
static void serial_write(uint8_t value) {
|
||||
while (!serial_trans_empty());
|
||||
serial_outb(SERIAL_PORT, value);
|
||||
io_outb(SERIAL_PORT, value);
|
||||
}
|
||||
|
||||
// REFERENCE: https://wiki.osdev.org/Serial_Ports
|
||||
bool serial_init(void) {
|
||||
serial_outb(SERIAL_PORT + 1, 0x00);
|
||||
serial_outb(SERIAL_PORT + 3, 0x80);
|
||||
serial_outb(SERIAL_PORT + 0, 0x03);
|
||||
serial_outb(SERIAL_PORT + 1, 0x00);
|
||||
serial_outb(SERIAL_PORT + 3, 0x03);
|
||||
serial_outb(SERIAL_PORT + 2, 0xc7);
|
||||
serial_outb(SERIAL_PORT + 4, 0x0b);
|
||||
serial_outb(SERIAL_PORT + 4, 0x1e);
|
||||
serial_outb(SERIAL_PORT + 0, 0xae);
|
||||
io_outb(SERIAL_PORT + 1, 0x00);
|
||||
io_outb(SERIAL_PORT + 3, 0x80);
|
||||
io_outb(SERIAL_PORT + 0, 0x03);
|
||||
io_outb(SERIAL_PORT + 1, 0x00);
|
||||
io_outb(SERIAL_PORT + 3, 0x03);
|
||||
io_outb(SERIAL_PORT + 2, 0xc7);
|
||||
io_outb(SERIAL_PORT + 4, 0x0b);
|
||||
io_outb(SERIAL_PORT + 4, 0x1e);
|
||||
io_outb(SERIAL_PORT + 0, 0xae);
|
||||
|
||||
if (serial_inb(SERIAL_PORT + 0) != 0xae) {
|
||||
if (io_inb(SERIAL_PORT + 0) != 0xae) {
|
||||
return false;
|
||||
}
|
||||
|
||||
serial_outb(SERIAL_PORT + 4, 0x0f);
|
||||
io_outb(SERIAL_PORT + 4, 0x0f);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user