]> Devi Nivas Git - cs3210-lab1.git/commitdiff
finish lab 1 master
authorAdvaith Menon <noreply-git@bp4k.net>
Tue, 3 Feb 2026 15:36:41 +0000 (21:06 +0530)
committerAdvaith Menon <noreply-git@bp4k.net>
Tue, 3 Feb 2026 15:36:41 +0000 (21:06 +0530)
bootblock/bootasm.S
bootblock/bootmain.c
kernel/src/backtrace.c
kernel/src/main.c
kernel/src/syscall.c
tools/buildall

index 120296fa65887dd141a81611f2250455b4afc1be..707dc53172fca43ca2efe76f90a94e28da43d2c5 100644 (file)
 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
 
index d3c2bdea7249acbb54df8f13ccf46bd26aeac059..173b7658ddacb303394ff2f9ba5045e2b7c3b096 100644 (file)
 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
index b93a2be2ccd7e28da9b95973b5d8290b0cad03c1..7daef38c88c8054e0aef936f471d4fb537a6437b 100644 (file)
@@ -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 */
index 3e22d265003b1a7ebe5d9347ecd9de13cfd222f7..d472dca3dc500e48d77823ccc0fa71ea4374f074 100644 (file)
 #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
 }
index f11e41f7c62de212e5f52544dab27465b68e4adc..a69bf8131b9c28807d0a2ba0196d38a8b36ddbf9 100644 (file)
@@ -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]) {
index 4af1d10be445ff36a59a2e45ca9494945c1091be..3e6504b6874bdf054698581ad555eb0357c4711e 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/sh
+
 set -e
 mkdir -p build
 cd build
-cmake .. -DCMAKE_BUILD_TYPE=Debug
+cmake .. -DCMAKE_BUILD_TYPE="$1"
 make