Skip to content

Commit

Permalink
add uint and standardize on typedefs instead of unsigned
Browse files Browse the repository at this point in the history
  • Loading branch information
rsc committed Jul 17, 2006
1 parent 857d60c commit b5ee516
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 82 deletions.
2 changes: 1 addition & 1 deletion bootmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ cmain(void)
bad:
outw(0x8A00, 0x8A00);
outw(0x8A00, 0x8E00);
while (1)
while(1)
/* do nothing */;
}

Expand Down
6 changes: 3 additions & 3 deletions console.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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 *);

6 changes: 3 additions & 3 deletions ide.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
struct ide_request {
uint32_t secno;
void *dst;
unsigned nsecs;
uint nsecs;
};
struct ide_request request[NREQUEST];
int head, tail;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions kalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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;
Expand Down
52 changes: 26 additions & 26 deletions mmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@

// 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 }
Expand All @@ -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__ */

Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions mp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
12 changes: 6 additions & 6 deletions proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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++){
Expand Down
6 changes: 3 additions & 3 deletions proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions spinlock.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
struct spinlock {
unsigned int locked;
unsigned locker_pc;
uint locked;
uint locker_pc;
};
12 changes: 6 additions & 6 deletions string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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.
Expand All @@ -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;
Expand Down
Loading

0 comments on commit b5ee516

Please sign in to comment.