📄 kernelasm.asm
字号:
; * kernelasm.asm : FritzOS C++ Kernel Assembly Routines and Second Stage Loader; Copyright (C) 2002 Tom Fritz;; * This program is a part of the FritzOS kernel, and may be freely; * copied under the terms of the GNU General Public License (GPL),; * version 2, or at your option any later version.; ; For more info, look at the COPYING file.;; Tell NASM that this is 32-bit PMode code[BITS 32]; This is loaded first, so let NASM know that there is a C++ Kernel EXTERN start ; The FritzOS C++ Kernel main function.; This tells NASM that in the C++ kernel there is a function called 'start_textmode' EXTERN start_textmode ; We need this so we can print messages.; This tells NASM that in the C++ kernel there is a function called 'LoadingGDTMsg' EXTERN LoadingGDTMsg ; We need this so the user knows the GDT is being loaded.; This tells NASM that in the C++ kernel there is a function called 'CheckVid' EXTERN CheckVid ; We need this to check if a video or color card is installed.; This tells NASM to tell GCC that the memcpy function is defined here. GLOBAL memcpy; This tells NASM to tell GCC that the memset function is defined here. GLOBAL memset; Registers Value Getting Functions For The C++ Kernel:GLOBAL geteaxGLOBAL getebxGLOBAL getecxGLOBAL getedxGLOBAL getcsGLOBAL getdsGLOBAL getesGLOBAL getfsGLOBAL getgsGLOBAL getssGLOBAL getebpGLOBAL getespGLOBAL geteflags; We don't make StartA20 a GLOBAL variable to be used in the FritzOS C Kernel because, we don't; want to change anything like that in the C Kernel right now. ; This is where the FritzOS Assembly Kernel starts; we get here from boot.asmAsmStart: ; Start Textmode functions: call start_textmode ; First, test for the correct video card, from the C++ kernel: call CheckVid ; Load the GDT; this is needed to set up where all the code and data goes: ; Print a message that says the GDT is being loaded: call LoadingGDTMsg lgdt [ GDTR ] ; enter pmode ; Jump, or go, to the the FritzOS C Kernel jmp start ; Jump, or go to, the FritzOS C Kernel jmp $ ; If the kernel wasn't loaded, freeze, but this shouldn't happen; End of asmstart; memcpy: Memory Copy Funciton for the FritzOS C Kernel.; It's defined here because it's in assembly language.; This is what the C definition code would look like:; extern void* memcpy( void* to, const void* from, size_t count );memcpy: push ebp mov ebp, esp mov esi, [ebp + 8] ; First Argument: src pointer mov edi, [ebp +12] ; Second Argument: dest pointer mov ecx, [ebp + 16] ; Third Argument: string size in bytes mov eax, edi ; Return Value: Save Now, before EDI changes cld ; Make sure direction flag set correctly rep movsb ; Block-Copy from src to dest pop ebp ; Restore Caller's stack frame ret; End of memcpy; memset: Memory Set Funciton for the FritzOS C Kernel.; It's defined here because it's in assembly language.; This is what the C definition code would look like:;爀xtern void* memset( void* buf, int ch, size_t cont );memset: push ebp mov ebp, esp mov edi, [ebp + 8] ; First Argument: buffer pointer mov edi, [ebp +12] ; Second Argument: value to write mov eax, [ebp + 16] ; Third Argument: string size in bytes push edi ; Return Value: Save Now, before EDI changes cld ; Make sure direction flag set correctly rep stosb pop eax ; Recover return value pop ebp ; Restore Caller's stack frame ret; End of memset;*************************************************************************************************************; GDTR; Make a new GDT for the IDT; Global Descriptor Table: This tells the computer where all the segments ( now selectors ) are.GDTR dw gdt_end-1 dd gdtgdtnullsel equ $-gdtgdt0 dd 0 dd 0CodeSel equ $-gdt dw 0ffffh dw 0 db 0 db 09ah db 0cfh db 0hDataSel equ $-gdt dw 0ffffh dw 0h db 0h db 092h db 0cfh db 0gdt_end; End of GDTR; For Getting The Register Values, For The C++ Kernel:geteax: ; unsigned long geteax(); retgetebx: ; unsigned long getebx(); mov eax, ebx retgetecx: ; unsigned long getecx(); mov eax, ecx retgetedx: ; unsigned long getedx(); mov eax, edx retgetcs: ; unsigned int getcs(); mov ax, cs retgetds: ; unsigned int getds(); mov ax, ds retgetes: ; unsigned int getes(); mov ax, es retgetfs: ; unsigned int getfs(); mov ax, fs retgetgs: ; unsigned int getgs(); mov ax, gs retgetss: ; unsigned int getss(); mov ax, fs retgetedi: ; unsigned long getedi(); mov eax, edi retgetesi: ; unsigned long getesi(); mov eax, esi retgetebp: ; unsigned long getebp(); mov eax, ebp retgetesp: ; unsigned long getesp(); mov eax, esp retgeteflags: ; unsigned long geteflags(); pushfd pop eax ret; End of kernelasm.asm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -