Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.0 KiB

  1. TITLE KERNSTUB - Assembly stub program for KERNEL.EXE
  2. .xlist
  3. ?DF = 1
  4. SWAPPRO = 0
  5. include cmacros.inc
  6. ; NOTE: This code is always assembled in real mode, so it'll run on any machine.
  7. ;
  8. PMODE32=0
  9. include newexe.inc
  10. include protect.inc
  11. ifdef WOW
  12. include vint.inc
  13. endif
  14. .list
  15. createSeg _TEXT,CODE,PARA,PUBLIC,CODE
  16. createSeg STACK,STACK,PARA,STACK,STACK
  17. sBegin STACK
  18. DB 128 DUP (?)
  19. stacktop LABEL BYTE
  20. sEnd STACK
  21. sBegin CODE
  22. assumes CS,CODE
  23. assumes DS,CODE
  24. KERNSTUB PROC FAR
  25. push cs
  26. pop ds
  27. mov si,codeOFFSET stacktop
  28. add si,1FFh
  29. and si,not 1FFh
  30. cmp cs:[si].ne_magic,NEMAGIC
  31. je @F
  32. jmp ksfail
  33. @@:
  34. mov ax,ds
  35. cli
  36. mov ss,ax
  37. mov sp,si
  38. sti
  39. mov bx,ds:[si].ne_autodata ; Get number of automatic DS
  40. dec bx
  41. jl ksg11 ; Continue if no DS
  42. shl bx,1
  43. shl bx,1
  44. shl bx,1
  45. .errnz 8 - SIZE new_seg
  46. add bx,ds:[si].ne_segtab ; DS:BX -> seg. tab. entry for DS
  47. mov ax,ds:[si+bx].ns_sector ; Compute paragraph address of DS
  48. cmp ds:[si].ne_align,0
  49. jne ksg10
  50. mov ds:[si].ne_align,NSALIGN ; in DI
  51. ksg10:
  52. mov cx,ds:[si].ne_align ; Convert sectors to paragraphs
  53. sub cx,4
  54. shl ax,cl
  55. mov di,cs ; Add to paragraph address of old
  56. sub di,20h ; exe header
  57. add di,ax
  58. ksg11:
  59. push cx
  60. mov bx,word ptr cs:[si].ne_csip+2 ; Get number of CS
  61. dec bx
  62. jl ksfail ; Error if no CS
  63. shl bx,1
  64. shl bx,1
  65. shl bx,1
  66. .errnz 8 - SIZE new_seg
  67. add bx,cs:[si].ne_segtab ; DS:BX -> seg. tab. entry for CS
  68. mov ax,cs:[si+bx].ns_sector ; Compute paragraph address of CS
  69. mov cx,cs:[si].ne_align ; Convert sectors to paragraphs
  70. sub cx,4
  71. shl ax,cl
  72. pop bx
  73. mov dx,cs ; Add to paragraph address of old
  74. sub dx,20h ; exe header
  75. add dx,ax
  76. push dx ; Push far address of start proc
  77. push word ptr cs:[si].ne_csip
  78. mov ds,di ; DS:0 points to automatic DS
  79. mov cx,si ; CX = file offset of new header
  80. add cx,200h
  81. jmp short ksgo
  82. org 0A0h
  83. ksgo:
  84. ;!!! The old CS selector should be freed up at some point!
  85. mov ax, "KO"
  86. ret ; FAR return to start proc
  87. ksfail:
  88. call ks1
  89. DB 'KERNSTUB: Error during boot',13,10,'$'
  90. ks1: pop dx
  91. push cs
  92. pop ds ; DS:DX -> error message
  93. mov ah,9 ; Print error message
  94. int 21h
  95. mov ax,4C01h ; Terminate program, exit code = 1
  96. int 21h
  97. KERNSTUB ENDP
  98. sEnd CODE
  99. END KERNSTUB