📄 markfile
字号:
#00100 ! This is the subroutine called by start386, it shares the same stack with00101 ! bootmanager, it will continue init the kernel execution environment.00102 00103 .sect .text00104 begtext:00105 .sect .rom00106 begrom:00107 .sect .data00108 begdata:00109 .sect .bss00110 begbss:00111 00112 #include "include/stuix/config.h"00113 #include "include/stuix/const.h"00114 #include "include/stuix/boot.h"00115 #include "const.h"00116 #include "protect.h"00117 00118 ! Exported functions00119 ! Note: in assembly language the .define statement applied to a function name00120 ! is loosely equivalent to a prototype in C code -- it makes it possible to00121 ! link to an entity declared in the assembly code but does not create 00122 ! the entity.00123 00124 .define _divide_error00125 .define _single_step_exception00126 .define _nmi00127 .define _breakpoint_exception00128 .define _overflow00129 .define _bounds_check00130 .define _inval_opcode00131 .define _copr_not_available00132 .define _double_fault00133 .define _copr_seg_overrun00134 .define _inval_tss00135 .define _segment_not_present00136 .define _stack_exception00137 .define _general_protection00138 .define _page_fault00139 .define _copr_error00140 00141 .define _hwint0000142 .define _hwint0100143 .define _hwint0200144 .define _hwint0300145 .define _hwint0400146 .define _hwint0500147 .define _hwint0600148 .define _hwint0700149 .define _hwint0800150 .define _hwint0900151 .define _hwint1000152 .define _hwint1100153 .define _hwint1200154 .define _hwint1300155 .define _hwint1400156 .define _hwint1500157 00158 .define _s_call00159 .define _savu00160 .define _retu00161 .define _aretu00162 .define _idle00163 .define _gohome00164 00165 ! Imported functions00166 .extern _cstart00167 .extern _swtch00168 .extern _clock_handler00169 .extern _kbd_hw_int00170 .extern _trap00171 .extern _nohandler00172 00173 ! Exported variables.00174 ! Note: when used with a variable the .define does not reserve storage,00175 ! it makes the name externally visible so it may be linked to.00176 00177 .define begbss00178 .define begdata00179 00180 ! Imported variables.00181 00182 .extern _runrun ! schedualing flag00183 .extern _gdt ! GDT table00184 .extern _bm_sp00185 .extern _usr_ppda_base ! Page directory physical address00186 .extern _usr_pagetab_ptr ! kernel stack pointer at this position00187 00188 .sect .text00189 00190 !*===========================================================================*00191 !* Stuix *00192 !*===========================================================================*00193 00194 STUIX:00195 ! Set up a C stack frame on the bootmanager stack, it shares the same stack with00196 ! boot manager. The stack won't switch until page is enabled.00197 00198 push ebp00199 mov ebp, esp00200 push esi00201 push edi00202 mov (_bm_sp), esp ! save return address00203 ! to start38600204 00205 ! Get the boot manager gdtr absolute address, it is used to switch back to real00206 ! address mode. 00207 00208 sgdt (_gdt + PNE_GDT_SELECTOR) 00209 00210 ! Copy the bootmanager global descriptor table to the address space of kernel00211 ! but don't switch over to it until the rest descriptors were all initialized 00212 ! by Prot_init() and the processor page unit is enabled.00213 ! FS contains the bootmanager data segment, used to copy first 8 descriptor00214 ! to the kernel address space for referencing.00215 00216 mov esi, BM_GDT_OFFSET ! 4*3 + 102400217 mov ebx, _gdt ! kernel gdt address00218 mov ecx, 8*800219 copygdt: 00220 fseg movb al,(esi)00221 movb (ebx),al00222 inc esi00223 inc ebx00224 loop copygdt00225 00226 ! Locate the kernel image segment information00227 ! and call C startup code to set up a proper00228 ! environment to run main()00229 00230 mov esi, A_TEXT_OFF00231 fseg mov ebx, (esi)00232 mov esi, A_DATA_OFF00233 fseg mov edx, (esi)00234 mov esi, A_BSS_OFF00235 fseg mov eax, (esi)00236 00237 push eax00238 push edx00239 push ebx00240 push KERNEL_DATA_SELECTOR00241 push KERNEL_CODE_SELECTOR00242 call _cstart ! cstart(cs, ds, textsize, datasize, bssize)00243 add esp, 5*400244 00245 ! Enable processor page unit, identity pages is required by the proceesor00246 ! to guarantees the correctly address referencing during critical section.00247 ! this makes the machine dependence code extremely hard to understand. Do00248 ! not try to figure out how it works if you are novice to the architecture00249 ! of IA-32. if you insist, we recommand you to read <Intel Architecture00250 ! Software Developer's Manual> volume 3, chapter 9. Also start386.asm need00251 ! to be grasped, since it highly coorperates with msx686.s00252 00253 ! The PDBR aways points to the physical address of current process's PPDA, 00254 ! the first two page directory entries in PPDA point to the physical address00255 ! of two kernel tables in contingous 8k space respectly. the thired page00256 ! directory entry in PPDA point to the usr 4k page table.00257 00258 ! As soon as the processor page unit is enabled, don't use long jump, it will00259 ! cause the processor deed lock, this characteristic was not referred by the00260 ! Intel document.00261 00262 mov eax, (_usr_ppda_base)00263 mov cr3, eax00264 mov eax, cr000265 or eax, 0x8000000000266 mov cr0, eax00267 jmp csinit00268 csinit:00269 00270 ! we are in identity mapped kernel code and data page now, load our new00271 ! GDT, IDT, LDT and switch to the new environment to call _main00272 00273 lgdt (_gdt + GDT_SELECTOR)00274 lidt (_gdt + IDT_SELECTOR)00275 o16 mov ax, LDT_SELECTOR00276 lldt ax00277 00278 jmpf KERNEL_VCODE_SELECTOR:csvinit00279 csvinit:00280 o16 mov ax, KERNEL_VDATA_SELECTOR00281 mov ds, ax00282 mov ss, ax00283 mov es, ax00284 mov fs, ax00285 mov gs, ax00286 00287 ! Load our 0# process kernel stack00288 00289 mov esp, (_usr_pagetab_ptr)00290 00291 ! Load our first and only task as the requirement of processor00292 o16 mov ax, KERNEL_TSS_SELECTOR 00293 ltr ax00294 push 0 ! set flags to known good state00295 popf ! clear nested task and disable interrupt00296 00297 call _main00298 00299 RING0 = 3 ! Processor code segment RPL00300 00301 !*===========================================================================*00302 !* interrupt handlers *00303 !*===========================================================================*00304 00305 !*===========================================================================*00306 !* hwint00 - 07 *00307 !*===========================================================================*00308 ! Note this is a macro, it looks like a subroutine.00309 #define hwint_master(irq, handler) \00310 cld /* set direction flag to a know value */;\00311 push 0 /* padding for error code */;\00312 push irq /* interrupt irq */;\00313 pushad /* save general registers */;\00314 push ds /* save ds */;\00315 push es /* save es */;\00316 push fs /* save fs */;\00317 push gs /* save gs */;\
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -