uint32_t -> uint &c
This commit is contained in:
parent
bd228a8156
commit
2927081628
16
bootmain.c
16
bootmain.c
|
@ -33,8 +33,8 @@
|
||||||
#define SECTSIZE 512
|
#define SECTSIZE 512
|
||||||
#define ELFHDR ((struct elfhdr *) 0x10000) // scratch space
|
#define ELFHDR ((struct elfhdr *) 0x10000) // scratch space
|
||||||
|
|
||||||
void readsect(void*, uint32_t);
|
void readsect(void*, uint);
|
||||||
void readseg(uint32_t, uint32_t, uint32_t);
|
void readseg(uint, uint, uint);
|
||||||
|
|
||||||
void
|
void
|
||||||
cmain(void)
|
cmain(void)
|
||||||
|
@ -42,14 +42,14 @@ 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((uint) ELFHDR, SECTSIZE*8, 0);
|
||||||
|
|
||||||
// is this a valid ELF?
|
// is this a valid ELF?
|
||||||
if (ELFHDR->magic != ELF_MAGIC)
|
if (ELFHDR->magic != ELF_MAGIC)
|
||||||
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 *) ((uchar *) 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);
|
||||||
|
@ -68,9 +68,9 @@ bad:
|
||||||
// Read 'count' bytes at 'offset' from kernel into virtual address 'va'.
|
// Read 'count' bytes at 'offset' from kernel into virtual address 'va'.
|
||||||
// Might copy more than asked
|
// Might copy more than asked
|
||||||
void
|
void
|
||||||
readseg(uint32_t va, uint32_t count, uint32_t offset)
|
readseg(uint va, uint count, uint offset)
|
||||||
{
|
{
|
||||||
uint32_t end_va;
|
uint end_va;
|
||||||
|
|
||||||
va &= 0xFFFFFF;
|
va &= 0xFFFFFF;
|
||||||
end_va = va + count;
|
end_va = va + count;
|
||||||
|
@ -85,7 +85,7 @@ readseg(uint32_t va, uint32_t count, uint32_t offset)
|
||||||
// We'd write more to memory than asked, but it doesn't matter --
|
// We'd write more to memory than asked, but it doesn't matter --
|
||||||
// we load in increasing order.
|
// we load in increasing order.
|
||||||
while (va < end_va) {
|
while (va < end_va) {
|
||||||
readsect((uint8_t*) va, offset);
|
readsect((uchar*) va, offset);
|
||||||
va += SECTSIZE;
|
va += SECTSIZE;
|
||||||
offset++;
|
offset++;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ waitdisk(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
readsect(void *dst, uint32_t offset)
|
readsect(void *dst, uint offset)
|
||||||
{
|
{
|
||||||
// wait for disk to be ready
|
// wait for disk to be ready
|
||||||
waitdisk();
|
waitdisk();
|
||||||
|
|
|
@ -28,7 +28,7 @@ static void
|
||||||
cons_putc(int c)
|
cons_putc(int c)
|
||||||
{
|
{
|
||||||
int crtport = 0x3d4; // io port of CGA
|
int crtport = 0x3d4; // io port of CGA
|
||||||
uint16_t *crt = (uint16_t *) 0xB8000; // base of CGA memory
|
ushort *crt = (ushort *) 0xB8000; // base of CGA memory
|
||||||
int ind;
|
int ind;
|
||||||
|
|
||||||
if(panicked){
|
if(panicked){
|
||||||
|
|
12
defs.h
12
defs.h
|
@ -40,8 +40,8 @@ int strncmp(const char *p, const char *q, uint n);
|
||||||
void syscall(void);
|
void syscall(void);
|
||||||
|
|
||||||
// picirq.c
|
// picirq.c
|
||||||
extern uint16_t irq_mask_8259A;
|
extern ushort irq_mask_8259A;
|
||||||
void irq_setmask_8259A(uint16_t mask);
|
void irq_setmask_8259A(ushort mask);
|
||||||
void pic_init(void);
|
void pic_init(void);
|
||||||
|
|
||||||
// mp.c
|
// mp.c
|
||||||
|
@ -50,9 +50,9 @@ void mp_startthem(void);
|
||||||
int mp_bcpu(void);
|
int mp_bcpu(void);
|
||||||
|
|
||||||
// lapic
|
// lapic
|
||||||
extern uint32_t *lapicaddr;
|
extern uint *lapicaddr;
|
||||||
void lapic_init(int);
|
void lapic_init(int);
|
||||||
void lapic_startap(uint8_t, int);
|
void lapic_startap(uchar, int);
|
||||||
void lapic_timerinit(void);
|
void lapic_timerinit(void);
|
||||||
void lapic_timerintr(void);
|
void lapic_timerintr(void);
|
||||||
void lapic_enableintr(void);
|
void lapic_enableintr(void);
|
||||||
|
@ -66,7 +66,7 @@ void release(struct spinlock*);
|
||||||
int holding(struct spinlock*);
|
int holding(struct spinlock*);
|
||||||
|
|
||||||
// main.c
|
// main.c
|
||||||
void load_icode(struct proc *p, uint8_t *binary, uint size);
|
void load_icode(struct proc *p, uchar *binary, uint size);
|
||||||
|
|
||||||
// pipe.c
|
// pipe.c
|
||||||
struct pipe;
|
struct pipe;
|
||||||
|
@ -87,6 +87,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, uint nsecs);
|
void* ide_start_read(uint secno, void *dst, uint nsecs);
|
||||||
int ide_finish_read(void *);
|
int ide_finish_read(void *);
|
||||||
|
|
||||||
|
|
46
elf.h
46
elf.h
|
@ -1,32 +1,32 @@
|
||||||
#define ELF_MAGIC 0x464C457FU /* "\x7FELF" in little endian */
|
#define ELF_MAGIC 0x464C457FU /* "\x7FELF" in little endian */
|
||||||
|
|
||||||
struct elfhdr {
|
struct elfhdr {
|
||||||
uint32_t magic; // must equal ELF_MAGIC
|
uint magic; // must equal ELF_MAGIC
|
||||||
uint8_t elf[12];
|
uchar elf[12];
|
||||||
uint16_t type;
|
ushort type;
|
||||||
uint16_t machine;
|
ushort machine;
|
||||||
uint32_t version;
|
uint version;
|
||||||
uint32_t entry;
|
uint entry;
|
||||||
uint32_t phoff;
|
uint phoff;
|
||||||
uint32_t shoff;
|
uint shoff;
|
||||||
uint32_t flags;
|
uint flags;
|
||||||
uint16_t ehsize;
|
ushort ehsize;
|
||||||
uint16_t phentsize;
|
ushort phentsize;
|
||||||
uint16_t phnum;
|
ushort phnum;
|
||||||
uint16_t shentsize;
|
ushort shentsize;
|
||||||
uint16_t shnum;
|
ushort shnum;
|
||||||
uint16_t shstrndx;
|
ushort shstrndx;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct proghdr {
|
struct proghdr {
|
||||||
uint32_t type;
|
uint type;
|
||||||
uint32_t offset;
|
uint offset;
|
||||||
uint32_t va;
|
uint va;
|
||||||
uint32_t pa;
|
uint pa;
|
||||||
uint32_t filesz;
|
uint filesz;
|
||||||
uint32_t memsz;
|
uint memsz;
|
||||||
uint32_t flags;
|
uint flags;
|
||||||
uint32_t align;
|
uint align;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Values for Proghdr type
|
// Values for Proghdr type
|
||||||
|
|
20
ide.c
20
ide.c
|
@ -18,7 +18,8 @@
|
||||||
#define IDE_ERR 0x01
|
#define IDE_ERR 0x01
|
||||||
|
|
||||||
struct ide_request {
|
struct ide_request {
|
||||||
uint32_t secno;
|
int diskno;
|
||||||
|
uint secno;
|
||||||
void *dst;
|
void *dst;
|
||||||
uint nsecs;
|
uint nsecs;
|
||||||
};
|
};
|
||||||
|
@ -26,7 +27,6 @@ struct ide_request request[NREQUEST];
|
||||||
int head, tail;
|
int head, tail;
|
||||||
struct spinlock ide_lock;
|
struct spinlock ide_lock;
|
||||||
|
|
||||||
static int diskno = 0;
|
|
||||||
int disk_channel;
|
int disk_channel;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -79,14 +79,6 @@ ide_probe_disk1(void)
|
||||||
return (x < 1000);
|
return (x < 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
ide_set_disk(int d)
|
|
||||||
{
|
|
||||||
if (d != 0 && d != 1)
|
|
||||||
panic("bad disk number");
|
|
||||||
diskno = d;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ide_start_request (void)
|
ide_start_request (void)
|
||||||
{
|
{
|
||||||
|
@ -100,13 +92,13 @@ ide_start_request (void)
|
||||||
outb(0x1F3, r->secno & 0xFF);
|
outb(0x1F3, r->secno & 0xFF);
|
||||||
outb(0x1F4, (r->secno >> 8) & 0xFF);
|
outb(0x1F4, (r->secno >> 8) & 0xFF);
|
||||||
outb(0x1F5, (r->secno >> 16) & 0xFF);
|
outb(0x1F5, (r->secno >> 16) & 0xFF);
|
||||||
outb(0x1F6, 0xE0 | ((diskno&1)<<4) | ((r->secno>>24)&0x0F));
|
outb(0x1F6, 0xE0 | ((r->diskno&1)<<4) | ((r->secno>>24)&0x0F));
|
||||||
outb(0x1F7, 0x20); // CMD 0x20 means read sector
|
outb(0x1F7, 0x20); // CMD 0x20 means read sector
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
ide_start_read(uint32_t secno, void *dst, uint nsecs)
|
ide_start_read(uint secno, void *dst, uint nsecs)
|
||||||
{
|
{
|
||||||
struct ide_request *r;
|
struct ide_request *r;
|
||||||
if(!holding(&ide_lock))
|
if(!holding(&ide_lock))
|
||||||
|
@ -122,6 +114,7 @@ ide_start_read(uint32_t secno, void *dst, uint nsecs)
|
||||||
r->secno = secno;
|
r->secno = secno;
|
||||||
r->dst = dst;
|
r->dst = dst;
|
||||||
r->nsecs = nsecs;
|
r->nsecs = nsecs;
|
||||||
|
r->diskno = 0;
|
||||||
|
|
||||||
ide_start_request();
|
ide_start_request();
|
||||||
|
|
||||||
|
@ -155,9 +148,10 @@ ide_finish_read(void *c)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ide_write(uint32_t secno, const void *src, uint nsecs)
|
ide_write(uint secno, const void *src, uint nsecs)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
int diskno = 0;
|
||||||
|
|
||||||
if(nsecs > 256)
|
if(nsecs > 256)
|
||||||
panic("ide_write");
|
panic("ide_write");
|
||||||
|
|
6
lapic.c
6
lapic.c
|
@ -92,7 +92,7 @@ enum { /* LAPIC_TDCR */
|
||||||
LAPIC_X1 = 0x0000000B, /* divide by 1 */
|
LAPIC_X1 = 0x0000000B, /* divide by 1 */
|
||||||
};
|
};
|
||||||
|
|
||||||
uint32_t *lapicaddr;
|
uint *lapicaddr;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
lapic_read(int r)
|
lapic_read(int r)
|
||||||
|
@ -127,7 +127,7 @@ lapic_timerintr(void)
|
||||||
void
|
void
|
||||||
lapic_init(int c)
|
lapic_init(int c)
|
||||||
{
|
{
|
||||||
uint32_t r, lvt;
|
uint r, lvt;
|
||||||
|
|
||||||
cprintf("lapic_init %d\n", c);
|
cprintf("lapic_init %d\n", c);
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ cpu(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
lapic_startap(uint8_t apicid, int v)
|
lapic_startap(uchar apicid, int v)
|
||||||
{
|
{
|
||||||
int crhi, i;
|
int crhi, i;
|
||||||
volatile int j = 0;
|
volatile int j = 0;
|
||||||
|
|
14
main.c
14
main.c
|
@ -11,9 +11,9 @@
|
||||||
#include "spinlock.h"
|
#include "spinlock.h"
|
||||||
|
|
||||||
extern char edata[], end[];
|
extern char edata[], end[];
|
||||||
extern uint8_t _binary_user1_start[], _binary_user1_size[];
|
extern uchar _binary_user1_start[], _binary_user1_size[];
|
||||||
extern uint8_t _binary_usertests_start[], _binary_usertests_size[];
|
extern uchar _binary_usertests_start[], _binary_usertests_size[];
|
||||||
extern uint8_t _binary_userfs_start[], _binary_userfs_size[];
|
extern uchar _binary_userfs_start[], _binary_userfs_size[];
|
||||||
|
|
||||||
extern int use_console_lock;
|
extern int use_console_lock;
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ main0(void)
|
||||||
lapic_enableintr();
|
lapic_enableintr();
|
||||||
|
|
||||||
// init disk device
|
// init disk device
|
||||||
//ide_init();
|
ide_init();
|
||||||
|
|
||||||
// Enable interrupts on this processor.
|
// Enable interrupts on this processor.
|
||||||
cpus[cpu()].nlock--;
|
cpus[cpu()].nlock--;
|
||||||
|
@ -81,8 +81,8 @@ main0(void)
|
||||||
|
|
||||||
p = copyproc(&proc[0]);
|
p = copyproc(&proc[0]);
|
||||||
|
|
||||||
load_icode(p, _binary_usertests_start, (uint) _binary_usertests_size);
|
//load_icode(p, _binary_usertests_start, (uint) _binary_usertests_size);
|
||||||
//load_icode(p, _binary_userfs_start, (uint) _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, uint size)
|
load_icode(struct proc *p, uchar *binary, uint size)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct elfhdr *elf;
|
struct elfhdr *elf;
|
||||||
|
|
82
mmu.h
82
mmu.h
|
@ -124,43 +124,43 @@ struct segdesc {
|
||||||
|
|
||||||
// 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
|
uint link; // Old ts selector
|
||||||
uintptr_t esp0; // Stack pointers and segment selectors
|
uint * esp0; // Stack pointers and segment selectors
|
||||||
uint16_t ss0; // after an increase in privilege level
|
ushort ss0; // after an increase in privilege level
|
||||||
uint16_t padding1;
|
ushort padding1;
|
||||||
uintptr_t esp1;
|
uint * esp1;
|
||||||
uint16_t ss1;
|
ushort ss1;
|
||||||
uint16_t padding2;
|
ushort padding2;
|
||||||
uintptr_t esp2;
|
uint * esp2;
|
||||||
uint16_t ss2;
|
ushort ss2;
|
||||||
uint16_t padding3;
|
ushort padding3;
|
||||||
physaddr_t cr3; // Page directory base
|
void * cr3; // Page directory base
|
||||||
uintptr_t eip; // Saved state from last task switch
|
uint * eip; // Saved state from last task switch
|
||||||
uint32_t eflags;
|
uint eflags;
|
||||||
uint32_t eax; // More saved state (registers)
|
uint eax; // More saved state (registers)
|
||||||
uint32_t ecx;
|
uint ecx;
|
||||||
uint32_t edx;
|
uint edx;
|
||||||
uint32_t ebx;
|
uint ebx;
|
||||||
uintptr_t esp;
|
uint * esp;
|
||||||
uintptr_t ebp;
|
uint * ebp;
|
||||||
uint32_t esi;
|
uint esi;
|
||||||
uint32_t edi;
|
uint edi;
|
||||||
uint16_t es; // Even more saved state (segment selectors)
|
ushort es; // Even more saved state (segment selectors)
|
||||||
uint16_t padding4;
|
ushort padding4;
|
||||||
uint16_t cs;
|
ushort cs;
|
||||||
uint16_t padding5;
|
ushort padding5;
|
||||||
uint16_t ss;
|
ushort ss;
|
||||||
uint16_t padding6;
|
ushort padding6;
|
||||||
uint16_t ds;
|
ushort ds;
|
||||||
uint16_t padding7;
|
ushort padding7;
|
||||||
uint16_t fs;
|
ushort fs;
|
||||||
uint16_t padding8;
|
ushort padding8;
|
||||||
uint16_t gs;
|
ushort gs;
|
||||||
uint16_t padding9;
|
ushort padding9;
|
||||||
uint16_t ldt;
|
ushort ldt;
|
||||||
uint16_t padding10;
|
ushort padding10;
|
||||||
uint16_t t; // Trap on task switch
|
ushort t; // Trap on task switch
|
||||||
uint16_t iomb; // I/O map base address
|
ushort iomb; // I/O map base address
|
||||||
};
|
};
|
||||||
|
|
||||||
// Gate descriptors for interrupts and traps
|
// Gate descriptors for interrupts and traps
|
||||||
|
@ -185,7 +185,7 @@ struct gatedesc {
|
||||||
// this interrupt/trap gate explicitly using an int instruction.
|
// this interrupt/trap gate explicitly using an int instruction.
|
||||||
#define SETGATE(gate, istrap, sel, off, d) \
|
#define SETGATE(gate, istrap, sel, off, d) \
|
||||||
{ \
|
{ \
|
||||||
(gate).off_15_0 = (uint32_t) (off) & 0xffff; \
|
(gate).off_15_0 = (uint) (off) & 0xffff; \
|
||||||
(gate).ss = (sel); \
|
(gate).ss = (sel); \
|
||||||
(gate).args = 0; \
|
(gate).args = 0; \
|
||||||
(gate).rsv1 = 0; \
|
(gate).rsv1 = 0; \
|
||||||
|
@ -193,13 +193,13 @@ struct gatedesc {
|
||||||
(gate).s = 0; \
|
(gate).s = 0; \
|
||||||
(gate).dpl = (d); \
|
(gate).dpl = (d); \
|
||||||
(gate).p = 1; \
|
(gate).p = 1; \
|
||||||
(gate).off_31_16 = (uint32_t) (off) >> 16; \
|
(gate).off_31_16 = (uint) (off) >> 16; \
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up a call gate descriptor.
|
// Set up a call gate descriptor.
|
||||||
#define SETCALLGATE(gate, ss, off, d) \
|
#define SETCALLGATE(gate, ss, off, d) \
|
||||||
{ \
|
{ \
|
||||||
(gate).off_15_0 = (uint32_t) (off) & 0xffff; \
|
(gate).off_15_0 = (uint) (off) & 0xffff; \
|
||||||
(gate).ss = (ss); \
|
(gate).ss = (ss); \
|
||||||
(gate).args = 0; \
|
(gate).args = 0; \
|
||||||
(gate).rsv1 = 0; \
|
(gate).rsv1 = 0; \
|
||||||
|
@ -207,7 +207,7 @@ struct gatedesc {
|
||||||
(gate).s = 0; \
|
(gate).s = 0; \
|
||||||
(gate).dpl = (d); \
|
(gate).dpl = (d); \
|
||||||
(gate).p = 1; \
|
(gate).p = 1; \
|
||||||
(gate).off_31_16 = (uint32_t) (off) >> 16; \
|
(gate).off_31_16 = (uint) (off) >> 16; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !__ASSEMBLER__ */
|
#endif /* !__ASSEMBLER__ */
|
||||||
|
|
38
mp.c
38
mp.c
|
@ -37,12 +37,12 @@ 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(uchar *addr, int len)
|
||||||
{
|
{
|
||||||
uint8_t *e, *p, sum;
|
uchar *e, *p, sum;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
cprintf("scanning: 0x%x\n", (uint32_t)addr);
|
cprintf("scanning: 0x%x\n", (uint)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))
|
||||||
|
@ -59,8 +59,8 @@ mp_scan(uint8_t *addr, int len)
|
||||||
static struct mp*
|
static struct mp*
|
||||||
mp_search(void)
|
mp_search(void)
|
||||||
{
|
{
|
||||||
uint8_t *bda;
|
uchar *bda;
|
||||||
uint32_t p;
|
uint p;
|
||||||
struct mp *mp;
|
struct mp *mp;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -70,25 +70,25 @@ mp_search(void)
|
||||||
* 2) in the last KB of system base memory;
|
* 2) in the last KB of system base memory;
|
||||||
* 3) in the BIOS ROM between 0xE0000 and 0xFFFFF.
|
* 3) in the BIOS ROM between 0xE0000 and 0xFFFFF.
|
||||||
*/
|
*/
|
||||||
bda = (uint8_t*) 0x400;
|
bda = (uchar*) 0x400;
|
||||||
if((p = (bda[0x0F]<<8)|bda[0x0E])){
|
if((p = (bda[0x0F]<<8)|bda[0x0E])){
|
||||||
if((mp = mp_scan((uint8_t*) p, 1024)))
|
if((mp = mp_scan((uchar*) p, 1024)))
|
||||||
return mp;
|
return mp;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
p = ((bda[0x14]<<8)|bda[0x13])*1024;
|
p = ((bda[0x14]<<8)|bda[0x13])*1024;
|
||||||
if((mp = mp_scan((uint8_t*)p-1024, 1024)))
|
if((mp = mp_scan((uchar*)p-1024, 1024)))
|
||||||
return mp;
|
return mp;
|
||||||
}
|
}
|
||||||
return mp_scan((uint8_t*)0xF0000, 0x10000);
|
return mp_scan((uchar*)0xF0000, 0x10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
mp_detect(void)
|
mp_detect(void)
|
||||||
{
|
{
|
||||||
struct mpctb *pcmp;
|
struct mpctb *pcmp;
|
||||||
uint8_t *p, sum;
|
uchar *p, sum;
|
||||||
uint32_t length;
|
uint length;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Search for an MP configuration table. For now,
|
* Search for an MP configuration table. For now,
|
||||||
|
@ -106,7 +106,7 @@ mp_detect(void)
|
||||||
|
|
||||||
length = pcmp->length;
|
length = pcmp->length;
|
||||||
sum = 0;
|
sum = 0;
|
||||||
for(p = (uint8_t*)pcmp; length; length--)
|
for(p = (uchar*)pcmp; length; length--)
|
||||||
sum += *p++;
|
sum += *p++;
|
||||||
|
|
||||||
if(sum || (pcmp->version != 1 && pcmp->version != 4))
|
if(sum || (pcmp->version != 1 && pcmp->version != 4))
|
||||||
|
@ -120,7 +120,7 @@ void
|
||||||
mp_init(void)
|
mp_init(void)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
uint8_t *p, *e;
|
uchar *p, *e;
|
||||||
struct mpctb *mpctb;
|
struct mpctb *mpctb;
|
||||||
struct mppe *proc;
|
struct mppe *proc;
|
||||||
struct mpbe *bus;
|
struct mpbe *bus;
|
||||||
|
@ -137,10 +137,10 @@ mp_init(void)
|
||||||
* 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 = (uint *) mpctb->lapicaddr;
|
||||||
cprintf("apicaddr: %x\n", lapicaddr);
|
cprintf("apicaddr: %x\n", lapicaddr);
|
||||||
p = ((uint8_t*)mpctb)+sizeof(struct mpctb);
|
p = ((uchar*)mpctb)+sizeof(struct mpctb);
|
||||||
e = ((uint8_t*)mpctb)+mpctb->length;
|
e = ((uchar*)mpctb)+mpctb->length;
|
||||||
|
|
||||||
while(p < e) {
|
while(p < e) {
|
||||||
switch(*p){
|
switch(*p){
|
||||||
|
@ -195,18 +195,18 @@ extern void mpmain(void);
|
||||||
void
|
void
|
||||||
mp_startthem(void)
|
mp_startthem(void)
|
||||||
{
|
{
|
||||||
extern uint8_t _binary_bootother_start[], _binary_bootother_size[];
|
extern uchar _binary_bootother_start[], _binary_bootother_size[];
|
||||||
extern int main();
|
extern int main();
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
memmove((void *) APBOOTCODE,_binary_bootother_start,
|
memmove((void *) APBOOTCODE,_binary_bootother_start,
|
||||||
(uint32_t) _binary_bootother_size);
|
(uint) _binary_bootother_size);
|
||||||
|
|
||||||
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);
|
||||||
*(uint *)(APBOOTCODE-4) = (uint) (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
|
||||||
*(uint *)(APBOOTCODE-8) = (uint)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, (uint) APBOOTCODE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
82
mp.h
82
mp.h
|
@ -5,63 +5,63 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct mp { /* floating pointer */
|
struct mp { /* floating pointer */
|
||||||
uint8_t signature[4]; /* "_MP_" */
|
uchar signature[4]; /* "_MP_" */
|
||||||
physaddr_t physaddr; /* physical address of MP configuration table */
|
void* physaddr; /* physical address of MP configuration table */
|
||||||
uint8_t length; /* 1 */
|
uchar length; /* 1 */
|
||||||
uint8_t specrev; /* [14] */
|
uchar specrev; /* [14] */
|
||||||
uint8_t checksum; /* all bytes must add up to 0 */
|
uchar checksum; /* all bytes must add up to 0 */
|
||||||
uint8_t type; /* MP system configuration type */
|
uchar type; /* MP system configuration type */
|
||||||
uint8_t imcrp;
|
uchar imcrp;
|
||||||
uint8_t reserved[3];
|
uchar reserved[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mpctb { /* configuration table header */
|
struct mpctb { /* configuration table header */
|
||||||
uint8_t signature[4]; /* "PCMP" */
|
uchar signature[4]; /* "PCMP" */
|
||||||
uint16_t length; /* total table length */
|
ushort length; /* total table length */
|
||||||
uint8_t version; /* [14] */
|
uchar version; /* [14] */
|
||||||
uint8_t checksum; /* all bytes must add up to 0 */
|
uchar checksum; /* all bytes must add up to 0 */
|
||||||
uint8_t product[20]; /* product id */
|
uchar product[20]; /* product id */
|
||||||
uintptr_t oemtable; /* OEM table pointer */
|
uint * oemtable; /* OEM table pointer */
|
||||||
uint16_t oemlength; /* OEM table length */
|
ushort oemlength; /* OEM table length */
|
||||||
uint16_t entry; /* entry count */
|
ushort entry; /* entry count */
|
||||||
uintptr_t lapicaddr; /* address of local APIC */
|
uint * lapicaddr; /* address of local APIC */
|
||||||
uint16_t xlength; /* extended table length */
|
ushort xlength; /* extended table length */
|
||||||
uint8_t xchecksum; /* extended table checksum */
|
uchar xchecksum; /* extended table checksum */
|
||||||
uint8_t reserved;
|
uchar reserved;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mppe { /* processor table entry */
|
struct mppe { /* processor table entry */
|
||||||
uint8_t type; /* entry type (0) */
|
uchar type; /* entry type (0) */
|
||||||
uint8_t apicid; /* local APIC id */
|
uchar apicid; /* local APIC id */
|
||||||
uint8_t version; /* local APIC verison */
|
uchar version; /* local APIC verison */
|
||||||
uint8_t flags; /* CPU flags */
|
uchar flags; /* CPU flags */
|
||||||
uint8_t signature[4]; /* CPU signature */
|
uchar signature[4]; /* CPU signature */
|
||||||
uint32_t feature; /* feature flags from CPUID instruction */
|
uint feature; /* feature flags from CPUID instruction */
|
||||||
uint8_t reserved[8];
|
uchar reserved[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mpbe { /* bus table entry */
|
struct mpbe { /* bus table entry */
|
||||||
uint8_t type; /* entry type (1) */
|
uchar type; /* entry type (1) */
|
||||||
uint8_t busno; /* bus id */
|
uchar 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) */
|
uchar type; /* entry type (2) */
|
||||||
uint8_t apicno; /* I/O APIC id */
|
uchar apicno; /* I/O APIC id */
|
||||||
uint8_t version; /* I/O APIC version */
|
uchar version; /* I/O APIC version */
|
||||||
uint8_t flags; /* I/O APIC flags */
|
uchar flags; /* I/O APIC flags */
|
||||||
uintptr_t addr; /* I/O APIC address */
|
uint * addr; /* I/O APIC address */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mpie { /* interrupt table entry */
|
struct mpie { /* interrupt table entry */
|
||||||
uint8_t type; /* entry type ([34]) */
|
uchar type; /* entry type ([34]) */
|
||||||
uint8_t intr; /* interrupt type */
|
uchar intr; /* interrupt type */
|
||||||
uint16_t flags; /* interrupt flag */
|
ushort flags; /* interrupt flag */
|
||||||
uint8_t busno; /* source bus id */
|
uchar busno; /* source bus id */
|
||||||
uint8_t irq; /* source bus irq */
|
uchar irq; /* source bus irq */
|
||||||
uint8_t apicno; /* destination APIC id */
|
uchar apicno; /* destination APIC id */
|
||||||
uint8_t intin; /* destination APIC [L]INTIN# */
|
uchar intin; /* destination APIC [L]INTIN# */
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { /* table entry types */
|
enum { /* table entry types */
|
||||||
|
|
4
picirq.c
4
picirq.c
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
// Current IRQ mask.
|
// Current IRQ mask.
|
||||||
// Initial IRQ mask has interrupt 2 enabled (for slave 8259A).
|
// Initial IRQ mask has interrupt 2 enabled (for slave 8259A).
|
||||||
uint16_t irq_mask_8259A = 0xFFFF & ~(1<<IRQ_SLAVE);
|
ushort irq_mask_8259A = 0xFFFF & ~(1<<IRQ_SLAVE);
|
||||||
|
|
||||||
/* Initialize the 8259A interrupt controllers. */
|
/* Initialize the 8259A interrupt controllers. */
|
||||||
void
|
void
|
||||||
|
@ -71,7 +71,7 @@ pic_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
irq_setmask_8259A(uint16_t mask)
|
irq_setmask_8259A(ushort mask)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
irq_mask_8259A = mask;
|
irq_mask_8259A = mask;
|
||||||
|
|
2
proc.h
2
proc.h
|
@ -65,7 +65,7 @@ extern struct proc *curproc[NCPU]; // can be NULL if no proc running.
|
||||||
#define MPSTACK 512
|
#define MPSTACK 512
|
||||||
|
|
||||||
struct cpu {
|
struct cpu {
|
||||||
uint8_t apicid; // Local APIC ID
|
uchar apicid; // Local APIC ID
|
||||||
struct jmpbuf jmpbuf;
|
struct jmpbuf jmpbuf;
|
||||||
char mpstack[MPSTACK]; // per-cpu start-up stack, only used to get into main()
|
char mpstack[MPSTACK]; // per-cpu start-up stack, only used to get into main()
|
||||||
struct proc *lastproc; // last proc scheduled on this cpu (never NULL)
|
struct proc *lastproc; // last proc scheduled on this cpu (never NULL)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
struct spinlock {
|
struct spinlock {
|
||||||
uint locked;
|
uint locked;
|
||||||
uint32_t pc;
|
uint pc;
|
||||||
int cpu;
|
int cpu;
|
||||||
};
|
};
|
||||||
|
|
6
string.c
6
string.c
|
@ -15,8 +15,8 @@ memset(void *dst, int c, uint n)
|
||||||
int
|
int
|
||||||
memcmp(const void *v1, const void *v2, uint n)
|
memcmp(const void *v1, const void *v2, uint n)
|
||||||
{
|
{
|
||||||
const uint8_t *s1 = (const uint8_t *) v1;
|
const uchar *s1 = (const uchar *) v1;
|
||||||
const uint8_t *s2 = (const uint8_t *) v2;
|
const uchar *s2 = (const uchar *) v2;
|
||||||
|
|
||||||
while (n-- > 0) {
|
while (n-- > 0) {
|
||||||
if (*s1 != *s2)
|
if (*s1 != *s2)
|
||||||
|
@ -55,7 +55,7 @@ strncmp(const char *p, const char *q, uint n)
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
return (int) ((uint8_t) *p - (uint8_t) *q);
|
return (int) ((uchar) *p - (uchar) *q);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Memcpy is deprecated and should NOT be called.
|
// Memcpy is deprecated and should NOT be called.
|
||||||
|
|
|
@ -235,8 +235,10 @@ sys_block(void)
|
||||||
if ((c = ide_start_read(i, buf, 1)) == 0) {
|
if ((c = ide_start_read(i, buf, 1)) == 0) {
|
||||||
panic("couldn't start read\n");
|
panic("couldn't start read\n");
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
cprintf("call sleep\n");
|
cprintf("call sleep\n");
|
||||||
sleep (c, &ide_lock);
|
sleep (c, &ide_lock);
|
||||||
|
#endif
|
||||||
if (ide_finish_read(c)) {
|
if (ide_finish_read(c)) {
|
||||||
panic("couldn't do read\n");
|
panic("couldn't do read\n");
|
||||||
}
|
}
|
||||||
|
|
12
types.h
12
types.h
|
@ -1,9 +1,3 @@
|
||||||
typedef unsigned int uint;
|
typedef unsigned int uint;
|
||||||
|
typedef unsigned short ushort;
|
||||||
typedef unsigned long long uint64_t;
|
typedef unsigned char uchar;
|
||||||
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;
|
|
||||||
|
|
177
x86.h
177
x86.h
|
@ -1,37 +1,36 @@
|
||||||
static __inline void breakpoint(void) __attribute__((always_inline));
|
static __inline void breakpoint(void) __attribute__((always_inline));
|
||||||
static __inline uint8_t inb(int port) __attribute__((always_inline));
|
static __inline uchar inb(int port) __attribute__((always_inline));
|
||||||
static __inline void insb(int port, void *addr, int cnt) __attribute__((always_inline));
|
static __inline void insb(int port, void *addr, int cnt) __attribute__((always_inline));
|
||||||
static __inline uint16_t inw(int port) __attribute__((always_inline));
|
static __inline ushort inw(int port) __attribute__((always_inline));
|
||||||
static __inline void insw(int port, void *addr, int cnt) __attribute__((always_inline));
|
static __inline void insw(int port, void *addr, int cnt) __attribute__((always_inline));
|
||||||
static __inline uint32_t inl(int port) __attribute__((always_inline));
|
static __inline uint inl(int port) __attribute__((always_inline));
|
||||||
static __inline void insl(int port, void *addr, int cnt) __attribute__((always_inline));
|
static __inline void insl(int port, void *addr, int cnt) __attribute__((always_inline));
|
||||||
static __inline void outb(int port, uint8_t data) __attribute__((always_inline));
|
static __inline void outb(int port, uchar data) __attribute__((always_inline));
|
||||||
static __inline void outsb(int port, const void *addr, int cnt) __attribute__((always_inline));
|
static __inline void outsb(int port, const void *addr, int cnt) __attribute__((always_inline));
|
||||||
static __inline void outw(int port, uint16_t data) __attribute__((always_inline));
|
static __inline void outw(int port, ushort data) __attribute__((always_inline));
|
||||||
static __inline void outsw(int port, const void *addr, int cnt) __attribute__((always_inline));
|
static __inline void outsw(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 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, uint 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(ushort sel) __attribute__((always_inline));
|
||||||
static __inline void ltr(uint16_t sel) __attribute__((always_inline));
|
static __inline void ltr(ushort sel) __attribute__((always_inline));
|
||||||
static __inline void lcr0(uint32_t val) __attribute__((always_inline));
|
static __inline void lcr0(uint val) __attribute__((always_inline));
|
||||||
static __inline uint32_t rcr0(void) __attribute__((always_inline));
|
static __inline uint rcr0(void) __attribute__((always_inline));
|
||||||
static __inline uint32_t rcr2(void) __attribute__((always_inline));
|
static __inline uint rcr2(void) __attribute__((always_inline));
|
||||||
static __inline void lcr3(uint32_t val) __attribute__((always_inline));
|
static __inline void lcr3(uint val) __attribute__((always_inline));
|
||||||
static __inline uint32_t rcr3(void) __attribute__((always_inline));
|
static __inline uint rcr3(void) __attribute__((always_inline));
|
||||||
static __inline void lcr4(uint32_t val) __attribute__((always_inline));
|
static __inline void lcr4(uint val) __attribute__((always_inline));
|
||||||
static __inline uint32_t rcr4(void) __attribute__((always_inline));
|
static __inline uint rcr4(void) __attribute__((always_inline));
|
||||||
static __inline void tlbflush(void) __attribute__((always_inline));
|
static __inline void tlbflush(void) __attribute__((always_inline));
|
||||||
static __inline uint32_t read_eflags(void) __attribute__((always_inline));
|
static __inline uint read_eflags(void) __attribute__((always_inline));
|
||||||
static __inline void write_eflags(uint32_t eflags) __attribute__((always_inline));
|
static __inline void write_eflags(uint eflags) __attribute__((always_inline));
|
||||||
static __inline uint32_t read_ebp(void) __attribute__((always_inline));
|
static __inline uint read_ebp(void) __attribute__((always_inline));
|
||||||
static __inline uint32_t read_esp(void) __attribute__((always_inline));
|
static __inline uint read_esp(void) __attribute__((always_inline));
|
||||||
static __inline void cpuid(uint32_t info, uint32_t *eaxp, uint32_t *ebxp, uint32_t *ecxp, uint32_t *edxp);
|
static __inline void cpuid(uint info, uint *eaxp, uint *ebxp, uint *ecxp, uint *edxp);
|
||||||
static __inline uint64_t read_tsc(void) __attribute__((always_inline));
|
|
||||||
static __inline void cli(void) __attribute__((always_inline));
|
static __inline void cli(void) __attribute__((always_inline));
|
||||||
static __inline void sti(void) __attribute__((always_inline));
|
static __inline void sti(void) __attribute__((always_inline));
|
||||||
|
|
||||||
|
@ -41,10 +40,10 @@ breakpoint(void)
|
||||||
__asm __volatile("int3");
|
__asm __volatile("int3");
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline uint8_t
|
static __inline uchar
|
||||||
inb(int port)
|
inb(int port)
|
||||||
{
|
{
|
||||||
uint8_t data;
|
uchar data;
|
||||||
__asm __volatile("inb %w1,%0" : "=a" (data) : "d" (port));
|
__asm __volatile("inb %w1,%0" : "=a" (data) : "d" (port));
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -58,10 +57,10 @@ insb(int port, void *addr, int cnt)
|
||||||
"memory", "cc");
|
"memory", "cc");
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline uint16_t
|
static __inline ushort
|
||||||
inw(int port)
|
inw(int port)
|
||||||
{
|
{
|
||||||
uint16_t data;
|
ushort data;
|
||||||
__asm __volatile("inw %w1,%0" : "=a" (data) : "d" (port));
|
__asm __volatile("inw %w1,%0" : "=a" (data) : "d" (port));
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -75,10 +74,10 @@ insw(int port, void *addr, int cnt)
|
||||||
"memory", "cc");
|
"memory", "cc");
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline uint32_t
|
static __inline uint
|
||||||
inl(int port)
|
inl(int port)
|
||||||
{
|
{
|
||||||
uint32_t data;
|
uint data;
|
||||||
__asm __volatile("inl %w1,%0" : "=a" (data) : "d" (port));
|
__asm __volatile("inl %w1,%0" : "=a" (data) : "d" (port));
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -93,7 +92,7 @@ insl(int port, void *addr, int cnt)
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline void
|
static __inline void
|
||||||
outb(int port, uint8_t data)
|
outb(int port, uchar data)
|
||||||
{
|
{
|
||||||
__asm __volatile("outb %0,%w1" : : "a" (data), "d" (port));
|
__asm __volatile("outb %0,%w1" : : "a" (data), "d" (port));
|
||||||
}
|
}
|
||||||
|
@ -108,7 +107,7 @@ outsb(int port, const void *addr, int cnt)
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline void
|
static __inline void
|
||||||
outw(int port, uint16_t data)
|
outw(int port, ushort data)
|
||||||
{
|
{
|
||||||
__asm __volatile("outw %0,%w1" : : "a" (data), "d" (port));
|
__asm __volatile("outw %0,%w1" : : "a" (data), "d" (port));
|
||||||
}
|
}
|
||||||
|
@ -132,7 +131,7 @@ outsl(int port, const void *addr, int cnt)
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline void
|
static __inline void
|
||||||
outl(int port, uint32_t data)
|
outl(int port, uint data)
|
||||||
{
|
{
|
||||||
__asm __volatile("outl %0,%w1" : : "a" (data), "d" (port));
|
__asm __volatile("outl %0,%w1" : : "a" (data), "d" (port));
|
||||||
}
|
}
|
||||||
|
@ -146,7 +145,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 ushort pd[3];
|
||||||
|
|
||||||
pd[0] = size-1;
|
pd[0] = size-1;
|
||||||
pd[1] = (uint)p;
|
pd[1] = (uint)p;
|
||||||
|
@ -158,7 +157,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 ushort pd[3];
|
||||||
|
|
||||||
pd[0] = size-1;
|
pd[0] = size-1;
|
||||||
pd[1] = (uint)p;
|
pd[1] = (uint)p;
|
||||||
|
@ -168,63 +167,63 @@ lidt(struct gatedesc *p, int size)
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline void
|
static __inline void
|
||||||
lldt(uint16_t sel)
|
lldt(ushort sel)
|
||||||
{
|
{
|
||||||
__asm __volatile("lldt %0" : : "r" (sel));
|
__asm __volatile("lldt %0" : : "r" (sel));
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline void
|
static __inline void
|
||||||
ltr(uint16_t sel)
|
ltr(ushort sel)
|
||||||
{
|
{
|
||||||
__asm __volatile("ltr %0" : : "r" (sel));
|
__asm __volatile("ltr %0" : : "r" (sel));
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline void
|
static __inline void
|
||||||
lcr0(uint32_t val)
|
lcr0(uint val)
|
||||||
{
|
{
|
||||||
__asm __volatile("movl %0,%%cr0" : : "r" (val));
|
__asm __volatile("movl %0,%%cr0" : : "r" (val));
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline uint32_t
|
static __inline uint
|
||||||
rcr0(void)
|
rcr0(void)
|
||||||
{
|
{
|
||||||
uint32_t val;
|
uint val;
|
||||||
__asm __volatile("movl %%cr0,%0" : "=r" (val));
|
__asm __volatile("movl %%cr0,%0" : "=r" (val));
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline uint32_t
|
static __inline uint
|
||||||
rcr2(void)
|
rcr2(void)
|
||||||
{
|
{
|
||||||
uint32_t val;
|
uint val;
|
||||||
__asm __volatile("movl %%cr2,%0" : "=r" (val));
|
__asm __volatile("movl %%cr2,%0" : "=r" (val));
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline void
|
static __inline void
|
||||||
lcr3(uint32_t val)
|
lcr3(uint val)
|
||||||
{
|
{
|
||||||
__asm __volatile("movl %0,%%cr3" : : "r" (val));
|
__asm __volatile("movl %0,%%cr3" : : "r" (val));
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline uint32_t
|
static __inline uint
|
||||||
rcr3(void)
|
rcr3(void)
|
||||||
{
|
{
|
||||||
uint32_t val;
|
uint val;
|
||||||
__asm __volatile("movl %%cr3,%0" : "=r" (val));
|
__asm __volatile("movl %%cr3,%0" : "=r" (val));
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline void
|
static __inline void
|
||||||
lcr4(uint32_t val)
|
lcr4(uint val)
|
||||||
{
|
{
|
||||||
__asm __volatile("movl %0,%%cr4" : : "r" (val));
|
__asm __volatile("movl %0,%%cr4" : : "r" (val));
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline uint32_t
|
static __inline uint
|
||||||
rcr4(void)
|
rcr4(void)
|
||||||
{
|
{
|
||||||
uint32_t cr4;
|
uint cr4;
|
||||||
__asm __volatile("movl %%cr4,%0" : "=r" (cr4));
|
__asm __volatile("movl %%cr4,%0" : "=r" (cr4));
|
||||||
return cr4;
|
return cr4;
|
||||||
}
|
}
|
||||||
|
@ -232,69 +231,69 @@ rcr4(void)
|
||||||
static __inline void
|
static __inline void
|
||||||
tlbflush(void)
|
tlbflush(void)
|
||||||
{
|
{
|
||||||
uint32_t cr3;
|
uint cr3;
|
||||||
__asm __volatile("movl %%cr3,%0" : "=r" (cr3));
|
__asm __volatile("movl %%cr3,%0" : "=r" (cr3));
|
||||||
__asm __volatile("movl %0,%%cr3" : : "r" (cr3));
|
__asm __volatile("movl %0,%%cr3" : : "r" (cr3));
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline uint32_t
|
static __inline uint
|
||||||
read_eflags(void)
|
read_eflags(void)
|
||||||
{
|
{
|
||||||
uint32_t eflags;
|
uint eflags;
|
||||||
__asm __volatile("pushfl; popl %0" : "=r" (eflags));
|
__asm __volatile("pushfl; popl %0" : "=r" (eflags));
|
||||||
return eflags;
|
return eflags;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline void
|
static __inline void
|
||||||
write_eflags(uint32_t eflags)
|
write_eflags(uint eflags)
|
||||||
{
|
{
|
||||||
__asm __volatile("pushl %0; popfl" : : "r" (eflags));
|
__asm __volatile("pushl %0; popfl" : : "r" (eflags));
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline uint32_t
|
static __inline uint
|
||||||
read_ebp(void)
|
read_ebp(void)
|
||||||
{
|
{
|
||||||
uint32_t ebp;
|
uint ebp;
|
||||||
__asm __volatile("movl %%ebp,%0" : "=r" (ebp));
|
__asm __volatile("movl %%ebp,%0" : "=r" (ebp));
|
||||||
return ebp;
|
return ebp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline uint32_t
|
static __inline uint
|
||||||
read_esp(void)
|
read_esp(void)
|
||||||
{
|
{
|
||||||
uint32_t esp;
|
uint esp;
|
||||||
__asm __volatile("movl %%esp,%0" : "=r" (esp));
|
__asm __volatile("movl %%esp,%0" : "=r" (esp));
|
||||||
return esp;
|
return esp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline uint32_t
|
static __inline uint
|
||||||
read_esi(void)
|
read_esi(void)
|
||||||
{
|
{
|
||||||
uint32_t esi;
|
uint esi;
|
||||||
__asm __volatile("movl %%esi,%0" : "=r" (esi));
|
__asm __volatile("movl %%esi,%0" : "=r" (esi));
|
||||||
return esi;
|
return esi;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline uint32_t
|
static __inline uint
|
||||||
read_edi(void)
|
read_edi(void)
|
||||||
{
|
{
|
||||||
uint32_t edi;
|
uint edi;
|
||||||
__asm __volatile("movl %%edi,%0" : "=r" (edi));
|
__asm __volatile("movl %%edi,%0" : "=r" (edi));
|
||||||
return edi;
|
return edi;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline uint32_t
|
static __inline uint
|
||||||
read_ebx(void)
|
read_ebx(void)
|
||||||
{
|
{
|
||||||
uint32_t ebx;
|
uint ebx;
|
||||||
__asm __volatile("movl %%ebx,%0" : "=r" (ebx));
|
__asm __volatile("movl %%ebx,%0" : "=r" (ebx));
|
||||||
return ebx;
|
return ebx;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline void
|
static __inline void
|
||||||
cpuid(uint32_t info, uint32_t *eaxp, uint32_t *ebxp, uint32_t *ecxp, uint32_t *edxp)
|
cpuid(uint info, uint *eaxp, uint *ebxp, uint *ecxp, uint *edxp)
|
||||||
{
|
{
|
||||||
uint32_t eax, ebx, ecx, edx;
|
uint eax, ebx, ecx, edx;
|
||||||
asm volatile("cpuid"
|
asm volatile("cpuid"
|
||||||
: "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
|
: "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
|
||||||
: "a" (info));
|
: "a" (info));
|
||||||
|
@ -308,10 +307,10 @@ cpuid(uint32_t info, uint32_t *eaxp, uint32_t *ebxp, uint32_t *ecxp, uint32_t *e
|
||||||
*edxp = edx;
|
*edxp = edx;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline uint32_t
|
static __inline uint
|
||||||
cmpxchg(uint32_t oldval, uint32_t newval, volatile uint32_t* lock_addr)
|
cmpxchg(uint oldval, uint newval, volatile uint* lock_addr)
|
||||||
{
|
{
|
||||||
uint32_t result;
|
uint result;
|
||||||
__asm__ __volatile__(
|
__asm__ __volatile__(
|
||||||
"lock; cmpxchgl %2, %0"
|
"lock; cmpxchgl %2, %0"
|
||||||
:"+m" (*lock_addr), "=a" (result) : "r"(newval), "1"(oldval) : "cc"
|
:"+m" (*lock_addr), "=a" (result) : "r"(newval), "1"(oldval) : "cc"
|
||||||
|
@ -319,14 +318,6 @@ cmpxchg(uint32_t oldval, uint32_t newval, volatile uint32_t* lock_addr)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline uint64_t
|
|
||||||
read_tsc(void)
|
|
||||||
{
|
|
||||||
uint64_t tsc;
|
|
||||||
__asm __volatile("rdtsc" : "=A" (tsc));
|
|
||||||
return tsc;
|
|
||||||
}
|
|
||||||
|
|
||||||
static __inline void
|
static __inline void
|
||||||
cli(void)
|
cli(void)
|
||||||
{
|
{
|
||||||
|
@ -341,30 +332,30 @@ sti(void)
|
||||||
|
|
||||||
struct trapframe {
|
struct trapframe {
|
||||||
/* registers as pushed by pusha */
|
/* registers as pushed by pusha */
|
||||||
uint32_t edi;
|
uint edi;
|
||||||
uint32_t esi;
|
uint esi;
|
||||||
uint32_t ebp;
|
uint ebp;
|
||||||
uint32_t oesp; /* Useless */
|
uint oesp; /* Useless */
|
||||||
uint32_t ebx;
|
uint ebx;
|
||||||
uint32_t edx;
|
uint edx;
|
||||||
uint32_t ecx;
|
uint ecx;
|
||||||
uint32_t eax;
|
uint eax;
|
||||||
/* rest of trap frame */
|
/* rest of trap frame */
|
||||||
uint16_t es;
|
ushort es;
|
||||||
uint16_t padding1;
|
ushort padding1;
|
||||||
uint16_t ds;
|
ushort ds;
|
||||||
uint16_t padding2;
|
ushort padding2;
|
||||||
uint32_t trapno;
|
uint trapno;
|
||||||
/* below here defined by x86 hardware */
|
/* below here defined by x86 hardware */
|
||||||
uint32_t err;
|
uint err;
|
||||||
uintptr_t eip;
|
uint eip;
|
||||||
uint16_t cs;
|
ushort cs;
|
||||||
uint16_t padding3;
|
ushort padding3;
|
||||||
uint32_t eflags;
|
uint eflags;
|
||||||
/* below here only when crossing rings, such as from user to kernel */
|
/* below here only when crossing rings, such as from user to kernel */
|
||||||
uintptr_t esp;
|
uint esp;
|
||||||
uint16_t ss;
|
ushort ss;
|
||||||
uint16_t padding4;
|
ushort padding4;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAX_IRQS 16 // Number of IRQs
|
#define MAX_IRQS 16 // Number of IRQs
|
||||||
|
|
Loading…
Reference in a new issue