1 Star 1 Fork 0

Xthoa / uFexos1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
asm.asm 2.94 KB
一键复制 编辑 原始数据 按行查看 历史
Xthoa 提交于 2021-01-26 09:12 . 'v7.a'
bits 32
section .text
extern _cputchar
extern _cputu8
extern _cputu16
extern _cputu32
global _int21_asm
extern _int21
_int21_asm:
pushad
xor eax,eax
in al,0x60
push eax
call _int21
add esp,4
mov al,0x20
out 0x20,al
popad
iretd
global _int20_asm
extern _int20
_int20_asm:
pushad
mov al,0x20
out 0x20,al
call _int20
popad
iretd
global _ljmp
_ljmp:
jmp far [esp+4]
ret
global _delay
_delay:
push ecx
mov ecx,[esp+8]
shl ecx,8
.lp:
loop .lp
pop ecx
ret
global _read_eflags
_read_eflags:
pushfd
pop eax
ret
global _enter_ring
extern _current_tss
_enter_ring:
;void enter_ring1(void* esp);
;WARNING: THIS MEANS NO WAY BACK!!!
;In order to do this,
;1.prepare ring1 ss esp cs eip and retf
;No more
;We need to keep the same env so
;start like this--
;1) store esp1
call _current_tss
mov edx,eax
mov esi,[edx+28]
mov eax,[esp+4] ;ring
cmp eax,2
jb .s1r1
je .s1r2
mov ecx,[edx+56]
jmp .s1ra
.s1r2:
mov ecx,[edx+20]
jmp .s1ra
.s1r1:
mov ecx,[edx+12]
.s1ra:
;2) push ss+(sizeof(gdt)*2+1)*ring
push ss
mov ebx,eax
shl eax,4
add eax,ebx
add word [esp],ax
;3) push esp
push ecx
;4) push cs+(sizeof(gdt)*2+1)*ring
push cs
add word [esp],ax
;5) push eip
push .ret
;6) retf!
mov cr3,esi
retf
;Now we are in ring1!
.ret:
;7) reset other segs as ss
mov ax,ss
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
ret
global _cprintf
_cprintf:
;void cprintf(char col,char* fmt,...);
push ebp ;set up stack frame
mov ebp,esp
push ebx ;store regs
push ecx
push edx
push esi
xor eax,eax
mov edx,[ebp+8] ;edx=color
mov esi,[ebp+12] ;esi=fmt
lea ebx,[ebp+12]
push edx ;push color
.lp:
lodsb ;al=*(fmt++)
test al,al ;if al==0:
jz .end ;goto .end
cmp al,'%' ;if al!='%':
jne .nlp ;goto .nlp // next loop
lodsb ;bl=*(fmt++)
mov cl,al
add ebx,4
mov eax,dword [ebx]
push eax
cmp cl,'c' ;if bl!='c':
jne .n1 ;goto .n1
call _cputchar ;putchar(al,dl)
jmp .fnlp ;goto .fnlp
.n1:
cmp cl,'b'
jne .n2
call _cputu8
jmp .fnlp
.n2:
cmp cl,'w'
jne .n3
call _cputu16
jmp .fnlp
.n3:
cmp cl,'x'
jne .n4
call _cputu32
jmp .fnlp
.n4:
pop eax
push '%'
call _cputchar
add esp,4
push eax
call _cputchar
.fnlp:
add esp,4
jmp .lp
.nlp:
push eax
call _cputchar
add esp,4
jmp .lp
.end:
add esp,4
pop esi
pop edx
pop ecx
pop ebx
mov esp,ebp
pop ebp
ret
global _syscall0_asm
extern _syscall0
_syscall0_asm:
pushad
sti
pushad
call _syscall0
add esp,0x20
mov [esp+0x1c],eax
popad
iretd
global _int0e_asm
extern _int0e
_int0e_asm: ;Page fault
mov eax,cr2
push eax
mov eax,cr3
push eax
call _int0e
add esp,8
iretd
global _int0d_asm
extern _int0d
_int0d_asm: ;Segment fault
call _int0d
add esp,4
iretd
global _setjmp
_setjmp:
push ebp
mov eax,[esp+8]
mov ebp,esp
mov esp,eax
add esp,40
push ebp
push .ret1
pushad
.ret0:
mov eax,0
mov esp,ebp
pop ebp
ret
.ret1:
mov eax,1
pop ebp
ret
global _longjmp
_longjmp: ;THIS MEANS NO WAY BACK
mov eax,[esp+4]
mov esp,eax
popad
pop eax ;eip
pop esp ;esp
jmp eax
C
1
https://gitee.com/xthoa/u-fexos1.git
git@gitee.com:xthoa/u-fexos1.git
xthoa
u-fexos1
uFexos1
master

搜索帮助