This commit is contained in:
HyperAssembler 2014-09-04 00:44:02 -04:00
parent 3fc652747c
commit 147622ef9b
38 changed files with 196 additions and 3175 deletions

BIN
Cygwin Terminal.lnk Normal file

Binary file not shown.

View File

@ -1,29 +0,0 @@
This is a simple operating system(still being developed). The image file is HOS.img. Please use bochs to see the real effect. What it enters protected mode, starts paging and runs a process. I did not have enough time to write elaborate comments on that. Therefore, just run and selectively read some codes. Please put the provided bochsrc file and the image into the directory of bochs and directly run bochs.exe and you will see the effect.
DIRECTORY:
-boot
Includes the bootloader
-boot.asm
Load the loader into memory(The computer starts executing here).
-loader.asm
Enter protected mode and init paging then load the kernel into memory
-inc
Include files for constants
-Fat12 Header.inc
For FAT12 file system.
-PM.inc
Constants for protected mode.
-kalib
Library in assembly language for protected mode.
-kclib
Library in C for protected mode.
-kernel
Codes executed as OS enters kernel
-lib
Library in assembly language for real mode.
-temp
Some developing functions.
-HOS.img
The OS image.
-makefile
Make command for building the system.
**Compiled by GNU GCC and NASM.

Binary file not shown.

View File

@ -1,25 +0,0 @@
org 07c00h
BaseOfStack equ 07c00h
BaseOfLoader equ 09000h
OffsetOfLoader equ 0100h
jmp short START
%include "FAT12Header.inc"
START:
mov ax, cs
mov ds, ax
mov es, ax
mov ss, ax
mov sp, BaseOfStack
;FAT12ReadFile(ULONG16 Base,ULONG16 Offset,ULONG16 OffsetFileName)
push LoaderFileName
push OffsetOfLoader
push BaseOfLoader
call near FAT12ReadFile
add sp,6
jmp BaseOfLoader:OffsetOfLoader
%include "fat12readfile.lib"
LoaderFileName: db 'LOADER BIN',0
times 510-($-$$) db 0
dw 0xaa55

View File

@ -1,248 +0,0 @@
org 0100h
jmp BEGIN
%include "pm.inc"
;GDT
DESC_VOID: Descriptor 0,0,0
DESC_GRAPH: Descriptor 0b8000h,0ffffh,DA_DRW | DA_DPL3
DESC_FLAT_C: Descriptor 0,0fffffh,DA_CR | DA_32 | DA_LIMIT_4K
DESC_FLAT_RW: Descriptor 0,0fffffh,DA_DRW | DA_32 | DA_LIMIT_4K
DESC_FLAT_USER_C: Descriptor 0,0fffffh,DA_CR | DA_32| DA_LIMIT_4K | DA_DPL3
DESC_FLAT_USER_RW: Descriptor 0,0fffffh,DA_DRW | DA_32 | DA_LIMIT_4K | DA_DPL3
GDTLEN equ $ - DESC_VOID
GDTPTR: dw GDTLEN - 1
dd LOADERINFLAT + DESC_VOID
;Paging
PDEBASE equ 100000h
PTEBASE equ 101000h
;kernel
LOADERBASE equ 09000h
LOADEROFFSET equ 0100h
LOADERINFLAT equ LOADERBASE*10h
KERNELFILENAME db 'KERNEL BIN',0
KERNELBASE equ 03000h
KERNELOFFSET equ 0000h
KERNELINFLAT equ KERNELBASE*10h + KERNELOFFSET
;Selectors
SLCT_FLAT_C equ DESC_FLAT_C - DESC_VOID
SLCT_GRAPH equ DESC_GRAPH - DESC_VOID
SLCT_FLAT_RW equ DESC_FLAT_RW - DESC_VOID
;==================Section .DATA==============================
;Variables
;Operating System Information
;OS:
OSINFO1: db 'Hyper-Assembler Operating System 1.0',0
OSINFO2: db "Loader written by Orange'S, Kernel written by Hyper-Assembler",0
KERNELFILELOADCOMPLETE db 'Kernel.bin Loaded to 0x30000',0
;GETMEMORY
RAMINFO1: db "Memory Information:",0
RAMTABLE16: db ' BASE L BASE H Length L Length H Type ',0
RAMSIZE: db 'RAM SIZE:',0
GETMEMFAIL: db 'Failed to Get The Memory',0
RAMAVAILABLE: db ' - Available',0
RAMRESERVED: db ' - Reserved',0
;Protected Mode:
PMINFO: db 'Protected Mode Entered...',0
PMINFO32 equ PMINFO + LOADERINFLAT
;PAGING:
PGINFO: db 'Paging Started...',0
PGINFO32 equ PGINFO + LOADERINFLAT
PTEINFO: db 'PTE Table BASE: ',0
PTEINFO32 equ PTEINFO + LOADERINFLAT
PDEINFO: db 'PDE Table BASE: ',0
PDEINFO32 equ PDEINFO + LOADERINFLAT
CR3INFO: db 'cr3: ',0
CR3INFO32 equ CR3INFO + LOADERINFLAT
;Variables Used in Functions
IO16_SPACE: db ' ',0
IO32_SPACE equ IO16_SPACE + LOADERINFLAT
IO16_RETURN: db 0Ah,0
IO32_RETURN equ IO16_RETURN + LOADERINFLAT
GRAPHPOS: dd 0
GRAPHPOS_32 equ GRAPHPOS + LOADERINFLAT
GETMEMBUFF: times 1024 db 0
GETMEMNUM: dd 0
GETMEMNUM_32 equ GETMEMBUFF + LOADERINFLAT
DISPMEMTOTAL: dd 0
DISPMEMTOTAL_32 equ DISPMEMTOTAL + LOADERINFLAT
KERNELLOADED: db 'KERNEL LOADED IN MEM.',0
KERNELLOADED_32 equ KERNELLOADED + LOADERINFLAT
%include "FAT12Header.inc"
;=========================STACK32=============================
[bits 32]
STACK32BASE:
times 1024 db 0
TOP:
STACK32TOP equ LOADERINFLAT + TOP
;==========================CODE16==============================
[bits 16]
%include "io16.lib"
%include "fat12readfile.lib"
BEGIN:
mov ax,cs
mov ds,ax
mov ss,ax
mov es,ax
mov ax,0003h
int 10h ;clear
xor eax,eax
mov eax,OSINFO1
push eax
call DISPSTR16
add esp,4
call DISPRETURN16
xor eax,eax
mov eax,OSINFO2
push eax
call DISPSTR16
add esp,4
call DISPRETURN16
call DISPRETURN16
xor eax,eax
mov eax,RAMINFO1
push eax
call DISPSTR16
add esp,4
call DISPRETURN16
call GETMEM16
mov eax,dword [ds:GETMEMNUM]
cmp eax,0
jne GETMEMSUCCESSFUL
xor eax,eax
mov eax,GETMEMFAIL
push eax
call DISPSTR16
pop eax
GETMEMSUCCESSFUL:
call DISPMEM16
call DISPRETURN16
;FAT12ReadFile(ULONG16 Base,ULONG16 Offset,ULONG16 OffsetFileName)
push KERNELFILENAME
push KERNELOFFSET
push KERNELBASE
call FAT12ReadFile
add esp,6
xor eax,eax
mov eax,KERNELFILELOADCOMPLETE
push eax
call DISPSTR16
add esp,4
call DISPRETURN16
;load gdt
lgdt [GDTPTR]
;close interupt
cli
;open A20
in al,92h
or al,00000010b
out 92h,al
;prepare to switch to the protected mode
mov eax,cr0
or eax,1
mov cr0,eax
jmp dword SLCT_FLAT_C:(CODE32_START + LOADERINFLAT)
;===================CODE32======================
[bits 32]
%include "mem32.lib"
%include "io32.lib"
CODE32_START:
mov ax,SLCT_FLAT_RW
mov ss,ax
mov ds,ax
mov es,ax
mov gs,ax
mov ax,SLCT_GRAPH
mov gs,ax
mov sp,STACK32TOP
mov eax,PMINFO32
push eax
call near DISPSTR32
pop eax
;Setup paging
call PAGINGINIT32
call DISPRETURN32
mov eax,PGINFO32
push eax
call near DISPSTR32
pop eax
call DISPRETURN32
;Print PDE Table Base
mov eax,PDEINFO32
push eax
call DISPSTR32
pop eax
mov eax,PDEBASE
push eax
call DISPINTEAX32
pop eax
call DISPRETURN32
;Print PTE table base
mov eax,PTEINFO32
push eax
call DISPSTR32
pop eax
mov eax,PTEBASE
push eax
call DISPINTEAX32
pop eax
call DISPRETURN32
;Print cr3
mov eax,CR3INFO32
push eax
call DISPSTR32
pop eax
mov eax,cr3
push eax
call DISPINTEAX32
pop eax
;Jump to The Kernel
jmp SLCT_FLAT_C:KERNELINFLAT

View File

@ -1,25 +0,0 @@
nop
BS_OEMName DB 'HYPERASM'
BPB_BytsPerSec DW 512
BPB_SecPerClus DB 1
BPB_RsvdSecCnt DW 1
BPB_NumFATs DB 2
BPB_RootEntCnt DW 224
BPB_TotSec16 DW 2880
BPB_Media DB 0xF0
BPB_FATSz16 DW 9
BPB_SecPerTrk DW 18
BPB_NumHeads DW 2
BPB_HiddSec DD 0
BPB_TotSec32 DD 0
BS_DrvNum DB 0
BS_Reserved1 DB 0
BS_BootSig DB 29h
BS_VolID DD 0
BS_VolLab DB 'HYPER_ASM '
BS_FileSysType DB 'FAT12 '
RootDirSectors equ 14
SectorNoOfRootDirectory equ 19
SectorNoOfFAT1 equ 1
DeltaSectorNo equ 17

View File

@ -1,324 +0,0 @@
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; pm.inc
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Forrest Yu, 2005
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; 描述符图示
; 图示一
;
; ------ ┏━━┳━━┓高地址
; 7
; ┣━━┫
;
; 字节 7
;
; ┣━━┫
; 0
; ------ ┣━━╋━━┫
; 7 G
; ┣━━╉──┨
; 6 D
; ┣━━╉──┨
; 5 0
; ┣━━╉──┨
; 4 AVL┃
; 字节 6 ┣━━╉──┨
; 3
; ┣━━┫
; 2
; ┣━━┫
; 1
; ┣━━┫
; 0
; ------ ┣━━╋━━┫
; 7 P
; ┣━━╉──┨
; 6
; ┣━━┫ DPL┃
; 5
; ┣━━╉──┨
; 4 S
; 字节 5 ┣━━╉──┨
; 3
; ┣━━┫ T
; 2 Y
; ┣━━┫ P
; 1 E
; ┣━━┫
; 0
; ------ ┣━━╋━━┫
; 23
; ┣━━┫
; 22
; ┣━━┫
;
; 字节
; 2, 3, 4
; ┣━━┫
; 1
; ┣━━┫
; 0
; ------ ┣━━╋━━┫
; 15
; ┣━━┫
; 14
; ┣━━┫
;
; 字节 0,1
;
; ┣━━┫
; 1
; ┣━━┫
; 0
; ------ ┗━━┻━━┛低地址
;
; 图示二
; 高地址………………………………………………………………………低地址
; | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
; |7654321076543210765432107654321076543210765432107654321076543210| <- 8 字节
; |--------========--------========--------========--------========|
; ┏━━━┳━━━━━━━┳━━━━━━━━━━━┳━━━━━━━┓
; ┃31..24 (见下图) 段基址(23..0) 段界限(15..0)
;
; 基址2┃③│②│ ①┃基址1b│ 基址1a 段界限1
; ┣━━━╋━━━┳━━━╋━━━━━━━━━━━╋━━━━━━━┫
; %6 %5 %4 %3 %2 %1
; ┗━━━┻━━━┻━━━┻━━━┻━━━━━━━┻━━━━━━━┛
; \_________
; \__________________
; \________________________________________________
; \
; ┏━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┓
; 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
; ┣━━╋━━╋━━╋━━╋━━┻━━┻━━┻━━╋━━╋━━┻━━╋━━╋━━┻━━┻━━┻━━┫
; G D 0 AVL┃ 段界限 2 (19..16) P DPL S TYPE
; ┣━━┻━━┻━━┻━━╋━━━━━━━━━━━╋━━┻━━━━━┻━━┻━━━━━━━━━━━┫
; : 属性 2 : 段界限 2 : 属性1
; ┗━━━━━━━━━━━┻━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━┛
; 高地址 低地址
;
;
; 说明:
;
; (1) P: 存在(Present)位。
; P=1 表示描述符对地址转换是有效的,或者说该描述符所描述的段存在,即在内存中;
; P=0 表示描述符对地址转换无效,即该段不存在。使用该描述符进行内存访问时会引起异常。
;
; (2) DPL: 表示描述符特权级(Descriptor Privilege level)共2位。它规定了所描述段的特权级用于特权检查以决定对该段能否访问。
;
; (3) S: 说明描述符的类型。
; 对于存储段描述符而言S=1,以区别与系统段描述符和门描述符(S=0)
;
; (4) TYPE: 说明存储段描述符所描述的存储段的具体属性。
;
;
; 数据段类型 类型值 说明
; ----------------------------------
; 0 只读
; 1 只读、已访问
; 2 /
; 3 /写、已访问
; 4 只读、向下扩展
; 5 只读、向下扩展、已访问
; 6 /写、向下扩展
; 7 /写、向下扩展、已访问
;
;
; 类型值 说明
; 代码段类型 ----------------------------------
; 8 只执行
; 9 只执行、已访问
; A 执行/
; B 执行/读、已访问
; C 只执行、一致码段
; D 只执行、一致码段、已访问
; E 执行/读、一致码段
; F 执行/读、一致码段、已访问
;
;
; 系统段类型 类型编码 说明
; ----------------------------------
; 0 <未定义>
; 1 可用286TSS
; 2 LDT
; 3 忙的286TSS
; 4 286调用门
; 5 任务门
; 6 286中断门
; 7 286陷阱门
; 8 未定义
; 9 可用386TSS
; A <未定义>
; B 忙的386TSS
; C 386调用门
; D <未定义>
; E 386中断门
; F 386陷阱门
;
; (5) G: 段界限粒度(Granularity)位。
; G=0 表示界限粒度为字节;
; G=1 表示界限粒度为4K 字节。
; 注意,界限粒度只对段界限有效,对段基地址无效,段基地址总是以字节为单位。
;
; (6) D: D位是一个很特殊的位在描述可执行段、向下扩展数据段或由SS寄存器寻址的段(通常是堆栈段)的三种描述符中的意义各不相同。
; 在描述可执行段的描述符中D位决定了指令使用的地址及操作数所默认的大小。
; D=1表示默认情况下指令使用32位地址及32位或8位操作数这样的代码段也称为32位代码段
; D=0 表示默认情况下使用16位地址及16位或8位操作数这样的代码段也称为16位代码段它与80286兼容。可以使用地址大小前缀和操作数大小前缀分别改变默认的地址或操作数的大小。
; 在向下扩展数据段的描述符中D位决定段的上部边界。
; D=1表示段的上部界限为4G
; D=0表示段的上部界限为64K这是为了与80286兼容。
; 在描述由SS寄存器寻址的段描述符中D位决定隐式的堆栈访问指令(如PUSH和POP指令)使用何种堆栈指针寄存器。
; D=1表示使用32位堆栈指针寄存器ESP
; D=0表示使用16位堆栈指针寄存器SP这与80286兼容。
;
; (7) AVL: 软件可利用位。80386对该位的使用未左规定Intel公司也保证今后开发生产的处理器只要与80386兼容就不会对该位的使用做任何定义或规定。
;
;----------------------------------------------------------------------------
; 描述符类型值说明
; 其中:
; DA_ : Descriptor Attribute
; D : 数据段
; C : 代码段
; S : 系统段
; R : 只读
; RW : 读写
; A : 已访问
; 其它 : 可按照字面意思理解
;----------------------------------------------------------------------------
DA_32 EQU 4000h ; 32 位段
DA_LIMIT_4K EQU 8000h ; 段界限粒度为 4K 字节
DA_DPL0 EQU 00h ; DPL = 0
DA_DPL1 EQU 20h ; DPL = 1
DA_DPL2 EQU 40h ; DPL = 2
DA_DPL3 EQU 60h ; DPL = 3
;----------------------------------------------------------------------------
; 存储段描述符类型值说明
;----------------------------------------------------------------------------
DA_DR EQU 90h ; 存在的只读数据段类型值
DA_DRW EQU 92h ; 存在的可读写数据段属性值
DA_DRWA EQU 93h ; 存在的已访问可读写数据段类型值
DA_C EQU 98h ; 存在的只执行代码段属性值
DA_CR EQU 9Ah ; 存在的可执行可读代码段属性值
DA_CCO EQU 9Ch ; 存在的只执行一致代码段属性值
DA_CCOR EQU 9Eh ; 存在的可执行可读一致代码段属性值
;----------------------------------------------------------------------------
; 系统段描述符类型值说明
;----------------------------------------------------------------------------
DA_LDT EQU 82h ; 局部描述符表段类型值
DA_TaskGate EQU 85h ; 任务门类型值
DA_386TSS EQU 89h ; 可用 386 任务状态段类型值
DA_386CGate EQU 8Ch ; 386 调用门类型值
DA_386IGate EQU 8Eh ; 386 中断门类型值
DA_386TGate EQU 8Fh ; 386 陷阱门类型值
;----------------------------------------------------------------------------
; 选择子图示:
; ┏━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┓
; 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
; ┣━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━╋━━╋━━┻━━┫
; 描述符索引 TI RPL
; ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━┻━━━━━┛
;
; RPL(Requested Privilege Level): 请求特权级,用于特权检查。
;
; TI(Table Indicator): 引用描述符表指示位
; TI=0 指示从全局描述符表GDT中读取描述符
; TI=1 指示从局部描述符表LDT中读取描述符。
;
;----------------------------------------------------------------------------
; 选择子类型值说明
; 其中:
; SA_ : Selector Attribute
SA_RPL0 EQU 0 ;
SA_RPL1 EQU 1 ; RPL
SA_RPL2 EQU 2 ;
SA_RPL3 EQU 3 ;
SA_TIG EQU 0 ; ┓TI
SA_TIL EQU 4 ;
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; 分页机制使用的常量说明
;----------------------------------------------------------------------------
PG_P EQU 1 ; 页存在属性位
PG_RWR EQU 0 ; R/W 属性位值, /执行
PG_RWW EQU 2 ; R/W 属性位值, //执行
PG_USS EQU 0 ; U/S 属性位值, 系统级
PG_USU EQU 4 ; U/S 属性位值, 用户级
;----------------------------------------------------------------------------
; =========================================
; FLAGS - Intel 8086 Family Flags Register
; =========================================
;
; |11|10|F|E|D|C|B|A|9|8|7|6|5|4|3|2|1|0|
; | | | | | | | | | | | | | | | | | '--- CF……Carry Flag
; | | | | | | | | | | | | | | | | '--- 1
; | | | | | | | | | | | | | | | '--- PF……Parity Flag
; | | | | | | | | | | | | | | '--- 0
; | | | | | | | | | | | | | '--- AF……Auxiliary Flag
; | | | | | | | | | | | | '--- 0
; | | | | | | | | | | | '--- ZF……Zero Flag
; | | | | | | | | | | '--- SF……Sign Flag
; | | | | | | | | | '--- TF……Trap Flag (Single Step)
; | | | | | | | | '--- IF……Interrupt Flag
; | | | | | | | '--- DF……Direction Flag
; | | | | | | '--- OF……Overflow flag
; | | | | '----- IOPL……I/O Privilege Level (286+ only)
; | | | '----- NT……Nested Task Flag (286+ only)
; | | '----- 0
; | '----- RF……Resume Flag (386+ only)
; '------ VM……Virtual Mode Flag (386+ only)
;
; : see PUSHF POPF STI CLI STD CLD
;
; ------------------------------------------------------------------------------------------------------
;
; 描述符
; usage: Descriptor Base, Limit, Attr
; Base: dd
; Limit: dd (low 20 bits available)
; Attr: dw (lower 4 bits of higher byte are always 0)
%macro Descriptor 3
dw %2 & 0FFFFh ; 段界限 1 (2 字节)
dw %1 & 0FFFFh ; 段基址 1 (2 字节)
db (%1 >> 16) & 0FFh ; 段基址 2 (1 字节)
dw ((%2 >> 8) & 0F00h) | (%3 & 0F0FFh) ; 属性 1 + 段界限 2 + 属性 2 (2 字节)
db (%1 >> 24) & 0FFh ; 段基址 3 (1 字节)
%endmacro ; 8 字节
;
;
; usage: Gate Selector, Offset, DCount, Attr
; Selector: dw
; Offset: dd
; DCount: db
; Attr: db
%macro Gate 4
dw (%2 & 0FFFFh) ; 偏移 1 (2 字节)
dw %1 ; 选择子 (2 字节)
dw (%3 & 1Fh) | ((%4 << 8) & 0FF00h) ; 属性 (2 字节)
dw ((%2 >> 16) & 0FFFFh) ; 偏移 2 (2 字节)
%endmacro ; 8 字节
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -1,318 +0,0 @@
;===================================================================32 BITS=============================================================
global __asm_KePrintHex32 ;VOID __asm_KePrintHex32(ULONG32 Hex)
global __asm_KePrintStr32 ;VOID __asm_KePrintStr32(PCHAR *OffsetStr)
global __asm_KeSetGraphPosition32; ULONG32 __asm_KeSetGraphPosition32(ULONG32 Row,ULONG32 Column)
global __asm_KeClearGraph32;VOID __asm_KeClearGraph32()
global __asm_KeGraphRowOverflow;ULONG32 _asm_KeGraphRowOverflow32(ULONG32 GraphPosition)
global __asm_KeGetCurrentGraphPosition32; ULONG32 _asm_KeGetCurrentGraphPosition32(VOID);
extern _KeCheckGraphRowForPrint
extern _KeCheckGraphRowForReturn
SLCT_GRAPH equ 8
SLCT_FLAT_C equ 16
SLCT_FLAT_RW equ 24
KeGraphPosition_32 dd 0
DOSGRAPHROW equ 25
DOSGRAPHCOLUMN equ 80
__asm_KeGetCurrentGraphPosition32:
mov eax, dword [ds:KeGraphPosition_32]
ret
__asm_KeSetGraphPosition32:
push ebp
mov ebp,esp
push esi
push edi
push ebx
push edx
mov eax,dword [ss:ebp+8]
mov ebx,dword [ss:ebp+12]
cmp eax,DOSGRAPHROW-1
ja .fault
cmp ebx,DOSGRAPHCOLUMN-1
ja .fault
mov dl,2*DOSGRAPHCOLUMN
mul dl
mov esi,eax
xor eax,eax
mov al,bl
mov dl,2
mul dl
add eax,esi
mov dword [ds:KeGraphPosition_32],eax
jmp .return
.fault:
mov dword [ds:KeGraphPosition_32],0
xor eax,eax
.return:
pop edx
pop ebx
pop edi
pop esi
mov esp,ebp
pop ebp
ret
__asm_KeClearGraph32:
push ecx
push esi
mov ecx,2*DOSGRAPHROW*DOSGRAPHCOLUMN-1
xor esi,esi
.loop:
mov byte [gs:esi],0
dec ecx
inc esi
cmp ecx,0
jne .loop
mov dword [KeGraphPosition_32],0
pop esi
pop ecx
ret
__asm_KePrintHex32:
;Entrance: push HEX
push ebp
mov ebp,esp
push eax
mov eax,dword [ss:ebp+8]
shr eax,24
mov ah,0Fh
push ax
call near DISPINTAL32
pop ax
mov eax,dword [ss:ebp+8]
shr eax,16
mov ah,0Fh
push ax
call near DISPINTAL32
pop ax
mov eax,dword [ss:ebp+8]
shr eax,8
mov ah,0Fh
push ax
call near DISPINTAL32
pop ax
mov eax,dword [ss:ebp+8]
mov ah,0Fh
push ax
call near DISPINTAL32
pop ax
pop eax
mov esp,ebp
pop ebp
ret
__asm_KePrintStr32:
;Entrance: push offset
;ds:offset = String
push ebp
mov ebp,esp
push esi
push edi
push eax
push ebx
push gs
mov ax,SLCT_GRAPH
mov gs,ax
mov esi,dword [ss:ebp+8]
mov edi,dword [ds:KeGraphPosition_32]
.loop1:
mov al,byte [ds:esi]
cmp al,0
je .end
cmp al,0Ah
jne .loop2
;Check For OverFlow
push eax
push edi
call _KeCheckGraphRowForReturn
add esp,4
mov edi,eax
pop eax
;let edi point to the next row
;edi/(80*2) - every row:80 chars, each char takes 2 bytes.
push eax
mov eax,edi
mov bl,2*DOSGRAPHCOLUMN
div bl
;only keep the low 8 of eax(al,aka quotion)
and eax, 0FFh
inc eax
;calculate the edi now
mov bl,2*DOSGRAPHCOLUMN
mul bl
mov edi,eax
pop eax
inc esi
jmp .loop1
.loop2:
;Check For OverFlow
push eax
push edi
call _KeCheckGraphRowForPrint
add esp,4
mov edi,eax
pop eax
;======
mov ah,0Fh
mov word [gs:edi],ax
add edi,2
inc esi
jmp .loop1
.end:
mov dword [ds:KeGraphPosition_32],edi
pop gs
pop ebx
pop eax
pop edi
pop esi
mov esp,ebp
pop ebp
ret
DISPINTAL32:
;Entrance: push ax ,AH=ATTR, AL=Char
push ebp
mov ebp,esp
push eax
push gs
push ecx
push edi
push ebx
mov edi,dword [ds:KeGraphPosition_32]
mov ax,SLCT_GRAPH
mov gs,ax
xor eax,eax
mov ax, word [ss:ebp+8]
mov bx,ax
;keep high 4 bits of al
and al,0F0H
mov cl,4
shr al,cl
call near CHANGEAL
;Check For OverFlow
push eax
push edi
call _KeCheckGraphRowForPrint
add esp,4
mov edi,eax
pop eax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov word [gs:edi],ax
add edi,2
mov dword [ds:KeGraphPosition_32],edi
;keep low 4 bits of al
mov ax,bx
and al,0Fh
call near CHANGEAL
mov ah,bh
mov word [gs:edi],ax
add edi,2
mov dword [ds:KeGraphPosition_32],edi
pop ebx
pop edi
pop ecx
pop gs
pop eax
pop ebp
ret
CHANGEAL:
;Entrance:void
cmp al,09h
jna .l2
add al,37h
jmp .end
.l2:
add al,30h
.end:
ret
__asm_KeGraphRowOverflow:
push ebp
mov ebp,esp
push esi
push edi
push edx
push ecx
push ebx
mov eax,[ss:ebp+8]
xor esi,esi
xor edi,edi
mov esi,2*DOSGRAPHCOLUMN
mov ebx,DOSGRAPHROW
.loop1:
mov ecx,2*DOSGRAPHCOLUMN-1
.loop2:
mov dl,byte [gs:esi]
mov byte [gs:edi],dl
inc edi
inc esi
dec ecx
cmp ecx,0
jne .loop2
dec ebx
cmp ebx,0
jne .loop1
push 0
push 24
call __asm_KeSetGraphPosition32
add esp,8
mov ecx,2*DOSGRAPHCOLUMN
.loop3:
mov byte [gs:eax],0
inc eax
dec ecx
cmp ecx,0
jne .loop3
push 0
push 24
call __asm_KeSetGraphPosition32
add esp,8
pop ebx
pop ecx
pop edx
pop edi
pop esi
mov esp,ebp
pop ebp
ret

View File

@ -1,257 +0,0 @@
global __asm_KeWritePort;VOID _asm_KeWritePort(ULONG16 Port,ULONG8 Value);
global __asm_KeReadPort;ULONG8 _asm_KeReadPort(ULONG16 Port);
global __asm_KeLoadIDT;VOID _asm_KeLoadIDT(VOID)
global __asm_KeWriteGDT; VOID _asm_KeWriteGDT(PGDT_DESCRIPTOR DescBase ,PWrite_GDT_DESCRIPTOR PDescriptor, ULONG32 index);
;IDT DESC
global __asm_KeDivideError
global __asm_KeSingleStepException
global __asm_KeNMI
global __asm_KeBreakpointException
global __asm_KeOverflow
global __asm_KeBoundsCheck
global __asm_KeInvalidOpcode
global __asm_KeCoprNotAvailable
global __asm_KeDoubleFault
global __asm_KeCoprSegmentOverrun
global __asm_KeInvalidTSS
global __asm_KeSegmentNotPresent
global __asm_KeStackException
global __asm_KeGeneralProtection
global __asm_KePageFault
global __asm_KeCoprError
;8259A Interrupts
global __asm_KeIrqInt00
global __asm_KeIrqInt01
global __asm_KeIrqInt02
global __asm_KeIrqInt03
global __asm_KeIrqInt04
global __asm_KeIrqInt05
global __asm_KeIrqInt06
global __asm_KeIrqInt07
global __asm_KeIrqInt08
global __asm_KeIrqInt09
global __asm_KeIrqInt10
global __asm_KeIrqInt11
global __asm_KeIrqInt12
global __asm_KeIrqInt13
global __asm_KeIrqInt14
global __asm_KeIrqInt15
global __asm_EIP2EAX
extern _KeIrqIntHandler
extern _KeIDTPtr
extern _KeExceptionHandler
SLCT_FLAT_C equ 16
__asm_EIP2EAX:
mov eax, [esp]
ret
__asm_KeReadPort:
mov edx, [esp + 4]
xor eax, eax
in al, dx
nop
nop
ret
;push ebp
;mov ebp,esp
;push edx
;mov edx,[ss:ebp+8]
;xor eax,eax
;in al,dx
;nop
;nop
;nop
;pop edx
;pop ebp
;ret
__asm_KeWritePort:
mov edx, [esp + 4]
mov al, [esp + 4 + 4]
out dx, al
nop
nop
ret
;push ebp
;mov ebp,esp
;push edx
;push eax
;mov edx,[ss:ebp+8]
;mov eax,[ss:ebp+12]
;out dx,al
;nop
;nop
;nop
;pop eax
;pop edx
;ret
__asm_KeLoadIDT:
lidt [_KeIDTPtr]
jmp SLCT_FLAT_C:.force
.force:
sti
ret
__asm_KeDivideError:
push 0xFFFFFFFF
push 0
jmp exception
__asm_KeSingleStepException:
push 0xFFFFFFFF
push 1
jmp exception
__asm_KeNMI:
push 0xFFFFFFFF
push 2
jmp exception
__asm_KeBreakpointException:
push 0xFFFFFFFF
push 3
jmp exception
__asm_KeOverflow:
push 0xFFFFFFFF
push 4
jmp exception
__asm_KeBoundsCheck:
push 0xFFFFFFFF
push 5
jmp exception
__asm_KeInvalidOpcode:
push 0xFFFFFFFF
push 6
jmp exception
__asm_KeCoprNotAvailable:
push 0xFFFFFFFF
push 7
jmp exception
__asm_KeDoubleFault:
push 0xFFFFFFFF
push 8
jmp exception
__asm_KeCoprSegmentOverrun:
push 0xFFFFFFFF
push 9
jmp exception
__asm_KeInvalidTSS:
push 0xFFFFFFFF
push 10
jmp exception
__asm_KeSegmentNotPresent:
push 0xFFFFFFFF
push 11
jmp exception
__asm_KeStackException:
push 0xFFFFFFFF
push 12
jmp exception
__asm_KeGeneralProtection:
push 0xFFFFFFFF
push 13
jmp exception
__asm_KePageFault:
push 0xFFFFFFFF
push 14
jmp exception
__asm_KeCoprError:
push 0xFFFFFFFF
push 15
jmp exception
exception:
call _KeExceptionHandler
add esp,8
hlt
__asm_KeIrqInt00:
push 0
jmp interrupt
__asm_KeIrqInt01:
push 1
jmp interrupt
__asm_KeIrqInt02:
push 2
jmp interrupt
__asm_KeIrqInt03:
push 3
jmp interrupt
__asm_KeIrqInt04:
push 4
jmp interrupt
__asm_KeIrqInt05:
push 5
jmp interrupt
__asm_KeIrqInt06:
push 6
jmp interrupt
__asm_KeIrqInt07:
push 7
jmp interrupt
__asm_KeIrqInt08:
push 8
jmp interrupt
__asm_KeIrqInt09:
push 9
jmp interrupt
__asm_KeIrqInt10:
push 10
jmp interrupt
__asm_KeIrqInt11:
push 11
jmp interrupt
__asm_KeIrqInt12:
push 12
jmp interrupt
__asm_KeIrqInt13:
push 13
jmp interrupt
__asm_KeIrqInt14:
push 14
jmp interrupt
__asm_KeIrqInt15:
push 15
jmp interrupt
interrupt:
call _KeIrqIntHandler
add esp,4
hlt

View File

@ -1,34 +0,0 @@
SLCT_GRAPH equ 8
SLCT_FLAT_C equ 16
SLCT_FLAT_RW equ 24
global __asm_KeMemoryCopy;PVOID _asm_KeMemoryCopy(PVOID src,PVOID dst,ULONG32 size)
__asm_KeMemoryCopy:
push ebp
mov ebp,esp
push esi
push edi
push ecx
mov ax,SLCT_FLAT_RW
mov es,ax
mov esi,dword [ss:ebp+8]
mov edi,dword [ss:ebp+12]
mov ecx,dword [ss:ebp+16]
.loop:
mov al,byte [es:esi]
mov byte [ds:edi],al
inc esi
inc edi
dec ecx
cmp ecx,0
je .end
jmp .loop
.end:
mov eax,dword [ss:ebp+8]
pop ecx
pop edi
pop esi
pop ebp
ret

View File

@ -1,56 +0,0 @@
P_STACKBASE equ 0
GSREG equ P_STACKBASE
FSREG equ GSREG + 4
ESREG equ FSREG + 4
DSREG equ ESREG + 4
EDIREG equ DSREG + 4
ESIREG equ EDIREG + 4
EBPREG equ ESIREG + 4
KERNELESPREG equ EBPREG + 4
EBXREG equ KERNELESPREG + 4
EDXREG equ EBXREG + 4
ECXREG equ EDXREG + 4
EAXREG equ ECXREG + 4
RETADR equ EAXREG + 4
EIPREG equ RETADR + 4
CSREG equ EIPREG + 4
EFLAGSREG equ CSREG + 4
ESPREG equ EFLAGSREG + 4
SSREG equ ESPREG + 4
P_STACKTOP equ SSREG + 4
P_LDT_SEL equ P_STACKTOP
P_LDT equ P_LDT_SEL + 2
TSS3_S_SP0 equ 4
extern _KeTSS
extern _PStartProcess
global __asm_KeLoadTSS;
global __asm_Restart;
__asm_KeLoadTSS:
push ebp
mov ebp,esp
push eax
;mov eax,dword [ss:ebp+8]
mov eax,56
ltr ax
pop eax
mov esp,ebp
pop ebp
ret
__asm_Restart:
mov esp,[_PStartProcess]
lea eax,[esp+P_STACKTOP]
mov dword [_KeTSS+TSS3_S_SP0],eax
pop gs
pop fs
pop es
pop ds
popad
add esp,4
iretd

View File

@ -1,306 +0,0 @@
#ifndef _KeDef_h_
#define _KeDef_h_
//Types
typedef unsigned int ULONG32,*PULONG32;
typedef unsigned int DWORD,*PDWORD;
typedef unsigned long long QWORD,*PQWORD;
typedef unsigned long long ULONG64,*PULONG64;
typedef unsigned char ULONG8,*PULONG8;
typedef unsigned char BYTE,*PBYTE;
typedef unsigned short ULONG16,*PULONG16;
typedef void VOID,*PVOID;
typedef char CHAR,*PCHAR;
//Physical Addresses
#define GDT_SELECTOR(Index,RPL) (((Index) << 3) + (RPL))
#define GDT_SELECTOR_DUMMY GDT_SELECTOR(0,0)
#define GDT_SELECTOR_GRAPH GDT_SELECTOR(1,0)
#define GDT_SELECTOR_CODE GDT_SELECTOR(2,0)
#define GDT_SELECTOR_DATA GDT_SELECTOR(3,0)
#define GDT_SELECTOR_USER_DATA GDT_SELECTOR(4,3)
#define GDT_SELECTOR_USER_CODE GDT_SELECTOR(5,3)
#define GDT_SELECTOR_LDT GDT_SELECTOR(6,0)
#define GDT_SELECTOR_TSS GDT_SELECTOR(7,0)
#define GDT_INDEX_DUMMY 0
#define GDT_INDEX_GRAPH 1
#define GDT_INDEX_CODE 2
#define GDT_INDEX_DATA 3
#define GDT_INDEX_USER_CODE 4
#define GDT_INDEX_USER_DATA 5
#define GDT_INDEX_LDT 6
#define GDT_INDEX_TSS 7
// #define LDT_SELECTOR_CODE 0
// #define LDT_SELECTOR_DATA 8
// #define LDT_SELECTOR_GRAPH 16
// #define LDT_INDEX_CODE 0
// #define LDT_INDEX_DATA 1
// #define LDT_INDEX_GRAPH 2
#define KeKernelPhysicalAddress 0x30000
#define KeLoaderPhysicalAddress 0x90000
#define KeBootPhysicalAddress 0x07c00
#define KePDEBase 0x100000
#define KePTEBase 0x101000
//DTs
#define GDT_DESCRIPTOR_NUMBER 128
#define IDT_GATE_NUMBER 256
#define LDT_DESCRIPTOR_NUMBER 3
#define MAXIMUM_PROCESS_NUMBER 1
#define PROCESS_STACK_MAX_SIZE 1024
//SegmentDescriptor_Attribute
//IDT
#define INT_M_CTL 0x20
#define INT_M_CTLMASK 0x21
#define INT_S_CTL 0xA0
#define INT_S_CTLMASK 0xA1
#define INT_VECTOR_IRQ0 0x20
#define INT_VECTOR_IRQ8 0x28
#define DA_32 0x4000 /* 32 位段 */
#define DA_LIMIT_4K 0x8000 /* 段界限粒度为 4K 字节 */
#define DA_DPL0 0x00 /* DPL = 0 */
#define DA_DPL1 0x20 /* DPL = 1 */
#define DA_DPL2 0x40 /* DPL = 2 */
#define DA_DPL3 0x60 /* DPL = 3 */
/* 存储段描述符类型值说明 */
#define DA_DR 0x90 /* 存在的只读数据段类型值 */
#define DA_DRW 0x92 /* 存在的可读写数据段属性值 */
#define DA_DRWA 0x93 /* 存在的已访问可读写数据段类型值 */
#define DA_C 0x98 /* 存在的只执行代码段属性值 */
#define DA_CR 0x9A /* 存在的可执行可读代码段属性值 */
#define DA_CCO 0x9C /* 存在的只执行一致代码段属性值 */
#define DA_CCOR 0x9E /* 存在的可执行可读一致代码段属性值 */
/* 系统段描述符类型值说明 */
#define DA_LDT 0x82 /* 局部描述符表段类型值 */
#define DA_TaskGate 0x85 /* 任务门类型值 */
#define DA_386TSS 0x89 /* 可用 386 任务状态段类型值 */
#define DA_386CGate 0x8C /* 386 调用门类型值 */
#define DA_386IGate 0x8E /* 386 中断门类型值 */
#define DA_386TGate 0x8F /* 386 陷阱门类型值 */
/* 选择子类型值说明 */
/* 其中, SA_ : Selector Attribute */
#define SA_RPL_MASK 0xFFFC
#define SA_RPL0 0
#define SA_RPL1 1
#define SA_RPL2 2
#define SA_RPL3 3
#define SA_TI_MASK 0xFFFB
#define SA_TIG 0
#define SA_TIL 4
/* RPL */
#define RPL_KRNL SA_RPL0
#define RPL_TASK SA_RPL1
#define RPL_USER SA_RPL3
//
#define INT_VECTOR_DIVIDE 0x0
#define INT_VECTOR_DEBUG 0x1
#define INT_VECTOR_NMI 0x2
#define INT_VECTOR_BREAKPOINT 0x3
#define INT_VECTOR_OVERFLOW 0x4
#define INT_VECTOR_BOUNDS 0x5
#define INT_VECTOR_INVAL_OP 0x6
#define INT_VECTOR_COPROC_NOT 0x7
#define INT_VECTOR_DOUBLE_FAULT 0x8
#define INT_VECTOR_COPROC_SEG 0x9
#define INT_VECTOR_INVAL_TSS 0xA
#define INT_VECTOR_SEG_NOT 0xB
#define INT_VECTOR_STACK_FAULT 0xC
#define INT_VECTOR_PROTECTION 0xD
#define INT_VECTOR_PAGE_FAULT 0xE
#define INT_VECTOR_COPROC_ERR 0x10
//System Data Structures
#pragma pack(push)
#pragma pack(1)
typedef struct _GDT_DESCRIPTOR
{
ULONG16 LimitLow;
ULONG16 BaseLow;
ULONG8 BaseMid;
ULONG8 Attr1;
ULONG8 LimitHigh_Attr2;
ULONG8 BaseHigh;
} GDT_DESCRIPTOR,*PGDT_DESCRIPTOR;
typedef GDT_DESCRIPTOR LDT_DESCRIPTOR,*PLDT_DESCRIPTRO;
typedef struct _GATE
{
ULONG16 OffsetLow;
ULONG16 Selector;
ULONG8 Count;
ULONG8 Attr;
ULONG16 OffsetHigh;
} GATE,*PGATE;
//Write GDT
#define KeWriteGDT_AVL_1 0x00100000
#define KeWriteGDT_AVL_0 0x0
#define KeWriteGDT_DB_0 0x0
#define KeWriteGDT_DB_1 0x00400000
#define KeWriteGDT_P_0 0x0
#define KeWriteGDT_P_1 0x00008000
#define KeWriteGDT_G_0 0x0
#define KeWriteGDT_G_1 0x00800000
#define KeWriteGDT_L_0 0x0
#define KeWriteGDT_L_1 0x00200000
#define KeWriteGDT_DPL_0 0x0
#define KeWriteGDT_DPL_1 0x00002000
#define KeWriteGDT_DPL_2 0x00004000
#define KeWriteGDT_DPL_3 0x00006000
#define KeWriteGDT_S_0 0x0
#define KeWriteGDT_S_1 0x00001000
#define KeWriteGDT_Type_Data_ReadOnly 0x0
#define KeWriteGDT_Type_Data_ReadOnlyAccessed 0x00000100
#define KeWriteGDT_Type_Data_ReadWrite 0x00000200
#define KeWriteGDT_Type_Data_ReadWriteAccessed 0x00000300
#define KeWriteGDT_Type_Data_ReadOnlyExpandDown 0x00000400
#define KeWriteGDT_Type_Data_ReadOnlyExpandDownAccessed 0x00000500
#define KeWriteGDT_Type_Data_ReadWriteExpandDown 0x00000600
#define KeWriteGDT_Type_Data_ReadWriteExpandDownAccessed 0x00000700
#define KeWriteGDT_Type_Code_ExecuteOnly 0x00000800
#define KeWriteGDT_Type_Code_ExecuteOnlyAccessed 0x00000900
#define KeWriteGDT_Type_Code_ExecuteRead 0x00000A00
#define KeWriteGDT_Type_Code_ExecuteReadAccessed 0x00000B00
#define KeWriteGDT_Type_Code_ExecuteOnlyConforming 0x00000C00
#define KeWriteGDT_Type_Code_ExecuteOnlyConformingAccessed 0x00000D00
#define KeWriteGDT_Type_Code_ExecuteReadConforming 0x00000E00
#define KeWriteGDT_Type_Code_ExecuteReadConformingAccessed 0x00000F00
#define KeWriteGDT_Type_System_Reserved1 0x00000000
#define KeWriteGDT_Type_System_16BitsTssAvailable 0x00000100
#define KeWriteGDT_Type_System_LDT 0x00000200
#define KeWriteGDT_Type_System_16BitsTssBusy 0x00000300
#define KeWriteGDT_Type_System_16BitsCallGate 0x00000400
#define KeWriteGDT_Type_System_TaskGate 0x00000500
#define KeWriteGDT_Type_System_16BitsInterruptGate 0x00000600
#define KeWriteGDT_Type_System_16BitsTrapGate 0x00000700
#define KeWriteGDT_Type_System_Reserved2 0x00000800
#define KeWriteGDT_Type_System_32BitsTSSAvailable 0x00000900
#define KeWriteGDT_Type_System_Reserved3 0x00000A00
#define KeWriteGDT_Type_System_32BitsTSSBusy 0x00000B00
#define KeWriteGDT_Type_System_32BitsCallGate 0x00000C00
#define KeWriteGDT_Type_System_Reserved4 0x00000D00
#define KeWriteGDT_Type_System_32BitsInterruptGate 0x00000E00
#define KeWriteGDT_Type_System_32BitsTrapGate 0x00000F00
typedef struct _Write_GDT_DESCRIPTOR
{
ULONG32 Base; //+0
ULONG32 Limit; //+4
ULONG32 AVL; //+8
ULONG32 DB; // +12
ULONG32 P; //+16
ULONG32 DPL; // +20
ULONG32 G; //+24
ULONG32 S; //+28
ULONG32 Type; //+32
} Write_GDT_DESCRIPTOR, *PWrite_GDT_DESCRIPTOR;
#define KeWriteIDT_P_0 0x0
#define KeWriteIDT_P_1 0x00008000
#define KeWriteIDT_DPL_0 0x0
#define KeWriteIDT_DPL_1 0x00002000
#define KeWriteIDT_DPL_2 0x00004000
#define KeWriteIDT_DPL_3 0x00006000
#define KeWriteIDT_D_0 0x0
#define KeWriteIDT_D_1 2048
#define KeWriteIDT_GateType_TaskGate 256
#define KeWriteIDT_GateType_InterruptGate 1536
#define KeWriteIDT_GateType_TrapGate 1792
//IDT Descriptor
typedef struct _Write_IDT_DESCRIPTOR
{
ULONG32 D;
ULONG32 Offset;
ULONG32 Selector;
ULONG32 DPL;
ULONG32 P;
ULONG32 GateType;
} Write_IDT_DESCRIPTOR, *PWrite_IDT_DESCRIPTOR;
//Process Stuff
typedef struct _hProcess_RestartStack
{
ULONG32 gs;
ULONG32 fs;
ULONG32 es;
ULONG32 ds;
ULONG32 edi;
ULONG32 esi;
ULONG32 ebp;
ULONG32 Kernel_esp;
ULONG32 ebx;
ULONG32 edx;
ULONG32 ecx;
ULONG32 eax;
ULONG32 ReturnAddress;
ULONG32 eip;
ULONG32 cs;
ULONG32 eFlags;
ULONG32 esp;
ULONG32 ss;
} hProcess_RestartStack,*PhProcess_RestartStack;
typedef ULONG32 PROCESSPRIVILEGE;
#define Process_Priviliege_User 0x01
#define Process_Priviliege_Kernel 0x00
typedef struct _hProcess
{
hProcess_RestartStack RestartStack;
//ULONG16 LDTSelector;
//LDT_DESCRIPTOR ProcessLDT[LDT_DESCRIPTOR_NUMBER];
ULONG32 ProcessID;
PCHAR ProcessName;
PROCESSPRIVILEGE Privilege;
} hPrcocess,*PhProcess;
typedef struct _TSS {
ULONG32 BackLine;
ULONG32 esp0;
ULONG32 ss0;
ULONG32 esp1;
ULONG32 ss1;
ULONG32 esp2;
ULONG32 ss2;
ULONG32 cr3;
ULONG32 eip;
ULONG32 flags;
ULONG32 eax;
ULONG32 ecx;
ULONG32 edx;
ULONG32 ebx;
ULONG32 esp;
ULONG32 ebp;
ULONG32 esi;
ULONG32 edi;
ULONG32 es;
ULONG32 cs;
ULONG32 ss;
ULONG32 ds;
ULONG32 fs;
ULONG32 gs;
ULONG32 LDT;
ULONG16 Trap;
ULONG16 IOBase;
} TSS,*PTSS;
typedef VOID (*PExceptionHandleFunc)(VOID);
#pragma pack(pop)
#endif

View File

@ -1,13 +0,0 @@
#include "KeDef.h"
#ifndef _KeGlobalVariables_h_
#define _KeGlobalVariables_h_
ULONG8 KeGDTPtr[6];
GDT_DESCRIPTOR KeGDT[GDT_DESCRIPTOR_NUMBER];
ULONG8 KeIDTPtr[6];
TSS KeTSS;
GATE KeIDT[IDT_GATE_NUMBER];
PhProcess PStartProcess;
hPrcocess KeUserProcessTable[MAXIMUM_PROCESS_NUMBER];
hPrcocess KeKernelProcessTable[MAXIMUM_PROCESS_NUMBER];
#endif
//Global Variables

View File

@ -1,46 +0,0 @@
#include "KeDef.h"
#include "KeGlobalVariables.h"
#ifndef _KeGraph32_h_
#define _KeGraph32_h_
#define DOSGraphColumn 80
#define DOSGraphRow 25
#define DOSGraphMaxBytes 4000
#define DOSGraphBase 0xb8000
VOID _asm_KePrintHex32(ULONG32 Hex);
VOID _asm_KePrintStr32(PCHAR OffsetStr);
ULONG32 _asm_KeSetGraphPosition32(ULONG32 Row,ULONG32 Column);
VOID _asm_KeClearGraph32(VOID);
ULONG32 _asm_KeGraphRowOverflow(ULONG32 GraphPosition);
ULONG32 KeCheckGraphRowForPrint(ULONG32 GraphPosition);
ULONG32 KeCheckGraphRowForReturn(ULONG32 GraphPosition);
ULONG32 _asm_KeGetCurrentGraphPosition32(VOID);
ULONG32 KeGetCurrentGraphRow(ULONG32 GraphPosition);
ULONG32 KeGetCurrentGraphRow(ULONG32 GraphPosition)
{
return (GraphPosition/2*DOSGraphColumn);
}
ULONG32 KeCheckGraphRowForPrint(ULONG32 GraphPosition)
{
if(GraphPosition>=DOSGraphMaxBytes)
{
GraphPosition = _asm_KeGraphRowOverflow(GraphPosition);
}
return GraphPosition;
}
ULONG32 KeCheckGraphRowForReturn(ULONG32 GraphPosition)
{
ULONG32 GraphRow = GraphPosition/(2*DOSGraphColumn);
if(GraphRow >= (DOSGraphRow-1))
{
GraphPosition = _asm_KeGraphRowOverflow(GraphPosition);
GraphPosition = _asm_KeSetGraphPosition32(23,0);
}
return GraphPosition;
}
#endif

View File

@ -1,317 +0,0 @@
#include "KeDef.h"
#include "KeGlobalVariables.h"
#include "KeGraph32.h"
#include "KeMemory32.h"
#ifndef _asm_KeIO32_h_
#define _asm_KeIO32_h_
//What e verrrrr
//asdasdasd1
#define PRIVILEGE_KERNEL 0
#define PRIVILEGE_TASK 1
#define PRIVILEGE_USER 3
VOID _asm_KeWritePort(ULONG16 Port,ULONG8 Value);
ULONG8 _asm_KeReadPort(ULONG16 Port);
VOID _asm_KeLoadIDT(VOID);
VOID KeInit8259A(VOID);
VOID KeInitInterrupt(VOID);
VOID KeSwitchGDT(VOID);
VOID KeInitIDT(VOID);
VOID KeWriteGDT(ULONG32 Index,PGDT_DESCRIPTOR Dest, PWrite_GDT_DESCRIPTOR Src);
VOID KeWriteIDT(ULONG32 Index,PGATE Dest ,PWrite_IDT_DESCRIPTOR Src);
VOID KeExceptionHandler(ULONG32 VectorNumber,ULONG32 ErrorCode,ULONG32 eip,ULONG32 cs,ULONG32 eFlags);
VOID _asm_KeDivideError(VOID);
VOID _asm_KeSingleStepException(VOID);
VOID _asm_KeNMI(VOID);
VOID _asm_KeBreakpointException(VOID);
VOID _asm_KeOverflow(VOID);
VOID _asm_KeBoundsCheck(VOID);
VOID _asm_KeInvalidOpcode(VOID);
VOID _asm_KeCoprNotAvailable(VOID);
VOID _asm_KeDoubleFault(VOID);
VOID _asm_KeCoprSegmentOverrun(VOID);
VOID _asm_KeInvalidTSS(VOID);
VOID _asm_KeSegmentNotPresent(VOID);
VOID _asm_KeStackException(VOID);
VOID _asm_KeGeneralProtection(VOID);
VOID _asm_KePageFault(VOID);
VOID _asm_KeCoprError(VOID);
VOID KeIrqIntHandler(ULONG32 IrqNumber);
VOID _asm_KeIrqInt00(VOID);
VOID _asm_KeIrqInt01(VOID);
VOID _asm_KeIrqInt02(VOID);
VOID _asm_KeIrqInt03(VOID);
VOID _asm_KeIrqInt04(VOID);
VOID _asm_KeIrqInt05(VOID);
VOID _asm_KeIrqInt06(VOID);
VOID _asm_KeIrqInt07(VOID);
VOID _asm_KeIrqInt08(VOID);
VOID _asm_KeIrqInt09(VOID);
VOID _asm_KeIrqInt10(VOID);
VOID _asm_KeIrqInt11(VOID);
VOID _asm_KeIrqInt12(VOID);
VOID _asm_KeIrqInt13(VOID);
VOID _asm_KeIrqInt14(VOID);
VOID _asm_KeIrqInt15(VOID);
VOID KeInitializeWriteGDTDescriptor(PWrite_GDT_DESCRIPTOR Desc, ULONG32 Base, ULONG32 Limit, ULONG32 G, ULONG32 P, ULONG32 S, ULONG32 Type, ULONG32 DPL, ULONG32 DB, ULONG32 AVL);
VOID KeInitializeWriteIDTDescriptor(PWrite_IDT_DESCRIPTOR Desc,ULONG32 GateType, ULONG32 DPL, ULONG32 D, ULONG32 P, ULONG32 Selector, ULONG32 Offset);
VOID KeWriteGDT(ULONG32 Index,PGDT_DESCRIPTOR Dest, PWrite_GDT_DESCRIPTOR Src)
{ //To be test by the previous one
ULONG32 temp = 0;
ULONG32 datal = 0;
ULONG32 datah = 0;
temp = (Src->Base);
datal = ((temp & 0x0000ffff) << 16 );
temp = Src->Limit;
datal = datal + (temp & 0x0000ffff);
temp = Src->Base;
datah = (temp & 0xff000000);
datah = datah + Src->AVL;
datah = datah + Src->DB;
datah = datah + Src->G;
datah = datah + Src->P;
datah = datah + Src->S;
datah = datah + Src->DPL;
datah = datah + Src->Type;
temp = Src->Limit;
temp = temp & 0x000f0000;
datah = datah + temp;
temp = Src->Base;
datah = datah + ((temp & 0x00ff0000) >> 16);
*(PULONG32)(Dest+Index) = datal;
*((PULONG32)(Dest+Index)+1) = datah;
return;
}
VOID KeInitializeWriteGDTDescriptor(PWrite_GDT_DESCRIPTOR Desc, ULONG32 Base, ULONG32 Limit, ULONG32 G, ULONG32 P, ULONG32 S, ULONG32 Type, ULONG32 DPL, ULONG32 DB, ULONG32 AVL)
{
Desc->Base = Base;
Desc->Limit = Limit;
Desc->G = G;
Desc->P = P;
Desc->S = S;
Desc->Type = Type;
Desc->DPL = DPL;
Desc->DB = DB;
Desc->AVL = AVL;
return;
}
VOID KeInitializeWriteIDTDescriptor(PWrite_IDT_DESCRIPTOR Desc,ULONG32 GateType, ULONG32 DPL, ULONG32 D, ULONG32 P, ULONG32 Selector, ULONG32 Offset)
{
Desc->GateType = GateType;
Desc->DPL = DPL;
Desc->D = D;
Desc->P = P;
Desc->Selector = Selector;
Desc->Offset = Offset;
return;
}
VOID KeSwitchGDT(VOID)
{
Write_GDT_DESCRIPTOR i;
*((PULONG16)(&KeGDTPtr[0]))= GDT_DESCRIPTOR_NUMBER * sizeof(GDT_DESCRIPTOR)-1;
*((PULONG32)(&KeGDTPtr[2])) = (ULONG32)&KeGDT[0];
KeInitializeWriteGDTDescriptor(&i,0x0,0xfffff,KeWriteGDT_G_1,KeWriteGDT_P_1,KeWriteGDT_S_1,KeWriteGDT_Type_Code_ExecuteOnly,KeWriteGDT_DPL_0,KeWriteGDT_DB_1,KeWriteGDT_AVL_0);
KeWriteGDT(GDT_INDEX_CODE,&KeGDT[0],&i);
KeInitializeWriteGDTDescriptor(&i,0x0b8000,0xffff,KeWriteGDT_G_0,KeWriteGDT_P_1,KeWriteGDT_S_1,KeWriteGDT_Type_Data_ReadWrite,KeWriteGDT_DPL_3,KeWriteGDT_DB_0,KeWriteGDT_AVL_0);
KeWriteGDT(GDT_INDEX_GRAPH,&KeGDT[0],&i);
KeInitializeWriteGDTDescriptor(&i,0x0,0xfffff,KeWriteGDT_G_1,KeWriteGDT_P_1,KeWriteGDT_S_1,KeWriteGDT_Type_Data_ReadWrite,KeWriteGDT_DPL_0,KeWriteGDT_DB_1,KeWriteGDT_AVL_0);
KeWriteGDT(GDT_INDEX_DATA,&KeGDT[0],&i);
KeInitializeWriteGDTDescriptor(&i,0,0,0,0,0,0,0,0,0);
KeWriteGDT(GDT_INDEX_DUMMY,&KeGDT[0],&i);
KeInitializeWriteGDTDescriptor(&i,0x0,0xfffff,KeWriteGDT_G_1,KeWriteGDT_P_1,KeWriteGDT_S_1,KeWriteGDT_Type_Code_ExecuteOnly,KeWriteGDT_DPL_3,KeWriteGDT_DB_1,KeWriteGDT_AVL_0);
KeWriteGDT(GDT_INDEX_USER_CODE,&KeGDT[0],&i);
KeInitializeWriteGDTDescriptor(&i,0x0,0xfffff,KeWriteGDT_G_1,KeWriteGDT_P_1,KeWriteGDT_S_1,KeWriteGDT_Type_Data_ReadWrite,KeWriteGDT_DPL_3,KeWriteGDT_DB_1,KeWriteGDT_AVL_0);
KeWriteGDT(GDT_INDEX_USER_DATA,&KeGDT[0],&i);
}
VOID KeInitInterrupt(VOID)
{
KeInit8259A();
KeInitIDT();
}
VOID KeWriteIDT(ULONG32 Index,PGATE Dest ,PWrite_IDT_DESCRIPTOR Src)
{
ULONG32 datah = 0;
ULONG32 datal = 0;
ULONG32 temp = 0;
temp = Src->Selector;
datal = ((temp & 0x0000ffff) << 16);
temp = Src->Offset;
datal = datal + (temp & 0x0000ffff);
temp = Src->Offset;
datah = datah + (temp & 0xffff0000);
datah = datah + Src->P;
datah = datah + Src->D;
datah = datah + Src->DPL;
datah = datah + Src->GateType;
*(PULONG32)(Dest + Index) = datal;
*((PULONG32)(Dest + Index)+1) = datah;
return;
}
VOID KeInit8259A(VOID)
{
_asm_KeWritePort(INT_M_CTL,0x11);
_asm_KeWritePort(INT_S_CTL,0x11);
_asm_KeWritePort(INT_M_CTLMASK,INT_VECTOR_IRQ0);
_asm_KeWritePort(INT_S_CTLMASK,INT_VECTOR_IRQ8);
_asm_KeWritePort(INT_M_CTLMASK,0x4);
_asm_KeWritePort(INT_S_CTLMASK,0x2);
_asm_KeWritePort(INT_M_CTLMASK,0x1);
_asm_KeWritePort(INT_S_CTLMASK,0x1);
_asm_KeWritePort(INT_M_CTLMASK,0xFD);
_asm_KeWritePort(INT_S_CTLMASK,0xFF);
}
VOID KeExceptionHandler(ULONG32 VectorNumber,ULONG32 ErrorCode,ULONG32 eip,ULONG32 cs,ULONG32 eFlags)
{
_asm_KeClearGraph32();
_asm_KePrintStr32("Exception Caught:\n");
_asm_KePrintStr32("VectorNumber:");
_asm_KePrintHex32(VectorNumber);
_asm_KePrintStr32("\nErrorCode:");
_asm_KePrintHex32(ErrorCode);
_asm_KePrintStr32("\nCS:");
_asm_KePrintHex32(cs);
_asm_KePrintStr32("\nEIP:");
_asm_KePrintHex32(eip);
_asm_KePrintStr32("\neFlags:");
_asm_KePrintHex32(eFlags);
}
VOID KeInitIDT(VOID)
{
*(PULONG16)(&KeIDTPtr[0])= IDT_GATE_NUMBER * sizeof(GATE) - 1;
*(PULONG32)(&KeIDTPtr[2])= (ULONG32)(&KeIDT[0]);
Write_IDT_DESCRIPTOR Desc;
//Exceptions
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeDivideError);
KeWriteIDT(INT_VECTOR_DIVIDE,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeSingleStepException);
KeWriteIDT(INT_VECTOR_DEBUG,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeNMI);
KeWriteIDT(INT_VECTOR_NMI,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeBreakpointException);
KeWriteIDT(INT_VECTOR_BREAKPOINT,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeOverflow);
KeWriteIDT(INT_VECTOR_OVERFLOW,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeBoundsCheck);
KeWriteIDT(INT_VECTOR_BOUNDS,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeInvalidOpcode);
KeWriteIDT(INT_VECTOR_INVAL_OP,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeCoprNotAvailable);
KeWriteIDT(INT_VECTOR_COPROC_NOT,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeCoprError);
KeWriteIDT(INT_VECTOR_COPROC_ERR,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeCoprSegmentOverrun);
KeWriteIDT(INT_VECTOR_COPROC_SEG,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeDoubleFault);
KeWriteIDT(INT_VECTOR_DOUBLE_FAULT,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeInvalidTSS);
KeWriteIDT(INT_VECTOR_INVAL_TSS,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeStackException);
KeWriteIDT(INT_VECTOR_STACK_FAULT,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeSegmentNotPresent);
KeWriteIDT(INT_VECTOR_SEG_NOT,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeGeneralProtection);
KeWriteIDT(INT_VECTOR_PROTECTION,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KePageFault);
KeWriteIDT(INT_VECTOR_PAGE_FAULT,&KeIDT[0],&Desc);
//Interrupts
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeIrqInt00);
KeWriteIDT(INT_VECTOR_IRQ0 + 0,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeIrqInt01);
KeWriteIDT(INT_VECTOR_IRQ0 + 1,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeIrqInt02);
KeWriteIDT(INT_VECTOR_IRQ0 + 2,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeIrqInt03);
KeWriteIDT(INT_VECTOR_IRQ0 + 3,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeIrqInt04);
KeWriteIDT(INT_VECTOR_IRQ0 + 4,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeIrqInt05);
KeWriteIDT(INT_VECTOR_IRQ0 + 5,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeIrqInt06);
KeWriteIDT(INT_VECTOR_IRQ0 + 6,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeIrqInt07);
KeWriteIDT(INT_VECTOR_IRQ0 + 7,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeIrqInt08);
KeWriteIDT(INT_VECTOR_IRQ8 + 0,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeIrqInt09);
KeWriteIDT(INT_VECTOR_IRQ8 + 1,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeIrqInt10);
KeWriteIDT(INT_VECTOR_IRQ8 + 2,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeIrqInt11);
KeWriteIDT(INT_VECTOR_IRQ8 + 3,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeIrqInt12);
KeWriteIDT(INT_VECTOR_IRQ8 + 4,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeIrqInt13);
KeWriteIDT(INT_VECTOR_IRQ8 + 5,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeIrqInt14);
KeWriteIDT(INT_VECTOR_IRQ8 + 6,&KeIDT[0],&Desc);
KeInitializeWriteIDTDescriptor(&Desc,KeWriteIDT_GateType_InterruptGate,KeWriteIDT_DPL_3,KeWriteIDT_D_1,KeWriteIDT_P_1, GDT_SELECTOR_CODE,(ULONG32)&_asm_KeIrqInt15);
KeWriteIDT(INT_VECTOR_IRQ8 + 7,&KeIDT[0],&Desc);
_asm_KeLoadIDT();
}
VOID KeIrqIntHandler(ULONG32 IrqNumber)
{
_asm_KePrintStr32("\nIrq Interrupt Detected. Irq Number:");
_asm_KePrintHex32(IrqNumber);
_asm_KePrintStr32("\n");
}
#endif

View File

@ -1,78 +0,0 @@
#include "KeDef.h"
#include "KeGlobalVariables.h"
#include "KeGraph32.h"
#include "KeMemory32.h"
#include "KeIO32.h"
#include "KeProcess32.h"
VOID KeSystemInit(VOID);
VOID KeRawDelay(ULONG32 time);
VOID ProcessA(VOID);
char TempStack[PROCESS_STACK_MAX_SIZE];
VOID KeSystemInit(VOID)
{
ULONG32 i;
KeRawDelay(3500);
_asm_KeClearGraph32();
_asm_KeSetGraphPosition32(KeGetCurrentGraphRow(_asm_KeGetCurrentGraphPosition32()),28);
KeRawDelay(500);
_asm_KePrintStr32("=Hyper Operating System=\n");
KeRawDelay(500);
_asm_KePrintStr32("New GDT Loaded\n");
KeRawDelay(500);
_asm_KePrintStr32("Kernel Entry Entered.\n");
KeRawDelay(500);
_asm_KePrintStr32("Initializing Interrupt...\n");
KeRawDelay(500);
KeInitInterrupt();
_asm_KePrintStr32("Interrupt Initialization Completed.\n");
_asm_KePrintStr32("Testing Scroll...\n");
KeRawDelay(1000);
for(i=0;i<=30;i++)
{
_asm_KePrintStr32("This is text #");
_asm_KePrintHex32(i);
_asm_KePrintStr32(", ");
_asm_KePrintHex32(30-i);
_asm_KePrintStr32(" left.\n");
KeRawDelay(50);
}
_asm_KePrintStr32("Scroll Test Completed.\n");
KeRawDelay(500);
_asm_KePrintStr32("Initializing Process Configurations...\n");
KeInitProcess();
KeRawDelay(500);
_asm_KePrintStr32("Initializing Process Completed.\n");
KeRawDelay(500);
_asm_KePrintStr32("Try to run a process.\n");
KeCreateProcess(0,&ProcessA,&TempStack[0],Process_Priviliege_Kernel);
shit: goto shit;
}
#define PTEBase 0x00045000
#define PDEBase 0x00046000
VOID ProcessA(VOID)
{
ULONG32 i = 0;
while(i<1000)
{
_asm_KePrintHex32(i);
KeRawDelay(250);
i++;
}
}
VOID KeRawDelay(ULONG32 time)
{
ULONG32 i,j;
for(i=0;i<=time;i++)
{
for(j=0;j<=10000;j++)
{
j=j;
}
}
}

View File

@ -1,163 +0,0 @@
#include "KeDef.h"
#include "KeGlobalVariables.h"
#ifndef _KeMemory32_h_
#define _KeMemory32_h_
#define KeVirtualAddressToPhysicalAddress(SegmentBase,VirtualAddress) (ULONG32)((ULONG32)SegmentBase+(ULONG32)(VirtualAddress))
typedef struct _WritePDE4K32_Descriptor
{
ULONG32 P;
ULONG32 RW;
ULONG32 US;
ULONG32 PWT;
ULONG32 PCD;
ULONG32 A;
ULONG32 PS;
ULONG32 Address;
} WritePDE4K32_Descriptor, *PWritePDE4K32_Descriptor;
typedef struct _WritePTE4K32_Descriptor
{
ULONG32 P;
ULONG32 RW;
ULONG32 US;
ULONG32 PWT;
ULONG32 PCD;
ULONG32 A;
ULONG32 D;
ULONG32 PS;
ULONG32 G;
ULONG32 Address;
} WritePTE4K32_Descriptor, *PWritePTE4K32_Descriptor;
PVOID _asm_KeMemoryCopy(PVOID src,PVOID dst,ULONG32 size);
PVOID KeMemoryCopy(PVOID src,PVOID dst,ULONG32 size);
VOID KeInitializeWritePDE4K32Descriptor(PWritePDE4K32_Descriptor Desc,ULONG32 P,ULONG32 RW, ULONG32 US,ULONG32 PWT,ULONG32 PCD,ULONG32 A,ULONG32 PS,ULONG32 Address);
VOID KeWritePDE4K32(PWritePDE4K32_Descriptor Desc, PVOID Dst);
VOID KeInitializeWritePTE4K32Descriptor(PWritePTE4K32_Descriptor Desc,ULONG32 P,ULONG32 RW, ULONG32 US,ULONG32 PWT,ULONG32 PCD,ULONG32 A,ULONG32 D,ULONG32 PS,ULONG32 G,ULONG32 Address);
VOID KeWritePTE4K32(PWritePTE4K32_Descriptor Desc,PVOID Dst );
ULONG32 SegmentToPhyscicalAddress(ULONG16 Segment)
{
PGDT_DESCRIPTOR PDescriptor = &KeGDT[(Segment>>3)];
return (PDescriptor->BaseHigh<<24 | PDescriptor->BaseMid<<16 | PDescriptor->BaseLow);
};
PVOID KeMemorySet(PVOID Source,BYTE Value,ULONG32 Length)
{
PVOID src = Source;
while(Length > 0)
{
*(PBYTE)Source = Value;
Source++;
Length--;
};
return src;
}
PVOID KeMemoryCopy(PVOID src,PVOID dst,ULONG32 size)
{
ULONG32 i = 0;
for(i=0;i<size;i++)
{
*((PCHAR)dst+i)=*((PCHAR)src+i);
}
return dst;
}
#define KeWritePDE4K32_P_0 0 // 0 for not present
#define KeWritePDE4K32_P_1 1 // 1 for Present
#define KeWritePDE4K32_RW_0 0 // 0 for ReadOnly
#define KeWritePDE4K32_RW_1 2 // 1 for ReadWrite
#define KeWritePDE4K32_US_0 0 // 0 for Superuser
#define KeWritePDE4K32_US_1 4 // 1 for All
#define KeWritePDE4K32_PWT_1 8 // Write back
#define KeWritePDE4K32_PWT_0 0 // Write Through
#define KeWritePDE4K32_PCD_0 0 // 0 for Cache Enabled
#define KeWritePDE4K32_PCD_1 16 // 1 for Cache Disabled
#define KeWritePDE4K32_A_0 0 //0 for not accessed
#define KeWritePDE4K32_A_1 32 //1 for accessed
#define KeWritePDE4K32_PS_0 0 //0 for 4K pages
#define KeWritePDE4K32_PS_1 128 //1 for 4M pages
VOID KeInitializeWritePDE4K32Descriptor(PWritePDE4K32_Descriptor Desc,ULONG32 P,ULONG32 RW, ULONG32 US,ULONG32 PWT,ULONG32 PCD,ULONG32 A,ULONG32 PS,ULONG32 Address)
{
Desc->P = P;
Desc->Address = Address;
Desc->A = A;
Desc->PS = PS;
Desc->US = US;
Desc->RW = RW;
Desc->PWT = PWT;
Desc->PCD = PCD;
return;
}
VOID KeWritePDE4K32(PWritePDE4K32_Descriptor Desc, PVOID Dst)
{
ULONG32 temp = 0;
temp = Desc->Address;
temp = (temp & 0xfffff000);
temp = temp + Desc->P;
temp = temp + Desc->RW;
temp = temp + Desc->US;
temp = temp + Desc->PWT;
temp = temp + Desc->PCD;
temp = temp + Desc->A;
temp = temp + Desc->PS;
*(PULONG32)Dst = temp;
return;
}
#define KeWritePTE4K32_P_0 0 // 0 for not present
#define KeWritePTE4K32_P_1 1 // 1 for present
#define KeWritePTE4K32_RW_0 0 // 0 for readonly
#define KeWritePTE4K32_RW_1 2 // 1 for readwrite
#define KeWritePTE4K32_US_0 0 // 0 for superuser
#define KeWritePTE4K32_US_1 4 // 1 for all
#define KeWritePTE4K32_PWT_0 0 // 0 for write through
#define KeWritePTE4K32_PWT_1 8 // 1 for write back
#define KeWritePTE4K32_PCD_0 0 // 0 for cache enabled
#define KeWritePTE4K32_PCD_1 16 // 1 for cache disabled
#define KeWritePTE4K32_A_0 0 // not accessed
#define KeWritePTE4K32_A_1 32 // accessed
#define KeWritePTE4K32_D_0 0 // Dirty - set for has been written to
#define KeWritePTE4K32_D_1 64 // Dirty - set for has been written to
#define KeWritePTE4K32_PS_0 0 // should be 0
#define KeWritePTE4K32_PS_1 128 //
#define KeWritePTE4K32_G_0 0 // Global Not Set
#define KeWritePTE4K32_G_1 256 // Global Set
VOID KeInitializeWritePTE4K32Descriptor(PWritePTE4K32_Descriptor Desc,ULONG32 P,ULONG32 RW, ULONG32 US,ULONG32 PWT,ULONG32 PCD,ULONG32 A,ULONG32 D,ULONG32 PS,ULONG32 G,ULONG32 Address)
{
Desc->P = P;
Desc->Address = Address;
Desc->A = A;
Desc->US = US;
Desc->RW = RW;
Desc->PWT = PWT;
Desc->PCD = PCD;
Desc->PS = PS;
Desc->G = G;
Desc->D = D;
return;
}
VOID KeWritePTE4K32(PWritePTE4K32_Descriptor Desc,PVOID Dst )
{
ULONG32 temp = 0;
temp = Desc->Address;
temp = (temp & 0xfffff000);
temp += Desc->P;
temp += Desc->RW;
temp += Desc->US;
temp += Desc->PWT;
temp += Desc->PCD;
temp += Desc->A;
temp += Desc->D;
temp += Desc->PS;
temp += Desc->G;
*(PULONG32)Dst = temp;
}
#endif

View File

@ -1,69 +0,0 @@
#include "KeDef.h"
#include "KeGlobalVariables.h"
#include "KeMemory32.h"
#include "KeGraph32.h"
#include "KeIO32.h"
#ifndef _KeProcess32_h_
#define _KeProcess32_h_
VOID KeCreateProcess(ULONG32 ProcessID,PVOID ProcessAddress,PVOID ProcessStack,PROCESSPRIVILEGE Privilege);
VOID KeInitProcess(VOID);
VOID _asm_KeLoadTSS(ULONG32 Selector_TSS);
VOID _asm_Restart();
VOID KeInitProcess(VOID)
{
//TSS
Write_GDT_DESCRIPTOR desc;
KeMemorySet(&KeTSS,0,sizeof(TSS));
KeTSS.ss0 = GDT_SELECTOR_DATA;
//DESC INIT
KeInitializeWriteGDTDescriptor(&desc, (ULONG32)&KeTSS, sizeof(TSS)-1, KeWriteGDT_G_0,KeWriteGDT_P_1 , KeWriteGDT_S_0, KeWriteGDT_Type_System_32BitsTSSAvailable, KeWriteGDT_DPL_0, KeWriteGDT_DB_1, KeWriteGDT_AVL_0);
KeWriteGDT(GDT_INDEX_TSS, &KeGDT[0], &desc);
KeTSS.IOBase = sizeof(TSS)-1;
_asm_KeLoadTSS(GDT_SELECTOR_TSS);
}
VOID KeCreateProcess(ULONG32 ProcessID,PVOID ProcessAddress,PVOID ProcessStack,PROCESSPRIVILEGE Privilege)
{
PhProcess process;
if(Privilege == Process_Priviliege_Kernel)
{
process = &KeKernelProcessTable[ProcessID];
process->ProcessID = ProcessID;
process->Privilege = Privilege;
process->RestartStack.cs = GDT_SELECTOR_CODE; //(LDT_SELECTOR_CODE & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_TASK;
process->RestartStack.ds = GDT_SELECTOR_DATA; //(LDT_SELECTOR_DATA & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_TASK;
process->RestartStack.es = GDT_SELECTOR_DATA; //(LDT_SELECTOR_DATA & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_TASK;
process->RestartStack.fs = GDT_SELECTOR_DATA; //(LDT_SELECTOR_DATA & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_TASK;
process->RestartStack.ss = GDT_SELECTOR_DATA; // (LDT_SELECTOR_DATA & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_TASK;
process->RestartStack.gs = GDT_SELECTOR_GRAPH; // (GDT_SELECTOR_GRAPH & SA_RPL_MASK) | RPL_TASK;
}
else
{
process = &KeUserProcessTable[ProcessID];
process->ProcessID = ProcessID;
process->Privilege = Privilege;
process->RestartStack.cs =GDT_SELECTOR_USER_CODE; //(LDT_SELECTOR_CODE & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_TASK;
process->RestartStack.ds =GDT_SELECTOR_USER_DATA; //(LDT_SELECTOR_DATA & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_TASK;
process->RestartStack.es =GDT_SELECTOR_USER_DATA; //(LDT_SELECTOR_DATA & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_TASK;
process->RestartStack.fs =GDT_SELECTOR_USER_DATA; //(LDT_SELECTOR_DATA & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_TASK;
process->RestartStack.ss =GDT_SELECTOR_USER_DATA; // (LDT_SELECTOR_DATA & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_TASK;
process->RestartStack.gs =GDT_SELECTOR_GRAPH; // (GDT_SELECTOR_GRAPH & SA_RPL_MASK) | RPL_TASK;
}
process->RestartStack.eip = (ULONG32)ProcessAddress;
process->RestartStack.esp = (ULONG32)ProcessStack + PROCESS_STACK_MAX_SIZE;
process->RestartStack.eFlags = 0x1202;
// process->LDTSelector = GDT_SELECTOR_LDT;
// KeMemoryCopy(&KeGDT[GDT_INDEX_CODE],&process->ProcessLDT[LDT_INDEX_CODE],sizeof(GDT_DESCRIPTOR));
// process->ProcessLDT[LDT_INDEX_CODE].Attr1 = DA_C | PRIVILEGE_TASK << 5;
// KeMemoryCopy(&KeGDT[GDT_INDEX_DATA],&process->ProcessLDT[LDT_INDEX_DATA],sizeof(GDT_DESCRIPTOR));
// process->ProcessLDT[LDT_INDEX_DATA].Attr1 = DA_DRW | PRIVILEGE_TASK << 5;
PStartProcess = process;
_asm_Restart();
}
#endif

View File

@ -1,36 +0,0 @@
extern _KeSystemInit
extern _KeGDTPtr
extern _KeSwitchGDT
extern _KeIDTPtr
global _start
;GDT
SLCT_GRAPH equ 8
SLCT_FLAT_C equ 16
SLCT_FLAT_RW equ 24
;Stack
[section .bss]
[BITS 32]
resb 2 * 1024
KernelStackTop:
[section .text]
[BITS 32]
_start:
mov esp,KernelStackTop
sgdt [_KeGDTPtr]
call _KeSwitchGDT
lgdt [_KeGDTPtr]
jmp SLCT_FLAT_C:GDT_COMPLETE
GDT_COMPLETE:
mov ax,SLCT_GRAPH
mov gs,ax
mov ax,SLCT_FLAT_RW
mov ds,ax
mov ss,ax
push 0
popfd
call _KeSystemInit

View File

@ -1,165 +0,0 @@
;FAT12ReadFile(ULONG16 Base,ULONG16 Offset,ULONG16 OffsetFileName)
FAT12ReadFile:
.START:
push bp
mov bp,sp
push bp
xor ah, ah
xor dl, dl
int 13h
mov word [wSectorNo], SectorNoOfRootDirectory
.LABEL_SEARCH_IN_ROOT_DIR_BEGIN:
cmp word [wRootDirSizeForLoop], 0
jz .LABEL_NO_LOADERBIN
dec word [wRootDirSizeForLoop]
mov ax, [ss:bp+4]
mov es, ax
mov bx, [ss:bp+6]
mov ax, [wSectorNo]
mov cl, 1
call ReadSector
mov si, [ss:bp+8]
mov di, [ss:bp+6]
cld
mov dx, 10h
.LABEL_SEARCH_FOR_LOADERBIN:
cmp dx, 0
jz .LABEL_GOTO_NEXT_SECTOR_IN_ROOT_DIR
dec dx
mov cx, 11
.LABEL_CMP_FILENAME:
cmp cx, 0
jz .LABEL_FILENAME_FOUND
dec cx
lodsb
cmp al, byte [es:di]
jz .LABEL_GO_ON
jmp .LABEL_DIFFERENT
.LABEL_GO_ON:
inc di
jmp .LABEL_CMP_FILENAME
.LABEL_DIFFERENT:
and di, 0FFE0h
add di, 20h
mov si, [ss:bp+8]
jmp .LABEL_SEARCH_FOR_LOADERBIN;
.LABEL_GOTO_NEXT_SECTOR_IN_ROOT_DIR:
add word [wSectorNo], 1
jmp .LABEL_SEARCH_IN_ROOT_DIR_BEGIN
.LABEL_NO_LOADERBIN:
jmp $
.LABEL_FILENAME_FOUND:
mov ax, RootDirSectors
and di, 0FFE0h
add di, 01Ah
mov cx, word [es:di]
push cx
add cx, ax
add cx, DeltaSectorNo
mov ax, [ss:bp+4]
mov es, ax
mov bx, [ss:bp+6]
mov ax, cx
.LABEL_GOON_LOADING_FILE:
mov cl, 1
call ReadSector
pop ax
push word [ss:bp+4]
call GetFATEntry
add sp,2
cmp ax, 0FFFh
jz .LABEL_FILE_LOADED
push ax
mov dx, RootDirSectors
add ax, dx
add ax, DeltaSectorNo
add bx, [BPB_BytsPerSec]
jmp .LABEL_GOON_LOADING_FILE
.LABEL_FILE_LOADED:
mov sp,[bp-2]
pop bp
ret
wRootDirSizeForLoop dw RootDirSectors
wSectorNo dw 0
bOdd db 0
ReadSector:
push bp
mov bp, sp
sub esp, 2
mov byte [bp-2], cl
push bx
mov bl, [BPB_SecPerTrk]
div bl
inc ah
mov cl, ah
mov dh, al
shr al, 1
mov ch, al
and dh, 1
pop bx
mov dl, [BS_DrvNum]
.GoOnReading:
mov ah, 2
mov al, byte [bp-2]
int 13h
jc .GoOnReading
add sp, 2
pop bp
ret
GetFATEntry:
push bp
mov bp,sp
push es
push bx
push ax
mov ax, [ss:bp+4]
sub ax, 0100h
mov es, ax
pop ax
mov byte [bOdd], 0
mov bx, 3
mul bx
mov bx, 2
div bx
cmp dx, 0
jz .LABEL_EVEN
mov byte [bOdd], 1
.LABEL_EVEN:
xor dx, dx
mov bx, [BPB_BytsPerSec]
div bx
push dx
mov bx, 0
add ax, SectorNoOfFAT1
mov cl, 2
call ReadSector
pop dx
add bx, dx
mov ax, [es:bx]
cmp byte [bOdd], 1
jnz .LABEL_EVEN_2
shr ax, 4
.LABEL_EVEN_2:
and ax, 0FFFh
.LABEL_GET_FAT_ENRY_OK:
pop bx
pop es
pop bp
ret

View File

@ -1,319 +0,0 @@
GETMEM16:
;ebx = 0
push eax
push ebx
push ecx
push edx
push esi
push edi
mov ax,es
push ax
mov ax,ds
push ax
mov ax,cs
mov es,ax
mov ds,ax
xor ebx,ebx
mov di,GETMEMBUFF ;es:di = ASRD
.loop:
mov eax,0E820h
mov ecx,20
;edx = 'SWAP'
mov edx,0534D4150h
int 15h
;if (CF!=0)
jc .fail
inc dword [GETMEMNUM]
;forward 20bytes
add di,20
cmp ebx,0
jne .loop
jmp .end
.fail:
mov dword [GETMEMNUM],0
.end:
pop ax
mov ds,ax
pop ax
mov es,ax
pop edi
pop esi
pop edx
pop ecx
pop ebx
pop eax
ret
DISPMEM16:
;must include io16.lib
push eax
push esi
push edi
push ecx
push edx
push ebp
mov ax,ds
push ax
mov ax,es
push ax
mov ax,cs
mov ds,ax
mov es,ax
xor eax,eax
mov eax,RAMTABLE16
push eax
call near DISPSTR16
pop eax
call DISPRETURN16
xor ebp,ebp
mov esi,GETMEMBUFF
mov ecx,[ds:GETMEMNUM]
mov edx,5
.loop1:
mov eax,dword [ds:esi]
push eax
call near DISPINTEAX16
pop eax
call near DISPSPACE16
inc ebp
dec edx
add esi,4
cmp ebp,5
jne .noinfo
xor ebp,ebp
cmp eax,1
je .ava
mov eax,RAMRESERVED
push eax
call near DISPSTR16
pop eax
jmp .noinfo
.ava:
mov eax,RAMAVAILABLE
push eax
call near DISPSTR16
pop eax
.noinfo:
cmp edx,0
jne .loop1
cmp dword [ds:esi-4],1
jne .end2
mov eax,dword [ds:esi-20]
add eax,dword [ds:esi-12]
cmp eax,[ds:DISPMEMTOTAL]
jb .end2
mov [ds:DISPMEMTOTAL],eax
.end2:
call near DISPRETURN16
dec ecx
mov edx,5
cmp ecx,0
je .end1
jmp .loop1
.end1:
call near DISPRETURN16
mov eax,RAMSIZE
push eax
call near DISPSTR16
pop eax
push dword [ds:DISPMEMTOTAL]
call near DISPINTEAX16
pop eax
pop ax
mov es,ax
pop ax
mov ds,ax
pop ebp
pop edx
pop ecx
pop edi
pop esi
pop eax
ret
DISPINTEAX16:
;Entrance: push eax
push ebp
mov ebp,esp
push eax
mov eax,dword [ss:ebp+6]
shr eax,24
mov ah,0Fh
push ax
call near DISPINTAL16
pop ax
mov eax,dword [ss:ebp+6]
shr eax,16
mov ah,0Fh
push ax
call near DISPINTAL16
pop ax
mov eax,dword [ss:ebp+6]
shr eax,8
mov ah,0Fh
push ax
call near DISPINTAL16
pop ax
mov eax,dword [ss:ebp+6]
mov ah,0Fh
push ax
call near DISPINTAL16
pop ax
pop eax
pop ebp
ret
DISPSTR16:
;Entrance: push offset
;ds:offset = String
push ebp
mov ebp,esp
push esi
push edi
push eax
push ebx
push gs
mov ax,0b800h
mov gs,ax
mov esi,dword [ss:ebp+6]
mov edi,dword [ds:GRAPHPOS]
.loop1:
mov al,byte [ds:esi]
cmp al,0
je .end
cmp al,0Ah
jne .loop2
;let edi point to the next row
;edi/(80*2) - every row:80 chars, each char takes 2 bytes.
push eax
mov eax,edi
mov bl,160
div bl
;only keep the low 8 of eax(al,aka quotion)
and eax, 0FFh
inc eax
;calculate the edi now
mov bl,160
mul bl
mov edi,eax
pop eax
inc esi
jmp .loop1
.loop2:
mov ah,0Fh
mov word [gs:edi],ax
add edi,2
inc esi
jmp .loop1
.end:
mov dword [ds:GRAPHPOS],edi
pop gs
pop ebx
pop eax
pop edi
pop esi
pop ebp
ret
DISPINTAL16:
;Entrance: push ax ,AH=ATTR, AL=Char
push ebp
mov ebp,esp
push eax
push gs
push ecx
push edi
push ebx
push ds
mov ax,cs
mov ds,ax
mov edi,dword [ds:GRAPHPOS]
mov ax,0b800h
mov gs,ax
xor eax,eax
mov ax, word [ss:ebp+6]
mov bx,ax
;keep high 4 bits of al
and al,0F0H
mov cl,4
shr al,cl
call near CHANGEAL
mov word [gs:edi],ax
add edi,2
mov dword [ds:GRAPHPOS],edi
;keep low 4 bits of al
mov ax,bx
and al,0Fh
call near CHANGEAL
mov ah,bh
mov word [gs:edi],ax
add edi,2
mov dword [ds:GRAPHPOS],edi
pop ds
pop ebx
pop edi
pop ecx
pop gs
pop eax
pop ebp
ret
CHANGEAL:
;Entrance:void
cmp al,09h
jna .l2
add al,37h
jmp .end
.l2:
add al,30h
.end:
ret
DISPRETURN16:
push eax
push ds
mov ax,cs
mov ds,ax
mov eax,IO16_RETURN
push eax
call near DISPSTR16
pop eax
pop ds
pop eax
ret
DISPSPACE16:
push eax
push ds
mov ax,cs
mov ds,ax
mov eax,IO16_SPACE
push eax
call near DISPSTR16
pop eax
pop ds
pop eax
ret

View File

@ -1,156 +0,0 @@
;===================================================================32 BITS=============================================================
DISPINTEAX32:
;Entrance: push eax
push ebp
mov ebp,esp
push eax
mov eax,dword [ss:ebp+8]
shr eax,24
mov ah,0Fh
push ax
call near DISPINTAL32
pop ax
mov eax,dword [ss:ebp+8]
shr eax,16
mov ah,0Fh
push ax
call near DISPINTAL32
pop ax
mov eax,dword [ss:ebp+8]
shr eax,8
mov ah,0Fh
push ax
call near DISPINTAL32
pop ax
mov eax,dword [ss:ebp+8]
mov ah,0Fh
push ax
call near DISPINTAL32
pop ax
pop eax
pop ebp
ret
DISPSTR32:
;Entrance: push offset
;ds:offset = String
push ebp
mov ebp,esp
push esi
push edi
push eax
push ebx
push gs
mov ax,SLCT_GRAPH
mov gs,ax
mov esi,dword [ss:ebp+8]
mov edi,dword [ds:GRAPHPOS_32]
.loop1:
mov al,byte [ds:esi]
cmp al,0
je .end
cmp al,0Ah
jne .loop2
;let edi point to the next row
;edi/(80*2) - every row:80 chars, each char takes 2 bytes.
push eax
mov eax,edi
mov bl,160
div bl
;only keep the low 8 of eax(al,aka quotion)
and eax, 0FFh
inc eax
;calculate the edi now
mov bl,160
mul bl
mov edi,eax
pop eax
inc esi
jmp .loop1
.loop2:
mov ah,0Fh
mov word [gs:edi],ax
add edi,2
inc esi
jmp .loop1
.end:
mov dword [ds:GRAPHPOS_32],edi
pop gs
pop ebx
pop eax
pop edi
pop esi
pop ebp
ret
DISPINTAL32:
;Entrance: push ax ,AH=ATTR, AL=Char
push ebp
mov ebp,esp
push eax
push gs
push ecx
push edi
push ebx
mov edi,dword [ds:GRAPHPOS_32]
mov ax,SLCT_GRAPH
mov gs,ax
xor eax,eax
mov ax, word [ss:ebp+8]
mov bx,ax
;keep high 4 bits of al
and al,0F0H
mov cl,4
shr al,cl
call near CHANGEAL
mov word [gs:edi],ax
add edi,2
mov dword [ds:GRAPHPOS_32],edi
;keep low 4 bits of al
mov ax,bx
and al,0Fh
call near CHANGEAL
mov ah,bh
mov word [gs:edi],ax
add edi,2
mov dword [ds:GRAPHPOS_32],edi
pop ebx
pop edi
pop ecx
pop gs
pop eax
pop ebp
ret
DISPRETURN32:
push eax
mov eax,IO32_RETURN
push eax
call near DISPSTR32
pop eax
pop eax
ret
DISPSPACE32:
push eax
mov eax,IO32_SPACE
push eax
call near DISPSTR32
pop eax
pop eax
ret

View File

@ -1,98 +0,0 @@
PAGINGINIT32:
;must be called in 32-bits protected mode
push eax
push edx
push ecx
push ebx
push edi
push es
mov ax,SLCT_FLAT_RW
mov es,ax
xor edx,edx
mov eax,dword [ds:DISPMEMTOTAL_32]
mov ebx,400000h
div ebx
mov ecx,eax
cmp edx,0
je .end
inc ecx
.end:
push ecx
;init all PDEs
mov eax, PTEBASE | PG_P | PG_USU | PG_RWW
mov edi, PDEBASE
.loop1:
mov dword [es:edi],eax
add edi,4
dec ecx
add eax,4096
cmp ecx,0
jne .loop1
;init all PTEs
pop eax
mov ebx,1024
mul ebx
mov ecx,eax
mov eax, PG_P | PG_USU | PG_RWW
xor edi,edi
mov edi, PTEBASE
.loop2:
mov dword [es:edi],eax
add edi,4
add eax,4096
dec ecx
cmp ecx,0
jne .loop2
mov eax, PDEBASE
mov cr3, eax
mov eax, cr0
or eax, 80000000h
mov cr0, eax
jmp short .end2
.end2:
nop
pop es
pop edi
pop ebx
pop ecx
pop edx
pop eax
ret
;void* MEMCPY32(void* Source;void* Destination;ULONG32 Size)
MEMCPY32:
push ebp
mov ebp,esp
push esi
push edi
push ecx
push eax
mov ax,SLCT_FLAT_RW
mov es,ax
mov esi,dword [ss:ebp+8]
mov edi,dword [ss:ebp+12]
mov ecx,dword [ss:ebp+16]
.loop:
mov al,byte [es:esi]
mov byte [ds:edi],al
inc esi
inc edi
dec ecx
cmp ecx,0
je .end
jmp .loop
.end:
pop eax
pop ecx
pop edi
pop esi
pop ebp
ret

View File

@ -1,93 +0,0 @@
ENTRYPOINT = 0x30000
ASM = nasm
ASMBOOTFLAGS = -I inc/ -I lib/
ASMLOADERFLAGS = -I inc/ -I lib/
ASMKERNELFLAGS = -f elf
CFLAGS = -I kclib/ -c -fno-builtin
LDFLAGS = -e _start -Ttext $(ENTRYPOINT)
CC = gcc
LD = ld
OPY = objcopy
#Add corresponding .o files from kclib and kalib
KERNELBINPRE = kernel/kernel.o kclib/KeKernelEntry.o kalib/_asm_KeMemory32.o kalib/_asm_KeGraph32.o kalib/_asm_KeIO32.o kalib/_asm_KeProcess32.o
#Add all .o files
OBJECTFILES = kernel/kernel.o kclib/KeKernelEntry.o kalib/_asm_KeMemory32.o kalib/_asm_KeGraph32.o kalib/_asm_KeIO32.o kalib/_asm_KeProcess32.o
#Add all .bin files
BINFILES = boot/boot.bin boot/loader.bin kernel/kernel.bin
#Add all temp files
TEMPFILES = kernel/kernel.out
#Prerequisites
#Add new .h files form kclib
KEKERNELENTRYPRE = kclib/KeKernelEntry.c kclib/KeGraph32.h kclib/KeDef.h kclib/KeGlobalVariables.h kclib/KeMemory32.h kclib/KeIO32.h kclib/KeProcess32.h
#No need to change
_ASM_KEGRAPH32PRE = kalib/_asm_KeGraph32.asm
_ASM_KEMEMORY32PRE = kalib/_asm_KeMemory32.asm
KERNELOPRE = kernel/kernel.asm
BOOTBINPRE = boot/boot.asm inc/FAT12Header.inc lib/fat12readfile.lib
LOADERBINPRE = boot/loader.asm inc/FAT12Header.inc inc/pm.inc lib/fat12readfile.lib lib/io16.lib lib/io32.lib lib/mem32.lib
_ASM_KEIO32PRE = kalib/_asm_KeIO32.asm
_ASM_KEPROCESS32PRE = kalib/_asm_KeProcess32.asm
.PHONY : everything clean all image buildimg
everything : $(BINFILES) $(OBJECTFILES) $(TEMPFILES)
all : clean everything
image: all buildimg
clean:
rm -rf $(BINFILES) $(OBJECTFILES) $(TEMPFILES)
buildimg:
dd if=boot/boot.bin of=a.img bs=512 count=1 conv=notrunc
cp -f kernel/kernel.bin os/
cp -f boot/loader.bin os/
cp -f a.img os/
rm -rf $(BINFILES) $(OBJECTFILES) $(TEMPFILES)
boot/boot.bin: $(BOOTBINPRE)
$(ASM) $(ASMBOOTFLAGS) -o boot/boot.bin boot/boot.asm
boot/loader.bin: $(LOADERPRE)
$(ASM) $(ASMBOOTFLAGS) -o boot/loader.bin boot/loader.asm
kernel/kernel.o: $(KERNELOPRE)
$(ASM) $(ASMKERNELFLAGS) -o kernel/kernel.o kernel/kernel.asm
kclib/KeKernelEntry.o: $(KEKERNELENTRYPRE)
$(CC) $(CFLAGS) -o kclib/KeKernelEntry.o kclib/KeKernelEntry.c
kalib/_asm_KeMemory32.o: $(_ASM_KEMEMORY32PRE)
$(ASM) $(ASMKERNELFLAGS) -o kalib/_asm_KeMemory32.o kalib/_asm_KeMemory32.asm
kalib/_asm_KeGraph32.o: $(_ASM_KEGRAPH32PRE)
$(ASM) $(ASMKERNELFLAGS) -o kalib/_asm_KeGraph32.o kalib/_asm_KeGraph32.asm
kalib/_asm_KeProcess32.o: $(_ASM_KEGRAPH32PRE)
$(ASM) $(ASMKERNELFLAGS) -o kalib/_asm_KeProcess32.o kalib/_asm_KeProcess32.asm
kernel/kernel.bin: $(KERNELBINPRE)
$(LD) $(OBJECTFILES) $(LDFLAGS) -o kernel/kernel.out
$(OPY) kernel/kernel.out -O binary kernel/kernel.bin
kalib/_asm_KeIO32.o: $(_ASM_KEIO32PRE)
$(ASM) $(ASMKERNELFLAGS) -o kalib/_asm_KeIO32.o kalib/_asm_KeIO32.asm

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

22
HOS.sln Normal file
View File

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HOS", "HOS\HOS.vcxproj", "{5EFE31D2-FEA1-4F64-87F6-03CB2FA88249}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5EFE31D2-FEA1-4F64-87F6-03CB2FA88249}.Debug|Win32.ActiveCfg = Debug|Win32
{5EFE31D2-FEA1-4F64-87F6-03CB2FA88249}.Debug|Win32.Build.0 = Debug|Win32
{5EFE31D2-FEA1-4F64-87F6-03CB2FA88249}.Release|Win32.ActiveCfg = Release|Win32
{5EFE31D2-FEA1-4F64-87F6-03CB2FA88249}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

102
HOS/HOS.vcxproj Normal file
View File

@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{5EFE31D2-FEA1-4F64-87F6-03CB2FA88249}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>HOS</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\kclib\KeCPUStruct32.h" />
<ClInclude Include="..\kclib\KeDef.h" />
<ClInclude Include="..\kclib\KeGlobalVariables.h" />
<ClInclude Include="..\kclib\KeGraph32.h" />
<ClInclude Include="..\kclib\KeIO32.h" />
<ClInclude Include="..\kclib\KeKernelStruct32.h" />
<ClInclude Include="..\kclib\KeMemory32.h" />
<ClInclude Include="..\kclib\KeProcess32.h" />
<ClInclude Include="..\kclib\MM\KeMemoryManager32.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\kclib\KeGraph32.c" />
<ClCompile Include="..\kclib\KeIO32.c" />
<ClCompile Include="..\kclib\KeKernelEntry.c" />
<ClCompile Include="..\kclib\KeMemory32.c" />
<ClCompile Include="..\kclib\KeProcess32.c" />
<ClCompile Include="..\kclib\MM\KeMemoryManager32.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

66
HOS/HOS.vcxproj.filters Normal file
View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\kclib\KeDef.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\kclib\KeGraph32.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\kclib\KeCPUStruct32.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\kclib\KeGlobalVariables.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\kclib\KeIO32.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\kclib\KeKernelStruct32.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\kclib\MM\KeMemoryManager32.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\kclib\KeMemory32.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\kclib\KeProcess32.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\kclib\KeGraph32.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\kclib\KeIO32.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\kclib\KeKernelEntry.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\kclib\KeMemory32.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\kclib\KeProcess32.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\kclib\MM\KeMemoryManager32.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -1,5 +1,7 @@
#include "KeGraph32.h"
#include "KeDef.h"
#include "KeGlobalVariables.h"
#include "KeKernelStruct32.h"
ULONG32 KeGetCurrentGraphRow( _IN_ ULONG32 GraphPosition)
{
return (GraphPosition/2*DOSGraphColumn);

View File

@ -1,4 +1,6 @@
#include "KeIO32.h"
#include "KeDef.h"
#include "KeKernelStruct32.h"
#include "KeGraph32.h"
VOID KeWriteGDT(_IN_ ULONG32 Index, _IN_ PIAGDT32 Dest, _IN_ PKeGDTDescriptor32 Src)
{

View File

@ -3,6 +3,7 @@
#include "KeGraph32.h"
#include "KeMemory32.h"
#include "KeIO32.h"
#include "KeKernelStruct32.h"
#include "KeProcess32.h"
VOID HYPKERNELAPI KeSystemInit(VOID);

View File

@ -1,4 +1,5 @@
#include "KeProcess32.h"
#include "KeDef.h"
#include "KeMemory32.h"
#include "KeKernelStruct32.h"
#include "KeIO32.h"

Binary file not shown.