Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
98 | cejka | 1 | /* |
2 | * Copyright (C) 2005 Josef Cejka |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * - The name of the author may not be used to endorse or promote products |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
95 | cejka | 28 | |
29 | |||
139 | cejka | 30 | #include <arch/boot/memmapasm.h> |
95 | cejka | 31 | |
98 | cejka | 32 | E820_SMAP = 0x534d4150 |
33 | |||
34 | .global memmap_arch_init |
||
139 | cejka | 35 | .global e801memorysize |
98 | cejka | 36 | |
37 | .code16 |
||
110 | jermar | 38 | .section K_TEXT_START_2 |
98 | cejka | 39 | |
95 | cejka | 40 | memmap_arch_init: |
139 | cejka | 41 | |
98 | cejka | 42 | e820begin: |
99 | jermar | 43 | xorl %ebx,%ebx # during first call, ebx must be 0 |
139 | cejka | 44 | movw %bx,%ds |
45 | movw %bx,%es |
||
243 | palkovsky | 46 | movw $e820table_boot,%di |
285 | decky | 47 | movb $MEMMAP_E820_MAX_RECORDS,e820counter_boot |
98 | cejka | 48 | e820loop: |
139 | cejka | 49 | movl $E820_SMAP,%edx # control sequence "SMAP" |
98 | cejka | 50 | |
139 | cejka | 51 | movl $0x0000e820,%eax # service |
285 | decky | 52 | movl $MEMMAP_E820_RECORD_SIZE,%ecx |
98 | cejka | 53 | int $0x15 |
139 | cejka | 54 | jc e820err |
98 | cejka | 55 | |
99 | jermar | 56 | cmpl $E820_SMAP,%eax # verifying BIOS |
139 | cejka | 57 | jne e820err |
58 | |||
285 | decky | 59 | cmpl $MEMMAP_E820_RECORD_SIZE,%ecx |
139 | cejka | 60 | jne e820err # bad record size - bug in bios |
98 | cejka | 61 | |
62 | movw %di,%ax # next record |
||
285 | decky | 63 | addw $MEMMAP_E820_RECORD_SIZE,%ax |
98 | cejka | 64 | movw %ax,%di |
65 | |||
243 | palkovsky | 66 | decb e820counter_boot # buffer is full |
101 | cejka | 67 | jz e820end |
98 | cejka | 68 | |
101 | cejka | 69 | cmpl $0,%ebx |
70 | jne e820loop |
||
71 | |||
98 | cejka | 72 | e820end: |
285 | decky | 73 | movb $MEMMAP_E820_MAX_RECORDS,%al |
243 | palkovsky | 74 | subb e820counter_boot,%al |
75 | movb %al,e820counter_boot # store # of valid entries in e820counter |
||
139 | cejka | 76 | |
77 | jmp e801begin |
||
78 | |||
79 | e820err: |
||
243 | palkovsky | 80 | movb $0,e820counter_boot |
139 | cejka | 81 | |
82 | # method e801 - get size of memory |
||
83 | |||
84 | e801begin: |
||
85 | xorw %dx,%dx |
||
86 | xorw %cx,%cx |
||
87 | xorw %bx,%bx |
||
88 | movw $0xe801,%ax |
||
89 | stc |
||
90 | int $0x15 |
||
98 | cejka | 91 | |
139 | cejka | 92 | jc e801end |
93 | |||
94 | # fix problem with some BIOSes which use ax:bx rather than cx:dx |
||
95 | testw %cx,%cx |
||
96 | jnz e801cxdx |
||
97 | testw %dx,%dx |
||
98 | jnz e801cxdx |
||
99 | |||
100 | movw %ax,%cx |
||
101 | movw %bx,%dx |
||
102 | |||
103 | e801cxdx: |
||
104 | andl $0xffff,%edx |
||
105 | shll $6,%edx |
||
106 | andl $0xffff,%ecx |
||
107 | addl %ecx,%edx |
||
149 | jermar | 108 | addl $0x0400,%edx # add lower 1 MB - it's not included by e801 method |
109 | movl %edx,e801memorysize |
||
139 | cejka | 110 | e801end: |
98 | cejka | 111 | ret |
112 | |||
139 | cejka | 113 | #memory size in 1 kb chunks |
114 | e801memorysize: |
||
115 | .long 0 |
||
264 | cejka | 116 |