📄 kernel.asm
字号:
; kernel startup stack
global init_tos
resw 512
init_tos:
; the last paragraph of conventional memory might become an MCB
resb 16
global __init_end
__init_end:
init_end:
segment _DATA
; blockdev private stack
global blk_stk_top
times 192 dw 0
blk_stk_top:
; clockdev private stack
global clk_stk_top
times 64 dw 0
clk_stk_top:
; Dynamic data:
; member of the DOS DATA GROUP
; and marks definitive end of all used data in kernel data segment
;
segment _DATAEND
_swap_indos:
; we don't know precisely what needs to be swapped before this, so set it here.
; this is just after FIXED_DATA+BSS+DATA and before (D)CONST+BSS
; probably, the clock and block stacks and disktransferbuffer should go past
; _swap_indos but only if int2a ah=80/81 (critical section start/end)
; are called upon entry and exit of the device drivers
times 96 dw 0x9090 ; Process 0 Stack
global _p_0_tos
_p_0_tos:
segment DYN_DATA
global _Dyn
_Dyn:
DynAllocated dw 0
segment ID_B
global __INIT_DATA_START
__INIT_DATA_START:
segment ID_E
global __INIT_DATA_END
__INIT_DATA_END:
segment INIT_TEXT_START
global __InitTextStart
__InitTextStart: ; and c version
;
; start end end of HMA area
segment HMA_TEXT_START
global __HMATextAvailable
__HMATextAvailable
global __HMATextStart
__HMATextStart:
;
; the HMA area is filled with 1eh+3(=sizeof VDISK) = 33 byte dummy data,
; so nothing will ever be below 0xffff:0031
;
segment HMA_TEXT
begin_hma:
times 10h db 0 ; filler [ffff:0..ffff:10]
times 20h db 0
db 0
; to minimize relocations
global _DGROUP_
_DGROUP_ dw DGROUP
%ifdef WATCOM
; 32 bit multiplication + division
global __U4M
__U4M:
LMULU
global __U4D
__U4D:
LDIVMODU
%endif
resb 0xd0 - ($-begin_hma)
; reserve space for far jump to cp/m routine
resb 5
;End of HMA segment
segment HMA_TEXT_END
global __HMATextEnd
__HMATextEnd: ; and c version
; The default stack (_TEXT:0) will overwrite the data area, so I create a dummy
; stack here to ease debugging. -- ror4
segment _STACK class=STACK stack
segment CONST
; dummy interrupt return handlers
global _int22_handler
global _int28_handler
global _int2a_handler
global _empty_handler
_int22_handler:
_int28_handler:
_int2a_handler:
_empty_handler:
iret
global _initforceEnableA20
initforceEnableA20:
call near forceEnableA20
retf
global __HMARelocationTableStart
__HMARelocationTableStart:
global _int2f_handler
extern reloc_call_int2f_handler
_int2f_handler: jmp 0:reloc_call_int2f_handler
call near forceEnableA20
global _int20_handler
extern reloc_call_int20_handler
_int20_handler: jmp 0:reloc_call_int20_handler
call near forceEnableA20
global _int21_handler
extern reloc_call_int21_handler
_int21_handler: jmp 0:reloc_call_int21_handler
call near forceEnableA20
global _low_int25_handler
extern reloc_call_low_int25_handler
_low_int25_handler: jmp 0:reloc_call_low_int25_handler
call near forceEnableA20
global _low_int26_handler
extern reloc_call_low_int26_handler
_low_int26_handler: jmp 0:reloc_call_low_int26_handler
call near forceEnableA20
global _int27_handler
extern reloc_call_int27_handler
_int27_handler: jmp 0:reloc_call_int27_handler
call near forceEnableA20
global _int0_handler
extern reloc_call_int0_handler
_int0_handler: jmp 0:reloc_call_int0_handler
call near forceEnableA20
global _int6_handler
extern reloc_call_int6_handler
_int6_handler: jmp 0:reloc_call_int6_handler
call near forceEnableA20
global _cpm_entry
extern reloc_call_cpm_entry
_cpm_entry: jmp 0:reloc_call_cpm_entry
call near forceEnableA20
global _reloc_call_blk_driver
extern _blk_driver
_reloc_call_blk_driver:
jmp 0:_blk_driver
call near forceEnableA20
global _reloc_call_clk_driver
extern _clk_driver
_reloc_call_clk_driver:
jmp 0:_clk_driver
call near forceEnableA20
global _CharMapSrvc ; in _DATA (see AARD)
extern _reloc_call_CharMapSrvc
_CharMapSrvc: jmp 0:_reloc_call_CharMapSrvc
call near forceEnableA20
global _init_call_p_0
extern reloc_call_p_0
_init_call_p_0: jmp 0:reloc_call_p_0
call near forceEnableA20
global __HMARelocationTableEnd
__HMARelocationTableEnd:
;
; if we were lucky, we found all entries from the outside to the kernel.
; if not, BUMS
;
;
; this routine makes the HMA area available. PERIOD.
; must conserve ALL registers
; will be only ever called, if HMA (DOS=HIGH) is enabled.
; for obvious reasons it should be located at the relocation table
;
global _XMSDriverAddress
_XMSDriverAddress:
dw 0 ; XMS driver, if detected
dw 0
global _ENABLEA20
_ENABLEA20:
mov ah,5
UsingXMSdriver:
push bx
call far [cs:_XMSDriverAddress]
pop bx
retf
global _DISABLEA20
_DISABLEA20:
mov ah,6
jmp short UsingXMSdriver
dslowmem dw 0
eshighmem dw 0ffffh
global forceEnableA20
forceEnableA20:
push ds
push es
push ax
forceEnableA20retry:
mov ds, [cs:dslowmem]
mov es, [cs:eshighmem]
mov ax, [ds:00000h]
cmp ax, [es:00010h]
jne forceEnableA20success
mov ax, [ds:00002h]
cmp ax, [es:00012h]
jne forceEnableA20success
mov ax, [ds:00004h]
cmp ax, [es:00014h]
jne forceEnableA20success
mov ax, [ds:00006h]
cmp ax, [es:00016h]
jne forceEnableA20success
;
; ok, we have to enable A20 )at least seems so
;
call far _ENABLEA20
jmp short forceEnableA20retry
forceEnableA20success:
pop ax
pop es
pop ds
ret
;
; global f*cking compatibility issues:
;
; very old brain dead software (PKLITE, copyright 1990)
; forces us to execute with A20 disabled
;
global _ExecUserDisableA20
_ExecUserDisableA20:
cmp word [cs:_XMSDriverAddress],0
jne NeedToDisable
cmp word [cs:_XMSDriverAddress+2],0
je noNeedToDisable
NeedToDisable:
push ax
call far _DISABLEA20
pop ax
noNeedToDisable:
iret
;
; Default Int 24h handler -- always returns fail
; so we have not to relocate it (now)
;
FAIL equ 03h
global _int24_handler
_int24_handler: mov al,FAIL
iret
;
; this makes some things easier
;
segment _LOWTEXT
global _TEXT_DGROUP
_TEXT_DGROUP dw DGROUP
segment INIT_TEXT
global _INIT_DGROUP
_INIT_DGROUP dw DGROUP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -