start:
cli # BIOS enabled interrupts; disable
+
+ mov $0x7E00, %eax
+ call do_e820
+
# Zero data segment registers DS, ES, and SS.
xorw %ax,%ax # Set %ax to zero
movw %ax,%ds # -> Data Segment
movw %ax, %gs # -> GS
# Set up the stack pointer and call into C.
+ # move the argument to di
+ movw %dx, %di
movl $start, %esp
call bootmain
static void readseg(uchar*, uint, uint);
void
-bootmain(void)
+bootmain(int krnlsz)
{
struct elfhdr *elf;
struct proghdr *ph, *eph;
- void (*entry)(void);
+ void (*entry)(int);
uchar* pa;
+
+
elf = (struct elfhdr*)0x10000; // scratch space
// Read 1st page off disk
// Call the entry point from the ELF header.
// Does not return!
- entry = (void(*)(void))(elf->entry);
- entry();
+ entry = (void(*)(int ))(elf->entry);
+ entry(krnlsz);
}
static void
/* should be really offset
* which is how many bytes away from fn start */
int lineno = 0;
- while (ebp != MAGIC_RETURN_ADDR) {
+ while (*((int *) ebp) != MAGIC_RETURN_ADDR) {
if (stab_info(get_ra(ebp), &si) == 0) {
/* do a strcpy like thing since not null
* terminated */
#include "string.h"
#include "stdio.h"
+#define E820_MEMORY_ADDR 0x7E00
+
static void startothers(void);
static void mpmain(void) __attribute__((noreturn));
extern pde_t *kpgdir;
extern char end[]; // first address after kernel loaded from ELF file
+#pragma pack(push, 1)
+struct e820_r {
+ unsigned long long pa;
+ unsigned long long length;
+ unsigned int type;
+ unsigned int unused;
+};
+#pragma pack(pop)
+
+
// Bootstrap processor starts running C code here.
// Allocate a real stack and switch to it, first
// doing some setup required for memory allocator to work.
int
main(void)
{
+ int num_e820_entries = *((int *) E820_MEMORY_ADDR);
+ unsigned long long max_addr = 0;
+ for (int i = 0; i < num_e820_entries; ++i) {
+ struct e820_r *e82;
+ e82 = ((struct e820_r *)((int *) E820_MEMORY_ADDR
+ + 1 + 6 * i));
+ if (e82->type == 1) {
+ if (e82-> pa + e82->length > max_addr) {
+ max_addr = e82->pa + e82->length;
+ }
+ }
+ }
+
+ if (max_addr > (DEVSPACE - KERNBASE)) {
+ max_addr = DEVSPACE - KERNBASE;
+ }
+
kinit1(end, P2V(4*1024*1024)); // phys page allocator
- kvmalloc(PHYSTOP); // kernel page table
+ // FIXME
+ kvmalloc(max_addr); // kernel page table
mpinit(); // detect other processors
lapicinit(); // interrupt controller
seginit(); // segment descriptors
fileinit(); // file table
ideinit(); // disk
startothers(); // start other processors
- kinit2(P2V(4*1024*1024), P2V(PHYSTOP), PHYSTOP); // must come after startothers()
+ kinit2(P2V(4*1024*1024), P2V((int) max_addr), max_addr); // must come after startothers()
userinit(); // first user process
mpmain(); // finish this processor's setup
}
#include "syscall.h"
#include "stdio.h"
-// FIXME
-#include "backtrace.h"
// User code makes a system call with INT T_SYSCALL.
// System call number in %eax.
// Arguments on the stack, from the user call to the C
int num;
struct proc *curproc = myproc();
- //FIXME
- backtrace();
+
num = curproc->tf->eax;
if(num > 0 && num < NELEM(syscalls) && syscalls[num]) {