add uint and standardize on typedefs instead of unsigned

This commit is contained in:
rsc 2006-07-17 01:52:13 +00:00
parent 857d60cb0c
commit b5ee516575
15 changed files with 84 additions and 82 deletions

View file

@ -61,7 +61,7 @@ cmain(void)
bad: bad:
outw(0x8A00, 0x8A00); outw(0x8A00, 0x8A00);
outw(0x8A00, 0x8E00); outw(0x8A00, 0x8E00);
while (1) while(1)
/* do nothing */; /* do nothing */;
} }

View file

@ -28,7 +28,7 @@ static void
real_cons_putc(int c) real_cons_putc(int c)
{ {
int crtport = 0x3d4; // io port of CGA 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; int ind;
if(panicked){ if(panicked){
@ -85,7 +85,7 @@ printint(int xx, int base, int sgn)
char buf[16]; char buf[16];
char digits[] = "0123456789ABCDEF"; char digits[] = "0123456789ABCDEF";
int i = 0, neg = 0; int i = 0, neg = 0;
unsigned int x; uint x;
if(sgn && xx < 0){ if(sgn && xx < 0){
neg = 1; neg = 1;
@ -111,7 +111,7 @@ void
cprintf(char *fmt, ...) cprintf(char *fmt, ...)
{ {
int i, state = 0, c; int i, state = 0, c;
unsigned int *ap = (unsigned int *)(void*)&fmt + 1; uint *ap = (uint *)(void*)&fmt + 1;
if(use_console_lock) if(use_console_lock)
acquire(&console_lock); acquire(&console_lock);

12
defs.h
View file

@ -32,10 +32,10 @@ void tvinit(void);
void idtinit(void); void idtinit(void);
// string.c // string.c
void * memset(void *dst, int c, unsigned n); void * memset(void *dst, int c, uint n);
int memcmp(const void *v1, const void *v2, unsigned n); int memcmp(const void *v1, const void *v2, uint n);
void *memmove(void *dst, const void *src, unsigned n); void *memmove(void *dst, const void *src, uint n);
int strncmp(const char *p, const char *q, unsigned n); int strncmp(const char *p, const char *q, uint n);
// syscall.c // syscall.c
void syscall(void); void syscall(void);
@ -68,7 +68,7 @@ void acquire1(struct spinlock * lock, struct proc *);
void release1(struct spinlock * lock, struct proc *); void release1(struct spinlock * lock, struct proc *);
// main.c // 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 // pipe.c
struct pipe; struct pipe;
@ -89,6 +89,6 @@ void fd_incref(struct fd *fd);
// ide.c // ide.c
void ide_init(void); void ide_init(void);
void ide_intr(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 *); int ide_finish_read(void *);

6
ide.c
View file

@ -19,7 +19,7 @@
struct ide_request { struct ide_request {
uint32_t secno; uint32_t secno;
void *dst; void *dst;
unsigned nsecs; uint nsecs;
}; };
struct ide_request request[NREQUEST]; struct ide_request request[NREQUEST];
int head, tail; int head, tail;
@ -104,7 +104,7 @@ ide_start_request (void)
} }
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; struct ide_request *r;
@ -149,7 +149,7 @@ ide_finish_read(void *c)
} }
int int
ide_write(uint32_t secno, const void *src, unsigned nsecs) ide_write(uint32_t secno, const void *src, uint nsecs)
{ {
int r; int r;

View file

@ -34,11 +34,11 @@ void
kinit(void) kinit(void)
{ {
extern int end; extern int end;
unsigned mem; uint mem;
char *start; char *start;
start = (char *) &end; start = (char *) &end;
start = (char *) (((unsigned)start + PAGE) & ~(PAGE-1)); start = (char *) (((uint)start + PAGE) & ~(PAGE-1));
mem = 256; // XXX mem = 256; // XXX
cprintf("mem = %d\n", mem * PAGE); cprintf("mem = %d\n", mem * PAGE);
kfree(start, mem * PAGE); kfree(start, mem * PAGE);

6
main.c
View file

@ -81,8 +81,8 @@ main0(void)
p = copyproc(&proc[0]); p = copyproc(&proc[0]);
load_icode(p, _binary_usertests_start, (unsigned) _binary_usertests_size); load_icode(p, _binary_usertests_start, (uint) _binary_usertests_size);
//load_icode(p, _binary_userfs_start, (unsigned) _binary_userfs_size); //load_icode(p, _binary_userfs_start, (uint) _binary_userfs_size);
p->state = RUNNABLE; p->state = RUNNABLE;
cprintf("loaded userfs\n"); cprintf("loaded userfs\n");
@ -107,7 +107,7 @@ mpmain(void)
} }
void void
load_icode(struct proc *p, uint8_t *binary, unsigned size) load_icode(struct proc *p, uint8_t *binary, uint size)
{ {
int i; int i;
struct Elf *elf; struct Elf *elf;

52
mmu.h
View file

@ -61,19 +61,19 @@
// Segment Descriptors // Segment Descriptors
struct Segdesc { struct Segdesc {
unsigned lim_15_0 : 16; // Low bits of segment limit uint lim_15_0 : 16; // Low bits of segment limit
unsigned base_15_0 : 16; // Low bits of segment base address uint base_15_0 : 16; // Low bits of segment base address
unsigned base_23_16 : 8; // Middle bits of segment base address uint base_23_16 : 8; // Middle bits of segment base address
unsigned type : 4; // Segment type (see STS_ constants) uint type : 4; // Segment type (see STS_ constants)
unsigned s : 1; // 0 = system, 1 = application uint s : 1; // 0 = system, 1 = application
unsigned dpl : 2; // Descriptor Privilege Level uint dpl : 2; // Descriptor Privilege Level
unsigned p : 1; // Present uint p : 1; // Present
unsigned lim_19_16 : 4; // High bits of segment limit uint lim_19_16 : 4; // High bits of segment limit
unsigned avl : 1; // Unused (available for software use) uint avl : 1; // Unused (available for software use)
unsigned rsv1 : 1; // Reserved uint rsv1 : 1; // Reserved
unsigned db : 1; // 0 = 16-bit segment, 1 = 32-bit segment uint db : 1; // 0 = 16-bit segment, 1 = 32-bit segment
unsigned g : 1; // Granularity: limit scaled by 4K when set uint g : 1; // Granularity: limit scaled by 4K when set
unsigned base_31_24 : 8; // High bits of segment base address uint base_31_24 : 8; // High bits of segment base address
}; };
// Null segment // Null segment
#define SEG_NULL (struct Segdesc){ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } #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 // Normal segment
#define SEG(type, base, lim, dpl) (struct Segdesc) \ #define SEG(type, base, lim, dpl) (struct Segdesc) \
{ ((lim) >> 12) & 0xffff, (base) & 0xffff, ((base) >> 16) & 0xff, \ { ((lim) >> 12) & 0xffff, (base) & 0xffff, ((base) >> 16) & 0xff, \
type, 1, dpl, 1, (unsigned) (lim) >> 28, 0, 0, 1, 1, \ type, 1, dpl, 1, (uint) (lim) >> 28, 0, 0, 1, 1, \
(unsigned) (base) >> 24 } (uint) (base) >> 24 }
#define SEG16(type, base, lim, dpl) (struct Segdesc) \ #define SEG16(type, base, lim, dpl) (struct Segdesc) \
{ (lim) & 0xffff, (base) & 0xffff, ((base) >> 16) & 0xff, \ { (lim) & 0xffff, (base) & 0xffff, ((base) >> 16) & 0xff, \
type, 1, dpl, 1, (unsigned) (lim) >> 16, 0, 0, 1, 0, \ type, 1, dpl, 1, (uint) (lim) >> 16, 0, 0, 1, 0, \
(unsigned) (base) >> 24 } (uint) (base) >> 24 }
#endif /* !__ASSEMBLER__ */ #endif /* !__ASSEMBLER__ */
@ -165,15 +165,15 @@ struct Taskstate {
// Gate descriptors for interrupts and traps // Gate descriptors for interrupts and traps
struct Gatedesc { struct Gatedesc {
unsigned off_15_0 : 16; // low 16 bits of offset in segment uint off_15_0 : 16; // low 16 bits of offset in segment
unsigned ss : 16; // segment selector uint ss : 16; // segment selector
unsigned args : 5; // # args, 0 for interrupt/trap gates uint args : 5; // # args, 0 for interrupt/trap gates
unsigned rsv1 : 3; // reserved(should be zero I guess) uint rsv1 : 3; // reserved(should be zero I guess)
unsigned type : 4; // type(STS_{TG,IG32,TG32}) uint type : 4; // type(STS_{TG,IG32,TG32})
unsigned s : 1; // must be 0 (system) uint s : 1; // must be 0 (system)
unsigned dpl : 2; // descriptor(meaning new) privilege level uint dpl : 2; // descriptor(meaning new) privilege level
unsigned p : 1; // Present uint p : 1; // Present
unsigned off_31_16 : 16; // high bits of offset in segment uint off_31_16 : 16; // high bits of offset in segment
}; };
// Set up a normal interrupt/trap gate descriptor. // Set up a normal interrupt/trap gate descriptor.

4
mp.c
View file

@ -205,8 +205,8 @@ mp_startthem(void)
for(c = 0; c < ncpu; c++){ for(c = 0; c < ncpu; c++){
if (c == cpu()) continue; if (c == cpu()) continue;
cprintf ("starting processor %d\n", c); cprintf ("starting processor %d\n", c);
*(unsigned *)(APBOOTCODE-4) = (unsigned) (cpus[c].mpstack) + MPSTACK; // tell it what to use for %esp *(uint *)(APBOOTCODE-4) = (uint) (cpus[c].mpstack) + MPSTACK; // tell it what to use for %esp
*(unsigned *)(APBOOTCODE-8) = (unsigned)mpmain; // tell it where to jump to *(uint *)(APBOOTCODE-8) = (uint)mpmain; // tell it where to jump to
lapic_startap(cpus[c].apicid, (uint32_t) APBOOTCODE); lapic_startap(cpus[c].apicid, (uint32_t) APBOOTCODE);
} }
} }

12
proc.c
View file

@ -26,18 +26,18 @@ setupsegs(struct proc *p)
{ {
memset(&p->ts, 0, sizeof(struct Taskstate)); memset(&p->ts, 0, sizeof(struct Taskstate));
p->ts.ss0 = SEG_KDATA << 3; 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! // XXX it may be wrong to modify the current segment table!
p->gdt[0] = SEG_NULL; p->gdt[0] = SEG_NULL;
p->gdt[SEG_KCODE] = SEG(STA_X|STA_R, 0, 0xffffffff, 0); 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_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); sizeof(p->ts), 0);
p->gdt[SEG_TSS].s = 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_UCODE] = SEG(STA_X|STA_R, (uint)p->mem, p->sz, 3);
p->gdt[SEG_UDATA] = SEG(STA_W, (unsigned)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. // 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). // Set up new jmpbuf to start executing at forkret (see below).
memset(&np->jmpbuf, 0, sizeof np->jmpbuf); memset(&np->jmpbuf, 0, sizeof np->jmpbuf);
np->jmpbuf.eip = (unsigned)forkret; np->jmpbuf.eip = (uint)forkret;
np->jmpbuf.esp = (unsigned)np->tf; np->jmpbuf.esp = (uint)np->tf;
// Copy file descriptors // Copy file descriptors
for(i = 0; i < NOFILE; i++){ for(i = 0; i < NOFILE; i++){

6
proc.h
View file

@ -37,7 +37,7 @@ enum proc_state { UNUSED, EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE };
struct proc{ struct proc{
char *mem; // start of process's physical memory 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 char *kstack; // kernel stack, separate from mem so it doesn't move
enum proc_state state; enum proc_state state;
enum proc_state newstate; // desired state after swtch() 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 Taskstate ts; // only to give cpu address of kernel stack
struct Segdesc gdt[NSEGS]; struct Segdesc gdt[NSEGS];
unsigned esp; // kernel stack pointer uint esp; // kernel stack pointer
unsigned ebp; // kernel frame pointer uint ebp; // kernel frame pointer
struct jmpbuf jmpbuf; struct jmpbuf jmpbuf;

View file

@ -1,4 +1,4 @@
struct spinlock { struct spinlock {
unsigned int locked; uint locked;
unsigned locker_pc; uint locker_pc;
}; };

View file

@ -2,7 +2,7 @@
#include "defs.h" #include "defs.h"
void * void *
memset(void *dst, int c, unsigned n) memset(void *dst, int c, uint n)
{ {
char *d = (char *) dst; char *d = (char *) dst;
@ -13,7 +13,7 @@ memset(void *dst, int c, unsigned n)
} }
int 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 *s1 = (const uint8_t *) v1;
const uint8_t *s2 = (const uint8_t *) v2; const uint8_t *s2 = (const uint8_t *) v2;
@ -28,7 +28,7 @@ memcmp(const void *v1, const void *v2, unsigned n)
} }
void * void *
memmove(void *dst, const void *src, unsigned n) memmove(void *dst, const void *src, uint n)
{ {
const char *s; const char *s;
char *d; char *d;
@ -48,14 +48,14 @@ memmove(void *dst, const void *src, unsigned n)
} }
int 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) while (n > 0 && *p && *p == *q)
n--, p++, q++; n--, p++, q++;
if (n == 0) if (n == 0)
return 0; return 0;
else 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. // 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 // Memcpy is here only because gcc compiles some
// structure assignments into calls to memcpy. // structure assignments into calls to memcpy.
void * void *
memcpy(void *dst, void *src, unsigned n) memcpy(void *dst, void *src, uint n)
{ {
char *d = (char *) dst; char *d = (char *) dst;
char *s = (char *) src; char *s = (char *) src;

View file

@ -24,7 +24,7 @@
* returns 0 if addr was OK, -1 if illegal. * returns 0 if addr was OK, -1 if illegal.
*/ */
int int
fetchint(struct proc *p, unsigned addr, int *ip) fetchint(struct proc *p, uint addr, int *ip)
{ {
*ip = 0; *ip = 0;
@ -37,7 +37,7 @@ fetchint(struct proc *p, unsigned addr, int *ip)
// Fetch byte from a user-supplied pointer. // Fetch byte from a user-supplied pointer.
// Returns 0 on success, -1 if pointer is illegal. // Returns 0 on success, -1 if pointer is illegal.
int int
fetchbyte(struct proc *p, unsigned addr, char* c) fetchbyte(struct proc *p, uint addr, char* c)
{ {
if(addr >= p->sz) if(addr >= p->sz)
return -1; return -1;
@ -49,14 +49,14 @@ fetchbyte(struct proc *p, unsigned addr, char* c)
int int
fetcharg(int argno, void *ip) 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); return fetchint(curproc[cpu()], esp + 4 + 4*argno, ip);
} }
int int
putint(struct proc *p, unsigned addr, int ip) putint(struct proc *p, uint addr, int ip)
{ {
if(addr > p->sz - 4) if(addr > p->sz - 4)
return -1; return -1;
@ -70,7 +70,7 @@ sys_pipe(void)
struct fd *rfd = 0, *wfd = 0; struct fd *rfd = 0, *wfd = 0;
int f1 = -1, f2 = -1; int f1 = -1, f2 = -1;
struct proc *p = curproc[cpu()]; struct proc *p = curproc[cpu()];
unsigned fdp; uint fdp;
if(pipe_alloc(&rfd, &wfd) < 0) if(pipe_alloc(&rfd, &wfd) < 0)
goto oops; goto oops;
@ -105,7 +105,7 @@ int
sys_write(void) sys_write(void)
{ {
int fd, n, ret; int fd, n, ret;
unsigned addr; uint addr;
struct proc *p = curproc[cpu()]; struct proc *p = curproc[cpu()];
if(fetcharg(0, &fd) < 0 || fetcharg(1, &addr) < 0 || fetcharg(2, &n) < 0) if(fetcharg(0, &fd) < 0 || fetcharg(1, &addr) < 0 || fetcharg(2, &n) < 0)
@ -124,7 +124,7 @@ int
sys_read(void) sys_read(void)
{ {
int fd, n, ret; int fd, n, ret;
unsigned addr; uint addr;
struct proc *p = curproc[cpu()]; struct proc *p = curproc[cpu()];
if(fetcharg(0, &fd) < 0 || fetcharg(1, &addr) < 0 || fetcharg(2, &n) < 0) if(fetcharg(0, &fd) < 0 || fetcharg(1, &addr) < 0 || fetcharg(2, &n) < 0)
@ -209,7 +209,7 @@ sys_cons_puts(void)
{ {
char buf[256]; char buf[256];
int i; int i;
unsigned addr; uint addr;
struct proc *cp = curproc[cpu()]; struct proc *cp = curproc[cpu()];
if(fetcharg(0, &addr) < 0) if(fetcharg(0, &addr) < 0)
@ -251,7 +251,7 @@ int
sys_panic(void) sys_panic(void)
{ {
struct proc *p = curproc[cpu()]; struct proc *p = curproc[cpu()];
unsigned int addr; uint addr;
if(fetcharg(0, &addr) < 0) if(fetcharg(0, &addr) < 0)
return -1; return -1;

6
trap.c
View file

@ -8,7 +8,7 @@
#include "syscall.h" #include "syscall.h"
struct Gatedesc idt[256]; 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 trapenter(void);
extern void trapenter1(void); extern void trapenter1(void);
@ -56,8 +56,8 @@ trap(struct Trapframe *tf)
} }
if((read_eflags() & FL_IF) == 0) if((read_eflags() & FL_IF) == 0)
panic("syscall returning but FL_IF clear"); panic("syscall returning but FL_IF clear");
if(read_esp() < (unsigned)cp->kstack || if(read_esp() < (uint)cp->kstack ||
read_esp() >= (unsigned)cp->kstack + KSTACKSIZE) read_esp() >= (uint)cp->kstack + KSTACKSIZE)
panic("trap ret esp wrong"); panic("trap ret esp wrong");
if(cp->killed) if(cp->killed)
proc_exit(); proc_exit();

View file

@ -1,7 +1,9 @@
typedef unsigned int uint;
typedef unsigned long long uint64_t; typedef unsigned long long uint64_t;
typedef unsigned int uint32_t; typedef unsigned int uint32_t;
typedef unsigned short uint16_t; typedef unsigned short uint16_t;
typedef unsigned char uint8_t; typedef unsigned char uint8_t;
typedef uint32_t uintptr_t; typedef uint32_t uintptr_t;
typedef uint32_t physaddr_t; typedef uint32_t physaddr_t;
typedef unsigned int uint;