2 ** Copyright 2002, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
5 #include "stage2_priv.h"
6 #include <boot/bootdir.h>
7 #include <boot/stage2.h>
10 static kernel_args ka
= { 0 };
12 #define BOOTDIR_ADDR 0x4381000
13 static const boot_entry
*bootdir
= (boot_entry
*)BOOTDIR_ADDR
;
15 int _start(char *boot_args
, char *monitor
);
16 int _start(char *boot_args
, char *monitor
)
18 unsigned int bootdir_pages
;
20 memset(&ka
, 0, sizeof(ka
));
22 init_nextmon(monitor
);
23 dprintf("\nNewOS stage2: args '%s', monitor %p\n", boot_args
, monitor
);
27 dprintf("tc 0x%x\n", get_tc());
28 dprintf("urp 0x%x\n", get_urp());
29 dprintf("srp 0x%x\n", get_srp());
31 // calculate how big the bootdir is
35 for (entry
= 0; entry
< BOOTDIR_MAX_ENTRIES
; entry
++) {
36 if (bootdir
[entry
].be_type
== BE_TYPE_NONE
)
39 bootdir_pages
+= bootdir
[entry
].be_size
;
41 ka
.bootdir_addr
.start
= (unsigned long)bootdir
;
42 ka
.bootdir_addr
.size
= bootdir_pages
* PAGE_SIZE
;
43 dprintf("bootdir: start %p, size 0x%x\n", (char *)ka
.bootdir_addr
.start
, ka
.bootdir_addr
.size
);
46 // begin to set up the physical page allocation range data structures
47 ka
.num_phys_alloc_ranges
= 1;
48 ka
.phys_alloc_range
[0].start
= ka
.bootdir_addr
.start
;
49 ka
.phys_alloc_range
[0].size
= ka
.bootdir_addr
.size
;
51 // allocate a stack for the kernel when we jump into it
52 ka
.cpu_kstack
[0].start
= allocate_page(&ka
);
53 ka
.cpu_kstack
[0].size
= PAGE_SIZE
;
60 unsigned long allocate_page(kernel_args
*ka
)
64 page
= ka
->phys_alloc_range
[0].start
+ ka
->phys_alloc_range
[0].size
;
65 ka
->phys_alloc_range
[0].size
+= PAGE_SIZE
;