eth: add safety asserts
This commit is contained in:
parent
824e91e6cb
commit
74bd81f87f
|
@ -277,6 +277,7 @@ impl<'rx> Eth<'rx> {
|
||||||
pub fn start_rx(&mut self, rx_buffers: [&'rx mut [u8]; rx::DESCS]) {
|
pub fn start_rx(&mut self, rx_buffers: [&'rx mut [u8]; rx::DESCS]) {
|
||||||
self.rx = Some(rx::DescList::new(rx_buffers));
|
self.rx = Some(rx::DescList::new(rx_buffers));
|
||||||
let list_addr = self.rx.as_ref().unwrap() as *const _ as u32;
|
let list_addr = self.rx.as_ref().unwrap() as *const _ as u32;
|
||||||
|
assert!(list_addr & 0b11 == 0);
|
||||||
self.regs.rx_qbar.write(
|
self.regs.rx_qbar.write(
|
||||||
regs::RxQbar::zeroed()
|
regs::RxQbar::zeroed()
|
||||||
.rx_q_baseaddr(list_addr >> 2)
|
.rx_q_baseaddr(list_addr >> 2)
|
||||||
|
|
|
@ -45,7 +45,9 @@ impl<'a> DescList<'a> {
|
||||||
pub fn new(buffers: [&'a mut [u8]; DESCS]) -> Self {
|
pub fn new(buffers: [&'a mut [u8]; DESCS]) -> Self {
|
||||||
let mut list: [DescEntry; DESCS] = unsafe { uninitialized() };
|
let mut list: [DescEntry; DESCS] = unsafe { uninitialized() };
|
||||||
for i in 0..DESCS {
|
for i in 0..DESCS {
|
||||||
|
assert!(buffers[i].len() >= 1536);
|
||||||
let buffer_addr = &mut buffers[i][0] as *mut _ as u32;
|
let buffer_addr = &mut buffers[i][0] as *mut _ as u32;
|
||||||
|
assert!(buffer_addr & 0b11 == 0);
|
||||||
list[i].word0.write(
|
list[i].word0.write(
|
||||||
DescWord0::zeroed()
|
DescWord0::zeroed()
|
||||||
.used(false)
|
.used(false)
|
||||||
|
|
Loading…
Reference in New Issue