Rev 597 | Rev 725 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 597 | Rev 709 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 7... | Line 7... | ||
7 | 7 | ||
Line 8... | Line 8... | ||
8 | $Revision: 597 $ |
8 | $Revision: 709 $ |
9 | 9 | ||
- | 10 | ||
Line 10... | Line 11... | ||
10 | 11 | ; Low-level driver for HDD access |
|
11 | ; Low-level driver for HDD access |
12 | ; DMA support by Mario79 |
12 | ; DMA support by Mario79 |
13 | ; Access through BIOS by diamond |
13 | 14 | ||
Line 43... | Line 44... | ||
43 | jnz hdreadcache |
44 | jnz hdreadcache |
Line 44... | Line 45... | ||
44 | 45 | ||
45 | call find_empty_slot ; ret in edi |
46 | call find_empty_slot ; ret in edi |
46 | cmp [hd_error],0 |
47 | cmp [hd_error],0 |
- | 48 | jne return_01 |
|
- | 49 | ; Read through BIOS? |
|
- | 50 | cmp [hdpos], 0x80 |
|
47 | jne return_01 |
51 | jae .bios |
48 | ; DMA read is permitted if [allow_dma_access]=1 or 2 |
52 | ; DMA read is permitted if [allow_dma_access]=1 or 2 |
49 | cmp [allow_dma_access], 2 |
53 | cmp [allow_dma_access], 2 |
50 | ja .nodma |
54 | ja .nodma |
51 | cmp [dma_hdd], 1 |
55 | cmp [dma_hdd], 1 |
52 | jnz .nodma |
56 | jnz .nodma |
53 | call hd_read_dma |
57 | call hd_read_dma |
54 | jmp @f |
58 | jmp @f |
55 | .nodma: |
59 | .nodma: |
- | 60 | call hd_read_pio |
|
- | 61 | jmp @f |
|
- | 62 | .bios: |
|
56 | call hd_read_pio |
63 | call bd_read |
57 | @@: |
64 | @@: |
58 | ; lea esi,[edi*8+HD_CACHE] |
65 | ; lea esi,[edi*8+HD_CACHE] |
59 | ; push eax |
66 | ; push eax |
60 | call calculate_cache_1 |
67 | call calculate_cache_1 |
Line 673... | Line 680... | ||
673 | align 4 |
680 | align 4 |
674 | write_cache_sector: |
681 | write_cache_sector: |
675 | mov [cache_chain_size],1 |
682 | mov [cache_chain_size],1 |
676 | mov [cache_chain_pos],edi |
683 | mov [cache_chain_pos],edi |
677 | write_cache_chain: |
684 | write_cache_chain: |
- | 685 | cmp [hdpos], 0x80 |
|
- | 686 | jae bd_write_cache_chain |
|
678 | push esi |
687 | push esi |
679 | mov eax, IDE_descriptor_table |
688 | mov eax, IDE_descriptor_table |
680 | mov edx,eax |
689 | mov edx,eax |
681 | pusha |
690 | pusha |
682 | mov esi,[cache_chain_pos] |
691 | mov esi,[cache_chain_pos] |
Line 771... | Line 780... | ||
771 | 780 | ||
772 | uglobal |
781 | uglobal |
773 | IDEContrRegsBaseAddr dw ? |
782 | IDEContrRegsBaseAddr dw ? |
774 | endg |
783 | endg |
- | 784 | ; \end{Mario79} |
|
- | 785 | ||
- | 786 | ; \begin{diamond} |
|
- | 787 | uglobal |
|
- | 788 | bios_hdpos dd 0 ; 0 is invalid value for [hdpos] |
|
- | 789 | bios_cur_sector dd ? |
|
- | 790 | bios_read_len dd ? |
|
- | 791 | endg |
|
- | 792 | bd_read: |
|
- | 793 | push eax |
|
- | 794 | push edx |
|
- | 795 | mov edx, [bios_hdpos] |
|
- | 796 | cmp edx, [hdpos] |
|
- | 797 | jne .notread |
|
- | 798 | mov edx, [bios_cur_sector] |
|
- | 799 | cmp eax, edx |
|
- | 800 | jb .notread |
|
- | 801 | add edx, [bios_read_len] |
|
- | 802 | dec edx |
|
- | 803 | cmp eax, edx |
|
- | 804 | ja .notread |
|
- | 805 | sub eax, [bios_cur_sector] |
|
- | 806 | shl eax, 9 |
|
- | 807 | add eax, (OS_BASE+0x9C000) |
|
- | 808 | push ecx esi edi |
|
- | 809 | mov esi, eax |
|
- | 810 | shl edi, 9 |
|
- | 811 | ; add edi, HD_CACHE+0x10000 |
|
- | 812 | push eax |
|
- | 813 | call calculate_cache_2 |
|
- | 814 | add edi,eax |
|
- | 815 | pop eax |
|
- | 816 | ||
- | 817 | mov ecx, 512/4 |
|
- | 818 | cld |
|
- | 819 | rep movsd |
|
- | 820 | pop edi esi ecx |
|
- | 821 | pop edx |
|
- | 822 | pop eax |
|
- | 823 | ret |
|
- | 824 | .notread: |
|
- | 825 | push ecx |
|
- | 826 | mov dl, 42h |
|
- | 827 | mov ecx, 16 |
|
- | 828 | call int13_call |
|
- | 829 | pop ecx |
|
- | 830 | test eax, eax |
|
- | 831 | jnz .v86err |
|
- | 832 | test edx, edx |
|
- | 833 | jz .readerr |
|
- | 834 | mov [bios_read_len], edx |
|
- | 835 | mov edx, [hdpos] |
|
- | 836 | mov [bios_hdpos], edx |
|
- | 837 | pop edx |
|
- | 838 | pop eax |
|
- | 839 | mov [bios_cur_sector], eax |
|
- | 840 | jmp bd_read |
|
- | 841 | .readerr: |
|
- | 842 | .v86err: |
|
- | 843 | mov [hd_error], 1 |
|
- | 844 | jmp hd_read_error |
|
- | 845 | ||
- | 846 | bd_write_cache_chain: |
|
- | 847 | pusha |
|
- | 848 | mov esi, [cache_chain_pos] |
|
- | 849 | shl esi, 9 |
|
- | 850 | call calculate_cache_2 |
|
- | 851 | add esi, eax |
|
- | 852 | mov edi, OS_BASE + 0x9C000 |
|
- | 853 | movzx ecx, [cache_chain_size] |
|
- | 854 | push ecx |
|
- | 855 | shl ecx, 9-2 |
|
- | 856 | rep movsd |
|
- | 857 | pop ecx |
|
- | 858 | mov dl, 43h |
|
- | 859 | mov eax, [cache_chain_ptr] |
|
- | 860 | mov eax, [eax] |
|
- | 861 | call int13_call |
|
- | 862 | test eax, eax |
|
- | 863 | jnz .v86err |
|
- | 864 | cmp edx, ecx |
|
- | 865 | jnz .writeerr |
|
- | 866 | popa |
|
- | 867 | ret |
|
- | 868 | .v86err: |
|
- | 869 | .writeerr: |
|
- | 870 | popa |
|
- | 871 | mov [hd_error], 1 |
|
- | 872 | jmp hd_write_error |
|
- | 873 | ||
- | 874 | uglobal |
|
- | 875 | int13_regs_in rb v86_regs.size |
|
- | 876 | int13_regs_out rb v86_regs.size |
|
- | 877 | endg |
|
- | 878 | ||
- | 879 | int13_call: |
|
- | 880 | ; Because this code uses fixed addresses, |
|
- | 881 | ; it can not be run simultaniously by many threads. |
|
- | 882 | ; In current implementation it is protected by common mutex 'hd1_status' |
|
- | 883 | mov word [BOOT_VAR + 510h], 10h ; packet length |
|
- | 884 | mov word [BOOT_VAR + 512h], cx ; number of sectors |
|
- | 885 | mov dword [BOOT_VAR + 514h], 9C000000h ; buffer 9C00:0000 |
|
- | 886 | mov dword [BOOT_VAR + 518h], eax |
|
- | 887 | and dword [BOOT_VAR + 51Ch], 0 |
|
- | 888 | push ebx ecx esi edi |
|
- | 889 | mov ebx, int13_regs_in |
|
- | 890 | mov edi, ebx |
|
- | 891 | mov ecx, v86_regs.size/4 |
|
- | 892 | xor eax, eax |
|
- | 893 | rep stosd |
|
- | 894 | mov byte [ebx+v86_regs.eax+1], dl |
|
- | 895 | mov eax, [hdpos] |
|
- | 896 | lea eax, [BiosDisksData+(eax-80h)*4] |
|
- | 897 | mov dl, [eax] |
|
- | 898 | mov byte [ebx+v86_regs.edx], dl |
|
- | 899 | movzx edx, byte [eax+1] |
|
- | 900 | ; mov dl, 5 |
|
- | 901 | test edx, edx |
|
- | 902 | jnz .hasirq |
|
- | 903 | dec edx |
|
- | 904 | jmp @f |
|
- | 905 | .hasirq: |
|
- | 906 | pushad |
|
- | 907 | stdcall enable_irq, edx |
|
- | 908 | popad |
|
- | 909 | @@: |
|
- | 910 | mov word [ebx+v86_regs.esi], 510h |
|
- | 911 | mov word [ebx+v86_regs.esp], 900h |
|
- | 912 | mov word [ebx+v86_regs.eip], 500h |
|
- | 913 | mov [ebx+v86_regs.eflags], 20200h |
|
- | 914 | mov esi, [sys_v86_machine] |
|
- | 915 | mov ecx, 0x502 |
|
- | 916 | call v86_start |
|
- | 917 | and [bios_hdpos], 0 |
|
- | 918 | pop edi esi ecx ebx |
|
- | 919 | movzx edx, byte [BOOT_VAR + 512h] |
|
- | 920 | test byte [int13_regs_out+v86_regs.eflags], 1 |
|
- | 921 | jnz @f |
|
- | 922 | mov edx, ecx |
|
- | 923 | @@: |
|
- | 924 | ret |