]> Devi Nivas Git - cs3210-lab1.git/commitdiff
add uint and standardize on typedefs instead of unsigned
authorrsc <rsc>
Mon, 17 Jul 2006 01:52:13 +0000 (01:52 +0000)
committerrsc <rsc>
Mon, 17 Jul 2006 01:52:13 +0000 (01:52 +0000)
15 files changed:
bootmain.c
console.c
defs.h
ide.c
kalloc.c
main.c
mmu.h
mp.c
proc.c
proc.h
spinlock.h
string.c
syscall.c
trap.c
types.h

index 89857760e863019c2d462aa3914a27f42ddf7536..a98ca823619c37c4172f75634de0a45103bb70d1 100644 (file)
@@ -61,7 +61,7 @@ cmain(void)
 bad:
        outw(0x8A00, 0x8A00);
        outw(0x8A00, 0x8E00);
-       while (1)
+       while(1)
                /* do nothing */;
 }
 
index 9c15494b0e1384cdbdebebc18f5dc3881907f1dd..6a82dacc99df6f92f2b47138ca9fe756251f0e57 100644 (file)
--- a/console.c
+++ b/console.c
@@ -28,7 +28,7 @@ static void
 real_cons_putc(int c)
 {
   int crtport = 0x3d4; // io port of CGA
-  unsigned short *crt = (unsigned short *) 0xB8000; // base of CGA memory
+  uint16_t *crt = (uint16_t *) 0xB8000; // base of CGA memory
   int ind;
 
   if(panicked){
@@ -85,7 +85,7 @@ printint(int xx, int base, int sgn)
   char buf[16];
   char digits[] = "0123456789ABCDEF";
   int i = 0, neg = 0;
-  unsigned int x;
+  uint x;
   
   if(sgn && xx < 0){
     neg = 1;
@@ -111,7 +111,7 @@ void
 cprintf(char *fmt, ...)
 {
   int i, state = 0, c;
-  unsigned int *ap = (unsigned int *)(void*)&fmt + 1;
+  uint *ap = (uint *)(void*)&fmt + 1;
 
   if(use_console_lock)
     acquire(&console_lock);
diff --git a/defs.h b/defs.h
index 00b7f0582abf3ddc4c14f66b9070c3037dc69ef6..2e74f847589bf5be66c6a66014faddac2bd57544 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -32,10 +32,10 @@ void tvinit(void);
 void idtinit(void);
 
 // string.c
-void * memset(void *dst, int c, unsigned n);
-int memcmp(const void *v1, const void *v2, unsigned n);
-void *memmove(void *dst, const void *src, unsigned n);
-int strncmp(const char *p, const char *q, unsigned n);
+void * memset(void *dst, int c, uint n);
+int memcmp(const void *v1, const void *v2, uint n);
+void *memmove(void *dst, const void *src, uint n);
+int strncmp(const char *p, const char *q, uint n);
 
 // syscall.c
 void syscall(void);
@@ -68,7 +68,7 @@ void acquire1(struct spinlock * lock, struct proc *);
 void release1(struct spinlock * lock, struct proc *);
 
 // main.c
-void load_icode(struct proc *p, uint8_t *binary, unsigned size);
+void load_icode(struct proc *p, uint8_t *binary, uint size);
 
 // pipe.c
 struct pipe;
@@ -89,6 +89,6 @@ void fd_incref(struct fd *fd);
 // ide.c
 void ide_init(void);
 void ide_intr(void);
-void* ide_start_read(uint32_t secno, void *dst, unsigned nsecs);
+void* ide_start_read(uint32_t secno, void *dst, uint nsecs);
 int ide_finish_read(void *);
 
diff --git a/ide.c b/ide.c
index e1ed25adf5daa12f52d2dd54fa4093077997cc3e..3228f7f60038192154bc01cfaf009317eae8902f 100644 (file)
--- a/ide.c
+++ b/ide.c
@@ -19,7 +19,7 @@
 struct ide_request {
   uint32_t secno;
   void *dst;
-  unsigned nsecs;
+  uint nsecs;
 };
 struct ide_request request[NREQUEST];
 int head, tail;
@@ -104,7 +104,7 @@ ide_start_request (void)
 }
 
 void *
-ide_start_read(uint32_t secno, void *dst, unsigned nsecs)
+ide_start_read(uint32_t secno, void *dst, uint nsecs)
 {
   struct ide_request *r;
 
@@ -149,7 +149,7 @@ ide_finish_read(void *c)
 }
 
 int
-ide_write(uint32_t secno, const void *src, unsigned nsecs)
+ide_write(uint32_t secno, const void *src, uint nsecs)
 {
   int r;
        
index d016090707cf281c0e0528dedd58e707c3f83fc6..0b22c9118ec88b43ad8d41ba98ee205b0302f617 100644 (file)
--- a/kalloc.c
+++ b/kalloc.c
@@ -34,11 +34,11 @@ void
 kinit(void)
 {
   extern int end;
-  unsigned mem;
+  uint mem;
   char *start;
   
   start = (char *) &end;
-  start = (char *) (((unsigned)start + PAGE) & ~(PAGE-1));
+  start = (char *) (((uint)start + PAGE) & ~(PAGE-1));
   mem = 256; // XXX
   cprintf("mem = %d\n", mem * PAGE);
   kfree(start, mem * PAGE);
diff --git a/main.c b/main.c
index 39c11dce973f9927f1dee9631574fe29130c9bec..694a0f7f6b16d43e43310a8acd05ea675220a721 100644 (file)
--- a/main.c
+++ b/main.c
@@ -81,8 +81,8 @@ main0(void)
 
   p = copyproc(&proc[0]);
   
-  load_icode(p, _binary_usertests_start, (unsigned) _binary_usertests_size);
-  //load_icode(p, _binary_userfs_start, (unsigned) _binary_userfs_size);
+  load_icode(p, _binary_usertests_start, (uint) _binary_usertests_size);
+  //load_icode(p, _binary_userfs_start, (uint) _binary_userfs_size);
   p->state = RUNNABLE;
   cprintf("loaded userfs\n");
 
@@ -107,7 +107,7 @@ mpmain(void)
 }
 
 void
-load_icode(struct proc *p, uint8_t *binary, unsigned size)
+load_icode(struct proc *p, uint8_t *binary, uint size)
 {
   int i;
   struct Elf *elf;
diff --git a/mmu.h b/mmu.h
index 829815d3778405992b5b0c96e2890bf0a9efe770..20dc3a381691679afca34392a9d65d1f7d9b6d21 100644 (file)
--- a/mmu.h
+++ b/mmu.h
 
 // Segment Descriptors
 struct Segdesc {
-       unsigned lim_15_0 : 16;  // Low bits of segment limit
-       unsigned base_15_0 : 16; // Low bits of segment base address
-       unsigned base_23_16 : 8; // Middle bits of segment base address
-       unsigned type : 4;       // Segment type (see STS_ constants)
-       unsigned s : 1;          // 0 = system, 1 = application
-       unsigned dpl : 2;        // Descriptor Privilege Level
-       unsigned p : 1;          // Present
-       unsigned lim_19_16 : 4;  // High bits of segment limit
-       unsigned avl : 1;        // Unused (available for software use)
-       unsigned rsv1 : 1;       // Reserved
-       unsigned db : 1;         // 0 = 16-bit segment, 1 = 32-bit segment
-       unsigned g : 1;          // Granularity: limit scaled by 4K when set
-       unsigned base_31_24 : 8; // High bits of segment base address
+       uint lim_15_0 : 16;  // Low bits of segment limit
+       uint base_15_0 : 16; // Low bits of segment base address
+       uint base_23_16 : 8; // Middle bits of segment base address
+       uint type : 4;       // Segment type (see STS_ constants)
+       uint s : 1;          // 0 = system, 1 = application
+       uint dpl : 2;        // Descriptor Privilege Level
+       uint p : 1;          // Present
+       uint lim_19_16 : 4;  // High bits of segment limit
+       uint avl : 1;        // Unused (available for software use)
+       uint rsv1 : 1;       // Reserved
+       uint db : 1;         // 0 = 16-bit segment, 1 = 32-bit segment
+       uint g : 1;          // Granularity: limit scaled by 4K when set
+       uint base_31_24 : 8; // High bits of segment base address
 };
 // Null segment
 #define SEG_NULL       (struct Segdesc){ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
@@ -82,12 +82,12 @@ struct Segdesc {
 // Normal segment
 #define SEG(type, base, lim, dpl) (struct Segdesc)                     \
 { ((lim) >> 12) & 0xffff, (base) & 0xffff, ((base) >> 16) & 0xff,      \
-    type, 1, dpl, 1, (unsigned) (lim) >> 28, 0, 0, 1, 1,               \
-    (unsigned) (base) >> 24 }
+    type, 1, dpl, 1, (uint) (lim) >> 28, 0, 0, 1, 1,           \
+    (uint) (base) >> 24 }
 #define SEG16(type, base, lim, dpl) (struct Segdesc)                   \
 { (lim) & 0xffff, (base) & 0xffff, ((base) >> 16) & 0xff,              \
-    type, 1, dpl, 1, (unsigned) (lim) >> 16, 0, 0, 1, 0,               \
-    (unsigned) (base) >> 24 }
+    type, 1, dpl, 1, (uint) (lim) >> 16, 0, 0, 1, 0,           \
+    (uint) (base) >> 24 }
 
 #endif /* !__ASSEMBLER__ */
 
@@ -165,15 +165,15 @@ struct Taskstate {
 
 // Gate descriptors for interrupts and traps
 struct Gatedesc {
-       unsigned off_15_0 : 16;   // low 16 bits of offset in segment
-       unsigned ss : 16;         // segment selector
-       unsigned args : 5;        // # args, 0 for interrupt/trap gates
-       unsigned rsv1 : 3;        // reserved(should be zero I guess)
-       unsigned type : 4;        // type(STS_{TG,IG32,TG32})
-       unsigned s : 1;           // must be 0 (system)
-       unsigned dpl : 2;         // descriptor(meaning new) privilege level
-       unsigned p : 1;           // Present
-       unsigned off_31_16 : 16;  // high bits of offset in segment
+       uint off_15_0 : 16;   // low 16 bits of offset in segment
+       uint ss : 16;         // segment selector
+       uint args : 5;        // # args, 0 for interrupt/trap gates
+       uint rsv1 : 3;        // reserved(should be zero I guess)
+       uint type : 4;        // type(STS_{TG,IG32,TG32})
+       uint s : 1;           // must be 0 (system)
+       uint dpl : 2;         // descriptor(meaning new) privilege level
+       uint p : 1;           // Present
+       uint off_31_16 : 16;  // high bits of offset in segment
 };
 
 // Set up a normal interrupt/trap gate descriptor.
diff --git a/mp.c b/mp.c
index 8e9eda8618814ca9959f18a6a42daf55acd19a3d..bce35cb6f1ef4d777657fcb368ffddc55116ce1c 100644 (file)
--- a/mp.c
+++ b/mp.c
@@ -205,8 +205,8 @@ mp_startthem(void)
   for(c = 0; c < ncpu; c++){
     if (c == cpu()) continue;
     cprintf ("starting processor %d\n", c);
-    *(unsigned *)(APBOOTCODE-4) = (unsigned) (cpus[c].mpstack) + MPSTACK; // tell it what to use for %esp
-    *(unsigned *)(APBOOTCODE-8) = (unsigned)mpmain; // tell it where to jump to
+    *(uint *)(APBOOTCODE-4) = (uint) (cpus[c].mpstack) + MPSTACK; // tell it what to use for %esp
+    *(uint *)(APBOOTCODE-8) = (uint)mpmain; // tell it where to jump to
     lapic_startap(cpus[c].apicid, (uint32_t) APBOOTCODE);
   }
 }
diff --git a/proc.c b/proc.c
index e916761e3b72002e8aec4f06994b4e61319e1784..ba6905bbb50774d2e4f81e6f5b182d248bd4e03d 100644 (file)
--- a/proc.c
+++ b/proc.c
@@ -26,18 +26,18 @@ setupsegs(struct proc *p)
 {
   memset(&p->ts, 0, sizeof(struct Taskstate));
   p->ts.ss0 = SEG_KDATA << 3;
-  p->ts.esp0 = (unsigned)(p->kstack + KSTACKSIZE);
+  p->ts.esp0 = (uint)(p->kstack + KSTACKSIZE);
 
   // XXX it may be wrong to modify the current segment table!
 
   p->gdt[0] = SEG_NULL;
   p->gdt[SEG_KCODE] = SEG(STA_X|STA_R, 0, 0xffffffff, 0);
   p->gdt[SEG_KDATA] = SEG(STA_W, 0, 0xffffffff, 0);
-  p->gdt[SEG_TSS] = SEG16(STS_T32A, (unsigned) &p->ts,
+  p->gdt[SEG_TSS] = SEG16(STS_T32A, (uint) &p->ts,
                                 sizeof(p->ts), 0);
   p->gdt[SEG_TSS].s = 0;
-  p->gdt[SEG_UCODE] = SEG(STA_X|STA_R, (unsigned)p->mem, p->sz, 3);
-  p->gdt[SEG_UDATA] = SEG(STA_W, (unsigned)p->mem, p->sz, 3);
+  p->gdt[SEG_UCODE] = SEG(STA_X|STA_R, (uint)p->mem, p->sz, 3);
+  p->gdt[SEG_UDATA] = SEG(STA_W, (uint)p->mem, p->sz, 3);
 }
 
 // Look in the process table for an UNUSED proc.
@@ -108,8 +108,8 @@ copyproc(struct proc* p)
 
   // Set up new jmpbuf to start executing at forkret (see below).
   memset(&np->jmpbuf, 0, sizeof np->jmpbuf);
-  np->jmpbuf.eip = (unsigned)forkret;
-  np->jmpbuf.esp = (unsigned)np->tf;
+  np->jmpbuf.eip = (uint)forkret;
+  np->jmpbuf.esp = (uint)np->tf;
 
   // Copy file descriptors
   for(i = 0; i < NOFILE; i++){
diff --git a/proc.h b/proc.h
index 9353f880cccc30d732ebc4620ccecf831690587b..256fa7c388ce08fe8abcfdbfac00aeae43c7e8dd 100644 (file)
--- a/proc.h
+++ b/proc.h
@@ -37,7 +37,7 @@ enum proc_state { UNUSED, EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE };
 
 struct proc{
   char *mem; // start of process's physical memory
-  unsigned sz; // total size of mem, including kernel stack
+  uint sz; // total size of mem, including kernel stack
   char *kstack; // kernel stack, separate from mem so it doesn't move
   enum proc_state state;
   enum proc_state newstate; // desired state after swtch()
@@ -50,8 +50,8 @@ struct proc{
 
   struct Taskstate ts;  // only to give cpu address of kernel stack
   struct Segdesc gdt[NSEGS];
-  unsigned esp; // kernel stack pointer
-  unsigned ebp; // kernel frame pointer
+  uint esp; // kernel stack pointer
+  uint ebp; // kernel frame pointer
 
   struct jmpbuf jmpbuf;
 
index bc84a581a4b396f3a0ce3ee2ebd159a715492beb..044e4d8da7ad54d250bca8f333dc596dd5596dae 100644 (file)
@@ -1,4 +1,4 @@
 struct spinlock {
-  unsigned int locked;
-  unsigned locker_pc;
+  uint locked;
+  uint locker_pc;
 };
index 07082e5abad77c4d71328e4b757c7a41295e32bf..dbce23141f692a079fc46a82fe8a6abab5a97747 100644 (file)
--- a/string.c
+++ b/string.c
@@ -2,7 +2,7 @@
 #include "defs.h"
 
 void *
-memset(void *dst, int c, unsigned n)
+memset(void *dst, int c, uint n)
 {
   char *d = (char *) dst;
 
@@ -13,7 +13,7 @@ memset(void *dst, int c, unsigned n)
 }
 
 int
-memcmp(const void *v1, const void *v2, unsigned n)
+memcmp(const void *v1, const void *v2, uint n)
 {
   const uint8_t *s1 = (const uint8_t *) v1;
   const uint8_t *s2 = (const uint8_t *) v2;
@@ -28,7 +28,7 @@ memcmp(const void *v1, const void *v2, unsigned n)
 }
 
 void *
-memmove(void *dst, const void *src, unsigned n)
+memmove(void *dst, const void *src, uint n)
 {
   const char *s;
   char *d;
@@ -48,14 +48,14 @@ memmove(void *dst, const void *src, unsigned n)
 }
 
 int
-strncmp(const char *p, const char *q, unsigned n)
+strncmp(const char *p, const char *q, uint n)
 {
        while (n > 0 && *p && *p == *q)
                n--, p++, q++;
        if (n == 0)
                return 0;
        else
-               return (int) ((unsigned char) *p - (unsigned char) *q);
+               return (int) ((uint8_t) *p - (uint8_t) *q);
 }
 
 // Memcpy is deprecated and should NOT be called.
@@ -64,7 +64,7 @@ strncmp(const char *p, const char *q, unsigned n)
 // Memcpy is here only because gcc compiles some
 // structure assignments into calls to memcpy.
 void *
-memcpy(void *dst, void *src, unsigned n)
+memcpy(void *dst, void *src, uint n)
 {
   char *d = (char *) dst;
   char *s = (char *) src;
index 2ab9bbb415e48069a79c3c193e06770a141d279a..7bd37b7dbed5228152272f99d86f227c7b159f7f 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -24,7 +24,7 @@
  * returns 0 if addr was OK, -1 if illegal.
  */
 int
-fetchint(struct proc *p, unsigned addr, int *ip)
+fetchint(struct proc *p, uint addr, int *ip)
 {
   *ip = 0;
 
@@ -37,7 +37,7 @@ fetchint(struct proc *p, unsigned addr, int *ip)
 // Fetch byte from a user-supplied pointer.
 // Returns 0 on success, -1 if pointer is illegal.
 int
-fetchbyte(struct proc *p, unsigned addr, char* c)
+fetchbyte(struct proc *p, uint addr, char* c)
 {
   if(addr >= p->sz)
     return -1;
@@ -49,14 +49,14 @@ fetchbyte(struct proc *p, unsigned addr, char* c)
 int
 fetcharg(int argno, void *ip)
 {
-  unsigned esp;
+  uint esp;
 
-  esp = (unsigned) curproc[cpu()]->tf->esp;
+  esp = (uint) curproc[cpu()]->tf->esp;
   return fetchint(curproc[cpu()], esp + 4 + 4*argno, ip);
 }
 
 int
-putint(struct proc *p, unsigned addr, int ip)
+putint(struct proc *p, uint addr, int ip)
 {
   if(addr > p->sz - 4)
     return -1;
@@ -70,7 +70,7 @@ sys_pipe(void)
   struct fd *rfd = 0, *wfd = 0;
   int f1 = -1, f2 = -1;
   struct proc *p = curproc[cpu()];
-  unsigned fdp;
+  uint fdp;
 
   if(pipe_alloc(&rfd, &wfd) < 0)
     goto oops;
@@ -105,7 +105,7 @@ int
 sys_write(void)
 {
   int fd, n, ret;
-  unsigned addr;
+  uint addr;
   struct proc *p = curproc[cpu()];
 
   if(fetcharg(0, &fd) < 0 || fetcharg(1, &addr) < 0 || fetcharg(2, &n) < 0)
@@ -124,7 +124,7 @@ int
 sys_read(void)
 {
   int fd, n, ret;
-  unsigned addr;
+  uint addr;
   struct proc *p = curproc[cpu()];
 
   if(fetcharg(0, &fd) < 0 || fetcharg(1, &addr) < 0 || fetcharg(2, &n) < 0)
@@ -209,7 +209,7 @@ sys_cons_puts(void)
 {
   char buf[256];
   int i;
-  unsigned addr;
+  uint addr;
   struct proc *cp = curproc[cpu()];
 
   if(fetcharg(0, &addr) < 0)
@@ -251,7 +251,7 @@ int
 sys_panic(void)
 {
   struct proc *p = curproc[cpu()];
-  unsigned int addr;
+  uint addr;
 
   if(fetcharg(0, &addr) < 0)
     return -1;
diff --git a/trap.c b/trap.c
index 41b8c8f238ef18667669e3fe7b1834af2499f6d7..38baee0d4be318ba64c2161c1de5800642691dba 100644 (file)
--- a/trap.c
+++ b/trap.c
@@ -8,7 +8,7 @@
 #include "syscall.h"
 
 struct Gatedesc idt[256];
-extern unsigned vectors[]; /* vectors.S, array of 256 entry point addresses */
+extern uint vectors[]; /* vectors.S, array of 256 entry point addresses */
 
 extern void trapenter(void);
 extern void trapenter1(void);
@@ -56,8 +56,8 @@ trap(struct Trapframe *tf)
     }
     if((read_eflags() & FL_IF) == 0)
       panic("syscall returning but FL_IF clear");
-    if(read_esp() < (unsigned)cp->kstack ||
-       read_esp() >= (unsigned)cp->kstack + KSTACKSIZE)
+    if(read_esp() < (uint)cp->kstack ||
+       read_esp() >= (uint)cp->kstack + KSTACKSIZE)
       panic("trap ret esp wrong");
     if(cp->killed)
       proc_exit();
diff --git a/types.h b/types.h
index f520c975312a0b2c312313d6ab74646a936ee77d..938154bed10541dee7c2a4361f564844701bee23 100644 (file)
--- a/types.h
+++ b/types.h
@@ -1,7 +1,9 @@
+typedef unsigned int       uint;
+
 typedef unsigned long long uint64_t;
-typedef unsigned int uint32_t;
-typedef unsigned short uint16_t;
-typedef unsigned char uint8_t;
-typedef uint32_t uintptr_t;
-typedef uint32_t physaddr_t;
-typedef unsigned int uint;
+typedef unsigned int       uint32_t;
+typedef unsigned short     uint16_t;
+typedef unsigned char      uint8_t;
+
+typedef uint32_t           uintptr_t;
+typedef uint32_t           physaddr_t;