mirror of
https://github.com/yourtion/30dayMakeOS.git
synced 2026-02-05 02:53:19 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35ece81b87 | ||
|
|
8205320110 | ||
|
|
362a753c51 | ||
|
|
d946717923 |
@@ -1,3 +1,6 @@
|
||||
OBJS_BOOTPACK = bootpack.obj naskfunc.obj hankaku.obj graphic.obj dsctbl.obj \
|
||||
int.obj
|
||||
|
||||
TOOLPATH = ../z_tools/
|
||||
INCPATH = ../z_tools/haribote/
|
||||
|
||||
@@ -28,45 +31,15 @@ ipl10.bin : ipl10.nas Makefile
|
||||
asmhead.bin : asmhead.nas Makefile
|
||||
$(NASK) asmhead.nas asmhead.bin asmhead.lst
|
||||
|
||||
bootpack.gas : bootpack.c Makefile
|
||||
$(CC1) -o bootpack.gas bootpack.c
|
||||
|
||||
bootpack.nas : bootpack.gas Makefile
|
||||
$(GAS2NASK) bootpack.gas bootpack.nas
|
||||
|
||||
bootpack.obj : bootpack.nas Makefile
|
||||
$(NASK) bootpack.nas bootpack.obj bootpack.lst
|
||||
|
||||
naskfunc.obj : naskfunc.nas Makefile
|
||||
$(NASK) naskfunc.nas naskfunc.obj naskfunc.lst
|
||||
|
||||
hankaku.bin : hankaku.txt Makefile
|
||||
$(MAKEFONT) hankaku.txt hankaku.bin
|
||||
|
||||
hankaku.obj : hankaku.bin Makefile
|
||||
$(BIN2OBJ) hankaku.bin hankaku.obj _hankaku
|
||||
|
||||
graphic.gas : graphic.c Makefile
|
||||
$(CC1) -o graphic.gas graphic.c
|
||||
|
||||
graphic.nas : graphic.gas Makefile
|
||||
$(GAS2NASK) graphic.gas graphic.nas
|
||||
|
||||
graphic.obj : graphic.nas Makefile
|
||||
$(NASK) graphic.nas graphic.obj graphic.lst
|
||||
|
||||
dsctbl.gas : dsctbl.c Makefile
|
||||
$(CC1) -o dsctbl.gas dsctbl.c
|
||||
|
||||
dsctbl.nas : dsctbl.gas Makefile
|
||||
$(GAS2NASK) dsctbl.gas dsctbl.nas
|
||||
|
||||
dsctbl.obj : dsctbl.nas Makefile
|
||||
$(NASK) dsctbl.nas dsctbl.obj dsctbl.lst
|
||||
|
||||
bootpack.bim : bootpack.obj naskfunc.obj hankaku.obj graphic.obj dsctbl.obj Makefile
|
||||
bootpack.bim : $(OBJS_BOOTPACK) Makefile
|
||||
$(OBJ2BIM) @$(RULEFILE) out:bootpack.bim stack:3136k map:bootpack.map \
|
||||
bootpack.obj naskfunc.obj hankaku.obj graphic.obj dsctbl.obj
|
||||
$(OBJS_BOOTPACK)
|
||||
# 3MB+64KB=3136KB
|
||||
|
||||
bootpack.hrb : bootpack.bim Makefile
|
||||
@@ -83,6 +56,17 @@ haribote.img : ipl10.bin haribote.sys Makefile
|
||||
|
||||
# 其他指令
|
||||
|
||||
%.gas : %.c Makefile
|
||||
$(CC1) -o $*.gas $*.c
|
||||
|
||||
%.nas : %.gas Makefile
|
||||
$(GAS2NASK) $*.gas $*.nas
|
||||
|
||||
%.obj : %.nas Makefile
|
||||
$(NASK) $*.nas $*.obj $*.lst
|
||||
|
||||
# 运行程序
|
||||
|
||||
img :
|
||||
$(MAKE) haribote.img
|
||||
|
||||
@@ -98,11 +82,7 @@ install :
|
||||
clean :
|
||||
-$(DEL) *.bin
|
||||
-$(DEL) *.lst
|
||||
-$(DEL) *.gas
|
||||
-$(DEL) *.obj
|
||||
-$(DEL) bootpack.nas
|
||||
-$(DEL) graphic.nas
|
||||
-$(DEL) dsctbl.nas
|
||||
-$(DEL) bootpack.map
|
||||
-$(DEL) bootpack.bim
|
||||
-$(DEL) bootpack.hrb
|
||||
|
||||
@@ -1,74 +1,20 @@
|
||||
/* bootpack */
|
||||
|
||||
#include "bootpack.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void io_hlt(void);
|
||||
void io_cli(void);
|
||||
void io_out8(int port, int data);
|
||||
int io_load_eflags(void);
|
||||
void io_store_eflags(int eflags);
|
||||
|
||||
void init_palette(void);
|
||||
void set_palette(int start, int end, unsigned char *rgb);
|
||||
void boxfill8(unsigned char *vram, int xsize, unsigned char c, int x0, int y0, int x1, int y1);
|
||||
void init_screen8(char *vram, int x, int y);
|
||||
void putfont8(char *vram, int xsize, int x, int y, char c, char *font);
|
||||
void putfonts8_asc(char *vram, int xsize, int x, int y, char c, unsigned char *s);
|
||||
void init_mouse_cursor8(char *mouse, char bc);
|
||||
void putblock8_8(char *vram, int vxsize, int pxsize,
|
||||
int pysize, int px0, int py0, char *buf, int bxsize);
|
||||
|
||||
#define COL8_000000 0
|
||||
#define COL8_FF0000 1
|
||||
#define COL8_00FF00 2
|
||||
#define COL8_FFFF00 3
|
||||
#define COL8_0000FF 4
|
||||
#define COL8_FF00FF 5
|
||||
#define COL8_00FFFF 6
|
||||
#define COL8_FFFFFF 7
|
||||
#define COL8_C6C6C6 8
|
||||
#define COL8_840000 9
|
||||
#define COL8_008400 10
|
||||
#define COL8_848400 11
|
||||
#define COL8_000084 12
|
||||
#define COL8_840084 13
|
||||
#define COL8_008484 14
|
||||
#define COL8_848484 15
|
||||
|
||||
struct BOOTINFO {
|
||||
char cyls, leds, vmode, reserve;
|
||||
short scrnx, scrny;
|
||||
char *vram;
|
||||
};
|
||||
|
||||
struct SEGMENT_DESCRIPTOR {
|
||||
short limit_low, base_low;
|
||||
char base_mid, access_right;
|
||||
char limit_high, base_high;
|
||||
};
|
||||
|
||||
struct GATE_DESCRIPTOR {
|
||||
short offset_low, selector;
|
||||
char dw_count, access_right;
|
||||
short offset_high;
|
||||
};
|
||||
|
||||
void init_gdtidt(void);
|
||||
void set_segmdesc(struct SEGMENT_DESCRIPTOR *sd, unsigned int limit, int base, int ar);
|
||||
void set_gatedesc(struct GATE_DESCRIPTOR *gd, int offset, int selector, int ar);
|
||||
void load_gdtr(int limit, int addr);
|
||||
void load_idtr(int limit, int addr);
|
||||
|
||||
void HariMain(void)
|
||||
{
|
||||
struct BOOTINFO *binfo = (struct BOOTINFO *) 0x0ff0;
|
||||
struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO;
|
||||
char s[40], mcursor[256];
|
||||
int mx, my;
|
||||
|
||||
init_gdtidt();
|
||||
init_pic();
|
||||
io_sti(); /* IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 */
|
||||
|
||||
init_palette();
|
||||
init_screen8(binfo->vram, binfo->scrnx, binfo->scrny);
|
||||
|
||||
mx = (binfo->scrnx - 16) / 2; /* 计算画面的中心坐标*/
|
||||
my = (binfo->scrny - 28 - 16) / 2;
|
||||
init_mouse_cursor8(mcursor, COL8_008484);
|
||||
@@ -76,7 +22,10 @@ void HariMain(void)
|
||||
sprintf(s, "(%d, %d)", mx, my);
|
||||
putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, COL8_FFFFFF, s);
|
||||
|
||||
io_out8(PIC0_IMR, 0xf9); /* PIC1とキーボードを許可(11111001) */
|
||||
io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */
|
||||
|
||||
for (;;) {
|
||||
io_hlt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
92
06_day/bootpack.h
Normal file
92
06_day/bootpack.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/* asmhead.nas */
|
||||
struct BOOTINFO { /* 0x0ff0-0x0fff */
|
||||
char cyls; /* 启动区读磁盘读到此为止 */
|
||||
char leds; /* 启动时键盘的LED的状态 */
|
||||
char vmode; /* 显卡模式为多少位彩色 */
|
||||
char reserve;
|
||||
short scrnx, scrny; /* 画面分辨率 */
|
||||
char *vram;
|
||||
};
|
||||
#define ADR_BOOTINFO 0x00000ff0
|
||||
|
||||
/* naskfunc.nas */
|
||||
void io_hlt(void);
|
||||
void io_cli(void);
|
||||
void io_sti(void);
|
||||
void io_out8(int port, int data);
|
||||
int io_load_eflags(void);
|
||||
void io_store_eflags(int eflags);
|
||||
void load_gdtr(int limit, int addr);
|
||||
void load_idtr(int limit, int addr);
|
||||
void asm_inthandler21(void);
|
||||
void asm_inthandler27(void);
|
||||
void asm_inthandler2c(void);
|
||||
|
||||
/* graphic.c */
|
||||
void init_palette(void);
|
||||
void set_palette(int start, int end, unsigned char *rgb);
|
||||
void boxfill8(unsigned char *vram, int xsize, unsigned char c, int x0, int y0, int x1, int y1);
|
||||
void init_screen8(char *vram, int x, int y);
|
||||
void putfont8(char *vram, int xsize, int x, int y, char c, char *font);
|
||||
void putfonts8_asc(char *vram, int xsize, int x, int y, char c, unsigned char *s);
|
||||
void init_mouse_cursor8(char *mouse, char bc);
|
||||
void putblock8_8(char *vram, int vxsize, int pxsize,
|
||||
int pysize, int px0, int py0, char *buf, int bxsize);
|
||||
#define COL8_000000 0
|
||||
#define COL8_FF0000 1
|
||||
#define COL8_00FF00 2
|
||||
#define COL8_FFFF00 3
|
||||
#define COL8_0000FF 4
|
||||
#define COL8_FF00FF 5
|
||||
#define COL8_00FFFF 6
|
||||
#define COL8_FFFFFF 7
|
||||
#define COL8_C6C6C6 8
|
||||
#define COL8_840000 9
|
||||
#define COL8_008400 10
|
||||
#define COL8_848400 11
|
||||
#define COL8_000084 12
|
||||
#define COL8_840084 13
|
||||
#define COL8_008484 14
|
||||
#define COL8_848484 15
|
||||
|
||||
/* dsctbl.c */
|
||||
struct SEGMENT_DESCRIPTOR {
|
||||
short limit_low, base_low;
|
||||
char base_mid, access_right;
|
||||
char limit_high, base_high;
|
||||
};
|
||||
struct GATE_DESCRIPTOR {
|
||||
short offset_low, selector;
|
||||
char dw_count, access_right;
|
||||
short offset_high;
|
||||
};
|
||||
void init_gdtidt(void);
|
||||
void set_segmdesc(struct SEGMENT_DESCRIPTOR *sd, unsigned int limit, int base, int ar);
|
||||
void set_gatedesc(struct GATE_DESCRIPTOR *gd, int offset, int selector, int ar);
|
||||
#define ADR_IDT 0x0026f800
|
||||
#define LIMIT_IDT 0x000007ff
|
||||
#define ADR_GDT 0x00270000
|
||||
#define LIMIT_GDT 0x0000ffff
|
||||
#define ADR_BOTPAK 0x00280000
|
||||
#define LIMIT_BOTPAK 0x0007ffff
|
||||
#define AR_DATA32_RW 0x4092
|
||||
#define AR_CODE32_ER 0x409a
|
||||
#define AR_INTGATE32 0x008e
|
||||
|
||||
/* int.c */
|
||||
void init_pic(void);
|
||||
void inthandler21(int *esp);
|
||||
void inthandler27(int *esp);
|
||||
void inthandler2c(int *esp);
|
||||
#define PIC0_ICW1 0x0020
|
||||
#define PIC0_OCW2 0x0020
|
||||
#define PIC0_IMR 0x0021
|
||||
#define PIC0_ICW2 0x0021
|
||||
#define PIC0_ICW3 0x0021
|
||||
#define PIC0_ICW4 0x0021
|
||||
#define PIC1_ICW1 0x00a0
|
||||
#define PIC1_OCW2 0x00a0
|
||||
#define PIC1_IMR 0x00a1
|
||||
#define PIC1_ICW2 0x00a1
|
||||
#define PIC1_ICW3 0x00a1
|
||||
#define PIC1_ICW4 0x00a1
|
||||
@@ -1,42 +1,31 @@
|
||||
/* GDT、IDT、descriptor table 关系处理 */
|
||||
|
||||
struct SEGMENT_DESCRIPTOR {
|
||||
short limit_low, base_low;
|
||||
char base_mid, access_right;
|
||||
char limit_high, base_high;
|
||||
};
|
||||
|
||||
struct GATE_DESCRIPTOR {
|
||||
short offset_low, selector;
|
||||
char dw_count, access_right;
|
||||
short offset_high;
|
||||
};
|
||||
|
||||
void init_gdtidt(void);
|
||||
void set_segmdesc(struct SEGMENT_DESCRIPTOR *sd, unsigned int limit, int base, int ar);
|
||||
void set_gatedesc(struct GATE_DESCRIPTOR *gd, int offset, int selector, int ar);
|
||||
void load_gdtr(int limit, int addr);
|
||||
void load_idtr(int limit, int addr);
|
||||
#include "bootpack.h"
|
||||
|
||||
void init_gdtidt(void)
|
||||
{
|
||||
struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) 0x00270000;
|
||||
struct GATE_DESCRIPTOR *idt = (struct GATE_DESCRIPTOR *) 0x0026f800;
|
||||
struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;
|
||||
struct GATE_DESCRIPTOR *idt = (struct GATE_DESCRIPTOR *) ADR_IDT;
|
||||
int i;
|
||||
|
||||
/* GDT初始化 */
|
||||
for (i = 0; i < 8192; i++) {
|
||||
for (i = 0; i <= LIMIT_GDT / 8; i++) {
|
||||
set_segmdesc(gdt + i, 0, 0, 0);
|
||||
}
|
||||
set_segmdesc(gdt + 1, 0xffffffff, 0x00000000, 0x4092);
|
||||
set_segmdesc(gdt + 2, 0x0007ffff, 0x00280000, 0x409a);
|
||||
load_gdtr(0xffff, 0x00270000);
|
||||
set_segmdesc(gdt + 1, 0xffffffff, 0x00000000, AR_DATA32_RW);
|
||||
set_segmdesc(gdt + 2, LIMIT_BOTPAK, ADR_BOTPAK, AR_CODE32_ER);
|
||||
load_gdtr(LIMIT_GDT, ADR_GDT);
|
||||
|
||||
/* IDT初始化 */
|
||||
for (i = 0; i < 256; i++) {
|
||||
for (i = 0; i <= LIMIT_IDT / 8; i++) {
|
||||
set_gatedesc(idt + i, 0, 0, 0);
|
||||
}
|
||||
load_idtr(0x7ff, 0x0026f800);
|
||||
load_idtr(LIMIT_IDT, ADR_IDT);
|
||||
|
||||
/* IDT设置*/
|
||||
set_gatedesc(idt + 0x21, (int) asm_inthandler21, 2 * 8, AR_INTGATE32);
|
||||
set_gatedesc(idt + 0x27, (int) asm_inthandler27, 2 * 8, AR_INTGATE32);
|
||||
set_gatedesc(idt + 0x2c, (int) asm_inthandler2c, 2 * 8, AR_INTGATE32);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,37 +1,6 @@
|
||||
/* 关于绘图部分的处理 */
|
||||
|
||||
void io_hlt(void);
|
||||
void io_cli(void);
|
||||
void io_out8(int port, int data);
|
||||
int io_load_eflags(void);
|
||||
void io_store_eflags(int eflags);
|
||||
|
||||
void init_palette(void);
|
||||
void set_palette(int start, int end, unsigned char *rgb);
|
||||
void boxfill8(unsigned char *vram, int xsize, unsigned char c, int x0, int y0, int x1, int y1);
|
||||
void init_screen8(char *vram, int x, int y);
|
||||
void putfont8(char *vram, int xsize, int x, int y, char c, char *font);
|
||||
void putfonts8_asc(char *vram, int xsize, int x, int y, char c, unsigned char *s);
|
||||
void init_mouse_cursor8(char *mouse, char bc);
|
||||
void putblock8_8(char *vram, int vxsize, int pxsize,
|
||||
int pysize, int px0, int py0, char *buf, int bxsize);
|
||||
|
||||
#define COL8_000000 0
|
||||
#define COL8_FF0000 1
|
||||
#define COL8_00FF00 2
|
||||
#define COL8_FFFF00 3
|
||||
#define COL8_0000FF 4
|
||||
#define COL8_FF00FF 5
|
||||
#define COL8_00FFFF 6
|
||||
#define COL8_FFFFFF 7
|
||||
#define COL8_C6C6C6 8
|
||||
#define COL8_840000 9
|
||||
#define COL8_008400 10
|
||||
#define COL8_848400 11
|
||||
#define COL8_000084 12
|
||||
#define COL8_840084 13
|
||||
#define COL8_008484 14
|
||||
#define COL8_848484 15
|
||||
#include "bootpack.h"
|
||||
|
||||
void init_palette(void)
|
||||
{
|
||||
|
||||
58
06_day/int.c
Normal file
58
06_day/int.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/*初始化关系 */
|
||||
|
||||
#include "bootpack.h"
|
||||
|
||||
void init_pic(void)
|
||||
/* PIC初始化 */
|
||||
{
|
||||
io_out8(PIC0_IMR, 0xff ); /* 禁止所有中断 */
|
||||
io_out8(PIC1_IMR, 0xff ); /* 禁止所有中断 */
|
||||
|
||||
io_out8(PIC0_ICW1, 0x11 ); /* 边缘触发模式(edge trigger mode) */
|
||||
io_out8(PIC0_ICW2, 0x20 ); /* IRQ0-7由INT20-27接收 */
|
||||
io_out8(PIC0_ICW3, 1 << 2); /* PIC1由IRQ2相连 */
|
||||
io_out8(PIC0_ICW4, 0x01 ); /* 无缓冲区模式 */
|
||||
|
||||
io_out8(PIC1_ICW1, 0x11 ); /* 边缘触发模式(edge trigger mode) */
|
||||
io_out8(PIC1_ICW2, 0x28 ); /* IRQ8-15由INT28-2f接收 */
|
||||
io_out8(PIC1_ICW3, 2 ); /* PIC1由IRQ2连接 */
|
||||
io_out8(PIC1_ICW4, 0x01 ); /* 无缓冲区模式 */
|
||||
|
||||
io_out8(PIC0_IMR, 0xfb ); /* 11111011 PIC1以外全部禁止 */
|
||||
io_out8(PIC1_IMR, 0xff ); /* 11111111 禁止所有中断 */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void inthandler21(int *esp)
|
||||
/* 来自PS/2键盘的中断 */
|
||||
{
|
||||
struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO;
|
||||
boxfill8(binfo->vram, binfo->scrnx, COL8_000000, 0, 0, 32 * 8 - 1, 15);
|
||||
putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, COL8_FFFFFF, "INT 21 (IRQ-1) : PS/2 keyboard");
|
||||
for (;;) {
|
||||
io_hlt();
|
||||
}
|
||||
}
|
||||
|
||||
void inthandler2c(int *esp)
|
||||
/* 来自PS/2鼠标的中断 */
|
||||
{
|
||||
struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO;
|
||||
boxfill8(binfo->vram, binfo->scrnx, COL8_000000, 0, 0, 32 * 8 - 1, 15);
|
||||
putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, COL8_FFFFFF, "INT 2C (IRQ-12) : PS/2 mouse");
|
||||
for (;;) {
|
||||
io_hlt();
|
||||
}
|
||||
}
|
||||
|
||||
void inthandler27(int *esp)
|
||||
/* PIC0中断的不完整策略 */
|
||||
/* 这个中断在Athlon64X2上通过芯片组提供的便利,只需执行一次 */
|
||||
/* 这个中断只是接收,不执行任何操作 */
|
||||
/* 为什么不处理?
|
||||
→ 因为这个中断可能是电气噪声引发的、只是处理一些重要的情况。*/
|
||||
{
|
||||
io_out8(PIC0_OCW2, 0x67); /* 通知PIC的IRQ-07(参考7-1) */
|
||||
return;
|
||||
}
|
||||
@@ -11,6 +11,8 @@
|
||||
GLOBAL _io_out8, _io_out16, _io_out32
|
||||
GLOBAL _io_load_eflags, _io_store_eflags
|
||||
GLOBAL _load_gdtr, _load_idtr
|
||||
GLOBAL _asm_inthandler21, _asm_inthandler27, _asm_inthandler2c
|
||||
EXTERN _inthandler21, _inthandler27, _inthandler2c
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
@@ -76,7 +78,7 @@ _io_store_eflags: ; void io_store_eflags(int eflags);
|
||||
PUSH EAX
|
||||
POPFD ; POP EFLAGS
|
||||
RET
|
||||
|
||||
|
||||
_load_gdtr: ; void load_gdtr(int limit, int addr);
|
||||
MOV AX,[ESP+4] ; limit
|
||||
MOV [ESP+6],AX
|
||||
@@ -87,4 +89,52 @@ _load_idtr: ; void load_idtr(int limit, int addr);
|
||||
MOV AX,[ESP+4] ; limit
|
||||
MOV [ESP+6],AX
|
||||
LIDT [ESP+6]
|
||||
RET
|
||||
RET
|
||||
|
||||
_asm_inthandler21:
|
||||
PUSH ES
|
||||
PUSH DS
|
||||
PUSHAD
|
||||
MOV EAX,ESP
|
||||
PUSH EAX
|
||||
MOV AX,SS
|
||||
MOV DS,AX
|
||||
MOV ES,AX
|
||||
CALL _inthandler21
|
||||
POP EAX
|
||||
POPAD
|
||||
POP DS
|
||||
POP ES
|
||||
IRETD
|
||||
|
||||
_asm_inthandler27:
|
||||
PUSH ES
|
||||
PUSH DS
|
||||
PUSHAD
|
||||
MOV EAX,ESP
|
||||
PUSH EAX
|
||||
MOV AX,SS
|
||||
MOV DS,AX
|
||||
MOV ES,AX
|
||||
CALL _inthandler27
|
||||
POP EAX
|
||||
POPAD
|
||||
POP DS
|
||||
POP ES
|
||||
IRETD
|
||||
|
||||
_asm_inthandler2c:
|
||||
PUSH ES
|
||||
PUSH DS
|
||||
PUSHAD
|
||||
MOV EAX,ESP
|
||||
PUSH EAX
|
||||
MOV AX,SS
|
||||
MOV DS,AX
|
||||
MOV ES,AX
|
||||
CALL _inthandler2c
|
||||
POP EAX
|
||||
POPAD
|
||||
POP DS
|
||||
POP ES
|
||||
IRETD
|
||||
|
||||
Reference in New Issue
Block a user