From: Advaith Menon Date: Tue, 3 Feb 2026 15:36:41 +0000 (+0530) Subject: finish lab 1 X-Git-Url: https://git.devinivas.org/?a=commitdiff_plain;ds=sidebyside;p=cs3210-lab1.git finish lab 1 --- diff --git a/bootblock/bootasm.S b/bootblock/bootasm.S index 120296f..707dc53 100644 --- a/bootblock/bootasm.S +++ b/bootblock/bootasm.S @@ -12,6 +12,10 @@ 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 @@ -62,6 +66,8 @@ start32: 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 diff --git a/bootblock/bootmain.c b/bootblock/bootmain.c index d3c2bde..173b765 100644 --- a/bootblock/bootmain.c +++ b/bootblock/bootmain.c @@ -15,13 +15,15 @@ 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 @@ -43,8 +45,8 @@ bootmain(void) // 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 diff --git a/kernel/src/backtrace.c b/kernel/src/backtrace.c index b93a2be..7daef38 100644 --- a/kernel/src/backtrace.c +++ b/kernel/src/backtrace.c @@ -22,7 +22,7 @@ void backtrace() { /* 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 */ diff --git a/kernel/src/main.c b/kernel/src/main.c index 3e22d26..d472dca 100644 --- a/kernel/src/main.c +++ b/kernel/src/main.c @@ -10,19 +10,49 @@ #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 @@ -36,7 +66,7 @@ main(void) 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 } diff --git a/kernel/src/syscall.c b/kernel/src/syscall.c index f11e41f..a69bf81 100644 --- a/kernel/src/syscall.c +++ b/kernel/src/syscall.c @@ -8,8 +8,6 @@ #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 @@ -137,8 +135,7 @@ syscall(void) int num; struct proc *curproc = myproc(); - //FIXME - backtrace(); + num = curproc->tf->eax; if(num > 0 && num < NELEM(syscalls) && syscalls[num]) { diff --git a/tools/buildall b/tools/buildall index 4af1d10..3e6504b 100755 --- a/tools/buildall +++ b/tools/buildall @@ -1,6 +1,7 @@ #!/bin/sh + set -e mkdir -p build cd build -cmake .. -DCMAKE_BUILD_TYPE=Debug +cmake .. -DCMAKE_BUILD_TYPE="$1" make