update codes
This commit is contained in:
parent
c417874aa8
commit
92c553113b
@ -97,7 +97,7 @@ struct e820map {
|
|||||||
* that convert Page to other data types, such as phyical address.
|
* that convert Page to other data types, such as phyical address.
|
||||||
* */
|
* */
|
||||||
struct Page {
|
struct Page {
|
||||||
atomic_t ref; // page frame's reference counter
|
int ref; // page frame's reference counter
|
||||||
uint32_t flags; // array of flags that describe the status of the page frame
|
uint32_t flags; // array of flags that describe the status of the page frame
|
||||||
unsigned int property; // the num of free block, used in first fit pm manager
|
unsigned int property; // the num of free block, used in first fit pm manager
|
||||||
list_entry_t page_link; // free list link
|
list_entry_t page_link; // free list link
|
||||||
|
@ -117,22 +117,24 @@ pde2page(pde_t pde) {
|
|||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref(struct Page *page) {
|
page_ref(struct Page *page) {
|
||||||
return atomic_read(&(page->ref));
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
set_page_ref(struct Page *page, int val) {
|
set_page_ref(struct Page *page, int val) {
|
||||||
atomic_set(&(page->ref), val);
|
page->ref = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref_inc(struct Page *page) {
|
page_ref_inc(struct Page *page) {
|
||||||
return atomic_add_return(&(page->ref), 1);
|
page->ref += 1;
|
||||||
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref_dec(struct Page *page) {
|
page_ref_dec(struct Page *page) {
|
||||||
return atomic_sub_return(&(page->ref), 1);
|
page->ref -= 1;
|
||||||
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern char bootstack[], bootstacktop[];
|
extern char bootstack[], bootstacktop[];
|
||||||
|
@ -3,167 +3,9 @@
|
|||||||
|
|
||||||
/* Atomic operations that C can't guarantee us. Useful for resource counting etc.. */
|
/* Atomic operations that C can't guarantee us. Useful for resource counting etc.. */
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
volatile int counter;
|
|
||||||
} atomic_t;
|
|
||||||
|
|
||||||
static inline int atomic_read(const atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline void atomic_set(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_add(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_sub(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_sub_test_zero(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_inc(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline void atomic_dec(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_inc_test_zero(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_dec_test_zero(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline int atomic_add_return(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline int atomic_sub_return(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_read - read atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically reads the value of @v.
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_read(const atomic_t *v) {
|
|
||||||
return v->counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_set - set atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: required value
|
|
||||||
*
|
|
||||||
* Atomically sets the value of @v to @i.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_set(atomic_t *v, int i) {
|
|
||||||
v->counter = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_add - add integer to atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to add
|
|
||||||
*
|
|
||||||
* Atomically adds @i to @v.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_add(atomic_t *v, int i) {
|
|
||||||
asm volatile ("addl %1, %0" : "+m" (v->counter) : "ir" (i));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub - subtract integer from atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_sub(atomic_t *v, int i) {
|
|
||||||
asm volatile("subl %1, %0" : "+m" (v->counter) : "ir" (i));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub_test_zero - subtract value from variable and test result
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v and
|
|
||||||
* returns true if the result is zero, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_sub_test_zero(atomic_t *v, int i) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("subl %2, %0; sete %1" : "+m" (v->counter), "=qm" (c) : "ir" (i) : "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_inc - increment atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically increments @v by 1.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_inc(atomic_t *v) {
|
|
||||||
asm volatile("incl %0" : "+m" (v->counter));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_dec - decrement atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically decrements @v by 1.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_dec(atomic_t *v) {
|
|
||||||
asm volatile("decl %0" : "+m" (v->counter));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_inc_test_zero - increment and test
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically increments @v by 1 and
|
|
||||||
* returns true if the result is zero, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_inc_test_zero(atomic_t *v) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("incl %0; sete %1" : "+m" (v->counter), "=qm" (c) :: "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_dec_test_zero - decrement and test
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically decrements @v by 1 and
|
|
||||||
* returns true if the result is 0, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_dec_test_zero(atomic_t *v) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("decl %0; sete %1" : "+m" (v->counter), "=qm" (c) :: "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_add_return - add integer and return
|
|
||||||
* @i: integer value to add
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically adds @i to @v and returns @i + @v
|
|
||||||
* Requires Modern 486+ processor
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_add_return(atomic_t *v, int i) {
|
|
||||||
int __i = i;
|
|
||||||
asm volatile("xaddl %0, %1" : "+r" (i), "+m" (v->counter) :: "memory");
|
|
||||||
return i + __i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub_return - subtract integer and return
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v and returns @v - @i
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_sub_return(atomic_t *v, int i) {
|
|
||||||
return atomic_add_return(v, -i);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline void clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline void change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline bool test_and_set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_and_clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_and_change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline bool test_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
|
|
||||||
/* *
|
/* *
|
||||||
@ -199,42 +41,6 @@ change_bit(int nr, volatile void *addr) {
|
|||||||
asm volatile ("btcl %1, %0" :"=m" (*(volatile long *)addr) : "Ir" (nr));
|
asm volatile ("btcl %1, %0" :"=m" (*(volatile long *)addr) : "Ir" (nr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_set_bit - Atomically set a bit and return its old value
|
|
||||||
* @nr: the bit to set
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_set_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btsl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_clear_bit - Atomically clear a bit and return its old value
|
|
||||||
* @nr: the bit to clear
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_clear_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btrl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_change_bit - Atomically change a bit and return its old value
|
|
||||||
* @nr: the bit to change
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_change_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btcl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
/* *
|
||||||
* test_bit - Determine whether a bit is set
|
* test_bit - Determine whether a bit is set
|
||||||
* @nr: the bit to test
|
* @nr: the bit to test
|
||||||
|
@ -98,7 +98,7 @@ struct e820map {
|
|||||||
* that convert Page to other data types, such as phyical address.
|
* that convert Page to other data types, such as phyical address.
|
||||||
* */
|
* */
|
||||||
struct Page {
|
struct Page {
|
||||||
atomic_t ref; // page frame's reference counter
|
int ref; // page frame's reference counter
|
||||||
uint32_t flags; // array of flags that describe the status of the page frame
|
uint32_t flags; // array of flags that describe the status of the page frame
|
||||||
unsigned int property; // the num of free block, used in first fit pm manager
|
unsigned int property; // the num of free block, used in first fit pm manager
|
||||||
list_entry_t page_link; // free list link
|
list_entry_t page_link; // free list link
|
||||||
|
@ -118,22 +118,24 @@ pde2page(pde_t pde) {
|
|||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref(struct Page *page) {
|
page_ref(struct Page *page) {
|
||||||
return atomic_read(&(page->ref));
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
set_page_ref(struct Page *page, int val) {
|
set_page_ref(struct Page *page, int val) {
|
||||||
atomic_set(&(page->ref), val);
|
page->ref = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref_inc(struct Page *page) {
|
page_ref_inc(struct Page *page) {
|
||||||
return atomic_add_return(&(page->ref), 1);
|
page->ref += 1;
|
||||||
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref_dec(struct Page *page) {
|
page_ref_dec(struct Page *page) {
|
||||||
return atomic_sub_return(&(page->ref), 1);
|
page->ref -= 1;
|
||||||
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern char bootstack[], bootstacktop[];
|
extern char bootstack[], bootstacktop[];
|
||||||
|
@ -3,167 +3,9 @@
|
|||||||
|
|
||||||
/* Atomic operations that C can't guarantee us. Useful for resource counting etc.. */
|
/* Atomic operations that C can't guarantee us. Useful for resource counting etc.. */
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
volatile int counter;
|
|
||||||
} atomic_t;
|
|
||||||
|
|
||||||
static inline int atomic_read(const atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline void atomic_set(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_add(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_sub(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_sub_test_zero(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_inc(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline void atomic_dec(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_inc_test_zero(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_dec_test_zero(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline int atomic_add_return(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline int atomic_sub_return(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_read - read atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically reads the value of @v.
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_read(const atomic_t *v) {
|
|
||||||
return v->counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_set - set atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: required value
|
|
||||||
*
|
|
||||||
* Atomically sets the value of @v to @i.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_set(atomic_t *v, int i) {
|
|
||||||
v->counter = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_add - add integer to atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to add
|
|
||||||
*
|
|
||||||
* Atomically adds @i to @v.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_add(atomic_t *v, int i) {
|
|
||||||
asm volatile ("addl %1, %0" : "+m" (v->counter) : "ir" (i));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub - subtract integer from atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_sub(atomic_t *v, int i) {
|
|
||||||
asm volatile("subl %1, %0" : "+m" (v->counter) : "ir" (i));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub_test_zero - subtract value from variable and test result
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v and
|
|
||||||
* returns true if the result is zero, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_sub_test_zero(atomic_t *v, int i) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("subl %2, %0; sete %1" : "+m" (v->counter), "=qm" (c) : "ir" (i) : "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_inc - increment atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically increments @v by 1.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_inc(atomic_t *v) {
|
|
||||||
asm volatile("incl %0" : "+m" (v->counter));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_dec - decrement atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically decrements @v by 1.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_dec(atomic_t *v) {
|
|
||||||
asm volatile("decl %0" : "+m" (v->counter));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_inc_test_zero - increment and test
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically increments @v by 1 and
|
|
||||||
* returns true if the result is zero, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_inc_test_zero(atomic_t *v) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("incl %0; sete %1" : "+m" (v->counter), "=qm" (c) :: "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_dec_test_zero - decrement and test
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically decrements @v by 1 and
|
|
||||||
* returns true if the result is 0, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_dec_test_zero(atomic_t *v) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("decl %0; sete %1" : "+m" (v->counter), "=qm" (c) :: "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_add_return - add integer and return
|
|
||||||
* @i: integer value to add
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically adds @i to @v and returns @i + @v
|
|
||||||
* Requires Modern 486+ processor
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_add_return(atomic_t *v, int i) {
|
|
||||||
int __i = i;
|
|
||||||
asm volatile("xaddl %0, %1" : "+r" (i), "+m" (v->counter) :: "memory");
|
|
||||||
return i + __i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub_return - subtract integer and return
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v and returns @v - @i
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_sub_return(atomic_t *v, int i) {
|
|
||||||
return atomic_add_return(v, -i);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline void clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline void change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline bool test_and_set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_and_clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_and_change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline bool test_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
|
|
||||||
/* *
|
/* *
|
||||||
@ -199,42 +41,6 @@ change_bit(int nr, volatile void *addr) {
|
|||||||
asm volatile ("btcl %1, %0" :"=m" (*(volatile long *)addr) : "Ir" (nr));
|
asm volatile ("btcl %1, %0" :"=m" (*(volatile long *)addr) : "Ir" (nr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_set_bit - Atomically set a bit and return its old value
|
|
||||||
* @nr: the bit to set
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_set_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btsl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_clear_bit - Atomically clear a bit and return its old value
|
|
||||||
* @nr: the bit to clear
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_clear_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btrl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_change_bit - Atomically change a bit and return its old value
|
|
||||||
* @nr: the bit to change
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_change_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btcl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
/* *
|
||||||
* test_bit - Determine whether a bit is set
|
* test_bit - Determine whether a bit is set
|
||||||
* @nr: the bit to test
|
* @nr: the bit to test
|
||||||
|
@ -98,7 +98,7 @@ struct e820map {
|
|||||||
* that convert Page to other data types, such as phyical address.
|
* that convert Page to other data types, such as phyical address.
|
||||||
* */
|
* */
|
||||||
struct Page {
|
struct Page {
|
||||||
atomic_t ref; // page frame's reference counter
|
int ref; // page frame's reference counter
|
||||||
uint32_t flags; // array of flags that describe the status of the page frame
|
uint32_t flags; // array of flags that describe the status of the page frame
|
||||||
unsigned int property; // used in buddy system, stores the order (the X in 2^X) of the continuous memory block
|
unsigned int property; // used in buddy system, stores the order (the X in 2^X) of the continuous memory block
|
||||||
int zone_num; // used in buddy system, the No. of zone which the page belongs to
|
int zone_num; // used in buddy system, the No. of zone which the page belongs to
|
||||||
|
@ -122,22 +122,24 @@ pde2page(pde_t pde) {
|
|||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref(struct Page *page) {
|
page_ref(struct Page *page) {
|
||||||
return atomic_read(&(page->ref));
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
set_page_ref(struct Page *page, int val) {
|
set_page_ref(struct Page *page, int val) {
|
||||||
atomic_set(&(page->ref), val);
|
page->ref = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref_inc(struct Page *page) {
|
page_ref_inc(struct Page *page) {
|
||||||
return atomic_add_return(&(page->ref), 1);
|
page->ref += 1;
|
||||||
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref_dec(struct Page *page) {
|
page_ref_dec(struct Page *page) {
|
||||||
return atomic_sub_return(&(page->ref), 1);
|
page->ref -= 1;
|
||||||
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern char bootstack[], bootstacktop[];
|
extern char bootstack[], bootstacktop[];
|
||||||
|
@ -3,167 +3,9 @@
|
|||||||
|
|
||||||
/* Atomic operations that C can't guarantee us. Useful for resource counting etc.. */
|
/* Atomic operations that C can't guarantee us. Useful for resource counting etc.. */
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
volatile int counter;
|
|
||||||
} atomic_t;
|
|
||||||
|
|
||||||
static inline int atomic_read(const atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline void atomic_set(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_add(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_sub(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_sub_test_zero(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_inc(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline void atomic_dec(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_inc_test_zero(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_dec_test_zero(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline int atomic_add_return(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline int atomic_sub_return(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_read - read atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically reads the value of @v.
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_read(const atomic_t *v) {
|
|
||||||
return v->counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_set - set atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: required value
|
|
||||||
*
|
|
||||||
* Atomically sets the value of @v to @i.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_set(atomic_t *v, int i) {
|
|
||||||
v->counter = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_add - add integer to atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to add
|
|
||||||
*
|
|
||||||
* Atomically adds @i to @v.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_add(atomic_t *v, int i) {
|
|
||||||
asm volatile ("addl %1, %0" : "+m" (v->counter) : "ir" (i));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub - subtract integer from atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_sub(atomic_t *v, int i) {
|
|
||||||
asm volatile("subl %1, %0" : "+m" (v->counter) : "ir" (i));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub_test_zero - subtract value from variable and test result
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v and
|
|
||||||
* returns true if the result is zero, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_sub_test_zero(atomic_t *v, int i) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("subl %2, %0; sete %1" : "+m" (v->counter), "=qm" (c) : "ir" (i) : "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_inc - increment atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically increments @v by 1.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_inc(atomic_t *v) {
|
|
||||||
asm volatile("incl %0" : "+m" (v->counter));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_dec - decrement atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically decrements @v by 1.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_dec(atomic_t *v) {
|
|
||||||
asm volatile("decl %0" : "+m" (v->counter));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_inc_test_zero - increment and test
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically increments @v by 1 and
|
|
||||||
* returns true if the result is zero, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_inc_test_zero(atomic_t *v) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("incl %0; sete %1" : "+m" (v->counter), "=qm" (c) :: "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_dec_test_zero - decrement and test
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically decrements @v by 1 and
|
|
||||||
* returns true if the result is 0, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_dec_test_zero(atomic_t *v) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("decl %0; sete %1" : "+m" (v->counter), "=qm" (c) :: "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_add_return - add integer and return
|
|
||||||
* @i: integer value to add
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically adds @i to @v and returns @i + @v
|
|
||||||
* Requires Modern 486+ processor
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_add_return(atomic_t *v, int i) {
|
|
||||||
int __i = i;
|
|
||||||
asm volatile("xaddl %0, %1" : "+r" (i), "+m" (v->counter) :: "memory");
|
|
||||||
return i + __i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub_return - subtract integer and return
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v and returns @v - @i
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_sub_return(atomic_t *v, int i) {
|
|
||||||
return atomic_add_return(v, -i);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline void clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline void change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline bool test_and_set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_and_clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_and_change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline bool test_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
|
|
||||||
/* *
|
/* *
|
||||||
@ -199,42 +41,6 @@ change_bit(int nr, volatile void *addr) {
|
|||||||
asm volatile ("btcl %1, %0" :"=m" (*(volatile long *)addr) : "Ir" (nr));
|
asm volatile ("btcl %1, %0" :"=m" (*(volatile long *)addr) : "Ir" (nr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_set_bit - Atomically set a bit and return its old value
|
|
||||||
* @nr: the bit to set
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_set_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btsl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_clear_bit - Atomically clear a bit and return its old value
|
|
||||||
* @nr: the bit to clear
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_clear_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btrl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_change_bit - Atomically change a bit and return its old value
|
|
||||||
* @nr: the bit to change
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_change_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btcl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
/* *
|
||||||
* test_bit - Determine whether a bit is set
|
* test_bit - Determine whether a bit is set
|
||||||
* @nr: the bit to test
|
* @nr: the bit to test
|
||||||
|
@ -127,7 +127,7 @@ struct e820map {
|
|||||||
* that convert Page to other data types, such as phyical address.
|
* that convert Page to other data types, such as phyical address.
|
||||||
* */
|
* */
|
||||||
struct Page {
|
struct Page {
|
||||||
atomic_t ref; // page frame's reference counter
|
int ref; // page frame's reference counter
|
||||||
uint32_t flags; // array of flags that describe the status of the page frame
|
uint32_t flags; // array of flags that describe the status of the page frame
|
||||||
unsigned int property; // used in buddy system, stores the order (the X in 2^X) of the continuous memory block
|
unsigned int property; // used in buddy system, stores the order (the X in 2^X) of the continuous memory block
|
||||||
int zone_num; // used in buddy system, the No. of zone which the page belongs to
|
int zone_num; // used in buddy system, the No. of zone which the page belongs to
|
||||||
|
@ -121,22 +121,24 @@ pde2page(pde_t pde) {
|
|||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref(struct Page *page) {
|
page_ref(struct Page *page) {
|
||||||
return atomic_read(&(page->ref));
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
set_page_ref(struct Page *page, int val) {
|
set_page_ref(struct Page *page, int val) {
|
||||||
atomic_set(&(page->ref), val);
|
page->ref = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref_inc(struct Page *page) {
|
page_ref_inc(struct Page *page) {
|
||||||
return atomic_add_return(&(page->ref), 1);
|
page->ref += 1;
|
||||||
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref_dec(struct Page *page) {
|
page_ref_dec(struct Page *page) {
|
||||||
return atomic_sub_return(&(page->ref), 1);
|
page->ref -= 1;
|
||||||
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern char bootstack[], bootstacktop[];
|
extern char bootstack[], bootstacktop[];
|
||||||
|
@ -33,7 +33,7 @@ struct mm_struct {
|
|||||||
pde_t *pgdir; // the PDT of these vma
|
pde_t *pgdir; // the PDT of these vma
|
||||||
int map_count; // the count of these vma
|
int map_count; // the count of these vma
|
||||||
void *sm_priv; // the private data for swap manager
|
void *sm_priv; // the private data for swap manager
|
||||||
atomic_t mm_count; // the number ofprocess which shared the mm
|
int mm_count; // the number ofprocess which shared the mm
|
||||||
lock_t mm_lock; // mutex for using dup_mmap fun to duplicat the mm
|
lock_t mm_lock; // mutex for using dup_mmap fun to duplicat the mm
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -64,22 +64,24 @@ bool copy_to_user(struct mm_struct *mm, void *dst, const void *src, size_t len);
|
|||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
mm_count(struct mm_struct *mm) {
|
mm_count(struct mm_struct *mm) {
|
||||||
return atomic_read(&(mm->mm_count));
|
return mm->mm_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
set_mm_count(struct mm_struct *mm, int val) {
|
set_mm_count(struct mm_struct *mm, int val) {
|
||||||
atomic_set(&(mm->mm_count), val);
|
mm->mm_count = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
mm_count_inc(struct mm_struct *mm) {
|
mm_count_inc(struct mm_struct *mm) {
|
||||||
return atomic_add_return(&(mm->mm_count), 1);
|
mm->mm_count += 1;
|
||||||
|
return mm->mm_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
mm_count_dec(struct mm_struct *mm) {
|
mm_count_dec(struct mm_struct *mm) {
|
||||||
return atomic_sub_return(&(mm->mm_count), 1);
|
mm->mm_count -= 1;
|
||||||
|
return mm->mm_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
@ -3,167 +3,9 @@
|
|||||||
|
|
||||||
/* Atomic operations that C can't guarantee us. Useful for resource counting etc.. */
|
/* Atomic operations that C can't guarantee us. Useful for resource counting etc.. */
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
volatile int counter;
|
|
||||||
} atomic_t;
|
|
||||||
|
|
||||||
static inline int atomic_read(const atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline void atomic_set(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_add(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_sub(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_sub_test_zero(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_inc(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline void atomic_dec(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_inc_test_zero(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_dec_test_zero(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline int atomic_add_return(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline int atomic_sub_return(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_read - read atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically reads the value of @v.
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_read(const atomic_t *v) {
|
|
||||||
return v->counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_set - set atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: required value
|
|
||||||
*
|
|
||||||
* Atomically sets the value of @v to @i.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_set(atomic_t *v, int i) {
|
|
||||||
v->counter = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_add - add integer to atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to add
|
|
||||||
*
|
|
||||||
* Atomically adds @i to @v.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_add(atomic_t *v, int i) {
|
|
||||||
asm volatile ("addl %1, %0" : "+m" (v->counter) : "ir" (i));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub - subtract integer from atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_sub(atomic_t *v, int i) {
|
|
||||||
asm volatile("subl %1, %0" : "+m" (v->counter) : "ir" (i));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub_test_zero - subtract value from variable and test result
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v and
|
|
||||||
* returns true if the result is zero, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_sub_test_zero(atomic_t *v, int i) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("subl %2, %0; sete %1" : "+m" (v->counter), "=qm" (c) : "ir" (i) : "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_inc - increment atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically increments @v by 1.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_inc(atomic_t *v) {
|
|
||||||
asm volatile("incl %0" : "+m" (v->counter));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_dec - decrement atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically decrements @v by 1.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_dec(atomic_t *v) {
|
|
||||||
asm volatile("decl %0" : "+m" (v->counter));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_inc_test_zero - increment and test
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically increments @v by 1 and
|
|
||||||
* returns true if the result is zero, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_inc_test_zero(atomic_t *v) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("incl %0; sete %1" : "+m" (v->counter), "=qm" (c) :: "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_dec_test_zero - decrement and test
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically decrements @v by 1 and
|
|
||||||
* returns true if the result is 0, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_dec_test_zero(atomic_t *v) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("decl %0; sete %1" : "+m" (v->counter), "=qm" (c) :: "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_add_return - add integer and return
|
|
||||||
* @i: integer value to add
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically adds @i to @v and returns @i + @v
|
|
||||||
* Requires Modern 486+ processor
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_add_return(atomic_t *v, int i) {
|
|
||||||
int __i = i;
|
|
||||||
asm volatile("xaddl %0, %1" : "+r" (i), "+m" (v->counter) :: "memory");
|
|
||||||
return i + __i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub_return - subtract integer and return
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v and returns @v - @i
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_sub_return(atomic_t *v, int i) {
|
|
||||||
return atomic_add_return(v, -i);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline void clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline void change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline bool test_and_set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_and_clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_and_change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline bool test_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
|
|
||||||
/* *
|
/* *
|
||||||
@ -199,42 +41,6 @@ change_bit(int nr, volatile void *addr) {
|
|||||||
asm volatile ("btcl %1, %0" :"=m" (*(volatile long *)addr) : "Ir" (nr));
|
asm volatile ("btcl %1, %0" :"=m" (*(volatile long *)addr) : "Ir" (nr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_set_bit - Atomically set a bit and return its old value
|
|
||||||
* @nr: the bit to set
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_set_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btsl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_clear_bit - Atomically clear a bit and return its old value
|
|
||||||
* @nr: the bit to clear
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_clear_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btrl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_change_bit - Atomically change a bit and return its old value
|
|
||||||
* @nr: the bit to change
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_change_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btcl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
/* *
|
||||||
* test_bit - Determine whether a bit is set
|
* test_bit - Determine whether a bit is set
|
||||||
* @nr: the bit to test
|
* @nr: the bit to test
|
||||||
|
@ -127,7 +127,7 @@ struct e820map {
|
|||||||
* that convert Page to other data types, such as phyical address.
|
* that convert Page to other data types, such as phyical address.
|
||||||
* */
|
* */
|
||||||
struct Page {
|
struct Page {
|
||||||
atomic_t ref; // page frame's reference counter
|
int ref; // page frame's reference counter
|
||||||
uint32_t flags; // array of flags that describe the status of the page frame
|
uint32_t flags; // array of flags that describe the status of the page frame
|
||||||
unsigned int property; // used in buddy system, stores the order (the X in 2^X) of the continuous memory block
|
unsigned int property; // used in buddy system, stores the order (the X in 2^X) of the continuous memory block
|
||||||
int zone_num; // used in buddy system, the No. of zone which the page belongs to
|
int zone_num; // used in buddy system, the No. of zone which the page belongs to
|
||||||
|
@ -121,22 +121,24 @@ pde2page(pde_t pde) {
|
|||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref(struct Page *page) {
|
page_ref(struct Page *page) {
|
||||||
return atomic_read(&(page->ref));
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
set_page_ref(struct Page *page, int val) {
|
set_page_ref(struct Page *page, int val) {
|
||||||
atomic_set(&(page->ref), val);
|
page->ref = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref_inc(struct Page *page) {
|
page_ref_inc(struct Page *page) {
|
||||||
return atomic_add_return(&(page->ref), 1);
|
page->ref += 1;
|
||||||
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref_dec(struct Page *page) {
|
page_ref_dec(struct Page *page) {
|
||||||
return atomic_sub_return(&(page->ref), 1);
|
page->ref -= 1;
|
||||||
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern char bootstack[], bootstacktop[];
|
extern char bootstack[], bootstacktop[];
|
||||||
|
@ -33,7 +33,7 @@ struct mm_struct {
|
|||||||
pde_t *pgdir; // the PDT of these vma
|
pde_t *pgdir; // the PDT of these vma
|
||||||
int map_count; // the count of these vma
|
int map_count; // the count of these vma
|
||||||
void *sm_priv; // the private data for swap manager
|
void *sm_priv; // the private data for swap manager
|
||||||
atomic_t mm_count; // the number ofprocess which shared the mm
|
int mm_count; // the number ofprocess which shared the mm
|
||||||
lock_t mm_lock; // mutex for using dup_mmap fun to duplicat the mm
|
lock_t mm_lock; // mutex for using dup_mmap fun to duplicat the mm
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -64,22 +64,24 @@ bool copy_to_user(struct mm_struct *mm, void *dst, const void *src, size_t len);
|
|||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
mm_count(struct mm_struct *mm) {
|
mm_count(struct mm_struct *mm) {
|
||||||
return atomic_read(&(mm->mm_count));
|
return mm->mm_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
set_mm_count(struct mm_struct *mm, int val) {
|
set_mm_count(struct mm_struct *mm, int val) {
|
||||||
atomic_set(&(mm->mm_count), val);
|
mm->mm_count = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
mm_count_inc(struct mm_struct *mm) {
|
mm_count_inc(struct mm_struct *mm) {
|
||||||
return atomic_add_return(&(mm->mm_count), 1);
|
mm->mm_count += 1;
|
||||||
|
return mm->mm_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
mm_count_dec(struct mm_struct *mm) {
|
mm_count_dec(struct mm_struct *mm) {
|
||||||
return atomic_sub_return(&(mm->mm_count), 1);
|
mm->mm_count -= 1;
|
||||||
|
return mm->mm_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
@ -3,167 +3,9 @@
|
|||||||
|
|
||||||
/* Atomic operations that C can't guarantee us. Useful for resource counting etc.. */
|
/* Atomic operations that C can't guarantee us. Useful for resource counting etc.. */
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
volatile int counter;
|
|
||||||
} atomic_t;
|
|
||||||
|
|
||||||
static inline int atomic_read(const atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline void atomic_set(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_add(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_sub(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_sub_test_zero(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_inc(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline void atomic_dec(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_inc_test_zero(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_dec_test_zero(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline int atomic_add_return(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline int atomic_sub_return(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_read - read atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically reads the value of @v.
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_read(const atomic_t *v) {
|
|
||||||
return v->counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_set - set atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: required value
|
|
||||||
*
|
|
||||||
* Atomically sets the value of @v to @i.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_set(atomic_t *v, int i) {
|
|
||||||
v->counter = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_add - add integer to atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to add
|
|
||||||
*
|
|
||||||
* Atomically adds @i to @v.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_add(atomic_t *v, int i) {
|
|
||||||
asm volatile ("addl %1, %0" : "+m" (v->counter) : "ir" (i));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub - subtract integer from atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_sub(atomic_t *v, int i) {
|
|
||||||
asm volatile("subl %1, %0" : "+m" (v->counter) : "ir" (i));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub_test_zero - subtract value from variable and test result
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v and
|
|
||||||
* returns true if the result is zero, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_sub_test_zero(atomic_t *v, int i) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("subl %2, %0; sete %1" : "+m" (v->counter), "=qm" (c) : "ir" (i) : "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_inc - increment atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically increments @v by 1.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_inc(atomic_t *v) {
|
|
||||||
asm volatile("incl %0" : "+m" (v->counter));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_dec - decrement atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically decrements @v by 1.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_dec(atomic_t *v) {
|
|
||||||
asm volatile("decl %0" : "+m" (v->counter));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_inc_test_zero - increment and test
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically increments @v by 1 and
|
|
||||||
* returns true if the result is zero, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_inc_test_zero(atomic_t *v) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("incl %0; sete %1" : "+m" (v->counter), "=qm" (c) :: "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_dec_test_zero - decrement and test
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically decrements @v by 1 and
|
|
||||||
* returns true if the result is 0, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_dec_test_zero(atomic_t *v) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("decl %0; sete %1" : "+m" (v->counter), "=qm" (c) :: "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_add_return - add integer and return
|
|
||||||
* @i: integer value to add
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically adds @i to @v and returns @i + @v
|
|
||||||
* Requires Modern 486+ processor
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_add_return(atomic_t *v, int i) {
|
|
||||||
int __i = i;
|
|
||||||
asm volatile("xaddl %0, %1" : "+r" (i), "+m" (v->counter) :: "memory");
|
|
||||||
return i + __i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub_return - subtract integer and return
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v and returns @v - @i
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_sub_return(atomic_t *v, int i) {
|
|
||||||
return atomic_add_return(v, -i);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline void clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline void change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline bool test_and_set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_and_clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_and_change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline bool test_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
|
|
||||||
/* *
|
/* *
|
||||||
@ -199,42 +41,6 @@ change_bit(int nr, volatile void *addr) {
|
|||||||
asm volatile ("btcl %1, %0" :"=m" (*(volatile long *)addr) : "Ir" (nr));
|
asm volatile ("btcl %1, %0" :"=m" (*(volatile long *)addr) : "Ir" (nr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_set_bit - Atomically set a bit and return its old value
|
|
||||||
* @nr: the bit to set
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_set_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btsl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_clear_bit - Atomically clear a bit and return its old value
|
|
||||||
* @nr: the bit to clear
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_clear_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btrl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_change_bit - Atomically change a bit and return its old value
|
|
||||||
* @nr: the bit to change
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_change_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btcl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
/* *
|
||||||
* test_bit - Determine whether a bit is set
|
* test_bit - Determine whether a bit is set
|
||||||
* @nr: the bit to test
|
* @nr: the bit to test
|
||||||
|
@ -127,7 +127,7 @@ struct e820map {
|
|||||||
* that convert Page to other data types, such as phyical address.
|
* that convert Page to other data types, such as phyical address.
|
||||||
* */
|
* */
|
||||||
struct Page {
|
struct Page {
|
||||||
atomic_t ref; // page frame's reference counter
|
int ref; // page frame's reference counter
|
||||||
uint32_t flags; // array of flags that describe the status of the page frame
|
uint32_t flags; // array of flags that describe the status of the page frame
|
||||||
unsigned int property; // used in buddy system, stores the order (the X in 2^X) of the continuous memory block
|
unsigned int property; // used in buddy system, stores the order (the X in 2^X) of the continuous memory block
|
||||||
int zone_num; // used in buddy system, the No. of zone which the page belongs to
|
int zone_num; // used in buddy system, the No. of zone which the page belongs to
|
||||||
|
@ -121,22 +121,24 @@ pde2page(pde_t pde) {
|
|||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref(struct Page *page) {
|
page_ref(struct Page *page) {
|
||||||
return atomic_read(&(page->ref));
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
set_page_ref(struct Page *page, int val) {
|
set_page_ref(struct Page *page, int val) {
|
||||||
atomic_set(&(page->ref), val);
|
page->ref = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref_inc(struct Page *page) {
|
page_ref_inc(struct Page *page) {
|
||||||
return atomic_add_return(&(page->ref), 1);
|
page->ref += 1;
|
||||||
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref_dec(struct Page *page) {
|
page_ref_dec(struct Page *page) {
|
||||||
return atomic_sub_return(&(page->ref), 1);
|
page->ref -= 1;
|
||||||
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern char bootstack[], bootstacktop[];
|
extern char bootstack[], bootstacktop[];
|
||||||
|
@ -35,7 +35,7 @@ struct mm_struct {
|
|||||||
pde_t *pgdir; // the PDT of these vma
|
pde_t *pgdir; // the PDT of these vma
|
||||||
int map_count; // the count of these vma
|
int map_count; // the count of these vma
|
||||||
void *sm_priv; // the private data for swap manager
|
void *sm_priv; // the private data for swap manager
|
||||||
atomic_t mm_count; // the number ofprocess which shared the mm
|
int mm_count; // the number ofprocess which shared the mm
|
||||||
semaphore_t mm_sem; // mutex for using dup_mmap fun to duplicat the mm
|
semaphore_t mm_sem; // mutex for using dup_mmap fun to duplicat the mm
|
||||||
int locked_by; // the lock owner process's pid
|
int locked_by; // the lock owner process's pid
|
||||||
|
|
||||||
@ -68,22 +68,24 @@ bool copy_to_user(struct mm_struct *mm, void *dst, const void *src, size_t len);
|
|||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
mm_count(struct mm_struct *mm) {
|
mm_count(struct mm_struct *mm) {
|
||||||
return atomic_read(&(mm->mm_count));
|
return mm->mm_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
set_mm_count(struct mm_struct *mm, int val) {
|
set_mm_count(struct mm_struct *mm, int val) {
|
||||||
atomic_set(&(mm->mm_count), val);
|
mm->mm_count = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
mm_count_inc(struct mm_struct *mm) {
|
mm_count_inc(struct mm_struct *mm) {
|
||||||
return atomic_add_return(&(mm->mm_count), 1);
|
mm->mm_count += 1;
|
||||||
|
return mm->mm_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
mm_count_dec(struct mm_struct *mm) {
|
mm_count_dec(struct mm_struct *mm) {
|
||||||
return atomic_sub_return(&(mm->mm_count), 1);
|
mm->mm_count -= 1;
|
||||||
|
return mm->mm_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
@ -3,167 +3,9 @@
|
|||||||
|
|
||||||
/* Atomic operations that C can't guarantee us. Useful for resource counting etc.. */
|
/* Atomic operations that C can't guarantee us. Useful for resource counting etc.. */
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
volatile int counter;
|
|
||||||
} atomic_t;
|
|
||||||
|
|
||||||
static inline int atomic_read(const atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline void atomic_set(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_add(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_sub(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_sub_test_zero(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_inc(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline void atomic_dec(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_inc_test_zero(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_dec_test_zero(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline int atomic_add_return(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline int atomic_sub_return(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_read - read atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically reads the value of @v.
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_read(const atomic_t *v) {
|
|
||||||
return v->counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_set - set atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: required value
|
|
||||||
*
|
|
||||||
* Atomically sets the value of @v to @i.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_set(atomic_t *v, int i) {
|
|
||||||
v->counter = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_add - add integer to atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to add
|
|
||||||
*
|
|
||||||
* Atomically adds @i to @v.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_add(atomic_t *v, int i) {
|
|
||||||
asm volatile ("addl %1, %0" : "+m" (v->counter) : "ir" (i));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub - subtract integer from atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_sub(atomic_t *v, int i) {
|
|
||||||
asm volatile("subl %1, %0" : "+m" (v->counter) : "ir" (i));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub_test_zero - subtract value from variable and test result
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v and
|
|
||||||
* returns true if the result is zero, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_sub_test_zero(atomic_t *v, int i) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("subl %2, %0; sete %1" : "+m" (v->counter), "=qm" (c) : "ir" (i) : "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_inc - increment atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically increments @v by 1.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_inc(atomic_t *v) {
|
|
||||||
asm volatile("incl %0" : "+m" (v->counter));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_dec - decrement atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically decrements @v by 1.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_dec(atomic_t *v) {
|
|
||||||
asm volatile("decl %0" : "+m" (v->counter));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_inc_test_zero - increment and test
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically increments @v by 1 and
|
|
||||||
* returns true if the result is zero, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_inc_test_zero(atomic_t *v) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("incl %0; sete %1" : "+m" (v->counter), "=qm" (c) :: "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_dec_test_zero - decrement and test
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically decrements @v by 1 and
|
|
||||||
* returns true if the result is 0, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_dec_test_zero(atomic_t *v) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("decl %0; sete %1" : "+m" (v->counter), "=qm" (c) :: "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_add_return - add integer and return
|
|
||||||
* @i: integer value to add
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically adds @i to @v and returns @i + @v
|
|
||||||
* Requires Modern 486+ processor
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_add_return(atomic_t *v, int i) {
|
|
||||||
int __i = i;
|
|
||||||
asm volatile("xaddl %0, %1" : "+r" (i), "+m" (v->counter) :: "memory");
|
|
||||||
return i + __i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub_return - subtract integer and return
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v and returns @v - @i
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_sub_return(atomic_t *v, int i) {
|
|
||||||
return atomic_add_return(v, -i);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline void clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline void change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline bool test_and_set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_and_clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_and_change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline bool test_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
|
|
||||||
/* *
|
/* *
|
||||||
@ -199,42 +41,6 @@ change_bit(int nr, volatile void *addr) {
|
|||||||
asm volatile ("btcl %1, %0" :"=m" (*(volatile long *)addr) : "Ir" (nr));
|
asm volatile ("btcl %1, %0" :"=m" (*(volatile long *)addr) : "Ir" (nr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_set_bit - Atomically set a bit and return its old value
|
|
||||||
* @nr: the bit to set
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_set_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btsl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_clear_bit - Atomically clear a bit and return its old value
|
|
||||||
* @nr: the bit to clear
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_clear_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btrl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_change_bit - Atomically change a bit and return its old value
|
|
||||||
* @nr: the bit to change
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_change_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btcl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
/* *
|
||||||
* test_bit - Determine whether a bit is set
|
* test_bit - Determine whether a bit is set
|
||||||
* @nr: the bit to test
|
* @nr: the bit to test
|
||||||
|
@ -27,7 +27,7 @@ fd_array_init(struct file *fd_array) {
|
|||||||
int fd;
|
int fd;
|
||||||
struct file *file = fd_array;
|
struct file *file = fd_array;
|
||||||
for (fd = 0; fd < FILES_STRUCT_NENTRY; fd ++, file ++) {
|
for (fd = 0; fd < FILES_STRUCT_NENTRY; fd ++, file ++) {
|
||||||
atomic_set(&(file->open_count), 0);
|
file->open_count = 0;
|
||||||
file->status = FD_NONE, file->fd = fd;
|
file->status = FD_NONE, file->fd = fd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ struct file {
|
|||||||
int fd;
|
int fd;
|
||||||
off_t pos;
|
off_t pos;
|
||||||
struct inode *node;
|
struct inode *node;
|
||||||
atomic_t open_count;
|
int open_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
void fd_array_init(struct file *fd_array);
|
void fd_array_init(struct file *fd_array);
|
||||||
@ -43,17 +43,19 @@ int file_mkfifo(const char *name, uint32_t open_flags);
|
|||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
fopen_count(struct file *file) {
|
fopen_count(struct file *file) {
|
||||||
return atomic_read(&(file->open_count));
|
return file->open_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
fopen_count_inc(struct file *file) {
|
fopen_count_inc(struct file *file) {
|
||||||
return atomic_add_return(&(file->open_count), 1);
|
file->open_count += 1;
|
||||||
|
return file->open_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
fopen_count_dec(struct file *file) {
|
fopen_count_dec(struct file *file) {
|
||||||
return atomic_sub_return(&(file->open_count), 1);
|
file->open_count -= 1;
|
||||||
|
return file->open_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !__KERN_FS_FILE_H__ */
|
#endif /* !__KERN_FS_FILE_H__ */
|
||||||
|
@ -38,7 +38,7 @@ files_create(void) {
|
|||||||
if ((filesp = kmalloc(sizeof(struct files_struct) + FILES_STRUCT_BUFSIZE)) != NULL) {
|
if ((filesp = kmalloc(sizeof(struct files_struct) + FILES_STRUCT_BUFSIZE)) != NULL) {
|
||||||
filesp->pwd = NULL;
|
filesp->pwd = NULL;
|
||||||
filesp->fd_array = (void *)(filesp + 1);
|
filesp->fd_array = (void *)(filesp + 1);
|
||||||
atomic_set(&(filesp->files_count), 0);
|
filesp->files_count = 0;
|
||||||
sem_init(&(filesp->files_sem), 1);
|
sem_init(&(filesp->files_sem), 1);
|
||||||
fd_array_init(filesp->fd_array);
|
fd_array_init(filesp->fd_array);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ struct file;
|
|||||||
struct files_struct {
|
struct files_struct {
|
||||||
struct inode *pwd; // inode of present working directory
|
struct inode *pwd; // inode of present working directory
|
||||||
struct file *fd_array; // opened files array
|
struct file *fd_array; // opened files array
|
||||||
atomic_t files_count; // the number of opened files
|
int files_count; // the number of opened files
|
||||||
semaphore_t files_sem; // lock protect sem
|
semaphore_t files_sem; // lock protect sem
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -42,17 +42,19 @@ int dup_files(struct files_struct *to, struct files_struct *from);
|
|||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
files_count(struct files_struct *filesp) {
|
files_count(struct files_struct *filesp) {
|
||||||
return atomic_read(&(filesp->files_count));
|
return filesp->files_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
files_count_inc(struct files_struct *filesp) {
|
files_count_inc(struct files_struct *filesp) {
|
||||||
return atomic_add_return(&(filesp->files_count), 1);
|
filesp->files_count += 1;
|
||||||
|
return filesp->files_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
files_count_dec(struct files_struct *filesp) {
|
files_count_dec(struct files_struct *filesp) {
|
||||||
return atomic_sub_return(&(filesp->files_count), 1);
|
filesp->files_count -= 1;
|
||||||
|
return filesp->files_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !__KERN_FS_FS_H__ */
|
#endif /* !__KERN_FS_FS_H__ */
|
||||||
|
@ -26,8 +26,8 @@ __alloc_inode(int type) {
|
|||||||
* */
|
* */
|
||||||
void
|
void
|
||||||
inode_init(struct inode *node, const struct inode_ops *ops, struct fs *fs) {
|
inode_init(struct inode *node, const struct inode_ops *ops, struct fs *fs) {
|
||||||
atomic_set(&(node->ref_count), 0);
|
node->ref_count = 0;
|
||||||
atomic_set(&(node->open_count), 0);
|
node->open_count = 0;
|
||||||
node->in_ops = ops, node->in_fs = fs;
|
node->in_ops = ops, node->in_fs = fs;
|
||||||
vop_ref_inc(node);
|
vop_ref_inc(node);
|
||||||
}
|
}
|
||||||
@ -49,7 +49,8 @@ inode_kill(struct inode *node) {
|
|||||||
* */
|
* */
|
||||||
int
|
int
|
||||||
inode_ref_inc(struct inode *node) {
|
inode_ref_inc(struct inode *node) {
|
||||||
return atomic_add_return(&(node->ref_count), 1);
|
node->ref_count += 1;
|
||||||
|
return node->ref_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *
|
/* *
|
||||||
@ -61,7 +62,9 @@ int
|
|||||||
inode_ref_dec(struct inode *node) {
|
inode_ref_dec(struct inode *node) {
|
||||||
assert(inode_ref_count(node) > 0);
|
assert(inode_ref_count(node) > 0);
|
||||||
int ref_count, ret;
|
int ref_count, ret;
|
||||||
if ((ref_count = atomic_sub_return(&(node->ref_count), 1)) == 0) {
|
node->ref_count-= 1;
|
||||||
|
ref_count = node->ref_count;
|
||||||
|
if (ref_count == 0) {
|
||||||
if ((ret = vop_reclaim(node)) != 0 && ret != -E_BUSY) {
|
if ((ret = vop_reclaim(node)) != 0 && ret != -E_BUSY) {
|
||||||
cprintf("vfs: warning: vop_reclaim: %e.\n", ret);
|
cprintf("vfs: warning: vop_reclaim: %e.\n", ret);
|
||||||
}
|
}
|
||||||
@ -75,7 +78,8 @@ inode_ref_dec(struct inode *node) {
|
|||||||
* */
|
* */
|
||||||
int
|
int
|
||||||
inode_open_inc(struct inode *node) {
|
inode_open_inc(struct inode *node) {
|
||||||
return atomic_add_return(&(node->open_count), 1);
|
node->open_count += 1;
|
||||||
|
return node->open_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *
|
/* *
|
||||||
@ -87,7 +91,9 @@ int
|
|||||||
inode_open_dec(struct inode *node) {
|
inode_open_dec(struct inode *node) {
|
||||||
assert(inode_open_count(node) > 0);
|
assert(inode_open_count(node) > 0);
|
||||||
int open_count, ret;
|
int open_count, ret;
|
||||||
if ((open_count = atomic_sub_return(&(node->open_count), 1)) == 0) {
|
node->open_count -= 1;
|
||||||
|
open_count = node->open_count;
|
||||||
|
if (open_count == 0) {
|
||||||
if ((ret = vop_close(node)) != 0) {
|
if ((ret = vop_close(node)) != 0) {
|
||||||
cprintf("vfs: warning: vop_close: %e.\n", ret);
|
cprintf("vfs: warning: vop_close: %e.\n", ret);
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,8 @@ struct inode {
|
|||||||
inode_type_device_info = 0x1234,
|
inode_type_device_info = 0x1234,
|
||||||
inode_type_sfs_inode_info,
|
inode_type_sfs_inode_info,
|
||||||
} in_type;
|
} in_type;
|
||||||
atomic_t ref_count;
|
int ref_count;
|
||||||
atomic_t open_count;
|
int open_count;
|
||||||
struct fs *in_fs;
|
struct fs *in_fs;
|
||||||
const struct inode_ops *in_ops;
|
const struct inode_ops *in_ops;
|
||||||
};
|
};
|
||||||
@ -236,12 +236,12 @@ void inode_check(struct inode *node, const char *opstr);
|
|||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
inode_ref_count(struct inode *node) {
|
inode_ref_count(struct inode *node) {
|
||||||
return atomic_read(&(node->ref_count));
|
return node->ref_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
inode_open_count(struct inode *node) {
|
inode_open_count(struct inode *node) {
|
||||||
return atomic_read(&(node->open_count));
|
return node->open_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !__KERN_FS_VFS_INODE_H__ */
|
#endif /* !__KERN_FS_VFS_INODE_H__ */
|
||||||
|
@ -127,7 +127,7 @@ struct e820map {
|
|||||||
* that convert Page to other data types, such as phyical address.
|
* that convert Page to other data types, such as phyical address.
|
||||||
* */
|
* */
|
||||||
struct Page {
|
struct Page {
|
||||||
atomic_t ref; // page frame's reference counter
|
int ref; // page frame's reference counter
|
||||||
uint32_t flags; // array of flags that describe the status of the page frame
|
uint32_t flags; // array of flags that describe the status of the page frame
|
||||||
unsigned int property; // used in buddy system, stores the order (the X in 2^X) of the continuous memory block
|
unsigned int property; // used in buddy system, stores the order (the X in 2^X) of the continuous memory block
|
||||||
int zone_num; // used in buddy system, the No. of zone which the page belongs to
|
int zone_num; // used in buddy system, the No. of zone which the page belongs to
|
||||||
|
@ -121,22 +121,24 @@ pde2page(pde_t pde) {
|
|||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref(struct Page *page) {
|
page_ref(struct Page *page) {
|
||||||
return atomic_read(&(page->ref));
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
set_page_ref(struct Page *page, int val) {
|
set_page_ref(struct Page *page, int val) {
|
||||||
atomic_set(&(page->ref), val);
|
page->ref = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref_inc(struct Page *page) {
|
page_ref_inc(struct Page *page) {
|
||||||
return atomic_add_return(&(page->ref), 1);
|
page->ref += 1;
|
||||||
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
page_ref_dec(struct Page *page) {
|
page_ref_dec(struct Page *page) {
|
||||||
return atomic_sub_return(&(page->ref), 1);
|
page->ref -= 1;
|
||||||
|
return page->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern char bootstack[], bootstacktop[];
|
extern char bootstack[], bootstacktop[];
|
||||||
|
@ -35,7 +35,7 @@ struct mm_struct {
|
|||||||
pde_t *pgdir; // the PDT of these vma
|
pde_t *pgdir; // the PDT of these vma
|
||||||
int map_count; // the count of these vma
|
int map_count; // the count of these vma
|
||||||
void *sm_priv; // the private data for swap manager
|
void *sm_priv; // the private data for swap manager
|
||||||
atomic_t mm_count; // the number ofprocess which shared the mm
|
int mm_count; // the number ofprocess which shared the mm
|
||||||
semaphore_t mm_sem; // mutex for using dup_mmap fun to duplicat the mm
|
semaphore_t mm_sem; // mutex for using dup_mmap fun to duplicat the mm
|
||||||
int locked_by; // the lock owner process's pid
|
int locked_by; // the lock owner process's pid
|
||||||
|
|
||||||
@ -69,22 +69,24 @@ bool copy_string(struct mm_struct *mm, char *dst, const char *src, size_t maxn);
|
|||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
mm_count(struct mm_struct *mm) {
|
mm_count(struct mm_struct *mm) {
|
||||||
return atomic_read(&(mm->mm_count));
|
return mm->mm_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
set_mm_count(struct mm_struct *mm, int val) {
|
set_mm_count(struct mm_struct *mm, int val) {
|
||||||
atomic_set(&(mm->mm_count), val);
|
mm->mm_count = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
mm_count_inc(struct mm_struct *mm) {
|
mm_count_inc(struct mm_struct *mm) {
|
||||||
return atomic_add_return(&(mm->mm_count), 1);
|
mm->mm_count += 1;
|
||||||
|
return mm->mm_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
mm_count_dec(struct mm_struct *mm) {
|
mm_count_dec(struct mm_struct *mm) {
|
||||||
return atomic_sub_return(&(mm->mm_count), 1);
|
mm->mm_count -= 1;
|
||||||
|
return mm->mm_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
@ -3,167 +3,9 @@
|
|||||||
|
|
||||||
/* Atomic operations that C can't guarantee us. Useful for resource counting etc.. */
|
/* Atomic operations that C can't guarantee us. Useful for resource counting etc.. */
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
volatile int counter;
|
|
||||||
} atomic_t;
|
|
||||||
|
|
||||||
static inline int atomic_read(const atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline void atomic_set(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_add(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_sub(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_sub_test_zero(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline void atomic_inc(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline void atomic_dec(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_inc_test_zero(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline bool atomic_dec_test_zero(atomic_t *v) __attribute__((always_inline));
|
|
||||||
static inline int atomic_add_return(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
static inline int atomic_sub_return(atomic_t *v, int i) __attribute__((always_inline));
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_read - read atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically reads the value of @v.
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_read(const atomic_t *v) {
|
|
||||||
return v->counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_set - set atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: required value
|
|
||||||
*
|
|
||||||
* Atomically sets the value of @v to @i.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_set(atomic_t *v, int i) {
|
|
||||||
v->counter = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_add - add integer to atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to add
|
|
||||||
*
|
|
||||||
* Atomically adds @i to @v.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_add(atomic_t *v, int i) {
|
|
||||||
asm volatile ("addl %1, %0" : "+m" (v->counter) : "ir" (i));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub - subtract integer from atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_sub(atomic_t *v, int i) {
|
|
||||||
asm volatile("subl %1, %0" : "+m" (v->counter) : "ir" (i));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub_test_zero - subtract value from variable and test result
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v and
|
|
||||||
* returns true if the result is zero, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_sub_test_zero(atomic_t *v, int i) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("subl %2, %0; sete %1" : "+m" (v->counter), "=qm" (c) : "ir" (i) : "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_inc - increment atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically increments @v by 1.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_inc(atomic_t *v) {
|
|
||||||
asm volatile("incl %0" : "+m" (v->counter));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_dec - decrement atomic variable
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically decrements @v by 1.
|
|
||||||
* */
|
|
||||||
static inline void
|
|
||||||
atomic_dec(atomic_t *v) {
|
|
||||||
asm volatile("decl %0" : "+m" (v->counter));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_inc_test_zero - increment and test
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically increments @v by 1 and
|
|
||||||
* returns true if the result is zero, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_inc_test_zero(atomic_t *v) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("incl %0; sete %1" : "+m" (v->counter), "=qm" (c) :: "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_dec_test_zero - decrement and test
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically decrements @v by 1 and
|
|
||||||
* returns true if the result is 0, or false for all other cases.
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
atomic_dec_test_zero(atomic_t *v) {
|
|
||||||
unsigned char c;
|
|
||||||
asm volatile("decl %0; sete %1" : "+m" (v->counter), "=qm" (c) :: "memory");
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_add_return - add integer and return
|
|
||||||
* @i: integer value to add
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
*
|
|
||||||
* Atomically adds @i to @v and returns @i + @v
|
|
||||||
* Requires Modern 486+ processor
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_add_return(atomic_t *v, int i) {
|
|
||||||
int __i = i;
|
|
||||||
asm volatile("xaddl %0, %1" : "+r" (i), "+m" (v->counter) :: "memory");
|
|
||||||
return i + __i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* atomic_sub_return - subtract integer and return
|
|
||||||
* @v: pointer of type atomic_t
|
|
||||||
* @i: integer value to subtract
|
|
||||||
*
|
|
||||||
* Atomically subtracts @i from @v and returns @v - @i
|
|
||||||
* */
|
|
||||||
static inline int
|
|
||||||
atomic_sub_return(atomic_t *v, int i) {
|
|
||||||
return atomic_add_return(v, -i);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline void clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline void change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline void change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
static inline bool test_and_set_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_and_clear_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_and_change_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
|
||||||
static inline bool test_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
static inline bool test_bit(int nr, volatile void *addr) __attribute__((always_inline));
|
||||||
|
|
||||||
/* *
|
/* *
|
||||||
@ -199,6 +41,18 @@ change_bit(int nr, volatile void *addr) {
|
|||||||
asm volatile ("btcl %1, %0" :"=m" (*(volatile long *)addr) : "Ir" (nr));
|
asm volatile ("btcl %1, %0" :"=m" (*(volatile long *)addr) : "Ir" (nr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* *
|
||||||
|
* test_bit - Determine whether a bit is set
|
||||||
|
* @nr: the bit to test
|
||||||
|
* @addr: the address to count from
|
||||||
|
* */
|
||||||
|
static inline bool
|
||||||
|
test_bit(int nr, volatile void *addr) {
|
||||||
|
int oldbit;
|
||||||
|
asm volatile ("btl %2, %1; sbbl %0,%0" : "=r" (oldbit) : "m" (*(volatile long *)addr), "Ir" (nr));
|
||||||
|
return oldbit != 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* *
|
/* *
|
||||||
* test_and_set_bit - Atomically set a bit and return its old value
|
* test_and_set_bit - Atomically set a bit and return its old value
|
||||||
* @nr: the bit to set
|
* @nr: the bit to set
|
||||||
@ -222,30 +76,5 @@ test_and_clear_bit(int nr, volatile void *addr) {
|
|||||||
asm volatile ("btrl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
asm volatile ("btrl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
||||||
return oldbit != 0;
|
return oldbit != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_and_change_bit - Atomically change a bit and return its old value
|
|
||||||
* @nr: the bit to change
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_and_change_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btcl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory");
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *
|
|
||||||
* test_bit - Determine whether a bit is set
|
|
||||||
* @nr: the bit to test
|
|
||||||
* @addr: the address to count from
|
|
||||||
* */
|
|
||||||
static inline bool
|
|
||||||
test_bit(int nr, volatile void *addr) {
|
|
||||||
int oldbit;
|
|
||||||
asm volatile ("btl %2, %1; sbbl %0,%0" : "=r" (oldbit) : "m" (*(volatile long *)addr), "Ir" (nr));
|
|
||||||
return oldbit != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* !__LIBS_ATOMIC_H__ */
|
#endif /* !__LIBS_ATOMIC_H__ */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user