Subversion Repositories HelenOS-historic

Rev

Rev 139 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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