Mercurial > hg > Members > kono > nitros9-code
changeset 2120:73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
added more comments and proper symbols to fsrqmem.asm
author | boisy |
---|---|
date | Fri, 24 Aug 2007 22:13:57 +0000 |
parents | 7759100a08a1 |
children | f9e0961519bf |
files | level1/modules/boot_common.asm level1/modules/kernel/fsrqmem.asm |
diffstat | 2 files changed, 91 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/level1/modules/boot_common.asm Fri Aug 24 17:00:55 2007 +0000 +++ b/level1/modules/boot_common.asm Fri Aug 24 22:13:57 2007 +0000 @@ -47,12 +47,26 @@ * instead allocate the memory temporarily off the stack. This gives us * two system ram pages that were not available before, and also prevents * a needless system call. +* Note: For Level 1, we actually use the page above the stack at $500-$5FF +* to hold LSN0 during the bootfile acquisition process. This is because the +* system stack is only 256 bytes and we are using more than that. Since +* the module directory table is at $400-$4FF, we must do this; otherwise, we +* would overwrite the bottom portion of the module directory table and corrupt +* it (it's already setup by krn before boot is called!) start orcc #IntMasks ensure IRQs are off (necessary?) * allocate memory on stack for vars and sector buffer - leas -size-256,s + IFEQ Level-1 +* Level 1: stack is only 256 bytes and its bottom runs against moddir ptrs... so cheat and use free page just above stack +* for 256 byte disk buffer + leas -size,s + tfr s,u get pointer to data area + ldx #$500 + ELSE + leas -size-256,s tfr s,u get pointer to data area leax size,u point U to 256 byte sector buffer + ENDC pshs u save pointer to data area stx blockloc,u @@ -104,7 +118,12 @@ ldx blockimg,u pointer to start of os9boot in memory clrb clear carry ldd bootsize,u -error leas 2+size+256,s reset the stack same as PULS U +error + IFEQ Level-1 + leas 2+size,s reset the stack same as PULS U + ELSE + leas 2+size+256,s reset the stack same as PULS U + ENDC rts return to kernel
--- a/level1/modules/kernel/fsrqmem.asm Fri Aug 24 17:00:55 2007 +0000 +++ b/level1/modules/kernel/fsrqmem.asm Fri Aug 24 22:13:57 2007 +0000 @@ -1,25 +1,45 @@ -FSRqMem ldd R$D,u - addd #$00FF - clrb - std R$D,u - ldx <D.FMBM+2 - ldd #$01FF - pshs b,a - bra L0604 +************************************************** +* System Call: F$SRqMem +* +* Function: Request memory +* +* F$SRqMem allocates memory from the system in 256 byte 'pages.' +* There are 256 of these '256 byte pages' in RAM (256*256=64K). +* The allocation map, pointed to by D.FMBM holds 8 pages per byte, making the +* allocation map itself 32 bytes in size. +* +* Memory is allocated from the top of the system RAM map downwards. Rel/Boot/Krn +* also reside in this area, and are loaded from $EE00-$FFFF. Since this area is +* always allocated, we start searching for free pages from page $ED downward. +* +* Input: D = Byte count +* +* Output: U = Address of allocated memory area +* +* Error: CC = C bit set; B = error code +* +FSRqMem ldd R$D,u get memory allocation size requested + addd #$00FF round it up to nearest 256 byte page (e.g. $1FF = $2FE) + clrb just keep # of pages (e.g. $2FE = $200) + std R$D,u save rounded version back to user + ldx <D.FMBM+2 get ptr to end of free memory bitmap + ldd #$01FF A = $01 (RAM IN USE flag), B = $FF (counter) + pshs b,a save onto stack + bra L0604 start the search L05FA dec $01,s ldb $01,s L05FE lsl ,s bcc L060A rol ,s -L0604 leax -1,x - cmpx <D.FMBM - bcs L0620 -L060A lda ,x - anda ,s - bne L05FA - dec 1,s +L0604 leax -1,x backup into free memory bitmap + cmpx <D.FMBM did we move past the begining? + bcs L0620 branch if so +L060A lda ,x get byte in current location in free memory bitmap + anda ,s AND with $01 on stack + bne L05FA branch if not free + dec 1,s decrement counter on stack subb 1,s - cmpb 1,u + cmpb R$A,u rora addb 1,s rola @@ -29,32 +49,49 @@ incb L0620 leas 2,s bcs L0635 - ldx <D.FMBM + ldx <D.FMBM get pointer to start of free memory bitmap tfr d,y - ldb 1,u - clra + ldb R$A,u get MSB into B (this will be bit count) + clra clear A exg d,y - bsr L065A +* X = address of allocation bitmap +* D = Number of first bit to set +* Y = Bit count (number of bits to set) + bsr L065A call into F$AllBit to allocate bits exg a,b - std 8,u + std R$U,u put allocated addres into caller's U L0633 clra rts L0635 comb ldb #E$MemFul rts -FSRtMem ldd R$D,u - addd #$00FF - tfr a,b - clra - tfr d,y - ldd R$U,u - beq L0633 - tstb + + +************************************************** +* System Call: F$SRtMem +* +* Function: Return memory +* +* Input: U = Address of memory to return +* D = Number of bytes to return +* +* Output: None +* +* Error: CC = C bit set; B = error code +* +FSRtMem ldd R$D,u get memory allocation size requested + addd #$00FF round it up to nearest 256 byte page (e.g. $1FF = $2FE) + tfr a,b put MSB into B + clra now D reflects number of pages (not bytes) + tfr d,y put 16 bit page count into Y + ldd R$U,u get address of memory to free + beq L0633 if user passed 0, ignore + tstb check for B = 0 (it should!) beq L064E - comb + comb the user has passed B<>0 for the address, so return bad page error ldb #E$BPAddr rts -L064E exg a,b - ldx <D.FMBM - bra L06AD +L064E exg a,b swap A/B + ldx <D.FMBM get pointer to free memory bitmap + bra L06AD call into FDelBit to delete bits