Subversion Repositories Kolibri OS

Rev

Rev 7965 | Rev 7968 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7965 Rev 7967
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2020. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2020. 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: 7965 $
8
$Revision: 7967 $
9
 
9
 
10
 
10
 
Line 1516... Line 1516...
1516
        pop     esi
1516
        pop     esi
1517
.fail:
1517
.fail:
1518
        ret
1518
        ret
1519
endp
1519
endp
Line -... Line 1520...
-
 
1520
 
-
 
1521
 
-
 
1522
 
-
 
1523
proc    user_ring stdcall, size:dword
-
 
1524
 
-
 
1525
locals
-
 
1526
        virt_ptr        dd ?
-
 
1527
        phys_ptr        dd ?
-
 
1528
        num_pages       dd ?
-
 
1529
endl
-
 
1530
 
-
 
1531
; Size must be an exact multiple of pagesize
-
 
1532
        mov     eax, size
-
 
1533
        test    eax, PAGE_SIZE-1
-
 
1534
        jnz     .exit
-
 
1535
 
-
 
1536
; We must have at least one complete page
-
 
1537
        shr     eax, 12
-
 
1538
        jz      .exit
-
 
1539
        mov     [num_pages], eax
-
 
1540
 
-
 
1541
; Allocate double the virtual memory
-
 
1542
        mov     eax, [size]
-
 
1543
        shl     eax, 1
-
 
1544
        jz      .exit
-
 
1545
        stdcall user_alloc, eax
-
 
1546
        test    eax, eax
-
 
1547
        jz      .exit
-
 
1548
        mov     [virt_ptr], eax
-
 
1549
 
-
 
1550
; Now allocate physical memory
-
 
1551
        stdcall alloc_pages, [num_pages]
-
 
1552
        test    eax, eax
-
 
1553
        jz      .exit_free_virt
-
 
1554
        mov     [phys_ptr], eax
-
 
1555
 
-
 
1556
; Map first half of virtual memory to physical memory
-
 
1557
        push    ecx esi edi
-
 
1558
        mov     ecx, [num_pages]
-
 
1559
        mov     esi, [virt_ptr]
-
 
1560
        mov     edi, [phys_ptr]
-
 
1561
  .loop1:
-
 
1562
        stdcall map_page, esi, edi, PG_UWR
-
 
1563
        add     esi, PAGE_SIZE
-
 
1564
        add     edi, PAGE_SIZE
-
 
1565
        dec     ecx
-
 
1566
        jnz     .loop1
-
 
1567
 
-
 
1568
; Map second half of virtual memory to same physical memory
-
 
1569
        mov     ecx, [pages]
-
 
1570
        mov     edi, [phys_ptr]
-
 
1571
  .loop2:
-
 
1572
        stdcall map_page, esi, edi, PG_UWR
-
 
1573
        add     esi, PAGE_SIZE
-
 
1574
        add     edi, PAGE_SIZE
-
 
1575
        dec     ecx
-
 
1576
        jnz     .loop2
-
 
1577
        pop     edi esi ecx
-
 
1578
 
-
 
1579
        mov     eax, [virt_ptr]
-
 
1580
        ret
-
 
1581
 
-
 
1582
  .exit_free_virt:
-
 
1583
        stdcall user_free, [virt_ptr]
-
 
1584
 
-
 
1585
  .exit:
-
 
1586
        xor     eax, eax
-
 
1587
        ret
-
 
1588
 
1520
1589
endp