standarize on unix-like lowercase struct names

This commit is contained in:
rsc 2006-07-17 01:58:13 +00:00
parent e0966f459f
commit b5f17007f4
10 changed files with 59 additions and 59 deletions

View file

@ -31,7 +31,7 @@
**********************************************************************/ **********************************************************************/
#define SECTSIZE 512 #define SECTSIZE 512
#define ELFHDR ((struct Elf *) 0x10000) // scratch space #define ELFHDR ((struct elfhdr *) 0x10000) // scratch space
void readsect(void*, uint32_t); void readsect(void*, uint32_t);
void readseg(uint32_t, uint32_t, uint32_t); void readseg(uint32_t, uint32_t, uint32_t);
@ -39,7 +39,7 @@ void readseg(uint32_t, uint32_t, uint32_t);
void void
cmain(void) cmain(void)
{ {
struct Proghdr *ph, *eph; struct proghdr *ph, *eph;
// read 1st page off disk // read 1st page off disk
readseg((uint32_t) ELFHDR, SECTSIZE*8, 0); readseg((uint32_t) ELFHDR, SECTSIZE*8, 0);
@ -49,7 +49,7 @@ cmain(void)
goto bad; goto bad;
// load each program segment (ignores ph flags) // load each program segment (ignores ph flags)
ph = (struct Proghdr *) ((uint8_t *) ELFHDR + ELFHDR->phoff); ph = (struct proghdr *) ((uint8_t *) ELFHDR + ELFHDR->phoff);
eph = ph + ELFHDR->phnum; eph = ph + ELFHDR->phnum;
for (; ph < eph; ph++) for (; ph < eph; ph++)
readseg(ph->va, ph->memsz, ph->offset); readseg(ph->va, ph->memsz, ph->offset);

4
elf.h
View file

@ -1,6 +1,6 @@
#define ELF_MAGIC 0x464C457FU /* "\x7FELF" in little endian */ #define ELF_MAGIC 0x464C457FU /* "\x7FELF" in little endian */
struct Elf { struct elfhdr {
uint32_t magic; // must equal ELF_MAGIC uint32_t magic; // must equal ELF_MAGIC
uint8_t elf[12]; uint8_t elf[12];
uint16_t type; uint16_t type;
@ -18,7 +18,7 @@ struct Elf {
uint16_t shstrndx; uint16_t shstrndx;
}; };
struct Proghdr { struct proghdr {
uint32_t type; uint32_t type;
uint32_t offset; uint32_t offset;
uint32_t va; uint32_t va;

12
main.c
View file

@ -57,8 +57,8 @@ main0(void)
p->mem = kalloc(p->sz); p->mem = kalloc(p->sz);
memset(p->mem, 0, p->sz); memset(p->mem, 0, p->sz);
p->kstack = kalloc(KSTACKSIZE); p->kstack = kalloc(KSTACKSIZE);
p->tf = (struct Trapframe *) (p->kstack + KSTACKSIZE - sizeof(struct Trapframe)); p->tf = (struct trapframe *) (p->kstack + KSTACKSIZE - sizeof(struct trapframe));
memset(p->tf, 0, sizeof(struct Trapframe)); memset(p->tf, 0, sizeof(struct trapframe));
p->tf->es = p->tf->ds = p->tf->ss = (SEG_UDATA << 3) | 3; p->tf->es = p->tf->ds = p->tf->ss = (SEG_UDATA << 3) | 3;
p->tf->cs = (SEG_UCODE << 3) | 3; p->tf->cs = (SEG_UCODE << 3) | 3;
p->tf->eflags = FL_IF; p->tf->eflags = FL_IF;
@ -110,11 +110,11 @@ void
load_icode(struct proc *p, uint8_t *binary, uint size) load_icode(struct proc *p, uint8_t *binary, uint size)
{ {
int i; int i;
struct Elf *elf; struct elfhdr *elf;
struct Proghdr *ph; struct proghdr *ph;
// Check magic number on binary // Check magic number on binary
elf = (struct Elf*) binary; elf = (struct elfhdr*) binary;
cprintf("elf %x magic %x\n", elf, elf->magic); cprintf("elf %x magic %x\n", elf, elf->magic);
if (elf->magic != ELF_MAGIC) if (elf->magic != ELF_MAGIC)
panic("load_icode: not an ELF binary"); panic("load_icode: not an ELF binary");
@ -123,7 +123,7 @@ load_icode(struct proc *p, uint8_t *binary, uint size)
p->tf->esp = p->sz; p->tf->esp = p->sz;
// Map and load segments as directed. // Map and load segments as directed.
ph = (struct Proghdr*) (binary + elf->phoff); ph = (struct proghdr*) (binary + elf->phoff);
for (i = 0; i < elf->phnum; i++, ph++) { for (i = 0; i < elf->phnum; i++, ph++) {
if (ph->type != ELF_PROG_LOAD) if (ph->type != ELF_PROG_LOAD)
continue; continue;

14
mmu.h
View file

@ -60,7 +60,7 @@
#else // not __ASSEMBLER__ #else // not __ASSEMBLER__
// Segment Descriptors // Segment Descriptors
struct Segdesc { struct segdesc {
uint lim_15_0 : 16; // Low bits of segment limit uint lim_15_0 : 16; // Low bits of segment limit
uint base_15_0 : 16; // Low bits of segment base address uint base_15_0 : 16; // Low bits of segment base address
uint base_23_16 : 8; // Middle bits of segment base address uint base_23_16 : 8; // Middle bits of segment base address
@ -76,15 +76,15 @@ struct Segdesc {
uint 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 }
// Segment that is loadable but faults when used // Segment that is loadable but faults when used
#define SEG_FAULT (struct Segdesc){ 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0 } #define SEG_FAULT (struct segdesc){ 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0 }
// 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, (uint) (lim) >> 28, 0, 0, 1, 1, \ type, 1, dpl, 1, (uint) (lim) >> 28, 0, 0, 1, 1, \
(uint) (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, (uint) (lim) >> 16, 0, 0, 1, 0, \ type, 1, dpl, 1, (uint) (lim) >> 16, 0, 0, 1, 0, \
(uint) (base) >> 24 } (uint) (base) >> 24 }
@ -123,7 +123,7 @@ struct Segdesc {
#ifndef __ASSEMBLER__ #ifndef __ASSEMBLER__
// Task state segment format (as described by the Pentium architecture book) // Task state segment format (as described by the Pentium architecture book)
struct Taskstate { struct taskstate {
uint32_t link; // Old ts selector uint32_t link; // Old ts selector
uintptr_t esp0; // Stack pointers and segment selectors uintptr_t esp0; // Stack pointers and segment selectors
uint16_t ss0; // after an increase in privilege level uint16_t ss0; // after an increase in privilege level
@ -164,7 +164,7 @@ struct Taskstate {
}; };
// Gate descriptors for interrupts and traps // Gate descriptors for interrupts and traps
struct Gatedesc { struct gatedesc {
uint off_15_0 : 16; // low 16 bits of offset in segment uint off_15_0 : 16; // low 16 bits of offset in segment
uint ss : 16; // segment selector uint ss : 16; // segment selector
uint args : 5; // # args, 0 for interrupt/trap gates uint args : 5; // # args, 0 for interrupt/trap gates

40
mp.c
View file

@ -31,12 +31,12 @@ static char* buses[] = {
#define APBOOTCODE 0x7000 // XXX hack #define APBOOTCODE 0x7000 // XXX hack
static struct MP* mp; // The MP floating point structure static struct mp* mp; // The MP floating point structure
struct cpu cpus[NCPU]; struct cpu cpus[NCPU];
int ncpu; int ncpu;
static struct cpu *bcpu; static struct cpu *bcpu;
static struct MP* static struct mp*
mp_scan(uint8_t *addr, int len) mp_scan(uint8_t *addr, int len)
{ {
uint8_t *e, *p, sum; uint8_t *e, *p, sum;
@ -44,24 +44,24 @@ mp_scan(uint8_t *addr, int len)
cprintf("scanning: 0x%x\n", (uint32_t)addr); cprintf("scanning: 0x%x\n", (uint32_t)addr);
e = addr+len; e = addr+len;
for(p = addr; p < e; p += sizeof(struct MP)){ for(p = addr; p < e; p += sizeof(struct mp)){
if(memcmp(p, "_MP_", 4)) if(memcmp(p, "_MP_", 4))
continue; continue;
sum = 0; sum = 0;
for(i = 0; i < sizeof(struct MP); i++) for(i = 0; i < sizeof(struct mp); i++)
sum += p[i]; sum += p[i];
if(sum == 0) if(sum == 0)
return (struct MP *)p; return (struct mp *)p;
} }
return 0; return 0;
} }
static struct MP* static struct mp*
mp_search(void) mp_search(void)
{ {
uint8_t *bda; uint8_t *bda;
uint32_t p; uint32_t p;
struct MP *mp; struct mp *mp;
/* /*
* Search for the MP Floating Pointer Structure, which according to the * Search for the MP Floating Pointer Structure, which according to the
@ -86,7 +86,7 @@ mp_search(void)
static int static int
mp_detect(void) mp_detect(void)
{ {
struct MPCTB *pcmp; struct mpctb *pcmp;
uint8_t *p, sum; uint8_t *p, sum;
uint32_t length; uint32_t length;
@ -100,7 +100,7 @@ mp_detect(void)
if((mp = mp_search()) == 0 || mp->physaddr == 0) if((mp = mp_search()) == 0 || mp->physaddr == 0)
return 1; return 1;
pcmp = (struct MPCTB *) mp->physaddr; pcmp = (struct mpctb *) mp->physaddr;
if(memcmp(pcmp, "PCMP", 4)) if(memcmp(pcmp, "PCMP", 4))
return 2; return 2;
@ -121,9 +121,9 @@ mp_init(void)
{ {
int r; int r;
uint8_t *p, *e; uint8_t *p, *e;
struct MPCTB *mpctb; struct mpctb *mpctb;
struct MPPE *proc; struct mppe *proc;
struct MPBE *bus; struct mpbe *bus;
int i; int i;
ncpu = 0; ncpu = 0;
@ -136,40 +136,40 @@ mp_init(void)
* application processors and initialising any I/O APICs. The table * application processors and initialising any I/O APICs. The table
* is guaranteed to be in order such that only one pass is necessary. * is guaranteed to be in order such that only one pass is necessary.
*/ */
mpctb = (struct MPCTB *) mp->physaddr; mpctb = (struct mpctb *) mp->physaddr;
lapicaddr = (uint32_t *) mpctb->lapicaddr; lapicaddr = (uint32_t *) mpctb->lapicaddr;
cprintf("apicaddr: %x\n", lapicaddr); cprintf("apicaddr: %x\n", lapicaddr);
p = ((uint8_t*)mpctb)+sizeof(struct MPCTB); p = ((uint8_t*)mpctb)+sizeof(struct mpctb);
e = ((uint8_t*)mpctb)+mpctb->length; e = ((uint8_t*)mpctb)+mpctb->length;
while(p < e) { while(p < e) {
switch(*p){ switch(*p){
case MPPROCESSOR: case MPPROCESSOR:
proc = (struct MPPE *) p; proc = (struct mppe *) p;
cpus[ncpu].apicid = proc->apicid; cpus[ncpu].apicid = proc->apicid;
cprintf("a processor %x\n", cpus[ncpu].apicid); cprintf("a processor %x\n", cpus[ncpu].apicid);
if (proc->flags & MPBP) { if (proc->flags & MPBP) {
bcpu = &cpus[ncpu]; bcpu = &cpus[ncpu];
} }
ncpu++; ncpu++;
p += sizeof(struct MPPE); p += sizeof(struct mppe);
continue; continue;
case MPBUS: case MPBUS:
bus = (struct MPBE *) p; bus = (struct mpbe *) p;
for(i = 0; buses[i]; i++){ for(i = 0; buses[i]; i++){
if(strncmp(buses[i], bus->string, sizeof(bus->string)) == 0) if(strncmp(buses[i], bus->string, sizeof(bus->string)) == 0)
break; break;
} }
cprintf("a bus %d\n", i); cprintf("a bus %d\n", i);
p += sizeof(struct MPBE); p += sizeof(struct mpbe);
continue; continue;
case MPIOAPIC: case MPIOAPIC:
cprintf("an I/O APIC\n"); cprintf("an I/O APIC\n");
p += sizeof(struct MPIOAPIC); p += sizeof(struct mpioapic);
continue; continue;
case MPIOINTR: case MPIOINTR:
cprintf("an I/O intr\n"); cprintf("an I/O intr\n");
p += sizeof(struct MPIE); p += sizeof(struct mpie);
continue; continue;
default: default:
cprintf("mpinit: unknown PCMP type 0x%x (e-p 0x%x)\n", *p, e-p); cprintf("mpinit: unknown PCMP type 0x%x (e-p 0x%x)\n", *p, e-p);

12
mp.h
View file

@ -4,7 +4,7 @@
* Credit: Plan 9 sources * Credit: Plan 9 sources
*/ */
struct MP { /* floating pointer */ struct mp { /* floating pointer */
uint8_t signature[4]; /* "_MP_" */ uint8_t signature[4]; /* "_MP_" */
physaddr_t physaddr; /* physical address of MP configuration table */ physaddr_t physaddr; /* physical address of MP configuration table */
uint8_t length; /* 1 */ uint8_t length; /* 1 */
@ -15,7 +15,7 @@ struct MP { /* floating pointer */
uint8_t reserved[3]; uint8_t reserved[3];
}; };
struct MPCTB { /* configuration table header */ struct mpctb { /* configuration table header */
uint8_t signature[4]; /* "PCMP" */ uint8_t signature[4]; /* "PCMP" */
uint16_t length; /* total table length */ uint16_t length; /* total table length */
uint8_t version; /* [14] */ uint8_t version; /* [14] */
@ -30,7 +30,7 @@ struct MPCTB { /* configuration table header */
uint8_t reserved; uint8_t reserved;
}; };
struct MPPE { /* processor table entry */ struct mppe { /* processor table entry */
uint8_t type; /* entry type (0) */ uint8_t type; /* entry type (0) */
uint8_t apicid; /* local APIC id */ uint8_t apicid; /* local APIC id */
uint8_t version; /* local APIC verison */ uint8_t version; /* local APIC verison */
@ -40,13 +40,13 @@ struct MPPE { /* processor table entry */
uint8_t reserved[8]; uint8_t reserved[8];
}; };
struct MPBE { /* bus table entry */ struct mpbe { /* bus table entry */
uint8_t type; /* entry type (1) */ uint8_t type; /* entry type (1) */
uint8_t busno; /* bus id */ uint8_t busno; /* bus id */
char string[6]; /* bus type string */ char string[6]; /* bus type string */
}; };
struct MPIOAPIC { /* I/O APIC table entry */ struct mpioapic { /* I/O APIC table entry */
uint8_t type; /* entry type (2) */ uint8_t type; /* entry type (2) */
uint8_t apicno; /* I/O APIC id */ uint8_t apicno; /* I/O APIC id */
uint8_t version; /* I/O APIC version */ uint8_t version; /* I/O APIC version */
@ -54,7 +54,7 @@ struct MPIOAPIC { /* I/O APIC table entry */
uintptr_t addr; /* I/O APIC address */ uintptr_t addr; /* I/O APIC address */
}; };
struct MPIE { /* interrupt table entry */ struct mpie { /* interrupt table entry */
uint8_t type; /* entry type ([34]) */ uint8_t type; /* entry type ([34]) */
uint8_t intr; /* interrupt type */ uint8_t intr; /* interrupt type */
uint16_t flags; /* interrupt flag */ uint16_t flags; /* interrupt flag */

6
proc.c
View file

@ -13,7 +13,7 @@ struct proc proc[NPROC];
struct proc *curproc[NCPU]; struct proc *curproc[NCPU];
int next_pid = 1; int next_pid = 1;
extern void forkret(void); extern void forkret(void);
extern void forkret1(struct Trapframe*); extern void forkret1(struct trapframe*);
/* /*
* set up a process's task state and segment descriptors * set up a process's task state and segment descriptors
@ -24,7 +24,7 @@ extern void forkret1(struct Trapframe*);
void void
setupsegs(struct proc *p) 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 = (uint)(p->kstack + KSTACKSIZE); p->ts.esp0 = (uint)(p->kstack + KSTACKSIZE);
@ -100,7 +100,7 @@ copyproc(struct proc* p)
setupsegs(np); setupsegs(np);
// Copy trapframe registers from parent. // Copy trapframe registers from parent.
np->tf = (struct Trapframe*)(np->kstack + KSTACKSIZE) - 1; np->tf = (struct trapframe*)(np->kstack + KSTACKSIZE) - 1;
*np->tf = *p->tf; *np->tf = *p->tf;
// Clear %eax so that fork system call returns 0 in child. // Clear %eax so that fork system call returns 0 in child.

6
proc.h
View file

@ -48,14 +48,14 @@ struct proc{
int killed; int killed;
struct fd *fds[NOFILE]; struct fd *fds[NOFILE];
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];
uint esp; // kernel stack pointer uint esp; // kernel stack pointer
uint ebp; // kernel frame pointer uint ebp; // kernel frame pointer
struct jmpbuf jmpbuf; struct jmpbuf jmpbuf;
struct Trapframe *tf; // points into kstack, used to find user regs struct trapframe *tf; // points into kstack, used to find user regs
}; };
extern struct proc proc[]; extern struct proc proc[];

4
trap.c
View file

@ -7,7 +7,7 @@
#include "traps.h" #include "traps.h"
#include "syscall.h" #include "syscall.h"
struct Gatedesc idt[256]; struct gatedesc idt[256];
extern uint 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);
@ -31,7 +31,7 @@ idtinit(void)
} }
void void
trap(struct Trapframe *tf) trap(struct trapframe *tf)
{ {
int v = tf->trapno; int v = tf->trapno;

14
x86.h
View file

@ -12,10 +12,10 @@ static __inline void outsw(int port, const void *addr, int cnt) __attribute__((a
static __inline void outsl(int port, const void *addr, int cnt) __attribute__((always_inline)); static __inline void outsl(int port, const void *addr, int cnt) __attribute__((always_inline));
static __inline void outl(int port, uint32_t data) __attribute__((always_inline)); static __inline void outl(int port, uint32_t data) __attribute__((always_inline));
static __inline void invlpg(void *addr) __attribute__((always_inline)); static __inline void invlpg(void *addr) __attribute__((always_inline));
struct Segdesc; struct segdesc;
static __inline void lgdt(struct Segdesc *p, int) __attribute__((always_inline)); static __inline void lgdt(struct segdesc *p, int) __attribute__((always_inline));
struct Gatedesc; struct gatedesc;
static __inline void lidt(struct Gatedesc *p, int) __attribute__((always_inline)); static __inline void lidt(struct gatedesc *p, int) __attribute__((always_inline));
static __inline void lldt(uint16_t sel) __attribute__((always_inline)); static __inline void lldt(uint16_t sel) __attribute__((always_inline));
static __inline void ltr(uint16_t sel) __attribute__((always_inline)); static __inline void ltr(uint16_t sel) __attribute__((always_inline));
static __inline void lcr0(uint32_t val) __attribute__((always_inline)); static __inline void lcr0(uint32_t val) __attribute__((always_inline));
@ -144,7 +144,7 @@ invlpg(void *addr)
} }
static __inline void static __inline void
lgdt(struct Segdesc *p, int size) lgdt(struct segdesc *p, int size)
{ {
volatile uint16_t pd[3]; volatile uint16_t pd[3];
@ -156,7 +156,7 @@ lgdt(struct Segdesc *p, int size)
} }
static __inline void static __inline void
lidt(struct Gatedesc *p, int size) lidt(struct gatedesc *p, int size)
{ {
volatile uint16_t pd[3]; volatile uint16_t pd[3];
@ -339,7 +339,7 @@ sti(void)
__asm__ volatile("sti"); __asm__ volatile("sti");
} }
struct Trapframe { struct trapframe {
/* registers as pushed by pusha */ /* registers as pushed by pusha */
uint32_t edi; uint32_t edi;
uint32_t esi; uint32_t esi;