📄 mos.asm
字号:
MOV EBX, OFFSET MonTSS ;Must put ptr to JCB in TSS
MOV [EBX.TSS_pJCB], EAX ;pJCB into MonTSS
MOV EBX, OFFSET PDir1 ;Page Directory
MOV ESI, OFFSET rgOSJob ;Job Name
MOV ECX, cbOSJob ;Size of Name
XOR EDX, EDX ;NO pVirtVid yet (set up later in init)
CALL InitNewJCB
; IMPORTANT - You can't call AllocExch before pRunTSS is VALID!
; THIS IS THE FIRST POINT AllocExh is valid
MOV EAX, pRunTSS
ADD EAX, TSS_Exch ;Alloc exch for initial (first) TSS
PUSH EAX
CALL FAR PTR _AllocExch
;=============================================================================
;
; Set up DEBUGGER Task and Job
; The debugger is set up as another job with its one task.
; The debugger must not be called (Int03) until this code executes,
; AND the video is initialized.
; We can't use NewTask because the debugger operates independent of
; the kernel until it is called (INT 03 or Exception)
;
;The following code section builds a descriptor entry for
;the initial TSS (for Debugger) and places it into the GDT
MOV EAX, sTSS ; Limit of TSS (TSS + SOFTSTATE)
MOV EBX, 0089h ; G(0),AV(0),LIM(0),P(1),DPL(0),B(0)
MOV EDX, OFFSET DbgTSS ; Address of Debugger TSS
MOV EDI, OFFSET rgTSSDesc+8 ; Address of GDT entry to fill in
CALL AddTSSDesc
;Now that we have valid Descriptor, we set up the TSS itself
MOV EAX, OFFSET rgTSSDesc+8 ; ptr to second TSS descriptor
SUB EAX, OFFSET GDT ; Sub offset of GDT Base to get Sel of TSS
MOV EBX, OFFSET DbgTSS ; Get ptr to initial TSS in EBX
MOV [EBX.Tid],AX ; Store TSS Selector in TSS (Task ID)
MOV [EBX.Priority], 1 ; Debugger is HIGH Priority
MOV [EBX.TSS_CR3], OFFSET PDir1 ;Physical address of PDir1
MOV EDX, OFFSET DbgTask
MOV [EBX.TSS_EIP],EDX
MOV [EBX.TSS_CS],OSCodeSel ; Put OSCodeSel in the TSS
MOV [EBX.TSS_DS],DataSel ; Put DataSel in the TSS
MOV [EBX.TSS_ES],DataSel ;
MOV [EBX.TSS_FS],DataSel ;
MOV [EBX.TSS_GS],DataSel ;
MOV [EBX.TSS_SS],DataSel ;
MOV [EBX.TSS_SS0],DataSel ;
MOV EAX, OFFSET Stack1Top
MOV [EBX.TSS_ESP],EAX ; A 1K Stack in the Dbg TSS
MOV [EBX.TSS_ESP0],EAX ;
MOV [EBX.TSS_EFlags],00000202h ; Load the Flags Register
MOV [EBX.TSSNum], 2 ; Number of Dubegger TSS
;Set up Job Control Block for Debugger
;JOB 0 is not allowed. First JCB IS job 1, debugger is always 2
MOV EAX, OFFSET DbgJCB
MOV [EAX.JobNum], 2 ;Number the JCB
MOV [EBX.TSS_pJCB], EAX ;EBX still points to DbgTSS
MOV EBX, OFFSET PDir1 ;Page Directory (OS PD to start)
MOV ESI, OFFSET rgDbgJob ;Name
MOV ECX, cbDbgJob ;size of name
MOV EDX, 1 ;Debugger gets video 1
CALL InitNewJCB
;Now allocate the default exchange for Debugger
MOV EAX, OFFSET DbgTSS
ADD EAX, TSS_Exch ;Alloc exch for Debugger TSS
PUSH EAX
CALL FAR PTR _AllocExch
;================================================================
; ALSO NOTE: The InitMemMgmt call enables PAGING! Physical addresses
; will not necessarily match Linear addresses. Pay attention!
;
CALL InitMemMgmt ;InitMemMgmt allocates an exch so
;this the first point it can be called.
;It also calls SEND!
;================================================================
; FIRST POINT memory management calls are valid
;================================================================
;Now we will allocate two virtual video screens (1 Page each)
;for the Monitor and Debugger and place them in the JCBs
;Also we set pVidMem for Monitor to VGATextBase address
;cause it has the active video by default
PUSH 1 ; 1 page
MOV EAX, OFFSET MonJCB ; Ptr to Monitor JCB
ADD EAX, pVirtVid ; Offset in JCB to pVirtVid
PUSH EAX
CALL FAR PTR _AllocOSPage ; Get 'em!
MOV EAX, OFFSET MonJCB ; Make VirtVid Active for Monitor
MOV [EAX.pVidMem], VGATextBase
PUSH 1 ; 1 page
MOV EAX, OFFSET DbgJCB ;
ADD EAX, pVirtVid
PUSH EAX
CALL FAR PTR _AllocOSPage ; Get 'em!
MOV EAX, OFFSET DbgJCB ; Make VirtVid Active for Debugger
MOV EBX, [EAX.pVirtVid]
MOV [EAX.pVidMem], EBX
CALL InitVideo ;Set Text Screen 0
;================================================================
; FIRST POINT video calls are valid
; FIRST POINT Debugger is working (only because it needs the video)
;================================================================
;We must allocate a Page Table to be used when one
;must be added to a PD (User or OS). This must be
;done in advance offinding out we need one because
;we may not have a linear address to access it in
;if the current PTs are all used up!
PUSH 1 ; 1 page for Next Page Table
MOV EAX, OFFSET pNextPT ;
PUSH EAX
CALL FAR PTR _AllocOSPage ; Get 'em!
;================================================================
; At this point we can allocate pages for dynamic structures and
; initialize them.
;================================================================
; Allocate 8 pages (32768 bytes) for 64 Task State Segments (structures).
; Then call InitFreeTSS (which fills them all in with default values)
PUSH 8 ; 8 pages for 64 TSSs (32768 bytes)
MOV EAX, OFFSET pDynTSSs ;
PUSH EAX
CALL FAR PTR _AllocOSPage ; Get 'em!
XOR EAX, EAX ; Clear allocated memory for TSSs
MOV ECX, 8192 ; (512 * 64 = 32768 = 8192 * 4)
MOV EDI, pDynTSSs ; where to store 0s
REP STOSD ; Do it
MOV EAX, pDynTSSs
MOV ECX, nTSS-2 ; count of dynamic TSSs (- OS & Dbgr TSS)
CALL InitFreeTSS ; Init the array of Process Control Blocks
;================================================================
; Allocate 4 pages (16384 bytes) for 32 Job Control Blocks (structures).
; Then call InitFreeJCB
PUSH 4 ; 4 pages for 32 JCBs (16384 bytes)
MOV EAX, OFFSET pJCBs ; Returns ptr to allocated mem in pJCBs
PUSH EAX ;
CALL FAR PTR _AllocOSPage ; Get 'em!
XOR EAX, EAX ; Clear allocated memory for JCBs
MOV ECX, 4096 ; (4*4096=16384 - DWORDS!)
MOV EDI, pJCBs ; where to store 0s
REP STOSD ; Do it
MOV EAX, pJCBs ; Ptr to JCBs
MOV ECX, nJCBs ; Count of Job Control Blocks
MOV EDX, sJCB ; EDX is size of a JCB
CALL InitFreeJCB ; Init the array of JCBs
;================================================================
; Allocate 2 pages (8192 bytes) for 128 Request Blocks (structures).
; Then call InitFreeRQB
PUSH 2 ; 2 pages for 128 RQBs
MOV EAX, OFFSET pRQBs ; Returns ptr to allocated mem in pRQBs
PUSH EAX ;
CALL FAR PTR _AllocOSPage ; Get 'em!
XOR EAX, EAX ; Clear allocated memory for RQBs
MOV ECX, 2048 ; (8192)
MOV EDI, pRQBs ; where to store 0s
REP STOSD ; Do it
MOV EAX, pRQBs ; Ptr to RQBs
MOV ECX, nRQBs ; Count of Request Blocks
MOV EDX, sRQB ; EDX is size of a RQB
CALL InitFreeRQB ; Init the array of RQBs
;================================================================
; Allocate 1 page (4096 bytes) for 256 Exchanges (16*256=4096).
; Exchanges are 16 bytes each. Then zero the memory which has
; the effect of initializing them because all fields in an Exch
; are zero if not allocated.
PUSH 1 ; 1 pages for 256 Exchs (4096 bytes)
MOV EAX, OFFSET pExchTmp ; Returns ptr to allocated mem in pJCBs
PUSH EAX ;
CALL FAR PTR _AllocOSPage ; Get it!
XOR EAX, EAX ; Clear allocated memory
MOV ECX, 1024 ; (4*1024=4096)
MOV EDI, pExchTmp ; where to store 0s
REP STOSD ; Store EAX in 1024 locations
;Now we move the contents of the 3 static exchanges
;into the dynamic array. This is 60 bytes for 3
;exchanges.
MOV ESI, prgExch ; Source (static ones)
MOV EDI, pExchTmp ; Destination (dynamic ones)
MOV ECX, 12 ; 12 DWords (3 Exchanges)
REP MOVSD ; Move 'em!
MOV EAX, pExchTmp ; The new ones
MOV prgExch, EAX ; prgExch now points to new ones
MOV nExch, nDynEXCH ; 256 to use (-3 already in use)
;================================================================
CALL FAR PTR _ClrScr ;Clear the screen
CALL NEAR PTR _Monitor ;Head for the Monitor!!
;The Monitor call never comes back (it better not...)
HLT ;Well, you never know (I AM human)
;
;
;=============================================================================
;=============================================================================
;=============================================================================
;
;
;=============================================================================
; DEVICE DRIVER interface code is loaded here.
;=============================================================================
;
INCLUDE DVDRCode.inc
;
;=============================================================================
; ALL Keyboard Code is included at this point.
;=============================================================================
;
INCLUDE KBDCode.inc
;
;=============================================================================
; ALL Numeric/String conversions are included here (for debugger/tesing)
;=============================================================================
;
INCLUDE NumCnvrt.inc ;Move to DLL later
;
;=============================================================================
; DEBUGGER CODE
;=============================================================================
;
INCLUDE DBGCode.inc
INCLUDE UASM.CAS ;Code for debugger diassembler
;
;=============================================================================
; FLOPPY & HARD DISK DRIVER CODE
;=============================================================================
;
INCLUDE FDD.CAS
INCLUDE HDD.CAS
;
;=============================================================================
; INCLUDE Comms Driver Code here (serial & parallel)
;=============================================================================
INCLUDE CommDrv.CAS
;=============================================================================
; INCLUDE File System Code here
;=============================================================================
INCLUDE FSys.CAS
;=============================================================================
; DMA Handler code is included here
;=============================================================================
;
INCLUDE DMACode.inc
;
;=============================================================================
; Interrupt Service Routine support is included
;=============================================================================
INCLUDE IntCode.inc
;=============================================================================
; Job Support Code is included here
;=============================================================================
INCLUDE JobCode.inc
INCLUDE JOBC.CAS
;=============================================================================
; Request Block Support Code is included here
;=============================================================================
INCLUDE RQBCode.inc
;=============================================================================
; Video Code is INCLUDED Here...
;=============================================================================
INCLUDE VidCode.inc
;=============================================================================
; Timer Code is INCLUDED Here...
;=============================================================================
INCLUDE TmrCode.inc
;=============================================================================
; Memory management Code is INCLUDED Here...
;=============================================================================
INCLUDE MemCode.inc
;=============================================================================
; Service Mgmt Code is INCLUDED Here...
;=============================================================================
INCLUDE SVCCode.inc
;=============================================================================
; Misc. Support Routines are INCLUDED Here...
;=============================================================================
INCLUDE MiscCode.inc
;=============================================================================
; Initialization Code is INCLUDED Here...
;=============================================================================
INCLUDE InitCode.inc
;=============================================================================
; KERNEL Code is INCLUDED Here...
;=============================================================================
INCLUDE KERNEL.inc
;=============================================================================
;=============================================================================
; DUMMY CALL for uninitialized GDT call gate slots
;=============================================================================
;
DummyCall PROC FAR
MOV EAX, ercBadCallGate
RETF
DummyCall ENDP
;=============================================================================
; Procedure jumped to by interrupt procedures to enter debugger
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -