add pio.h

This commit is contained in:
Hojun-Cho 2024-11-27 21:29:33 +09:00
parent 3f556cba19
commit 00a8c3acac
2 changed files with 46 additions and 12 deletions

View File

@ -1,8 +1,11 @@
#include "pio.h"
typedef unsigned short u16;
typedef unsigned char u8;
typedef int dev_t;
#define SCREEN_WIDTH 80
#define SCREEN_LENGTH 25
#define VGA_BUFFER_ADDR 0xb8000
#define VGA_WIDTH 80
#define VGA_LENGTH 25
char*
memcpy(char *a, char *b, int l)
@ -37,20 +40,43 @@ itostr(int n, char *s)
return s;
}
void
setcursor(int x, int y)
{
u16 pos = y * VGA_WIDTH + x;
outb(0x3D4, 0x0F);
outb(0x3D5, (u8) (pos & 0xFF));
outb(0x3D4, 0x0E);
outb(0x3D5, (u8) ((pos >> 8) & 0xFF));
}
void
wr8(u8 c, u8 fg, u8 bg, int x, int y)
{
u16 attrib = (bg << 4) | (fg & 0x0F);
volatile u16 * where;
where = (volatile u16 *)0xB8000 + (y * 80 + x);
*where = c | (attrib << 8);
}
void
boot(dev_t bootdev)
{
char *p;
char s[SCREEN_WIDTH] = "booted on disk:0x";
short* vga = (short*)VGA_BUFFER_ADDR;
char s[VGA_WIDTH] = "booted on disk:0x";
p = s+strlen(s);
p = itostr((int)bootdev, p);
for(int j = 0; j < SCREEN_LENGTH; ++j){
for (int i = 0; i < sizeof(s); ++i) {
vga[(j*SCREEN_WIDTH) + (i + SCREEN_WIDTH*2)] = 0x9100 | s[i];
}
}
while(1)
;
setcursor(0,0);
for (int i = 0; i < sizeof(s); ++i)
wr8(s[i], 0xe8, 0x00, i, 0);
for(int i = 1; i < VGA_LENGTH; ++i)
for(int j = 0; j < VGA_WIDTH; ++j)
wr8(0x00, 0x91, 0x00, j, i);
// disable cursor
outb(0x3D4, 0x0a);
outb(0x3D5, 0x20);
asm("hlt");
}

8
boot/pio.h Normal file
View File

@ -0,0 +1,8 @@
#define outb(port, data) \
(__outb(port, data))
static __inline void
__outb(int port, unsigned char data)
{
__asm volatile("outb %0,%w1" : : "a" (data), "d" (port));
}