add pio.h
This commit is contained in:
parent
3f556cba19
commit
00a8c3acac
50
boot/boot.c
50
boot/boot.c
@ -1,8 +1,11 @@
|
|||||||
|
#include "pio.h"
|
||||||
|
|
||||||
|
typedef unsigned short u16;
|
||||||
|
typedef unsigned char u8;
|
||||||
typedef int dev_t;
|
typedef int dev_t;
|
||||||
|
|
||||||
#define SCREEN_WIDTH 80
|
#define VGA_WIDTH 80
|
||||||
#define SCREEN_LENGTH 25
|
#define VGA_LENGTH 25
|
||||||
#define VGA_BUFFER_ADDR 0xb8000
|
|
||||||
|
|
||||||
char*
|
char*
|
||||||
memcpy(char *a, char *b, int l)
|
memcpy(char *a, char *b, int l)
|
||||||
@ -37,20 +40,43 @@ itostr(int n, char *s)
|
|||||||
return 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
|
void
|
||||||
boot(dev_t bootdev)
|
boot(dev_t bootdev)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
char s[SCREEN_WIDTH] = "booted on disk:0x";
|
char s[VGA_WIDTH] = "booted on disk:0x";
|
||||||
short* vga = (short*)VGA_BUFFER_ADDR;
|
|
||||||
|
|
||||||
p = s+strlen(s);
|
p = s+strlen(s);
|
||||||
p = itostr((int)bootdev, p);
|
p = itostr((int)bootdev, p);
|
||||||
for(int j = 0; j < SCREEN_LENGTH; ++j){
|
setcursor(0,0);
|
||||||
for (int i = 0; i < sizeof(s); ++i) {
|
for (int i = 0; i < sizeof(s); ++i)
|
||||||
vga[(j*SCREEN_WIDTH) + (i + SCREEN_WIDTH*2)] = 0x9100 | 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)
|
||||||
while(1)
|
wr8(0x00, 0x91, 0x00, j, i);
|
||||||
;
|
// disable cursor
|
||||||
|
outb(0x3D4, 0x0a);
|
||||||
|
outb(0x3D5, 0x20);
|
||||||
|
asm("hlt");
|
||||||
}
|
}
|
||||||
|
|||||||
8
boot/pio.h
Normal file
8
boot/pio.h
Normal 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));
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user