Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. align 4
  2.  
  3. B32:
  4. ; CLEAR 0x280000-0xF00000
  5.  
  6.         xor   eax,eax
  7.         mov   edi,0x280000
  8.         mov   ecx,(0x100000*0xF-0x280000) / 4
  9.         cld
  10.         rep   stosd
  11. ; CLEAR 0x80000-0x90000
  12. ;       xor   eax,eax
  13.  
  14.         mov   edi,0x80000
  15.         mov   ecx,(0x90000-0x80000)/4
  16. ;       cld
  17.         rep   stosd
  18.  
  19. ; CLEAR KERNEL UNDEFINED GLOBALS
  20.         mov   edi, endofcode
  21.         mov   ecx, (uglobals_size/4)+4
  22.         rep   stosd
  23.  
  24. ; SAVE & CLEAR 0-0xffff
  25.  
  26.         mov   esi,0x0000
  27.         mov   edi,0x2F0000
  28.         mov   ecx,0x10000 / 4
  29.         cld
  30.         rep   movsd
  31.         xor   eax,eax
  32.         mov   edi,0
  33.         mov   ecx,0x10000 / 4
  34.         cld
  35.         rep   stosd
  36.  
  37. ; SAVE REAL MODE VARIABLES
  38.         mov     ax, [0x2f0000 + 0x9031]
  39.         mov     [IDEContrRegsBaseAddr], ax
  40. ; --------------- APM ---------------------
  41.     mov    eax, [0x2f0000 + 0x9040]    ; entry point
  42.     mov    dword[apm_entry], eax
  43.     mov    word [apm_entry + 4], apm_code_32 - gdts
  44.  
  45.     mov    eax, [0x2f0000 + 0x9044]    ; version & flags
  46.     mov    [apm_vf], eax
  47. ; -----------------------------------------
  48. ;        movzx eax,byte [0x2f0000+0x9010]  ; mouse port
  49. ;        mov   [0xF604],byte 1  ;al
  50.         mov     al, [0x2F0000+0x901F]   ; DMA writing
  51.         mov     [allow_dma_write], al
  52.         mov   al,[0x2f0000+0x9000]        ; bpp
  53.         mov   [ScreenBPP],al
  54.         movzx eax,word [0x2f0000+0x900A]  ; X max
  55.         dec   eax
  56.         mov   [ScreenWidth],eax
  57.         mov   [screen_workarea.right],eax
  58.         movzx eax,word [0x2f0000+0x900C]  ; Y max
  59.         dec   eax
  60.         mov   [ScreenHeight],eax
  61.         mov   [screen_workarea.bottom],eax
  62.         movzx eax,word [0x2f0000+0x9008]  ; screen mode
  63.         mov   [SCR_MODE],eax
  64.         mov   eax,[0x2f0000+0x9014]       ; Vesa 1.2 bnk sw add
  65.         mov   [BANK_SWITCH],eax
  66.         mov   [BytesPerScanLine],word 640*4         ; Bytes PerScanLine
  67.         cmp   [SCR_MODE],word 0x13          ; 320x200
  68.         je    @f
  69.         cmp   [SCR_MODE],word 0x12          ; VGA 640x480
  70.         je    @f
  71.         mov   ax,[0x2f0000+0x9001]        ; for other modes
  72.         mov   [BytesPerScanLine],ax
  73.       @@:
  74.  
  75. ; GRAPHICS ADDRESSES
  76.  
  77.         ;mov     eax,0x100000*8                    ; LFB address
  78.         ;cmp     [0xfe0c],word 0x13
  79.         ;je      no_d_lfb
  80.         ;cmp     [0xfe0c],word 0x12
  81.         ;je      no_d_lfb
  82.         ;cmp     [0x2f0000+0x901e],byte 1
  83.         ;jne     no_d_lfb
  84.         mov     byte [0x2f0000+0x901e],0x0
  85.         mov     eax,[0x2f0000+0x9018]
  86.       ;no_d_lfb:
  87.         mov     [LFBAddress],eax
  88.  
  89.         cmp     [SCR_MODE],word 0100000000000000b
  90.         jge     setvesa20
  91.         cmp     [SCR_MODE],word 0x13
  92.         je      v20ga32
  93.         mov     [PUTPIXEL],dword Vesa12_putpixel24  ; Vesa 1.2
  94.         mov     [0xe024],dword Vesa12_getpixel24
  95.         cmp     [ScreenBPP],byte 24
  96.         jz      ga24
  97.         mov     [PUTPIXEL],dword Vesa12_putpixel32
  98.         mov     [0xe024],dword Vesa12_getpixel32
  99.       ga24:
  100.         jmp     v20ga24
  101.       setvesa20:
  102.         mov     [PUTPIXEL],dword Vesa20_putpixel24  ; Vesa 2.0
  103.         mov     [0xe024],dword Vesa20_getpixel24
  104.         cmp     [ScreenBPP],byte 24
  105.         jz      v20ga24
  106.       v20ga32:
  107.         mov     [PUTPIXEL],dword Vesa20_putpixel32
  108.         mov     [0xe024],dword Vesa20_getpixel32
  109.       v20ga24:
  110.         cmp     [SCR_MODE],word 0x12                ; 16 C VGA 640x480
  111.         jne     no_mode_0x12
  112.         mov     [PUTPIXEL],dword VGA_putpixel
  113.         mov     [0xe024],dword Vesa20_getpixel32
  114.       no_mode_0x12:
  115.  
  116.            call test_cpu
  117. ;           btr [cpu_caps], CAPS_SSE    ;test: dont't use sse code
  118. ;           btr [cpu_caps], CAPS_SSE2   ;test: don't use sse2
  119.  
  120. ;           btr [cpu_caps], CAPS_FXSR   ;test: disable sse support
  121.                                         ;all sse commands rise #UD exption
  122. ;           btr [cpu_caps], CAPS_PSE    ;test: don't use large pages
  123. ;           btr [cpu_caps], CAPS_PGE    ;test: don't use global pages
  124. ;           btr [cpu_caps], CAPS_MTRR   ;test: don't use MTRR
  125.            bts [cpu_caps], CAPS_TSC     ;force use rdtsc
  126.  
  127. ; -------- Fast System Call init ----------
  128. ; Intel SYSENTER/SYSEXIT (AMD CPU support it too)
  129.            bt [cpu_caps], CAPS_SEP
  130.            jnc .SEnP   ; SysEnter not Present
  131.            xor edx, edx
  132.            mov ecx, MSR_SYSENTER_CS
  133.            mov eax, os_code
  134.            wrmsr
  135.            mov ecx, MSR_SYSENTER_ESP
  136. ;           mov eax, sysenter_stack ; Check it
  137.            xor     eax, eax
  138.            wrmsr
  139.            mov ecx, MSR_SYSENTER_EIP
  140.            mov eax, sysenter_entry
  141.            wrmsr
  142. .SEnP:
  143. ; AMD SYSCALL/SYSRET
  144.            cmp byte[cpu_vendor], 'A'
  145.            jne .noSYSCALL
  146.            mov eax, 0x80000001
  147.            cpuid
  148.            test edx, 0x800  ; bit_11 - SYSCALL/SYSRET support
  149.            jz .noSYSCALL
  150.            mov ecx, MSR_AMD_EFER
  151.            rdmsr
  152.            or eax, 1   ; bit_0 - System Call Extension (SCE)
  153.            wrmsr
  154.  
  155.         ; !!!! It`s dirty hack, fix it !!!
  156.         ; Bits of EDX :
  157.         ; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register
  158.         ;  and the contents of this field, plus 8, are copied into the SS register.
  159.         ; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register
  160.         ;  and the contents of this field, plus 8, are copied into the SS register.
  161.  
  162.         ; mov   edx, (os_code + 16) * 65536 + os_code
  163.            mov edx, 0x1B0013
  164.  
  165.            mov eax, syscall_entry
  166.            mov ecx, MSR_AMD_STAR
  167.            wrmsr
  168. .noSYSCALL:
  169. ; -----------------------------------------
  170.  
  171.  
  172.  
  173. ; MEMORY MODEL
  174.            call mem_test
  175.            call init_mtrr
  176.            call init_mem
  177.            call init_page_map
  178.  
  179. ; ENABLE PAGING
  180.            mov eax, sys_pgdir
  181.            mov cr3, eax
  182.  
  183.            mov eax,cr0
  184.            or eax,CR0_PG
  185.            mov cr0,eax
  186.  
  187.            call init_kernel_heap
  188.            stdcall kernel_alloc, RING0_STACK_SIZE+512
  189.            mov [os_stack], eax
  190.  
  191.            call init_LFB
  192.            call init_fpu
  193.  
  194.            call init_malloc
  195.  
  196.            stdcall alloc_kernel_space, 0x4F000
  197.            mov [ipc_tmp], eax
  198.            mov ebx, 0x1000
  199.  
  200.            add eax, 0x40000
  201.            mov [proc_mem_map], eax
  202.  
  203.            add eax, 0x8000
  204.            mov [proc_mem_pdir], eax
  205.  
  206.            add eax, ebx
  207.            mov [proc_mem_tab], eax
  208.  
  209.            add eax, ebx
  210.            mov [tmp_task_pdir], eax
  211.  
  212.            add eax, ebx
  213.            mov [tmp_task_ptab], eax
  214.  
  215.            add eax, ebx
  216.            mov [ipc_pdir], eax
  217.  
  218.            add eax, ebx
  219.            mov [ipc_ptab], eax
  220.  
  221.            call init_events
  222.  
  223.            mov eax, srv.fd-SRV_FD_OFFSET
  224.            mov [srv.fd], eax
  225.            mov [srv.bk], eax
  226.  
  227.            mov edi, irq_tab
  228.            xor eax, eax
  229.            mov ecx, 16
  230.            rep stosd
  231.  
  232. ;Set base of graphic segment to linear address of LFB
  233.         mov     eax,[LFBAddress]          ; set for gs
  234.         mov     [graph_data_l+2],ax
  235.         shr     eax,16
  236.         mov     [graph_data_l+4],al
  237.         mov     [graph_data_l+7],ah
  238.  
  239.  
  240. ; BUILD SCHEDULER
  241.  
  242.         call   build_scheduler ; sys32.inc
  243.  
  244. ; LOAD IDT
  245.         lidt   [cs:idtreg]
  246.         cli
  247.  
  248. ;!!!!!!!!!!!!!!!!!!!!!!!!!!
  249. include 'detect/disks.inc'
  250. ;!!!!!!!!!!!!!!!!!!!!!!!!!!
  251.  
  252. ; READ RAMDISK IMAGE FROM HD
  253.  
  254. ;!!!!!!!!!!!!!!!!!!!!!!!
  255. ;include 'rdload.inc'
  256. ;!!!!!!!!!!!!!!!!!!!!!!!
  257. ;    mov    [dma_hdd],1
  258. ; CALCULATE FAT CHAIN FOR RAMDISK
  259.  
  260.         call  calculatefatchain
  261.  
  262. ; LOAD VMODE DRIVER
  263.  
  264. ;!!!!!!!!!!!!!!!!!!!!!!!
  265. include 'vmodeld.inc'
  266. ;!!!!!!!!!!!!!!!!!!!!!!!
  267.  
  268. ; LOAD FONTS I and II
  269.  
  270.         mov   [CURRENT_TASK],dword 1
  271.         mov   [TASK_COUNT],dword 1
  272.         mov   [TASK_BASE],dword TASK_DATA
  273.  
  274.         pushad
  275.         push    eax
  276.         mov             eax,char  - std_application_base_address
  277.         call    file_system_lfn
  278.         mov             eax,char2  - std_application_base_address
  279.         call    file_system_lfn
  280.         pop     eax
  281.         popad
  282.  
  283.  
  284. ;        mov   esi,char
  285. ;        xor   ebx,ebx
  286. ;        mov   ecx,2560;26000
  287. ;        mov   edx,FONT_I
  288. ;        call  fs_RamdiskRead
  289.  
  290. ;        mov   esi,char2
  291. ;        xor   ebx,ebx
  292. ;        mov   ecx,2560;26000
  293. ;        mov   edx,FONT_II
  294. ;        call  fs_RamdiskRead
  295.  
  296.         mov   esi,boot_fonts
  297.         call  boot_log
  298.  
  299. ; PRINT AMOUNT OF MEMORY
  300.         mov     esi, boot_memdetect
  301.         call    boot_log
  302.  
  303.         movzx   ecx, word [boot_y]
  304.         or      ecx, (10+29*6) shl 16 ; "Determining amount of memory"
  305.         sub     ecx, 10
  306.         mov     edx, 0xFFFFFF
  307.         mov     ebx, [MEM_AMOUNT]
  308.         shr     ebx, 20
  309.         mov     edi, 1
  310.         mov     eax, 0x00040000
  311.         call    display_number_force
  312.  
  313. ; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
  314.  
  315.         mov   esi,boot_irqs
  316.         call  boot_log
  317.         call  rerouteirqs
  318.  
  319.         mov    esi,boot_tss
  320.         call   boot_log
  321.  
  322.         mov    esi,boot_devices
  323.         call   boot_log
  324.         call   detect_devices
  325.  
  326.  ; TIMER SET TO 1/100 S
  327.  
  328.         mov   esi,boot_timer
  329.         call  boot_log
  330.         mov   al,0x34              ; set to 100Hz
  331.         out   0x43,al
  332.         mov   al,0x9b              ; lsb    1193180 / 1193
  333.         out   0x40,al
  334.         mov   al,0x2e              ; msb
  335.         out   0x40,al
  336.  
  337. ; SET MOUSE
  338.  
  339.         mov   esi,boot_setmouse
  340.         call  boot_log
  341.         call  setmouse
  342.  
  343.         mov  [pci_access_enabled],1
  344.  
  345. ; SET PRELIMINARY WINDOW STACK AND POSITIONS
  346.  
  347.         mov   esi,boot_windefs
  348.         call  boot_log
  349.         call  setwindowdefaults
  350.  
  351. ; SET BACKGROUND DEFAULTS
  352.  
  353.         mov   esi,boot_bgr
  354.         call  boot_log
  355.         call  calculatebackground
  356.  
  357. ; RESERVE SYSTEM IRQ'S JA PORT'S
  358.  
  359.         mov   esi,boot_resirqports
  360.         call  boot_log
  361.         call  reserve_irqs_ports
  362.  
  363. ; SET PORTS FOR IRQ HANDLERS
  364.  
  365.         mov  esi,boot_setrports
  366.         call boot_log
  367.         call setirqreadports
  368.  
  369. ; SET UP OS TASK
  370.  
  371.         mov  esi,boot_setostask
  372.         call boot_log
  373.  
  374. ;        mov eax, fpu_data
  375. ;        mov  dword [SLOT_BASE+APPDATA.fpu_state], eax
  376. ;        mov  dword [SLOT_BASE+APPDATA.fpu_handler], 0
  377. ;        mov  dword [SLOT_BASE+APPDATA.sse_handler], 0
  378.  
  379.         ; name for OS/IDLE process
  380.  
  381.         mov dword [SLOT_BASE+256+APPDATA.app_name],   dword 'OS/I'
  382.         mov dword [SLOT_BASE+256+APPDATA.app_name+4], dword 'DLE '
  383.         mov edi, [os_stack]
  384.         mov dword [SLOT_BASE+256+APPDATA.pl0_stack], edi
  385.         add edi, RING0_STACK_SIZE
  386.         mov dword [SLOT_BASE+256+APPDATA.fpu_state], edi
  387.  
  388.         mov esi, fpu_data
  389.         mov ecx, 512/4
  390.         cld
  391.         rep movsd
  392.  
  393.         mov dword [SLOT_BASE+256+APPDATA.fpu_handler], 0
  394.         mov dword [SLOT_BASE+256+APPDATA.sse_handler], 0
  395.  
  396.         mov ebx, [def_cursor]
  397.         mov dword [SLOT_BASE+256+APPDATA.cursor], ebx
  398.  
  399.         mov ebx, SLOT_BASE+256+APP_OBJ_OFFSET
  400.         mov  dword [SLOT_BASE+256+APPDATA.fd_obj], ebx
  401.         mov  dword [SLOT_BASE+256+APPDATA.bk_obj], ebx
  402.  
  403.         ; task list
  404.         mov  [TASK_DATA+TASKDATA.wnd_number], 1 ; on screen number
  405.         mov  [TASK_DATA+TASKDATA.pid], 1        ; process id number
  406.         mov  [TASK_DATA+TASKDATA.mem_start], 0  ; process base address
  407.  
  408.         mov  edi,tss_data+tss_step
  409.         mov ecx, (tss_step)/4
  410.         xor eax, eax
  411.         cld
  412.         rep stosd
  413.  
  414.         mov  edi,tss_data+tss_step
  415.         mov  [edi+TSS._ss0], os_data
  416.         mov  eax,cr3
  417.         mov  [edi+TSS._cr3],eax
  418.         mov  [edi+TSS._eip],osloop
  419.         mov  [edi+TSS._eflags],dword 0x11202 ; sti and resume
  420.         mov eax, [os_stack]
  421.         add eax, RING0_STACK_SIZE
  422.         mov  [edi+TSS._esp], eax
  423.         mov  [edi+TSS._cs],os_code
  424.         mov  [edi+TSS._ss],os_data
  425.         mov  [edi+TSS._ds],os_data
  426.         mov  [edi+TSS._es],os_data
  427.         mov  [edi+TSS._fs],os_data
  428.         mov  [edi+TSS._gs],os_data
  429.  
  430.         mov  ax,tss0
  431.         ltr  ax
  432.  
  433.         call init_cursors
  434.  
  435.  
  436. ; READ TSC / SECOND
  437.  
  438.         mov   esi,boot_tsc
  439.         call  boot_log
  440.         call  _rdtsc
  441.         mov   ecx,eax
  442.         mov   esi,250               ; wait 1/4 a second
  443.         call  delay_ms
  444.         call  _rdtsc
  445.         sub   eax,ecx
  446.         shl   eax,2
  447.         mov   [CPU_FREQ],eax          ; save tsc / sec
  448.         mov ebx, 1000000
  449.         div ebx
  450.         mov [stall_mcs], eax
  451.  
  452. ; SET VARIABLES
  453.  
  454.         call  set_variables
  455.  
  456. ; STACK AND FDC
  457.  
  458.         call  stack_init
  459.         call  fdc_init
  460.  
  461. ; PALETTE FOR 320x200 and 640x480 16 col
  462.  
  463.         cmp   [SCR_MODE],word 0x12
  464.         jne   no_pal_vga
  465.         mov   esi,boot_pal_vga
  466.         call  boot_log
  467.         call  paletteVGA
  468.       no_pal_vga:
  469.  
  470.         cmp   [SCR_MODE],word 0x13
  471.         jne   no_pal_ega
  472.         mov   esi,boot_pal_ega
  473.         call  boot_log
  474.         call  palette320x200
  475.       no_pal_ega:
  476.  
  477. ; LOAD DEFAULT SKIN
  478.  
  479.         mov     esi,_skin_file_default
  480.         mov     edi,_skin_file
  481.         movsd
  482.         movsd
  483.         movsd
  484.         call    load_skin
  485.  
  486. ; LOAD FIRST APPLICATION
  487.         mov   [CURRENT_TASK],dword 1
  488.         mov   [TASK_COUNT],dword 1
  489.         cli
  490.         cmp   byte [0x2f0000+0x9030],1
  491.         jne   no_load_vrr_m
  492.  
  493.         mov ebp, vrr_m
  494.         xor ebx, ebx
  495.         xor edx, edx
  496.         call fs_execute
  497.         cmp   eax,2                  ; if vrr_m app found (PID=2)
  498.         je    first_app_found
  499.  
  500. no_load_vrr_m:
  501.         mov ebp, firstapp
  502.         xor ebx, ebx
  503.         xor edx, edx
  504.         call fs_execute
  505.         cmp   eax,2                  ; continue if a process has been loaded
  506.         je    first_app_found
  507.         mov   eax, 0xDEADBEEF        ; otherwise halt
  508.         hlt
  509. first_app_found:
  510.         cli
  511.  
  512.         ;mov   [TASK_COUNT],dword 2
  513.         mov   [CURRENT_TASK],dword 1       ; set OS task fisrt
  514.  
  515.  
  516. ; SET KEYBOARD PARAMETERS
  517.         mov   al, 0xf6         ; reset keyboard, scan enabled
  518.         call  kb_write
  519.  
  520.         ; wait until 8042 is ready
  521.         xor ecx,ecx
  522.       @@:
  523.         in     al,64h
  524.         and    al,00000010b
  525.         loopnz @b
  526.  
  527.        ; mov   al, 0xED       ; svetodiody - only for testing!
  528.        ; call  kb_write
  529.        ; call  kb_read
  530.        ; mov   al, 111b
  531.        ; call  kb_write
  532.        ; call  kb_read
  533.  
  534.         mov   al, 0xF3       ; set repeat rate & delay
  535.         call  kb_write
  536. ;        call  kb_read
  537.         mov   al, 0 ; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
  538.         call  kb_write
  539. ;        call  kb_read
  540.      ;// mike.dld [
  541.         call  set_lights
  542.      ;// mike.dld ]
  543.  
  544. ; START MULTITASKING
  545.  
  546.         mov   esi,boot_tasking
  547.         call  boot_log
  548.  
  549.  ;      mov   [ENABLE_TASKSWITCH],byte 1        ; multitasking enabled
  550.  
  551. ; UNMASK ALL IRQ'S
  552.  
  553.         mov   esi,boot_allirqs
  554.         call  boot_log
  555.  
  556.         cli                          ;guarantee forbidance of interrupts.
  557.         mov   al,0                   ; unmask all irq's
  558.         out   0xA1,al
  559.         out   0x21,al
  560.  
  561.         mov   ecx,32
  562.  
  563.      ready_for_irqs:
  564.  
  565.         mov   al,0x20                ; ready for irqs
  566.         out   0x20,al
  567.         out   0xa0,al
  568.  
  569.         loop  ready_for_irqs         ; flush the queue
  570.  
  571.         stdcall attach_int_handler, dword 1, irq1
  572.  
  573. ;        mov    [dma_hdd],1
  574.         cmp     [IDEContrRegsBaseAddr], 0
  575.         setnz   [dma_hdd]
  576.  
  577.         sti
  578.         jmp   $                      ; wait here for timer to take control
  579.  
  580.         ; Fly :)
  581.  
  582.  
  583.