2 ** Copyright 2001-2004, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
8 #include <boot/stage2.h>
9 #include <boot/bootdir.h>
13 // needed for console stuff
14 static unsigned short *kScreenBase
= (unsigned short*) 0xb8000;
15 static unsigned screenOffset
= 0;
16 static unsigned int line
= 0;
18 #define SCREEN_WIDTH 80
19 #define SCREEN_HEIGHT 25
20 #define PAGE_SIZE 4096
22 static unsigned char *heap_ptr
= (unsigned char *)0x1000000;
25 #define TARGET ((void *)0x400000)
27 void _start(unsigned int mem
, void *ext_mem_block
, int ext_mem_count
, int in_vesa
, unsigned int vesa_ptr
)
30 boot_dir
*bootdir
= TARGET
;
31 void (*stage2_entry
)(unsigned int mem
, void *ext_mem_block
, int ext_mem_count
, int in_vesa
, unsigned int vesa_ptr
, int console_ptr
);
35 dprintf("stage1 boot, decompressing system");
37 len
= gunzip((unsigned char const *)&_end
, TARGET
, kmalloc(32*1024));
38 dprintf("done, len %d\n", len
);
40 dprintf("finding stage2...");
41 stage2_entry
= (void*)((char *)bootdir
+ bootdir
->bd_entry
[1].be_offset
* PAGE_SIZE
+ bootdir
->bd_entry
[1].be_code_ventr
);
42 dprintf("entry at %p\n", stage2_entry
);
45 stage2_entry(mem
, ext_mem_block
, ext_mem_count
, in_vesa
, vesa_ptr
, screenOffset
);
48 void *kmalloc(unsigned int size
)
50 // dprintf("kmalloc: size %d, ptr %p\n", size, heap_ptr - size);
52 return (heap_ptr
-= size
);
63 for(i
=0; i
< SCREEN_WIDTH
*SCREEN_HEIGHT
*2; i
++) {
64 kScreenBase
[i
] = 0xf20;
71 memcpy(kScreenBase
, kScreenBase
+ SCREEN_WIDTH
,
72 SCREEN_WIDTH
* SCREEN_HEIGHT
* 2 - SCREEN_WIDTH
* 2);
73 screenOffset
= (SCREEN_HEIGHT
- 1) * SCREEN_WIDTH
;
74 for(i
=0; i
<SCREEN_WIDTH
; i
++)
75 kScreenBase
[screenOffset
+ i
] = 0x0720;
76 line
= SCREEN_HEIGHT
- 1;
79 void puts(const char *str
)
84 if(line
> SCREEN_HEIGHT
- 1)
87 screenOffset
+= SCREEN_WIDTH
- (screenOffset
% 80);
89 kScreenBase
[screenOffset
++] = 0xf00 | *str
;
91 if (screenOffset
>= SCREEN_WIDTH
* SCREEN_HEIGHT
)
98 int dprintf(const char *fmt
, ...)
105 ret
= vsprintf(temp
,fmt
,args
);
113 int panic(const char *fmt
, ...)
120 ret
= vsprintf(temp
,fmt
,args
);
123 puts("STAGE1 PANIC: ");
127 puts("spinning forever...");