Leaked source code of windows server 2003
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.

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