Fixed spinlock halting caused by data misalignment
parent
7797ae7810
commit
623c44fcb3
|
|
@ -8,12 +8,6 @@
|
||||||
#include "proc.h"
|
#include "proc.h"
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
void initlock(struct spinlock *lk, char *name) {
|
|
||||||
lk->name = name;
|
|
||||||
lk->locked = 0;
|
|
||||||
lk->cpu = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Acquire the lock.
|
// Acquire the lock.
|
||||||
// Loops (spins) until the lock is acquired.
|
// Loops (spins) until the lock is acquired.
|
||||||
void acquire(struct spinlock *lk) {
|
void acquire(struct spinlock *lk) {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,18 @@
|
||||||
|
use core::ptr::null_mut;
|
||||||
|
|
||||||
// Mutual exclusion lock.
|
// Mutual exclusion lock.
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct SpinLock {
|
pub struct SpinLock {
|
||||||
// Is the lock held?
|
// Is the lock held?
|
||||||
pub locked: u32, // C boolean
|
pub locked: u32, // C boolean
|
||||||
// For debugging:
|
// For debugging:
|
||||||
pub name: Option<*mut ()>, // Name of lock.
|
pub name: *const u8, // Name of lock.
|
||||||
pub cpu: Option<*mut ()>, // The cpu holding the lock.
|
pub cpu: *mut (), // The cpu holding the lock.
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn initlock(lock: *mut SpinLock, name: *const u8) {
|
||||||
|
(*lock).name = name;
|
||||||
|
(*lock).locked = 0;
|
||||||
|
(*lock).cpu = null_mut();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
use crate::{memlayout::UART0, spinlock::SpinLock};
|
use crate::{
|
||||||
use core::ptr::addr_of_mut;
|
memlayout::UART0,
|
||||||
|
spinlock::{initlock, SpinLock},
|
||||||
|
};
|
||||||
|
use core::ptr::{addr_of_mut, null, null_mut};
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
// spinlock.c
|
// spinlock.c
|
||||||
fn push_off();
|
fn push_off();
|
||||||
fn pop_off();
|
fn pop_off();
|
||||||
fn initlock(spinlock: *mut SpinLock, name: *const u8);
|
|
||||||
fn acquire(spinlock: *mut SpinLock);
|
fn acquire(spinlock: *mut SpinLock);
|
||||||
fn release(spinlock: *mut SpinLock);
|
fn release(spinlock: *mut SpinLock);
|
||||||
|
|
||||||
|
|
@ -60,12 +62,12 @@ pub fn WriteReg(reg: u8, v: u8) {
|
||||||
// the transmit output buffer.
|
// the transmit output buffer.
|
||||||
static mut uart_tx_lock: crate::spinlock::SpinLock = crate::spinlock::SpinLock {
|
static mut uart_tx_lock: crate::spinlock::SpinLock = crate::spinlock::SpinLock {
|
||||||
locked: 0,
|
locked: 0,
|
||||||
cpu: None,
|
cpu: null_mut(),
|
||||||
name: None,
|
name: null(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// NOTE: string 'uart\0' for c-implmentation of spinlock. Stupid but works.
|
// NOTE: string 'uart\0' for c-implmentation of spinlock. Stupid but works.
|
||||||
static UART_LOCK_NAME: [u8; 5] = [117, 97, 114, 116, 0];
|
static UART_LOCK_NAME: [u8; 5] = [0x75, 0x61, 0x72, 0x74, 0];
|
||||||
|
|
||||||
const UART_TX_BUF_SIZE: usize = 32;
|
const UART_TX_BUF_SIZE: usize = 32;
|
||||||
static mut uart_tx_buf: [u8; UART_TX_BUF_SIZE] = [0; UART_TX_BUF_SIZE];
|
static mut uart_tx_buf: [u8; UART_TX_BUF_SIZE] = [0; UART_TX_BUF_SIZE];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue