Skip to content
Snippets Groups Projects
Commit 42bda3b6 authored by Bensong Liu's avatar Bensong Liu
Browse files

add bus io

parent 3ba21a66
No related branches found
No related tags found
No related merge requests found
......@@ -76,11 +76,11 @@ disk_io_error:
_init_prot_mode:
cli
lgdt [gdt_desc]
cli ; turn off interrupt, until we set interrupt vector for 32b protected mode.
lgdt [gdt_desc] ; set GDT,
mov eax, cr0
or eax, 0x1
mov cr0, eax
mov cr0, eax ; and set CR0.
; We're almost in 32bit protected mode now. Flush the pipeline by far jump.
jmp CODE_SEG_OFFSET:_prot_begin
......
......@@ -10,7 +10,7 @@ head:
nasm -f elf image_head.asm -o image_head.o
kernel:
g++ -ffreestanding -fno-pie -c kernel.cc -o kernel.o -m32
g++ -ffreestanding -fno-pie -c kernel.cc -o kernel.o -m32 -std=c++17
clean:
rm *.o *.img
......
#ifndef ROS_KERN_BUS_IO_HPP
#define ROS_KERN_BUS_IO_HPP
#include "stdint.hpp"
inline auto read_byte_from_bus(uint16_t port) {
uint8_t result;
asm ("in %%dx, %%al" : "=a"(result) : "d"(port));
return result;
}
inline auto read_word_from_bus(uint16_t port) {
uint16_t result;
asm ("in %%dx, %%ax" : "=a"(result) : "d"(port));
return result;
}
inline auto read_dword_from_bus(uint16_t port) {
uint32_t result;
asm ("in %%dx, %%eax" : "=a"(result) : "d"(port));
return result;
}
inline void write_byte_to_bus(uint16_t port, uint8_t data) {
asm ("out %%al, %%dx": : "a"(data), "d"(port));
}
inline void write_word_to_bus(uint16_t port, uint16_t data) {
asm ("out %%ax, %%dx": : "a"(data), "d"(port));
}
inline void write_dword_to_bus(uint16_t port, uint32_t data) {
asm ("out %%eax, %%dx": : "a"(data), "d"(port));
}
#endif
#ifndef ROS_KERN_STDINT_HPP
#define ROS_KERN_STDINT_HPP
using uint8_t = unsigned char;
using uint16_t = unsigned short;
using uint32_t = unsigned int;
using uint64_t = unsigned long long;
static_assert(sizeof(uint8_t) == 1);
static_assert(sizeof(uint16_t) == 2);
static_assert(sizeof(uint32_t) == 4);
static_assert(sizeof(uint64_t) == 8);
using sint8_t = signed char;
using sint16_t = signed short;
using sint32_t = signed int;
using sint64_t = signed long long;
static_assert(sizeof(sint8_t) == 1);
static_assert(sizeof(sint16_t) == 2);
static_assert(sizeof(sint32_t) == 4);
static_assert(sizeof(sint64_t) == 8);
using size_t = uint32_t;
#endif
#ifndef ROS_KERN_VGA_HPP
#define ROS_KERN_VGA_HPP
inline char *vga_begin = (char *)0xb8000;
void push_char(char c, char color) {
static int pos = 0;
vga_begin[pos++] = c;
vga_begin[pos++] = color;
}
void set_char(int x, int y, char c, char color) {
auto pos = x + 80 * y;
vga_begin[pos*2] = c;
vga_begin[pos*2+1] = color;
}
#endif
\ No newline at end of file
char *vga_begin = (char *)0xb8000;
void push_char(char c, char color) {
static int pos = 0;
vga_begin[pos++] = c;
vga_begin[pos++] = color;
#include "include/vga.hpp"
#include "include/bus_io.hpp"
void test_dummy_function() {
auto tmp = read_byte_from_bus(0x3f2);
tmp |= 0x08;
write_byte_to_bus(0x3f2, tmp);
}
void main() {
int pos = 0;
for(int cter = 0; cter < 256; ++cter) {
push_char(cter % 10 + '0', cter);
for(int i = 1; i < 10; ++i) {
push_char(i + '0', cter);
for(auto y = 0; y < 25; ++y) {
for(auto x = 0; x < 80; ++x) {
char c = x%10 + '0';
char color = x + y*80;
set_char(x, y, c, color);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment